:root {
  --bg: #f3f5f2;
  --card: #ffffff;
  --ink: #1d2a22;
  --muted: #66736b;
  --line: #dde3dd;
  --brand: #1f7a3d;
  --brand-dark: #165c2d;
  --brand-soft: #e7f3eb;
  --accent: #e8841a;
  --danger: #c0392b;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 14px; color: var(--ink); background: var(--bg); }
#app { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar { width: 240px; flex: none; background: #143d23; color: #dfeee4; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-title { font-size: 18px; font-weight: 700; color: #fff; }
.brand-sub { font-size: 12px; opacity: .7; margin-top: 2px; }
nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav button { text-align: left; background: none; border: 0; color: inherit; padding: 9px 12px; border-radius: 8px; font: inherit; cursor: pointer; }
nav button:hover { background: rgba(255,255,255,.08); }
nav button.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; padding: 14px 12px 4px; }
.sidebar-foot { font-size: 11px; opacity: .6; padding: 14px 18px; line-height: 1.5; }

/* ---------- main ---------- */
main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.view { display: none; }
.view.active { display: block; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; color: var(--brand-dark); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > * { min-width: 0; }
.grid2 > .card, .grid2 > div > .card:last-child { margin-bottom: 16px; }
.row { display: flex; gap: 12px; align-items: flex-end; }
.row > * { flex: 1; min-width: 0; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
label { display: block; font-size: 12px; font-weight: 600; color: #44524a; margin-bottom: 10px; }
input, select { width: 100%; font: inherit; font-weight: 400; color: var(--ink); padding: 7px 9px; border: 1px solid #c9d2cb; border-radius: 7px; background: #fff; margin-top: 4px; }
input:focus, select:focus { outline: 2px solid rgba(31,122,61,.25); border-color: var(--brand); }
input[type=file] { border: 0; padding-left: 0; }
code { background: var(--brand-soft); padding: 1px 5px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid #c9d2cb; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; margin: 0; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #e6b8b2; }
.btn.tiny { padding: 3px 8px; font-size: 12px; }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 15px; padding: 4px 6px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: #eef1ee; color: var(--ink); }
.icon-btn.del:hover { color: var(--danger); }

.info { background: var(--brand-soft); color: var(--brand-dark); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.nomor-preview { background: #f7f8f6; border: 1px dashed #c9d2cb; border-radius: 8px; padding: 8px 12px; font-size: 12px; line-height: 1.7; font-family: Consolas, monospace; overflow-wrap: anywhere; }
input.auto { background: #f2f5f2; color: var(--brand-dark); font-weight: 700; cursor: default; }
.ok { color: var(--brand); font-weight: 600; }
.nomor-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.nomor-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.nomor-card h3 { margin: 0 0 8px; font-size: 14px; }
.nomor-card input { font-size: 18px; font-weight: 700; max-width: 140px; }
.nomor-card .next { margin-top: 10px; font-size: 12px; color: var(--muted); }
.nomor-card .next code { display: block; margin-top: 4px; font-size: 12px; overflow-wrap: anywhere; }
@media (max-width: 1000px) { .nomor-grid { grid-template-columns: 1fr; } }
.total-box { margin-top: 4px; text-align: right; font-size: 15px; }
.total-box b { color: var(--brand-dark); font-size: 18px; }

/* peserta */
.peserta-list { border: 1px solid var(--line); border-radius: 8px; height: 262px; overflow: auto; margin: 8px 0 12px; }
.peserta-item { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid #eef1ee; cursor: pointer; font-weight: 400; margin: 0; }
.peserta-item:hover { background: #f6f9f6; }
.peserta-item input { width: auto; margin: 0; }
.peserta-item.on { background: var(--brand-soft); }
.peserta-item .nm { font-weight: 600; font-size: 13px; color: var(--ink); }
.peserta-item .jb { font-size: 11px; color: var(--muted); }
.peserta-item .gol { margin-left: auto; font-size: 11px; background: #eef1ee; padding: 2px 7px; border-radius: 10px; white-space: nowrap; color: var(--ink); }

/* biaya table */
.biaya-wrap { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; }
table.biaya { width: 100%; border-collapse: collapse; font-size: 12px; }
table.biaya th { position: sticky; top: 0; background: #f2f5f2; text-align: right; padding: 6px; font-weight: 600; z-index: 1; }
table.biaya th:first-child { text-align: left; }
table.biaya td { padding: 2px 6px; border-top: 1px solid #f0f2f0; }
table.biaya td.grp { font-weight: 700; background: #fafbfa; padding: 6px; }
table.biaya input { margin: 0; padding: 3px 5px; text-align: right; font-size: 12px; width: 100%; min-width: 50px; }
table.biaya td.tot { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.biaya tr.has td:first-child { color: var(--brand-dark); font-weight: 600; }

/* data tables */
.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 12px; color: var(--muted); padding: 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.data td { padding: 6px 8px; border-bottom: 1px solid #eef1ee; vertical-align: middle; }
table.data.edit td { padding: 3px 6px; }
table.data.edit input, table.data.edit select { margin: 0; padding: 5px 7px; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.act { white-space: nowrap; text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }

/* preview */
.preview-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.preview-head h2 { margin: 0; }
.tabs { display: flex; background: #eef1ee; border-radius: 8px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; font: inherit; font-size: 13px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.preview-stage { background: #6f7a73; border-radius: 8px; padding: 20px; overflow: auto; }
#previewBox { margin: 0 auto; width: max-content; }
#previewBox .doc-page { box-shadow: 0 4px 18px rgba(0,0,0,.3); }

.logo-box { height: 110px; border: 1px dashed #c9d2cb; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.logo-box img { max-height: 90px; max-width: 80%; }
.logo-box img:not([src]), .logo-box img[src=""] { display: none; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(80px); background: #143d23; color: #fff; padding: 10px 18px; border-radius: 8px; transition: transform .25s; z-index: 50; }
#toast.show { transform: translateX(-50%) translateY(0); }

/* ================= DOCUMENTS ================= */
.doc-page { background: #fff; color: #000; margin: 0 auto 20px; position: relative; }
.doc-page.portrait { width: 210mm; min-height: 297mm; padding: 14mm 22mm 12mm 25mm; font-family: "Times New Roman", Times, serif; font-size: 12pt; }
.doc-page.landscape { width: 297mm; min-height: 210mm; padding: 7mm 10mm; font-family: Arial, Helvetica, sans-serif; font-size: 8pt; }

/* memo/sppd */
.memo .logo { position: absolute; top: 8mm; right: 22mm; height: 20mm; }
.memo .kop { font-weight: bold; line-height: 1.3; margin-top: 8mm; }
.memo .judul { text-align: center; font-weight: bold; font-size: 13.5pt; margin: 10mm 0 7mm; line-height: 1.3; }
.memo .judul u { text-underline-offset: 2px; }
.memo table.kv { border-collapse: collapse; width: 100%; }
.memo table.kv td { padding: 2.5px 0; vertical-align: top; }
.memo table.kv td.k { width: 42mm; }
.memo table.kv td.s { width: 4mm; }
.memo table.kv td.jam { width: 40mm; white-space: nowrap; }
.memo .ttd { display: flex; justify-content: space-between; margin-top: 9mm; }
.memo .ttd > div { width: 46%; }
.memo .ttd .r { text-align: center; }
.memo .ttd .space { height: 20mm; }
.memo .ttd .nm { font-weight: bold; text-decoration: underline; }
.memo .ttd .line { display: inline-block; border-bottom: 1px solid #000; min-width: 45mm; }
.memo .spk { margin-top: 9mm; }
.memo .spk-judul { text-align: center; font-weight: bold; font-size: 13.5pt; margin-bottom: 3mm; }

/* ppab */
.ppab table { border-collapse: collapse; width: 100%; }
.ppab .frame { border: 1.5px solid #000; }
.ppab .hdr { text-align: center; padding: 2px 4px 6px; border-bottom: 1px solid #000; position: relative; }
.ppab .hdr .co { position: absolute; left: 4px; top: 2px; font-weight: bold; font-style: italic; }
.ppab .hdr .t { font-weight: bold; font-size: 9pt; margin-top: 12px; }
.ppab .meta { padding: 6px 4px; border-bottom: 1px solid #000; }
.ppab .meta td { padding: 1px 3px; vertical-align: top; }
.ppab table.rinci th, .ppab table.rinci td { border-left: 1px solid #000; padding: 1.5px 4px; }
.ppab table.rinci th.fc, .ppab table.rinci tbody td:first-child { border-left: 0; }
.ppab table.rinci thead th { border-bottom: 1px solid #000; border-top: 1px solid #000; font-weight: bold; text-align: center; }
.ppab table.rinci tbody td { border-bottom: 1px solid #ddd; height: 13px; }
.ppab table.rinci td.n { text-align: right; font-variant-numeric: tabular-nums; }
.ppab table.rinci td.b { font-weight: bold; }
.ppab table.rinci tr.sum td { border-top: 1px solid #000; border-bottom: 1px solid #000; font-weight: bold; }
.ppab table.ttd td { border: 1px solid #000; text-align: center; padding: 2px; }
.ppab table.ttd td.h { font-weight: bold; }
.ppab table.ttd td.sp { height: 22mm; border-bottom: 0; border-top: 0; vertical-align: bottom; }
.ppab table.ttd .nm { font-weight: bold; text-decoration: underline; }

/* ---------- print ---------- */
#printArea { display: none; }
@page { size: A4 portrait; margin: 0; }
@page land { size: A4 landscape; margin: 0; }
@media print {
  body { background: #fff; }
  #app, #toast, #login, dialog { display: none !important; }
  #printArea { display: block; }
  #printArea .doc-page { margin: 0; box-shadow: none; break-after: page; overflow: hidden; }
  #printArea .doc-page:last-child { break-after: auto; }
  #printArea .doc-page.portrait { height: 297mm; }
  #printArea .doc-page.landscape { page: land; height: 210mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 1100px) {
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------- login & akun ---------- */
body.keluar #app { display: none; }
body:not(.keluar) #login { display: none; }
#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: #143d23; }
#formLogin { background: #fff; border-radius: 14px; padding: 26px; width: 100%; max-width: 360px; }
#formLogin img { width: 84px; display: block; margin: 0 auto 8px; }
#formLogin h1, #formLogin h2 { text-align: center; }
#formLogin .btn { width: 100%; }
#pesanLogin { color: var(--danger); min-height: 18px; margin: 10px 0 0; text-align: center; }
dialog { border: 0; border-radius: 12px; padding: 22px; width: min(380px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
body.operator .khusus-admin { display: none; }
.sidebar-foot { opacity: 1; }
.akun { display: flex; gap: 6px; margin-top: 8px; }
.akun button { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 6px; padding: 8px 10px; font: inherit; cursor: pointer; }
#btnMenu { display: none; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- tablet & HP ---------- */
@media screen and (max-width: 900px) {
  #app { display: block; }
  body.keluar #app { display: none; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 20; display: block; }
  .brand { padding: 10px 64px 10px 16px; border: 0; }
  .brand-title { font-size: 16px; }
  #btnMenu { display: block; position: absolute; right: 8px; top: 6px; width: 44px; height: 44px; border: 0; background: none; color: #fff; font-size: 24px; }
  .sidebar nav, .sidebar-foot { display: none; }
  .menu-buka .sidebar { max-height: 100vh; max-height: 100dvh; overflow-y: auto; }
  .menu-buka .sidebar nav { display: flex; }
  .menu-buka .sidebar-foot { display: block; font-size: 13px; }
  nav button { padding: 12px; font-size: 16px; }
  main { padding: 16px 16px 96px; }
  input, select { font-size: 16px; min-height: 42px; }
  input[type=checkbox] { min-height: 0; width: 20px; height: 20px; }
  .peserta-item { padding: 10px; }
  .btn { min-height: 42px; }
  .icon-btn { min-width: 40px; min-height: 40px; font-size: 18px; }
  #view-form > .page-head .head-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: #fff; border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  #view-form > .page-head .head-actions .btn { flex: 1; }
  table.biaya input { min-width: 64px; font-size: 16px; }
  table.biaya td:first-child { min-width: 120px; }
  table.data.edit input, table.data.edit select { min-width: 120px; }
  #karyawanTable td:nth-child(2) input, #karyawanTable td:nth-child(4) input, #tujuanTable td:nth-child(2) input, #atasanTable input { min-width: 220px; }
  #riwayatTable { min-width: 860px; }
  #riwayatTable td.act { position: sticky; right: 0; background: #fff; box-shadow: -6px 0 8px -6px rgba(0,0,0,.2); }
  .preview-stage { padding: 8px; }
  #toast { bottom: 84px; width: max-content; max-width: 92vw; }
}
@media screen and (max-width: 640px) {
  .row { flex-direction: column; align-items: stretch; gap: 0; }
  .row3 { grid-template-columns: 1fr; gap: 0; }
  .tabs { width: 100%; flex-direction: column; }
  .tabs button { min-height: 42px; }
  .card { padding: 14px; }
  .preview-head .btn, .page-head .head-actions { width: 100%; }
}

#toast { visibility: hidden; }
#toast.show { visibility: visible; }
