:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-raised: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11,11,11,0.10);
  --grid: #e1e0d9;
  --accent: #eb6834;
  --accent-ink: #ffffff;
  --series-present: #2a78d6;
  --series-absent: #d03b3b;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --status-good-bg: rgba(12,163,12,0.12);
  --status-warning-bg: rgba(250,178,25,0.16);
  --status-critical-bg: rgba(208,59,59,0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0d0d0d; --surface: #1a1a19; --surface-raised: #201f1d;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
    --border: rgba(255,255,255,0.10); --grid: #2c2c2a;
    --accent: #d95926; --series-present: #3987e5;
    --status-good-bg: rgba(12,163,12,0.20); --status-warning-bg: rgba(250,178,25,0.20);
    --status-critical-bg: rgba(208,59,59,0.22);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0d0d0d; --surface: #1a1a19; --surface-raised: #201f1d;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
  --border: rgba(255,255,255,0.10); --grid: #2c2c2a;
  --accent: #d95926; --series-present: #3987e5;
  --status-good-bg: rgba(12,163,12,0.20); --status-warning-bg: rgba(250,178,25,0.20);
  --status-critical-bg: rgba(208,59,59,0.22);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text-primary);
  font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.display { font-family: "Plus Jakarta Sans", "Public Sans", system-ui, sans-serif; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---- App shell ---- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { padding: 4px 10px 18px; }
.sidebar-brand .eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin: 0 0 2px; }
.sidebar-brand .name { font-size: 16px; font-weight: 800; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  color: var(--text-secondary); text-decoration: none; font-size: 13px; font-weight: 600;
}
.nav-link:hover { background: var(--surface-raised); color: var(--text-primary); }
.nav-link.active { background: var(--accent); color: var(--accent-ink); }
.nav-section-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); padding: 14px 10px 4px; }
.sidebar-user { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid var(--border); }
.sidebar-user .who { font-size: 12px; font-weight: 700; }
.sidebar-user .role { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.logout-link { font-size: 12px; color: var(--text-muted); text-decoration: none; }
.logout-link:hover { color: var(--status-critical); }

.main { flex: 1; min-width: 0; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 24px 56px; }

.mobile-topbar { display: none; }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed; z-index: 40; inset: 0 auto 0 0; transform: translateX(-100%);
    transition: transform 0.2s ease; box-shadow: 0 0 0 9999px rgba(0,0,0,0); width: 240px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 9999px rgba(0,0,0,0.35); }
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
    position: sticky; top: 0; z-index: 30;
  }
  .mobile-topbar button { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; color: var(--text-primary); font-size: 18px; line-height: 1; }
  .wrap { padding: 20px 16px 48px; }
}

/* ---- Header ---- */
header.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin: 0 0 6px; }
h1 { font-size: clamp(22px, 4vw, 30px); font-weight: 800; margin: 0 0 6px; text-wrap: balance; }
.subtitle { color: var(--text-secondary); font-size: 14px; margin: 0; }

/* ---- Filter bar ---- */
.filter-bar { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; margin-bottom: 22px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.field input, .field select {
  font: inherit; font-size: 13px; padding: 7px 9px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-raised); color: var(--text-primary);
}
.field input[type="number"] { width: 80px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.btn {
  font: inherit; font-size: 12px; font-weight: 600; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-raised); color: var(--text-secondary);
  cursor: pointer;
}
.btn:hover { color: var(--text-primary); border-color: var(--text-muted); }
.btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--status-critical); border-color: var(--status-critical); }
.status-line { font-size: 12px; color: var(--text-muted); margin-left: 4px; }
.status-line.error { color: var(--status-critical); font-weight: 600; }

/* ---- KPI ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; }
.kpi-label { font-size: 12px; color: var(--text-secondary); margin: 0 0 8px; }
.kpi-value { font-size: 30px; font-weight: 800; line-height: 1; margin: 0 0 8px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin: 0; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.pill.good { background: var(--status-good-bg); color: var(--status-good); }
.pill.warning { background: var(--status-warning-bg); color: #9a6b00; }
:root:not([data-theme="light"]) .pill.warning, :root[data-theme="dark"] .pill.warning { color: var(--status-warning); }
.pill.critical { background: var(--status-critical-bg); color: var(--status-critical); }
.pill .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }

/* ---- Panels & tables ---- */
section.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px 20px 8px; margin-bottom: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.panel-title { font-size: 15px; font-weight: 700; margin: 0; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; }

.table-scroll { overflow-x: auto; }
.attendance-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.attendance-table th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.attendance-table th.num { text-align: right; }
.attendance-table td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.attendance-table tbody tr:last-child td { border-bottom: none; }
.attendance-table tbody tr:hover td { background: var(--surface-raised); }
.attendance-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .attendance-table { min-width: 480px; } }

