/* ==========================================================================
   Online LMS - design system
   --------------------------------------------------------------------------
   Order: tokens -> base -> app shell -> components -> pages -> utilities.

   Themes. Light is the default. `data-theme="dark"` on <html> forces dark,
   `data-theme="light"` forces light, and no attribute means "system": the
   prefers-color-scheme query below decides and follows the OS live.
   static/js/theme.js sets the attribute before first paint, so there is no
   flash of the wrong theme.

   Every colour, space, radius and shadow in this file comes from a token.
   The short legacy names (--bg, --surface, --primary ...) are aliases kept
   because templates use them in inline styles.
   ========================================================================== */

:root {
  color-scheme: light;

  /* typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
               "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --text-2xs: .6875rem;   /* 11px */
  --text-xs:  .75rem;     /* 12px */
  --text-sm:  .8125rem;   /* 13px */
  --text-base: .875rem;   /* 14px */
  --text-md:  .9375rem;   /* 15px */
  --text-lg:  1.0625rem;  /* 17px */
  --text-xl:  1.25rem;    /* 20px */
  --text-2xl: 1.5rem;     /* 24px */
  --text-3xl: 1.875rem;   /* 30px */
  --leading-tight: 1.25;
  --leading: 1.55;

  /* spacing (4px grid) */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;

  /* radius */
  --radius-xs: 4px; --radius-sm: 7px; --radius-md: 10px; --radius-lg: 16px; --radius-xl: 22px;
  --radius-full: 999px;

  /* motion */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --duration-fast: 120ms;
  --duration: 180ms;
  --duration-slow: 260ms;

  /* layers */
  --z-sticky: 20; --z-sidebar: 30; --z-backdrop: 40; --z-drawer: 50; --z-dropdown: 60; --z-skip: 100;

  /* layout */
  --sidebar-width: 264px;
  --sidebar-width-collapsed: 76px;
  --topbar-height: 60px;
  --content-max: 1320px;

  /* colour - light */
  --color-bg:             #f3f5fa;
  --color-surface:        #ffffff;
  --color-surface-2:      #f8fafd;
  --color-surface-3:      #edf1f7;
  --color-border:         #e4e9f2;
  --color-border-strong:  #cdd6e4;
  --color-text:           #0f172a;
  --color-text-muted:     #51607a;
  --color-text-faint:     #8391a7;

  --color-primary:            #2f5bea;   /* text, links, accents */
  --color-primary-solid:      #2f5bea;   /* fills that carry white text */
  --color-primary-solid-hover:#2349c8;
  --color-primary-soft:       #ecf1fe;
  --color-on-primary:         #ffffff;

  --color-success: #15803d; --color-success-soft: #e6f5eb; --color-success-solid: #15803d;
  --color-warning: #b45309; --color-warning-soft: #fdf2e0; --color-warning-solid: #b45309;
  --color-danger:  #d92d20; --color-danger-soft:  #fdeceb; --color-danger-solid:  #d92d20;
  --color-info:    #0e7490; --color-info-soft:    #e1f3f7;
  --color-violet:  #6d4ae0; --color-violet-soft:  #efeafd;
  --color-live:    #e11d48; --color-live-soft:    #fde8ee; --color-live-solid:    #e11d48;

  --color-sidebar:             #ffffff;
  --color-sidebar-text:        #334155;
  --color-sidebar-muted:       #7b8aa1;
  --color-sidebar-hover:       #f1f5fb;
  --color-sidebar-active:      #ecf1fe;
  --color-sidebar-active-text: #2349c8;

  --color-overlay: rgba(15, 23, 42, .45);
  --color-tooltip-bg: #0f172a;
  --color-tooltip-text: #f8fafc;

  --focus-ring: 0 0 0 3px rgba(47, 91, 234, .30);
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, .07), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 10px 24px -8px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .05);
  --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, .24), 0 6px 14px rgba(16, 24, 40, .07);

  /* brand */
  --gradient-brand: linear-gradient(135deg, #2f5bea 0%, #6d4ae0 100%);
  --gradient-hero: linear-gradient(120deg, #eef2ff 0%, #f5f0ff 55%, #eaf6ff 100%);

  /* charts (docs/ui.md "Charts"; validated with the dataviz palette checks) */
  --series-1: #2a78d6;
  --status-good: #0ca30c; --status-warning: #fab219; --status-critical: #d03b3b; --status-neutral: #8a94a6;
  --chart-grid: #e8ecf3; --chart-axis: #64748b;

  /* legacy aliases - templates use these in inline styles */
  --bg: var(--color-bg);
  --surface: var(--color-surface);
  --surface-2: var(--color-surface-2);
  --border: var(--color-border);
  --text: var(--color-text);
  --text-muted: var(--color-text-muted);
  --text-faint: var(--color-text-faint);
  --primary: var(--color-primary);
  --primary-hover: var(--color-primary-solid-hover);
  --primary-soft: var(--color-primary-soft);
  --success: var(--color-success);
  --success-soft: var(--color-success-soft);
  --warning: var(--color-warning);
  --warning-soft: var(--color-warning-soft);
  --danger: var(--color-danger);
  --danger-soft: var(--color-danger-soft);
  --live: var(--color-live);
  --radius: var(--radius-md);
  --shadow: var(--shadow-sm);
  --font: var(--font-sans);
  --mono: var(--font-mono);
}

/* colour - dark. Written twice because "system" and "forced dark" must both
   produce it and CSS has no way to share a declaration block between an
   attribute selector and a media query. Keep the two blocks identical. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg:             #0b1120;
  --color-surface:        #111a2e;
  --color-surface-2:      #16213a;
  --color-surface-3:      #1c2944;
  --color-border:         #1f2b45;
  --color-border-strong:  #2c3b5c;
  --color-text:           #e5eaf3;
  --color-text-muted:     #9aa7bf;
  --color-text-faint:     #6c7a93;
  --color-primary:            #8daeff;
  --color-primary-solid:      #3b63e6;
  --color-primary-solid-hover:#4a72f0;
  --color-primary-soft:       rgba(99, 135, 255, .16);
  --color-on-primary:         #ffffff;
  --color-success: #4ade80; --color-success-soft: rgba(74, 222, 128, .13); --color-success-solid: #15803d;
  --color-warning: #fbbf24; --color-warning-soft: rgba(251, 191, 36, .13); --color-warning-solid: #b45309;
  --color-danger:  #f87171; --color-danger-soft:  rgba(248, 113, 113, .14); --color-danger-solid: #dc2626;
  --color-info:    #38bdf8; --color-info-soft:    rgba(56, 189, 248, .13);
  --color-violet:  #a78bfa; --color-violet-soft:  rgba(167, 139, 250, .15);
  --color-live:    #fb7185; --color-live-soft:    rgba(251, 113, 133, .15); --color-live-solid: #e11d48;
  --color-sidebar:             #0d1526;
  --color-sidebar-text:        #c7d0e0;
  --color-sidebar-muted:       #7c8aa5;
  --color-sidebar-hover:       rgba(255, 255, 255, .05);
  --color-sidebar-active:      rgba(99, 135, 255, .16);
  --color-sidebar-active-text: #aec4ff;
  --color-overlay: rgba(2, 6, 23, .62);
  --color-tooltip-bg: #e5eaf3;
  --color-tooltip-text: #0b1120;
  --focus-ring: 0 0 0 3px rgba(141, 174, 255, .45);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .25);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, .35), 0 2px 4px rgba(0, 0, 0, .25);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, .5), 0 6px 12px rgba(0, 0, 0, .3);
  --gradient-hero: linear-gradient(120deg, #141f3a 0%, #1b1838 55%, #102336 100%);
  --series-1: #3987e5;
  --status-neutral: #64748b;
  --chart-grid: #1f2b45; --chart-axis: #8b97ad;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --color-bg:             #0b1120;
    --color-surface:        #111a2e;
    --color-surface-2:      #16213a;
    --color-surface-3:      #1c2944;
    --color-border:         #1f2b45;
    --color-border-strong:  #2c3b5c;
    --color-text:           #e5eaf3;
    --color-text-muted:     #9aa7bf;
    --color-text-faint:     #6c7a93;
    --color-primary:            #8daeff;
    --color-primary-solid:      #3b63e6;
    --color-primary-solid-hover:#4a72f0;
    --color-primary-soft:       rgba(99, 135, 255, .16);
    --color-on-primary:         #ffffff;
    --color-success: #4ade80; --color-success-soft: rgba(74, 222, 128, .13); --color-success-solid: #15803d;
    --color-warning: #fbbf24; --color-warning-soft: rgba(251, 191, 36, .13); --color-warning-solid: #b45309;
    --color-danger:  #f87171; --color-danger-soft:  rgba(248, 113, 113, .14); --color-danger-solid: #dc2626;
    --color-info:    #38bdf8; --color-info-soft:    rgba(56, 189, 248, .13);
    --color-violet:  #a78bfa; --color-violet-soft:  rgba(167, 139, 250, .15);
    --color-live:    #fb7185; --color-live-soft:    rgba(251, 113, 133, .15); --color-live-solid: #e11d48;
    --color-sidebar:             #0d1526;
    --color-sidebar-text:        #c7d0e0;
    --color-sidebar-muted:       #7c8aa5;
    --color-sidebar-hover:       rgba(255, 255, 255, .05);
    --color-sidebar-active:      rgba(99, 135, 255, .16);
    --color-sidebar-active-text: #aec4ff;
    --color-overlay: rgba(2, 6, 23, .62);
    --color-tooltip-bg: #e5eaf3;
    --color-tooltip-text: #0b1120;
    --focus-ring: 0 0 0 3px rgba(141, 174, 255, .45);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .25);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, .35), 0 2px 4px rgba(0, 0, 0, .25);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, .5), 0 6px 12px rgba(0, 0, 0, .3);
    --gradient-hero: linear-gradient(120deg, #141f3a 0%, #1b1838 55%, #102336 100%);
    --series-1: #3987e5;
    --status-neutral: #64748b;
    --chart-grid: #1f2b45; --chart-axis: #8b97ad;
  }
}

/* --- base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { margin: 0 0 var(--space-2); line-height: var(--leading-tight); font-weight: 650; color: var(--color-text); }
h1 { font-size: var(--text-2xl); letter-spacing: -.015em; }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
p  { margin: 0 0 var(--space-3); }

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

code, kbd, samp { font-family: var(--font-mono); font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--color-border); margin: var(--space-4) 0; }
img { max-width: 100%; height: auto; }
::selection { background: var(--color-primary-soft); }

/* --- icons ----------------------------------------------------------------- */
.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -.25em;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 22px; height: 22px; }

