/* Dashboard Kualitas Udara (/data/dashboard-ku).
   Kiosk layout: header / filterbar / [stats | map | tables] / footer,
   fills the viewport. Colors use the app.css variables so light/dark
   themes flip automatically; header & filterbar stay dark brand bars. */

.hd-shell {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr) 380px;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
        "header  header  header"
        "filter  filter  filter"
        "left    map     right"
        "footer  footer  footer";
    overflow: hidden;
    background: var(--bg-color);
    color: var(--text-color);
}

/* ============================================================
   HEADER
   ============================================================ */
.hd-header {
    grid-area: header;
    position: relative;
    z-index: 20; /* dropdown menu harus di atas filterbar di bawahnya */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    padding: 0.55rem 1.25rem;
    background: linear-gradient(120deg, #0b1220 0%, #0f172a 55%, #13233d 100%);
    color: #fff;
    border-bottom: 3px solid var(--primary-color);
}

.hd-brand {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    min-width: 0;
}

.hd-logo-link {
    flex-shrink: 0;
    border-radius: 12px;
    transition: transform 0.12s ease;
}

.hd-logo-link:hover {
    transform: scale(1.05);
}

.hd-logo {
    width: 44px;
    height: 44px;
    object-fit: contain;
    padding: 3px;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 10px;
    flex-shrink: 0;
}

.hd-org {
    font-size: 0.64rem;
    letter-spacing: 0.09em;
    margin: 0;
    color: rgba(255, 255, 255, 0.68);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hd-title {
    font-size: 1.18rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hd-sub {
    font-size: 0.7rem;
    margin: 0;
    color: rgba(255, 255, 255, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hd-header-right {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-shrink: 0;
}

.hd-clock {
    text-align: right;
    line-height: 1.15;
    margin-right: 0.3rem;
}

.hd-clock-time {
    font-size: 1.45rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.hd-clock-date {
    font-size: 0.76rem;
    color: rgba(255, 255, 255, 0.72);
}

.hd-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.hd-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.hd-btn:active {
    transform: scale(0.94);
}

.hd-btn svg {
    width: 19px;
    height: 19px;
}

/* Tombol menu: ikon + label teks, sedikit lebih lebar */
.hd-btn-menu {
    width: auto;
    gap: 0.4rem;
    padding: 0 0.8rem;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--primary-color);
    border-color: rgba(255, 255, 255, 0.2);
}

.hd-btn-menu:hover {
    filter: brightness(1.12);
    background: var(--primary-color);
}

.hd-btn-menu-label {
    line-height: 1;
}

@media (max-width: 767.98px) {
    .hd-btn-menu-label {
        display: none;
    }

    .hd-btn-menu {
        padding: 0;
        width: 40px;
    }
}

/* ============================================================
   FILTER BAR — wilayah (polygon) + rentang tanggal
   ============================================================ */
.hd-filterbar {
    grid-area: filter;
    position: relative;
    z-index: 15; /* dropdown menu di dalamnya harus di atas peta */
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    padding: 0.45rem 1.25rem;
    background: #0f172a;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
}

.hd-filterbar-group {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.hd-filterbar-sep {
    width: 1px;
    align-self: stretch;
    background: rgba(255, 255, 255, 0.18);
    flex-shrink: 0;
}

/* Tombol aksi (tema, layar penuh, menu) — menempel kanan pada desktop */
.hd-filterbar-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-left: auto;
    flex-shrink: 0;
}

.hd-filter-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.65);
}

.hd-filter-field select,
.hd-filter-field input {
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.25;
    min-height: 32px;
}

.hd-filter-field select {
    max-width: 210px;
    cursor: pointer;
}

.hd-filter-field select:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.hd-filter-field option,
.hd-filter-field optgroup {
    background: #0f172a;
    color: #e2e8f0;
}

[data-theme="dark"] .hd-filter-field input {
    color-scheme: dark;
}

.hd-range-btn {
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 7px;
    background: var(--primary-color);
    color: #fff;
    padding: 0.35rem 0.85rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.25;
    cursor: pointer;
    transition: filter 0.15s ease;
}

.hd-range-btn:hover {
    filter: brightness(1.15);
}

.hd-range-reset {
    background: rgba(255, 255, 255, 0.08);
}

.hd-filter-error {
    flex-basis: 100%;
    margin: 0;
    font-size: 0.72rem;
    color: #fca5a5;
}

/* ============================================================
   HEADER — MAP MENU (pengganti kontrol on-map Leaflet)
   ============================================================ */
.hd-menu-wrap {
    position: relative;
}

.hd-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 1200;
    min-width: 245px;
    padding: 0.45rem;
    display: none;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.hd-menu.open {
    display: block;
}

.hd-menu-title {
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    padding: 0.4rem 0.6rem 0.25rem;
}

.hd-menu-zoom {
    display: flex;
    gap: 0.4rem;
    padding: 0 0.2rem 0.3rem;
}

.hd-menu-zoom .hd-menu-item {
    flex: 1;
    justify-content: center;
    border: 1px solid var(--border-color);
}

.hd-menu-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-color);
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
}

button.hd-menu-item:hover {
    background: var(--secondary-color);
}

.hd-menu-item svg {
    width: 17px;
    height: 17px;
    color: var(--primary-color);
    flex-shrink: 0;
}

/* --- Toggle switch (tombol layer) --- */
.hd-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-color);
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
}

