/* ====================================================================
   SCHOOL GRADING SYSTEM — AKOBEN DESIGN SYSTEM v1.0
   Warm, editorial, data-dense. OKLCH color, Fraunces + system-sans,
   strict 4pt spatial grid. Every token from the Akoben spec.
   ==================================================================== */

/* ---------- AKOBEN DESIGN TOKENS ---------- */
:root {
  /* ===== NEUTRALS (tinted warm, hue ~60-74°) ===== */
  --bg:            oklch(0.984 0.006 74);
  --surface:       oklch(0.998 0.003 74);
  --surface-2:     oklch(0.965 0.008 74);
  --border:        oklch(0.905 0.009 74);
  --border-strong: oklch(0.84 0.012 74);
  --muted:         oklch(0.58 0.016 60);
  --ink-2:         oklch(0.44 0.018 58);
  --ink:           oklch(0.27 0.021 58);

  /* ===== BRAND & ACCENT ===== */
  --clay:       oklch(0.53 0.142 42);
  --clay-dark:  oklch(0.44 0.132 42);
  --clay-tint:  oklch(0.95 0.03 46);
  --gold:       oklch(0.80 0.118 82);
  --gold-tint:  oklch(0.95 0.03 82);
  --green:      oklch(0.58 0.108 156);
  --green-tint: oklch(0.95 0.03 156);
  --red:        oklch(0.57 0.168 26);
  --red-tint:   oklch(0.95 0.03 26);
  --blue:       oklch(0.58 0.09 245);
  --blue-tint:  oklch(0.95 0.03 245);

  /* ===== ALIASES (for existing class compatibility) ===== */
  --color-bg:           var(--bg);
  --color-surface:      var(--surface);
  --color-surface-2:    var(--surface-2);
  --color-border:       var(--border);
  --color-border-strong: var(--border-strong);
  --color-text:         var(--ink);
  --color-text-soft:    var(--ink-2);
  --color-text-muted:   var(--muted);
  --color-text-inverse: var(--surface);
  --color-primary:      var(--clay);
  --color-primary-hover: var(--clay-dark);
  --color-primary-light: var(--clay-tint);
  --color-primary-text:  var(--clay-dark);
  --color-success:       var(--green);
  --color-success-light: var(--green-tint);
  --color-warning:       var(--gold);
  --color-warning-light: var(--gold-tint);
  --color-error:         var(--red);
  --color-error-light:  var(--red-tint);

  /* ===== SIDEBAR ===== */
  --sidebar-bg:          var(--surface);
  --sidebar-border:      var(--border);
  --sidebar-text:        var(--ink-2);
  --sidebar-text-muted:  var(--muted);
  --sidebar-hover:       var(--surface-2);
  --sidebar-active-bg:   var(--clay-tint);
  --sidebar-active-text: var(--clay-dark);
  --sidebar-active-border: var(--clay);

  /* ===== SHADOWS (whisper-quiet, warm-tinted) ===== */
  --shadow-xs: 0 1px 2px oklch(0.27 0.021 58 / 0.04);
  --shadow-sm: 0 1px 3px oklch(0.27 0.021 58 / 0.05), 0 1px 2px oklch(0.27 0.021 58 / 0.04);
  --shadow-md: 0 4px 14px oklch(0.27 0.021 58 / 0.07);
  --shadow-lg: 0 10px 15px -3px oklch(0.27 0.021 58 / 0.06), 0 4px 6px -4px oklch(0.27 0.021 58 / 0.04);
  --shadow-xl: 0 20px 25px -5px oklch(0.27 0.021 58 / 0.07), 0 8px 10px -6px oklch(0.27 0.021 58 / 0.04);

  /* ===== RADIUS ===== */
  --radius-sm: 7px;   /* nav items, small chips, seg buttons */
  --radius:    10px;  /* buttons, inputs, avatars, mini-cards */
  --radius-lg: 16px;  /* panels, stat strip, large containers */
  --radius-xl: 20px;
  --radius-full: 9999px;
  --radius-md: var(--radius);  /* compat alias */
  --radius-pill: var(--radius-full);

  /* ===== SPACING (4pt base grid) ===== */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;
  /* compat aliases */
  --space-1: var(--space-xs);
  --space-2: var(--space-sm);
  --space-3: var(--space-md);
  --space-4: var(--space-lg);
  --space-5: var(--space-xl);
  --space-6: var(--space-2xl);
  --space-8: var(--space-2xl);
  --space-10: var(--space-3xl);
  --space-12: var(--space-3xl);

  /* ===== TYPOGRAPHY ===== */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Segoe UI", "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-serif: "Fraunces", "Iowan Old Style", "Apple Garamond", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;

  /* Type scale (ratio ≈ 1.25) */
  --text-xs: 11px;       /* eyebrow labels */
  --text-sm: 13.5px;     /* secondary / meta */
  --text-base: 15px;     /* body / UI label */
  --text-lg: 19px;       /* section head */
  --text-xl: 24px;
  --text-2xl: 30px;      /* page title */
  --text-3xl: 38px;
  --text-4xl: 46px;      /* display */
  --text-5xl: 58px;

  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* ===== MOTION ===== */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 130ms var(--ease);
  --t-base: 250ms var(--ease);
  --t-slow: 350ms var(--ease);

  /* ===== Z-INDEX ===== */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal-backdrop: 300;
  --z-modal: 310;
  --z-toast: 400;

  /* ===== LAYOUT ===== */
  --nav-h: 56px;
  --tabbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ---------- RESET & BASE ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
  padding-top: var(--safe-top);
  text-rendering: optimizelegibility;
}
a { color: var(--clay-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
input, select, textarea {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
img { max-width: 100%; height: auto; display: block; }
table { border-collapse: collapse; }
:focus { outline: none; }

/* ---------- UTILITY ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ====================================================================
   LOGIN SCREEN
   ==================================================================== */
#login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-xl);
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-3xl) var(--space-2xl);
}
.login-header { text-align: center; margin-bottom: var(--space-2xl); }
.login-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-lg);
  background: var(--clay);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 14px oklch(0.53 0.142 42 / 0.25);
}
.login-title {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.login-subtitle {
  font-size: var(--text-sm);
  color: var(--muted);
  margin-top: var(--space-xs);
}

.login-form .form-field { margin-bottom: var(--space-lg); }
.login-form .form-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--muted);
  margin-bottom: var(--space-xs);
  padding-left: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.login-form .input-wrapper {
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.login-form .input-wrapper:focus-within {
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-tint);
}
.login-form .form-input {
  width: 100%;
  padding: 12px 14px;
  font-size: var(--text-base);
  border: none;
  background: transparent;
  padding-left: 40px;
}
.login-form .input-icon { position: absolute; left: 12px; color: var(--muted); }
.login-form .form-hint { display: none; }

