/* =========================================================
   TEMA GELAP / TERANG  (halaman publik + admin)
   ---------------------------------------------------------
   - Dipilih lewat atribut  <html data-theme="light|dark">  yang diatur
     oleh js/theme.js (mengikuti pilihan pengguna, atau pengaturan
     sistem bila belum memilih).
   - Tema terang = tampilan asli. Tema gelap menimpa variabel warna di
     style.css dan warna "hardcode" yang ada di css lain / <style> inline.
   - Muat file ini SETELAH style.css / admin.css / live.css / welcome.css.
   ========================================================= */

/* ---------- Tombol ganti tema ---------- */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  min-width: 36px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.26);
  border-color: rgba(255, 255, 255, 0.5);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

/* Tampilkan ikon sesuai tema: matahari saat gelap (klik -> terang), bulan saat terang */
.theme-toggle .i-sun { display: none; }
.theme-toggle .i-moon { display: block; }
html[data-theme="dark"] .theme-toggle .i-sun { display: block; }
html[data-theme="dark"] .theme-toggle .i-moon { display: none; }

/* di dalam admin-strip: ikut ukuran tautan */
.admin-strip .theme-toggle {
  width: 32px;
  height: 32px;
  min-width: 32px;
  margin-left: 4px;
}

/* halaman tanpa bar atas (login): melayang di pojok */
.theme-toggle.floating {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top, 0px));
  right: calc(14px + env(safe-area-inset-right, 0px));
  z-index: 3000;
  background: rgba(15, 23, 42, 0.55);
  border-color: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(6px);
}

html[data-theme="light"] .theme-toggle.floating {
  background: rgba(255, 255, 255, 0.85);
  border-color: var(--border);
  color: #0f172a;
  box-shadow: var(--shadow-sm);
}

.topbar .theme-toggle { margin-left: 2px; }

@media (max-width: 780px) {
  .topbar .theme-toggle { width: 34px; height: 34px; min-width: 34px; }
}

