/* School Timetable — styles */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --surface-3: #e6e9f1;
  --text: #121826;
  --muted: #5b6477;
  --faint: #8a93a6;
  --line: #e1e5ee;
  --line-2: #cfd5e2;
  --brand: #2347c5;
  --brand-2: #1b3aa6;
  --brand-soft: #e7ecfd;
  --brand-ink: #ffffff;
  --danger: #c8281d;
  --danger-soft: #fdecea;
  --warn: #a35a00;
  --warn-soft: #fff3df;
  --ok: #0b7a4b;
  --ok-soft: #e3f6ec;
  --now: #f59e0b;
  --now-soft: #fff6e1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .22);
  --r: 12px;
  --r-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e121a; --surface: #161b25; --surface-2: #1c2230; --surface-3: #252c3c;
    --text: #e8ebf2; --muted: #a2abbd; --faint: #78819a; --line: #272e3e; --line-2: #343c4f;
    --brand: #7e9bff; --brand-2: #9db3ff; --brand-soft: #1e2847; --brand-ink: #0b1020;
    --danger: #ff7b70; --danger-soft: #3a1c1c; --warn: #f3b25b; --warn-soft: #362812;
    --ok: #4fd39a; --ok-soft: #12301f; --now: #fbbf24; --now-soft: #33290f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.3);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e121a; --surface: #161b25; --surface-2: #1c2230; --surface-3: #252c3c;
  --text: #e8ebf2; --muted: #a2abbd; --faint: #78819a; --line: #272e3e; --line-2: #343c4f;
  --brand: #7e9bff; --brand-2: #9db3ff; --brand-soft: #1e2847; --brand-ink: #0b1020;
  --danger: #ff7b70; --danger-soft: #3a1c1c; --warn: #f3b25b; --warn-soft: #362812;
  --ok: #4fd39a; --ok-soft: #12301f; --now: #fbbf24; --now-soft: #33290f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.3);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px max(16px, calc((100vw - 1500px) / 2));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; margin-right: auto; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  display: grid; place-items: center; background: var(--brand); color: var(--brand-ink);
}
.logo .ic { width: 20px; height: 20px; }
.brand h1 { font-size: 16px; margin: 0; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand > div { min-width: 0; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.savestate { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.savestate .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.savestate.pending .dot, .savestate.saving .dot { background: var(--now); }
.savestate.error { color: var(--danger); }
.savestate.error .dot { background: var(--danger); }

/* ---------- Layout ---------- */
main { padding: 16px max(16px, calc((100vw - 1500px) / 2)) 40px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card h2, .h2 { font-size: 15px; margin: 0 0 4px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.stack { display: grid; gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .cols2 { grid-template-columns: 1fr; } }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
  touch-action: manipulation;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line-2)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 30px; padding: 0 9px; font-size: 12.5px; }
.btn.icon { padding: 0; width: 36px; }
.btn.sm.icon { width: 30px; }
:is(.btn, .chip, .seg button, .slot, .opt, .mapcell, input, select, textarea, summary):focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 0 12px; min-height: 32px; border-radius: 7px;
  font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.input, select.input, textarea.input {
  min-height: 36px; padding: 0 10px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--surface); min-width: 0;
}
textarea.input { padding: 8px 10px; min-height: 70px; resize: vertical; width: 100%; }
.input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.input.sm { min-height: 30px; font-size: 13px; }
.input.num { width: 70px; text-align: center; }
.input.time { width: 110px; }
input[type="color"].swatch { width: 34px; height: 30px; padding: 2px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--surface); cursor: pointer; }
label.field { display: grid; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
label.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
label.check input { width: 16px; height: 16px; accent-color: var(--brand); }

.search { position: relative; display: flex; align-items: center; }
.search .ic { position: absolute; left: 10px; color: var(--faint); pointer-events: none; width: 16px; height: 16px; }
.search input { padding-left: 32px; width: 240px; }
@media (max-width: 700px) {
  .search { flex: 1 1 160px; }
  .search input { width: 100%; }
  .bar > select.input { flex: 1 1 140px; }
  .bar .spacer { display: none; }
}

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; min-height: 32px;
  border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface);
  font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip small { font-weight: 600; opacity: .75; font-size: 11px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }

/* ---------- Toolbars ---------- */
.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.bar .spacer { flex: 1 1 auto; }
.datenav { display: inline-flex; align-items: center; gap: 4px; }
.datebox { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap; }
.datebox input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.datebox input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }

