:root {
  --bg: #f4f6fa; --surface: #fff; --text: #1c2433; --muted: #5d6b82; --line: #dfe4ee;
  --accent: #1f5fbf; --accent-d: #174a96; --accent-bg: #e8f0fc; --ok: #1d7a46; --ok-bg: #e5f5ec;
  --warn: #9a6200; --warn-bg: #fff3d6; --bad: #b3261e; --bad-bg: #fdecea; --radius: 10px;
  --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 14px rgba(20,30,50,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151d; --surface: #1a202b; --text: #e8edf6; --muted: #93a0b8; --line: #2b3444;
    --accent: #6ea2ff; --accent-d: #8db6ff; --accent-bg: #1d2a42; --ok: #5fd08c; --ok-bg: #16301f;
    --warn: #f0b84a; --warn-bg: #352a10; --bad: #ff8a80; --bad-bg: #3a1c1a; --shadow: none; }
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; } h2 { font-size: 1.1rem; margin: 0 0 .75rem; } h3 { font-size: 1rem; margin: 0 0 .5rem; }
a { color: var(--accent); } p { margin: .25rem 0 .75rem; }
.boot { padding: 2rem; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; padding: .25rem .5rem 1rem; font-size: 1.05rem; }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .9rem .5rem .25rem; }
.nav a { display: block; padding: .5rem .6rem; border-radius: 8px; color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--accent-bg); } .nav a.active { background: var(--accent-bg); color: var(--accent-d); font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 1rem; max-width: 1200px; width: 100%; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: inline-flex; }
}

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card-head { display: flex; gap: .5rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: .45rem .8rem; min-height: 38px; }
.btn:hover { border-color: var(--accent); } .btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.primary:hover { background: var(--accent-d); }
.btn.danger { color: var(--bad); border-color: var(--bad); } .btn.small { padding: .2rem .55rem; min-height: 30px; font-size: .85rem; }
.btn.ghost { border-color: transparent; background: transparent; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; min-height: 38px; max-width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; min-height: 160px; font-family: ui-monospace, monospace; font-size: .85rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
.field { display: flex; flex-direction: column; } .field input, .field select { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem; }
.checks { display: flex; flex-wrap: wrap; gap: .25rem .9rem; } .checks label { display: inline-flex; gap: .35rem; align-items: center; color: var(--text); font-size: .95rem; margin: 0; }
.form-error { color: var(--bad); min-height: 1.2rem; margin: .5rem 0 0; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .75rem; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
tr:hover td { background: color-mix(in srgb, var(--accent-bg) 45%, transparent); }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--accent-bg); color: var(--accent-d); margin: .1rem; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.bad { background: var(--bad-bg); color: var(--bad); }
.notice { padding: .7rem .9rem; border-radius: 8px; margin-bottom: .75rem; background: var(--accent-bg); }
.notice.warn { background: var(--warn-bg); color: var(--warn); } .notice.bad { background: var(--bad-bg); color: var(--bad); } .notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice ul { margin: .3rem 0 0 1.1rem; padding: 0; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; }
.stat b { display: block; font-size: 1.6rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tab { border: 0; background: none; font: inherit; color: var(--muted); padding: .55rem .9rem; cursor: pointer; border-bottom: 3px solid transparent; }
.tab.active { color: var(--accent-d); border-bottom-color: var(--accent); font-weight: 600; }
.tree-item { border-left: 3px solid var(--line); padding-left: .75rem; margin: .5rem 0 .5rem .25rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line); border-radius: 999px; padding: .1rem .2rem .1rem .7rem; margin: .15rem; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: .1rem .35rem; }
.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: .4rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 1.5rem; color: var(--muted); }

/* modal + toast */
dialog.modal { border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem; width: min(640px, 94vw); background: var(--surface); color: var(--text); max-height: 90vh; overflow-y: auto; }
dialog.modal.wide { width: min(980px, 96vw); }
dialog::backdrop { background: rgba(10,15,25,.5); }
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--ok); padding: .6rem .9rem; border-radius: 8px; box-shadow: var(--shadow); max-width: 340px; }
.toast.bad { border-left-color: var(--bad); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { margin: 0 auto; width: min(420px, 100%); }

/* timetable grid */
.tt { min-width: 640px; }
.tt th, .tt td { text-align: center; }
.tt td.cell { cursor: pointer; min-width: 120px; height: 64px; font-size: .85rem; }
.tt td.cell.filled { background: var(--accent-bg); } .tt td.cell.readonly { cursor: default; }
.tt td.cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.tt .t { color: var(--muted); font-size: .75rem; display: block; }
.mt { margin-top: 1rem; }
.btn[data-full] { width: 100%; }
.stat-link { text-decoration: none; color: inherit; } .stat-link:hover { border-color: var(--accent); }

.tbl-filter { width: 100%; max-width: 320px; margin: 0 0 .5rem; }