/* ==========================================================================
   App shell: sidebar + topbar + content
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}
.app-main { min-width: 0; display: flex; flex-direction: column; }

/* sidebar ------------------------------------------------------------------- */
.sidebar {
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--color-sidebar);
  border-right: 1px solid var(--color-border);
  z-index: var(--z-sidebar);
  min-width: 0;
}
.sidebar-head {
  height: var(--topbar-height); flex: none;
  display: flex; align-items: center; gap: var(--space-2);
  padding: 0 var(--space-3) 0 var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.brand {
  display: flex; align-items: center; gap: var(--space-3);
  min-width: 0; color: var(--color-text);
  font-weight: 700; font-size: var(--text-md); white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary-solid), var(--color-violet));
  color: #fff; font-size: var(--text-2xs); font-weight: 800; letter-spacing: .04em;
  box-shadow: var(--shadow-sm);
}
.brand-name { overflow: hidden; text-overflow: ellipsis; }
.brand-name small { display: block; font-size: var(--text-2xs); font-weight: 500; color: var(--color-text-faint); letter-spacing: .02em; }

.side-nav { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: var(--space-3) var(--space-3) var(--space-6); }
.side-section + .side-section { margin-top: var(--space-4); }
.side-section-toggle {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: none; border: 0; border-radius: var(--radius-sm);
  font: inherit; font-size: var(--text-2xs); font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
  color: var(--color-sidebar-muted); cursor: pointer;
}
.side-section-toggle:hover { color: var(--color-sidebar-text); }
.side-section-toggle .icon { width: 14px; height: 14px; transition: transform var(--duration) var(--ease); }
.side-section-toggle[aria-expanded="false"] .icon { transform: rotate(-90deg); }

.side-list { list-style: none; margin: var(--space-1) 0 0; padding: 0; display: grid; gap: 2px; }
.side-list[hidden] { display: none; }

.side-link {
  position: relative;
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 38px; padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-text); font-weight: 500;
  text-decoration: none;
  transition: background var(--duration-fast), color var(--duration-fast);
}
.side-link .icon { width: 20px; height: 20px; color: var(--color-sidebar-muted); transition: color var(--duration-fast); }
.side-link:hover { background: var(--color-sidebar-hover); color: var(--color-text); text-decoration: none; }
.side-link:hover .icon { transform: translateX(1px); }
.side-link .icon { transition: color var(--duration-fast), transform var(--duration) var(--ease); }
.side-link:hover .icon { color: var(--color-text-muted); }
.side-link[aria-current="page"] {
  background: var(--color-sidebar-active); color: var(--color-sidebar-active-text); font-weight: 600;
}
.side-link[aria-current="page"] .icon { color: currentColor; }
.side-link[aria-current="page"]::before {
  content: ""; position: absolute; left: calc(-1 * var(--space-3)); top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--gradient-brand);
}
.side-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-link .side-trail { width: 14px; height: 14px; color: var(--color-text-faint); }

.sidebar-foot {
  flex: none; padding: var(--space-3);
  border-top: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: flex-end;
}

/* collapsed rail (desktop only) */
@media (min-width: 1024px) {
  html[data-sidebar="collapsed"] .app-shell { grid-template-columns: var(--sidebar-width-collapsed) minmax(0, 1fr); }
  html[data-sidebar="collapsed"] .sidebar-head { justify-content: center; padding: 0; }
  html[data-sidebar="collapsed"] .brand-name,
  html[data-sidebar="collapsed"] .side-label,
  html[data-sidebar="collapsed"] .side-section-toggle .section-name,
  html[data-sidebar="collapsed"] .side-link .side-trail {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  html[data-sidebar="collapsed"] .side-nav { overflow: visible; padding: var(--space-3) var(--space-2); }
  html[data-sidebar="collapsed"] .side-section-toggle {
    height: 1px; padding: 0; margin: var(--space-3) var(--space-2); background: var(--color-border);
    pointer-events: none;
  }
  html[data-sidebar="collapsed"] .side-section-toggle .icon { display: none; }
  html[data-sidebar="collapsed"] .side-list[hidden] { display: grid; }
  html[data-sidebar="collapsed"] .side-link { justify-content: center; padding: 0; }
  html[data-sidebar="collapsed"] .side-link[aria-current="page"]::before { left: calc(-1 * var(--space-2)); }
  html[data-sidebar="collapsed"] .sidebar-foot { justify-content: center; }
  html[data-sidebar="collapsed"] .sidebar-collapse .icon { transform: scaleX(-1); }

  /* tooltips, since the labels are gone */
  html[data-sidebar="collapsed"] .side-link[data-tooltip]:hover::after,
  html[data-sidebar="collapsed"] .side-link[data-tooltip]:focus-visible::after {
    content: attr(data-tooltip);
    position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
    padding: 5px 10px; border-radius: var(--radius-sm);
    background: var(--color-tooltip-bg); color: var(--color-tooltip-text);
    font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
    box-shadow: var(--shadow-md); z-index: var(--z-dropdown); pointer-events: none;
  }
}

/* drawer (below desktop) */
.sidebar-backdrop { display: none; }
@media (max-width: 1023.98px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: min(var(--sidebar-width), 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--duration-slow) var(--ease), visibility 0s linear var(--duration-slow);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-drawer);
  }
  html.drawer-open .sidebar { transform: none; visibility: visible; transition-delay: 0s; }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0;
    background: var(--color-overlay);
    z-index: var(--z-backdrop);
    opacity: 0; pointer-events: none;
    transition: opacity var(--duration-slow) var(--ease);
  }
  html.drawer-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  html.drawer-open body { overflow: hidden; }
  /* .icon-btn (later in the file) sets display, hence the compound selector */
  .icon-btn.sidebar-collapse { display: none; }
}
@media (min-width: 1024px) {
  .icon-btn.drawer-toggle, .icon-btn.drawer-close { display: none; }
}

