:root {
  --paper: #F5F7FB;
  --field: #E6ECF5;
  --field-past: #DCE3EE;
  --ink: #1B2440;
  --muted: #5D6883;
  --rule: #CFD7E6;
  --block: #5A64EE;
  --block-soft: #C9CDFB;
  --edge: #F2A33A;
  --pass: #2F9B6E;
  --d: #D8A21A;
  --fail: #D2433F;
  --surface: #FFFFFF;
  --focus: #1D4ED8;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12172A; --field: #1A2138; --field-past: #151B2E; --ink: #E7EBF5; --muted: #9AA5C2;
    --rule: #2C3653; --block: #7079F5; --block-soft: #343B7A; --surface: #1B2238; --focus: #93B4FF;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12172A; --field: #1A2138; --field-past: #151B2E; --ink: #E7EBF5; --muted: #9AA5C2;
  --rule: #2C3653; --block: #7079F5; --block-soft: #343B7A; --surface: #1B2238; --focus: #93B4FF;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font: 15px/1.5 "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  display: flex; flex-direction: column;
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

button {
  border: 1px solid var(--rule); background: var(--surface); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--block); border-color: var(--block); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 2px 8px; font-size: 13px; }
button.danger { color: var(--fail); }
select, input[type=text], input[type=number], input[type=password] {
  border: 1px solid var(--rule); background: var(--surface); border-radius: 6px; padding: 5px 8px; min-width: 0;
}

/* Bilah atas */
.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--rule); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.plan-picker { display: flex; gap: 6px; align-items: center; }
.plan-picker select { max-width: 220px; }
.cur-name { color: var(--muted); font-size: 14px; }
.cur-name button { margin-left: 6px; }
.save-state { color: var(--muted); font-size: 13px; }
.account { margin-left: auto; display: flex; gap: 8px; align-items: center; font-size: 14px; }

