/* =========================================================
   Abuu School — Design System (Phase 1)
   Loaded AFTER theme.css. It re-tints the existing admin by overriding
   the theme's CSS variables, then adds a small set of reusable components.
   Nothing here changes page markup, so it is safe to roll out and to roll back
   (remove the <link> and the old look returns).
   Documented in /docs/design-system.html
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Source+Serif+4:opsz,wght@8..60,600;8..60,700&display=swap');

/* ---------- 1. Tokens ---------- */
:root {
  /* Navy scale (brand) */
  --ds-navy-950: #0b1426;
  --ds-navy-900: #101d38;
  --ds-navy-800: #1b2b4b;
  --ds-navy-700: #26406b;
  /* Blue scale (action) */
  --ds-blue-700: #1d4ed8;
  --ds-blue-600: #2563eb;
  --ds-blue-100: #dbe7fe;
  --ds-blue-50:  #eff4ff;
  /* Neutrals (cool slate) */
  --ds-ink:      #14213d;
  --ds-slate-600:#4f5b70;
  --ds-slate-500:#667286;
  --ds-slate-300:#cdd5e1;
  --ds-slate-200:#e1e6ee;
  --ds-slate-100:#eef1f6;
  --ds-slate-50: #f5f7fa;
  /* Status — each has a text colour (AA on white) and a soft fill */
  --ds-green: #15803d;  --ds-green-soft: #e6f4ea;
  --ds-amber: #a15c07;  --ds-amber-soft: #fdf1d8;
  --ds-red:   #b42318;  --ds-red-soft:   #fdeceb;
  --ds-sky:   #0b6a99;  --ds-sky-soft:   #e3f1f9;

  /* Spacing (4px base) */
  --ds-s1: 4px;  --ds-s2: 8px;  --ds-s3: 12px; --ds-s4: 16px;
  --ds-s5: 24px; --ds-s6: 32px; --ds-s7: 48px; --ds-s8: 64px;
  /* Radius — restrained */
  --ds-r-sm: 4px; --ds-r-md: 6px; --ds-r-lg: 8px;
  /* Type */
  --ds-font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --ds-font-display: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --ds-text-xs: .75rem; --ds-text-sm: .8125rem; --ds-text-base: .9375rem;
  --ds-text-lg: 1.125rem; --ds-text-xl: 1.375rem; --ds-text-2xl: 1.75rem;

  /* Map onto the variables theme.css already uses */
  --bg: var(--ds-slate-50);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: var(--ds-ink);
  --text-muted: var(--ds-slate-500);
  --border: var(--ds-slate-200);
  --primary: var(--ds-blue-600);
  --primary-hover: var(--ds-blue-700);
  --primary-soft: var(--ds-blue-50);
  --success: var(--ds-green);  --success-soft: var(--ds-green-soft);
  --warning: var(--ds-amber);  --warning-soft: var(--ds-amber-soft);
  --danger:  var(--ds-red);    --danger-soft:  var(--ds-red-soft);
  --info:    var(--ds-sky);    --info-soft:    var(--ds-sky-soft);
  --sidebar-bg: var(--ds-navy-900);
  --sidebar-text: #b4c0d6;
  --sidebar-active: var(--ds-navy-700);
  --shadow: 0 1px 2px rgba(16, 29, 56, .06);
  --shadow-lg: 0 8px 24px rgba(16, 29, 56, .12);
  --radius: var(--ds-r-lg);
}

[data-theme="dark"] {
  --bg: #0b1426;
  --surface: #101d38;
  --surface-2: #14233f;
  --text: #e4eaf4;
  --text-muted: #94a3bd;
  --border: #243453;
  --primary: #5b8def;
  --primary-hover: #7aa3f5;
  --primary-soft: #182a4d;
  --success: #4ade80;  --success-soft: #0f2c1d;
  --warning: #fbbf24;  --warning-soft: #33260a;
  --danger:  #f87171;  --danger-soft:  #3a1717;
  --info:    #38bdf8;  --info-soft:    #0c2a3a;
  --sidebar-bg: #08101f;
  --sidebar-text: #94a3bd;
  --sidebar-active: #1b2b4b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
}