.login-form .btn-block {
  width: 100%;
  min-height: 44px;
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  border-radius: var(--radius);
  margin-top: var(--space-lg);
}

.login-footer {
  text-align: center;
  margin-top: var(--space-2xl);
  font-size: var(--text-xs);
  color: var(--muted);
}

/* Login message */
.msg { font-size: var(--text-sm); padding: var(--space-sm) var(--space-lg); }
.msg.err { color: var(--red); }

/* ====================================================================
   APP SHELL
   ==================================================================== */
#app { display: none; min-height: 100vh; min-height: 100dvh; }

/* ---------- NAVIGATION BAR (sticky topbar) ---------- */
.topbar {
  position: fixed;
  top: var(--safe-top);
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--nav-h);
  background: oklch(0.998 0.003 74 / 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-lg);
  padding-left: max(var(--space-lg), var(--safe-left));
  padding-right: max(var(--space-lg), var(--safe-right));
}
.topbar-left { display: flex; align-items: center; gap: var(--space-sm); flex: 1; }
.topbar-right { display: flex; align-items: center; gap: var(--space-sm); }
.topbar-spacer { flex: 1; }
.nav-toggle { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  letter-spacing: -0.015em;
  color: var(--ink);
}
.brand-icon {
  width: 28px;
  height: 28px;
  background: var(--clay);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

/* User menu */
.user-menu { position: relative; }
.user-avatar-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: opacity var(--t-fast);
}
.user-avatar-btn:active { opacity: 0.6; }
.avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--clay);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: var(--font-semibold);
  flex-shrink: 0;
}
.user-name { font-size: var(--text-sm); font-weight: var(--font-medium); }
.user-role {
  font-size: 10px;
  color: #fff;
  background: var(--clay);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: var(--font-semibold);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: none;
  z-index: 200;
}
.dropdown-menu.show { display: block; animation: dropdownIn var(--t-base); }
@keyframes dropdownIn { from { opacity: 0; transform: translateY(-8px) scale(0.96); } to { opacity: 1; transform: none; } }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 12px var(--space-lg);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: var(--text-base);
  cursor: pointer;
  transition: background var(--t-fast);
  border-bottom: 1px solid var(--border);
}
.dropdown-item:active { background: var(--surface-2); }
.dropdown-item.danger { color: var(--red); }
.dropdown-divider { height: 1px; background: var(--border); }

