:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #6b7785;
  --accent: #2f6fed;
  --accent-d: #2257c9;
  --border: #e3e7ee;
  --sidebar: #1f2a3a;
  --sidebar-ink: #c5cedd;
  --sidebar-active: #2f6fed;
  --badge: #e7f0ff;
  --ok: #1e8e3e;
  --warn: #b8860b;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 1px 2px rgba(20, 30, 50, .04);
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
h3 { font-size: .95rem; margin: 1.4rem 0 .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); }
.brand-sub { color: var(--muted); font-weight: 400; font-size: .8rem; }

button {
  cursor: pointer; border: none; border-radius: 8px; padding: .55rem .9rem;
  background: var(--accent); color: #fff; font-size: .88rem; font-weight: 500;
  transition: background .15s;
}
button:hover { background: var(--accent-d); }
button.link { background: none; color: var(--accent); padding: .25rem .4rem; font-weight: 500; }
button.link:hover { background: var(--badge); }
button[disabled] { background: #c7cdd6; cursor: not-allowed; }
input, select {
  padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  font-size: .9rem; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--badge); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; color: var(--muted); }

/* ---------- Login ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #2f6fed 0%, #1f2a3a 100%); }
.login-card { background: #fff; padding: 2.2rem; border-radius: 14px; width: 320px;
  display: flex; flex-direction: column; gap: 1rem; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.brand-lg { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.login-card .brand-sub { margin-top: -.8rem; }
.login-card button { margin-top: .4rem; padding: .65rem; }

/* ---------- Shell ---------- */
#shell { display: flex; min-height: 100vh; }
#sidebar {
  width: 230px; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 1.2rem 0; flex-shrink: 0;
}
.brand { font-size: 1.3rem; font-weight: 700; color: #fff; padding: 0 1.3rem 1.2rem; }
.brand .brand-sub { display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 .6rem; flex: 1; }
.nav-item {
  background: none; color: var(--sidebar-ink); text-align: left; border-radius: 8px;
  padding: .6rem .8rem; font-weight: 500; display: flex; align-items: center; gap: .6rem;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item .ico { font-size: 1rem; }
.nav-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: #6b7890; padding: 1.1rem .9rem .3rem; }
.sidebar-foot { padding: 1rem 1.3rem 0; border-top: 1px solid rgba(255,255,255,.08);
  margin-top: .6rem; font-size: .82rem; }
.sidebar-foot #who { color: #fff; margin-bottom: .4rem; }
.sidebar-foot .link { color: var(--sidebar-ink); padding-left: 0; }
.sidebar-foot .link:hover { background: none; color: #fff; }

#content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#page-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.1rem 1.8rem; background: var(--card); border-bottom: 1px solid var(--border);
}
.year-pick { flex-direction: row; align-items: center; gap: .5rem; color: var(--muted); }
#app { padding: 1.6rem 1.8rem; max-width: 1200px; width: 100%; }

/* ---------- Cards & tables ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.2rem; margin-bottom: 1.2rem; }
.table-card { padding: 0; overflow: hidden; }
.table-card table { margin: 0; }
.hint { color: var(--muted); margin: 0 0 1rem; }
.search { width: 100%; max-width: 380px; margin-bottom: 1.1rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem .9rem; border-bottom: 1px solid var(--border); }
th { background: #f7f9fc; color: var(--muted); font-weight: 600; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: #f3f7ff; cursor: pointer; }
tfoot td { font-weight: 600; background: #f7f9fc; }

.badge { background: var(--badge); color: var(--accent); padding: .12rem .5rem;
  border-radius: 999px; font-size: .72rem; font-weight: 600; }
.chip { font-size: .7rem; padding: .1rem .5rem; border-radius: 999px; white-space: nowrap; }
.chip.locked { background: #e7f6ec; color: var(--ok); }
.chip.requested { background: #fff6e2; color: var(--warn); }
.error { color: var(--danger); font-size: .85rem; }
.ok { color: var(--ok); font-size: .85rem; }
.pill { font-size: .72rem; padding: .1rem .5rem; border-radius: 999px; background: #eef1f6; color: var(--muted); }
.pill.admin { background: #fdeaea; color: var(--danger); }

/* ---------- Course editor ---------- */
.back { margin-bottom: .6rem; }
.detail-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .2rem; }
.meta { display: flex; flex-wrap: wrap; gap: 1.3rem; margin: .4rem 0 1.2rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .9rem; }
.needs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem; }
.needs-grid .need-cell { display: grid; grid-template-columns: 1fr 5rem; gap: .5rem; align-items: end; }

.staff-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
#staff-table { min-width: 760px; }
#staff-table th, #staff-table td { padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
#staff-table thead th { position: sticky; top: 0; }
#staff-table .grp { text-align: center; border-left: 1px solid var(--border); background: #eef2f8; }
#staff-table .grp.teach { background: #eaf3ee; }
#staff-table input[type="number"] { width: 3.8rem; padding: .3rem; }
#staff-table select[data-col="person_name"] { width: 13rem; padding: .3rem; }
#staff-table .budgeted, #staff-table .tot, #staff-table .row-delta, #staff-table .tot-delta { text-align: right; font-variant-numeric: tabular-nums; }
#staff-table .budgeted { font-weight: 600; }
.delta { font-variant-numeric: tabular-nums; font-weight: 600; }
.delta.up { color: var(--danger); } .delta.down { color: var(--ok); } .delta.zero { color: var(--muted); font-weight: 400; }
.editor-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }
.editor-actions #save-btn { margin-left: auto; padding: .6rem 1.4rem; }

/* ---------- Baseline panel ---------- */
.baseline-panel { display: flex; flex-wrap: wrap; align-items: center; gap: .9rem;
  padding: .9rem 1.1rem; border-radius: var(--radius); margin: 0 0 1.2rem;
  background: #f4f6fa; border: 1px solid var(--border); }
.baseline-panel.status-locked { background: #edf7f0; border-color: #cfe9d6; }
.baseline-panel.status-requested { background: #fff8e8; border-color: #f3e0a8; }
.bl-status { font-weight: 600; }
.bl-actions { display: flex; gap: .5rem; align-items: center; }
.bl-meta { flex-basis: 100%; color: var(--muted); font-size: .85rem; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .3rem; margin-bottom: 1.1rem; }
.tab { background: #fff; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: .45rem 1rem; }
.tab:hover { background: #f3f7ff; }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Forms ---------- */
.inline-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.inline-form input, .inline-form select { min-width: 9rem; }
#users-table tr.editing input, #users-table tr.editing select,
#people-table tr.editing input, #people-table tr.editing select { width: 100%; min-width: 0; padding: .3rem; }

/* ---------- Formula card ---------- */
.formula-card .formula { font-size: 1rem; line-height: 2.4; color: var(--ink); }
.formula-card .formula input { width: 4rem; text-align: center; font-weight: 600; }
.formula-actions { margin-top: 1.2rem; display: flex; gap: 1rem; align-items: center; }

/* course-access checkbox grid */
.access-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .3rem .8rem; margin: .5rem 0; }
.access-grid label { flex-direction: row; align-items: center; gap: .35rem; color: var(--ink); font-size: .85rem; }
.code-list { display: flex; flex-wrap: wrap; gap: .25rem; }
