/* ==========================================================================
   SIPM&R Campus — design system (v2)
   Visual language: quiet, editorial, institutional. Warm neutral surfaces, hairline
   borders, ink-dark actions, one institutional green for links/active states.
   Sections: 1 tokens · 2 base · 3 shell · 4 components · 5 states/skeleton
             6 motion · 7 responsive · 8 utilities
   ========================================================================== */

/* 1. TOKENS -------------------------------------------------------------- */
:root {
  --font-sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, Consolas, monospace;
  --text-2xs: 0.6875rem; --text-xs: 0.75rem; --text-sm: 0.8125rem; --text-md: 0.875rem; --text-lg: 1rem; --text-xl: 1.125rem; --text-2xl: 1.375rem; --text-3xl: 1.75rem;
  --leading: 1.5;

  --spacing-xs: 4px; --spacing-sm: 8px; --spacing-md: 16px; --spacing-lg: 24px; --spacing-xl: 32px; --spacing-2xl: 48px;
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 10px; --radius-pill: 999px;

  --shadow-menu: 0 8px 24px rgba(20, 20, 18, 0.10), 0 1px 2px rgba(20, 20, 18, 0.06);
  --shadow-dialog: 0 24px 64px rgba(20, 20, 18, 0.18), 0 2px 6px rgba(20, 20, 18, 0.08);

  /* Neutrals (warm) */
  --surface-primary: #f6f6f3;
  --surface-secondary: #ffffff;
  --surface-muted: #f0f0ec;
  --surface-raised: #ffffff;
  --surface-hover: #f2f2ee;
  --surface-inset: #fafaf8;
  --border-default: #e6e5df;
  --border-strong: #cfcdc4;
  --text-primary: #1b1b18;
  --text-secondary: #56564f;
  --text-muted: #86857c;
  --text-inverse: #ffffff;

  /* Institutional accent: deep pine green (rehabilitation / clinical calm) */
  --accent: #1b5e4a; --accent-hover: #174f3e; --accent-soft: #e6f0eb; --accent-contrast: #ffffff;
  /* Primary action = ink */
  --primary: #1b1b18; --primary-hover: #33332e; --primary-active: #000000; --primary-soft: #ecebe6; --primary-contrast: #ffffff;
  --success: #1e7a46; --success-soft: #e4f3ea; --warning: #a35a00; --warning-soft: #fbefdc; --danger: #b42318; --danger-soft: #fbe9e7; --info: #175cd3; --info-soft: #e6eefb;
  --focus-ring: 0 0 0 2px var(--surface-secondary), 0 0 0 4px rgba(27, 94, 74, 0.55);

  --sidebar-bg: #fbfbf9; --sidebar-text: #56564f; --sidebar-text-active: #1b5e4a; --sidebar-hover: #f0f0ec; --sidebar-active: #e6f0eb; --sidebar-border: #e6e5df;
  --sidebar-width: 248px; --sidebar-collapsed-width: 64px; --topbar-height: 52px; --content-max: 1360px;

  --motion-instant: 100ms; --motion-fast: 150ms; --motion-normal: 200ms; --motion-slow: 280ms;
  --ease-standard: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

[data-theme="dark"] {
  --surface-primary: #131412; --surface-secondary: #1b1c1a; --surface-muted: #222421; --surface-raised: #232522; --surface-hover: #262825; --surface-inset: #181917;
  --border-default: #2c2e2a; --border-strong: #3f423d;
  --text-primary: #ebeae4; --text-secondary: #b3b2aa; --text-muted: #85847b; --text-inverse: #131412;
  --accent: #6cc39c; --accent-hover: #86d1af; --accent-soft: rgba(108, 195, 156, 0.14); --accent-contrast: #0f2b21;
  --primary: #ebeae4; --primary-hover: #ffffff; --primary-active: #d6d5cf; --primary-soft: #2c2e2a; --primary-contrast: #131412;
  --success: #5cc389; --success-soft: rgba(92, 195, 137, 0.14); --warning: #e3a44a; --warning-soft: rgba(227, 164, 74, 0.14); --danger: #f0776b; --danger-soft: rgba(240, 119, 107, 0.14); --info: #7fb0f5; --info-soft: rgba(127, 176, 245, 0.14);
  --focus-ring: 0 0 0 2px var(--surface-secondary), 0 0 0 4px rgba(108, 195, 156, 0.6);
  --shadow-menu: 0 8px 24px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-dialog: 0 24px 64px rgba(0, 0, 0, 0.6);
  --sidebar-bg: #161715; --sidebar-text: #b3b2aa; --sidebar-text-active: #86d1af; --sidebar-hover: #222421; --sidebar-active: rgba(108, 195, 156, 0.12); --sidebar-border: #2c2e2a;
  color-scheme: dark;
}

/* 2. BASE ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font-sans); font-size: var(--text-md); line-height: var(--leading); color: var(--text-primary); background: var(--surface-primary); -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01"; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; letter-spacing: -0.012em; }
p { margin: 0 0 var(--spacing-sm); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code { font-family: var(--font-mono); font-size: 0.8125em; background: var(--surface-muted); padding: 1px 6px; border-radius: 4px; color: var(--text-primary); }
svg.icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; vertical-align: -3px; }
svg.icon.icon-sm { width: 13px; height: 13px; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; top: -48px; left: var(--spacing-md); background: var(--primary); color: var(--primary-contrast); padding: var(--spacing-sm) var(--spacing-md); border-radius: var(--radius-md); z-index: 100; }
.skip-link:focus { top: var(--spacing-md); }
[hidden] { display: none !important; }
.sprite { display: none; }
kbd { font-family: var(--font-sans); font-size: var(--text-2xs); padding: 1px 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-secondary); color: var(--text-muted); line-height: 1.4; }

/* 3. SHELL --------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; z-index: 40; border-right: 1px solid var(--sidebar-border); transition: width var(--motion-normal) var(--ease-standard), transform var(--motion-normal) var(--ease-standard); }
.sidebar-brand { height: var(--topbar-height); display: flex; align-items: center; padding: 0 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text-primary); min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--primary); color: var(--primary-contrast); display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: -0.02em; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-weight: 600; font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.brand-sub { font-size: var(--text-2xs); color: var(--text-muted); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 10px 12px; }
.nav-group { margin-top: 14px; }
.nav-group:first-child { margin-top: 2px; }
.nav-group-title { font-size: var(--text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); padding: 6px 10px 4px; white-space: nowrap; }
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.nav-link { display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--sidebar-text); font-size: var(--text-sm); font-weight: 500; white-space: nowrap; transition: background var(--motion-fast), color var(--motion-fast); }
.nav-link:hover { background: var(--sidebar-hover); color: var(--text-primary); text-decoration: none; }
.nav-link.is-active { background: var(--sidebar-active); color: var(--sidebar-text-active); }
.nav-link .icon { color: var(--text-muted); }
.nav-link.is-active .icon, .nav-link:hover .icon { color: currentColor; }
.sidebar-footer { padding: 8px 10px; border-top: 1px solid var(--sidebar-border); display: flex; justify-content: flex-end; }
.sidebar-footer .btn { color: var(--text-muted); }

.app-main { flex: 1; min-width: 0; margin-left: var(--sidebar-width); display: flex; flex-direction: column; transition: margin-left var(--motion-normal) var(--ease-standard); }
.topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar-height); display: grid; grid-template-columns: 1fr minmax(240px, 420px) 1fr; align-items: center; gap: var(--spacing-md); padding: 0 var(--spacing-lg); background: rgba(246, 246, 243, 0.85); backdrop-filter: saturate(160%) blur(8px); border-bottom: 1px solid var(--border-default); }
[data-theme="dark"] .topbar { background: rgba(19, 20, 18, 0.85); }
.topbar-left { display: flex; align-items: center; gap: var(--spacing-sm); min-width: 0; }
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 2px; }
.search-trigger { display: flex; align-items: center; gap: 10px; height: 34px; width: 100%; padding: 0 10px 0 12px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--surface-secondary); color: var(--text-muted); font: inherit; font-size: var(--text-sm); cursor: text; transition: border-color var(--motion-fast), box-shadow var(--motion-fast); }
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger span:first-of-type { flex: 1; text-align: left; }
.search-trigger kbd + kbd { margin-left: 2px; }
.breadcrumbs ol { list-style: none; display: flex; align-items: center; gap: 6px; margin: 0; padding: 0; font-size: var(--text-sm); color: var(--text-muted); flex-wrap: nowrap; overflow: hidden; }
.breadcrumbs li { white-space: nowrap; }
.breadcrumbs li + li::before { content: "/"; margin-right: 6px; color: var(--border-strong); }
.breadcrumbs a { color: var(--text-secondary); }
.breadcrumbs [aria-current="page"] { color: var(--text-primary); font-weight: 500; }
.page { padding: var(--spacing-lg) var(--spacing-xl) var(--spacing-2xl); max-width: var(--content-max); width: 100%; margin: 0 auto; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--spacing-md); margin-bottom: var(--spacing-lg); flex-wrap: wrap; }
.page-title { font-size: var(--text-2xl); letter-spacing: -0.02em; }
.page-subtitle { margin: 4px 0 0; color: var(--text-secondary); font-size: var(--text-sm); }
.page-actions { display: flex; align-items: center; gap: var(--spacing-sm); flex-wrap: wrap; }

.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-width); }
.sidebar-collapsed .app-main { margin-left: var(--sidebar-collapsed-width); }
.sidebar-collapsed .brand-text, .sidebar-collapsed .nav-label, .sidebar-collapsed .nav-group-title { display: none; }
.sidebar-collapsed .nav-link { justify-content: center; padding: 0; }
.sidebar-collapsed .sidebar-footer .icon { transform: rotate(180deg); }
.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(27, 27, 24, 0.4); z-index: 35; }

.user-chip { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 8px 0 4px; border-radius: var(--radius-md); cursor: pointer; list-style: none; border: 1px solid transparent; }
.user-chip:hover { background: var(--surface-hover); }
.user-chip::-webkit-details-marker { display: none; }
.user-chip-name { font-size: var(--text-sm); font-weight: 500; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 10px; font-weight: 600; letter-spacing: 0.02em; display: inline-grid; place-items: center; flex-shrink: 0; }
.avatar-sm { width: 22px; height: 22px; font-size: 9px; }
.avatar-lg { width: 52px; height: 52px; font-size: var(--text-lg); }
[data-theme="dark"] .icon-sun, :root:not([data-theme="dark"]) .icon-moon { display: none; }

/* Auth */
.auth-body { background: var(--surface-primary); }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-aside { display: flex; flex-direction: column; justify-content: space-between; padding: var(--spacing-2xl); background: var(--primary); color: var(--primary-contrast); }
[data-theme="dark"] .auth-aside { background: #0f2b21; color: #ebeae4; }
.auth-aside .brand-mark { background: rgba(255, 255, 255, 0.14); color: inherit; }
.auth-aside .brand-name, .auth-aside .brand-sub { color: inherit; }
.auth-aside .brand-sub { opacity: 0.7; }
.auth-statement { font-size: clamp(1.5rem, 2.6vw, 2.25rem); font-weight: 500; letter-spacing: -0.025em; line-height: 1.15; max-width: 22ch; }
.auth-statement em { font-style: normal; opacity: 0.6; }
.auth-aside-footer { font-size: var(--text-xs); opacity: 0.65; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: var(--spacing-2xl) var(--spacing-lg); }
.auth-card { width: 100%; max-width: 380px; }
.auth-title { font-size: var(--text-2xl); letter-spacing: -0.02em; margin-bottom: 6px; }
.auth-footer { margin: var(--spacing-lg) 0 0; }

/* 4. COMPONENTS ---------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px; font: inherit; font-size: var(--text-sm); font-weight: 500; line-height: 1; border-radius: var(--radius-md); border: 1px solid transparent; cursor: pointer; white-space: nowrap; transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast), transform var(--motion-instant); text-decoration: none; }
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn.is-disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-secondary); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text-primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }
.btn-sm { height: 28px; padding: 0 10px; font-size: var(--text-xs); }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn-block { width: 100%; }
.btn[aria-busy="true"] { position: relative; color: transparent; }
.btn[aria-busy="true"]::after { content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid var(--primary-contrast); border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
.btn-secondary[aria-busy="true"]::after, .btn-ghost[aria-busy="true"]::after { border-color: var(--text-primary); border-right-color: transparent; }

.card { background: var(--surface-secondary); border: 1px solid var(--border-default); border-radius: var(--radius-lg); padding: var(--spacing-lg); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-md); margin-bottom: var(--spacing-md); flex-wrap: wrap; }
.card-title { font-size: var(--text-md); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-table { padding: 0; overflow: hidden; }
.card-form { max-width: 860px; }
.card-narrow { max-width: 520px; }
.card-narrow-wide { max-width: 760px; }
.card-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-md); padding: 10px var(--spacing-md); flex-wrap: wrap; position: sticky; top: calc(var(--topbar-height) + 8px); z-index: 5; }
.count { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--surface-muted); color: var(--text-secondary); font-size: var(--text-2xs); font-weight: 600; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--spacing-lg); }
.grid-3-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: var(--spacing-lg); align-items: start; }
.stack { display: flex; flex-direction: column; gap: var(--spacing-lg); }
.cluster { display: flex; align-items: center; gap: var(--spacing-sm); flex-wrap: wrap; }
.cluster-sm { display: inline-flex; align-items: center; gap: 6px; }

/* Metrics */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1px; background: var(--border-default); border: 1px solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden; }
.metric-card { display: flex; flex-direction: column; gap: 6px; background: var(--surface-secondary); padding: 18px 20px; color: inherit; min-height: 108px; transition: background var(--motion-fast); }
a.metric-card:hover { text-decoration: none; background: var(--surface-inset); }
.metric-label { font-size: var(--text-xs); color: var(--text-secondary); font-weight: 500; }
.metric-value { font-size: var(--text-3xl); font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.metric-hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: auto; }
.metric-inline { font-size: var(--text-2xl); font-weight: 600; margin: 0; letter-spacing: -0.02em; }

/* Forms */
.form-section { border: 0; padding: 0; margin: 0 0 var(--spacing-lg); min-width: 0; }
.form-section + .form-section { padding-top: var(--spacing-lg); border-top: 1px solid var(--border-default); }
.form-section-title { font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--spacing-md); padding: 0; color: var(--text-primary); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--spacing-md) var(--spacing-lg); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-field-full { grid-column: 1 / -1; }
.form-field-2 { grid-column: span 2; }
.form-field-3 { grid-column: span 3; }
.form-field-grow { flex: 1; }
.form-label { font-size: var(--text-sm); font-weight: 500; color: var(--text-primary); }
.form-input { font: inherit; font-size: var(--text-md); color: var(--text-primary); background: var(--surface-secondary); border: 1px solid var(--border-strong); border-radius: var(--radius-md); padding: 0 10px; width: 100%; height: 36px; transition: border-color var(--motion-fast), box-shadow var(--motion-fast); }
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(27, 94, 74, 0.18); outline: none; }
[data-theme="dark"] .form-input:focus { box-shadow: 0 0 0 3px rgba(108, 195, 156, 0.25); }
.form-input:disabled { background: var(--surface-muted); color: var(--text-muted); }
.form-input[readonly] { background: var(--surface-inset); }
textarea.form-input { height: auto; padding: 8px 10px; resize: vertical; min-height: 72px; }
select.form-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2386857c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; padding-right: 30px; }
.input-code { text-transform: uppercase; font-family: var(--font-mono); font-size: var(--text-sm); }
.font-mono { font-family: var(--font-mono); font-size: var(--text-sm); }
.form-help { font-size: var(--text-xs); color: var(--text-muted); }
.form-error { font-size: var(--text-xs); color: var(--danger); font-weight: 500; }
.form-error:empty { display: none; }
.input-validation-error { border-color: var(--danger); }
.form-check { display: flex; align-items: flex-start; gap: 10px; font-size: var(--text-sm); cursor: pointer; line-height: 1.4; }
.form-check input { width: 15px; height: 15px; margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
.form-check-sm { font-size: var(--text-xs); align-items: center; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px var(--spacing-md); }
.form-actions { display: flex; align-items: center; gap: var(--spacing-sm); padding-top: var(--spacing-md); border-top: 1px solid var(--border-default); }
.form-actions-compact { border-top: 0; padding-top: var(--spacing-sm); }
.input-group { display: flex; gap: var(--spacing-sm); }
.input-group .form-input { flex: 1; }
.inline-form { padding: var(--spacing-md); border: 1px solid var(--border-default); border-radius: var(--radius-md); margin-bottom: var(--spacing-md); background: var(--surface-inset); }
.form-inline-add { display: flex; align-items: flex-end; gap: var(--spacing-sm); }
.form-inline-add .form-field:first-child { width: 90px; }

/* Filter bar */
.filter-bar { display: flex; align-items: center; gap: var(--spacing-sm); padding: 12px var(--spacing-md); border-bottom: 1px solid var(--border-default); flex-wrap: wrap; background: var(--surface-inset); }
.filter-search { position: relative; flex: 1 1 260px; display: flex; align-items: center; }
.filter-search .icon { position: absolute; left: 10px; color: var(--text-muted); pointer-events: none; }
.filter-search .form-input { padding-left: 32px; }
.filter-select { width: auto; min-width: 150px; flex: 0 1 auto; }
.filter-chips { display: flex; gap: var(--spacing-sm); padding: 8px var(--spacing-md); border-bottom: 1px solid var(--border-default); }
.chip { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent); font-size: var(--text-xs); font-weight: 500; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th, .data-table td { padding: 0 12px; height: 44px; text-align: left; border-bottom: 1px solid var(--border-default); vertical-align: middle; }
.data-table th:first-child, .data-table td:first-child { padding-left: var(--spacing-md); }
.data-table th:last-child, .data-table td:last-child { padding-right: var(--spacing-md); }
.data-table thead th { position: sticky; top: 0; height: 38px; background: var(--surface-secondary); color: var(--text-muted); font-weight: 500; font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.07em; white-space: nowrap; z-index: 1; }
.data-table tbody tr { transition: background var(--motion-fast); }
.data-table tbody tr:hover { background: var(--surface-inset); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table td { font-variant-numeric: tabular-nums; }
.data-table .col-num { text-align: right; }
.data-table .col-actions { text-align: right; width: 1%; white-space: nowrap; }
.data-table-compact th, .data-table-compact td { height: 36px; padding: 0 10px; }
.data-table-compact th:first-child, .data-table-compact td:first-child, .data-table-compact th:last-child, .data-table-compact td:last-child { padding-left: 10px; padding-right: 10px; }
.sort-link { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.sort-link:hover { color: var(--text-primary); text-decoration: none; }
th[aria-sort="ascending"] .sort-link, th[aria-sort="descending"] .sort-link { color: var(--text-primary); }
.link-strong { font-weight: 500; color: var(--text-primary); }
.link-strong:hover { color: var(--accent); }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diff-old { color: var(--danger); }
.diff-new { color: var(--success); }
.diff-table td { font-family: var(--font-mono); font-size: var(--text-xs); word-break: break-word; height: auto; padding: 8px 10px; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-md); padding: 10px var(--spacing-md); border-top: 1px solid var(--border-default); flex-wrap: wrap; background: var(--surface-inset); }
.pagination-controls { display: flex; align-items: center; gap: var(--spacing-sm); }
.pagination-page { font-variant-numeric: tabular-nums; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--surface-muted); color: var(--text-secondary); }

/* Alerts */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-md); font-size: var(--text-sm); border: 1px solid; }
.alert .icon { flex-shrink: 0; margin-top: 2px; }
.alert-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.alert div { color: var(--text-primary); }
.alert-danger div { color: var(--danger); }

