/* ════════════════════════════════════════════════════════════════
   Shared theme overrides — light/dark manual switch
   Menang atas @media (prefers-color-scheme) yang ditulis per-page.
   Variabel mengikuti konvensi yang sudah dipakai semua halaman:
   --bg, --surface, --surface2, --border, --text, --text2, --text3, --shadow
   ════════════════════════════════════════════════════════════════ */

html[data-theme="light"] {
  --bg:       #f8fafc;
  --surface:  #ffffff;
  --surface2: #f1f5f9;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --text2:    #334155;
  --text3:    #64748b;
  --shadow:   0 8px 24px -8px rgba(15, 23, 42, 0.12);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg:       #020617;
  --surface:  #0f172a;
  --surface2: #1e293b;
  --border:   #1e293b;
  --text:     #f1f5f9;
  --text2:    #cbd5e1;
  --text3:    #94a3b8;
  --shadow:   0 8px 24px -8px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* Image & embed adjustments di dark mode (kalau ada brand logo putih dll.) */
html[data-theme="dark"] img.theme-invert {
  filter: invert(1) hue-rotate(180deg);
}

/* Form inputs di dark: pastikan background & teks terbaca walau page tidak meng-style */
html[data-theme="dark"] input:not([type="button"]):not([type="submit"]):not([type="file"]),
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  background-color: var(--surface2);
  color: var(--text);
  border-color: var(--border);
  color-scheme: dark;
}

/* Tombol theme-toggle generik (boleh dipakai page yang belum punya) */
.theme-toggle {
  width: 36px; height: 36px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 16px; cursor: pointer; transition: all .15s;
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--surface2); }

/* Floating toggle untuk page tanpa header (mis. login screen) */
.theme-toggle.floating {
  position: fixed; top: 14px; right: 14px; z-index: 199;
  box-shadow: var(--shadow);
}


/* ==================================================================
   [BL] LAPISAN TAMBAHAN
   1. Token gelap lengkap - HANYA untuk halaman ber-atribut
      data-theme-auto, yaitu halaman yang belum punya CSS gelap sendiri.
      Halaman dengan tema gelap garapan sendiri (admin, analis, pemutus,
      pipeline, dsb) tidak tersentuh blok ini.
   2. Optimasi tampilan mobile - berlaku untuk semua halaman.
   ================================================================== */

html[data-theme="dark"][data-theme-auto] {
  --canvas:        #020617;
  --muted:         #94a3b8;
  --primary:       #4f8ef7;
  --primary-dark:  #3b76d8;
  --primary-light: #1c2b45;
  --accent:        #4f8ef7;
  --accent-light:  #1c2b45;
  --accent-soft:   #6fa4f9;
  --blue:          #4f8ef7;
  --blue-soft:     #16283f;
  --success:       #34c98a;
  --green:         #34c98a;
  --green-soft:    #122c22;
  --danger:        #f2635a;
  --red:           #f2635a;
  --red-soft:      #331b1a;
  --warning:       #e0a33c;
  --gold:          #d9a441;
  --gold-soft:     #2e2513;
  --sidebar-bg:    #0b1220;
  --shadow-md:     0 10px 28px -10px rgba(0, 0, 0, .65);
  --shadow-lg:     0 20px 48px -16px rgba(0, 0, 0, .75);
}

html[data-theme="dark"][data-theme-auto] body { background: var(--bg); color: var(--text); }
html[data-theme="dark"][data-theme-auto] .card,
html[data-theme="dark"][data-theme-auto] .panel,
html[data-theme="dark"][data-theme-auto] .box,
html[data-theme="dark"][data-theme-auto] .modal-content,
html[data-theme="dark"][data-theme-auto] .modal-card {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
html[data-theme="dark"][data-theme-auto] thead th { background: var(--surface2); color: var(--text2); }
html[data-theme="dark"][data-theme-auto] tbody tr:nth-child(even) { background: rgba(255, 255, 255, .02); }
html[data-theme="dark"][data-theme-auto] hr { border-color: var(--border); }
html[data-theme="dark"][data-theme-auto] ::placeholder { color: var(--text3); }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; }

  /* 16px mencegah iOS auto-zoom saat field difokuskan */
  input, select, textarea { font-size: 16px !important; }

  button, .btn, .nav-item, .tab, a.btn { min-height: 40px; }

  .table-scroll, .table-wrap, .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .form-grid, .grid-equal, .summary-cards,
  .kpi-grid, .stats-grid, .cards-grid { grid-template-columns: 1fr !important; }

  .tagihan-kpi-grid { grid-template-columns: repeat(2, 1fr) !important; }

  .modal-content, .modal-card {
    max-height: 92vh;
    overflow-y: auto;
  }

  .actions, .card-header { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .tagihan-kpi-grid { grid-template-columns: 1fr !important; }
  h1 { font-size: 20px; }
  h2 { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle { transition: none; }
}

/* Cetak selalu terang, dan tombol tema disembunyikan */
@media print {
  .theme-toggle { display: none !important; }
  html[data-theme="dark"] {
    --bg: #ffffff; --surface: #ffffff; --surface2: #f1f5f9;
    --border: #e2e8f0; --text: #0f172a; --text2: #334155; --text3: #64748b;
  }
}
