/* ===================== SCHOOL GRADING SYSTEM — DESIGN SYSTEM v4 ===================== */
/* Modern, clean, accessible design with design tokens and component library */

/* ---------- DESIGN TOKENS ---------- */
:root {
  /* Color Primitives */
  --color-white: #ffffff;
  --color-black: #000000;

  /* Brand Colors - Modern indigo/slate palette */
  --brand-50:  #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-300: #a5b4fc;
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-800: #3730a3;
  --brand-900: #312e81;
  --brand-950: #1e1b4b;

  /* Neutral/Slate Scale */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;

  /* Semantic Colors */
  --success-50:  #f0fdf4;
  --success-100: #dcfce7;
  --success-500: #22c55e;
  --success-600: #16a34a;
  --success-700: #15803d;

  --warning-50:  #fffbeb;
  --warning-100: #fef3c7;
  --warning-500: #f59e0b;
  --warning-600: #d97706;
  --warning-700: #b45309;

  --error-50:  #fef2f2;
  --error-100: #fee2e2;
  --error-500: #ef4444;
  --error-600: #dc2626;
  --error-700: #b91c1c;

  /* Aliases for clarity */
  --color-bg:        var(--slate-50);
  --color-surface:   var(--color-white);
  --color-surface-2: var(--slate-50);
  --color-border:    var(--slate-200);
  --color-border-strong: var(--slate-300);

  --color-text:      var(--slate-900);
  --color-text-soft: var(--slate-600);
  --color-text-muted: var(--slate-400);
  --color-text-inverse: var(--color-white);

  --color-primary:      var(--brand-600);
  --color-primary-hover: var(--brand-700);
  --color-primary-light: var(--brand-50);
  --color-primary-text:  var(--brand-700);

  --color-success:      var(--success-600);
  --color-success-light: var(--success-50);
  --color-success-text:  var(--success-700);

  --color-warning:      var(--warning-600);
  --color-warning-light: var(--warning-50);
  --color-warning-text:  var(--warning-700);

  --color-error:      var(--error-600);
  --color-error-light: var(--error-50);
  --color-error-text:  var(--error-700);

  /* Sidebar (now light) */
  --sidebar-bg:        var(--color-white);
  --sidebar-border:    var(--color-border);
  --sidebar-text:      var(--slate-700);
  --sidebar-text-muted: var(--slate-500);
  --sidebar-hover:     var(--slate-50);
  --sidebar-active-bg: var(--brand-50);
  --sidebar-active-text: var(--brand-700);
  --sidebar-active-border: var(--brand-500);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.04);

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Spacing Scale (4px base) */
  --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;

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text-xs: 0.7rem;     /* 11.2px */
  --text-sm: 0.8125rem;  /* 13px */
  --text-base: 0.875rem; /* 14px */
  --text-lg: 1rem;       /* 16px */
  --text-xl: 1.125rem;   /* 18px */
  --text-2xl: 1.25rem;   /* 20px */
  --text-3xl: 1.5rem;    /* 24px */
  --text-4xl: 1.875rem;  /* 30px */

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

  /* Transitions */
  --transition-fast: 100ms ease;
  --transition-base: 150ms ease;
  --transition-slow: 250ms ease;

  /* Z-index Scale */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal-backdrop: 300;
  --z-modal: 310;
  --z-toast: 400;
  --z-tooltip: 500;
}

/* Dark mode support (optional - can be toggled) */
@media (prefers-color-scheme: dark) {
  :root[data-theme="dark"] {
    --color-bg:        var(--slate-950);
    --color-surface:   var(--slate-900);
    --color-surface-2: var(--slate-800);
    --color-border:    var(--slate-700);
    --color-border-strong: var(--slate-600);

    --color-text:      var(--slate-50);
    --color-text-soft: var(--slate-300);
    --color-text-muted: var(--slate-500);

    --sidebar-bg:      var(--slate-900);
    --sidebar-border:  var(--slate-700);
    --sidebar-text:    var(--slate-200);
    --sidebar-text-muted: var(--slate-500);
    --sidebar-hover:   var(--slate-800);
    --sidebar-active-bg: var(--brand-950);
    --sidebar-active-text: var(--brand-300);
    --sidebar-active-border: var(--brand-500);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  }
}