/* topbar -------------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  height: var(--topbar-height); flex: none;
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-6);
  background: var(--color-bg);
  background: color-mix(in srgb, var(--color-bg) 84%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--color-border);
}
.topbar-title { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.topbar-icon {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--color-primary-soft); color: var(--color-primary);
}
.topbar-icon .icon { width: 19px; height: 19px; }
@media (max-width: 479.98px) { .topbar-icon { display: none; } }
.topbar-title .crumb { font-size: var(--text-xs); color: var(--color-text-faint); font-weight: 500; }
.topbar-title .title { font-size: var(--text-md); font-weight: 650; color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-1); }

.icon-btn {
  position: relative;
  width: 38px; height: 38px; flex: none;
  display: inline-grid; place-items: center;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent; color: var(--color-text-muted);
  cursor: pointer; font: inherit;
  transition: background var(--duration-fast), color var(--duration-fast);
}
.icon-btn:hover { background: var(--color-surface-3); color: var(--color-text); text-decoration: none; }
.icon-btn .icon { width: 20px; height: 20px; }

/* the unread count sits on the bell; the fragment is swapped into .notif-slot */
.notif-slot { position: absolute; top: 3px; right: 2px; line-height: 0; pointer-events: none; }
.notif-slot .badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  justify-content: center;
  background: var(--color-danger-solid); color: #fff;
  font-size: var(--text-2xs); font-weight: 700;
  border: 2px solid var(--color-bg);
}

/* dropdown menus (<details class="menu">) */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 224px; max-width: min(320px, calc(100vw - 24px));
  padding: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  transform-origin: top right;
  animation: menu-in var(--duration) var(--ease);
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .menu-panel, .row-menu-panel:popover-open { animation: none; } }
.menu > summary.icon-btn[aria-expanded="true"], .menu[open] > summary.icon-btn { background: var(--color-surface-3); color: var(--color-text); }
.menu-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: var(--text-2xs); font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
  color: var(--color-text-faint);
}
.menu-item {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; min-height: 36px; padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--color-text);
  font: inherit; font-size: var(--text-base); text-align: left; text-decoration: none;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--color-primary-soft); color: var(--color-primary); text-decoration: none; }
.menu-item:hover .icon, .menu-item:focus-visible .icon { color: currentColor; }
.menu-item .icon { color: var(--color-text-muted); }
.menu-item .menu-check { margin-left: auto; visibility: hidden; color: var(--color-primary); }
.menu-item[aria-checked="true"],
.menu-item[aria-current="true"] { color: var(--color-primary); font-weight: 600; }
.menu-item[aria-checked="true"] .icon,
.menu-item[aria-current="true"] .icon { color: currentColor; }
.menu-item[aria-checked="true"] .menu-check,
.menu-item[aria-current="true"] .menu-check { visibility: visible; }
.menu-sep { height: 1px; margin: var(--space-2) 0; background: var(--color-border); }
.menu form { margin: 0; }
.menu-panel .menu-danger { color: var(--color-danger); }
.menu-panel .menu-danger .icon { color: currentColor; }

/* Row action menus (templates/partials/row_menu_*): a "⋮" button per table
   row opening a [popover] panel. The popover lives in the top layer, so a
   scrolling .table-wrap or a stacked card cannot clip it; static/js/app.js
   places it beside its button and inside the viewport. */
.row-menu { display: inline-flex; }
.row-menu-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-md);
  background: none; color: var(--color-text-muted); cursor: pointer;
}
.row-menu-toggle:hover { background: var(--color-surface-2); color: var(--color-text); }
.row-menu-toggle:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.row-menu-toggle[aria-expanded="true"] { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-border); }
.row-menu-panel {
  position: fixed; inset: auto; margin: 0;
  animation: menu-in var(--duration) var(--ease);
  min-width: 208px; max-width: min(300px, calc(100vw - 16px));
  color: var(--color-text);
}
.row-menu-panel form { margin: 0; }
.row-menu-panel .menu-item:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.row-menu-panel .menu-item[aria-disabled="true"] { color: var(--color-text-faint); cursor: default; }

/* "or" between the password form and the HEMIS buttons on the sign-in page */
.auth-divider { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-4) 0; color: var(--color-text-faint); font-size: var(--text-sm); }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--color-border); }

.menu-user { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3) var(--space-3); }
.menu-user-name { font-weight: 650; }
.menu-user-meta { font-size: var(--text-xs); color: var(--color-text-muted); overflow-wrap: anywhere; }

/* which theme icon the theme button shows follows the stored choice */
.theme-glyph { display: none; }
html[data-theme-choice="light"] .theme-glyph-light,
html[data-theme-choice="dark"] .theme-glyph-dark,
html[data-theme-choice="system"] .theme-glyph-system,
html:not([data-theme-choice]) .theme-glyph-system { display: block; }

.lang-code {
  font-size: var(--text-2xs); font-weight: 750; letter-spacing: .04em;
  color: var(--color-text-muted);
}
.icon-btn.lang-button { width: auto; padding: 0 var(--space-2); gap: 6px; display: inline-flex; align-items: center; }

.user-button {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 40px; padding: 0 var(--space-2) 0 4px; margin-left: var(--space-1);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.user-button:hover { border-color: var(--color-border-strong); }
.user-button .icon { width: 16px; height: 16px; color: var(--color-text-faint); }
.user-button-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); }

.avatar {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary-solid), var(--color-violet));
  color: #fff; font-size: var(--text-xs); font-weight: 750; letter-spacing: .02em;
}
.avatar-lg { width: 40px; height: 40px; font-size: var(--text-sm); }

/* content ------------------------------------------------------------------- */
.content { flex: 1; padding: var(--space-6) var(--space-6) var(--space-12); min-width: 0; }
.container { max-width: var(--content-max); margin: 0 auto; padding: 0 var(--space-4); }
.content > .container { padding: 0; }
main:focus, main:focus-visible { outline: none; }

/* ==========================================================================
   Components
   ========================================================================== */

/* page header */
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
  margin-bottom: var(--space-6);
}
.page-header h1 { margin: 0; }
.page-eyebrow {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--color-primary); margin-bottom: var(--space-1);
}
.page-subtitle { margin: var(--space-1) 0 0; color: var(--color-text-muted); }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  margin: var(--space-8) 0 var(--space-3);
}
.section-title {
  display: flex; align-items: center; gap: var(--space-2);
  margin: 0; font-size: var(--text-md); font-weight: 650;
}
.section-title .icon { color: var(--color-text-muted); }

/* cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  min-width: 0;
}
.card + .card { margin-top: var(--space-4); }
.card-header {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.card-header h2, .card-header h3 { margin: 0; font-size: var(--text-md); font-weight: 650; display: flex; align-items: center; gap: var(--space-3); }
.card-icon {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--tone-soft, var(--color-primary-soft)); color: var(--tone, var(--color-primary));
}
.card-icon .icon { width: 18px; height: 18px; }
.card-sub { display: block; font-size: var(--text-xs); font-weight: 500; color: var(--color-text-muted); margin-top: 2px; }
.card-interactive { transition: border-color var(--duration), box-shadow var(--duration), transform var(--duration) var(--ease); }
.card-interactive:hover { border-color: var(--color-border-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-header .card-actions { margin-left: auto; display: flex; gap: var(--space-2); align-items: center; }
.card-body { padding: var(--space-5); }
.card-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-2);
  font-size: var(--text-sm); color: var(--color-text-muted);
}

/* tones - one pair of custom properties drives icons, pills and chips */
[data-tone] { --tone: var(--color-text-muted); --tone-soft: var(--color-surface-3); }
[data-tone="primary"] { --tone: var(--color-primary); --tone-soft: var(--color-primary-soft); }
[data-tone="success"] { --tone: var(--color-success); --tone-soft: var(--color-success-soft); }
[data-tone="warning"] { --tone: var(--color-warning); --tone-soft: var(--color-warning-soft); }
[data-tone="danger"]  { --tone: var(--color-danger);  --tone-soft: var(--color-danger-soft); }
[data-tone="info"]    { --tone: var(--color-info);    --tone-soft: var(--color-info-soft); }
[data-tone="violet"]  { --tone: var(--color-violet);  --tone-soft: var(--color-violet-soft); }
[data-tone="live"]    { --tone: var(--color-live);    --tone-soft: var(--color-live-soft); }

/* KPI cards */
.kpi-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
}
.kpi {
  position: relative;
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  color: inherit; text-decoration: none;
  transition: border-color var(--duration), box-shadow var(--duration), transform var(--duration);
  min-width: 0;
}
a.kpi:hover { text-decoration: none; border-color: color-mix(in srgb, var(--tone, var(--color-primary)) 35%, var(--color-border)); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.kpi { box-shadow: var(--shadow-sm); overflow: hidden; }
.kpi::after {
  content: ""; position: absolute; inset: auto -30px -40px auto; width: 120px; height: 120px;
  border-radius: 50%; background: var(--tone-soft, var(--color-surface-3)); opacity: .55; pointer-events: none;
}
.kpi > * { position: relative; z-index: 1; }
@media (min-width: 1200px) { .kpi-grid.is-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); } .kpi-grid.is-5 .kpi { padding: var(--space-4); gap: var(--space-3); } .kpi-grid.is-5 .kpi-icon { width: 42px; height: 42px; } .kpi-grid.is-5 .kpi-value { font-size: var(--text-2xl); } }
.kpi-meta { display: block; margin-top: 2px; font-size: var(--text-xs); color: var(--color-text-muted); }
.kpi-icon {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--tone-soft); color: var(--tone);
}
.kpi-icon .icon { width: 22px; height: 22px; }
.kpi-body { min-width: 0; display: flex; flex-direction: column; }
.kpi-label { display: block; font-size: var(--text-sm); font-weight: 550; color: var(--color-text-muted); }
.kpi-value {
  display: block;
  margin-top: 2px;
  font-size: var(--text-3xl); font-weight: 700; line-height: 1.1; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; color: var(--color-text);
}
.kpi-arrow { margin-left: auto; color: var(--color-text-faint); opacity: 0; transition: opacity var(--duration); }
a.kpi:hover .kpi-arrow { opacity: 1; }

/* metric tiles inside a card */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); }
.metric-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric {
  display: flex; flex-direction: column;
  padding: var(--space-5);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  min-width: 0;
}
.metric-label {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-sm); color: var(--color-text-muted); font-weight: 550;
}
.metric-label .dot { color: var(--tone); }
/* pushed to the bottom so a row of figures lines up even when one label wraps */
.metric-value {
  margin-top: auto; padding-top: var(--space-2);
  font-size: var(--text-2xl); font-weight: 700; line-height: 1.1; letter-spacing: -.015em;
  font-variant-numeric: tabular-nums;
}
.metric[data-tone] .metric-value.is-active { color: var(--tone); }
.metric-grid-wrap { overflow: hidden; }
.metric-grid-wrap .metric-grid { margin: 0 -1px -1px 0; }

/* status pill */
.status-pill {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 28px; padding: 0 var(--space-3) 0 10px;
  border-radius: var(--radius-full);
  background: var(--tone-soft); color: var(--tone);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: .02em;
  white-space: nowrap;
}
.status-pill .icon { width: 16px; height: 16px; }

/* dashboard layout */
.dash-grid { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); margin-top: var(--space-5); }
.dash-grid > .card + .card { margin-top: 0; }

/* lesson rows (teacher / student dashboards) */
.lesson {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  gap: var(--space-5);
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.lesson:last-child { border-bottom: 0; }
.lesson.is-live { background: linear-gradient(90deg, var(--color-live-soft), transparent 62%); }
.lesson-time { font-variant-numeric: tabular-nums; }
.lesson-time .from { font-size: var(--text-lg); font-weight: 650; display: block; }
.lesson-time .to   { font-size: var(--text-sm); color: var(--color-text-muted); }
.lesson-title { font-size: var(--text-md); font-weight: 620; margin-bottom: 2px; }
.lesson-meta  { font-size: var(--text-sm); color: var(--color-text-muted); display: flex; gap: var(--space-3); flex-wrap: wrap; }
.lesson-actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 38px; padding: 0 var(--space-4);
  font-family: inherit; font-size: var(--text-base); font-weight: 600; line-height: 1;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--duration-fast), border-color var(--duration-fast), box-shadow var(--duration-fast), color var(--duration-fast);
}
.btn:hover { background: var(--color-surface-2); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn[disabled], .btn.is-disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn .icon { width: 16px; height: 16px; }

.btn-primary {
  background: var(--color-primary-solid); border-color: transparent; color: var(--color-on-primary);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .12), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.btn-primary:hover { background: var(--color-primary-solid-hover); color: var(--color-on-primary); box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--color-primary-solid) 60%, transparent); }
.btn:active { transform: translateY(1px); }
.btn-danger  { background: var(--color-danger-solid); border-color: transparent; color: #fff; }
.btn-danger:hover { background: var(--color-danger-solid); filter: brightness(1.08); color: #fff; }
.btn-live    { background: var(--color-live-solid); border-color: transparent; color: #fff; }
.btn-live:hover { background: var(--color-live-solid); filter: brightness(1.08); color: #fff; }
.btn-success { background: var(--color-success-solid); border-color: transparent; color: #fff; }
.btn-ghost   { background: transparent; border-color: transparent; box-shadow: none; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-surface-3); color: var(--color-text); }
.btn-sm { min-height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn-lg { min-height: 44px; padding: 0 var(--space-5); font-size: var(--text-md); }
.btn-block { width: 100%; }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 9px;
  font-size: var(--text-xs); font-weight: 650;
  border-radius: var(--radius-full);
  background: var(--color-surface-3); color: var(--color-text-muted);
  white-space: nowrap; vertical-align: middle;
}
.badge-live    { background: var(--color-live-soft);    color: var(--color-live); }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-soft);  color: var(--color-danger); }
.badge-info    { background: var(--color-primary-soft); color: var(--color-primary); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.dot-pulse { animation: pulse 1.7s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .28; } }

/* legacy stat cards */
.stat-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 165px), 1fr));
}
.stat {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow-xs);
}
.stat-value { font-size: var(--text-3xl); font-weight: 700; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: var(--space-1); }

