:root {
  --bg: oklch(99% 0.002 240);
  --surface: oklch(100% 0 0);
  --surface-2: oklch(98% 0.003 240);
  --fg: oklch(18% 0.012 250);
  --muted: oklch(54% 0.012 250);
  --border: oklch(92% 0.005 250);
  --border-strong: oklch(86% 0.006 250);
  --accent: oklch(58% 0.18 255);
  --accent-soft: oklch(96% 0.04 255);
  --success: oklch(56% 0.14 145);
  --success-soft: oklch(96% 0.04 145);
  --warn: oklch(62% 0.14 75);
  --warn-soft: oklch(96% 0.05 80);
  --danger: oklch(56% 0.20 25);
  --danger-soft: oklch(96% 0.04 25);
  --teal: oklch(60% 0.10 200);
  --teal-soft: oklch(96% 0.03 200);
  --font-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', system-ui, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "sidebar topbar" "sidebar main";
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 0;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 20px 18px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--fg);
  color: var(--surface);
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 13px; font-weight: 600;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { font-size: 10.5px; font-weight: 400; color: var(--muted); letter-spacing: 0.02em; margin-top: 2px; }
.nav-group {
  padding: 14px 20px 6px;
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 20px;
  color: var(--fg);
  border-left: 2px solid transparent;
  font-size: 13.5px;
  position: relative;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}
.nav-icon { width: 16px; height: 16px; opacity: 0.6; flex-shrink: 0; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 1px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-badge { background: var(--surface); border-color: oklch(85% 0.08 255); color: var(--accent); }

/* ── Topbar ──────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}
.crumbs { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.crumbs strong { color: var(--fg); font-weight: 500; }
.crumbs .sep { color: var(--border-strong); }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.season-pill {
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px;
}
.season-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.user-chip {
  display: flex; gap: 8px; align-items: center;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
}
.avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--fg); color: var(--surface);
  display: grid; place-items: center;
  font-size: 10.5px; font-weight: 600;
  font-family: var(--font-mono);
}

/* ── Main ────────────────────────────────────────────── */
.main {
  grid-area: main;
  padding: 28px 32px 64px;
  overflow-y: auto;
}
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 24px;
  margin-bottom: 24px;
}
.page-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}
.page-sub { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-primary { background: var(--fg); color: var(--surface); border-color: var(--fg); }
.btn-primary:hover { background: oklch(28% 0.012 250); border-color: oklch(28% 0.012 250); }
.btn-accent { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.btn-accent:hover { background: oklch(52% 0.18 255); }
.btn svg { width: 14px; height: 14px; }
.btn-row { display: flex; gap: 8px; align-items: center; }

/* ── Tabs ────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--fg); font-weight: 500; }
.tab .count {
  color: var(--muted);
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 11.5px;
}
.tab.active .count { color: var(--fg); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Filters ─────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-bottom: 12px;
}
.input, .select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  color: var(--fg);
  height: 32px;
}
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px oklch(58% 0.18 255 / 0.12); }
.select {
  padding-right: 28px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2354566c' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 14px; height: 14px; pointer-events: none; }
.search { padding-left: 30px; min-width: 240px; }

.filter-pill {
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.filter-pill:hover { color: var(--fg); border-color: var(--border-strong); }
.filter-pill.active { background: var(--fg); color: var(--surface); border-color: var(--fg); }
.filter-pill .count { font-variant-numeric: tabular-nums; opacity: 0.7; }

.right-of { margin-left: auto; }

/* ── Cards / KPIs ─────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.card-pad { padding: 18px; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.card-title { font-weight: 600; font-size: 14px; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 6px;
}
.kpi-label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.kpi-label .pin { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }
.kpi-value {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.kpi-delta { font-size: 12px; font-variant-numeric: tabular-nums; font-family: var(--font-mono); display: inline-flex; align-items: center; gap: 4px; }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }
.kpi-delta.flat { color: var(--muted); }
.kpi-spark { height: 24px; margin-top: 4px; }

/* ── Table ───────────────────────────────────────────── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.num, tbody td.num { text-align: right; }
thead th.action, tbody td.action { text-align: right; width: 1%; }
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td .primary-cell { display: flex; flex-direction: column; }
td .primary-cell strong { font-weight: 500; }
td .primary-cell .id { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 2px; }
.tabular { font-variant-numeric: tabular-nums; font-family: var(--font-mono); }

/* ── Status / chips ───────────────────────────────────── */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid;
  white-space: nowrap;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-stable, .status-active, .status-live, .status-approved, .status-published { color: var(--success); border-color: oklch(85% 0.06 145); background: var(--success-soft); }
.status-hungry, .status-paused, .status-review { color: var(--warn); border-color: oklch(86% 0.07 80); background: var(--warn-soft); }
.status-sleeping, .status-draft, .status-archived, .status-inactive { color: var(--muted); border-color: var(--border); background: var(--bg); }
.status-recovering, .status-pending, .status-scheduled { color: var(--accent); border-color: oklch(85% 0.08 255); background: var(--accent-soft); }
.status-blocked, .status-error, .status-rejected { color: var(--danger); border-color: oklch(85% 0.08 25); background: var(--danger-soft); }

.stage {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}
.stage-bar { display: inline-flex; gap: 2px; }
.stage-bar i { display: block; width: 6px; height: 14px; border-radius: 1px; background: var(--border); }
.stage[data-stage="0"] .stage-bar i:nth-child(-n+0) { background: var(--accent); }
.stage[data-stage="1"] .stage-bar i:nth-child(-n+1) { background: var(--teal); }
.stage[data-stage="2"] .stage-bar i:nth-child(-n+2) { background: var(--accent); }
.stage[data-stage="3"] .stage-bar i:nth-child(-n+3) { background: var(--accent); }

.role-chip {
  display: inline-flex; padding: 2px 8px;
  border-radius: 4px; font-size: 11.5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.role-chip.student { color: var(--accent); border-color: oklch(85% 0.08 255); background: var(--accent-soft); }
.role-chip.teacher { color: var(--success); border-color: oklch(85% 0.06 145); background: var(--success-soft); }
.role-chip.parent { color: var(--warn); border-color: oklch(86% 0.07 80); background: var(--warn-soft); }
.role-chip.admin { color: var(--fg); border-color: var(--border-strong); background: var(--bg); font-weight: 500; }

.muted { color: var(--muted); }
.dim { color: var(--muted); font-size: 12px; }

.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.icon-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  display: grid; place-items: center;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface); border-color: var(--border); color: var(--fg); }
.icon-btn svg { width: 14px; height: 14px; }

.table-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
}
.pagination { display: flex; gap: 4px; }
.page-btn {
  min-width: 28px; height: 28px; padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  display: inline-grid; place-items: center;
  color: var(--fg);
}
.page-btn:hover { background: var(--surface-2); }
.page-btn.active { background: var(--fg); color: var(--surface); border-color: var(--fg); }
.page-btn:disabled { color: var(--muted); cursor: not-allowed; opacity: 0.5; }