button.hd-switch:hover,
label.hd-switch:hover {
    background: var(--secondary-color);
}

.hd-switch-label {
    flex: 1;
}

.hd-switch-track {
    position: relative;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
    border-radius: 999px;
    background: #94a3b8;
    transition: background 0.18s ease;
}

.hd-switch-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: transform 0.18s ease;
}

.hd-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.hd-switch input:checked ~ .hd-switch-track,
.hd-switch-btn.active .hd-switch-track {
    background: #16a34a;
}

.hd-switch input:checked ~ .hd-switch-track .hd-switch-knob,
.hd-switch-btn.active .hd-switch-track .hd-switch-knob {
    transform: translateX(16px);
}

.hd-switch-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.hd-switch-btn:disabled:hover {
    background: transparent;
}

/* ============================================================
   LEFT PANEL — stat cards
   ============================================================ */
.hd-left {
    grid-area: left;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    padding: 0.85rem;
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
    background: var(--card-bg-alt);
}

.hd-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

.hd-card-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
    line-height: 1.35;
}

.hd-total-value {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.hd-card-caption {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    line-height: 1.4;
}

.hd-cert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-left: 5px solid transparent;
    padding: 0.7rem 1rem;
}

.hd-cert .hd-cert-value {
    font-size: 1.55rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.hd-cert-high {
    border-left-color: #ef4444;
}

.hd-cert-high .hd-cert-value {
    color: #ef4444;
}

.hd-cert-medium {
    border-left-color: #eab308;
}

.hd-cert-medium .hd-cert-value {
    color: #ca8a04;
}

.hd-cert-low {
    border-left-color: #22c55e;
}

.hd-cert-low .hd-cert-value {
    color: #16a34a;
}

.hd-update-note {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0;
}

/* --- Legend --- */
.hd-legend {
    display: flex;
    flex-direction: column;
    gap: 0.32rem;
    font-size: 0.76rem;
}

.hd-legend-sub {
    font-size: 0.63rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 0.45rem 0 0.15rem;
    padding-bottom: 0.2rem;
    border-bottom: 1px dashed var(--border-color);
}

.hd-legend .hd-legend-sub:first-child {
    margin-top: 0;
    border-top: 0;
}

.hd-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hd-legend-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

/* ============================================================
   MAP
   ============================================================ */
.hd-map-wrap {
    grid-area: map;
    position: relative;
    min-height: 0;
    min-width: 0;
    background: #0b1220;
}

#hotspot-map {
    width: 100%;
    height: 100%;
    margin: 0;
    border-radius: 0;
}

.hd-map-note {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    max-width: min(90%, 32rem);
    padding: 0.6rem 1.1rem;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.88);
    color: #fff;
    font-size: 0.85rem;
    text-align: center;
    pointer-events: none;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

/* ============================================================
   RIGHT PANEL — tables
   ============================================================ */
.hd-right {
    grid-area: right;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    padding: 0.85rem;
    overflow-y: auto;
    border-left: 1px solid var(--border-color);
    background: var(--card-bg-alt);
}

.hd-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.8rem;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

.hd-panel-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.55rem;
    padding-bottom: 0.45rem;
    border-bottom: 1px solid var(--border-color);
    line-height: 1.4;
}

/* Override the homepage fixed heights from map.css — panels scroll instead */
.hd-right .pm25-ranking-table,
.hd-right .hotspot-region-stats {
    max-height: none;
    overflow: visible;
    flex: none;
    min-width: 0;
}

.hd-right .table {
    font-size: 0.8rem;
    --bs-table-hover-color: var(--text-color);
}

/* Baris total & baris provinsi mengikuti tema (bukan putih kaku) */
.hd-right .hd-table-foot td {
    background-color: var(--secondary-color);
    color: var(--text-primary);
}

.hd-right .province-row td {
    background-color: var(--card-bg-alt);
}

/* Sel PM2.5: nilai di atas, kategori di bawahnya (lebih kecil) */
.hd-pm25-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    line-height: 1.15;
}

.hd-pm25-value {
    font-weight: 700;
    font-size: 0.92rem;
    font-variant-numeric: tabular-nums;
}