/* ---------- RESET & BASE ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}
img { max-width: 100%; height: auto; display: block; }
table { border-collapse: collapse; }
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- UTILITY CLASSES ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--color-text-muted); }
.text-soft { color: var(--color-text-soft); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- COMPONENTS: BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1.4;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { outline-offset: 2px; }

/* Sizes */
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); gap: var(--space-1); min-height: 32px; }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-base); min-height: 44px; }

/* Variants */
.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  box-shadow: var(--shadow-sm);
}
.btn-primary:active:not(:disabled) { transform: scale(0.98); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--color-surface-2);
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-sm);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-soft);
  border-color: transparent;
  box-shadow: none;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.btn-danger {
  background: var(--color-error);
  color: var(--color-text-inverse);
  border-color: var(--color-error);
  box-shadow: var(--shadow-xs);
}
.btn-danger:hover:not(:disabled) {
  background: var(--error-700);
  border-color: var(--error-700);
  box-shadow: var(--shadow-sm);
}

.btn-success {
  background: var(--color-success);
  color: var(--color-text-inverse);
  border-color: var(--color-success);
  box-shadow: var(--shadow-xs);
}
.btn-success:hover:not(:disabled) {
  background: var(--success-700);
  border-color: var(--success-700);
  box-shadow: var(--shadow-sm);
}

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-outline:hover:not(:disabled) {
  background: var(--color-primary-light);
}

/* ---------- COMPONENTS: INPUTS ---------- */
.form-field { margin-bottom: var(--space-4); }
.form-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--color-text-soft);
  margin-bottom: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
.form-input::placeholder { color: var(--color-text-muted); }
.form-input:disabled,
.form-select:disabled { background: var(--color-surface-2); color: var(--color-text-muted); cursor: not-allowed; }
.form-input.error,
.form-select.error { border-color: var(--color-error); }
.form-input.error:focus,
.form-select.error:focus { box-shadow: 0 0 0 3px var(--color-error-light); }
.form-textarea { min-height: 80px; resize: vertical; }
.form-hint { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: var(--space-1); }
.form-error { font-size: var(--text-xs); color: var(--color-error); margin-top: var(--space-1); }

/* Input with icon */
.input-wrapper { position: relative; display: flex; align-items: center; }
.input-wrapper .form-input { padding-left: 36px; }
.input-icon { position: absolute; left: 10px; color: var(--color-text-muted); pointer-events: none; }

/* ---------- COMPONENTS: CARDS ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); }
.card-title { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--color-text); }
.card-subtitle { font-size: var(--text-sm); color: var(--color-text-soft); margin-top: var(--space-1); }
.card-body { padding: var(--space-5); }
.card-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: var(--space-3); }

/* Stat Card */
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card .icon { width: 40px; height: 40px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: var(--text-xl); margin-bottom: var(--space-3); }
.stat-card .icon-primary { background: var(--color-primary-light); color: var(--color-primary); }
.stat-card .icon-success { background: var(--success-50); color: var(--color-success); }
.stat-card .icon-warning { background: var(--warning-50); color: var(--color-warning); }
.stat-card .icon-error { background: var(--error-50); color: var(--color-error); }
.stat-value { font-size: var(--text-3xl); font-weight: var(--font-bold); color: var(--color-text); line-height: 1.2; }
.stat-label { font-size: var(--text-sm); color: var(--color-text-soft); font-weight: var(--font-medium); margin-top: var(--space-1); }

