:root {
  --bg: #F8FAFC; --bg-subtle: #F1F5F9;
  --surface: #FFFFFF; --surface-hover: #F8FAFC; --surface-active: #F1F5F9;
  --border: #E2E8F0; --border-strong: #CBD5E1;
  --text: #0F172A; --text-secondary: #475569; --text-muted: #64748B;
  --brand: #6366F1; --brand-hover: #4F46E5; --brand-soft: #EEF2FF;
  --brand-soft-border: #C7D2FE; --brand-text: #4338CA; --brand-contrast: #FFFFFF;
  --brand-grad-from: #6366F1; --brand-grad-to: #8B5CF6;
  --success: #10B981; --success-soft: #ECFDF5; --success-text: #065F46;
  --warning: #F59E0B; --warning-soft: #FFFBEB; --warning-text: #92400E;
  --danger: #EF4444; --danger-soft: #FEF2F2; --danger-text: #991B1B;
  --info: #0EA5E9; --info-soft: #F0F9FF; --info-text: #0C4A6E;
  --shadow-xs: 0 1px 2px rgba(15,23,42,.04);
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 6px -1px rgba(15,23,42,.07), 0 2px 4px -2px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 15px -3px rgba(15,23,42,.08), 0 4px 6px -4px rgba(15,23,42,.04);
  --shadow-xl: 0 20px 25px -5px rgba(15,23,42,.1), 0 8px 10px -6px rgba(15,23,42,.04);
  --radius-sm: 6px; --radius: 10px; --radius-lg: 14px; --radius-xl: 20px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 120ms; --dur-base: 200ms; --dur-slow: 300ms;
}