.hd-pm25-cat {
    font-size: 0.58rem;
    font-weight: 600;
    padding: 0.18em 0.55em;
    letter-spacing: 0.02em;
}

/* Baris peringkat PM2.5 dapat diklik → zoom ke stasiun */
.hd-right .hd-pm25-row:hover td {
    background-color: var(--table-hover, #f1f5f9);
}

/* Indikator memuat pada kartu statistik */
.hd-loading-text {
    animation: hd-pulse 1.2s ease-in-out infinite;
}

@keyframes hd-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* ============================================================
   WEATHER INFO — bagian cuaca pada popup stasiun
   (dashboard-weather.js; popup max-width 300px dari map.css)
   ============================================================ */
.hd-wx-wrap {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-color, #cbd5e1);
}

.hd-wx-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #64748b);
    margin-bottom: 6px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.hd-wx-loc {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    color: var(--primary-color, #1a73e8);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hd-wx-loading {
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
}

.hd-wx-failed {
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
    margin: 0;
}

.hd-wx-now {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.hd-wx-now-icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.hd-wx-now-main {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    flex: 1;
    min-width: 0;
}

.hd-wx-now-temp {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
}

.hd-wx-now-desc {
    font-size: 0.72rem;
    color: var(--text-muted, #64748b);
}

.hd-wx-now-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.66rem;
    color: var(--text-muted, #64748b);
    text-align: right;
}

.hd-wx-days {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.hd-wx-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 4px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    background: var(--card-bg-alt, #f8fafc);
    min-width: 0;
}

.hd-wx-day-label {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted, #64748b);
}

.hd-wx-day-icon {
    width: 26px;
    height: 26px;
}

.hd-wx-day-temp {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    font-variant-numeric: tabular-nums;
}

.hd-wx-day-desc {
    font-size: 0.58rem;
    color: var(--text-muted, #64748b);
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hd-right::-webkit-scrollbar,
.hd-left::-webkit-scrollbar {
    width: 6px;
}

.hd-right::-webkit-scrollbar-thumb,
.hd-left::-webkit-scrollbar-thumb {
    background: var(--text-muted, #ccc);
    border-radius: 3px;
}

/* ============================================================
   FOOTER
   ============================================================ */
.hd-footer {
    grid-area: footer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    padding: 0.4rem 1.25rem;
    font-size: 0.7rem;
    background: var(--footer-bg);
    color: rgba(255, 255, 255, 0.8);
}

/* ============================================================
   RESPONSIVE — tablet: kolom lebih ramping
   ============================================================ */
@media (max-width: 1399.98px) {
    .hd-shell {
        grid-template-columns: 260px minmax(0, 1fr) 330px;
    }
}

/* ============================================================
   RESPONSIVE — mobile: layout bertumpuk, stat menjadi strip
   horizontal yang bisa digeser, map 50vh.
   ============================================================ */
@media (max-width: 991.98px) {
    .hd-shell {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto 50vh auto auto auto;
        grid-template-areas:
            "header"
            "filter"
            "map"
            "left"
            "right"
            "footer";
        height: auto;
        min-height: 100dvh;
        overflow: visible;
    }

    .hd-map-wrap {
        min-height: 50vh;
    }

    #hotspot-map {
        height: 100%;
        min-height: 50vh;
    }

    .hd-header {
        padding: 0.5rem 0.9rem;
    }

    .hd-title {
        font-size: 0.98rem;
        white-space: normal;
    }

    .hd-sub,
    .hd-org {
        white-space: normal;
    }

    .hd-clock-time {
        font-size: 1.05rem;
    }

    .hd-clock-date {
        display: none;
    }

    .hd-filterbar {
        padding: 0.4rem 0.9rem;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .hd-filterbar-sep {
        flex-shrink: 0;
    }

    .hd-filter-field select {
        max-width: 160px;
    }

    .hd-left {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 0.6rem 0.9rem;
        gap: 0.55rem;
    }

    .hd-left .hd-card {
        flex-shrink: 0;
        min-width: 150px;
    }

    .hd-total-value {
        font-size: 1.9rem;
    }

    .hd-left .hd-card:nth-last-child(2),
    .hd-left .hd-card:last-child {
        flex-shrink: 0;
        min-width: 200px;
    }

    .hd-right {
        overflow: visible;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }

    .hd-footer {
        justify-content: center;
        text-align: center;
    }
}

@media (max-width: 575.98px) {
    .hd-brand {
        gap: 0.6rem;
    }

    .hd-logo {
        width: 36px;
        height: 36px;
    }

    .hd-org {
        display: none;
    }

    .hd-header-right {
        gap: 0.45rem;
    }

    .hd-btn {
        width: 36px;
        height: 36px;
    }

    .hd-clock {
        margin-right: 0;
    }

    .hd-clock-time {
        font-size: 0.92rem;
    }
}