/* ---------- COMPONENTS: TABLES ---------- */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--color-border); background: var(--color-surface); }
.table { width: 100%; font-size: var(--text-sm); }
.table thead { background: var(--color-surface-2); }
.table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
}
.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:hover { background: var(--color-surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table td.actions { white-space: nowrap; }
.table .badge { display: inline-flex; align-items: center; padding: var(--space-1) var(--space-2); font-size: var(--text-xs); font-weight: var(--font-medium); border-radius: var(--radius-full); }
.badge-primary { background: var(--color-primary-light); color: var(--color-primary-text); }
.badge-success { background: var(--success-50); color: var(--success-700); }
.badge-warning { background: var(--warning-50); color: var(--warning-700); }
.badge-error { background: var(--error-50); color: var(--error-700); }
.badge-neutral { background: var(--slate-100); color: var(--slate-700); }

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

/* ---------- COMPONENTS: MODALS ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center;
  padding: var(--space-4); z-index: var(--z-modal-backdrop);
  animation: fadeIn var(--transition-base);
}
.modal-backdrop.show { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp var(--transition-base);
}
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.modal-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--color-text); }
.modal-close { background: none; border: none; padding: var(--space-1); color: var(--color-text-muted); border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all var(--transition-fast); }
.modal-close:hover { background: var(--color-surface-2); color: var(--color-text); }
.modal-body { padding: var(--space-5); overflow-y: auto; flex: 1; }
.modal-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: var(--space-3); }

/* ---------- COMPONENTS: TOASTS ---------- */
.toast-container { position: fixed; bottom: var(--space-6); right: var(--space-6); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-2); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); min-width: 280px; max-width: 420px; animation: toastIn var(--transition-base); }
@keyframes toastIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: none; } }
.toast.success { border-left: 4px solid var(--color-success); }
.toast.error { border-left: 4px solid var(--color-error); }
.toast.warning { border-left: 4px solid var(--color-warning); }
.toast.info { border-left: 4px solid var(--color-primary); }
.toast-icon { flex-shrink: 0; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.toast.success .toast-icon { color: var(--color-success); }
.toast.error .toast-icon { color: var(--color-error); }
.toast.warning .toast-icon { color: var(--color-warning); }
.toast.info .toast-icon { color: var(--color-primary); }
.toast-content { flex: 1; min-width: 0; }
.toast-title { font-weight: var(--font-semibold); font-size: var(--text-sm); color: var(--color-text); }
.toast-message { font-size: var(--text-sm); color: var(--color-text-soft); margin-top: 2px; }
.toast-close { flex-shrink: 0; background: none; border: none; padding: var(--space-1); color: var(--color-text-muted); cursor: pointer; border-radius: var(--radius-sm); }
.toast-close:hover { background: var(--color-surface-2); color: var(--color-text); }

/* ---------- COMPONENTS: TOOLBAR ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-bottom: var(--space-5); padding: var(--space-4); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
.toolbar-group { display: flex; align-items: center; gap: var(--space-2); flex: 1; min-width: 200px; }
.toolbar-group.single { flex: 0 0 auto; }
.toolbar-label { font-size: var(--text-xs); font-weight: var(--font-medium); color: var(--color-text-muted); white-space: nowrap; }
.toolbar .form-select { min-width: 180px; }
.toolbar-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ---------- COMPONENTS: TABS ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-4); }
.tab-btn { padding: var(--space-3) var(--space-5); font-size: var(--text-sm); font-weight: var(--font-medium); color: var(--color-text-soft); background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; transition: all var(--transition-fast); position: relative; }
.tab-btn:hover { color: var(--color-text); }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn var(--transition-fast); }

/* ---------- COMPONENTS: AVATAR ---------- */
.avatar { width: 36px; height: 36px; border-radius: var(--radius-full); background: var(--color-primary-light); color: var(--color-primary); display: flex; align-items: center; justify-content: center; font-weight: var(--font-semibold); font-size: var(--text-sm); flex-shrink: 0; overflow: hidden; }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-base); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- COMPONENTS: DROPDOWN ---------- */
.dropdown { position: relative; }
.dropdown-menu { position: absolute; top: 100%; right: 0; margin-top: var(--space-1); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); min-width: 180px; padding: var(--space-1); z-index: var(--z-dropdown); display: none; animation: fadeIn var(--transition-fast); }
.dropdown-menu.show { display: block; }
.dropdown-item { display: flex; align-items: center; gap: var(--space-2); width: 100%; padding: var(--space-2) var(--space-3); font-size: var(--text-sm); color: var(--color-text); background: none; border: none; border-radius: var(--radius-sm); cursor: pointer; text-align: left; transition: background var(--transition-fast); }
.dropdown-item:hover { background: var(--color-surface-2); }
.dropdown-item.danger { color: var(--color-error); }
.dropdown-item.danger:hover { background: var(--color-error-light); }
.dropdown-divider { height: 1px; background: var(--color-border); margin: var(--space-1) 0; }