/* tables - a table outside a card gets the card's surface, so it never sits
   directly on the page background */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card .table-wrap { background: transparent; border: 0; border-radius: 0; box-shadow: none; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-base); }
table.data th, table.data td {
  padding: 11px var(--space-4);
  text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--color-border);
}
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: var(--text-xs); font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
  white-space: nowrap;
}
table.data tbody tr { transition: background var(--duration-fast); }
table.data tbody tr:hover { background: var(--color-surface-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td a:not(.btn) { font-weight: 550; }
table.data th:first-child, table.data td:first-child { padding-left: var(--space-5); }
table.data th:last-child, table.data td:last-child { padding-right: var(--space-5); }

/* pagination */
.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
  margin-top: var(--space-4); font-size: var(--text-sm);
}
.pagination-pages { display: inline-flex; align-items: center; gap: var(--space-2); }
.pagination-current { color: var(--color-text-muted); font-variant-numeric: tabular-nums; padding: 0 var(--space-2); }

/* progress */
.progress { height: 6px; background: var(--color-surface-3); border-radius: var(--radius-full); overflow: hidden; min-width: 70px; }
.progress > span { display: block; height: 100%; background: var(--color-primary-solid); border-radius: var(--radius-full); }
.progress.is-success > span { background: var(--color-success-solid); }
.progress.is-warning > span { background: var(--color-warning-solid); }
.progress.is-danger  > span { background: var(--color-danger-solid); }

/* forms */
.field { margin-bottom: var(--space-4); min-width: 0; }
.field label, .form-label {
  display: block; margin-bottom: 6px;
  font-size: var(--text-sm); font-weight: 600; color: var(--color-text);
}
.input, select, textarea,
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="date"], input[type="time"], input[type="url"], input[type="tel"] {
  width: 100%; min-height: 40px;
  padding: 8px var(--space-3);
  font-family: inherit; font-size: var(--text-base); line-height: 1.4;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
textarea { min-height: 96px; resize: vertical; }
.input:hover, select:hover, textarea:hover { border-color: var(--color-text-faint); }
.input:focus, select:focus, textarea:focus,
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus, input[type="number"]:focus,
input[type="search"]:focus, input[type="date"]:focus, input[type="time"]:focus {
  outline: none; border-color: var(--color-primary-solid); box-shadow: var(--focus-ring);
}
.input::placeholder, textarea::placeholder { color: var(--color-text-faint); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--color-primary-solid); width: 16px; height: 16px; }
.help { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 6px; }
.material-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.material-item { display: flex; gap: var(--space-3); justify-content: space-between; align-items: flex-start; padding-bottom: var(--space-3); border-bottom: 1px solid var(--color-border); min-width: 0; }
.material-item:last-child { border-bottom: 0; padding-bottom: 0; }
.material-main { min-width: 0; flex: 1; }
.material-title { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; font-weight: 600; overflow-wrap: anywhere; }
.material-body { margin: var(--space-1) 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { .material-item { flex-direction: column; } }
.form-section { border: 1px solid var(--color-border); border-radius: var(--radius-md, 10px); padding: var(--space-3) var(--space-4) 0; margin: 0 0 var(--space-4); min-width: 0; }
.form-section[hidden] { display: none; }
.form-section > legend { font-weight: 600; font-size: var(--text-sm); padding: 0 var(--space-2); }
label.help { margin-top: 0; }
.errorlist { list-style: none; margin: 6px 0 0; padding: 0; color: var(--color-danger); font-size: var(--text-xs); font-weight: 550; }
.field.has-error .input, .field .input[aria-invalid="true"] { border-color: var(--color-danger); }

/* a filter bar (form > .row of fields and buttons): the fields drop their bottom
   margin so the buttons sit level with the inputs, and match their height */
form .row { align-items: flex-end; }
form .row > .field { margin-bottom: 0; }
form .row > .btn { min-height: 40px; }

/* messages */
.messages { display: grid; gap: var(--space-2); margin-bottom: var(--space-5); }
.message {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-text-faint);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-base);
}
.message.success { background: var(--color-success-soft); border-color: transparent; border-left-color: var(--color-success); }
.message.error   { background: var(--color-danger-soft);  border-color: transparent; border-left-color: var(--color-danger); }
.message.warning { background: var(--color-warning-soft); border-color: transparent; border-left-color: var(--color-warning); }
.message.info    { background: var(--color-primary-soft); border-color: transparent; border-left-color: var(--color-primary); }

/* empty states */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  padding: var(--space-10) var(--space-5);
  text-align: center; color: var(--color-text-muted);
}
.empty-icon {
  width: 52px; height: 52px; margin-bottom: var(--space-1);
  display: grid; place-items: center;
  border-radius: var(--radius-full);
  background: var(--tone-soft, var(--color-surface-3)); color: var(--tone, var(--color-text-faint));
}
.empty-icon .icon { width: 24px; height: 24px; }
.empty-title { color: var(--color-text); font-weight: 650; font-size: var(--text-md); }
/* an empty table row keeps its cell a table cell, or the colspan stops working */
td.empty, table.data td.empty { display: table-cell; padding: var(--space-10) var(--space-5); text-align: center; }
table.data tbody tr:hover:has(> td.empty) { background: transparent; }
td.empty .empty-icon { margin: 0 auto var(--space-3); }

/* auth pages */
.auth-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--space-8) var(--space-4);
}
.auth-screen {
  background:
    radial-gradient(900px 480px at 12% -8%, var(--color-primary-soft), transparent 62%),
    radial-gradient(700px 420px at 100% 110%, var(--color-violet-soft), transparent 60%),
    var(--color-bg);
}
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card { border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); }
.auth-card .card-body { padding: var(--space-8); }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: var(--space-3); margin-bottom: var(--space-6); }
.auth-toolbar {
  position: fixed; top: var(--space-4); right: var(--space-4);
  display: flex; align-items: center; gap: var(--space-1);
  z-index: var(--z-sticky);
}
.content .auth-wrap { min-height: auto; padding: var(--space-8) 0; }
.auth-foot { margin-top: var(--space-5); text-align: center; font-size: var(--text-xs); color: var(--color-text-faint); }
.auth-main { display: block; }
/* Below the language/theme toolbar (top right), which it would otherwise
   cover on a phone, where it spans the width. */
.auth-messages {
  position: fixed; top: calc(var(--space-4) + 48px); left: 50%; transform: translateX(-50%);
  width: min(420px, calc(100vw - 2 * var(--space-4))); z-index: var(--z-sticky);
}
.auth-title { font-size: var(--text-xl); line-height: var(--leading-tight); margin: 0 0 var(--space-1); }
.auth-lead { margin: 0 0 var(--space-5); }
.auth-step-icon {
  width: 44px; height: 44px; margin-bottom: var(--space-4);
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--color-primary-soft); color: var(--color-primary);
}
.auth-step-icon .icon { width: 22px; height: 22px; }