.nowstrip { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 14px; margin-bottom: 12px; border-radius: var(--r); background: var(--now-soft); border: 1px solid color-mix(in srgb, var(--now) 35%, transparent); font-size: 13.5px; }
.nowstrip b { font-weight: 700; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--now); box-shadow: 0 0 0 0 color-mix(in srgb, var(--now) 60%, transparent); animation: pulse 2s infinite; display: inline-block; margin-right: 6px; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--r); margin-bottom: 12px; font-size: 13.5px; border: 1px solid var(--line); background: var(--surface-2); }
.notice .ic { margin-top: 1px; }
.notice.info { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 25%, transparent); }
.notice.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.notice.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.notice.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }

/* ---------- Timetable grid ---------- */
.tablewrap { overflow: auto; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); max-height: calc(100vh - 170px); -webkit-overflow-scrolling: touch; }
table.tt { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 860px; }
.tt th, .tt td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; vertical-align: middle; }
.tt thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface-2); font-size: 12px; font-weight: 700;
  text-align: center; padding: 8px 4px; white-space: nowrap;
}
.tt thead th .pl { display: block; font-size: 13px; }
.tt thead th small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.tt thead th.now { background: var(--now-soft); box-shadow: inset 0 -3px 0 var(--now); }
.tt .corner { left: 0; z-index: 4; text-align: left; padding-left: 12px; }
.tt .rowh {
  position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left;
  padding: 6px 12px; font-weight: 700; white-space: nowrap; font-size: 13.5px; min-width: 76px;
}
.tt tr.today .rowh { box-shadow: inset 3px 0 0 var(--now); background: var(--now-soft); }
.tt .rowh small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.tt th.brk, .tt td.brk { width: 34px; min-width: 34px; max-width: 34px; padding: 0; background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, var(--surface) 6px 12px); }
.tt td.brk span, .tt th.brk span { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); display: inline-block; }
.tt th.brk { text-align: center; }
.tt th.brk small { display: none; }
.tt td.brk { text-align: center; }
.tt td.slot { min-width: 96px; height: 52px; }
.tt td.slot.now { background: var(--now-soft); }

.lesson {
  --c: #888;
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
  min-height: 44px; height: 100%; padding: 5px 8px; border-radius: 7px;
  background: color-mix(in srgb, var(--c) 15%, var(--surface));
  border-left: 3px solid var(--c);
  text-align: left; line-height: 1.25; transition: opacity .15s, filter .15s, box-shadow .15s;
}
.lesson .l-sub { font-weight: 700; font-size: 12.5px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.lesson .l-t { font-size: 11.5px; color: var(--muted); overflow-wrap: anywhere; }
.lesson .l-cls { font-size: 13px; }
.tag { font-size: 9.5px; font-weight: 800; letter-spacing: .05em; padding: 1px 5px; border-radius: 4px; background: var(--warn); color: #fff; }
.free { color: var(--faint); font-size: 12px; display: block; text-align: center; }
.dim .lesson:not(.hit) { opacity: .25; filter: grayscale(1); }
.lesson.hit { box-shadow: 0 0 0 2px var(--c); }

.tt tfoot td { background: var(--surface-2); position: sticky; bottom: 0; z-index: 2; vertical-align: top; }
.tt tfoot .rowh { background: var(--surface-2); z-index: 3; }
.freelist { display: flex; flex-wrap: wrap; gap: 3px; max-height: 120px; overflow: auto; }
.freelist span { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); white-space: nowrap; }

/* Editor-specific cell states */
.tt.edit td.slot { cursor: pointer; position: relative; }
.tt.edit td.slot:hover { background: var(--surface-2); }
.tt.edit td.slot .empty { display: grid; place-items: center; height: 44px; border: 1.5px dashed var(--line-2); border-radius: 7px; color: var(--faint); font-size: 18px; }
.tt.edit td.slot:hover .empty { border-color: var(--brand); color: var(--brand); }
.tt.edit td.slot.sel { box-shadow: inset 0 0 0 2px var(--brand); }
.tt.edit td.slot.clash .lesson { box-shadow: 0 0 0 2px var(--danger); background: color-mix(in srgb, var(--danger) 16%, var(--surface)); }
.tt.edit td.slot.absent .lesson { box-shadow: 0 0 0 2px var(--warn); background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--warn) 18%, var(--surface)) 0 6px, var(--surface) 6px 12px); }
.tt.edit td.slot.dragover { background: var(--brand-soft); box-shadow: inset 0 0 0 2px var(--brand); }
.tt.edit td.slot.swapsrc { box-shadow: inset 0 0 0 2px var(--now); }
.lockic { position: absolute; top: 6px; right: 6px; width: 12px; height: 12px; color: var(--muted); }
.tt.edit .rowh { cursor: pointer; }
.tt.edit tr.focus .rowh { box-shadow: inset 3px 0 0 var(--brand); background: var(--brand-soft); }