/* ---------- COMPONENTS: LOADING ---------- */
.loading-spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--color-border); border-top-color: var(--color-primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { position: absolute; inset: 0; background: rgba(255,255,255,0.8); display: flex; align-items: center; justify-content: center; z-index: 10; border-radius: inherit; }
.loading-overlay .spinner { width: 32px; height: 32px; border-width: 3px; }

/* ---------- COMPONENTS: BREADCRUMB ---------- */
.breadcrumb { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--color-text-soft); margin-bottom: var(--space-4); flex-wrap: wrap; }
.breadcrumb a { color: var(--color-text-soft); }
.breadcrumb a:hover { color: var(--color-primary); }
.breadcrumb-separator { color: var(--color-text-muted); }
.breadcrumb-current { color: var(--color-text); font-weight: var(--font-medium); }

/* ---------- PAGE LAYOUT ---------- */
#login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: linear-gradient(135deg, var(--slate-50) 0%, var(--brand-50) 100%);
}
.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: var(--space-10) var(--space-8);
  width: 100%;
  max-width: 420px;
}
.login-header { text-align: center; margin-bottom: var(--space-8); }
.login-icon { width: 56px; height: 56px; border-radius: var(--radius-lg); background: var(--color-primary-light); color: var(--color-primary); display: inline-flex; align-items: center; justify-content: center; font-size: var(--text-3xl); margin-bottom: var(--space-4); }
.login-title { font-size: var(--text-2xl); font-weight: var(--font-bold); color: var(--color-text); margin-bottom: var(--space-1); }
.login-subtitle { font-size: var(--text-sm); color: var(--color-text-soft); }
.login-form .form-field { margin-bottom: var(--space-5); }
.login-form .form-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; }
.login-form .btn { width: 100%; margin-top: var(--space-2); }
.login-footer { margin-top: var(--space-6); padding-top: var(--space-4); border-top: 1px solid var(--color-border); text-align: center; font-size: var(--text-xs); color: var(--color-text-muted); }

#app { display: none; }
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-xs);
  height: 64px;
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-6);
}
.topbar-left { display: flex; align-items: center; gap: var(--space-3); }
.nav-toggle { display: none; background: none; border: none; padding: var(--space-2); color: var(--color-text-soft); border-radius: var(--radius-md); cursor: pointer; }
.nav-toggle:hover { background: var(--color-surface-2); color: var(--color-text); }
.brand { font-size: var(--text-lg); font-weight: var(--font-bold); color: var(--color-text); display: flex; align-items: center; gap: var(--space-2); }
.brand-icon { width: 32px; height: 32px; border-radius: var(--radius-md); background: var(--color-primary-light); color: var(--color-primary); display: flex; align-items: center; justify-content: center; font-size: var(--text-lg); }
.topbar-spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: var(--space-3); }
.user-menu { position: relative; }
.user-avatar-btn { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1); background: none; border: 1px solid var(--color-border); border-radius: var(--radius-full); cursor: pointer; transition: all var(--transition-fast); }
.user-avatar-btn:hover { background: var(--color-surface-2); border-color: var(--color-border-strong); }
.user-name { font-size: var(--text-sm); font-weight: var(--font-medium); color: var(--color-text); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: var(--text-xs); font-weight: var(--font-medium); padding: 2px 8px; border-radius: var(--radius-full); background: var(--color-primary-light); color: var(--color-primary-text); text-transform: uppercase; letter-spacing: 0.03em; }

.layout { display: flex; min-height: calc(100vh - 64px); }
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform var(--transition-base);
}
.sidebar-header { padding: var(--space-4); border-bottom: 1px solid var(--sidebar-border); display: none; align-items: center; justify-content: space-between; }
.sidebar-title { font-size: var(--text-xs); font-weight: var(--font-bold); text-transform: uppercase; letter-spacing: 0.08em; color: var(--sidebar-text-muted); }
.sidebar-close { background: none; border: none; color: var(--sidebar-text-muted); padding: var(--space-1); cursor: pointer; border-radius: var(--radius-sm); }
.sidebar-close:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.nav-group { margin-bottom: var(--space-2); }
.nav-group-label { padding: var(--space-3) var(--space-4) var(--space-1); font-size: var(--text-xs); font-weight: var(--font-semibold); text-transform: uppercase; letter-spacing: 0.06em; color: var(--sidebar-text-muted); }
.nav-btn {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; padding: var(--space-2) var(--space-4);
  background: none; border: none; border-left: 3px solid transparent;
  color: var(--sidebar-text); font-size: var(--text-sm); font-weight: var(--font-medium);
  cursor: pointer; transition: all var(--transition-fast);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-right: var(--space-2);
}
.nav-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.nav-btn.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); border-left-color: var(--sidebar-active-border); font-weight: var(--font-semibold); }
.nav-btn .nav-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-backdrop { display: none; position: fixed; inset: 64px 0 0 0; background: rgba(15, 23, 42, 0.35); backdrop-filter: blur(1px); z-index: 40; }