/* sign-in: a brand panel beside the form on wide screens */
.auth-split { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.auth-split > .auth-wrap { min-height: auto; }
.auth-showcase { display: none; }
@media (min-width: 1024px) {
  .auth-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .auth-showcase {
    position: relative; overflow: hidden;
    display: flex; align-items: center;
    padding: var(--space-12) clamp(32px, 5vw, 80px);
    background: var(--gradient-brand); color: #fff;
  }
  .auth-showcase::before, .auth-showcase::after {
    content: ""; position: absolute; border-radius: 50%; pointer-events: none;
    background: rgba(255, 255, 255, .08);
  }
  .auth-showcase::before { width: 420px; height: 420px; right: -140px; top: -120px; }
  .auth-showcase::after { width: 300px; height: 300px; left: -100px; bottom: -110px; }
}
.auth-showcase-inner { position: relative; max-width: 520px; }
.auth-showcase-brand { display: flex; align-items: center; gap: var(--space-3); font-weight: 750; font-size: var(--text-lg); margin-bottom: var(--space-10); }
.auth-showcase-brand .brand-mark { background: rgba(255, 255, 255, .18); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28); }
.auth-showcase h2 { color: #fff; font-size: clamp(1.6rem, 2.4vw, 2.2rem); line-height: 1.2; letter-spacing: -.02em; margin-bottom: var(--space-4); }
.auth-showcase p { color: rgba(255, 255, 255, .85); font-size: var(--text-md); }
.auth-features { list-style: none; margin: var(--space-8) 0 0; padding: 0; display: grid; gap: var(--space-5); }
.auth-features li { display: flex; gap: var(--space-4); align-items: flex-start; }
.auth-features strong { display: block; color: #fff; margin-bottom: 2px; }
.auth-features li > span:last-child { color: rgba(255, 255, 255, .82); font-size: var(--text-sm); }
.auth-feature-icon {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  border-radius: var(--radius-md); background: rgba(255, 255, 255, .14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
}
.auth-feature-icon .icon { width: 22px; height: 22px; }
.auth-showcase .auth-showcase-langs { margin: var(--space-10) 0 0; font-size: var(--text-sm); letter-spacing: .02em; color: rgba(255, 255, 255, .7); }

/* a text-styled button, for POST actions that read as links (sign out) */
.link-button {
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
  color: var(--color-primary); text-decoration: underline; text-underline-offset: 2px;
}
.link-button:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-xs); }

/* an input with a button inside its right edge (show/hide password) */
.input-with-action { position: relative; }
.input-with-action .input { padding-right: 48px; }
.input-with-action .input-action {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 40px; height: 40px;
}
[data-password-toggle] .when-shown { display: none; }
[data-password-toggle][aria-pressed="true"] .when-shown { display: inline; }
[data-password-toggle][aria-pressed="true"] .when-hidden { display: none; }

/* a submit button waiting for the server (static/js/app.js, form[data-busy]) */
.btn[aria-busy="true"] { cursor: progress; opacity: .8; }

/* filter forms above lists */
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); }
.filter-bar .field { margin: 0; min-width: 180px; flex: 1 1 180px; }
.filter-bar .field:first-child { flex-basis: 260px; }
.inline-form { display: inline; }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }

/* --------------------------------------------------------------------------
   "View as" banner (apps.accounts.impersonation)
   A fixed height, so the sticky sidebar and top bar can sit exactly below it
   at every width; on a phone the explanatory sentence is dropped rather than
   letting the bar wrap and cover the page.
   -------------------------------------------------------------------------- */
:root { --impersonation-height: 48px; }
.impersonation-banner {
  position: sticky; top: 0; z-index: calc(var(--z-drawer) + 1);
  height: var(--impersonation-height);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: 0 var(--space-4);
  background: var(--color-warning-solid); color: #fff;
  font-size: var(--text-sm);
}
.impersonation-text { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.impersonation-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.impersonation-text .icon { flex: none; width: 18px; height: 18px; }
.impersonation-note { opacity: .9; margin-left: var(--space-2); }
.impersonation-return {
  flex: none; background: #fff; color: var(--color-warning); border-color: transparent; font-weight: 650;
}
.impersonation-return:hover { background: #fff; color: var(--color-text); }
.is-impersonating .sidebar { top: var(--impersonation-height); height: calc(100vh - var(--impersonation-height)); }
.is-impersonating .topbar { top: var(--impersonation-height); }
@media (max-width: 767.98px) {
  /* The return button keeps its visible label - it is the button's name for
     screen readers too. The banner text truncates instead. */
  .impersonation-note { display: none; }
  .impersonation-banner { padding: 0 var(--space-3); }
}

/* ==========================================================================
   Page hero, tabs, charts (the redesign)
   ========================================================================== */

/* A dashboard's opening band: greeting, date, the day's key actions. */
.page-hero {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-5); flex-wrap: wrap;
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  background: var(--gradient-hero);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.page-hero::before {
  content: ""; position: absolute; right: -60px; top: -80px; width: 260px; height: 260px;
  border-radius: 50%; background: var(--gradient-brand); opacity: .09; pointer-events: none;
}
.page-hero > * { position: relative; }
.page-hero h1 { margin: 0; font-size: var(--text-2xl); }
.page-hero .page-subtitle { margin-top: var(--space-1); }
.hero-icon {
  width: 52px; height: 52px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius-lg);
  background: var(--gradient-brand); color: #fff;
  box-shadow: 0 10px 24px -10px color-mix(in srgb, var(--color-primary-solid) 70%, transparent);
}
.hero-icon .icon { width: 26px; height: 26px; }
.hero-main { display: flex; align-items: center; gap: var(--space-4); min-width: 0; }
@media (max-width: 559.98px) { .page-hero { padding: var(--space-5); } .hero-icon { width: 44px; height: 44px; } }

/* Tabs (static/js/app.js, [data-tabs]). Without JavaScript every panel is
   shown, one under the other, and the tab strip links to them. */
.tabs { margin-top: var(--space-2); }
.tab-list {
  display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: none;
  padding: 4px; margin-bottom: var(--space-5);
  background: var(--color-surface-3);
  border-radius: var(--radius-md);
  width: max-content; max-width: 100%;
}
.tab-list::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 36px; padding: 0 var(--space-4);
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--color-text-muted);
  font: inherit; font-weight: 600; font-size: var(--text-sm); white-space: nowrap;
  cursor: pointer; text-decoration: none;
  transition: background var(--duration-fast), color var(--duration-fast), box-shadow var(--duration-fast);
}
.tab .icon { width: 16px; height: 16px; }
.tab:hover { color: var(--color-text); text-decoration: none; }
.tab[aria-selected="true"] { background: var(--color-surface); color: var(--color-primary); box-shadow: var(--shadow-sm); }
.tab:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.tab-count {
  min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-grid; place-items: center;
  border-radius: var(--radius-full);
  background: var(--color-surface); color: var(--color-text-muted);
  font-size: var(--text-2xs); font-weight: 700;
}
.tab[aria-selected="true"] .tab-count { background: var(--color-primary-soft); color: var(--color-primary); }
.tab-panel:focus-visible { outline: none; }
.tabs.is-enhanced .tab-panel[hidden] { display: none; }
.tabs:not(.is-enhanced) .tab-panel + .tab-panel { margin-top: var(--space-6); }

/* --- charts ---------------------------------------------------------------
   Thin marks, 4px rounded data ends on the baseline, a 2px surface gap
   between stacked parts, recessive grid; text in text colours, never the
   series colour. */
.chart { margin: 0; min-width: 0; }
.chart-empty { margin: 0; padding: var(--space-8) var(--space-4); text-align: center; color: var(--color-text-muted); font-size: var(--text-sm); }
.chart-legend { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-3); padding: 0; font-size: var(--text-xs); color: var(--color-text-muted); }
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--series-1); }
.swatch[data-key="held"] { background: var(--series-1); }
.swatch[data-key="failed"], .swatch[data-key="absent"] { background: var(--status-critical); }
.swatch[data-key="present"] { background: var(--status-good); }
.swatch[data-key="partial"] { background: var(--status-warning); }
.swatch[data-key="excused"] { background: var(--status-neutral); }