/* ---------- LAYOUT ---------- */
.layout {
  display: flex;
  flex-direction: column;
  padding-top: var(--nav-h);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
}
.sidebar, .nav-backdrop, .nav-toggle, #nav-toggle, #nav-close, #nav-backdrop { display: none !important; }
.layout.nav-open { overflow: hidden; }

/* ---------- MAIN CONTENT ---------- */
.main { flex: 1; min-height: 0; }

/* ---------- PAGES ---------- */
.page {
  display: none;
  animation: pageIn var(--t-base);
}
.page.active { display: block; }
@keyframes pageIn { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }

/* Page header — Akoben large title (Fraunces) */
.page-header,
.page-header-flex {
  padding: var(--space-lg) var(--space-lg) var(--space-md);
  padding-left: max(var(--space-lg), var(--safe-left));
  padding-right: max(var(--space-lg), var(--safe-right));
}
.page-header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
}
.page-title {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.15;
  text-wrap: balance;
}
.page-desc {
  font-size: var(--text-sm);
  color: var(--muted);
  margin-top: var(--space-xs);
  text-wrap: pretty;
}
.page-header-flex .page-desc { margin-top: 2px; }

/* ====================================================================
   STAT CARDS (Dashboard) — Akoben stat strip
   ==================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 0 var(--space-lg) var(--space-lg);
  margin-left: max(var(--space-lg), var(--safe-left));
  margin-right: max(var(--space-lg), var(--safe-right));
}
.stat-card {
  background: var(--surface);
  padding: var(--space-lg);
  box-shadow: none;
  position: relative;
  overflow: hidden;
  transition: background var(--t-fast);
}
.stat-card:active { background: var(--surface-2); }
.stat-card .n {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: var(--font-semibold);
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-card .l {
  font-size: var(--text-xs);
  color: var(--muted);
  font-weight: var(--font-semibold);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.stat-card .icon { display: none; }
.stat-card:hover { transform: none; box-shadow: none; }

/* Activity list */
.section { margin-bottom: var(--space-2xl); padding: 0 var(--space-lg); padding-left: max(var(--space-lg), var(--safe-left)); padding-right: max(var(--space-lg), var(--safe-right)); }
.section-header { margin-bottom: var(--space-sm); }
.section-title { font-family: var(--font-serif); font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--ink); }