/* transisi halus saat pindah tema (dimatikan bila pengguna minta minim animasi) */
html.theme-anim,
html.theme-anim body,
html.theme-anim .panel,
html.theme-anim .sidebar,
html.theme-anim .card,
html.theme-anim .stats div {
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

@media (prefers-reduced-motion: reduce) {
  html.theme-anim,
  html.theme-anim * { transition: none !important; }
}

/* =========================================================
   TEMA TERANG — hanya yang perlu disesuaikan
   ========================================================= */

html[data-theme="light"] {
  color-scheme: light;
}

/* login: latar mengikuti tema (aslinya selalu gelap) */
html[data-theme="light"] .login-screen {
  background:
    radial-gradient(1200px 700px at 15% 10%, rgba(13, 122, 61, 0.18), transparent 60%),
    radial-gradient(900px 600px at 85% 90%, rgba(249, 115, 22, 0.14), transparent 55%),
    linear-gradient(150deg, #f4f8f6, #eaf1ee 55%, #e2edf0);
}

html[data-theme="light"] .login-box {
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.16);
  border-color: var(--border);
}

/* =========================================================
   TEMA GELAP
   ========================================================= */

html[data-theme="dark"] {
  color-scheme: dark;

  --brand-light: #12301f;
  --bg: #0b1220;
  --surface: #121c2e;
  --surface-2: #182539;
  --border: #25344b;
  --text: #e6edf6;
  --text-muted: #a3b3c8;
  --text-faint: #7b8da6;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
}

/* ---------- scrollbar ---------- */
html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #34455f; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #4a5f80; }

/* ---------- bar atas ---------- */
html[data-theme="dark"] .topbar {
  background: linear-gradient(120deg, #06241a, #0a3a22 60%, #0c4a2b);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

html[data-theme="dark"] .admin-strip {
  background: linear-gradient(120deg, #050a14, #0a1426 60%, #0b1b2b);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

/* ---------- panel & form ---------- */
html[data-theme="dark"] .panel:hover { border-color: #33466a; }

/* select & button dasar sudah memakai variabel (--surface, --border, --text);
   di sini hanya warna "hardcode" hover/active. :where() menjaga specificity
   serendah aturan dasar agar tombol ber-class (live-pill, menu-toggle, dst.)
   tidak ikut tertimpa. */
:where(html[data-theme="dark"]) select { background-color: var(--surface-2); }

:where(html[data-theme="dark"]) button:hover { border-color: #3b5075; }
:where(html[data-theme="dark"]) button:active { background: #263a58; }

html[data-theme="dark"] select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a3b3c8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
}

html[data-theme="dark"] select option { background: var(--surface); color: var(--text); }

html[data-theme="dark"] select:focus,
html[data-theme="dark"] button:focus-visible {
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.22);
  border-color: #34d399;
}

html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]),
html[data-theme="dark"] textarea {
  background-color: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: var(--text-faint); }

html[data-theme="dark"] input[type="file"] { color: var(--text-muted); }

/* tombol yang punya warna sendiri harus tetap menang atas aturan "button" di atas */
html[data-theme="dark"] .hotspot-date-group button,
html[data-theme="dark"] .map-search-go,
html[data-theme="dark"] button.primary,
html[data-theme="dark"] .login-box button[type="submit"],
html[data-theme="dark"] .up-form button {
  color: #fff;
}
html[data-theme="dark"] .hotspot-date-group button { background-color: var(--brand); border-color: transparent; }
html[data-theme="dark"] .hotspot-date-group button:hover:not(:disabled) { background-color: var(--brand-dark); }
html[data-theme="dark"] .map-search-go { background-color: var(--brand); border-color: transparent; }
html[data-theme="dark"] .map-search-go:hover { background-color: var(--brand-dark); }
html[data-theme="dark"] button.primary,
html[data-theme="dark"] .login-box button[type="submit"],
html[data-theme="dark"] .up-form button { background: linear-gradient(120deg, var(--brand-dark), var(--brand)); border: 0; }

/* rentang waktu */
html[data-theme="dark"] .time-range-btn { background: transparent; border-color: transparent; color: var(--text-muted); }
html[data-theme="dark"] .time-range-btn:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--border); }
html[data-theme="dark"] .time-range-btn.active { background: var(--danger); border-color: var(--danger); color: #fff; }

/* tombol aktif (GPS ikuti / ukur) — di terang berwarna gelap, di gelap dibalik */
html[data-theme="dark"] #gpsFollowButton.active,
html[data-theme="dark"] .measure-button.active {
  background: #e6edf6;
  color: #0b1220;
  border-color: #e6edf6;
}

html[data-theme="dark"] .hotspot-date-live { background: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .hotspot-date-live.is-loading .btn-spinner {
  border-color: rgba(255, 255, 255, 0.25);
  border-top-color: var(--text);
}
html[data-theme="dark"] .hotspot-date-downloads button { background: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .hotspot-date-status.is-error { background: #3a1517; color: #fca5a5; }

/* status / info */
html[data-theme="dark"] .gps-status.success,
html[data-theme="dark"] .kml-status.success,
html[data-theme="dark"] .status-msg.ok { background: #0f2a1c; color: #86efac; border-color: #1c4a2f; }
html[data-theme="dark"] .status-msg.ok { background: none; border: 0; }
html[data-theme="dark"] .gps-status.error,
html[data-theme="dark"] .kml-status.error { background: #34161a; color: #fca5a5; border-color: #5b2329; }
html[data-theme="dark"] .status-msg.err { color: #fca5a5; }

html[data-theme="dark"] .gps-info strong { color: var(--text); }

/* hasil per wilayah */
html[data-theme="dark"] .wilayah-result { color: var(--text); }
html[data-theme="dark"] .wr-chip.high { background: #451a1c; color: #fca5a5; }
html[data-theme="dark"] .wr-chip.nominal { background: #44250f; color: #fdba74; }
html[data-theme="dark"] .wr-chip.low { background: #3d3410; color: #fde047; }
html[data-theme="dark"] .wilayah-result .wr-title[style] { color: #f87171 !important; }

html[data-theme="dark"] .dot { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.07); }
html[data-theme="dark"] .confidence-low { color: #facc15; }

/* ---------- peta & kontrol melayang ---------- */
html[data-theme="dark"] .map-wrap { background: #0f1b2a; }

html[data-theme="dark"] .map-search-box,
html[data-theme="dark"] .basemap-switcher,
html[data-theme="dark"] .basemap-panel,
html[data-theme="dark"] .map-icon-btn {
  background: rgba(18, 28, 46, 0.95);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

html[data-theme="dark"] .map-search-results {
  background: rgba(18, 28, 46, 0.98);
  border-color: rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] #mapSearchInput { background: transparent; border: 0; color: var(--text); }
html[data-theme="dark"] .map-search-clear { background: transparent; color: var(--text-muted); border: 0; }
html[data-theme="dark"] .map-search-clear:hover { background: rgba(255, 255, 255, 0.1); }

html[data-theme="dark"] .ol-zoom button,
html[data-theme="dark"] .ol-control button {
  background-color: rgba(18, 28, 46, 0.95);
  color: var(--text);
  border: 0;
}
html[data-theme="dark"] .ol-zoom button:hover,
html[data-theme="dark"] .ol-control button:hover { background-color: #1f2f48; }

html[data-theme="dark"] .ol-attribution,
html[data-theme="dark"] .ol-attribution ul { background: rgba(18, 28, 46, 0.8); color: var(--text-muted); text-shadow: none; }
html[data-theme="dark"] .ol-attribution a { color: #7dd3fc; }
html[data-theme="dark"] .ol-scale-line { background: rgba(18, 28, 46, 0.8); }
html[data-theme="dark"] .ol-scale-line-inner { color: var(--text); border-color: var(--text-muted); }

/* Basemap OpenStreetMap dibuat gelap lewat filter (layer diberi class basemap-osm
   di js/app.js). Satelit Google tidak diubah. */
html[data-theme="dark"] .basemap-osm {
  filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.92) saturate(0.8);
}

/* ---------- popup ---------- */
html[data-theme="dark"] .popup-copy-btn { color: var(--text); background: var(--surface-2); }
html[data-theme="dark"] .popup-copy-btn:hover { background: #22334e; }
html[data-theme="dark"] .popup-table tr { border-bottom-color: var(--border); }

/* =========================================================
   ADMIN
   ========================================================= */

html[data-theme="dark"] .login-box { background: rgba(18, 28, 46, 0.97); border-color: rgba(255, 255, 255, 0.08); }
html[data-theme="dark"] .login-box h1 { color: var(--text); }
html[data-theme="dark"] .back-public:hover { color: #34d399; }

html[data-theme="dark"] .tag-you { background: #1e2f57; color: #93b4ff; }
html[data-theme="dark"] .notice { background: #0f2a1c; color: #86efac; border-color: #1c4a2f; }
html[data-theme="dark"] .err { background: #34161a; color: #fca5a5; border-color: #5b2329; }
html[data-theme="dark"] .del-btn:hover { background: #3a1517; }
html[data-theme="dark"] th, html[data-theme="dark"] td { border-bottom-color: var(--border); }
html[data-theme="dark"] code { background: var(--surface-2); color: #c7d5e8; padding: 1px 5px; border-radius: 4px; }

/* layer kawasan */
html[data-theme="dark"] .layer-row { box-shadow: none; }
html[data-theme="dark"] .layer-row:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); }
html[data-theme="dark"] .layer-row .lihat { background: #0f2a1c; border-color: #1c4a2f; color: #86efac; }
html[data-theme="dark"] .layer-row .lihat:hover,
html[data-theme="dark"] .layer-row .lihat.active { background: #14391f; border-color: #2f7a4a; color: #bbf7d0; }
html[data-theme="dark"] .layer-row .del { background: #34161a; border-color: #5b2329; color: #fca5a5; }
html[data-theme="dark"] .layer-row .del:hover { background: #46191f; border-color: #8a3a42; }
html[data-theme="dark"] .layer-row .publik { background: #172a52; border-color: #274a8f; color: #93b4ff; }
html[data-theme="dark"] .layer-row .publik:hover { background: #1d3566; }
html[data-theme="dark"] .layer-row .publik.active { background: #2563eb; border-color: #1d4ed8; color: #fff; }

/* chat admin (CSS-nya inline di admin/index.php) */
html[data-theme="dark"] .chat-box { background: var(--surface); color: var(--text); }
html[data-theme="dark"] .chat-msgs { background: #0e1726; }
html[data-theme="dark"] .chat-m { background: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .chat-m.me { background: #14391f; }
html[data-theme="dark"] .chat-m .who { color: var(--text-muted); }
html[data-theme="dark"] .chat-form { background: var(--surface); border-top-color: var(--border); }
html[data-theme="dark"] .chat-form input[type="text"] { background: var(--surface-2); color: var(--text); border-color: #3b5075; }
html[data-theme="dark"] .chat-form button,
html[data-theme="dark"] .chat-head button { background-color: transparent; color: #fff; }
html[data-theme="dark"] .chat-form button { background-color: #095c2d; }
html[data-theme="dark"] .chat-head select { background: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .chat-fab { background-color: #095c2d; color: #fff; }
html[data-theme="dark"] .chat-toast { background: var(--surface); }
html[data-theme="dark"] .chat-toast b { color: #4ade80; }
html[data-theme="dark"] .chat-toast span { color: var(--text); }

/* log aktivitas (inline di admin/activity.php) */
html[data-theme="dark"] .ac-stat b { color: var(--text); }
html[data-theme="dark"] .ac-stat span { color: var(--text-muted); }
html[data-theme="dark"] .ac-stat.warn b { color: #fca5a5; }
html[data-theme="dark"] .ac-btn { background: var(--surface-2); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .ac-btn:hover { background: #22334e; }
html[data-theme="dark"] .ac-table .t-time { color: var(--text-muted); }
html[data-theme="dark"] .ac-table .t-ip { color: var(--text-faint); }
html[data-theme="dark"] .ac-chip.ok { background: #0f2a1c; color: #86efac; }
html[data-theme="dark"] .ac-chip.bad { background: #3a1517; color: #fca5a5; }
html[data-theme="dark"] .ac-chip.warn { background: #3d2f0c; color: #fcd34d; }
html[data-theme="dark"] .ac-chip.info { background: #1e2557; color: #a5b4fc; }
html[data-theme="dark"] .ac-chip.na { background: var(--surface-2); color: var(--text-muted); }
html[data-theme="dark"] .ac-pager a,
html[data-theme="dark"] .ac-pager span { background: var(--surface-2); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .ac-pager span.cur { background: #095c2d; border-color: #095c2d; color: #fff; }
html[data-theme="dark"] .ac-pager span.off { background: var(--surface); color: var(--text-faint); }
html[data-theme="dark"] .ac-empty,
html[data-theme="dark"] .ac-hint { color: var(--text-muted); }

/* urutan menu (inline di admin/menu_order.php) */
html[data-theme="dark"] .mo-list li { background: var(--surface-2); border-color: var(--border); }
html[data-theme="dark"] .mo-num,
html[data-theme="dark"] .mo-hint { color: var(--text-muted); }
html[data-theme="dark"] .mo-btns button { background: var(--surface); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .mo-btns button:hover { background: #22334e; }
html[data-theme="dark"] .mo-dirty { color: #fcd34d; }

/* live drone (admin) */
html[data-theme="dark"] .live-hint { color: var(--text-muted); }
html[data-theme="dark"] .live-btn { background: var(--surface-2); color: #86efac; border-color: #2f7a4a; }
html[data-theme="dark"] .live-btn.primary { background: #095c2d; color: #fff; border-color: #095c2d; }
html[data-theme="dark"] .live-details summary { color: #86efac; }
html[data-theme="dark"] .live-chip.waiting { color: #fcd34d; }
html[data-theme="dark"] .live-chip.ended { color: var(--text-muted); }
html[data-theme="dark"] .live-chip.live { color: #f87171; }

/* =========================================================
   WELCOME (disclaimer awal halaman publik)
   ========================================================= */

html[data-theme="dark"] .welcome-overlay { background: rgba(2, 8, 6, 0.8); }
html[data-theme="dark"] .welcome-card { background: var(--surface); color: var(--text); }
html[data-theme="dark"] .welcome-card h2 { color: #4ade80; }
html[data-theme="dark"] .welcome-disclaimer { background: #2b2210; border-color: #5a4614; border-left-color: #d97706; }
html[data-theme="dark"] .welcome-disclaimer h3 { color: #fcd34d; }
html[data-theme="dark"] .welcome-btn { background: #0d7a3d; color: #fff; }
html[data-theme="dark"] .welcome-btn:hover { background: #0f8c46; }

/* ---------- menu scroll admin ---------- */
html[data-theme="dark"] .scroll-menu .sm-bar {
  background: rgba(18, 28, 46, 0.96);
  border-color: var(--border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
}
html[data-theme="dark"] .scroll-menu .sm-btn { color: var(--text); background-color: transparent; }
html[data-theme="dark"] .scroll-menu .sm-btn:hover:not(:disabled) { background-color: #22334e; }
html[data-theme="dark"] .scroll-menu .sm-btn.active { background-color: var(--brand); color: #fff; }
html[data-theme="dark"] .scroll-menu .sm-list { background: var(--surface); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6); }
html[data-theme="dark"] .scroll-menu .sm-item { color: var(--text); background-color: transparent; }
html[data-theme="dark"] .scroll-menu .sm-item:hover { background-color: var(--surface-2); }
html[data-theme="dark"] .scroll-menu .sm-item.current { background-color: #14391f; color: #86efac; }

/* filter log aktivitas: select punya background shorthand sendiri (inline di activity.php) */
html[data-theme="dark"] .ac-filter select {
  background-image: none;
  background-color: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.basemap-osm { pointer-events: auto; }