/* ---------- 2. Base ---------- */
body {
  font-family: var(--ds-font);
  font-size: var(--ds-text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6 { color: var(--text); font-weight: 600; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.text-muted { color: var(--text-muted) !important; }
.num, .table td.num, .table th.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- 3. Re-tint existing components (no markup change) ---------- */
.sidebar-brand .logo-badge { background: var(--ds-navy-700); border-radius: var(--ds-r-md); }
.sidebar-nav .nav-link { border-radius: var(--ds-r-md); font-weight: 500; }
.sidebar-nav .nav-link.active { background: var(--sidebar-active); box-shadow: inset 3px 0 0 var(--ds-blue-600); }
.sidebar-section-title { color: #7d8aa6; letter-spacing: .1em; }

.topbar { box-shadow: none; }
.card, .stat-card, .modal-content { border-radius: var(--ds-r-lg); box-shadow: var(--shadow); }
.card-header { padding: var(--ds-s3) var(--ds-s4); font-size: var(--ds-text-base); }
.stat-icon { border-radius: var(--ds-r-md); }
.stat-value { font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

.form-control, .form-select { border-radius: var(--ds-r-md); font-size: var(--ds-text-base); }
.form-control:focus, .form-select:focus { box-shadow: 0 0 0 3px var(--primary-soft); }
.btn { border-radius: var(--ds-r-md); font-weight: 500; font-size: var(--ds-text-base); }
.btn-sm { font-size: var(--ds-text-sm); }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.badge { border-radius: var(--ds-r-sm); font-weight: 600; font-size: var(--ds-text-xs); padding: 4px 8px; }
.table thead th { font-size: var(--ds-text-xs); letter-spacing: .05em; background: var(--surface-2); }
.table > :not(caption) > * > * { padding: .65rem .85rem; }
.dropdown-menu { border-radius: var(--ds-r-md); }
.theme-toggle-btn { border-radius: var(--ds-r-md); }
.avatar-circle { background: var(--ds-navy-700); }
.deadline-ticker { background: var(--ds-navy-800); border-radius: var(--ds-r-md); }
.login-wrap { background: linear-gradient(180deg, var(--ds-navy-900) 0 38%, var(--bg) 38%); }
.dataTables_wrapper .dataTables_paginate .paginate_button { border-radius: var(--ds-r-md); }

/* ---------- 4. New reusable components ---------- */

/* Page header: title, optional breadcrumb, primary action on the right */
.ds-page-header { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: var(--ds-s3); margin-bottom: var(--ds-s5); }
.ds-page-header h1 { font-size: var(--ds-text-xl); margin: 0; }
.ds-page-header .ds-sub { color: var(--text-muted); font-size: var(--ds-text-sm); margin-top: 2px; }
.ds-breadcrumb { font-size: var(--ds-text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 2px; }
.ds-breadcrumb a { color: var(--text-muted); }
.ds-breadcrumb a:hover { color: var(--primary); }

/* Summary strip: compact figures in ONE bordered row instead of a card per metric */
.ds-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--ds-r-lg); box-shadow: var(--shadow); margin-bottom: var(--ds-s5); }
.ds-summary > div { padding: var(--ds-s4) var(--ds-s5); border-right: 1px solid var(--border); }
.ds-summary > div:last-child { border-right: 0; }
.ds-summary .ds-figure { font-size: var(--ds-text-2xl); font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.ds-summary .ds-label { font-size: var(--ds-text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.ds-summary .ds-note { font-size: var(--ds-text-xs); color: var(--text-muted); margin-top: 2px; }
@media (max-width: 575.98px) { .ds-summary > div { border-right: 0; border-bottom: 1px solid var(--border); } .ds-summary > div:last-child { border-bottom: 0; } }

/* Toolbar above tables: search + filters left, actions right */
.ds-toolbar { display: flex; flex-wrap: wrap; gap: var(--ds-s2); align-items: center; justify-content: space-between; padding: var(--ds-s3) var(--ds-s4); border-bottom: 1px solid var(--border); }
.ds-toolbar .ds-filters { display: flex; flex-wrap: wrap; gap: var(--ds-s2); align-items: center; }

/* Status: dot + text, quieter than a filled badge in dense tables */
.ds-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--ds-text-sm); font-weight: 500; }
.ds-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--ds-slate-300); }
.ds-status.is-ok::before   { background: var(--success); }
.ds-status.is-warn::before { background: var(--warning); }
.ds-status.is-bad::before  { background: var(--danger); }
.ds-status.is-info::before { background: var(--info); }

/* Empty / loading / error states */
.ds-state { text-align: center; padding: var(--ds-s7) var(--ds-s4); color: var(--text-muted); }
.ds-state i { font-size: 1.75rem; display: block; margin-bottom: var(--ds-s2); color: var(--ds-slate-300); }
.ds-state .ds-state-title { color: var(--text); font-weight: 600; margin-bottom: 2px; }
.ds-state.is-error i { color: var(--danger); }
.ds-skeleton { background: linear-gradient(90deg, var(--ds-slate-100) 25%, var(--ds-slate-50) 37%, var(--ds-slate-100) 63%); background-size: 400% 100%; animation: ds-shimmer 1.4s ease infinite; border-radius: var(--ds-r-sm); min-height: 14px; }
@keyframes ds-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* Alerts: left rule + soft fill */
.ds-alert { border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--ds-r-md); padding: var(--ds-s3) var(--ds-s4); background: var(--surface); font-size: var(--ds-text-sm); }
.ds-alert.is-info    { border-left-color: var(--info);    background: var(--info-soft); }
.ds-alert.is-success { border-left-color: var(--success); background: var(--success-soft); }
.ds-alert.is-warning { border-left-color: var(--warning); background: var(--warning-soft); }
.ds-alert.is-danger  { border-left-color: var(--danger);  background: var(--danger-soft); }

/* Stepper for multi-step workflows (e.g. promotion wizard) */
.ds-steps { display: flex; gap: 0; list-style: none; padding: 0; margin: 0 0 var(--ds-s5); counter-reset: ds-step; overflow-x: auto; }
.ds-steps li { flex: 1; min-width: 120px; position: relative; padding: var(--ds-s2) var(--ds-s3) var(--ds-s2) 0; font-size: var(--ds-text-sm); color: var(--text-muted); counter-increment: ds-step; border-top: 3px solid var(--border); }
.ds-steps li::before { content: counter(ds-step); display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 50%; background: var(--ds-slate-100); font-size: var(--ds-text-xs); font-weight: 600; margin-right: 6px; color: var(--text-muted); }
.ds-steps li.is-done { border-top-color: var(--success); color: var(--text); }
.ds-steps li.is-done::before { background: var(--success); color: #fff; content: '\2713'; }
.ds-steps li.is-current { border-top-color: var(--primary); color: var(--text); font-weight: 600; }
.ds-steps li.is-current::before { background: var(--primary); color: #fff; }

/* Description list for record detail pages */
.ds-dl { display: grid; grid-template-columns: 160px 1fr; gap: var(--ds-s2) var(--ds-s4); margin: 0; font-size: var(--ds-text-base); }
.ds-dl dt { color: var(--text-muted); font-weight: 500; font-size: var(--ds-text-sm); }
.ds-dl dd { margin: 0; }
@media (max-width: 575.98px) { .ds-dl { grid-template-columns: 1fr; gap: 0; } .ds-dl dd { margin-bottom: var(--ds-s3); } }

@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- 5. Admin shell (Phase 2) ---------- */

/* Collapsible sidebar groups */
.sidebar-group-toggle {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: 0; text-align: left;
  color: var(--sidebar-text); font-size: .9rem; font-weight: 600;
  padding: 10px 12px; margin-top: 4px; border-radius: var(--ds-r-md);
  transition: background .15s ease, color .15s ease;
}
.sidebar-group-toggle > i:first-child { width: 18px; text-align: center; font-size: 1rem; }
.sidebar-group-toggle > span { flex: 1; }
.sidebar-group-toggle:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-group-toggle:focus-visible { outline: 2px solid #8fb2ff; outline-offset: -2px; }
.sidebar-chevron { font-size: .7rem; transition: transform .2s ease; }
.sidebar-group-toggle.collapsed .sidebar-chevron { transform: rotate(-90deg); }
.sidebar-group { margin: 2px 0 6px 18px; padding-left: 8px; border-left: 1px solid rgba(255,255,255,.1); }
.sidebar-group .nav-link { padding: 8px 10px; font-size: .875rem; margin-bottom: 1px; }

/* Header */
.ds-year-chip {
  align-items: center; gap: 6px; height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--ds-r-md);
  background: var(--surface-2); color: var(--text); font-size: var(--ds-text-sm); font-weight: 500;
}
.ds-year-chip i { color: var(--text-muted); }
.ds-year-chip:hover { border-color: var(--primary); color: var(--primary); }
.topbar .ds-breadcrumb { line-height: 1.2; }