/* Menus */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel { position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px; background: var(--surface-raised); border: 1px solid var(--border-default); border-radius: var(--radius-md); box-shadow: var(--shadow-menu); padding: 4px; z-index: 50; animation: menu-in var(--motion-fast) var(--ease-standard); }
.menu-right .menu-panel { left: auto; right: 0; }
.menu-header { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--border-default); margin-bottom: 4px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 32px; padding: 0 10px; border: 0; background: none; font: inherit; font-size: var(--text-sm); color: var(--text-primary); text-align: left; border-radius: var(--radius-sm); cursor: pointer; }
.menu-item:hover { background: var(--surface-hover); text-decoration: none; }
.menu-item .icon { color: var(--text-muted); }
.menu-item-danger, .menu-item-danger .icon { color: var(--danger); }
.menu-form { margin: 0; }

/* Detail lists */
.detail-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--spacing-md) var(--spacing-lg); margin: 0; }
.detail-list > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.detail-list dt { font-size: var(--text-xs); color: var(--text-muted); font-weight: 500; }
.detail-list dd { margin: 0; font-size: var(--text-md); overflow-wrap: anywhere; }
.detail-list-compact { grid-template-columns: 1fr; gap: 0; }
.detail-list-compact > div { flex-direction: row; justify-content: space-between; gap: var(--spacing-md); padding: 8px 0; border-bottom: 1px solid var(--border-default); }
.detail-list-compact > div:last-child { border-bottom: 0; }
.detail-list-compact dt { font-size: var(--text-sm); color: var(--text-secondary); }
.detail-list-compact dd { font-size: var(--text-sm); text-align: right; }
.link-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.link-list li a { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border-default); color: var(--text-primary); font-size: var(--text-sm); font-weight: 500; }
.link-list li:last-child a { border-bottom: 0; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-sm); padding: 8px 0; border-bottom: 1px solid var(--border-default); font-size: var(--text-sm); }
.list-row:last-child { border-bottom: 0; }
.group-title { font-size: var(--text-2xs); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: var(--spacing-sm); }