.group-name { font-size: 13px; font-weight: 600; }
.rate-cell { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.mini-bar-track { position: relative; width: 60px; height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; display: flex; flex-shrink: 0; }
.mini-bar-seg { height: 100%; }
.mini-bar-seg.present { background: var(--series-present); border-radius: 4px 0 0 4px; }
.mini-bar-seg.absent { background: var(--series-absent); border-radius: 0 4px 4px 0; margin-left: 1px; }
.mini-bar-seg.present.full { border-radius: 4px; }
.rate-label { font-size: 13px; font-weight: 700; }
.rate-label.good { color: var(--status-good); }
.rate-label.warning { color: #9a6b00; }
:root:not([data-theme="light"]) .rate-label.warning, :root[data-theme="dark"] .rate-label.warning { color: var(--status-warning); }
.rate-label.critical { color: var(--status-critical); }

.teacher-cell { display: flex; flex-direction: column; gap: 2px; }
.teacher-name { font-size: 12px; font-weight: 600; }
.teacher-badge { font-size: 11px; font-weight: 700; }
.teacher-badge.good { color: var(--status-good); }
.teacher-badge.warning { color: #9a6b00; }
:root:not([data-theme="light"]) .teacher-badge.warning, :root[data-theme="dark"] .teacher-badge.warning { color: var(--status-warning); }
.teacher-badge.critical { color: var(--status-critical); }
.teacher-badge.muted { color: var(--text-muted); font-weight: 500; }

.erp-link { color: inherit; text-decoration: none; border-bottom: 1px dashed var(--border); }
.erp-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

.empty-note { color: var(--text-muted); font-size: 13px; padding: 20px 0; text-align: center; }

.absent-groups { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding-bottom: 20px; }
@media (max-width: 640px) { .absent-groups { grid-template-columns: 1fr; } }
.absent-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface-raised); }
.absent-card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.absent-card-name { font-size: 13px; font-weight: 700; }
.absent-card-count { font-size: 12px; color: var(--status-critical); font-weight: 700; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; background: var(--status-critical-bg); color: var(--text-primary); padding: 4px 9px; border-radius: 999px; border: 1px solid var(--border); }
.meta-row { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.meta-row a { color: inherit; }

.streak-row { display: grid; grid-template-columns: 1fr 200px 110px 120px; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.streak-row:last-child { border-bottom: none; }
@media (max-width: 640px) { .streak-row { grid-template-columns: 1fr; gap: 4px; padding: 12px 0; } .streak-last { text-align: left; } }
.streak-name { font-size: 13px; font-weight: 600; }
.streak-group { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.streak-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; justify-self: start; }
.streak-badge.warning { background: var(--status-warning-bg); color: #9a6b00; }
:root:not([data-theme="light"]) .streak-badge.warning, :root[data-theme="dark"] .streak-badge.warning { color: var(--status-warning); }
.streak-badge.critical { background: var(--status-critical-bg); color: var(--status-critical); }
.streak-last { font-size: 12px; color: var(--text-muted); text-align: right; }

/* ---- Kanban ---- */
.kanban-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .kanban-board { grid-template-columns: 1fr; } }
.kanban-col { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; min-height: 120px; }
.kanban-col-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.kanban-col-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-secondary); }
.kanban-col-count { font-size: 11px; font-weight: 700; color: var(--text-muted); background: var(--surface-raised); border-radius: 999px; padding: 2px 8px; }
.kanban-card { background: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.kanban-card-name { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.kanban-card-group { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.kanban-card textarea {
  width: 100%; font: inherit; font-size: 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--page); color: var(--text-primary); padding: 6px 8px; resize: vertical; min-height: 44px;
}
.kanban-card .row-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; gap: 6px; }
.kanban-add-form { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.kanban-add-form input { font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-raised); color: var(--text-primary); width: 160px; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 26px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p.sub { color: var(--text-secondary); font-size: 13px; margin: 0 0 20px; }
.login-card label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.login-card input { width: 100%; font: inherit; font-size: 14px; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-raised); color: var(--text-primary); margin-bottom: 14px; }
.login-card button { width: 100%; padding: 10px; border-radius: 9px; border: none; background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; }
.login-error { color: var(--status-critical); font-size: 12px; margin-bottom: 12px; }

footer.note { color: var(--text-muted); font-size: 11px; text-align: center; margin-top: 8px; }

.token-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px;
  padding: 10px 16px; font-size: 13px; font-weight: 600; text-align: center;
}
.token-banner.warning { background: var(--status-warning-bg); color: #7a5200; }
:root:not([data-theme="light"]) .token-banner.warning, :root[data-theme="dark"] .token-banner.warning { color: var(--status-warning); }
.token-banner.critical { background: var(--status-critical-bg); color: var(--status-critical); }
.token-banner a { color: inherit; text-decoration: underline; }

.refresh-bar {
  display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 10px;
  padding: 8px 16px; font-size: 12px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.refresh-bar .btn { padding: 5px 11px; font-size: 12px; }
.refresh-muted { color: var(--text-muted); }
.refresh-spin { display: inline-block; animation: refresh-spin 1s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }

.token-status-card { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.token-status-value { font-size: 20px; font-weight: 800; }