.activity-list { padding: 0; }
.activity-list .activity-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
}
.activity-list .activity-item:last-child { border-bottom: none; }
.activity-list .activity-icon {
  font-size: 20px;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.activity-list .activity-content { flex: 1; min-width: 0; }
.activity-list .activity-text { font-size: var(--text-base); font-weight: var(--font-medium); color: var(--ink); }
.activity-list .activity-meta { font-size: var(--text-sm); color: var(--muted); margin-top: 2px; }
.activity-list .activity-empty { padding: var(--space-2xl); text-align: center; color: var(--muted); font-size: var(--text-sm); }
.empty { padding: var(--space-2xl); text-align: center; color: var(--muted); }

/* ====================================================================
   PANELS / CARDS
   ==================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.card-header {
  padding: var(--space-lg) var(--space-lg);
  border-bottom: 1px solid var(--border);
}
.card-title { font-family: var(--font-serif); font-size: var(--text-lg); font-weight: var(--font-semibold); }
.card-subtitle { font-size: var(--text-sm); color: var(--muted); }
.card-body { padding: var(--space-xl); }
.card-footer { padding: var(--space-md) var(--space-lg); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--space-sm); }

/* ====================================================================
   BUTTONS — Akoben style
   ==================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px var(--space-lg);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  line-height: 1.3;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; }

.btn-sm { padding: 6px 12px; font-size: var(--text-xs); min-height: 32px; border-radius: var(--radius-sm); }
.btn-lg { padding: 12px var(--space-xl); font-size: var(--text-base); min-height: 48px; }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--clay);
  color: #fff;
  border-color: var(--clay);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) {
  background: var(--clay-dark);
  border-color: var(--clay-dark);
}
.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--clay);
}
.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border-color: transparent;
  box-shadow: none;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--clay-dark);
}
.btn-danger {
  background: var(--red-tint);
  color: var(--red);
  border-color: oklch(0.57 0.168 26 / 0.2);
}
.btn-danger:hover:not(:disabled) {
  background: oklch(0.57 0.168 26 / 0.12);
}
.btn-success {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.btn-outline {
  background: transparent;
  color: var(--clay-dark);
  border-color: var(--clay);
}
.btn-outline:hover:not(:disabled) {
  background: var(--clay-tint);
}
.btn svg { width: 1em; height: 1em; }

/* ====================================================================
   FORM CONTROLS — Akoben style
   ==================================================================== */
.form-field { margin-bottom: var(--space-md); }
.form-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--muted);
  margin-bottom: var(--space-xs);
  padding-left: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: var(--text-base);
  line-height: 1.4;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-tint);
}
.form-input::placeholder { color: oklch(0.58 0.016 60 / 0.6); }
.form-input:disabled, .form-select:disabled { background: var(--surface); color: var(--muted); }
.form-input.error, .form-select.error { border-color: var(--red); }
.form-textarea { min-height: 100px; resize: vertical; border-radius: var(--radius); }
.form-hint { font-size: var(--text-xs); color: var(--muted); margin-top: var(--space-xs); padding-left: var(--space-xs); }
.form-error { font-size: var(--text-xs); color: var(--red); margin-top: var(--space-xs); padding-left: var(--space-xs); }

/* Input with icon */
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input-wrapper:focus-within { border-color: var(--clay); box-shadow: 0 0 0 3px var(--clay-tint); }
.input-wrapper .form-input { border: none; background: transparent; padding-left: 40px; box-shadow: none; }
.input-wrapper:focus-within .form-input { box-shadow: none; }
.input-icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; z-index: 1; }

/* Select */
.form-select { cursor: pointer; padding-right: 30px; background-color: var(--surface-2); }

/* ====================================================================
   TOOLBAR — Akoben filter bar
   ==================================================================== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin: 0 var(--space-lg) var(--space-md);
  margin-left: max(var(--space-lg), var(--safe-left));
  margin-right: max(var(--space-lg), var(--safe-right));
  padding: var(--space-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.toolbar-group { display: flex; align-items: center; gap: var(--space-sm); flex: 1; min-width: 140px; }
.toolbar-group.single { flex: 0 0 auto; }
.toolbar-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--muted);
  white-space: nowrap;
  min-width: 50px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.toolbar .form-select { min-width: 100px; }
.toolbar-actions { display: flex; gap: var(--space-sm); flex-wrap: wrap; }

/* ====================================================================
   TABLES — Akoben data table style
   ==================================================================== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  margin: 0 var(--space-lg);
  margin-left: max(var(--space-lg), var(--safe-left));
  margin-right: max(var(--space-lg), var(--safe-right));
  -webkit-overflow-scrolling: touch;
}
.table { width: 100%; font-size: var(--text-base); }
.table thead { background: var(--surface-2); }
.table th {
  padding: 10px 14px;
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table td.actions { white-space: nowrap; }

/* Badges / Chips — Akoben chip style */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 11.5px;
  font-weight: var(--font-semibold);
  border-radius: var(--radius-full);
}
.badge-primary { background: var(--clay-tint); color: var(--clay-dark); }
.badge-success { background: var(--green-tint); color: var(--green); }
.badge-warning { background: var(--gold-tint); color: var(--gold); }
.badge-error { background: var(--red-tint); color: var(--red); }
.badge-neutral { background: var(--surface-2); color: var(--muted); }