/* Profile + tabs */
.profile-header { display: flex; align-items: center; gap: var(--spacing-md); margin-bottom: var(--spacing-lg); }
.profile-name { font-size: var(--text-xl); letter-spacing: -0.015em; }
.tabs { display: flex; flex-direction: column; gap: var(--spacing-md); }
.tab-list { display: flex; gap: 2px; border-bottom: 1px solid var(--border-default); overflow-x: auto; }
.tab { height: 38px; padding: 0 12px; border: 0; background: none; font: inherit; font-size: var(--text-sm); font-weight: 500; color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; transition: color var(--motion-fast), border-color var(--motion-fast); }
.tab:hover { color: var(--text-primary); }
.tab[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--text-primary); }
.tab-panel { animation: fade-in var(--motion-normal) var(--ease-standard); }

/* Permission editor */
.permission-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: var(--spacing-md); }
.permission-module { border: 1px solid var(--border-default); margin: 0; min-width: 0; }
.permission-module:disabled { opacity: 0.7; }
.permission-list { display: flex; flex-direction: column; gap: 2px; }
.permission-item { padding: 6px 8px; border-radius: var(--radius-sm); }
.permission-item:hover { background: var(--surface-hover); }
.permission-item > span { display: flex; flex-direction: column; gap: 1px; }
.permission-code { font-size: 11px; color: var(--text-muted); background: none; padding: 0; }