.chart-frame { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: var(--space-2); }
.chart-axis { position: relative; width: 34px; height: 180px; font-size: var(--text-2xs); color: var(--chart-axis); font-variant-numeric: tabular-nums; }
.chart-axis span { position: absolute; right: 0; bottom: var(--y); transform: translateY(50%); line-height: 1; }
.chart-plot {
  position: relative; height: 180px;
  display: flex; align-items: flex-end; gap: 6px;
  border-bottom: 1px solid var(--chart-axis);
}
.chart-grid { position: absolute; inset: 0; pointer-events: none; }
.chart-grid span { position: absolute; left: 0; right: 0; bottom: var(--y); border-top: 1px solid var(--chart-grid); }
.chart-grid span:first-child { display: none; }
.chart-col {
  position: relative; flex: 1 1 0; height: 100%; min-width: 0;
  display: flex; flex-direction: column-reverse; gap: 2px;
  border-radius: 4px 4px 0 0; cursor: default; outline: none;
}
.chart-col::before { content: ""; position: absolute; inset: 0 -3px; border-radius: 6px; background: var(--color-primary-soft); opacity: 0; transition: opacity var(--duration-fast); }
.chart-col:hover::before, .chart-col:focus-visible::before { opacity: .7; }
.chart-col:focus-visible { box-shadow: var(--focus-ring); }
.chart-seg { position: relative; height: var(--h); min-height: 2px; background: var(--series-1); }
.chart-seg:last-child { border-radius: 4px 4px 0 0; }
.chart-seg[data-key="failed"] { background: var(--status-critical); }
.chart-xlabels { grid-column: 2; display: flex; gap: 6px; margin-top: 6px; font-size: var(--text-2xs); color: var(--chart-axis); font-variant-numeric: tabular-nums; }
.chart-xlabels span { flex: 1 1 0; min-width: 0; text-align: center; overflow: hidden; white-space: nowrap; }
.chart-columns .chart-xlabels span:nth-child(even) { visibility: hidden; }
@media (min-width: 900px) { .chart-columns .chart-xlabels span:nth-child(even) { visibility: visible; } }
.chart-xlabels.is-positioned { position: relative; display: block; height: 14px; }
.chart-xlabels.is-positioned span { position: absolute; left: var(--x); transform: translateX(-50%); }
.chart-xlabels.is-positioned span:first-child { transform: none; }
.chart-xlabels.is-positioned span:last-child { transform: translateX(-100%); }
@media (max-width: 599.98px) { .chart-xlabels.is-positioned span:nth-child(even) { visibility: hidden; } }

.chart-line .chart-plot { display: block; }
.chart-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.chart-stroke { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--series-1); opacity: .08; }
.chart-dot {
  position: absolute; left: var(--x); top: var(--y);
  width: 10px; height: 10px; margin: -5px 0 0 -5px;
  border-radius: 50%; background: var(--series-1);
  box-shadow: 0 0 0 2px var(--color-surface);
  outline: none; cursor: default;
}
.chart-dot::before { content: ""; position: absolute; inset: -9px; border-radius: 50%; }
.chart-dot:hover, .chart-dot:focus-visible { box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 5px color-mix(in srgb, var(--series-1) 30%, transparent); }

.meter { display: flex; gap: 2px; height: 14px; border-radius: var(--radius-full); overflow: hidden; background: var(--color-surface-3); }
.meter-seg { width: var(--w); min-width: 3px; background: var(--status-neutral); }
.meter-seg[data-key="present"] { background: var(--status-good); }
.meter-seg[data-key="partial"] { background: var(--status-warning); }
.meter-seg[data-key="absent"] { background: var(--status-critical); }
.meter-legend { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.meter-legend li { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); background: var(--color-surface-2); font-size: var(--text-sm); }
.meter-label { color: var(--color-text-muted); }
.meter-value { font-weight: 700; color: var(--color-text); }
.meter-pct { color: var(--color-text-muted); font-size: var(--text-xs); min-width: 44px; text-align: right; }

.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.hbar { display: grid; grid-template-columns: minmax(70px, 140px) minmax(0, 1fr) 54px; align-items: center; gap: var(--space-3); padding: 2px 4px; border-radius: var(--radius-sm); outline: none; }
.hbar:hover, .hbar:focus-visible { background: var(--color-surface-2); }
.hbar:focus-visible { box-shadow: var(--focus-ring); }
.hbar-label { font-size: var(--text-sm); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 10px; border-radius: var(--radius-full); background: var(--color-surface-3); overflow: hidden; }
.hbar-fill { display: block; height: 100%; width: var(--w); background: var(--series-1); border-radius: var(--radius-full); }
.hbar-value { font-size: var(--text-sm); font-weight: 650; text-align: right; }

.chart-table { margin-top: var(--space-3); font-size: var(--text-sm); }
.chart-table > summary { cursor: pointer; color: var(--color-text-muted); font-weight: 550; width: max-content; }
.chart-table > summary:hover { color: var(--color-primary); }
.chart-table .table-wrap { margin-top: var(--space-2); max-height: 260px; }

/* the hover/focus tooltip for [data-tip] marks (static/js/app.js) */
.viz-tip {
  position: fixed; z-index: var(--z-dropdown); pointer-events: none;
  max-width: 260px; padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--color-tooltip-bg); color: var(--color-tooltip-text);
  font-size: var(--text-xs); font-weight: 600; line-height: 1.35;
  box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(4px); transition: opacity var(--duration-fast), transform var(--duration-fast);
}
.viz-tip.is-visible { opacity: 1; transform: none; }

/* a headline figure with its caption, above a chart */
.headline { display: flex; align-items: baseline; gap: var(--space-2); margin-bottom: var(--space-4); flex-wrap: wrap; }
.headline-value { font-size: var(--text-3xl); font-weight: 750; letter-spacing: -.02em; line-height: 1; }
.headline-label { color: var(--color-text-muted); font-size: var(--text-sm); }

.dash-grid.is-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dash-grid.is-single { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 1023.98px) { .dash-grid, .dash-grid.is-even { grid-template-columns: minmax(0, 1fr); } }

/* ==========================================================================
   Utilities
   ========================================================================== */
.muted    { color: var(--color-text-muted); }
.faint    { color: var(--color-text-faint); }
.small    { font-size: var(--text-sm); }
.mono     { font-family: var(--font-mono); font-size: .88em; }
.row      { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: var(--space-3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.stack    { display: grid; gap: var(--space-4); }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: var(--space-2); } .mt-2 { margin-top: var(--space-4); } .mt-3 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--space-4); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }

.htmx-request .htmx-indicator { visibility: visible; }
.htmx-indicator { visibility: hidden; }

/* A polled region whose last refresh failed. Dimmed rather than emptied:
   the last known participant count is still worth something to an admin
   watching a lesson, but it has to stop looking current. static/js/app.js
   also puts a translated title on it. */
[data-stale] {
  opacity: .5;
  filter: grayscale(1);
  transition: opacity .2s ease;
}

.sr-only, .visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------------------
   Keyboard access
   -------------------------------------------------------------------------- */

/* Off-screen rather than display:none, because a hidden element is not
   focusable and the whole point is that it is the first thing Tab reaches. */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: var(--z-skip);
  background: var(--color-primary-solid); color: var(--color-on-primary);
  padding: var(--space-3) var(--space-4); border-radius: 0 0 var(--radius-sm) 0;
  text-decoration: none; font-weight: 600;
}
.skip-link:focus { left: 0; }