[data-theme="dark"] {
  --bg: #0B1220; --bg-subtle: #0F172A;
  --surface: #111827; --surface-hover: #1F2937; --surface-active: #374151;
  --border: #1F2937; --border-strong: #374151;
  --text: #F1F5F9; --text-secondary: #94A3B8; --text-muted: #94A3B8;
  --brand: #818CF8; --brand-hover: #A5B4FC; --brand-soft: #1E1B4B;
  --brand-soft-border: #4338CA; --brand-text: #C7D2FE; --brand-contrast: #0B1220;
  --brand-grad-from: #818CF8; --brand-grad-to: #C4B5FD;
  --success: #34D399; --success-soft: #052E16; --success-text: #86EFAC;
  --warning: #FBBF24; --warning-soft: #451A03; --warning-text: #FCD34D;
  --danger: #F87171; --danger-soft: #450A0A; --danger-text: #FCA5A5;
  --info: #38BDF8; --info-soft: #082F49; --info-text: #7DD3FC;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur-base), color var(--dur-base);
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-soft); border-radius: 6px; }
img, svg { display: block; max-width: 100%; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px; animation: fadeIn var(--dur-slow) var(--ease); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -0.025em; display: flex; align-items: center; gap: 10px; }
.page-title i { color: var(--brand); }
.page-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.grid-auto { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.dim { color: var(--text-muted); }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 0.92em; }
.text-sm { font-size: 12px; } .text-xs { font-size: 11px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; min-height: 38px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: all var(--dur-fast) var(--ease);
  box-shadow: var(--shadow-xs);
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn i { font-size: 13px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--brand-contrast); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; border-color: #DC2626; color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #059669; border-color: #059669; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 6px 12px; min-height: 30px; font-size: 12px; }
.btn-sm i { font-size: 11px; }
.btn-icon { padding: 0; width: 36px; height: 36px; min-height: 36px; border-radius: var(--radius); }
.btn-icon.btn-sm { width: 30px; height: 30px; min-height: 30px; }
.btn-block { width: 100%; }

/* Forms */
.field { display: block; margin-bottom: 16px; }
.field > span, .field > label { display: block; font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.input {
  width: 100%; padding: 9px 12px; min-height: 38px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 13px;
  transition: all var(--dur-fast) var(--ease);
}
.input:hover { border-color: var(--border-strong); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input:disabled { opacity: 0.6; cursor: not-allowed; background: var(--surface-hover); }
.input::placeholder { color: var(--text-muted); }
select.input {
  appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748B' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
textarea.input { resize: vertical; min-height: 80px; padding-top: 10px; line-height: 1.55; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
input[type="date"].input, input[type="time"].input { cursor: pointer; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-xs); transition: all var(--dur-fast) var(--ease);
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 15px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.card-title i { color: var(--brand); font-size: 14px; }

/* Stats */
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat { padding: 18px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); transition: all var(--dur-fast) var(--ease); }
a.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-icon { width: 40px; height: 40px; border-radius: 11px; background: var(--brand-soft); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-size: 15px; margin-bottom: 14px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.025em; line-height: 1; color: var(--text); }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; margin-top: 6px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 500; line-height: 1.4; white-space: nowrap; }
.badge i { font-size: 9px; }
.badge-brand { background: var(--brand-soft); color: var(--brand-text); }
.badge-success { background: var(--success-soft); color: var(--success-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-info { background: var(--info-soft); color: var(--info-text); }
.badge-gray { background: var(--surface-hover); color: var(--text-secondary); }

/* Tables */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--surface); box-shadow: var(--shadow-xs); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--bg-subtle); }
th { padding: 11px 16px; text-align: left; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
tbody tr { transition: background var(--dur-fast) var(--ease); }
tbody tr:hover td { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: none; }

/* Empty */
.empty { padding: 48px 24px; text-align: center; color: var(--text-muted); font-size: 13px; }
.empty i { display: block; font-size: 36px; opacity: 0.4; margin-bottom: 12px; color: var(--text-muted); }
.empty-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }

/* Search */
.search-wrap { position: relative; }
.search-wrap .input { padding-left: 36px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 13px; pointer-events: none; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; min-height: 34px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 13px; font-weight: 500;
  transition: all var(--dur-fast) var(--ease); white-space: nowrap;
}
.chip:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.chip i { font-size: 12px; opacity: 0.75; }
.chip.on i { opacity: 1; }

/* Modal */
dialog { border: none; padding: 0; background: transparent; max-width: 100vw; max-height: 100vh; margin: auto; }
dialog::backdrop { background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(6px) saturate(140%); -webkit-backdrop-filter: blur(6px) saturate(140%); animation: backdropIn var(--dur-base) ease; }
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
  background: var(--surface); border-radius: var(--radius-xl); border: 1px solid var(--border);
  width: min(540px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.4);
  animation: modalIn var(--dur-slow) var(--ease);
}
.modal-content.wide { width: min(720px, calc(100vw - 32px)); }
.modal-content.xwide { width: min(920px, calc(100vw - 32px)); }
@keyframes modalIn { from { opacity: 0; transform: translateY(20px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header { padding: 22px 26px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; background: linear-gradient(180deg, var(--bg-subtle), var(--surface)); }
.modal-title { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.modal-sub { font-size: 12.5px; color: var(--text-secondary); margin-top: 5px; line-height: 1.55; }
.modal-close { width: 34px; height: 34px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; transition: all var(--dur-fast) var(--ease); }
.modal-close:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }
.modal-body { padding: 22px 26px; overflow-y: auto; flex: 1; }
.modal-body::-webkit-scrollbar { width: 8px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.modal-footer { padding: 16px 26px; border-top: 1px solid var(--border); background: var(--surface); display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(150%); background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: var(--radius); font-size: 13px; font-weight: 500; z-index: 9999; pointer-events: none; max-width: calc(100vw - 32px); box-shadow: var(--shadow-xl); transition: transform var(--dur-slow) var(--ease); }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

/* Topnav */
.topnav { position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px); border-bottom: 1px solid var(--border); }
.topnav-inner { max-width: 1280px; margin: 0 auto; padding: 0 24px; height: 60px; display: flex; align-items: center; gap: 20px; }
.topnav-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; letter-spacing: -0.02em; color: var(--text); flex-shrink: 0; }
.topnav-brand:hover { color: var(--text); }
.topnav-logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--brand-grad-from), var(--brand-grad-to)); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; box-shadow: 0 2px 8px -2px rgba(99,102,241,.5); }
.topnav-links { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topnav-links::-webkit-scrollbar { display: none; }
.topnav-link { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: var(--radius); font-size: 13px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; transition: all var(--dur-fast) var(--ease); }
.topnav-link:hover { background: var(--surface-hover); color: var(--text); }
.topnav-link.active { background: var(--brand-soft); color: var(--brand-text); }
.topnav-link i { font-size: 12px; opacity: 0.75; }
.topnav-link.active i { opacity: 1; }
.topnav-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.topnav-btn { width: 36px; height: 36px; border-radius: var(--radius); border: none; background: transparent; color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; cursor: pointer; transition: all var(--dur-fast) var(--ease); position: relative; }
.topnav-btn:hover { background: var(--surface-hover); color: var(--text); }
.topnav-avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--brand-grad-from), var(--brand-grad-to)); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; cursor: pointer; border: none; padding: 0; text-transform: uppercase; letter-spacing: -0.02em; box-shadow: 0 2px 8px -2px rgba(99,102,241,.5); }