/* Timeline, quick links */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border-default); font-size: var(--text-sm); }
.timeline-item:last-child { border-bottom: 0; }
.timeline-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-top: 7px; flex-shrink: 0; }
.quick-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.quick-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border-default); border-radius: var(--radius-md); color: var(--text-primary); font-size: var(--text-sm); font-weight: 500; transition: border-color var(--motion-fast), background var(--motion-fast); }
.quick-link:hover { text-decoration: none; border-color: var(--border-strong); background: var(--surface-inset); }
.quick-link .icon { color: var(--text-muted); }

/* Toasts */
.toast-host { position: fixed; bottom: var(--spacing-lg); right: var(--spacing-lg); display: flex; flex-direction: column; gap: var(--spacing-sm); z-index: 80; max-width: min(400px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: var(--spacing-md); padding: 10px 12px; border-radius: var(--radius-md); background: var(--primary); color: var(--primary-contrast); font-size: var(--text-sm); box-shadow: var(--shadow-menu); opacity: 0; transform: translateY(6px); transition: opacity var(--motion-normal) var(--ease-standard), transform var(--motion-normal) var(--ease-standard); }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--success); margin-top: 6px; flex-shrink: 0; }
.toast-danger::before { background: var(--danger); }
.toast-info::before { background: var(--info); }
.toast-warning::before { background: var(--warning); }
.toast-message { flex: 1; }
.toast-close { border: 0; background: none; font-size: 18px; line-height: 1; cursor: pointer; color: inherit; opacity: 0.7; padding: 0; }

/* Dialog */
.dialog { border: 1px solid var(--border-default); border-radius: var(--radius-lg); padding: 0; background: var(--surface-raised); color: var(--text-primary); box-shadow: var(--shadow-dialog); width: min(440px, calc(100vw - 32px)); animation: modal-in var(--motion-normal) var(--ease-standard); }
.dialog::backdrop { background: rgba(27, 27, 24, 0.45); }
.dialog-body { padding: var(--spacing-lg); margin: 0; }
.dialog-title { font-size: var(--text-lg); margin-bottom: 6px; }
.dialog-message { color: var(--text-secondary); font-size: var(--text-sm); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--spacing-sm); margin-top: var(--spacing-lg); }