/* focus-visible rather than focus, so a mouse click does not leave a ring
   behind but a Tab does. Applied to everything interactive: it used to be on
   .btn alone, which left every link and table action with the browser
   default - and in the dark theme that default is close to invisible. */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}
.side-link:focus-visible, .menu-item:focus-visible, .icon-btn:focus-visible,
.user-button:focus-visible, .kpi:focus-visible, .tab:focus-visible,
.chart-col:focus-visible, .hbar:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-md); }
.chart-dot:focus-visible { outline: none; border-radius: 50%; }

/* --------------------------------------------------------------------------
   Legacy top header - kept so a page rendered by an older template still
   has a usable navigation bar.
   -------------------------------------------------------------------------- */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: var(--z-sticky);
}
.site-header .inner { display: flex; align-items: center; gap: var(--space-4); min-height: 58px; }
.nav { display: flex; gap: var(--space-1); align-items: center; margin-left: auto; flex-wrap: wrap; }
.nav a, .nav button {
  color: var(--color-text-muted); padding: 6px var(--space-3); border-radius: var(--radius-sm);
  font-size: var(--text-base); background: none; border: 0; cursor: pointer; font-family: inherit;
}
.nav a:hover, .nav button:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--color-text); font-weight: 600; }
main { display: block; }
.site-header ~ main { padding: var(--space-6) 0 var(--space-12); }

/* --------------------------------------------------------------------------
   Two-factor authentication
   -------------------------------------------------------------------------- */

/* The QR is inline SVG, so it inherits currentColor unless told otherwise.
   A white plate behind it keeps it scannable in a dark theme, where an
   inverted code will not read on most phones. */
.qr-box {
  margin: var(--space-4) auto;
  padding: var(--space-3);
  width: max-content; max-width: 100%;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.qr-box svg { display: block; width: 190px; height: 190px; }

.secret-key {
  display: inline-block;
  margin-top: var(--space-1);
  padding: 6px 10px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  /* The key is long and unbreakable; let it wrap rather than push the card
     wide enough to scroll the page sideways on a phone. */
  word-break: break-all;
}

.recovery-codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: var(--space-4) 0 0;
  padding: 0;
  list-style: none;
}
.recovery-codes code {
  display: block;
  padding: var(--space-2) 10px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  letter-spacing: .04em;
  text-align: center;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1280px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1279.98px) {
  /* table.data.stack-lg: the stack-md cards, up to 1279px, for tables of
     seven columns or more - beside the sidebar they do not fit before that. */
  table.data.stack-lg thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0);
  }
  table.data.stack-lg, table.data.stack-lg tbody,
  table.data.stack-lg tr, table.data.stack-lg td { display: block; width: 100%; }
  table.data.stack-lg tr { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); }
  table.data.stack-lg tbody tr:last-child { border-bottom: 0; }
  table.data.stack-lg tbody td,
  table.data.stack-lg tbody td:first-child,
  table.data.stack-lg tbody td:last-child { display: flex; gap: var(--space-3); padding: 3px 0; border: 0; }
  table.data.stack-lg td[data-label]::before {
    content: attr(data-label); flex: 0 0 30%;
    color: var(--color-text-muted); font-size: var(--text-xs); font-weight: 650;
    letter-spacing: .04em; text-transform: uppercase; padding-top: 2px;
  }
  table.data.stack-lg td:empty { display: none; }
  table.data.stack-lg tbody td.row-actions { flex-wrap: wrap; gap: var(--space-2); padding-top: var(--space-2); }
}

@media (max-width: 1023.98px) {
  .topbar { padding: 0 var(--space-4); }
  .content { padding: var(--space-5) var(--space-4) var(--space-10); }

  /* table.data.stack-md: one card per row up to tablet width, each cell on its own
     line labelled from data-label. For tables whose last columns matter -
     a "cancelled" badge or a Move button must not sit behind a sideways
     scroll. The header stays in the accessibility tree. */
  table.data.stack-md thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0);
  }
  table.data.stack-md, table.data.stack-md tbody,
  table.data.stack-md tr, table.data.stack-md td { display: block; width: 100%; }
  table.data.stack-md tr { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); }
  table.data.stack-md tbody tr:last-child { border-bottom: 0; }
  table.data.stack-md tbody td,
  table.data.stack-md tbody td:first-child,
  table.data.stack-md tbody td:last-child { display: flex; gap: var(--space-3); padding: 3px 0; border: 0; }
  table.data.stack-md td[data-label]::before {
    content: attr(data-label); flex: 0 0 30%;
    color: var(--color-text-muted); font-size: var(--text-xs); font-weight: 650;
    letter-spacing: .04em; text-transform: uppercase; padding-top: 2px;
  }
  table.data.stack-md td:empty { display: none; }
  table.data.stack-md tbody td.row-actions { flex-wrap: wrap; gap: var(--space-2); padding-top: var(--space-2); }
}

@media (max-width: 767.98px) {
  h1 { font-size: var(--text-xl); }
  .page-header { margin-bottom: var(--space-5); align-items: flex-start; }
  /* two KPIs per row on a phone, icon above the number */
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .kpi { flex-direction: column; align-items: flex-start; gap: var(--space-3); padding: var(--space-4); }
  .kpi-icon { width: 40px; height: 40px; }
  .kpi-arrow { display: none; }
  .kpi-value { font-size: var(--text-2xl); }
  .metric-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { padding: var(--space-4); }
  .user-button-name { display: none; }
  .user-button { padding: 0 6px 0 4px; }
  .topbar-title .crumb { display: none; }
  .card-header, .card-body { padding-left: var(--space-4); padding-right: var(--space-4); }
  table.data th:first-child, table.data td:first-child { padding-left: var(--space-4); }
  table.data th:last-child, table.data td:last-child { padding-right: var(--space-4); }

  .lesson { grid-template-columns: 1fr; gap: var(--space-2); }
  .lesson-time .from, .lesson-time .to { display: inline; }
  .lesson-actions { justify-content: flex-start; }

  /* Filter bars: a select squeezed to a third of a phone's width shows
     about two characters of "Mathematics and Computer Science". */
  .row > .field { flex: 1 1 100%; }
  .row > .field .input { width: 100%; }

  /* the legacy header scrolls sideways rather than stacking */
  .site-header { position: static; }
  .site-header .inner { flex-wrap: wrap; gap: var(--space-2); padding-top: var(--space-2); padding-bottom: var(--space-2); }
  .nav { margin-left: 0; width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a, .nav button { white-space: nowrap; }
}

@media (max-width: 479.98px) {
  .topbar { gap: var(--space-2); }
  .topbar-actions { gap: 0; }
  .icon-btn { width: 36px; height: 36px; }
  /* the globe alone on a phone; the language code needs room it does not have */
  .icon-btn.lang-button { width: 36px; padding: 0; justify-content: center; }
  .lang-button .lang-code { display: none; }
  /* three tiles side by side leave ~65px for a label, less than "Обрабатывается"
     needs; on a phone they become rows with the figure on the right */
  .metric-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .metric-grid-3 .metric {
    flex-direction: row; align-items: center; justify-content: space-between; gap: var(--space-3);
    padding-top: var(--space-3); padding-bottom: var(--space-3);
  }
  .metric-grid-3 .metric-value { margin-top: 0; padding-top: 0; font-size: var(--text-xl); }
  .auth-card .card-body { padding: var(--space-6) var(--space-5); }
  .recovery-codes { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .dot-pulse { animation: none; }
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
