:root {
  --accent: #1e3054;
  --accent-soft: #e9edf5;
  --hl: #b5451b;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #e2e5ea;
  --line-2: #eef0f3;
  --text: #1c2230;
  --muted: #6b7385;
  --faint: #a3a9b6;
  --danger: #b42318;
  --warn: #b7791f;
  --ok: #2f7d4f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.16), 0 2px 6px rgba(16,24,40,.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd { font: 600 11px var(--font); background: var(--surface); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ── top bar ─────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 50; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 12px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.weeknav { display: flex; align-items: center; gap: 6px; }
.week-title { display: flex; flex-direction: column; align-items: center; border: 0; background: none; padding: 2px 12px; border-radius: 8px; min-width: 230px; }
.week-title:hover { background: var(--bg); }
.wt-main { font-weight: 700; font-size: 15px; }
.wt-sub { font-size: 12px; color: var(--muted); }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 18px; line-height: 1; display: grid; place-items: center; }
.icon-btn:hover { background: var(--bg); }
.pill-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: 12.5px; }
.pill-btn:hover { background: var(--bg); }
.top-right { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.save-state { white-space: nowrap; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.save-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.save-state[data-state="saving"]::before { background: var(--warn); }
.save-state[data-state="error"] { color: var(--danger); }
.save-state[data-state="error"]::before { background: var(--danger); }

.tabs { display: flex; gap: 4px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 18px 20px 60px; max-width: 1600px; margin: 0 auto; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── buttons & inputs ────────────────────────────── */
a.btn { text-decoration: none; color: inherit; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 12px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.12); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fdf0ef; }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--bg); }
.btn.sm { padding: 3px 9px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--surface); outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 960px) { .two-col { grid-template-columns: 1fr; } }

