:root {
  color-scheme: light;
  --bg: #f5f5f1;
  --surface: #ffffff;
  --surface-2: #f0f0eb;
  --text: #1b1b19;
  --muted: #5f5e59;
  --line: #e2e1dc;
  --accent: #17695a;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ec;
  --bar: #2a78d6;
  --bar-track: #e8e8e3;
  --ref: #3d3c38;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn-soft: #fdf3dc;
  --ok-soft: #e4f3e8;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413;
    --surface: #1d1d1b;
    --surface-2: #262624;
    --text: #efeee9;
    --muted: #b0afa8;
    --line: #34332f;
    --accent: #3fae95;
    --accent-ink: #0d1f1b;
    --accent-soft: #1c3530;
    --bar: #3987e5;
    --bar-track: #2e2e2b;
    --ref: #e6e5df;
    --danger: #f2827a;
    --danger-soft: #3a1d1b;
    --warn-soft: #3a3019;
    --ok-soft: #1b3324;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --surface: #1d1d1b; --surface-2: #262624; --text: #efeee9; --muted: #b0afa8; --line: #34332f;
  --accent: #3fae95; --accent-ink: #0d1f1b; --accent-soft: #1c3530; --bar: #3987e5; --bar-track: #2e2e2b; --ref: #e6e5df;
  --danger: #f2827a; --danger-soft: #3a1d1b; --warn-soft: #3a3019; --ok-soft: #1b3324;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code { font-size: .875em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }

/* ---------- Komponen umum ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1.1rem;
  border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 34px; padding: .3rem .75rem; font-size: .875rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .score:focus-visible, .grade:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; flex: 1; min-width: 0; }
.field > span { font-size: .875rem; font-weight: 600; color: var(--muted); }
.field.small { flex: 0 0 110px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: auto; }
.w-small { width: 90px; flex: 0 0 auto; }
.row { display: flex; gap: .9rem; flex-wrap: wrap; }
.row.inline { align-items: center; margin-bottom: .6rem; }
.row.inline input:not(.w-small) { flex: 1; min-width: 160px; width: auto; }
.check { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.form.narrow { max-width: 420px; margin: 0 auto; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin: 0 0 1rem; }
.flash.ok { background: var(--ok-soft); }
.flash.err { background: var(--danger-soft); color: var(--danger); }
.flash.warn, .card.warn { background: var(--warn-soft); }

.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.tag.on { background: var(--accent-soft); color: var(--accent); }
.status { font-size: 1.05rem; margin: 0 0 .5rem; }
.status.on::before, .status.off::before { content: ""; display: inline-block; width: .65rem; height: .65rem; border-radius: 50%; margin-right: .5rem; }
.status.on::before { background: #1f9d55; }
.status.off::before { background: var(--muted); }

.fill-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.fill-wrap > .card { width: 100%; max-width: 460px; }

/* ---------- Admin ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: .5rem 16px; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: .2rem; flex-wrap: wrap; flex: 1; }
.nav a { padding: .4rem .65rem; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: .925rem; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.who { display: flex; gap: .8rem; align-items: center; font-size: .9rem; }
.who form { margin: 0; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 1.25rem 16px 3rem; }

.table-wrap { overflow-x: auto; margin: 0 -.25rem; }
table { border-collapse: collapse; width: 100%; font-size: .925rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.dim td { color: var(--muted); }
tr.group td { background: var(--surface-2); font-weight: 600; }
tr.below td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.matrix td, .matrix th { padding: .35rem .45rem; font-size: .85rem; }
.matrix td:first-child { white-space: nowrap; position: sticky; left: 0; background: var(--surface); }
.link-copy { font-size: .8rem; }

.checklist { border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; margin: 0 0 1rem; max-height: 420px; overflow: auto; }
.checklist legend { font-weight: 600; padding: 0 .3rem; }
.checklist label { display: flex; gap: .6rem; align-items: flex-start; padding: .3rem 0; }
.checklist input { margin-top: .3rem; }
.checklist[disabled] { opacity: .7; }

.filters { display: flex; gap: .9rem; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; min-width: 180px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .15rem; }
.tile span { font-size: .85rem; color: var(--muted); }
.tile b { font-size: 1.9rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); }
.downloads { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.downloads h2 { width: 100%; margin-bottom: .25rem; }

.barcol { width: 34%; min-width: 140px; }
.bar { position: relative; display: block; height: 12px; background: var(--bar-track); border-radius: 4px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bar); border-radius: 0 4px 4px 0; }
.bar b { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--ref); }
.pred { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 6px; font-size: .8rem; font-weight: 700; background: var(--surface-2); }
.comments { padding-left: 1.1rem; }
.comments li { margin-bottom: .5rem; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary h2 { display: inline; }
details summary::after { content: " ▸"; color: var(--muted); }
details[open] summary::after { content: " ▾"; }

/* ---------- Halaman pengisian santri ---------- */
.isi { max-width: 720px; margin: 0 auto; padding-bottom: 96px; }
.isi-head { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: .75rem 16px .6rem; border-bottom: 1px solid var(--line); }
.isi-title { font-weight: 700; }
.isi-unit { font-size: .85rem; color: var(--muted); }
.progress { height: 6px; background: var(--bar-track); border-radius: 99px; margin-top: .5rem; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.isi-main { padding: 1rem 16px; }
.grades { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.grade { min-height: 56px; border: 2px solid var(--line); background: var(--surface); color: var(--text); border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; }
.grade.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.qmeta { font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.qtext { font-size: 1.25rem; }
.scale-legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .8rem; color: var(--muted); }
.scale-legend b { color: var(--text); }
.ulist { list-style: none; margin: 0 0 1rem; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.urow { display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.urow:last-child { border-bottom: 0; }
.uname { flex: 1 1 200px; font-weight: 600; min-width: 0; }
.uname small { display: block; font-weight: 400; color: var(--muted); }
.scores { display: flex; gap: .35rem; }
.score {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 700; cursor: pointer;
}
.score.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.isi-foot { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: .7rem 16px calc(.7rem + env(safe-area-inset-bottom)); z-index: 5; }
.isi-foot-inner { max-width: 720px; margin: 0 auto; display: flex; justify-content: space-between; gap: .75rem; }
.isi-foot .btn { flex: 1; max-width: 240px; }
.isi-foot .btn.primary { margin-left: auto; }

@media (max-width: 420px) {
  .score { width: 40px; height: 40px; }
  .scores { width: 100%; justify-content: space-between; }
}
td:has(> .pred) { white-space: nowrap; }
.recs h3 { font-size: 1rem; margin: 1.1rem 0 .35rem; }
.recs ul { padding-left: 1.2rem; margin: .3rem 0 .6rem; }
.recs li { margin-bottom: .35rem; }
.recs form { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: 1rem; }