/* Command palette */
.palette { position: fixed; inset: 0; z-index: 90; display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; }
.palette-backdrop { position: absolute; inset: 0; background: rgba(27, 27, 24, 0.4); }
.palette-panel { position: relative; width: min(600px, calc(100vw - 32px)); background: var(--surface-raised); border: 1px solid var(--border-default); border-radius: 12px; box-shadow: var(--shadow-dialog); overflow: hidden; animation: modal-in var(--motion-normal) var(--ease-standard); }
.palette-input-wrap { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--border-default); }
.palette-input-wrap .icon { color: var(--text-muted); }
.palette-input { flex: 1; height: 50px; border: 0; background: none; font: inherit; font-size: var(--text-lg); color: var(--text-primary); outline: none; }
.palette-list { max-height: 56vh; overflow-y: auto; padding: 6px; margin: 0; list-style: none; }
.palette-group { font-size: var(--text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); padding: 10px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-primary); font-size: var(--text-sm); }
.palette-item .icon { color: var(--text-muted); }
.palette-item.is-active { background: var(--surface-hover); }
.palette-item-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.palette-item-sub { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-item-kind { font-size: var(--text-2xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.palette-empty { padding: 28px; text-align: center; color: var(--text-muted); font-size: var(--text-sm); }
.palette-footer { display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border-default); font-size: var(--text-2xs); color: var(--text-muted); }

/* Drawer */
.drawer { position: fixed; inset: 0; z-index: 60; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(27, 27, 24, 0.35); opacity: 0; transition: opacity var(--motion-slow) var(--ease-standard); }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface-raised); border-left: 1px solid var(--border-default); box-shadow: var(--shadow-dialog); display: flex; flex-direction: column; transform: translateX(100%); transition: transform var(--motion-slow) var(--ease-standard); outline: none; }
.drawer.is-open .drawer-backdrop { opacity: 1; }
.drawer.is-open .drawer-panel { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 12px var(--spacing-lg); border-bottom: 1px solid var(--border-default); }
.drawer-title { font-size: var(--text-md); font-weight: 600; }
.drawer-body { padding: var(--spacing-lg); overflow-y: auto; flex: 1; }

/* 5. STATES & SKELETON --------------------------------------------------- */
.state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--spacing-2xl) var(--spacing-lg); gap: 6px; }
.state-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--surface-muted); color: var(--text-muted); display: grid; place-items: center; margin-bottom: 6px; }
.state-icon .icon { width: 18px; height: 18px; }
.state-error .state-icon, .state-conflict .state-icon { background: var(--danger-soft); color: var(--danger); }
.state-restricted .state-icon { background: var(--warning-soft); color: var(--warning); }
.state-title { font-size: var(--text-md); font-weight: 600; }
.state-message { color: var(--text-secondary); font-size: var(--text-sm); max-width: 440px; margin: 0; }
.state .btn { margin-top: var(--spacing-sm); }
.state-actions { display: flex; justify-content: center; padding-bottom: var(--spacing-xl); margin-top: calc(-1 * var(--spacing-lg)); }
.state-conflict { padding: 12px var(--spacing-md); flex-direction: row; text-align: left; align-items: center; background: var(--danger-soft); border-radius: var(--radius-md); gap: var(--spacing-md); margin-bottom: var(--spacing-lg); }
.state-conflict .state-icon { width: 32px; height: 32px; margin: 0; }
.state-conflict .state-title { font-size: var(--text-sm); }
.state-conflict .state-message { flex: 1; }
.state-conflict .btn { margin: 0; }

.skeleton { display: inline-block; background: linear-gradient(90deg, var(--surface-muted) 25%, var(--border-default) 50%, var(--surface-muted) 75%); background-size: 400% 100%; border-radius: 4px; animation: shimmer 1.4s ease-in-out infinite; }
.skeleton-text { height: 10px; }
.skeleton-heading { height: 24px; margin: 6px 0; }
.skeleton-block { display: block; height: 160px; border-radius: var(--radius-md); }
.skeleton-table { padding: 0; }
.skeleton-row { display: flex; gap: var(--spacing-lg); height: 44px; padding: 0 var(--spacing-md); border-bottom: 1px solid var(--border-default); align-items: center; }
.skeleton-row > .skeleton { flex: 1 1 0; }
.skeleton-row-head { height: 38px; }
.skeleton-row:last-child { border-bottom: 0; }
.w-20 { width: 20%; } .w-30 { width: 30%; } .w-35 { width: 35%; } .w-40 { width: 40%; } .w-45 { width: 45%; } .w-50 { width: 50%; } .w-55 { width: 55%; } .w-60 { width: 60%; } .w-70 { width: 70%; }
.fragment { min-height: 120px; transition: opacity var(--motion-fast) var(--ease-standard); }
.fragment.is-swapping { opacity: 0.4; }
.fragment.is-revealed > * { animation: fade-up var(--motion-normal) var(--ease-standard); }
.fragment[aria-busy="true"] { cursor: progress; }

/* 6. MOTION -------------------------------------------------------------- */
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
@keyframes menu-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modal-in { from { opacity: 0; transform: scale(0.985); } to { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .skeleton { animation: none; background: var(--surface-muted); }
}

/* 7. RESPONSIVE ---------------------------------------------------------- */
@media (max-width: 1200px) {
  .form-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-field-3 { grid-column: span 2; }
  .topbar { grid-template-columns: 1fr auto; }
  .topbar-search { display: none; }
}
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-width); }
  .sidebar-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-dialog); }
  .app-main, .sidebar-collapsed .app-main { margin-left: 0; }
  .sidebar-collapsed .brand-text, .sidebar-collapsed .nav-label, .sidebar-collapsed .nav-group-title { display: initial; }
  .sidebar-collapsed .nav-link { justify-content: flex-start; padding: 0 10px; }
  .sidebar-footer { display: none; }
  .grid-3-1 { grid-template-columns: 1fr; }
  .page { padding: var(--spacing-md) var(--spacing-md) var(--spacing-2xl); }
  .topbar { padding: 0 var(--spacing-md); }
  .card-toolbar { top: var(--topbar-height); }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}