/* Empty state */
.table-empty { padding: var(--space-3xl) var(--space-lg); text-align: center; color: var(--muted); }
.table-empty svg { width: 48px; height: 48px; margin: 0 auto var(--space-md); opacity: 0.35; }

/* ====================================================================
   MODALS — Akoben bottom sheet
   ==================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0.27 0.021 58 / 0.35);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 300;
  padding: 0;
}
.modal-backdrop.show { display: flex; animation: fadeIn var(--t-base); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: sheetUp var(--t-slow);
  padding-bottom: var(--safe-bottom);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

.modal-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  padding-top: var(--space-xl);
}
.modal-header::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
}
.modal-title { font-family: var(--font-serif); font-size: var(--text-lg); font-weight: var(--font-semibold); }
.modal-close {
  background: none;
  border: none;
  padding: var(--space-xs);
  color: var(--clay-dark);
  font-size: var(--text-base);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:active { background: var(--surface-2); }
.modal-body { padding: var(--space-lg); overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* ====================================================================
   TOASTS — Akoben notification
   ==================================================================== */
.toast-container {
  position: fixed;
  top: calc(var(--safe-top) + 60px);
  left: var(--space-lg);
  right: var(--space-lg);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: 12px var(--space-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--clay);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 0;
  max-width: 100%;
  animation: toastIn var(--t-base);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: none; } }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--gold); }
.toast.info { border-left-color: var(--clay); }
.toast-icon { flex-shrink: 0; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; border-radius: var(--radius-full); }
.toast.success .toast-icon { color: var(--green); }
.toast.error .toast-icon { color: var(--red); }
.toast.warning .toast-icon { color: var(--gold); }
.toast.info .toast-icon { color: var(--clay); }
.toast-content { flex: 1; min-width: 0; }
.toast-title { font-weight: var(--font-semibold); font-size: var(--text-sm); color: var(--ink); }
.toast-message { font-size: var(--text-sm); color: var(--muted); margin-top: 2px; }
.toast-close { flex-shrink: 0; background: none; border: none; padding: 2px; color: var(--muted); cursor: pointer; font-size: 16px; }

/* ====================================================================
   BOTTOM TAB BAR
   ==================================================================== */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: oklch(0.998 0.003 74 / 0.88);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  padding-top: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: var(--font-medium);
  transition: color var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  min-height: 56px;
}
.tabbar-item.active { color: var(--clay); }
.tabbar-item:active { opacity: 0.6; }
.tabbar-item svg { width: 22px; height: 22px; }
.tabbar-item span { font-size: 10px; line-height: 1; }

/* ====================================================================
   MORE SHEET
   ==================================================================== */
.more-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-xl);
  z-index: 350;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform var(--t-slow);
  padding-bottom: var(--safe-bottom);
}
.more-sheet.show { transform: none; }
.more-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  margin: 8px auto 0;
}
.more-sheet-title {
  text-align: center;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--muted);
  padding: var(--space-sm) var(--space-lg);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.more-sheet-group { margin: 0 var(--space-lg) var(--space-md); }
