:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1c2330; --muted: #667085; --line: #e3e6eb;
  --accent: #2458d6; --accent-ink: #fff; --ok: #1f8a4c; --warn: #b7791f; --err: #c0392b;
  --okbg: #e7f5ed; --warnbg: #fdf4e3; --errbg: #fbeaea;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --panel: #1c2027; --ink: #e6e9ee; --muted: #98a2b3; --line: #2c323c;
    --accent: #6f9bff; --accent-ink: #0b1020; --okbg: #15301f; --warnbg: #33290f; --errbg: #3a1b1b; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.8rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 .4rem; }
header.top { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header.top a { text-decoration: none; color: var(--ink); }
header.top a.active { color: var(--accent); }
.brand { font-weight: 700; }
.school-name { font-weight: 600; }
.spacer { flex: 1; }
.shell { display: flex; min-height: calc(100vh - 50px); }
nav.side { width: 210px; flex: none; padding: 1rem .6rem; border-right: 1px solid var(--line); background: var(--panel); }
nav.side a { display: block; padding: .3rem .6rem; border-radius: 6px; color: var(--ink); text-decoration: none; }
nav.side a.active, nav.side a:hover { background: var(--bg); color: var(--accent); }
.navhead { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1rem .6rem .3rem; }
main { flex: 1; padding: 1.2rem 1.6rem 3rem; min-width: 0; }
.narrow { max-width: 460px; }
.muted { color: var(--muted); }
.small, table.small { font-size: .88rem; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.count { font-size: .9rem; color: var(--muted); margin-left: .5rem; font-weight: 400; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
table { border-collapse: collapse; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; background: var(--bg); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; }
tr.short td { background: var(--warnbg); }
button, .button { font: inherit; padding: .42rem .85rem; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.danger { color: var(--err); border-color: var(--err); }
button.danger { background: var(--panel); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.link.danger { color: var(--err); }
header.top button.link { color: var(--muted); text-decoration: none; }
form.inline { display: inline; }
form.stack { display: flex; flex-direction: column; gap: .8rem; max-width: 720px; }
form.stack label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; }
label.check { flex-direction: row !important; align-items: center; gap: .4rem; font-weight: 400 !important; }
input, select, textarea { font: inherit; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); }
input[readonly] { background: var(--bg); }
small, .help { color: var(--muted); font-weight: 400; font-size: .82rem; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.flabel { font-weight: 600; }
.req { color: var(--err); }
.checks { display: flex; flex-wrap: wrap; gap: .2rem 1rem; max-height: 220px; overflow: auto; padding: .4rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.gridpick table { width: auto; }
.gridpick td, .gridpick th { padding: .2rem .35rem; }
label.tick { display: inline-flex; align-items: center; gap: 2px; margin-right: 4px; font-size: .75rem; }
label.tick.brk { opacity: .45; }
.flash { padding: .6rem .8rem; border-radius: 8px; background: var(--okbg); margin: .6rem 0; }
.flash.err { background: var(--errbg); }
.flash.warn { background: var(--warnbg); }
.badge { display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .75rem; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.err { color: var(--err); border-color: var(--err); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .7rem; margin: 1rem 0; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; display: flex; flex-direction: column; text-decoration: none; color: var(--ink); }
.tile .num { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile span:last-child { color: var(--muted); font-size: .85rem; }
.tile.bad .num { color: var(--err); }
.tiles.small .num { font-size: 1.15rem; }
ul.cards { list-style: none; padding: 0; display: grid; gap: .6rem; }
ul.cards li { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; }
ul.issues { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
ul.issues li { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 6px; padding: .5rem .7rem; }
ul.issues li.err { border-left-color: var(--err); }
ul.issues li.warn { border-left-color: var(--warn); }
.lvl { font-weight: 700; margin-right: .5rem; }
li.err .lvl { color: var(--err); } li.warn .lvl { color: var(--warn); }
.area { color: var(--muted); margin-right: .5rem; }
ul.errors li { color: var(--err); }
.bar { display: inline-block; width: 90px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.bar span { display: block; height: 100%; }
.bar .ok { background: var(--ok); } .bar .mid { background: var(--warn); } .bar .low { background: var(--err); }
details.box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .9rem; margin: .8rem 0; }
details.box summary { cursor: pointer; font-weight: 600; }
details.menu summary { cursor: pointer; color: var(--accent); }
details.menu[open] { background: var(--bg); padding: .5rem; border-radius: 6px; }
.secret code { font-size: 1.4rem; padding: .4rem .7rem; background: var(--panel); border: 1px dashed var(--accent); border-radius: 6px; user-select: all; }
.filter { margin: .4rem 0 .6rem; width: 260px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .8rem; }
table.formtable input { width: 100%; }
nav.tabs { display: flex; gap: .2rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: 1rem 0; }
.tab { padding: .45rem .8rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-color: var(--accent); }
form.picker { margin-bottom: .8rem; }
.gridwrap { overflow-x: auto; }
table.tt { table-layout: fixed; min-width: 640px; }
table.tt th.time, table.tt thead th:first-child { width: 70px; font-variant-numeric: tabular-nums; }
table.tt td { padding: 3px; height: 3rem; }
table.tt tr.brk td, table.tt tr.brk th { background: var(--bg); height: auto; }
.lesson { border-radius: 5px; padding: 3px 6px; font-size: .8rem; line-height: 1.25; display: flex; flex-direction: column; margin-bottom: 2px; }
.lesson span { color: inherit; opacity: .75; font-size: .75rem; }
.lesson.clash { outline: 2px solid var(--err); }
.c0{background:#dbe8ff;color:#123}.c1{background:#dff5e3;color:#132}.c2{background:#fde7d6;color:#321}.c3{background:#efe0fb;color:#213}
.c4{background:#fff4c2;color:#330}.c5{background:#d8f3f5;color:#123}.c6{background:#fbdde6;color:#312}.c7{background:#e4ecd4;color:#231}
.c8{background:#e6e0d5;color:#221}.c9{background:#d6e4f0;color:#123}.c10{background:#f5dccf;color:#311}.c11{background:#e0e7ff;color:#113}
progress { width: 100%; max-width: 480px; height: 16px; }
@media print {
  header.top, nav.side, nav.tabs, .head .row, form, .tiles, p.muted, .bottombar, .navbtn, .agenda, .gridswitch, .daytabs, .selbar { display: none !important; }
  .ttwrap .gridwrap { display: block !important; }
  main { padding: 0; } body { background: #fff; } table.tt { min-width: 0; font-size: 10px; }
}
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .7rem; }
.preset { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; display: flex; flex-direction: column; gap: .2rem; }
.preset p { margin: 0; }
.preset form { margin-top: auto; }
.warn { color: var(--warn); }
tr.off td { opacity: .55; }
fieldset.box { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .9rem; background: var(--panel); }
fieldset.box legend { font-weight: 600; padding: 0 .3rem; }
details.runrules { margin-top: .5rem; }
details.runrules summary { cursor: pointer; color: var(--accent); }
.prose { max-width: 760px; }
.prose p, .prose li { line-height: 1.55; }
/* timetable editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .editor { grid-template-columns: 1fr; } }
aside.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; position: sticky; top: .5rem; }
aside.panel h3 { margin-top: 0; }
aside.panel ol { padding-left: 1.2rem; }
a.lesson.editable { text-decoration: none; cursor: pointer; }
a.lesson.editable:hover { outline: 2px solid var(--accent); }
.lesson.selected { outline: 3px solid var(--accent); }
a.addhere { display: block; text-align: center; color: var(--muted); text-decoration: none; border: 1px dashed var(--line); border-radius: 5px; }
a.addhere:hover { color: var(--accent); border-color: var(--accent); }
form.target { display: block; margin-top: 2px; }
.target { font-size: .72rem; padding: 2px 5px; border-radius: 4px; border: 1px solid transparent; width: 100%; display: inline-block; }
.target.better { background: #d9f2e1; color: #145a32; border-color: #7cc79a; }
.target.same { background: #eceff3; color: #3c4655; border-color: #c9ced6; }
.target.worse { background: #fbefd9; color: #7a4d00; border-color: #e3b866; }
.target.clash { background: #f9dcdc; color: #8a1c1c; border-color: #e09a9a; }
table.tt.edit td { height: auto; min-width: 90px; }
/* rule builder */
.steps { font-size: .9rem; color: var(--muted); }
.steps .now { color: var(--accent); font-weight: 600; }
.steps .done { color: var(--ink); }
a.preset.choose { text-decoration: none; color: var(--ink); }
a.preset.choose:hover { border-color: var(--accent); }
.taggroups { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .5rem; margin: .4rem 0; }
.taggroup { border: 1px solid var(--line); border-radius: 6px; padding: .4rem .6rem; }
.checks.inline { max-height: none; }
.previewbox { border: 2px solid var(--accent); border-radius: 10px; padding: .6rem .9rem; background: var(--panel); }
.previewbox h3 { margin-top: 0; }

/* ---------- phones and tablets ---------- */
.navtoggle, .gridmode { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.navbtn { display: none; width: 40px; height: 40px; flex-direction: column; justify-content: center; gap: 5px; cursor: pointer; flex: none; }
.navbtn span { display: block; height: 2px; width: 22px; margin: 0 auto; background: var(--ink); border-radius: 2px; }
.desk { display: flex; gap: 1rem; align-items: center; }
.scrim, .bottombar, .mob, .gridswitch, .agenda, .daytabs, .selbar { display: none; }
body:not(.has-school) nav.side { display: none; }
a.why { display: inline-block; font-size: .7rem; color: var(--muted); margin-top: 1px; }
.whybox { border-bottom: 1px solid var(--line); margin-bottom: .8rem; padding-bottom: .6rem; }
.agday { margin-bottom: 1.1rem; }
.agday h3 { margin: .2rem 0 .4rem; }
.agrow { display: flex; gap: .6rem; margin-bottom: .35rem; }
.agtime { width: 3.1rem; flex: none; font-size: .85rem; font-variant-numeric: tabular-nums; padding-top: .3rem; }
.aglessons { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.aglessons .lesson { font-size: .92rem; padding: .45rem .65rem; margin: 0; }
.aglessons .lesson span { font-size: .82rem; }

/* Tablets in portrait and phones: the menu becomes a drawer. */
@media (max-width: 900px) {
  .navbtn { display: flex; }
  .desk, .spacer, .badge.role { display: none; }
  header.top { position: sticky; top: 0; z-index: 30; gap: .5rem; padding: .45rem .7rem; flex-wrap: nowrap; }
  .school-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body:not(.has-school) header.top .brand { flex: 1; }
  nav.side, body:not(.has-school) nav.side {
    display: block; position: fixed; top: 0; left: 0; bottom: 0; width: min(84vw, 300px); z-index: 50;
    transform: translateX(-105%); transition: transform .18s ease-out; overflow-y: auto;
    padding: 1rem .6rem calc(1rem + env(safe-area-inset-bottom)); box-shadow: 0 0 28px rgba(0,0,0,.28);
  }
  .navtoggle:checked ~ .shell nav.side { transform: none; }
  .navtoggle:checked ~ .shell .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .mob { display: block; }
  .mob form { margin: 0; }
  nav.side a, nav.side button.link { display: block; padding: .62rem .7rem; font-size: 1rem; }
  nav.side button.link { color: var(--ink); text-decoration: none; text-align: left; width: 100%; }
  main { padding: 1rem .9rem 1.5rem; }
  body.has-school main { padding-bottom: calc(5.2rem + env(safe-area-inset-bottom)); }
  .bottombar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; background: var(--panel);
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottombar a, .bottombar label {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: .45rem 0 .5rem;
    font-size: .72rem; color: var(--muted); text-decoration: none; cursor: pointer; min-height: 48px;
  }
  .bottombar .ico { font-size: 1.25rem; line-height: 1.15; }
  .bottombar a.active { color: var(--accent); }
  .editor { grid-template-columns: 1fr; }
  aside.panel { position: static; }
  nav.tabs { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .daytabs { display: flex; gap: .35rem; margin: .5rem 0; overflow-x: auto; }
  .daytabs a { padding: .45rem .8rem; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--ink); background: var(--panel); white-space: nowrap; }
  .daytabs a.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  main:has(.selbar) { padding-bottom: calc(9rem + env(safe-area-inset-bottom)); }
  .selbar {
    display: flex; gap: .8rem; align-items: center; position: fixed; z-index: 34; left: .6rem; right: .6rem;
    bottom: calc(3.9rem + env(safe-area-inset-bottom)); margin: 0;
    background: var(--accent); color: var(--accent-ink); padding: .55rem .8rem; border-radius: 10px; box-shadow: 0 4px 14px rgba(0,0,0,.2);
  }
  .selbar span { flex: 1; min-width: 0; }
  .selbar a { color: var(--accent-ink); font-weight: 600; }
}

/* Phones. */
@media (max-width: 760px) {
  h1 { font-size: 1.3rem; }
  h2 { font-size: 1.08rem; }
  .head { align-items: flex-start; }
  form.stack, .narrow { max-width: none; }
  .filter { width: 100%; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .45rem; }
  .tile { padding: .45rem .55rem; }
  .tile .num { font-size: 1.1rem; }
  .tile span:last-child { font-size: .72rem; line-height: 1.2; }
  .tiles.small .num { font-size: 1rem; }
  label.check { align-items: flex-start; }
  .grid2, .presets, .taggroups { grid-template-columns: 1fr; }
  main table:not(.tt) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  main table:not(.tt) th, main table:not(.tt) td { white-space: nowrap; }
  main table:not(.tt) td.small { white-space: normal; min-width: 12rem; }
  .row { gap: .5rem; }
  .upload { display: flex; flex-direction: column; gap: .4rem; align-items: stretch; }
  /* Timetables read as a day-by-day list; the week grid is one tap away. */
  .gridswitch { display: inline-block; margin: .2rem 0 .7rem; color: var(--accent); text-decoration: underline; cursor: pointer; }
  .gridswitch .to-list { display: none; }
  .gridmode:checked + .gridswitch .to-grid { display: none; }
  .gridmode:checked + .gridswitch .to-list { display: inline; }
  .agenda { display: block; }
  .ttwrap .gridwrap { display: none; }
  .gridmode:checked ~ .gridwrap { display: block; }
  .gridmode:checked ~ .agenda { display: none; }
  table.tt.edit { min-width: 0; }
  table.tt th.time, table.tt thead th:first-child { width: 3.3rem; padding-left: .3rem; padding-right: .3rem; }
  table.tt.edit td { min-width: 0; }
  .lesson { font-size: .82rem; }
}

/* Touch screens: bigger targets, and 16px inputs so iOS doesn't zoom. */
@media (pointer: coarse) {
  button, .button, select, input:not([type=checkbox]):not([type=radio]):not([type=file]) { min-height: 44px; }
  input, select, textarea { font-size: 16px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  label.check { padding: .3rem 0; }
  .checks { gap: .1rem 1.2rem; }
  .target { padding: .55rem .35rem; font-size: .8rem; }
  a.why { padding: .35rem .2rem; font-size: .78rem; }
  a.addhere { padding: .5rem 0; }
  nav.tabs .tab { padding: .65rem .85rem; }
  button.link { min-height: 0; padding: .3rem 0; }
  details summary { padding: .35rem 0; }
}

/* ---------- menus, sub-menus and the setup workflow ---------- */
details.navgroup { margin: .15rem 0; }
details.navgroup > summary { list-style: none; cursor: pointer; padding: .35rem .6rem; border-radius: 6px; font-weight: 600; color: var(--ink); }
details.navgroup > summary::-webkit-details-marker { display: none; }
details.navgroup > summary::after { content: "▸"; float: right; color: var(--muted); }
details.navgroup[open] > summary::after { content: "▾"; }
details.navgroup > summary.active { color: var(--accent); }
details.navgroup a { padding-left: 1.2rem !important; font-size: .95rem; }
nav.subnav { display: flex; gap: .25rem; flex-wrap: wrap; margin: -.3rem 0 1rem; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
nav.subnav a { padding: .3rem .7rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: .9rem; white-space: nowrap; }
nav.subnav a:hover { background: var(--panel); color: var(--ink); }
nav.subnav a.active { background: var(--accent); color: var(--accent-ink); }
.stepnav { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-top: 2rem; padding-top: .8rem; border-top: 1px solid var(--line); flex-wrap: wrap; }
.stepnav a.center { color: var(--muted); font-size: .9rem; }
.stepnav a.next { font-weight: 600; }
ol.steps-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
ol.steps-list li { display: flex; align-items: center; gap: .8rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; }
ol.steps-list .num { width: 2rem; height: 2rem; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; background: var(--bg); border: 2px solid var(--line); }
ol.steps-list li.done .num { background: var(--ok); color: #fff; border-color: var(--ok); }
ol.steps-list li.attn .num { background: var(--warn); color: #fff; border-color: var(--warn); }
ol.steps-list li.attn { border-color: var(--warn); }
ol.steps-list .body { flex: 1; min-width: 0; }
ol.steps-list .title a { font-weight: 600; text-decoration: none; }
ol.steps-list .note { margin-top: .15rem; color: var(--ink); }
.setupbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: .6rem .9rem; margin: .8rem 0; }
label.choice { display: flex !important; flex-direction: row !important; gap: .6rem; align-items: flex-start; padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 8px; font-weight: 400 !important; cursor: pointer; }
label.choice:has(input:checked) { border-color: var(--accent); background: var(--bg); }
label.choice.disabled { opacity: .55; }
form.generate:has(input[value=fresh]:checked) .updateonly { display: none; }
@media (max-width: 760px) {
  nav.subnav { flex-wrap: nowrap; overflow-x: auto; }
  .stepnav a.center { order: -1; width: 100%; text-align: center; }
}

/* suggested fixes */
details.fixes { margin-top: .5rem; }
details.fixes > summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.fixcard { border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; margin-top: .45rem; background: var(--bg); }
.fixcard ul { margin: .3rem 0 .45rem; padding-left: 1.2rem; }
.fixcard.accept { border-style: dashed; }
.fixhead { margin-bottom: .15rem; }
