/* CBT Madrasah — satu stylesheet, font bawaan perangkat agar cepat dimuat. */
:root {
  --paper: #F3F6F5; --surface: #FFFFFF; --ink: #17262B; --muted: #5A6A6E; --line: #D3DCD9;
  --jade: #0E5E52; --jade-ink: #FFFFFF; --jade-soft: #DCEDE8;
  --amber: #A9690B; --amber-soft: #FBEFD6; --red: #B42318; --red-soft: #FBE4E1; --ok-soft: #DDF1E6;
  --bubble: #17262B; --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  --q-size: 1.0625rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F1A1C; --surface: #172427; --ink: #E7EEEC; --muted: #9DB0AD; --line: #2E4044;
    --jade: #4FB8A4; --jade-ink: #08201B; --jade-soft: #173B35; --amber: #E5A84A; --amber-soft: #3A2C12;
    --red: #F08A7E; --red-soft: #3D1D1A; --ok-soft: #173B2A; --bubble: #E7EEEC; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0F1A1C; --surface: #172427; --ink: #E7EEEC; --muted: #9DB0AD; --line: #2E4044;
  --jade: #4FB8A4; --jade-ink: #08201B; --jade-soft: #173B35; --amber: #E5A84A; --amber-soft: #3A2C12;
  --red: #F08A7E; --red-soft: #3D1D1A; --ok-soft: #173B2A; --bubble: #E7EEEC; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 1rem/1.5 var(--font); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
a { color: var(--jade); }
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--jade); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.note { padding: .7rem .9rem; border-radius: 10px; background: var(--jade-soft); }
.note.err { background: var(--red-soft); color: var(--red); }
.note.ok { background: var(--ok-soft); }
.note.warn { background: var(--amber-soft); }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); border: 1.5px dashed var(--line); border-radius: var(--radius); }

/* ---------- tombol & formulir ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1.1rem; border: 0; border-radius: 10px;
  background: var(--jade); color: var(--jade-ink); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.big { width: 100%; min-height: 52px; font-size: 1.05rem; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.danger { background: var(--red); color: #fff; }
.btn.sm { min-height: 34px; padding: .3rem .7rem; font-size: .875rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { color: var(--jade); font-weight: 600; text-decoration: none; }
.form { display: grid; gap: .9rem; }
.form label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
.form fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: .9rem; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: .6rem .75rem; background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 10px; font-weight: 400; font-size: 1rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--jade); outline: none; }
input[type=checkbox] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--jade); }
.check { display: flex !important; align-items: center; gap: .5rem; font-weight: 400 !important; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

/* ---------- masuk ---------- */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); padding: 1.75rem 1.5rem; border-radius: 16px; border: 1px solid var(--line); }
.auth-card.wide { max-width: 520px; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: 1rem; }
.brand { color: var(--jade); font-weight: 700; margin-bottom: .25rem; }