.more-sheet-group-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 var(--space-lg) var(--space-xs);
}
.more-sheet-list {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.more-sheet-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 13px var(--space-lg);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: var(--text-base);
  color: var(--ink);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
  min-height: 44px;
}
.more-sheet-item:last-child { border-bottom: none; }
.more-sheet-item:active { background: var(--surface-2); }
.more-sheet-item .icon-wrap {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.more-sheet-item svg { width: 16px; height: 16px; }
.more-sheet-item .chevron {
  margin-left: auto;
  color: var(--border-strong);
  width: 7px !important;
  height: 12px !important;
}
.more-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0.27 0.021 58 / 0.3);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 340;
  display: none;
}
.more-backdrop.show { display: block; animation: fadeIn var(--t-base); }

/* ====================================================================
   SETTINGS GRID
   ==================================================================== */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xl);
  padding: 0 var(--space-lg);
  padding-left: max(var(--space-lg), var(--safe-left));
  padding-right: max(var(--space-lg), var(--safe-right));
}
.settings-section {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: var(--space-lg);
}
.settings-section-title {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--ink);
  margin-bottom: var(--space-md);
}

/* ====================================================================
   CARDS (teacher assignments)
   ==================================================================== */
.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  padding: 0 var(--space-lg);
  padding-left: max(var(--space-lg), var(--safe-left));
  padding-right: max(var(--space-lg), var(--safe-right));
}

/* ====================================================================
   ANALYTICS GRID
   ==================================================================== */
.analytics-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  padding: 0 var(--space-lg);
  padding-left: max(var(--space-lg), var(--safe-left));
  padding-right: max(var(--space-lg), var(--safe-right));
}

/* ====================================================================
   IFRAME / REPORT VIEWER
   ==================================================================== */
.iframe-wrap { width: 100%; min-height: 500px; border: none; border-radius: var(--radius-lg); }

/* ====================================================================
   GRADE SCALE EDITOR
   ==================================================================== */
.grade-scale-editor {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.grade-scale-header {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  padding: 10px 12px;
  background: var(--surface-2);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ====================================================================
   IMPORT TABS
   ==================================================================== */
.import-tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 2px;
  margin-bottom: var(--space-lg);
}
.import-tab {
  flex: 1;
  padding: 8px var(--space-lg);
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--muted);
  cursor: pointer;
  transition: all var(--t-fast);
}
.import-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
  font-weight: var(--font-semibold);
}
.import-pane { display: none; }
.import-pane.active { display: block; }

/* ====================================================================
   MISC
   ==================================================================== */
.msg { font-size: var(--text-sm); padding: var(--space-sm) var(--space-lg); }
.msg.err { color: var(--red); }
.msg.ok, .msg.success { color: var(--green); }
iframe { border: none; }

/* Hide old nav */
.nav-group, .nav-group-label, .nav-btn, .sidebar-header, .sidebar-title, .sidebar-close { display: none !important; }

/* ====================================================================
   MOBILE FIXES — prevent overlapping, overflow, and cramped layouts
   ==================================================================== */

/* Hide user name on small screens — show only avatar + role */
@media (max-width: 480px) {
  .user-name { display: none; }
  .user-avatar-btn { padding: 4px 8px 4px 4px; gap: 4px; }
  .user-role { font-size: 9px; padding: 2px 6px; }
}

/* Page header: stack title + buttons vertically on small screens */
.page-header-flex {
  flex-direction: column;
  align-items: stretch;
}
.page-header-flex > div:first-child {
  width: 100%;
}
.page-header-flex .btn,
.page-header-flex .toolbar-actions {
  width: 100%;
  justify-content: center;
}
@media (min-width: 768px) {
  .page-header-flex {
    flex-direction: row;
    align-items: center;
  }
  .page-header-flex .btn,
  .page-header-flex .toolbar-actions {
    width: auto;
    justify-content: flex-end;
  }
}

/* Toolbar: stack groups vertically, full-width inputs */
.toolbar {
  flex-direction: column;
}
.toolbar-group {
  width: 100%;
  min-width: 0 !important;
}
.toolbar-group .form-select,
.toolbar-group .form-input,
.toolbar-group .input-wrapper {
  width: 100%;
  min-width: 0 !important;
}
/* Remove inline min-widths on mobile */
.toolbar .form-select[style*="min-width"],
.toolbar .form-input[style*="width"] {
  width: 100% !important;
  min-width: 0 !important;
}