/* Tata letak */
.layout { flex: 1; display: grid; grid-template-columns: 300px minmax(0, 1fr) auto; min-height: 0; }
.rail { border-right: 1px solid var(--rule); padding: 20px; overflow-y: auto; }
.board { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.drawer {
  width: 380px; border-left: 1px solid var(--rule); background: var(--surface);
  overflow-y: auto; padding: 20px; position: relative;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .drawer { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: -8px 0 24px rgba(20, 30, 60, .18);
    padding-top: calc(20px + env(safe-area-inset-top, 0px)); max-width: 100%; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid var(--rule); }
  .top { gap: 10px; padding: 10px 14px; }
}

/* Panel ringkasan */
.verdict { margin: 0 0 18px; }
.verdict .big { font-size: 30px; line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; }
.verdict .big.late { color: var(--fail); }
.verdict p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0 0 20px; }
.stats div { border-top: 2px solid var(--ink); padding-top: 4px; }
.stats b { display: block; font-size: 20px; }
.stats span { font-size: 13px; color: var(--muted); }
.rail h3 { font-size: 14px; margin: 22px 0 8px; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper output { font-size: 22px; font-weight: 700; min-width: 2ch; text-align: center; }
.rail .help { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.opt { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; margin: 6px 0; }
.opt input { margin-top: 4px; }
.warn-list { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.warn-list li { padding: 6px 0 6px 10px; border-left: 3px solid var(--rule); margin-bottom: 4px; }
.warn-list li.error { border-color: var(--fail); }
.warn-list li.warn { border-color: var(--d); }
.checks { width: 100%; border-collapse: collapse; font-size: 13px; }
.checks td { padding: 4px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.checks td:last-child { text-align: right; white-space: nowrap; }
.checks .no { color: var(--fail); font-weight: 600; }

/* Legenda */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 12px 20px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--rule); align-items: center; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend .hint { flex-basis: 100%; }
.sw { width: 18px; height: 10px; border-radius: 2px; display: inline-block; background: var(--block); }
.sw.pass { background: var(--pass); } .sw.d { background: var(--d); } .sw.e { background: var(--fail); }
.sw.retake { background: var(--block); box-shadow: inset 4px 0 0 var(--fail); }
.sw.ungraded { background: repeating-linear-gradient(45deg, var(--block) 0 2px, var(--block-soft) 2px 5px); }
.ln { width: 18px; height: 2px; background: var(--edge); display: inline-block; }

/* Diagram */
.chart-wrap { overflow: auto; flex: 1; padding: 0 0 24px; }
.chart { display: block; font-family: inherit; }
.chart-sticky { position: sticky; top: 0; z-index: 2; background: var(--paper); width: max-content; }
.col-bg { fill: var(--field); stroke: var(--paper); stroke-width: 2; }
.col-bg.past, .col.past .col-bg { fill: var(--field-past); }
.col.now .col-bg { stroke: var(--block); stroke-width: 1.5; }
.col-bg.now { stroke: var(--block); stroke-width: 1.5; }
.col-head { cursor: pointer; }
.col-head:hover .col-bg { fill: var(--block-soft); }
.col-head:hover .col-title, .col-head:focus-visible .col-title { text-decoration: underline; }
.col-title { font-size: 13px; font-weight: 700; fill: var(--ink); }
.col-sub { font-size: 12px; fill: var(--muted); }
.col-now { font-size: 11px; font-weight: 600; fill: var(--block); }
.bar-bg { fill: var(--rule); } .bar { fill: var(--block); } .bar.over { fill: var(--fail); }
.ontime { stroke: var(--fail); stroke-dasharray: 4 4; stroke-width: 1.5; }
.row { cursor: pointer; }
.row-hit { fill: transparent; }
.row:hover .row-hit, .row:focus-visible .row-hit, .row.sel .row-hit { fill: rgba(90, 100, 238, .08); }
.label { font-size: 12.5px; fill: var(--ink); }
.blk { fill: var(--block); }
.blk.g-A, .blk.g-B, .blk.g-C { fill: var(--pass); }
.blk.g-D { fill: var(--d); }
.blk.g-E { fill: var(--fail); }
.blk.ungraded { fill: url(#hatch); }
.blk.retake { fill: var(--block); stroke: var(--fail); stroke-width: 2.5; }
.blk.improve { fill: var(--block-soft); stroke: var(--block); stroke-dasharray: 3 2; }
.blk-sks { font-size: 11px; fill: #fff; pointer-events: none; }
.blk-mark { font-size: 11px; font-weight: 700; fill: #fff; pointer-events: none; }
.row:has(.ungraded) .blk-sks, .row:has(.ungraded) .blk-mark,
.row:has(.improve) .blk-sks, .row:has(.improve) .blk-mark { fill: var(--ink); }
.pin { fill: var(--ink); stroke: var(--surface); stroke-width: 1.5; }
.edge { fill: none; stroke: var(--edge); stroke-width: 1.6; pointer-events: none; }
.edge.co { stroke-dasharray: 5 3; }
.edge.bad { stroke: var(--fail); stroke-dasharray: 3 3; }
.edge.hot { stroke-width: 3; }
.empty { padding: 40px; color: var(--muted); }

/* Laci detail */
.drawer h2 { font-size: 20px; line-height: 1.25; margin: 0 32px 4px 0; letter-spacing: -0.01em; }
.drawer .meta { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.drawer h4 { font-size: 14px; margin: 20px 0 8px; }
.drawer .close { position: absolute; top: 14px; right: 14px; }
.drawer ul.plain { list-style: none; padding: 0; margin: 0; }
.drawer ul.plain li { padding: 7px 0; border-bottom: 1px solid var(--rule); display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 14px; }
.drawer ul.plain li .t { flex: 1; min-width: 0; }
.drawer ul.plain li small { color: var(--muted); display: block; }
.grades { display: inline-flex; gap: 3px; flex-shrink: 0; }
.grades button { width: 28px; padding: 3px 0; font-weight: 600; font-size: 13px; }
.grades button[aria-pressed=true] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.grades button[data-g=E][aria-pressed=true] { background: var(--fail); border-color: var(--fail); }
.grades button[data-g=D][aria-pressed=true] { background: var(--d); border-color: var(--d); color: #1B2440; }
.tag { font-size: 12px; color: var(--muted); }
.ok { color: var(--pass); } .bad { color: var(--fail); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
.note { background: var(--field); padding: 8px 10px; border-radius: 6px; font-size: 13px; }

/* Dialog */
dialog { border: 1px solid var(--rule); border-radius: 10px; padding: 0; background: var(--surface); color: var(--ink); max-width: min(1100px, 96vw); width: 100%; }
dialog.narrow { max-width: 380px; }
dialog::backdrop { background: rgba(18, 23, 42, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--rule); gap: 12px; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-body { padding: 16px 20px; max-height: 72vh; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--rule); flex-wrap: wrap; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 14px; }
.form .err { color: var(--fail); font-size: 14px; min-height: 1.2em; margin: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); padding: 0 20px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 12px; }
.tabs button[aria-selected=true] { border-color: var(--block); font-weight: 600; }
.tbl-wrap { overflow-x: auto; }
table.edit { border-collapse: collapse; font-size: 13px; width: 100%; }
table.edit th { text-align: left; font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--ink); position: sticky; top: 0; background: var(--surface); }
table.edit td { padding: 3px 4px; border-bottom: 1px solid var(--rule); }
table.edit input, table.edit select { width: 100%; padding: 3px 5px; font-size: 13px; }
table.edit input.w-s { width: 56px; } table.edit input.w-m { width: 90px; }
.menu { display: grid; gap: 8px; }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 8px 16px; border-radius: 6px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

.drawer ul.plain button.ghost, .drawer p button.ghost { border: 0; padding: 0; background: none; text-align: left; font-weight: 600; color: var(--ink); }
.drawer ul.plain button.ghost:hover, .drawer p button.ghost:hover { text-decoration: underline; }
.drawer ul.plain button.ghost.danger { color: var(--fail); font-weight: 500; }
