/* ============================================================
   css/ui.css - lapisan tampilan global (dimuat di SEMUA halaman lewat
   partials/theme_head.php).
   1. Palet tema LIGHT (siang) & DARK (malam) - efek kaca (glassmorphism)
      sudah menyatu di keduanya, tidak ada opsi glass terpisah.
   2. Kontrol tema, scrollbar atas tabel, marker & legenda peta.
   3. Responsive penuh untuk semua ukuran HP (320px ke atas).
   Selektor memakai ":root"/"html body" agar menang dari CSS lama
   tanpa bergantung urutan file.
   ============================================================ */

/* ---------- 1. PALET ---------- */
:root:root.theme-light,
:root:root.theme-light body,
:root:root:not(.theme-dark) body {
    --primary-color: #0a6cc2;
    --primary-dark: #07539a;
    --primary-light: #e0efff;
    --secondary-color: #0ea5c6;
    --secondary-dark: #0b86a3;
    --success-color: #16a34a;
    --warning-color: #d97706;
    --error-color: #dc2626;
    --bg-color: #dbeafe;
    --bg-gradient: linear-gradient(180deg, #bfdbfe 0%, #dbeafe 38%, #eef6ff 72%, #f8fbff 100%);
    --card-bg: rgba(255, 255, 255, 0.78);
    --input-bg: rgba(255, 255, 255, 0.92);
    --tab-bg: rgba(226, 238, 252, 0.8);
    --white: #ffffff;
    --text-dark: #0f1f33;
    --text-light: #4b5d73;
    --border-color: rgba(10, 70, 140, 0.16);
    --shadow: 0 8px 30px rgba(20, 70, 140, 0.12);
    --radius: 16px;
    --glass-bg: rgba(255, 255, 255, 0.62);
    --glass-bg-strong: rgba(255, 255, 255, 0.86);
    --glass-border: rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 8px 32px rgba(20, 70, 140, 0.14);
    --glass-blur: blur(14px) saturate(140%);
    --glass-radius: 18px;
    --accent-user: #ef4444;
    --accent-covered: #16a34a;
    --accent-other: #64748b;
}

:root:root.theme-dark,
:root:root.theme-dark body {
    --primary-color: #3b8beb;
    --primary-dark: #2563eb;
    --primary-light: #172554;
    --secondary-color: #0891b2;
    --secondary-dark: #0e7490;
    --success-color: #34d399;
    --warning-color: #fbbf24;
    --error-color: #f87171;
    --bg-color: #0b1224;
    --bg-gradient: linear-gradient(180deg, #050a18 0%, #0b1224 40%, #111b38 75%, #16224a 100%);
    --card-bg: rgba(17, 27, 51, 0.72);
    --input-bg: rgba(10, 18, 38, 0.85);
    --tab-bg: rgba(30, 41, 70, 0.7);
    --white: #ffffff;
    --text-dark: #e6edf7;
    --text-light: #a3b3c9;
    --border-color: rgba(148, 163, 184, 0.2);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    --radius: 16px;
    --glass-bg: rgba(15, 23, 42, 0.55);
    --glass-bg-strong: rgba(15, 23, 42, 0.85);
    --glass-border: rgba(148, 163, 184, 0.22);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    --glass-blur: blur(14px) saturate(130%);
    --glass-radius: 18px;
    --accent-user: #f87171;
    --accent-covered: #34d399;
    --accent-other: #94a3b8;
}

html body {
    background: var(--bg-gradient) fixed;
    background-color: var(--bg-color);
    color: var(--text-dark);
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

/* Permukaan kaca untuk semua kartu utama (light & dark) */
html body header,
html body .search-section,
html body .user-info-bar,
html body .map-controls,
html body .results-section,
html body .cbn-wrap,
html body .auth-card,
html body .dsh-card,
html body .adm-card,
html body .ah-card,
html body .lp-card,
html body .face-container,
html body .theme-toggle-wrap {
    background: var(--glass-bg);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}
html body header { border-bottom: 4px solid var(--primary-color); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    html body header, html body .search-section, html body .user-info-bar, html body .map-controls,
    html body .results-section, html body .cbn-wrap, html body .auth-card, html body .dsh-card,
    html body .adm-card, html body .ah-card, html body .lp-card, html body .face-container,
    html body .theme-toggle-wrap { background: var(--glass-bg-strong); }
}

html body input, html body select, html body textarea {
    background-color: var(--input-bg);
    color: var(--text-dark);
    border-color: var(--border-color);
}

/* ---------- 2a. KONTROL TEMA ---------- */
html body .theme-toggle-wrap {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 14px;
}
html body .theme-floating {
    width: fit-content;
    max-width: calc(100% - 20px);
    margin: 10px 10px 0 auto;
    position: relative;
    z-index: 5;
}
html body .theme-segmented {
    display: inline-flex;
    background: var(--tab-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}
html body .theme-segment-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 0;
    background: transparent;
    color: var(--text-light);
    font: 600 12px/1 inherit;
    padding: 7px 10px;
    border-radius: 8px;
    cursor: pointer;
    min-height: 32px;
}
html body .theme-segment-btn.current { color: var(--text-dark); }
html body .theme-segment-btn.active {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
html body .theme-auto-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: auto;
    height: 34px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--tab-bg);
    color: var(--text-dark);
    font: 600 12px/1 inherit;
    cursor: pointer;
}
html body .theme-auto-btn.active {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-color: transparent;
    color: #fff;
}
html body .theme-glass-btn { display: none !important; }
html body .theme-clock-widget {
    background: var(--tab-bg);
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    border-radius: 10px;
    min-width: 0;
    padding: 5px 10px;
}

/* ---------- 2b. SCROLLBAR HORIZONTAL DI ATAS TABEL ---------- */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}
.top-scroll {
    display: none;
    align-items: center;
    gap: 6px;
    position: sticky;
    top: 0;
    z-index: 6;
    margin-bottom: 6px;
    padding: 4px;
    border-radius: 10px;
    background: var(--glass-bg-strong);
    border: 1px solid var(--border-color);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    user-select: none;
    touch-action: none;
}
.top-scroll.show { display: flex; }
.top-scroll-btn {
    flex: 0 0 auto;
    width: 30px;
    height: 26px;
    min-height: 0 !important;
    border: 0;
    border-radius: 8px;
    background: var(--tab-bg);
    color: var(--primary-color);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
}
.top-scroll-track {
    position: relative;
    flex: 1 1 auto;
    height: 12px;
    border-radius: 8px;
    background: rgba(100, 116, 139, 0.18);
    cursor: pointer;
}
.top-scroll-thumb {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    min-width: 28px;
    border-radius: 8px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    cursor: grab;
}
.top-scroll-thumb:active { cursor: grabbing; }
.top-scroll-hint {
    flex: 0 0 auto;
    font-size: 11px;
    color: var(--text-light);
    white-space: nowrap;
}
@media (max-width: 420px) { .top-scroll-hint { display: none; } }
/* kolom nomor & HID tetap mudah dibaca saat digeser */
#hid-table th, #hid-table td { white-space: nowrap; }

/* ---------- 2c. MARKER & LEGENDA PETA ---------- */
.mm-marker { background: none !important; border: 0 !important; }
.mm-user { position: relative; }
.mm-user .mm-pin {
    position: absolute;
    left: 50%;
    top: 0;
    width: 30px;
    height: 30px;
    margin-left: -15px;
    background: var(--accent-user, #ef4444);
    border: 3px solid #fff;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}
.mm-user .mm-pin-dot {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    margin: -5px 0 0 -5px;
    background: #fff;
    border-radius: 50%;
}
.mm-user .mm-pulse {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 16px;
    height: 16px;
    margin-left: -8px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.45);
    animation: mm-pulse 1.8s ease-out infinite;
}
@keyframes mm-pulse {
    0% { transform: scale(0.6); opacity: 0.9; }
    100% { transform: scale(3.2); opacity: 0; }
}
.mm-hid-covered .mm-dot,
.mm-hid-other .mm-dot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    font-size: 13px;
}
.mm-hid-covered .mm-dot { background: var(--accent-covered, #16a34a); }
.mm-hid-other .mm-dot { background: var(--accent-other, #64748b); opacity: 0.9; }
.mm-legend {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 6px 9px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.92);
    color: #0f1f33;
    font: 600 11px/1.3 'Inter', 'Segoe UI', sans-serif;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
:root.theme-dark .mm-legend { background: rgba(15, 23, 42, 0.9); color: #e6edf7; }
.mm-legend span { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.mm-lg { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2); }
.mm-lg-user { background: var(--accent-user, #ef4444); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.mm-lg-covered { background: var(--accent-covered, #16a34a); }
.mm-lg-other { background: var(--accent-other, #64748b); }
.mm-popup .leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.45; }
.mm-popup .leaflet-popup-content h4 { margin: 0 0 6px; font-size: 14px; }
.mm-popup .leaflet-popup-content p { margin: 2px 0; }
.mm-popup .btn-copy, .mm-popup .btn-primary { width: 100%; min-height: 36px; margin-top: 6px; }
:root.theme-dark .leaflet-popup-content-wrapper,
:root.theme-dark .leaflet-popup-tip { background: #111b33; color: #e6edf7; }

/* ---------- 3. RESPONSIVE ---------- */
/* item grid/flex tidak boleh melebar melebihi layar karena isi tabel */
html body .adm-card, html body .dsh-card, html body .ah-card,
html body .grid2 > *, html body [class*="grid"] > * { min-width: 0; }
img, video, canvas:not(#particle-canvas), iframe { max-width: 100%; }
html body .leaflet-container img { max-width: none; }

@media (max-width: 768px) {
    html body { padding-left: 0; padding-right: 0; }
    html body .container { padding: 10px; }
    html body header { padding: 14px 12px; margin-bottom: 12px; }
    html body header h1 { font-size: 1.25em; line-height: 1.3; }
    html body header p { font-size: 0.88em; }

    /* cegah zoom otomatis iOS saat fokus input */
    html body input, html body select, html body textarea { font-size: 16px; }
    html body button, html body .btn, html body .btn-primary, html body .btn-secondary { min-height: 42px; }

    /* baris info user + tombol */
    html body .user-info-bar { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px; }
    html body .user-info-bar > div:last-child { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px; }
    html body .user-info-bar > div:last-child a { width: 100%; padding: 10px 8px !important; font-size: 13px !important; }
    html body .user-info-bar > div:first-child { word-break: break-word; }

    /* tab pencarian jadi grid 2 kolom yang ringkas */
    html body .search-tabs, html body .tab-buttons, html body .tabs {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    html body .tab-button {
        width: 100%;
        margin: 0 !important;
        padding: 10px 8px !important;
        font-size: 13px !important;
        border-radius: 10px !important;
        line-height: 1.25;
        white-space: normal;
        text-align: center;
    }
    html body .tab-button:last-child:nth-child(odd) { grid-column: 1 / -1; }
    html body .search-section { padding: 12px !important; }
    html body .search-form { padding: 0; }
    html body .form-row, html body .input-row { flex-direction: column; gap: 10px; }

    /* kontrol peta */
    html body .map-controls { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; }
    html body .map-controls > * { width: 100%; }
    html body .map-type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
    html body .map-type-toggle .btn-map-type { width: 100%; }
    html body .coverage-info { text-align: center; }
    html body .map-container, html body #map { height: 58vh !important; min-height: 300px; }

    html body .results-section { padding: 12px !important; }
    html body .table-header { flex-direction: column; align-items: flex-start; gap: 4px; }

    /* dashboard & admin */
    html body .adm-wrap, html body .dsh-wrap, html body .ah-wrap { padding: 12px !important; }
    html body .adm-card, html body .dsh-card, html body .ah-card { padding: 14px !important; border-radius: 14px; }
    html body .adm-head { flex-direction: column; align-items: stretch !important; gap: 10px; }
    html body .adm-title, html body .ah-title { font-size: 18px !important; }
    html body .adm-actions, html body .adm-nav {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 8px !important;
        width: 100%;
    }
    html body .adm-actions .btn, html body .adm-nav .btn { width: 100%; justify-content: center; text-align: center; }
    html body .stat-grid { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
    html body .stat-box { padding: 12px !important; }
    html body .stat-box .num { font-size: 22px !important; }
    html body .grid2 { grid-template-columns: 1fr !important; }
    /* tabel lebar: geser kanan-kiri (scrollbar di atas), sel tidak terjepit */
    html body .tbl-wide > table { width: max-content; min-width: 100%; }
    html body .tbl-wide th, html body .tbl-wide td { white-space: nowrap; }
    html body .tbl-wide td.ah-hbody, html body .tbl-wide td.th-reply, html body .tbl-wide td.th-in,
    html body .tbl-wide td.wrap { white-space: normal; min-width: 220px; max-width: 320px; }
    html body .table-scroll:not(.tbl-wide) td { word-break: break-word; }
    /* tabel kunci-nilai (class kv): judul di atas, isi di bawah */
    html body table.kv, html body table.kv tbody, html body table.kv tr,
    html body table.kv th, html body table.kv td { display: block; width: 100% !important; }
    html body table.kv tr { padding: 8px 0; border-bottom: 1px solid var(--border-color); }
    html body table.kv th, html body table.kv td { border: 0 !important; padding: 3px 4px !important; background: transparent !important; }
    html body table.kv tr.kv-head { display: none; }
    html body .adm-table th, html body .adm-table td,
    html body .ah-table th, html body .ah-table td { padding: 8px 10px; font-size: 13px; }
    html body .adm-filters, html body .dsh-filters, html body .filt,
    html body form.filters { flex-direction: column; align-items: stretch !important; }
    html body .adm-filters > *, html body .dsh-filters > *, html body .filt > * { width: 100%; }
    html body .ah-pag, html body .adm-pag { flex-direction: column; gap: 8px; align-items: center; }
    html body .ah-pag-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }

    /* halaman login / register / face */
    html body .auth-wrap, html body .lp-wrap { padding: 14px !important; align-items: flex-start; }
    html body .auth-card, html body .lp-card { padding: 20px 16px !important; margin-top: 8px; }
    html body .face-container { padding: 16px !important; width: 100%; }
    html body video, html body .face-video, html body #video { width: 100% !important; height: auto !important; }

    /* topbar form GAS */
    html body .gw-topbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
    html body .gw-topbar .gw-nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; width: 100%; }
    html body .gw-topbar .gw-link { text-align: center; padding: 8px 4px; font-size: 12.5px; }
    html body .gw-topbar .theme-toggle-wrap { width: 100%; justify-content: center; }
    html body .gw-topbar .gw-user { width: 100%; text-align: center; }

    html body .theme-floating { margin: 8px auto 0; max-width: calc(100% - 16px); justify-content: center; }
    html body .leaflet-control-attribution { font-size: 9px; }
}

@media (max-width: 420px) {
    html body .theme-toggle-label { display: none; }
    html body .theme-segment-btn .segment-label { display: none; }
    html body .theme-segment-btn { padding: 7px 12px; font-size: 15px; }
    html body .theme-clock-widget { font-size: 12px; padding: 5px 8px; }
    html body .theme-toggle-wrap { gap: 6px; padding: 6px 8px; justify-content: center; }
    html body .gw-topbar .gw-nav { grid-template-columns: 1fr 1fr 1fr; }
}

@media (max-width: 340px) {
    html body .container { padding: 6px; }
    html body header h1 { font-size: 1.08em; }
    html body .tab-button { font-size: 12px !important; padding: 9px 6px !important; }
    html body .user-info-bar > div:last-child { grid-template-columns: 1fr; }
    html body .stat-grid { grid-template-columns: 1fr !important; }
    html body .adm-actions, html body .adm-nav { grid-template-columns: 1fr; }
    html body .theme-auto-btn .auto-label { display: none; }
}

/* Layar sangat pendek (HP landscape) */
@media (max-height: 480px) and (orientation: landscape) {
    html body .map-container, html body #map { height: 80vh !important; }
}

@media (prefers-reduced-motion: reduce) {
    .mm-user .mm-pulse { animation: none; }
}

/* Latar animasi selalu di BELAKANG semua konten (termasuk halaman form GAS) */
html body #particle-canvas { z-index: -1 !important; position: fixed !important; }
html { background: transparent; }

/* ---------- TABEL HASIL HID: selalu mode tabel (bukan kartu) ----------
   Di HP tabel digeser kanan-kiri memakai scrollbar di atas tabel,
   sehingga semua kolom tetap sejajar & mudah dibandingkan. */
html body #hid-table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 13px; }
html body #hid-table thead { display: table-header-group; }
html body #hid-table thead th {
    position: sticky; top: 0; z-index: 1;
    background: var(--tab-bg); color: var(--text-dark);
    padding: 9px 10px; font-size: 12px; text-align: left; white-space: nowrap;
    border-bottom: 2px solid var(--primary-color);
}
html body #hid-table tbody tr {
    display: table-row; padding: 0; margin: 0; border: 0; border-radius: 0;
    background: transparent; box-shadow: none; transform: none;
}
html body #hid-table tbody tr:nth-of-type(even) { background: rgba(100, 116, 139, 0.07); }
html body #hid-table tbody tr:hover { background: var(--primary-light); transform: none; }
html body #hid-table tbody td,
html body #hid-table tbody td:first-child,
html body #hid-table tbody td:last-child {
    display: table-cell; padding: 8px 10px; margin: 0;
    border-bottom: 1px solid var(--border-color); border-radius: 0;
    white-space: nowrap !important; max-width: 260px !important;
    overflow: hidden !important; text-overflow: ellipsis !important;
    background: transparent; color: var(--text-dark); font-weight: normal;
    font-size: 13px; text-align: left;
}
html body #hid-table tbody td::before { content: none !important; }
html body #hid-table tbody td:first-child { font-weight: 700; color: var(--primary-color); }
html body #hid-table tbody td:last-child { overflow: visible !important; max-width: none !important; }
html body #hid-table .hid-actions { display: flex; flex-direction: row; gap: 6px; }
html body #hid-table .hid-actions button { min-height: 32px; padding: 6px 10px; font-size: 12px; white-space: nowrap; width: auto; border-radius: 8px; }

/* Tautan di kartu admin/dashboard terbaca di kedua tema */
html body .adm-card a:not(.btn), html body .dsh-card a:not(.btn), html body .ah-card a:not(.btn) { color: var(--primary-color); }
:root.theme-dark .adm-card a:not(.btn), :root.theme-dark .dsh-card a:not(.btn) { color: #7cb8ff; }

/* ---------- Navigasi halus ala SPA ---------- */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: 160ms ease-out both vt-fade-out; }
::view-transition-new(root) { animation: 220ms ease-out both vt-fade-in; }
@keyframes vt-fade-out { to { opacity: 0; } }
@keyframes vt-fade-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}
.nav-progress {
    position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 99999;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    box-shadow: 0 0 8px var(--secondary-color);
    pointer-events: none; opacity: 0;
}
.nav-progress.run { opacity: 1; animation: nav-progress 6s cubic-bezier(.08,.8,.2,1) forwards; }
@keyframes nav-progress { 0% { width: 0; } 30% { width: 55%; } 100% { width: 92%; } }