/* ---------- Agenda (mobile) ---------- */
.agenda { display: none; }
@media (max-width: 760px) {
  .weekwrap .tablewrap { display: none; }
  .agenda { display: block; }
}
.agenda-list { display: grid; gap: 6px; margin-top: 10px; }
.ag-item { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: stretch; }
.ag-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 6px; text-align: right; }
.ag-time b { display: block; color: var(--text); font-size: 13px; }
.ag-item.now .ag-time b { color: var(--now); }
.ag-item.now .lesson, .ag-item.now .ag-free { box-shadow: 0 0 0 2px var(--now); }
.ag-brk { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); text-align: center; padding: 4px; border-top: 1px dashed var(--line-2); border-bottom: 1px dashed var(--line-2); margin: 2px 0 2px 74px; }
.ag-free { border: 1.5px dashed var(--line-2); border-radius: 7px; padding: 10px; color: var(--faint); font-size: 12.5px; }

/* ---------- Legend / stat cards ---------- */
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.legend .lesson { min-height: 0; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; min-width: 120px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.wide { flex: 1; min-width: 220px; }
@media (max-width: 700px) {
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { min-width: 0; padding: 8px 10px; }
  .stat b { font-size: 18px; }
  .stat.wide { grid-column: 1 / -1; min-width: 0; }
}

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; scrollbar-width: none; }
.tabs button {
  border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center;
}
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count { font-size: 11px; background: var(--danger); color: #fff; border-radius: 999px; padding: 0 6px; }

.panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.bal { display: grid; gap: 6px; }
.bal-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 12.5px; align-items: center; }
.bal-row .bar { grid-column: 1 / -1; height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; margin: 0; display: block; }
.bal-row .bar i { display: block; height: 100%; background: var(--c, var(--brand)); border-radius: 4px; }
.bal-row.over b { color: var(--danger); }
.bal-row.done b { color: var(--ok); }
.problems { display: grid; gap: 4px; max-height: 420px; overflow: auto; }
.prob { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; padding: 6px 8px; border-radius: 6px; background: var(--surface-2); border: 0; text-align: left; cursor: pointer; width: 100%; }
.prob:hover { background: var(--surface-3); }
.prob .ic { width: 15px; height: 15px; margin-top: 1px; }
.prob.error .ic { color: var(--danger); }
.prob.warn .ic { color: var(--warn); }
.allgood { display: flex; gap: 8px; align-items: center; color: var(--ok); font-weight: 600; font-size: 13px; }

/* Mapping matrix */
table.matrix { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.matrix th, .matrix td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; }
.matrix thead th { position: sticky; top: 0; background: var(--surface-2); z-index: 3; font-size: 12px; padding: 6px; vertical-align: bottom; min-width: 128px; }
.matrix thead th button { border: 0; background: none; cursor: pointer; font-weight: 700; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; padding: 4px; border-radius: 6px; }
.matrix thead th button:hover { background: var(--surface-3); }
.matrix .rowh { position: sticky; left: 0; background: var(--surface); z-index: 2; font-weight: 700; padding: 6px 12px; white-space: nowrap; }
.matrix thead .rowh { z-index: 4; background: var(--surface-2); }
.dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; display: inline-block; }
.mapcell {
  width: 100%; min-height: 48px; border: 1px solid transparent; border-radius: 7px; cursor: pointer; text-align: left; padding: 5px 8px;
  background: color-mix(in srgb, var(--c) 12%, var(--surface)); display: flex; flex-direction: column; gap: 1px; font-size: 12px; line-height: 1.25;
}
.mapcell:hover { border-color: var(--c); }
.mapcell b { font-size: 11px; color: var(--muted); font-weight: 600; }
.mapcell.unset { background: transparent; border: 1.5px dashed var(--line-2); color: var(--faint); align-items: center; justify-content: center; }
.mapcell.unset:hover { border-color: var(--brand); color: var(--brand); }
.mapcell.warn { border-color: var(--warn); }
.total { font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; white-space: nowrap; font-size: 13px; }
.total.over { color: var(--danger); }
.total.under { color: var(--warn); }
.total.ok { color: var(--ok); }

