/* ==========================================================================
   Stylesheet.html - Sistem Informasi Administrasi Dana BOK Puskesmas
   Tema terang/gelap via class .dark pada <html>
   ========================================================================== */
:root {
  --bg: #eef3f2;
  --surface: #ffffff;
  --surface-2: #f6f9f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dde5e8;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #d9f6f1;
  --on-primary: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --ring: rgba(15, 118, 110, .35);
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 6px 18px rgba(15, 23, 42, .05);
}
.dark {
  --bg: #0b1220;
  --surface: #111a2c;
  --surface-2: #0e1626;
  --text: #e5e9f0;
  --muted: #93a1b8;
  --border: #243049;
  --primary: #2dd4bf;
  --primary-hover: #5eead4;
  --primary-soft: rgba(45, 212, 191, .13);
  --on-primary: #04201d;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .15);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .14);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, .14);
  --ring: rgba(45, 212, 191, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
}
html { color-scheme: light; }
html.dark { color-scheme: dark; }
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------ Layout ---------------------------------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.app-header-inner {
  max-width: 1200px; margin: 0 auto; padding: .65rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
}
.brand { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.brand-icon {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  background: var(--primary); color: var(--on-primary);
  display: flex; align-items: center; justify-content: center;
}
.brand-title { font-weight: 700; font-size: .95rem; line-height: 1.15; }
.brand-sub { font-size: .72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 52vw; }
.app-main { max-width: 1200px; margin: 0 auto; padding: 1rem 1rem 6rem; }
@media (min-width: 768px) { .app-main { padding-bottom: 2rem; } }

.top-nav { display: none; max-width: 1200px; margin: 0 auto; padding: .5rem 1rem 0; gap: .35rem; }
@media (min-width: 768px) { .top-nav { display: flex; } .bottom-nav { display: none !important; } }
.nav-btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .55rem .9rem; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--muted); font-weight: 600; font-size: .85rem; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--primary-soft); color: var(--primary); }
.nav-btn.active { background: var(--primary); color: var(--on-primary); }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .08);
}
.bottom-nav .nav-btn {
  flex-direction: column; gap: 2px; border-radius: 0; font-size: .64rem;
  padding: .5rem .1rem; justify-content: center;
}
.bottom-nav .nav-btn.active { background: var(--primary-soft); color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn .22s ease; }
.subpanel { display: none; }
.subpanel.active { display: block; animation: fadeIn .22s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ------------------------------ Komponen -------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 1rem; box-shadow: var(--shadow);
}
.card-title { font-weight: 700; font-size: 1rem; display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.page-title { font-size: 1.15rem; font-weight: 800; }
.label { display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
.input {
  width: 100%; padding: .55rem .75rem; font-size: .9rem; font-family: inherit;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.input:disabled, .input[readonly] { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
textarea.input { resize: vertical; min-height: 72px; }
.money { text-align: right; font-variant-numeric: tabular-nums; }
.hint { font-size: .72rem; color: var(--muted); margin-top: .2rem; }
.terbilang { font-size: .78rem; font-style: italic; color: var(--primary); margin-top: .25rem; min-height: 1.1em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem .95rem; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: .86rem; font-family: inherit; cursor: pointer;
  transition: background .15s, transform .05s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-sm { padding: .3rem .55rem; font-size: .75rem; border-radius: 8px; }
.btn svg, .nav-btn svg { width: 16px; height: 16px; flex: none; }

.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: 2px 9px; border-radius: 999px; font-size: .68rem; font-weight: 700; white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-info { background: var(--primary-soft); color: var(--primary); }

.banner { border-radius: 12px; padding: .65rem .85rem; font-size: .83rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner-info { background: var(--primary-soft); color: var(--primary); }

.chip-group { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { position: relative; display: inline-block; }
.chip input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; margin: 0; }
.chip span {
  display: inline-block; padding: .45rem .95rem; border: 1px solid var(--border);
  border-radius: 999px; font-size: .84rem; font-weight: 600; background: var(--surface); color: var(--text);
}
.chip input:checked + span { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--ring); }

.subtab-btn, .doc-tab {
  padding: .45rem .9rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-weight: 600; font-size: .82rem; cursor: pointer; white-space: nowrap;
}
.subtab-btn:hover, .doc-tab:hover { color: var(--primary); border-color: var(--primary); }
.subtab-btn.active, .doc-tab.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-x::-webkit-scrollbar { height: 6px; }
.scroll-x::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

/* ------------------------------ Statistik ------------------------------- */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat .k { font-size: .72rem; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: .35rem; }
.stat .v { font-size: 1.2rem; font-weight: 800; margin-top: .2rem; font-variant-numeric: tabular-nums; word-break: break-word; }
.stat .s { font-size: .72rem; color: var(--muted); margin-top: .1rem; }
.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .5s ease; }
.progress.warn > div { background: #d97706; }
.progress.danger > div { background: var(--danger); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 14px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar { width: 100%; max-width: 34px; background: var(--primary); border-radius: 6px 6px 0 0; min-height: 2px; opacity: .9; transition: height .5s ease; }
.bar-val { font-size: 9px; color: var(--muted); margin-bottom: 2px; white-space: nowrap; }
.bar-lbl { font-size: 10px; color: var(--muted); margin-top: 4px; }
.mini-row { margin-bottom: .75rem; }
.mini-row .top { display: flex; justify-content: space-between; gap: .5rem; font-size: .8rem; margin-bottom: .25rem; }
.mini-row .top b { font-variant-numeric: tabular-nums; }

/* ------------------------------ Kontrol pagu ---------------------------- */
.kontrol { border: 1px dashed var(--primary); background: var(--primary-soft); border-radius: 12px; padding: .85rem; }
.kontrol.over { border-color: var(--danger); background: var(--danger-soft); }
.kontrol .row { display: flex; justify-content: space-between; gap: .5rem; font-size: .85rem; padding: 2px 0; }
.kontrol .row b { font-variant-numeric: tabular-nums; }
.kontrol .row.total { border-top: 1px solid var(--border); margin-top: .35rem; padding-top: .4rem; font-size: .92rem; }

/* ------------------------------ Tabel ----------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: .8rem; }
.tbl th {
  background: var(--surface-2); color: var(--muted); text-align: left; font-size: .68rem;
  text-transform: uppercase; letter-spacing: .03em; padding: .55rem .65rem; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.tbl td { padding: .55rem .65rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .sub { color: var(--muted); font-size: .72rem; }
.empty-state { text-align: center; padding: 1.75rem 1rem; color: var(--muted); font-size: .85rem; }

/* ------------------------------ Modal & Loader -------------------------- */
.modal-backdrop {
  display: none; position: fixed; inset: 0; z-index: 90; padding: 1rem;
  background: rgba(2, 6, 23, .55); align-items: center; justify-content: center;
}
.modal-backdrop.show { display: flex; }
.modal { width: min(680px, 100%); max-height: 92vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 1.1rem; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); }
.loader {
  display: none; position: fixed; inset: 0; z-index: 100; flex-direction: column;
  align-items: center; justify-content: center; gap: .75rem;
  background: rgba(2, 6, 23, .5); color: #fff; font-weight: 600;
}
.loader.show { display: flex; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .25); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; height: 1.2rem; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ------------------------------ Unggah Logo ----------------------------- */
.logo-box { display: flex; align-items: center; justify-content: center; height: 110px; border: 1px dashed var(--border); border-radius: 12px; background: #ffffff; color: #64748b; font-size: .8rem; }
.logo-box img { max-height: 90px; max-width: 90%; }

/* ------------------------------ Pratinjau Dokumen ----------------------- */
.doc-scroll { overflow-x: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.doc {
  background: #fff; color: #000; margin: 0 auto;
  font-family: 'Times New Roman', Times, serif; font-size: 11pt; line-height: 1.35;
  width: 215mm; padding: 12mm 15mm; box-sizing: border-box;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .25);
}
.doc.landscape { width: 330mm; }
.doc * { color: #000; }
.doc .kop { text-align: center; border-bottom: 3px double #000; padding-bottom: 6px; margin-bottom: 12px; }
.doc .kop-tbl { width: 100%; border-collapse: collapse; }
.doc .kop-tbl td { border: none; padding: 0; vertical-align: middle; }
.doc .kop-logo { width: 24mm; text-align: center; }
.doc .kop-logo img { max-width: 22mm; max-height: 22mm; display: block; margin: 0 auto; }
.doc .kop-text { text-align: center; }
.doc .kop.thick { border-bottom: 4px solid #000; }
.doc .kop.plain { border-bottom: none; margin-bottom: 8px; }
.doc .kop.small .k1 { font-size: 10pt; }
.doc .kop .k4 { font-size: 8.5pt; font-weight: 700; }
.doc .kop .kn { font-size: 10.5pt; }
.doc .kop-fmt { text-align: right; font-weight: 700; vertical-align: top; }
.doc .npd-info { width: 100%; border-collapse: collapse; margin-bottom: 6px; font-size: 10pt; }
.doc .npd-info td { border: none; padding: 1px 4px; vertical-align: top; }
.doc .npd-info td.no { width: 22px; }
.doc .npd-info td.k { width: 230px; }
.doc .npd-info td.c { width: 12px; }
.doc .gap { display: inline-block; width: 60px; }
.doc .b { font-weight: 700; }
.doc .i { font-style: italic; }
.doc .doc-table.mid { font-size: 9.5pt; }
.doc .doc-table .nomor td { background: #e9e9e9; text-align: center; font-size: 7.5pt; }
.doc .doc-table.nb th, .doc .doc-table.nb td { border: none; }
.doc .doc-table.nb th { text-decoration: underline; background: none; }
.doc .doc-table .tot td { border-top: 2px solid #000; }
.doc .doc-table .neg { color: #c00000; background: #ffd6d6; }
.doc .sp-outer { width: 100%; border-collapse: collapse; }
.doc .sp-outer td { border: none; vertical-align: top; padding: 0; }
.doc .sp-left { width: 62%; }
.doc .sp-right { padding-left: 12px; }
.doc .sp-tbl { width: 100%; border-collapse: collapse; margin: 4px 0 8px; }
.doc .sp-tbl td { border: none; padding: 3px 6px; vertical-align: top; }
.doc .sp-tbl tr.shade td { background: #d9d9d9; font-weight: 700; }
.doc .sp-tbl td.amt { text-align: right; white-space: nowrap; }
.doc .sp-tbl td.rp { width: 46px; white-space: nowrap; }
.doc .ttd-wrap.right { justify-content: flex-end; }
.doc .kop .k1 { font-size: 12pt; font-weight: 700; text-transform: uppercase; }
.doc .kop .k2 { font-size: 14pt; font-weight: 700; text-transform: uppercase; }
.doc .kop .k3 { font-size: 9.5pt; }
.doc .doc-title { text-align: center; font-weight: 700; text-transform: uppercase; text-decoration: underline; margin: 8px 0 2px; font-size: 12pt; }
.doc .doc-subtitle { text-align: center; margin-bottom: 10px; }
.doc p { margin: 0 0 6px; text-align: justify; }
.doc .doc-table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.doc .doc-table th, .doc .doc-table td { border: 1px solid #000; padding: 3px 5px; vertical-align: top; }
.doc .doc-table th { text-align: center; font-weight: 700; background: #e9e9e9; vertical-align: middle; }
.doc .doc-table.small { font-size: 8pt; }
.doc .doc-table.small th, .doc .doc-table.small td { padding: 2px 3px; }
.doc .doc-table .num { text-align: right; white-space: nowrap; }
.doc .doc-table .ctr { text-align: center; }
.doc .doc-table .b { font-weight: 700; }
.doc .doc-table .lv1 td { background: #d9d9d9; font-weight: 700; }
.doc .doc-table .lv2 td { background: #e6e6e6; font-weight: 700; }
.doc .doc-table .lv3 td { background: #f0f0f0; font-weight: 700; }
.doc .doc-table .lv4 td { background: #f7f7f7; font-weight: 600; }
.doc .doc-table .grand td { background: #cfcfcf; font-weight: 700; }
.doc .kv { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.doc .kv td { border: none; padding: 1px 4px; vertical-align: top; }
.doc .kv td.k { width: 190px; white-space: nowrap; }
.doc .kv td.c { width: 12px; }
.doc .ttd-wrap { display: flex; justify-content: space-between; margin-top: 18px; break-inside: avoid; page-break-inside: avoid; }
.doc .ttd { width: 46%; text-align: center; }
.doc .ttd .space { height: 64px; }
.doc .ttd .nama { font-weight: 700; text-decoration: underline; }
.doc .terbilang-box { border: 1px solid #000; padding: 4px 8px; font-style: italic; margin: 6px 0; font-weight: 700; }
.doc .page-break { break-after: page; page-break-after: always; }
.doc tr { break-inside: avoid; page-break-inside: avoid; }
.doc thead { display: table-header-group; }

/* ------------------------------ Cetak (F4 / Folio) ---------------------- */
@page { size: 215mm 330mm; margin: 12mm 15mm; }
@page landscape-folio { size: 330mm 215mm; margin: 12mm 15mm; }
@media print {
  html, body { background: #fff !important; color: #000 !important; }
  .no-print, .app-header, .top-nav, .bottom-nav, .loader, .modal-backdrop { display: none !important; }
  .app-main { max-width: none; padding: 0; margin: 0; }
  .tab-panel { display: none !important; }
  #tab-cetak { display: block !important; }
  .card { box-shadow: none; border: none; padding: 0; background: none; }
  .doc-scroll { overflow: visible; background: none; border: none; padding: 0; border-radius: 0; }
  .doc { width: auto; padding: 0; box-shadow: none; margin: 0; }
  .doc.landscape { page: landscape-folio; width: auto; }
  .doc .doc-table .nomor td, .doc .sp-tbl tr.shade td, .doc .doc-table .neg,
  .doc .doc-table th, .doc .doc-table .lv1 td, .doc .doc-table .lv2 td, .doc .doc-table .lv3 td,
  .doc .doc-table .lv4 td, .doc .doc-table .grand td {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
@media (max-width: 480px) {
  .stat .v { font-size: 1.02rem; }
  .card { padding: .85rem; }
}

/* ------------------------------ Login ----------------------------------- */
.login-backdrop { background: rgba(2, 6, 23, .94); }
.login-box { width: min(400px, 100%); }
.login-err { color: var(--danger); font-size: .8rem; min-height: 1.1em; margin-top: .5rem; }