.main { flex: 1; padding: var(--space-6) var(--space-8); overflow: auto; }
.page { display: none; animation: fadeIn var(--transition-fast); }
.page.active { display: block; }
.page-header { margin-bottom: var(--space-6); }
.page-title { font-size: var(--text-2xl); font-weight: var(--font-bold); color: var(--color-text); margin-bottom: var(--space-1); }
.page-desc { font-size: var(--text-sm); color: var(--color-text-soft); }
.page-header-flex { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-6); }

/* Stat Grid */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }

/* Section Card */
.section { margin-bottom: var(--space-6); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); flex-wrap: wrap; gap: var(--space-3); }
.section-title { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--color-text); }
.section-actions { display: flex; gap: var(--space-2); }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1024px) {
  .nav-toggle { display: flex; }
  .sidebar { position: fixed; top: 64px; left: 0; bottom: 0; width: 280px; max-width: 85vw; z-index: 50; transform: translateX(-100%); box-shadow: var(--shadow-xl); }
  .layout.nav-open .sidebar { transform: translateX(0); }
  .layout.nav-open .nav-backdrop { display: block; }
  .sidebar-header { display: flex; }
  .main { padding: var(--space-5); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .topbar { padding: 0 var(--space-4); height: 56px; }
  .brand span { display: none; }
  .user-name { display: none; }
  .main { padding: var(--space-4); }
  .stat-grid { grid-template-columns: 1fr; }
  .page-title { font-size: var(--text-xl); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-group { width: 100%; }
  .toolbar .form-select { width: 100%; min-width: 0; }
  .modal { max-width: 100%; max-height: 100vh; border-radius: 0; margin: 0; }
  .toast-container { left: var(--space-4); right: var(--space-4); bottom: var(--space-4); }
  .toast { min-width: 0; max-width: 100%; }
  .table th, .table td { padding: var(--space-2) var(--space-3); }
}

/* ---------- REPORT PAGE SPECIFIC (iframe) ---------- */
.iframe-wrap {
  width: 100%;
  min-height: 70vh;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

/* ---------- PRINT STYLES ---------- */
@media print {
  .topbar, .sidebar, .nav-backdrop, .nav-toggle, .toolbar, .modal-backdrop, .toast-container, .page-header-flex .section-actions, .btn { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  .page { display: block !important; }
  .card { box-shadow: none; border: 1px solid var(--color-border); break-inside: avoid; }
  .table-wrapper { border: none; }
  .table { font-size: 11px; }
  .table th, .table td { padding: 6px 8px; }
  .stat-grid { display: none; }
  body { background: white; }
}

/* ---------- ANIMATIONS ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.animate-pulse { animation: pulse 2s ease-in-out infinite; }

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

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --color-border: var(--slate-400);
    --color-border-strong: var(--slate-300);
    --sidebar-border: var(--slate-400);
  }
  .btn-primary, .btn-danger, .btn-success { border-width: 2px; }
  .nav-btn.active { border-left-width: 4px; }
}

/* ---------- SPECIFIC PAGE ENHANCEMENTS ---------- */
/* Score entry grid */
.score-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-4); }
.score-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-4); box-shadow: var(--shadow-xs); transition: box-shadow var(--transition-fast); }
.score-card:hover { box-shadow: var(--shadow-md); }
.score-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); padding-bottom: var(--space-3); border-bottom: 1px solid var(--color-border); }
.score-student-name { font-weight: var(--font-semibold); color: var(--color-text); }
.score-student-id { font-size: var(--text-xs); color: var(--color-text-muted); font-family: var(--font-mono); }
.score-inputs { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
.score-input-group { display: flex; flex-direction: column; gap: var(--space-1); }
.score-input-label { font-size: var(--text-xs); font-weight: var(--font-medium); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.score-input { padding: var(--space-2) var(--space-3); font-size: var(--text-base); font-weight: var(--font-medium); text-align: center; font-family: var(--font-mono); }

/* Teacher assignment cards */
.assign-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-4); box-shadow: var(--shadow-xs); transition: all var(--transition-fast); }
.assign-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.assign-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: var(--space-3); }
.assign-class-name { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--color-text); }
.assign-subject { font-size: var(--text-sm); color: var(--color-primary); font-weight: var(--font-medium); background: var(--color-primary-light); padding: var(--space-1) var(--space-2); border-radius: var(--radius-full); }
.assign-meta { display: flex; gap: var(--space-4); font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: var(--space-3); padding-bottom: var(--space-3); border-bottom: 1px solid var(--color-border); }
.assign-meta-item { display: flex; align-items: center; gap: var(--space-1); }
.assign-students-count { font-weight: var(--font-medium); color: var(--color-text-soft); }