/* Data tables */
table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.list td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.list tr:last-child td { border-bottom: 0; }
.list .input { width: 100%; }
.list .actions { white-space: nowrap; text-align: right; }
.scrollx { overflow-x: auto; }
.pill { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; display: inline-block; margin: 1px; }
.loadbar { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.loadbar .track { width: 80px; height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.loadbar .track i { display: block; height: 100%; background: var(--brand); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(10, 14, 24, .45); animation: fade .12s ease-out; }
.dialog { width: min(520px, 100%); max-height: min(86vh, 860px); display: flex; flex-direction: column; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); animation: pop .14s ease-out; }
.dialog.wide { width: min(760px, 100%); }
.dialog header { display: flex; align-items: flex-start; gap: 10px; padding: 16px 16px 10px; }
.dialog header h2 { margin: 0; font-size: 16px; }
.dialog header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.dialog .body { padding: 4px 16px 16px; overflow: auto; }
.dialog footer { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); }
@media (max-width: 600px) {
  .modal { place-items: end stretch; padding: 0; }
  .dialog, .dialog.wide { width: 100%; max-height: 90vh; border-radius: 16px 16px 0 0; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .modal, .dialog { animation: none; } }

.optgroup { margin: 8px 0 4px; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.opts { display: grid; gap: 6px; }
.opt {
  --c: #888; display: grid; grid-template-columns: 4px 1fr auto; gap: 10px; align-items: center; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.opt:hover { border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, var(--surface)); }
.opt::before { content: ""; align-self: stretch; border-radius: 3px; background: var(--c); }
.opt .o-main b { display: block; font-size: 13.5px; }
.opt .o-main span { font-size: 12px; color: var(--muted); }
.opt .o-side { text-align: right; font-size: 12px; white-space: nowrap; }
.opt .o-side .need { font-weight: 700; font-variant-numeric: tabular-nums; }
.opt .o-side .st { display: block; font-size: 11.5px; }
.opt.cur { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.opt.busy { background: var(--surface-2); }
.opt.busy .o-main b { color: var(--muted); }
.st.ok { color: var(--ok); }
.st.bad { color: var(--danger); }
.st.warn { color: var(--warn); }
.checklist { display: grid; gap: 2px; max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 4px; }
.checklist label { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px; }
.checklist label:hover { background: var(--surface-2); }
.checklist label small { margin-left: auto; color: var(--muted); font-size: 12px; }
.checklist input { width: 16px; height: 16px; accent-color: var(--brand); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-2); border-radius: var(--r-sm); overflow: hidden; }
.stepper button { border: 0; background: var(--surface-2); width: 36px; height: 36px; cursor: pointer; font-size: 18px; font-weight: 600; }
.stepper input { width: 52px; height: 36px; border: 0; text-align: center; background: var(--surface); font-weight: 700; font-size: 15px; }

/* Menus */
.menuwrap { position: relative; display: inline-block; }
.menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 270px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 4px; }
.menu button { display: grid; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-weight: 600; font-size: 13.5px; }
.menu button small { font-weight: 400; color: var(--muted); font-size: 12px; }
.menu button:hover { background: var(--surface-2); }

/* Toasts */
#toasts { position: fixed; z-index: 200; left: 50%; bottom: 18px; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: center; padding: 11px 14px; border-radius: 10px; background: #1b2232; color: #fff; box-shadow: var(--shadow-lg); font-size: 13.5px; animation: pop .16s ease-out; }
.toast.error { background: #9b1c13; }
.toast.ok { background: #0c5d3a; }
.toast .btn { margin-left: auto; min-height: 28px; background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }

/* Login + empty states */
.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-state h2 { color: var(--text); font-size: 17px; margin: 0 0 6px; }
.loader { display: grid; place-items: center; min-height: 50vh; color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.foot { text-align: center; color: var(--faint); font-size: 12px; padding: 20px 16px 28px; }
.foot a { color: inherit; }

@media (max-width: 700px) {
  .top { gap: 8px; }
  .clock .lbl, .hide-sm { display: none !important; }
  .bar > * { max-width: 100%; }
  .bar .seg { width: 100%; }
  .bar .seg button { flex: 1; justify-content: center; }
  .tt td.slot { min-width: 88px; }
  .tablewrap { max-height: none; }
}

/* ---------- Print ---------- */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  :root { --bg: #fff; --surface: #fff; --surface-2: #f3f4f6; --line: #c9ced8; --muted: #444; }
  body { font-size: 11px; background: #fff; }
  .top, .bar, .nowstrip, .noprint, #toasts, .foot, .agenda, .tabs { display: none !important; }
  main { padding: 0; }
  .print-title { display: block !important; margin: 0 0 8px; font-size: 16px; }
  .tablewrap { max-height: none; overflow: visible; box-shadow: none; display: block !important; }
  .weekwrap .tablewrap { display: block !important; }
  table.tt { min-width: 0; }
  .tt thead th, .tt .rowh, .tt tfoot td { position: static; }
  .tt td.slot { min-width: 0; height: auto; }
  .lesson { min-height: 0; padding: 3px 5px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .dim .lesson:not(.hit) { opacity: 1; filter: none; }
}
.print-title { display: none; }