/* Popover */
.popover { position: absolute; top: calc(60px - 4px); right: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); min-width: 280px; padding: 8px; z-index: 100; opacity: 0; transform: translateY(-8px) scale(0.98); pointer-events: none; transition: all var(--dur-base) var(--ease); }
.popover.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.popover-header { padding: 12px; display: flex; align-items: center; gap: 12px; }
.popover-avatar { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, var(--brand-grad-from), var(--brand-grad-to)); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 16px; flex-shrink: 0; text-transform: uppercase; }
.popover-info { flex: 1; min-width: 0; }
.popover-name { font-weight: 600; font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-email { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-divider { height: 1px; background: var(--border); margin: 6px 0; }
.popover-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: none; background: transparent; color: var(--text); font-size: 13px; text-align: left; cursor: pointer; transition: all var(--dur-fast) var(--ease); }
.popover-item:hover { background: var(--surface-hover); }
.popover-item i { width: 16px; color: var(--text-muted); font-size: 13px; }
.popover-item:hover i { color: var(--brand); }
.popover-school-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer; transition: all var(--dur-fast); }
.popover-school-item:hover { background: var(--surface-hover); }
.popover-school-item.active { background: var(--brand-soft); color: var(--brand-text); }
.popover-school-icon { width: 28px; height: 28px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }
.popover-school-item.active .popover-school-icon { background: var(--brand); color: #fff; }

/* Auth */
.auth-shell { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); position: relative; overflow: hidden; }
.auth-shell::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at 20% 20%, rgba(99,102,241,0.15) 0%, transparent 45%), radial-gradient(circle at 80% 80%, rgba(139,92,246,0.12) 0%, transparent 45%); pointer-events: none; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); padding: 36px 32px; box-shadow: var(--shadow-xl); position: relative; z-index: 1; }
.auth-brand { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 24px; font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.auth-brand-icon { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, var(--brand-grad-from), var(--brand-grad-to)); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; box-shadow: 0 4px 12px -4px rgba(99,102,241,.5); overflow: hidden; }
.auth-title { font-size: 24px; font-weight: 700; letter-spacing: -0.025em; margin-bottom: 6px; }
.auth-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 28px; line-height: 1.5; }

/* List items */
.list-item { display: flex; gap: 12px; padding: 14px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.list-item:last-child { border-bottom: none; }
.list-item-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 500; font-size: 13.5px; color: var(--text); }
.list-item-meta { font-size: 11.5px; color: var(--text-secondary); margin-top: 3px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}