/* ── schedule toolbar ───────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 600; background: var(--surface); border: 1px solid var(--line); }
.chip.warn { background: #fff7e6; border-color: #f3d79b; color: #8a5a00; }
.chip.ok { background: #ecf7f0; border-color: #bfe3cc; color: var(--ok); }
.chip button { border: 0; background: none; font-weight: 700; color: inherit; padding: 0 2px; text-decoration: underline; }

.empty-week { background: var(--surface); border: 1px dashed #c9ced8; border-radius: var(--radius); padding: 28px; text-align: center; margin-bottom: 16px; }
.empty-week h3 { margin: 0 0 4px; font-size: 17px; }
.empty-week p { margin: 0 0 16px; color: var(--muted); }
.empty-week .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ── grade grid ─────────────────────────────────── */
.grade-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.grade-head { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); border-left: 5px solid var(--gc); }
.grade-head h3 { margin: 0; font-size: 14.5px; }
.grade-head .students { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grade-head .spacer { flex: 1; }
.grid-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 900px; }
table.grid th { font-size: 12px; font-weight: 600; color: var(--muted); text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); background: #fafbfc; }
table.grid th .d { color: var(--text); font-size: 12.5px; }
table.grid th .dn { float: right; font-weight: 600; color: var(--muted); background: var(--bg); border-radius: 999px; padding: 0 7px; }
table.grid th.off .dn { background: #fff1e0; color: #8a5a00; }
table.grid th.rowcol { width: 38px; }
table.grid td { border-bottom: 1px solid var(--line-2); border-right: 1px solid var(--line-2); vertical-align: top; padding: 0; }
table.grid td:last-child { border-right: 0; }
table.grid tr:last-child td { border-bottom: 0; }
td.rownum { text-align: center; color: var(--faint); font-size: 11.5px; padding-top: 8px; position: relative; background: #fafbfc; }
td.rownum .rn-tools { display: none; position: absolute; left: 2px; top: 2px; z-index: 3; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 2px; box-shadow: var(--shadow-lg); }
td.rownum:hover .rn-tools, td.rownum:focus-within .rn-tools { display: flex; }
.rn-tools button { border: 0; background: none; border-radius: 5px; width: 28px; height: 22px; font-size: 12px; color: var(--muted); }
.rn-tools button:hover { background: var(--bg); color: var(--text); }
.rn-tools button.del:hover { color: var(--danger); background: #fdf0ef; }

.cell { position: relative; }
.cell .ci { padding: 6px 8px 7px 10px; min-height: 52px; border-left: 3px solid transparent; }
.cell.has .ci { border-left-color: var(--gc); }
.cell.off { background: repeating-linear-gradient(135deg, #fbfbfc 0 8px, #f5f6f8 8px 16px); }
.cell input.subj { display: block; width: calc(100% - 22px); border: 0; padding: 0; background: transparent; outline: none;
  font-weight: 650; font-size: 12.5px; color: var(--gc); }
.cell input.subj::placeholder { color: transparent; font-weight: 600; }
.cell.empty:hover input.subj:not(.noinh)::placeholder, .cell.empty:focus-within input.subj:not(.noinh)::placeholder { color: color-mix(in srgb, var(--gc) 50%, white); }
.cell.empty input.subj.noinh::placeholder { color: transparent; }
.cell.empty:focus-within input.subj.noinh::placeholder { color: var(--faint); font-weight: 500; }
.cell textarea.les { display: block; width: 100%; border: 0; padding: 0; margin-top: 1px; background: transparent; outline: none; resize: none; overflow: hidden;
  font-size: 13.5px; line-height: 1.35; min-height: 18px; }
.cell textarea.les::placeholder { color: var(--faint); }
.cell:focus-within { background: #f8faff; box-shadow: inset 0 0 0 2px var(--accent); z-index: 2; }
.cell.test .ci { background: color-mix(in srgb, var(--hl) 7%, white); border-left-color: var(--hl); }
.cell.test input.subj { color: var(--hl); }
.cell.needs textarea.les { background: linear-gradient(transparent 85%, #f7d28a 85%); }
.cell .tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.cell .tags:empty { display: none; }
.tag { font-size: 10.5px; font-weight: 600; border-radius: 999px; padding: 0 6px; line-height: 16px; white-space: nowrap; border: 1px solid; }
.tag.link { color: #3657a8; background: #eef3ff; border-color: #cdd9f6; }
.tag.only { color: #6b4f1d; background: #f8f1e3; border-color: #e6d4ad; }
.tag.not { color: #9a3b1f; background: #fdf1ec; border-color: #f0cbbd; }
.tag.gone { color: #777; background: #f1f1f1; border-color: #ddd; }
.tag.flag { color: #fff; background: var(--hl); border-color: var(--hl); }
.cell .more, .cell .grip { position: absolute; top: 4px; width: 20px; height: 20px; border-radius: 5px; border: 0; background: none;
  color: var(--faint); font-size: 14px; line-height: 20px; text-align: center; padding: 0; opacity: 0; }
.cell .more { right: 3px; font-weight: 700; }
.cell .grip { right: 3px; top: 26px; cursor: grab; font-size: 12px; }
.cell:hover .more, .cell:hover .grip, .cell:focus-within .more { opacity: 1; }
.cell .more:hover, .cell .grip:hover { background: var(--bg); color: var(--text); }
.cell.empty .more, .cell.empty .grip { display: none; }
.cell.drop-target { box-shadow: inset 0 0 0 2px #3c7be0; background: #eef4ff; }
.cell.dragging { opacity: .4; }
.cell.flash { animation: flash 1.2s ease; }
@keyframes flash { 0% { background: #fff3c4; } 100% { background: transparent; } }
.cell.subj-missing input.subj::placeholder { color: var(--danger); }

/* ── popover / modal / toasts ───────────────────── */
.popover { position: absolute; z-index: 100; width: 340px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 12px; }
.popover.as-menu { width: auto; min-width: 250px; padding: 5px; }
.popover h4 { margin: 0 0 2px; font-size: 13.5px; }
.popover .sub { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.popover .sec { border-top: 1px solid var(--line-2); padding-top: 9px; margin-top: 9px; }
.popover .sec-title { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.popover .grow { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 3px 0; }
.popover .gname { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--gc, #888); }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px 2px 6px; font-size: 12.5px; cursor: pointer; }
.checks label:has(input:checked) { background: #fdf1ec; border-color: #f0cbbd; color: #9a3b1f; }
.popover .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.menu { position: absolute; z-index: 100; min-width: 230px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 5px; max-height: 70vh; overflow: auto; }
.menu a, .menu button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 7px; text-decoration: none; color: var(--text); font-size: 13px; }
.menu a:hover, .menu button:hover { background: var(--bg); }
.menu .sep { height: 1px; background: var(--line-2); margin: 4px 2px; }
.menu .label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 6px 10px 2px; }
.menu .cnt { margin-left: auto; color: var(--faint); font-size: 12px; }
.menu .cur { font-weight: 700; }

.modal-back { position: fixed; inset: 0; z-index: 200; background: rgba(16,24,40,.35); display: grid; place-items: center; padding: 20px; }
.modal { width: min(520px, 100%); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 20px; max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal p.lead { margin: 0 0 16px; color: var(--muted); }
.modal .opts { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.modal .opt { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.modal .opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.modal .opt b { display: block; }
.modal .opt small { color: var(--muted); }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.inline-checks { display: flex; gap: 14px; flex-wrap: wrap; }
.inline-checks label { display: inline-flex; gap: 6px; align-items: center; }

.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1c2230; color: #fff; border-radius: 10px; padding: 9px 14px; font-size: 13px; box-shadow: var(--shadow-lg); display: flex; gap: 12px; align-items: center; }
.toast button { border: 0; background: none; color: #9fc0ff; font-weight: 700; padding: 0; }
.toast.err { background: var(--danger); }

/* ── weekly & notes ─────────────────────────────── */
.witem { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.witem .wrow { display: flex; gap: 8px; align-items: center; }
.witem input.wsubj { flex: 1; border: 0; outline: none; font-weight: 700; font-size: 14px; padding: 2px 0; background: none; }
.witem textarea.wdesc { width: 100%; border: 0; outline: none; resize: vertical; min-height: 24px; padding: 2px 0; color: #3d4556; background: none; }
.witem:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.gchips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.gchip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; color: var(--muted); }
.gchip.on { background: var(--gc); border-color: var(--gc); color: #fff; }
.note-day { margin-bottom: 10px; }
.note-day .field > span { display: flex; justify-content: space-between; }
.note-day textarea { width: 100%; min-height: 64px; }

/* ── students & settings ────────────────────────── */
.srow select.input { max-width: 120px; }
.srow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line-2); }
.srow:last-child { border-bottom: 0; }
.srow input.sname { flex: 1; min-width: 0; border: 1px solid transparent; border-radius: 7px; padding: 5px 8px; font-weight: 600; outline: none; background: none; }
.srow input.sname:hover { border-color: var(--line); }
.srow input.sname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; align-items: start; }
.settings-grid .card { margin: 0; }
.form-rows { display: flex; flex-direction: column; gap: 10px; }
.form-inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.color-in { width: 38px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.offlist { max-height: 220px; overflow: auto; border: 1px solid var(--line-2); border-radius: 8px; }
.offrow { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.offrow:last-child { border-bottom: 0; }
.offrow .lbl { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-row { display: flex; gap: 10px; }
.stat { flex: 1; background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.help { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.small { font-size: 12px; }

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; padding: 8px 12px; }
  .brand { display: none; }
  .week-title { min-width: 0; }
  main { padding: 12px 10px 60px; }
  .tabs { padding: 0 10px; overflow-x: auto; }
  .save-state { display: none; }
}

/* ── sign-in pages ──────────────────────────────── */
.auth-page { min-height: 100vh; display: grid; place-items: start center; }
.auth-wrap { width: min(420px, 100%); padding: 9vh 16px 40px; }
.auth-brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 9px; margin: 0 0 16px 4px; }
.auth-brand::before { content: ""; width: 12px; height: 12px; border-radius: 3px; background: var(--accent); }
.auth-card { padding: 24px; }
.auth-card h1 { font-size: 20px; margin: 0 0 6px; letter-spacing: -.01em; }
.auth-card p.muted { margin: 0 0 16px; }
.auth-card .form-rows { margin-top: 14px; }
.auth-card .input { padding: 9px 11px; font-size: 15px; }
.auth-submit { justify-content: center; padding: 10px; font-size: 14px; margin-top: 4px; }
.auth-error { background: #fdf0ef; border: 1px solid #f3c7c3; color: var(--danger); border-radius: 8px; padding: 8px 11px; margin: 10px 0 0; font-size: 13.5px; }
.auth-note { color: var(--muted); font-size: 12.5px; text-align: center; margin-top: 14px; }
.auth-below { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 13px; }
.auth-below a { color: var(--muted); }
.linkish { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 0; font-size: 13px; }

/* ── user menu & accounts ───────────────────────── */
.user-btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 10px 3px 4px; font-weight: 600; font-size: 13px; max-width: 200px; }
.user-btn:hover { background: var(--bg); }
.user-btn .av { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 11.5px; flex-shrink: 0; }
.user-btn .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.acct { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.acct th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.acct td { padding: 8px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.acct tr.off td { color: var(--faint); }
table.acct .uname { font-weight: 700; }
table.acct .acts { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 8px; background: var(--bg); color: var(--muted); margin-left: 4px; }
.badge.master { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: #f1f1f1; color: #888; }
.badge.warn { background: #fff7e6; color: #8a5a00; }
.secret { font: 600 18px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg); border: 1px dashed #c9ced8; border-radius: 10px; padding: 12px; text-align: center; letter-spacing: .04em; user-select: all; margin: 12px 0; }
.backup-list { max-height: 260px; overflow: auto; border: 1px solid var(--line-2); border-radius: 8px; margin-top: 8px; }
.backup-list .offrow .lbl { flex: 1; }
.scroll-x { overflow-x: auto; }