/* Settings form */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-6); }
.settings-section { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-5); }
.settings-section-title { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--color-text); margin-bottom: var(--space-4); padding-bottom: var(--space-3); border-bottom: 1px solid var(--color-border); }

/* Grade Scale Editor */
.grade-scale-editor { display: flex; flex-direction: column; gap: var(--space-3); }
.grade-scale-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 80px 40px; gap: var(--space-2); align-items: start; }
.grade-scale-header { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 80px 40px; gap: var(--space-2); padding: var(--space-2); font-size: var(--text-xs); font-weight: var(--font-semibold); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.03em; background: var(--color-surface-2); border-radius: var(--radius-sm); }
.grade-scale-row .form-input { width: 100%; }
.grade-scale-row .btn-sm { height: 40px; }

/* Import tabs */
.import-tabs { display: flex; border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-4); }
.import-tab { padding: var(--space-3) var(--space-5); font-size: var(--text-sm); font-weight: var(--font-medium); color: var(--color-text-soft); background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; transition: all var(--transition-fast); }
.import-tab:hover { color: var(--color-text); }
.import-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.import-pane { display: none; }
.import-pane.active { display: block; animation: fadeIn var(--transition-fast); }

/* Dashboard recent activity */
.activity-list { display: flex; flex-direction: column; gap: var(--space-3); }
.activity-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); transition: all var(--transition-fast); }
.activity-item:hover { box-shadow: var(--shadow-sm); }
.activity-icon { width: 36px; height: 36px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: var(--text-base); flex-shrink: 0; }
.activity-icon.student { background: var(--color-primary-light); color: var(--color-primary); }
.activity-icon.teacher { background: var(--success-50); color: var(--color-success); }
.activity-icon.grade { background: var(--warning-50); color: var(--color-warning); }
.activity-icon.report { background: var(--slate-100); color: var(--slate-600); }
.activity-content { flex: 1; min-width: 0; }
.activity-title { font-size: var(--text-sm); font-weight: var(--font-medium); color: var(--color-text); }
.activity-meta { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }
.activity-time { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Broadsheet table enhancements */
.broadsheet-table { font-size: var(--text-xs); }
.broadsheet-table th { position: sticky; top: 0; z-index: 1; background: var(--color-surface-2); }
.broadsheet-table th:first-child { position: sticky; left: 0; z-index: 2; background: var(--color-surface-2); }
.broadsheet-table tbody tr:nth-child(even) td { background: var(--color-surface-2); }
.broadsheet-table .score-cell { font-family: var(--font-mono); font-weight: var(--font-medium); text-align: center; }
.broadsheet-table .position-cell { text-align: center; font-weight: var(--font-medium); }
.broadsheet-table .total-row { font-weight: var(--font-bold); background: var(--brand-50) !important; }
.broadsheet-table .avg-row { font-weight: var(--font-semibold); background: var(--slate-100) !important; }

/* Analytics cards */
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-4); }
.analytics-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-5); }
.analytics-card-title { font-size: var(--text-sm); font-weight: var(--font-semibold); color: var(--color-text-soft); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: var(--space-2); }
.analytics-card-value { font-size: var(--text-3xl); font-weight: var(--font-bold); color: var(--color-text); line-height: 1.2; }
.analytics-card-sub { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: var(--space-1); }
.analytics-card-trend { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); font-weight: var(--font-medium); margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--color-border); }
.analytics-card-trend.up { color: var(--color-success); }
.analytics-card-trend.down { color: var(--color-error); }

