:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #dbe1e8;
  --primary: #0b5cad;
  --primary-ink: #ffffff;
  --primary-soft: #e6f0fa;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --ok: #157347;
  --ok-soft: #e5f4ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.topbar {
  background: var(--primary);
  color: var(--primary-ink);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto; padding: .6rem 16px;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .3px; }
.brand small { font-weight: 400; opacity: .85; margin-left: .35rem; }
.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--primary-ink); text-decoration: none; padding: .35rem .7rem; border-radius: 6px; opacity: .85;
}
.nav a.active, .nav a:hover { background: rgba(255, 255, 255, .16); opacity: 1; }
.userbox { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.userbox .btn { background: rgba(255, 255, 255, .15); color: #fff; border-color: transparent; }

.demo-banner {
  background: var(--warn-soft); color: var(--warn); text-align: center; font-size: .85rem; padding: .35rem 16px;
}
main { max-width: 1040px; margin: 0 auto; padding: 1.25rem 16px 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head p { margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }

/* ---------- forms ---------- */
.grid { display: grid; gap: .75rem 1rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 7px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
input[readonly] { background: #f1f3f6; }
select:disabled, input:disabled { background: #eef1f4; color: #8a94a3; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .5rem .95rem; border-radius: 7px; border: 1px solid var(--border);
  background: #fff; color: var(--text); white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-lg { padding: .7rem 1.4rem; font-size: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; }

/* ---------- ARTE cards ---------- */
.arte {
  border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: .75rem; background: #fbfcfd;
}
.arte-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.arte-no {
  display: inline-flex; align-items: center; gap: .5rem; font-weight: 700;
}
.arte-no span {
  background: var(--primary); color: #fff; border-radius: 999px; min-width: 1.8rem; height: 1.8rem;
  display: inline-flex; align-items: center; justify-content: center; font-size: .85rem;
}

/* ---------- alerts ---------- */
.alert { border-radius: 8px; padding: .75rem 1rem; margin-bottom: 1rem; }
.alert ul { margin: .35rem 0 0; padding-left: 1.2rem; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-info { background: var(--primary-soft); color: var(--primary); }
.alert-lock { background: #eef1f4; color: var(--muted); }

/* ---------- indikasi ---------- */
.indikasi { list-style: none; margin: 0; padding: 0; }
.indikasi li {
  display: flex; gap: 1rem; align-items: center;
  padding: .75rem .85rem; border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: 8px; margin-bottom: .5rem; background: #fff;
}
.indikasi li { flex-direction: column; align-items: stretch; gap: .6rem; }
.indikasi .ind-main { display: flex; gap: 1rem; align-items: center; }
.indikasi li[data-status=ada] { border-left-color: var(--ok); }
.indikasi li[data-status=tidak_ada] { border-left-color: var(--warn); }
.indikasi li.incomplete { background: var(--warn-soft); }
.ind-alasan { display: flex; flex-direction: column; gap: .25rem; }
.ind-alasan[hidden] { display: none; }
.ind-alasan label { font-size: .82rem; font-weight: 600; color: var(--text); }
.ind-alasan .req { color: var(--danger); font-weight: 400; }
.ind-alasan textarea { resize: vertical; min-height: 2.6rem; }
.choice-ada input:checked + span { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.choice-tidak_ada input:checked + span { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.tag-Komoditas { background: #e3f2f7; color: #0b6b85; }
.indikasi .ind-body { flex: 1; min-width: 0; }
.indikasi .arte-list { font-size: .85rem; color: var(--muted); margin-top: .2rem; }

.ind-choice { display: flex; gap: .4rem; flex: none; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice span {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  min-height: 38px; padding: .4rem .8rem; border-radius: 7px; white-space: nowrap;
  border: 1px solid var(--border); background: #fff; color: var(--muted); font-weight: 600; font-size: .88rem;
}
.choice span::before {
  content: ""; width: .9rem; height: .9rem; border-radius: 50%; border: 2px solid currentColor; flex: none;
}
.choice:hover span { border-color: #a9b4c2; color: var(--text); }
.choice input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.choice-sesuai input:checked + span { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.choice-perbaikan input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.choice input:checked + span::before { background: currentColor; box-shadow: inset 0 0 0 2px #fff; }

/* penanda langkah (blok) */
.stepper { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.stepper .step > a, .stepper .step > span {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .7rem; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted); text-decoration: none; font-size: .88rem; height: 100%;
}
.stepper .step > a:hover { border-color: var(--primary); color: var(--primary); }
.step-no {
  flex: none; width: 1.6rem; height: 1.6rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: #e6e9ee; color: var(--muted); font-weight: 700; font-size: .8rem;
}
.step.done .step-no { background: var(--ok); color: #fff; }
.step.active > span { border: 2px solid var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.step.active .step-no { background: var(--primary); color: #fff; }

.badge-warn {
  display: inline-block; margin-top: .25rem; font-size: .75rem; font-weight: 600; text-decoration: none;
  padding: .1rem .45rem; border-radius: 4px; background: var(--warn-soft); color: var(--warn);
}

/* pilihan pada form karakteristik */
.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.choice-pick input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.choice-check span::before { border-radius: 3px; }
.choice-check input:checked + span::before {
  background: currentColor; box-shadow: inset 0 0 0 2px #fff;
}
.field[hidden] { display: none; }

/* daftar keterangan (key-value) */
.kv { margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 1.5rem; }
.kv > div { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; font-weight: 600; text-align: right; }
.tag {
  display: inline-block; font-size: .72rem; font-weight: 700; padding: .05rem .45rem; border-radius: 4px; margin-right: .35rem;
  vertical-align: 1px;
}
.tag-Pengeluaran { background: var(--warn-soft); color: var(--warn); }
.tag-Konsistensi { background: var(--danger-soft); color: var(--danger); }
.tag-Konfirmasi { background: #ece8fb; color: #5b3fb5; }

/* nomor bagian di Blok 3 */
.sec-no {
  display: inline-flex; align-items: center; justify-content: center; width: 1.6rem; height: 1.6rem; margin-right: .35rem;
  border-radius: 50%; background: var(--primary); color: #fff; font-size: .85rem; vertical-align: 2px;
}

/* pertanyaan konfirmasi */
.qlist { list-style: none; counter-reset: q; margin: 0; padding: 0; }
.qlist li {
  counter-increment: q; display: flex; align-items: center; gap: 1rem;
  padding: .7rem .85rem; border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: 8px; margin-bottom: .5rem; background: #fff;
}
.qlist li.answered { border-left-color: var(--primary); }
.qlist li.q-group {
  counter-increment: none; display: block; border: 0; background: transparent; padding: .6rem 0 .1rem; margin: 0;
  font-weight: 700; font-size: .85rem; color: var(--muted);
}
.qlist .q-text { flex: 1; min-width: 0; }
.qlist .q-text::before { content: counter(q) ". "; font-weight: 700; color: var(--muted); }
.qlist .seg { flex: none; }

.month-tab.locked { cursor: not-allowed; opacity: .6; background: #f1f3f6; }
.chip.locked { opacity: .7; background: #f1f3f6; }

.progress { height: 8px; background: #e6e9ee; border-radius: 99px; overflow: hidden; margin: .25rem 0 .75rem; }
.progress > div { height: 100%; background: var(--ok); transition: width .2s; }

/* ---------- list ---------- */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.filters .field { width: 160px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); background: #f8fafc; }
td.num, th.num { text-align: right; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip {
  font-size: .78rem; padding: .15rem .5rem; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); background: #fff;
}
.chip.done { background: var(--ok-soft); color: var(--ok); border-color: #b9dfc9; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login h1 { color: var(--primary); }
.login .field { margin-bottom: .75rem; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%) translateY(150%);
  background: #1c2430; color: #fff; padding: .65rem 1.1rem; border-radius: 8px; box-shadow: var(--shadow);
  transition: transform .25s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

a.chip { text-decoration: none; }
a.chip:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1rem; }
.stat-box {
  display: block; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem 1.1rem; transition: border-color .15s;
}
.stat-box:hover { border-color: var(--primary); }
.stat-box.current { border: 2px solid var(--primary); }
.stat-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: .5rem; }
.stat-head h2 { margin: 0; color: var(--primary); }
.stat-num { font-size: 2.2rem; font-weight: 700; line-height: 1.1; margin-bottom: .75rem; font-variant-numeric: tabular-nums; }
.stat-num span { font-size: .9rem; font-weight: 400; color: var(--muted); }
.stat-label { display: flex; justify-content: space-between; font-size: .85rem; }
.stat-box .progress { margin: .3rem 0 .4rem; }
.stat-box p { margin-bottom: .6rem; }
.stat-months { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; }
.stat-month {
  display: flex; flex-direction: column; align-items: center; padding: .3rem; border-radius: 6px;
  background: #f1f3f6; font-size: .8rem; color: var(--muted);
}
.stat-month strong { color: var(--text); font-variant-numeric: tabular-nums; }
.stat-month.full { background: var(--ok-soft); color: var(--ok); }
.stat-month.full strong { color: var(--ok); }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .stat-grid { grid-template-columns: 1fr; } }

/* ---------- tab bulan ---------- */
.month-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1rem; }
.month-tab {
  font: inherit; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: .1rem;
  padding: .65rem .85rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.month-tab .small { color: var(--muted); }
.month-tab.done { border-color: #b9dfc9; }
.month-tab.done strong { color: var(--ok); }
.month-tab.active { border: 2px solid var(--primary); background: var(--primary-soft); }
.month-tab.active strong { color: var(--primary); }

.money { font-variant-numeric: tabular-nums; }
.total-input { font-size: 1.15rem; font-weight: 600; max-width: 320px; }

.ico { width: 1.15rem; height: 1.15rem; flex: none; }
.nav a { display: inline-flex; align-items: center; gap: .4rem; }
.show-sm { display: none; }
summary { cursor: pointer; }

/* =====================================================================
   RESPONSIVE — tablet & handphone
   ===================================================================== */
@media (max-width: 720px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

  /* header ringkas: brand + akun saja */
  .topbar-inner { flex-wrap: nowrap; gap: .5rem; padding: .55rem 16px; }
  .brand { flex: 1; white-space: nowrap; }
  .brand small, .user-role { display: none; }
  .user-name { max-width: 9.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* menu pindah ke bawah layar */
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(16, 24, 40, .06);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .nav a {
    flex-direction: column; gap: .15rem; justify-content: center;
    min-height: 58px; padding: .4rem .25rem; border-radius: 0;
    color: var(--muted); opacity: 1; font-size: .75rem; font-weight: 600;
  }
  .nav a .ico { width: 1.4rem; height: 1.4rem; }
  .nav a.active, .nav a:hover { background: transparent; color: var(--primary); }
  .nav a.active { box-shadow: inset 0 3px 0 var(--primary); }

  main { padding: 1rem 12px 2rem; }
  .card { padding: .9rem; border-radius: 8px; }
  .page-head { margin-bottom: .75rem; }
  .page-head > .btn.dup-nav { display: none; } /* tombol duplikat; sudah ada di menu bawah */
  .page-head > .field { width: 100% !important; }
  h1 { font-size: 1.25rem; }

  /* cegah zoom otomatis iOS saat fokus input */
  input, select, textarea { font-size: 16px; padding: .6rem .65rem; }

  .grid { grid-template-columns: 1fr 1fr; gap: .65rem .75rem; }
  .filters .field { width: calc(50% - .25rem); }
  .actions.end { flex-direction: column-reverse; align-items: stretch; }
  .actions.end .btn { width: 100%; }
  .btn-lg { width: 100%; }
  .arte { padding: .75rem; }

  /* tabel -> kartu */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr {
    border: 1px solid var(--border); border-radius: 8px; padding: .65rem .75rem; margin-bottom: .6rem; background: var(--surface);
  }
  table.stack td { border: 0; padding: .2rem 0; text-align: left; display: flex; gap: .75rem; justify-content: space-between; }
  table.stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .82rem; flex: none; }
  table.stack td.cell-title { font-size: 1rem; padding-bottom: .35rem; }
  table.stack td.cell-full { flex-direction: column; gap: .3rem; }
  table.stack td.cell-actions { padding-top: .6rem; }
  table.stack td.cell-actions .actions { flex-direction: row; width: 100%; }
  table.stack td.cell-actions .btn { flex: 1; width: auto; }
  table.stack .hide-sm { display: none; }
  .show-sm { display: inline; }
  .table-wrap { overflow: visible; }

  .month-tabs { gap: .35rem; }
  .month-tab { padding: .5rem .55rem; }
  .month-tab strong { font-size: .9rem; }
  .month-tab .small { font-size: .72rem; }

  .indikasi li { padding: .65rem; flex-direction: column; align-items: stretch; gap: .6rem; }
  .ind-choice { display: grid; grid-template-columns: 1fr 1fr; }
  .indikasi .ind-main { flex-direction: column; align-items: stretch; gap: .6rem; }
  .qlist li { flex-direction: column; align-items: stretch; gap: .5rem; padding: .65rem; }
  .qlist li.q-group { padding: .6rem 0 .1rem; }
  .qlist .seg { display: grid; grid-template-columns: 1fr 1fr; }
  .seg .choice { flex: 1 1 0; }
  .seg .choice span { width: 100%; min-height: 44px; }
  .kv { grid-template-columns: 1fr; }
  .stepper { gap: .3rem; }
  .stepper .step > a, .stepper .step > span { flex-direction: column; gap: .2rem; padding: .45rem .3rem; text-align: center; font-size: .72rem; line-height: 1.2; }
  table.stack td.cell-title { display: block; }
  .choice span { width: 100%; min-height: 44px; }
  .total-input { max-width: none; }

  #toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; gap: .75rem; }
  .stat-num { font-size: 1.9rem; margin-bottom: .5rem; }
}

@media (max-width: 360px) {
  .user-name { display: none; }
}