@media (min-width: 768px) {
  .toolbar { flex-direction: row; flex-wrap: wrap; }
  .toolbar-group { min-width: 140px; }
}

/* Grade scale editor: horizontal scroll on mobile */
.grade-scale-editor {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.grade-scale-header {
  min-width: 500px;
}
.grade-scale-editor > div:not(.grade-scale-header) {
  min-width: 500px;
}

/* More sheet: cover tabbar, proper z-index */
.more-sheet {
  z-index: 360;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--space-lg));
}
.more-backdrop {
  z-index: 350;
}

/* Modal: don't overlap tabbar */
.modal {
  max-height: calc(85vh - var(--tabbar-h));
  margin-bottom: var(--tabbar-h);
}

/* Tables: ensure horizontal scroll works */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Cards: remove fixed widths on mobile */
.cards {
  grid-template-columns: 1fr;
}

/* Stat grid: 2 columns on mobile */
.stat-grid {
  grid-template-columns: repeat(2, 1fr);
}

/* Activity list: prevent text overflow */
.activity-list .activity-text {
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Topbar: prevent brand overlap with user menu */
.topbar {
  gap: var(--space-sm);
}
.brand {
  min-width: 0;
  overflow: hidden;
}
.brand > span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right {
  flex-shrink: 0;
}

/* Fix any inline width styles on mobile */
@media (max-width: 767px) {
  [style*="min-width: 300px"],
  [style*="min-width: 200px"],
  [style*="width: 140px"] {
    width: 100% !important;
    min-width: 0 !important;
  }
  
  /* Settings grid: single column on mobile */
  .settings-grid { flex-direction: column; }
  
  /* Page title smaller on mobile */
  .page-title { font-size: var(--text-xl); }
  
  /* Modal full width */
  .modal { max-width: 100%; }
  
  /* Buttons in headers: full width */
  .page-header-flex .btn { width: 100%; }
}

/* ====================================================================
   DESKTOP ADAPTATION
   ==================================================================== */
@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .stat-card .n { font-size: var(--text-4xl); }
  .settings-grid { flex-direction: row; flex-wrap: wrap; }
  .settings-section { flex: 1; min-width: 320px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .page-title { font-size: var(--text-4xl); }
  .modal { max-width: 600px; align-self: center; border-radius: var(--radius-lg); margin-bottom: 0; }
  .modal-backdrop { align-items: center; }
}

/* ====================================================================
   LEGACY CLASS COMPATIBILITY
   ==================================================================== */
.stat-card .stat-value { font-family: var(--font-serif); font-size: var(--text-3xl); font-weight: var(--font-semibold); letter-spacing: -0.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-card .stat-label { font-size: var(--text-xs); color: var(--muted); font-weight: var(--font-semibold); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.1em; }

.table.data, table.data { width: 100%; font-size: var(--text-base); border-collapse: collapse; }
.table.data th, table.data th { padding: 10px 14px; text-align: left; font-size: var(--text-xs); font-weight: var(--font-semibold); color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
.table.data td, table.data td { padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--ink); vertical-align: middle; font-variant-numeric: tabular-nums; }

.tag { display: inline-flex; align-items: center; padding: 2px 10px; font-size: 11.5px; font-weight: var(--font-semibold); border-radius: var(--radius-full); }
.field { margin-bottom: var(--space-md); }
.card-t, .card-s, .card-m { background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border); }

table { font-size: var(--text-base); }
th, td { padding: 10px 14px; }
input[type="number"] { -webkit-appearance: none; }
input[type="search"] { -webkit-appearance: none; border-radius: var(--radius); }
input[type="file"] { font-size: var(--text-sm); }
code { font-family: var(--font-mono); font-size: 0.85em; background: var(--surface-2); padding: 2px 6px; border-radius: var(--radius-sm); }