/* ---------- LEGACY / JS-GENERATED COMPONENT STYLES (compat) ---------- */
/* Data tables produced by app.v4.js */
table.data { width: 100%; font-size: var(--text-sm); border-collapse: collapse; }
table.data thead { background: var(--color-surface-2); }
table.data th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
table.data td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
}
table.data tbody tr { transition: background var(--transition-fast); }
table.data tbody tr:hover { background: var(--color-surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data td.actions { white-space: nowrap; }
table.data .badge { display: inline-flex; align-items: center; padding: var(--space-1) var(--space-2); font-size: var(--text-xs); font-weight: var(--font-medium); border-radius: var(--radius-full); }

/* Status tags (teacher/term status) */
.tag { display: inline-flex; align-items: center; padding: 2px 10px; font-size: var(--text-xs); font-weight: var(--font-medium); border-radius: var(--radius-full); background: var(--color-surface-2); color: var(--color-text-soft); }
.tag.ok { background: var(--success-50); color: var(--success-700); }

/* Empty state */
.empty { padding: var(--space-8) var(--space-4); text-align: center; color: var(--color-text-muted); font-size: var(--text-sm); }

/* Modal field rows produced by JS */
.field { margin-bottom: var(--space-4); }
.field label { display: block; font-size: var(--text-xs); font-weight: var(--font-medium); color: var(--color-text-soft); margin-bottom: var(--space-1); text-transform: uppercase; letter-spacing: 0.03em; }
.field input, .field select, .field textarea { width: 100%; padding: var(--space-2) var(--space-3); font-size: var(--text-sm); color: var(--color-text); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); transition: border-color var(--transition-fast), box-shadow var(--transition-fast); }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-3); }
.modal-actions .btn { min-height: 40px; }

/* Inline status message */
.msg { font-size: var(--text-sm); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); margin-top: var(--space-3); }
.msg.ok { background: var(--success-50); color: var(--success-700); border: 1px solid var(--success-100); }
.msg.err { background: var(--error-50); color: var(--error-700); border: 1px solid var(--error-100); }

/* Descriptive lead text */
.desc { font-size: var(--text-sm); color: var(--color-text-soft); margin-bottom: var(--space-4); }

/* Teacher assignment cards (loadTAssign uses .card-t/.card-s/.card-m inside .card) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-4); }
.card-t { font-size: var(--text-lg); font-weight: var(--font-semibold); color: var(--color-text); }
.card-s { font-size: var(--text-sm); color: var(--color-primary); font-weight: var(--font-medium); margin-top: var(--space-1); }
.card-m { font-size: var(--text-sm); color: var(--color-text-soft); margin-top: var(--space-2); }
.card-m b { color: var(--color-text); }

/* Dashboard stat cards (loadDashboard uses .n / .l) */
.stat-card .n { font-size: var(--text-3xl); font-weight: var(--font-bold); color: var(--color-text); line-height: 1.2; }
.stat-card .l { font-size: var(--text-sm); color: var(--color-text-soft); font-weight: var(--font-medium); margin-top: var(--space-1); }

/* Responsive card-mode for data tables on phones */
@media (max-width: 640px) {
  .table-wrapper table.data thead { display: none; }
  .table-wrapper table.data tbody tr { display: block; border: 1px solid var(--color-border); border-radius: var(--radius-md); margin-bottom: var(--space-3); padding: var(--space-2); box-shadow: var(--shadow-xs); }
  .table-wrapper table.data tbody td { display: flex; justify-content: space-between; gap: var(--space-3); border-bottom: 1px solid var(--color-border); padding: var(--space-2) var(--space-1); }
  .table-wrapper table.data tbody td:last-child { border-bottom: none; }
  .table-wrapper table.data tbody td::before { content: attr(data-label); font-size: var(--text-xs); font-weight: var(--font-semibold); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
}