@media (max-width: 767px) {
  .grid-2, .quick-links, .form-grid, .form-grid-4, .detail-list { grid-template-columns: 1fr; }
  .form-field-2, .form-field-3 { grid-column: auto; }
  .user-chip-name { display: none; }
  .breadcrumbs { display: none; }
  .page-title { font-size: var(--text-xl); }
  .filter-bar { padding: var(--spacing-md); }
  .filter-select { min-width: 0; flex: 1 1 45%; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; height: auto; }
  .data-table tr { padding: var(--spacing-sm) var(--spacing-md); border-bottom: 1px solid var(--border-default); }
  .data-table td { display: flex; justify-content: space-between; align-items: center; gap: var(--spacing-md); padding: 5px 0; border: 0; text-align: right; }
  .data-table td:first-child, .data-table td:last-child { padding-left: 0; padding-right: 0; }
  .data-table td[data-label]::before { content: attr(data-label); font-size: var(--text-2xs); color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; text-align: left; }
  .data-table td.col-actions { justify-content: flex-end; width: 100%; }
  .data-table td.col-num { text-align: right; }
  .truncate { max-width: 200px; }
  .pagination { flex-direction: column; align-items: stretch; text-align: center; }
  .pagination-controls { justify-content: center; }
  .toast-host { left: var(--spacing-md); right: var(--spacing-md); bottom: var(--spacing-md); }
  .form-inline-add { flex-wrap: wrap; }
  .permission-grid { grid-template-columns: 1fr; }
  .card-toolbar { position: static; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 8. UTILITIES ----------------------------------------------------------- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.tabular { font-variant-numeric: tabular-nums; }

.palette-input:focus-visible { box-shadow: none; }

.semester-block { padding: 12px 0; border-top: 1px solid var(--border-default); }
.semester-block:first-of-type { border-top: 0; }
.semester-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.semester-head .group-title { margin: 0; }

.tab-list { scrollbar-width: none; }
.tab-list::-webkit-scrollbar { display: none; }
.profile-header { padding: 16px 20px; }

/* 9. NOTIFICATIONS (topbar bell + dropdown) ------------------------------- */
.notification-bell > summary.notification-trigger { position: relative; }
.notification-badge { position: absolute; top: 1px; right: 1px; min-width: 15px; height: 15px; padding: 0 4px; border-radius: var(--radius-pill); background: var(--danger); color: #fff; font-size: 10px; font-weight: 600; line-height: 15px; text-align: center; pointer-events: none; }
.notification-panel { width: 340px; max-width: min(92vw, 380px); padding: 0; overflow: hidden; }
.notification-head { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-sm); padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--border-default); min-height: 40px; }
.notification-heading { font-size: var(--text-sm); font-weight: 600; }
.notification-head form { margin: 0; }
.notification-list { list-style: none; margin: 0; padding: 4px; max-height: 380px; overflow-y: auto; }
.notification-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); }
.notification-item.is-unread { background: var(--surface-muted); }
.notification-item + .notification-item { margin-top: 2px; }
.notification-icon { color: var(--text-muted); display: inline-flex; margin-top: 2px; }
.notification-item.is-unread .notification-icon { color: var(--accent); }
.notification-body { flex: 1 1 auto; min-width: 0; }
.notification-item-title { display: block; font-size: var(--text-sm); font-weight: 500; color: var(--text-primary); overflow-wrap: anywhere; }
a.notification-item-title:hover { color: var(--accent); }
.notification-message { margin: 1px 0 0; font-size: var(--text-xs); color: var(--text-secondary); overflow-wrap: anywhere; }
.notification-time { display: block; margin-top: 2px; font-size: var(--text-2xs); color: var(--text-muted); }
.notification-item-action { margin: 0; flex-shrink: 0; }
.notification-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: var(--spacing-xl) var(--spacing-md); text-align: center; color: var(--text-secondary); font-size: var(--text-sm); }
.notification-empty .icon { width: 22px; height: 22px; color: var(--text-muted); }
.notification-empty p { margin: 0; }
.notification-skeleton { padding: 12px; }

/* Detail-list rows that span both columns (used on the disciplinary case page). */
.detail-list .detail-span { grid-column: 1 / -1; }

/* 10. PRINT / REPORTS ----------------------------------------------------- */
/* Screen styling for the Reports module (report cards, printable sheet chrome)
   plus the @media print rules that turn a report page into a clean paper
   document: application chrome hidden, black on white, bordered tables. */

/* Reports index: card grid. */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--spacing-md); }
.report-card { display: flex; gap: var(--spacing-md); align-items: flex-start; padding: var(--spacing-lg); background: var(--surface-secondary); border: 1px solid var(--border-default); border-radius: var(--radius-lg); color: var(--text-primary); transition: border-color var(--motion-fast), background var(--motion-fast); }
.report-card:hover { border-color: var(--border-strong); background: var(--surface-inset); }
.report-card-icon { display: inline-flex; color: var(--accent); margin-top: 2px; }
.report-card-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.report-card-title { font-weight: 600; }
.report-card-desc { font-size: var(--text-sm); color: var(--text-secondary); }

/* Parameter bar and on-screen actions. */
.filter-select-wide { min-width: 340px; max-width: 100%; }
.report-actions { display: flex; justify-content: flex-end; gap: var(--spacing-sm); padding: 10px var(--spacing-md); border-bottom: 1px solid var(--border-default); }

/* The printable sheet. */
.report-sheet { padding: var(--spacing-lg) var(--spacing-lg) var(--spacing-xl); }
.report-head { text-align: center; border-bottom: 2px solid var(--text-primary); padding-bottom: var(--spacing-md); margin-bottom: var(--spacing-md); }
.report-institution { margin: 0; font-size: var(--text-lg); font-weight: 700; letter-spacing: 0.02em; }
.report-institution-sub { margin: 0 0 6px; font-size: var(--text-sm); color: var(--text-secondary); }
.report-title { margin: 0; font-size: var(--text-md); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.report-meta { display: flex; justify-content: space-between; gap: var(--spacing-md); margin-top: 8px; font-size: var(--text-sm); color: var(--text-secondary); flex-wrap: wrap; }
.report-footnote { margin: var(--spacing-md) 0 0; font-size: var(--text-xs); color: var(--text-muted); }
.report-table td.col-num, .report-table th.col-num { text-align: right; }
.report-total-row td { font-weight: 600; background: var(--surface-inset); border-top: 2px solid var(--border-strong); }

/* Summary stats (result sheet, DMC footer). */
.report-summary { display: flex; gap: var(--spacing-md); flex-wrap: wrap; margin: 0 0 var(--spacing-md); }
.report-summary-final { margin: var(--spacing-md) 0 0; }
.report-stat { border: 1px solid var(--border-default); border-radius: var(--radius-md); padding: 8px 14px; min-width: 110px; }
.report-stat dt { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); }
.report-stat dd { margin: 2px 0 0; font-size: var(--text-lg); font-weight: 600; font-variant-numeric: tabular-nums; }

/* DMC particulars and signature strip. */
.report-particulars { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px var(--spacing-lg); margin: 0 0 var(--spacing-lg); }
.report-particulars dt { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); }
.report-particulars dd { margin: 1px 0 0; font-weight: 500; }
.report-term { margin-bottom: var(--spacing-lg); break-inside: avoid; }
.report-term-title { font-size: var(--text-sm); font-weight: 600; margin: 0 0 6px; }
.report-signatures { display: flex; justify-content: space-between; gap: var(--spacing-xl); margin-top: 64px; }
.report-signature { flex: 0 1 220px; border-top: 1px solid var(--text-primary); padding-top: 6px; text-align: center; font-size: var(--text-sm); color: var(--text-secondary); }