/* ---------- beranda siswa ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar div { display: grid; }
.wrap { max-width: 720px; margin: 0 auto; padding: 1rem 1rem 3rem; }
.h-page { font-size: 1.35rem; margin: .5rem 0 1rem; }
.exam-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: .8rem; display: grid; gap: .8rem; }
.exam-card h2 { font-size: 1.15rem; margin: 0; }
.exam-card .muted { margin: 0 0 .3rem; }
.exam-card .small { margin: 0; color: var(--muted); }
.token-form { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.token-form input { text-transform: uppercase; letter-spacing: .15em; font-weight: 700; text-align: center; }
.state { margin: 0; font-weight: 600; color: var(--muted); }
.state.done { color: var(--jade); }
.score { font-size: 2.25rem; font-weight: 800; margin: 0; color: var(--jade); line-height: 1.1; }
@media (min-width: 560px) { .exam-card { grid-template-columns: 1fr auto; align-items: center; } .ec-act { text-align: right; } }

/* ---------- ruang ujian ---------- */
body.exam { -webkit-user-select: none; user-select: none; overscroll-behavior-y: contain; }
body.f-md { --q-size: 1.0625rem; } body.f-lg { --q-size: 1.25rem; } body.f-xl { --q-size: 1.45rem; }
.xbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .55rem .9rem; padding-top: max(.55rem, env(safe-area-inset-top)); background: var(--jade); color: #fff;
}
.xtitle { display: grid; min-width: 0; line-height: 1.25; }
.xtitle b, .xtitle span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xtitle span { font-size: .8rem; opacity: .85; }
.xtime {
  flex: none; border: 0; border-radius: 999px; padding: .35rem .85rem; background: rgba(255,255,255,.16); color: #fff;
  font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; min-width: 5.2rem;
}
.xtime.low { background: #fff; color: var(--red); }
:root[data-theme="dark"] .xbar, .exam .xbar { color: #fff; }
.xnet { position: sticky; top: 52px; z-index: 4; padding: .45rem .9rem; background: var(--amber-soft); color: var(--ink); font-size: .85rem; }
.xbody { max-width: 760px; margin: 0 auto; padding: 1rem 1rem calc(88px + env(safe-area-inset-bottom)); }
.loading { padding: 3rem 0; text-align: center; color: var(--muted); }
.qno { font-weight: 700; color: var(--jade); margin-bottom: .5rem; }
.qno span { color: var(--muted); font-weight: 400; }
.qtext { font-size: var(--q-size); line-height: 1.6; margin-bottom: 1rem; overflow-wrap: anywhere; }
.qimg { display: block; margin: 0 0 1rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.opts { display: grid; gap: .6rem; }
.opt {
  display: flex; align-items: flex-start; gap: .8rem; width: 100%; text-align: left;
  padding: .7rem .8rem; min-height: 56px; background: var(--surface); border: 1.5px solid var(--line);
  border-radius: var(--radius); cursor: pointer; font-size: var(--q-size); line-height: 1.45;
  -webkit-tap-highlight-color: transparent; transition: border-color .12s, background-color .12s;
}
.opt .otext { padding-top: .2rem; overflow-wrap: anywhere; flex: 1; }
.bub {
  flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid var(--bubble); font-weight: 700; font-size: .95rem; transition: background-color .12s, color .12s;
}
.opt.on { border-color: var(--jade); background: var(--jade-soft); }
.opt.on .bub { background: var(--bubble); color: var(--surface); }
.essay { min-height: 160px; font-size: var(--q-size); line-height: 1.55; -webkit-user-select: text; user-select: text; resize: vertical; }

.xnav {
  position: fixed; inset: auto 0 0 0; z-index: 5; display: grid; grid-template-columns: 1fr 1fr auto 1.25fr; gap: .4rem;
  padding: .55rem .6rem; padding-bottom: max(.55rem, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.nbtn {
  min-height: 48px; padding: .3rem .4rem; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: .95rem; cursor: pointer; white-space: nowrap;
}
.nbtn:disabled { opacity: .4; }
.nbtn.main { background: var(--jade); color: var(--jade-ink); border-color: var(--jade); }
.nbtn.ragu[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); color: #fff; }
#list { min-width: 58px; font-variant-numeric: tabular-nums; }
@media (min-width: 760px) { .xnav { max-width: 760px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 14px 14px 0 0; } }

.sheet, .overlay { position: fixed; inset: 0; z-index: 20; background: rgba(10, 20, 22, .55); display: flex; }
.sheet { align-items: flex-end; }
.sheet-panel {
  width: 100%; max-width: 760px; margin: 0 auto; max-height: 85vh; overflow: auto; background: var(--surface);
  border-radius: 18px 18px 0 0; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); display: grid; gap: .9rem;
}
.sheet-head { display: flex; align-items: center; gap: .5rem; }
.sheet-head b { flex: 1; font-size: 1.1rem; }
.x, .fontbtn { width: 44px; height: 44px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .8rem; color: var(--muted); }
.lg::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; border: 1.5px solid var(--line); }
.lg.done::before { background: var(--bubble); border-color: var(--bubble); }
.lg.flag::before { background: var(--amber); border-color: var(--amber); }
.ljk { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: .45rem; }
.ljk button {
  height: 46px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface);
  font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer;
}
.ljk button.done { background: var(--bubble); border-color: var(--bubble); color: var(--surface); }
.ljk button.flag { background: var(--amber); border-color: var(--amber); color: #fff; }
.ljk button.cur { outline: 3px solid var(--jade); outline-offset: 1px; }
.overlay { align-items: center; justify-content: center; padding: 1rem; z-index: 30; }
.ov-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; padding: 1.4rem; }
.ov-card h2 { font-size: 1.25rem; }
#lock { background: var(--paper); }
#lock .ov-card { border: 2px solid var(--red); }
#lock h2 { color: var(--red); }
.done-card { text-align: center; padding: 2.5rem 1rem; display: grid; gap: .5rem; justify-items: center; }
.done-card .btn { margin-top: 1rem; max-width: 360px; }

/* ---------- panel admin ---------- */
body.admin { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .75rem; display: flex; flex-direction: column; gap: .2rem; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side .brand { padding: 0 .6rem .8rem; border-bottom: 1px solid var(--line); margin-bottom: .5rem; }
.side .brand small { display: block; color: var(--muted); font-weight: 400; }
.side a { display: block; padding: .6rem .7rem; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
.side a:hover { background: var(--paper); }
.side a.on { background: var(--jade-soft); color: var(--jade); font-weight: 700; }
.side .sp { flex: 1; }
.main { padding: 1.25rem 1.5rem 3rem; min-width: 0; }
.main h1 { font-size: 1.45rem; }
.head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.head h1 { margin: 0; }
.head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.panel h2 { font-size: 1.05rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--paper); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--paper); border: 1px solid var(--line); white-space: nowrap; }
.pill.go { background: var(--jade-soft); color: var(--jade); border-color: transparent; }
.pill.lock { background: var(--red-soft); color: var(--red); border-color: transparent; }
.pill.done { background: var(--ok-soft); border-color: transparent; }
.pill.off { color: var(--muted); }
.pill.warn { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.tok { font-size: 1.6rem; font-weight: 800; letter-spacing: .18em; font-variant-numeric: tabular-nums; }
.inline { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .8rem; }
.filters select, .filters input { width: auto; min-height: 38px; padding: .3rem .6rem; }
.bar { height: 8px; border-radius: 99px; background: var(--paper); overflow: hidden; min-width: 70px; }
.bar i { display: block; height: 100%; background: var(--jade); }
.essay-ans { white-space: pre-wrap; background: var(--paper); padding: .6rem .7rem; border-radius: 8px; margin: .3rem 0 .5rem; }
.menu-btn { display: none; }
@media (max-width: 860px) {
  body.admin { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-105%); transition: transform .2s; box-shadow: 0 0 0 100vmax transparent; }
  body.nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .menu-btn { display: inline-flex; }
  .main { padding: 1rem; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- kartu peserta (cetak) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .6rem; }
.card { border: 1.5px dashed #555; border-radius: 8px; padding: .7rem .8rem; background: #fff; color: #111; break-inside: avoid; font-size: .85rem; }
.card h3 { font-size: .9rem; margin: 0 -6.4rem .4rem 0; padding-bottom: .35rem; border-bottom: 1px solid #999; }
.card table { font-size: .85rem; } .card td { border: 0; padding: .1rem .3rem .1rem 0; }
.card { position: relative; padding-right: 7rem; }
.card-qr { position: absolute; right: .6rem; top: 50%; transform: translateY(-40%); width: 6rem; }
.card-qr svg { display: block; width: 100%; height: auto; }
.card .pw { font-family: ui-monospace, Consolas, monospace; font-size: 1rem; font-weight: 700; letter-spacing: .05em; }
@media print {
  .side, .head .actions, .no-print, .menu-btn { display: none !important; }
  body.admin { display: block; background: #fff; }
  .main { padding: 0; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- QR ujian ---------- */
.qr-sheet {
  background: #fff; color: #111; border: 1px solid var(--line); border-radius: var(--radius);
  max-width: 560px; margin: 0 auto 1rem; padding: 1.75rem 1.5rem; text-align: center;
}
.qr-school { color: #0E5E52; font-weight: 700; margin: 0 0 .25rem; }
.qr-title { font-size: 1.6rem; margin: 0 0 1rem; color: #111; }
.qr-title span { display: block; font-size: 1.1rem; font-weight: 600; color: #0E5E52; margin-top: .25rem; }
.qr-code { width: min(100%, 340px); margin: 0 auto; }
.qr-code svg { display: block; width: 100%; height: auto; }
.qr-url { font-weight: 700; font-size: 1.05rem; word-break: break-all; margin: .75rem 0 1rem; }
.qr-steps { text-align: left; max-width: 400px; margin: 0 auto; padding-left: 1.25rem; font-size: .95rem; line-height: 1.6; }
body.qr-full .side, body.qr-full .main > :not(#sheets), body.qr-full .qr-sheet ~ .qr-sheet { display: none !important; }
body.qr-full { display: block; background: #fff; }
body.qr-full .main { padding: 0; }
body.qr-full .qr-sheet {
  border: 0; max-width: none; min-height: 100vh; margin: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; cursor: zoom-out;
}
body.qr-full .qr-code { width: min(70vh, 80vw); }
body.qr-full .qr-title { font-size: clamp(1.8rem, 4vw, 3rem); }
body.qr-full .qr-url { font-size: clamp(1.1rem, 2.4vw, 1.8rem); }
body.qr-full .qr-steps { display: none; }
@media print {
  .qr-sheet { border: 0; max-width: none; padding: 1.5cm 1cm; break-after: page; page-break-after: always; }
  .qr-sheet:last-child { break-after: auto; page-break-after: auto; }
  .qr-code { width: 11cm; }
  .qr-title { font-size: 26pt; } .qr-url { font-size: 14pt; } .qr-steps { font-size: 13pt; max-width: 15cm; }
  .note { display: none; }
}