/* ── Dashboard helpers ───────────────────────────────── */
.split-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.split-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.list-rows .row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}
.list-rows .row:last-child { border-bottom: none; }
.list-rows .when { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); width: 64px; flex-shrink: 0; }
.list-rows .what { flex: 1; font-size: 13px; }
.list-rows .what strong { font-weight: 500; }

.metric-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.metric-row:last-child { border-bottom: none; }
.metric-row .label { color: var(--muted); font-size: 13px; }
.metric-row .value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }

.progress-row { display: flex; flex-direction: column; gap: 4px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.progress-row:last-child { border-bottom: none; }
.progress-row .top { display: flex; justify-content: space-between; font-size: 13px; }
.progress-row .value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--muted); }
.progress-bar { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.progress-bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress-bar i.success { background: var(--success); }
.progress-bar i.warn { background: var(--warn); }

/* ── Catalog (index) ─────────────────────────────────── */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.catalog-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  transition: border-color 0.15s, transform 0.15s;
}
.catalog-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.catalog-card .head { display: flex; justify-content: space-between; align-items: flex-start; }
.catalog-card .num { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.catalog-card h3 { font-family: var(--font-display); font-size: 15.5px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.catalog-card p { font-size: 13px; color: var(--muted); margin: 4px 0 0; line-height: 1.5; }
.catalog-card .meta {
  display: flex; gap: 6px; flex-wrap: wrap;
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  margin-top: auto;
}
.catalog-card .meta span { padding: 2px 6px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; }
.catalog-card .open { font-size: 12.5px; color: var(--accent); display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }

.section-head { display: flex; justify-content: space-between; align-items: baseline; margin: 28px 0 12px; }
.section-head h2 { font-family: var(--font-display); font-size: 15px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.section-head small { color: var(--muted); font-size: 12px; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr; grid-template-areas: "topbar" "sidebar" "main"; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); padding: 8px 12px; display: flex; gap: 4px; overflow-x: auto; white-space: nowrap; align-items: center; }
  .brand { padding: 0 8px 0 0; border-right: 1px solid var(--border); margin-right: 4px; }
  .nav-group { display: none; }
  .nav-item { padding: 6px 10px; border-left: none; border-radius: 6px; flex-shrink: 0; font-size: 13px; }
  .nav-item.active { border-left: none; }
  .nav-badge { display: none; }
  .split-2, .split-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .main { padding: 16px; }
  .topbar { padding: 0 14px; }
  .season-pill { display: none; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  table { font-size: 12px; }
  thead th, tbody td { padding: 8px 10px; }
  .filter-bar > .right-of { margin-left: 0; width: 100%; }
  .search { min-width: 0; width: 100%; }
}