/* Attendance matrix: wide table scrolls in its own container on screen. */
.report-matrix-wrap { overflow-x: auto; }
.report-matrix { width: auto; min-width: 100%; }
.report-matrix th.col-mark, .report-matrix td.col-mark { text-align: center; padding: 0 6px; }
.report-matrix .report-name-cell { white-space: nowrap; }
.mark-date { display: inline-block; font-size: var(--text-2xs); white-space: nowrap; }
.mark { display: inline-block; min-width: 18px; text-align: center; font-weight: 600; font-size: var(--text-xs); }
.mark-present { color: var(--success, #1a7f37); }
.mark-absent { color: var(--danger, #b42318); }
.mark-late { color: var(--warning, #b54708); }
.mark-excused, .mark-leave { color: var(--text-secondary); }

/* Keep the attendance matrix a real table on small screens (it scrolls instead of stacking). */
@media (max-width: 767px) {
  .report-matrix thead { display: table-header-group; }
  .report-matrix { display: table; width: auto; }
  .report-matrix tbody { display: table-row-group; width: auto; }
  .report-matrix tr { display: table-row; padding: 0; }
  .report-matrix td, .report-matrix th { display: table-cell; width: auto; height: 40px; text-align: left; border-bottom: 1px solid var(--border-default); }
  .report-matrix td.col-mark, .report-matrix th.col-mark { text-align: center; }
}

/* Landscape hint for wide registers (named page; honoured by Chromium-based browsers). */
.report-landscape { page: report-landscape; }
@page report-landscape { size: A4 landscape; }
@page { margin: 14mm 12mm; }

@media print {
  /* Hide every piece of application chrome. */
  .sidebar, .sidebar-backdrop, .topbar, .filter-bar, .report-actions, .page-actions,
  .btn, nav, .breadcrumbs, .skip-link, .toast-host, .palette, .dialog, .state-actions,
  .pagination { display: none !important; }

  /* The report sheet carries its own institution header, so the app page header
     (which would duplicate the title) is hidden too. */
  .page-header { display: none !important; }

  html, body, .app-body { background: #fff !important; color: #000 !important; }
  .app-main, .sidebar-collapsed .app-main { margin-left: 0 !important; }
  .page { padding: 0 !important; max-width: none !important; }

  /* The sheet fills the paper; drop card chrome. */
  .card, .card-table { border: 0 !important; border-radius: 0 !important; background: #fff !important; padding: 0 !important; box-shadow: none !important; overflow: visible !important; }
  .report-sheet { padding: 0; width: 100%; color: #000; }
  .report-head { border-color: #000; }
  .report-institution, .report-title { color: #000; }
  .report-meta, .report-institution-sub, .report-footnote { color: #333; }

  /* Black-on-white bordered tables that break cleanly across pages. */
  .table-wrap, .report-matrix-wrap { overflow: visible !important; }
  .data-table { font-size: 9pt; color: #000; }
  .data-table th, .data-table td { border: 1px solid #000 !important; height: auto; padding: 3pt 5pt; color: #000 !important; background: #fff !important; }
  .data-table thead th { position: static; background: #eee !important; color: #000 !important; }
  .data-table thead { display: table-header-group; }
  .data-table tbody tr:hover { background: #fff; }
  .data-table tr { break-inside: avoid; }
  .report-total-row td { background: #eee !important; }
  .report-matrix { width: 100%; }

  /* Restore the stacked-mobile table rules in case a narrow viewport is printing. */
  .data-table { display: table; width: 100%; }
  .data-table tbody { display: table-row-group; }
  .data-table tr { display: table-row; padding: 0; }
  .data-table td { display: table-cell; text-align: left; }
  .data-table td.col-num, .data-table th.col-num { text-align: right; }
  .report-matrix td.col-mark, .report-matrix th.col-mark { text-align: center; }
  .data-table td[data-label]::before { content: none; }

  /* Badges and marks print as plain bordered text. */
  .badge { border: 1px solid #000 !important; background: #fff !important; color: #000 !important; }
  .mark, .mark-present, .mark-absent, .mark-late, .mark-excused, .mark-leave { color: #000; }
  .report-stat { border-color: #000; }
  .report-stat dt, .report-stat dd, .report-particulars dt, .report-particulars dd { color: #000; }
  .report-signature { border-color: #000; color: #000; }
  a, a:visited { color: #000 !important; text-decoration: none; }
  code { background: none; padding: 0; }
}

/* 11. ANALYTICS ----------------------------------------------------------- */
/* Executive analytics (/analytics). All charts are server-rendered inline SVG —
   the CSP forbids chart libraries and inline styles, so bar geometry comes from
   SVG width/x/height attributes and every colour from these classes. Bars use a
   0-100 user-space with preserveAspectRatio="none"; labels stay in HTML so they
   never distort and remain readable to screen readers and to print. */

/* Categorical series colours (segmented bars + legends). */
:root {
  --chart-1: #1b5e4a; --chart-2: #2f7d92; --chart-3: #175cd3; --chart-4: #a35a00;
  --chart-5: #7a4bb5; --chart-6: #b42318; --chart-7: #4b8b3b; --chart-8: #86857c;
  --chart-alt: #9dc0b2;         /* second series in grouped bars (invoiced) */
  --chart-track: var(--surface-muted);
}
[data-theme="dark"] {
  --chart-1: #6cc39c; --chart-2: #6fb7cc; --chart-3: #7fb0f5; --chart-4: #e3a44a;
  --chart-5: #b394e8; --chart-6: #f0776b; --chart-7: #8fcb7c; --chart-8: #a8a79d;
  --chart-alt: #3f6e5c;
}

/* Sheet + panel grid. */
.analytics-sheet { display: block; }
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--spacing-lg); align-items: start; }
.analytics-panel { min-width: 0; }
.analytics-panel-wide { grid-column: 1 / -1; }
.analytics-print-only { display: none; }
.chart-subtitle { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: var(--spacing-md) 0 var(--spacing-sm); }
.analytics-panel > .chart-subtitle:first-of-type { margin-top: 0; }
.chart-note { margin: var(--spacing-sm) 0 0; font-size: var(--text-xs); color: var(--text-muted); }

/* Horizontal bar rows: label · bar · value. */
.chart-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.chart-row { display: grid; grid-template-columns: minmax(88px, 36%) minmax(0, 1fr) auto; align-items: center; gap: var(--spacing-sm); }
.chart-row-label { font-size: var(--text-sm); color: var(--text-secondary); overflow-wrap: anywhere; }
.chart-row-track { display: block; background: var(--chart-track); border-radius: var(--radius-sm); overflow: hidden; line-height: 0; }
.chart-row-value { font-size: var(--text-sm); font-weight: 600; white-space: nowrap; }
.chart-bar-svg { display: block; width: 100%; height: 12px; }
.chart-bar { fill: var(--accent); }
.chart-bar-alt { fill: var(--chart-alt); }
.chart-bar-good { fill: var(--success); }
.chart-bar-warn { fill: var(--warning); }
.chart-bar-danger { fill: var(--danger); }

/* Segmented (stacked) single bar + its legend. */
.chart-stack { display: block; width: 100%; height: 16px; border-radius: var(--radius-sm); overflow: hidden; background: var(--chart-track); }
.chart-legend { list-style: none; margin: var(--spacing-md) 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 6px var(--spacing-md); }
.chart-legend-inline { grid-template-columns: repeat(auto-fit, minmax(130px, max-content)); }
.chart-legend-item { display: flex; align-items: center; gap: 8px; font-size: var(--text-sm); color: var(--text-secondary); min-width: 0; }
.chart-legend-value { margin-left: auto; font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.chart-swatch { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 2px; background: var(--text-muted); }
.chart-swatch-main { background: var(--accent); }
.chart-swatch-alt { background: var(--chart-alt); }

/* Series palette: works both as an SVG fill and as a legend swatch background. */
.chart-c1 { fill: var(--chart-1); background: var(--chart-1); }
.chart-c2 { fill: var(--chart-2); background: var(--chart-2); }
.chart-c3 { fill: var(--chart-3); background: var(--chart-3); }
.chart-c4 { fill: var(--chart-4); background: var(--chart-4); }
.chart-c5 { fill: var(--chart-5); background: var(--chart-5); }
.chart-c6 { fill: var(--chart-6); background: var(--chart-6); }
.chart-c7 { fill: var(--chart-7); background: var(--chart-7); }
.chart-c8 { fill: var(--chart-8); background: var(--chart-8); }

/* Grouped column chart (fee trend). Keeps its aspect ratio, so its text scales evenly. */
.chart-fig { display: block; width: 100%; height: auto; max-height: 260px; }
.chart-axis { stroke: var(--border-strong); stroke-width: 1; }
.chart-axis-label { fill: var(--text-muted); font-size: 10px; font-family: var(--font-sans); }

@media (max-width: 767px) {
  .chart-row { grid-template-columns: minmax(72px, 42%) minmax(0, 1fr) auto; }
}

@media print {
  /* Panels stay bordered cards on paper (the generic print rule strips card chrome). */
  .analytics-print-only { display: block; }
  .analytics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8pt; }
  .analytics-panel { border: 1px solid #000 !important; border-radius: 0 !important; padding: 8pt !important; break-inside: avoid; }
  .analytics-panel-wide { grid-column: 1 / -1; }
  /* Bars must keep their ink on paper. */
  .chart-row-track, .chart-stack, .chart-swatch, .chart-bar, .chart-bar-alt, .chart-seg,
  .chart-bar-good, .chart-bar-warn, .chart-bar-danger { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .chart-row-label, .chart-row-value, .chart-legend-item, .chart-legend-value, .chart-subtitle, .chart-note { color: #000 !important; }
  .chart-axis-label { fill: #000; }
}

/* 12. ROOM CALENDAR ------------------------------------------------------- */
/* Day grid for /room-bookings: rooms are rows, the working day (08:00–20:00) is
   columns. Occupancy is rendered server-side as table cells with a colspan, so
   there is no inline geometry and nothing to compute in JS. Class slots (owned by
   the timetable) and booking slots are told apart by class, never by colour alone
   — each carries a text kind label. The grid is wide, so it scrolls inside its own
   container and never widens the page. */

.rc-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.rc-grid { border-collapse: collapse; width: 100%; min-width: 960px; table-layout: fixed; font-size: var(--text-sm); }
.rc-grid th, .rc-grid td { border: 1px solid var(--border-default); padding: 0; vertical-align: top; }
.rc-grid thead th { background: var(--surface-inset); color: var(--text-muted); font-size: var(--text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; padding: 6px 4px; text-align: center; white-space: nowrap; }
.rc-grid thead th.rc-corner { text-align: left; padding-left: var(--spacing-md); }

/* Room label column: pinned so the room stays readable while the day scrolls. */
.rc-room { width: 200px; background: var(--surface-secondary); position: sticky; left: 0; z-index: 1; text-align: left; padding: 8px var(--spacing-md) !important; font-weight: 600; color: var(--text-primary); }
.rc-grid thead th.rc-corner { position: sticky; left: 0; z-index: 2; background: var(--surface-inset); width: 200px; }
.rc-room-meta { display: block; font-weight: 400; font-size: var(--text-xs); color: var(--text-muted); }

.rc-free { background: var(--surface-secondary); height: 44px; }
.rc-slot { padding: 6px 8px !important; overflow: hidden; }
.rc-slot-label { display: block; font-weight: 600; color: var(--text-primary); overflow-wrap: anywhere; }
.rc-slot-meta { display: block; font-size: var(--text-2xs); color: var(--text-secondary); overflow-wrap: anywhere; }
.rc-slot-kind { display: inline-block; font-size: var(--text-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }

/* Class = timetabled teaching (accent). Booking = approved reservation (info).
   Requested = pending, drawn hatched-light so it never reads as confirmed. */
.rc-slot-class { background: var(--accent-soft); border-left: 3px solid var(--accent) !important; }
.rc-slot-class .rc-slot-kind { color: var(--accent); }
.rc-slot-booking { background: var(--info-soft); border-left: 3px solid var(--info) !important; }
.rc-slot-booking .rc-slot-kind { color: var(--info); }
.rc-slot-requested { background: var(--warning-soft); border-left: 3px dashed var(--warning) !important; }
.rc-slot-requested .rc-slot-kind { color: var(--warning); }

.rc-legend { list-style: none; display: flex; flex-wrap: wrap; gap: var(--spacing-md); margin: 0; padding: 10px var(--spacing-md); border-top: 1px solid var(--border-default); background: var(--surface-inset); }
.rc-legend-item { display: flex; align-items: center; gap: 8px; font-size: var(--text-xs); color: var(--text-secondary); }
.rc-swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.rc-swatch-class { background: var(--accent-soft); border: 1px solid var(--accent); }
.rc-swatch-booking { background: var(--info-soft); border: 1px solid var(--info); }
.rc-swatch-requested { background: var(--warning-soft); border: 1px dashed var(--warning); }

.rc-daynav { display: flex; align-items: center; gap: var(--spacing-sm); flex-wrap: wrap; }
.rc-daynav-label { font-weight: 600; color: var(--text-primary); white-space: nowrap; }

@media (max-width: 767px) {
  .rc-room, .rc-grid thead th.rc-corner { width: 132px; }
}
