:root {
  --hijau: #0f766e;
  --hijau-tua: #115e59;
  --hijau-muda: #ccfbf1;
  --emas: #b45309;
  --emas-muda: #fef3c7;
  --merah: #b91c1c;
  --merah-muda: #fee2e2;
  --biru: #1d4ed8;
  --biru-muda: #dbeafe;
  --teks: #1f2937;
  --abu: #6b7280;
  --garis: #e5e7eb;
  --latar: #f6f7f5;
  --putih: #fff;
  --radius: 12px;
  --bayang: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--teks); background: var(--latar); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--hijau); text-decoration: none; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--abu); }
.small { font-size: .85rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--hijau-tua); color: #e6fffa; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #fff; }
.brand .logo-ph { width: 40px; height: 40px; border-radius: 50%; background: #14b8a6; display: grid; place-items: center; font-weight: 700; color: #fff; }
.brand b { display: block; font-size: .98rem; line-height: 1.2; }
.brand span { font-size: .75rem; opacity: .75; }
.nav a {
  display: flex; align-items: center; gap: 10px; color: #d1fae5; padding: 9px 12px; border-radius: 9px; margin-bottom: 2px; font-size: .95rem;
}
.nav a:hover { background: rgba(255,255,255,.08); }
.nav a.active { background: #fff; color: var(--hijau-tua); font-weight: 600; }
.nav .ico { width: 20px; text-align: center; }
.sidebar .user { border-top: 1px solid rgba(255,255,255,.15); margin-top: 16px; padding: 14px 10px 0; font-size: .85rem; }
.main { flex: 1; min-width: 0; padding: 22px 26px 90px; max-width: 1200px; }
.topbar { display: none; }
.bottomnav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 14px 12px 88px; }
  .topbar {
    display: flex; align-items: center; gap: 10px; background: var(--hijau-tua); color: #fff; padding: 10px 14px;
    position: sticky; top: 0; z-index: 20;
  }
  .topbar img, .topbar .logo-ph { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #fff; }
  .topbar .logo-ph { background: #14b8a6; display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
  .topbar b { font-size: .98rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar button { background: transparent; border: 0; color: #fff; font-size: 1.3rem; }
  .app { display: block; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--garis);
    z-index: 30; padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a { flex: 1; text-align: center; padding: 7px 2px 6px; font-size: .68rem; color: var(--abu); }
  .bottomnav a .ico { display: block; font-size: 1.25rem; line-height: 1.3; }
  .bottomnav a.active { color: var(--hijau); font-weight: 600; }
}

/* Komponen */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; }
.card { background: var(--putih); border-radius: var(--radius); box-shadow: var(--bayang); padding: 16px; margin-bottom: 14px; }
.card h2 { margin-bottom: 10px; }
.grid { display: grid; gap: 12px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (max-width: 860px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid-3, .grid-2 { grid-template-columns: 1fr; } }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--bayang); padding: 14px 16px; }
.stat .label { font-size: .8rem; color: var(--abu); }
.stat .value { font-size: 1.5rem; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: .8rem; color: var(--abu); }
.stat.hijau .value { color: var(--hijau); }
.stat.emas .value { color: var(--emas); }
.stat.merah .value { color: var(--merah); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--garis); background: #fff;
  color: var(--teks); padding: 8px 14px; border-radius: 9px; font-size: .92rem; cursor: pointer; font-weight: 500; font-family: inherit;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--hijau); border-color: var(--hijau); color: #fff; }
.btn.primary:hover { background: var(--hijau-tua); }
.btn.wa { background: #16a34a; border-color: #16a34a; color: #fff; }
.btn.danger { color: var(--merah); border-color: #fecaca; }
.btn.sm { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; color: #374151; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 9px; font-size: 16px; font-family: inherit; background: #fff; color: var(--teks);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #99f6e4; border-color: var(--hijau); }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.field .hint { font-size: .78rem; color: var(--abu); margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { width: auto; min-width: 140px; flex: 1 1 140px; max-width: 260px; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--garis); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--abu); font-weight: 600; background: #fafafa; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f0fdfa; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: #f3f4f6; color: #374151; white-space: nowrap; }
.badge.hijau, .badge.Lancar, .badge.H { background: var(--hijau-muda); color: var(--hijau-tua); }
.badge.emas, .badge.Cukup, .badge.I { background: var(--emas-muda); color: var(--emas); }
.badge.merah, .badge.Ulang, .badge.A { background: var(--merah-muda); color: var(--merah); }
.badge.biru, .badge.S { background: var(--biru-muda); color: var(--biru); }

.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--garis); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex-shrink: 0; font-size: .9rem; }
.avatar.L { background: #0ea5e9; } .avatar.P { background: #ec4899; } .avatar.X { background: #94a3b8; }

.seg { display: inline-flex; border: 1px solid #d1d5db; border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 11px; font-size: .88rem; cursor: pointer; font-weight: 600; color: var(--abu); font-family: inherit; }
.seg button + button { border-left: 1px solid #d1d5db; }
.seg button.on.H, .seg button.on.Lancar { background: var(--hijau); color: #fff; }
.seg button.on.I, .seg button.on.Cukup { background: #d97706; color: #fff; }
.seg button.on.S { background: var(--biru); color: #fff; }
.seg button.on.A, .seg button.on.Ulang { background: var(--merah); color: #fff; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--garis); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--abu); border-bottom: 2px solid transparent; font-weight: 600; font-size: .92rem; white-space: nowrap; }
.tabs a.active { color: var(--hijau); border-color: var(--hijau); }

.bar { height: 8px; background: #f3f4f6; border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--hijau); border-radius: 99px; }

/* SPP grid */
.spp-grid td.m { text-align: center; padding: 6px 4px; min-width: 44px; }
.spp-cell { display: inline-block; width: 34px; height: 30px; line-height: 30px; border-radius: 7px; font-size: .8rem; cursor: pointer; font-weight: 700; }
.spp-cell.lunas { background: var(--hijau-muda); color: var(--hijau-tua); }
.spp-cell.belum { background: #f3f4f6; color: #9ca3af; }
.spp-cell.telat { background: var(--merah-muda); color: var(--merah); }
.spp-cell.gratis { background: transparent; color: #cbd5e1; cursor: default; }
.spp-mobile { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 8px; }
.spp-mobile .spp-cell { width: auto; height: 38px; line-height: 38px; text-align: center; font-size: .8rem; }
@media (max-width: 600px) {
  .seg button { padding: 10px 14px; font-size: .95rem; }
  .list-item { padding: 13px 4px; }
  .btn { padding: 10px 14px; }
  .btn.sm { padding: 7px 11px; }
  .chip { padding: 8px 13px; }
  .filters > * { max-width: none; }
  .page-head h1 { font-size: 1.2rem; }
  .kv { grid-template-columns: 110px 1fr; }
}
.spp-grid th.sticky, .spp-grid td.sticky { position: sticky; left: 0; background: #fff; z-index: 1; min-width: 150px; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--garis); }
.modal-head h2 { margin: 0; }
.modal-head button { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--abu); line-height: 1; }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--garis); display: flex; gap: 8px; justify-content: flex-end; }
@media (max-width: 600px) {
  .modal-back { padding: 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; overflow-y: auto; }
  .modal-head { position: sticky; top: 0; background: #fff; z-index: 2; border-radius: 16px 16px 0 0; }
  .modal-foot { position: sticky; bottom: 0; background: #fff; z-index: 2; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
}

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 99px; z-index: 200; font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }
.toast.err { background: var(--merah); }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #0f766e 0%, #115e59 50%, #134e4a 100%); }
.auth-card { background: #fff; border-radius: 16px; padding: 28px 24px; width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-card .brand-big { text-align: center; margin-bottom: 18px; }
.auth-card .brand-big img, .auth-card .brand-big .logo-ph { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 8px; object-fit: cover; }
.auth-card .brand-big .logo-ph { background: var(--hijau); color: #fff; display: grid; place-items: center; font-size: 1.4rem; font-weight: 700; }

.empty { text-align: center; padding: 30px 10px; color: var(--abu); }
.loading { text-align: center; padding: 40px; color: var(--abu); }
.alert { padding: 10px 14px; border-radius: 10px; background: var(--emas-muda); color: #78350f; font-size: .9rem; margin-bottom: 12px; }
.alert.info { background: #ecfeff; color: #155e75; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; font-size: .92rem; }
.kv dt { color: var(--abu); }
.kv dd { margin: 0; font-weight: 500; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid #d1d5db; background: #fff; font-size: .85rem; cursor: pointer; font-family: inherit; }
.chip.on { background: var(--hijau); border-color: var(--hijau); color: #fff; }

/* Cetak */
#print { display: none; }
.kop { display: flex; align-items: center; gap: 14px; border-bottom: 3px double #111; padding-bottom: 10px; margin-bottom: 14px; }
.kop img { width: 64px; height: 64px; object-fit: cover; border-radius: 50%; }
.kop h1 { margin: 0; font-size: 1.3rem; }
.kop p { margin: 0; font-size: .85rem; }
.ttd { display: flex; justify-content: flex-end; margin-top: 30px; }
.ttd > div { text-align: center; min-width: 200px; }
.ttd .space { height: 60px; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 12px; }
  body.printing .app, body.printing .modal-back, body.printing .toast { display: none !important; }
  body.printing #print { display: block !important; }
  .no-print, .sidebar, .topbar, .bottomnav { display: none !important; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  th { background: #f3f4f6 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
