/* ================================================================
   Uaddara Basic School — SBA Management System
   Design System | Rebecca Purple Brand
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables ──────────────────────────────────────────────── */
:root {
  /* Rebecca Purple Brand — Refined Palette */
  --clr-primary-50:  #f8f2fd;
  --clr-primary-100: #f0e1f9;
  --clr-primary-200: #e1c4f3;
  --clr-primary-300: #cd9eea;
  --clr-primary-400: #b46de0;
  --clr-primary-500: #9633cc;
  --clr-primary-600: #7e2bb3;
  --clr-primary-700: #662391;
  --clr-primary-800: #4e1a6e;
  --clr-primary-900: #36124c;
  --clr-primary-950: #1a0824;

  --clr-primary:     var(--clr-primary-600);
  --clr-primary-rgb: 126, 43, 179;

  /* Semantic colours */
  --clr-success:     #10b981; /* Emerald */
  --clr-success-bg:  #ecfdf5;
  --clr-warning:     #f59e0b; /* Amber */
  --clr-warning-bg:  #fffbeb;
  --clr-danger:      #ef4444; /* Rose */
  --clr-danger-bg:   #fef2f2;
  --clr-info:        #3b82f6; /* Blue */
  --clr-info-bg:     #eff6ff;

  /* Neutral */
  --clr-text:        #0f172a;
  --clr-text-muted:  #64748b;
  --clr-border:      #e2e8f0;
  --clr-bg:          #fcfaff;
  --clr-surface:     #ffffff;
  --clr-surface-2:   #f8fafc;

  /* Typography */
  --font-sans:  'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:  'JetBrains Mono', monospace;
  --text-xs:    0.75rem;
  --text-sm:    0.875rem;
  --text-base:  1rem;
  --text-lg:    1.125rem;
  --text-xl:    1.25rem;
  --text-2xl:   1.75rem;
  --text-3xl:   2.25rem;

  /* Layout */
  --sidebar-w:  270px;
  --header-h:   72px;
  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  20px;
  --radius-xl:  28px;
  --radius-full:9999px;

  /* Shadows — Multi-layered for depth */
  --shadow-xs:  0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm:  0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md:  0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:  0 10px 15px -3px rgb(150 51 204 / 0.08), 0 4px 6px -4px rgb(150 51 204 / 0.1);
  --shadow-xl:  0 20px 25px -5px rgb(150 51 204 / 0.1), 0 8px 10px -6px rgb(150 51 204 / 0.1);
  --shadow-purple: 0 10px 25px -5px rgba(150, 51, 204, 0.4);

  /* Transitions */
  --dur-fast:   150ms;
  --dur-med:    250ms;
  --dur-slow:   400ms;
  --ease:       cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Custom Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--clr-primary-100); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--clr-primary-200); }

/* ── Reset & Base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--clr-text);
  background: var(--clr-bg);
  line-height: 1.6;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a  { color: var(--clr-primary-600); text-decoration: none; transition: all var(--dur-fast) var(--ease); }
a:hover { color: var(--clr-primary-700); }


/* ── App Shell ──────────────────────────────────────────────────── */
.app-layout {
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--clr-primary-900) 0%, var(--clr-primary-950) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 100;
  border-right: 1px solid rgba(255,255,255,0.05);
  transition: transform var(--dur-slow) cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-logo {
  padding: 1.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid rgba(255,255,255,.05);
}

.sidebar-logo img {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  object-fit: contain;
  background: #fff;
  padding: 4px;
  box-shadow: 0 0 20px rgba(150,51,204,0.3);
}

.sidebar-logo .school-name {
  font-size: var(--text-base);
  font-weight: 800;
  line-height: 1.2;
  color: #fff;
  letter-spacing: -0.02em;
}

.sidebar-logo .school-sub {
  font-size: 0.65rem;
  color: var(--clr-primary-300);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.sidebar-nav { flex: 1; padding: 1.5rem 0.75rem; }

.nav-section-label {
  padding: 1.25rem 1rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--clr-primary-400);
  text-transform: uppercase;
  opacity: 0.8;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.75rem 1rem;
  font-size: var(--text-sm);
  color: rgba(255,255,255,.65);
  border-radius: var(--radius-md);
  margin-bottom: 0.25rem;
  transition: all var(--dur-fast) var(--ease);
  cursor: pointer;
  text-decoration: none;
  position: relative;
}

.nav-item:hover {
  background: rgba(255,255,255,.05);
  color: #fff;
}

.nav-item.active {
  background: var(--clr-primary-600);
  color: #fff;
  box-shadow: var(--shadow-purple);
  font-weight: 600;
}

.nav-item.active::after {
  content: '';
  position: absolute;
  right: -0.75rem;
  top: 20%;
  bottom: 20%;
  width: 4px;
  background: #fff;
  border-radius: 4px 0 0 4px;
  box-shadow: 0 0 10px rgba(255,255,255,0.8);
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; opacity: .7; transition: opacity var(--dur-fast); }
.nav-item:hover svg, .nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--clr-primary-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  color: #fff;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: var(--text-sm); font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: var(--text-xs); color: var(--clr-primary-300); text-transform: capitalize; }

/* ── Top Header ───────────────────────────────────────────────────── */
.app-header {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  padding: 0 2rem;
  gap: 1.5rem;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
}

.header-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--clr-text);
  flex: 1;
}

.header-actions { display: flex; align-items: center; gap: 0.75rem; }

/* ── Main Content Area ────────────────────────────────────────────── */
.app-content {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin-left: var(--sidebar-w);
  min-width: 0;
  transition: margin-left var(--dur-slow) cubic-bezier(0.4, 0, 0.2, 1);
}

.app-main { padding: 2rem 1.5rem; overflow-y: auto; }

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-med) var(--ease);
}
.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--clr-border);
}

.card-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--clr-text);
}

/* ── Stat Cards ──────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--dur-med) var(--ease);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.stat-icon {
  width: 64px; height: 64px;
  border-radius: var(--radius-md);
  background: var(--stat-bg, var(--clr-primary-50));
  color: var(--stat-color, var(--clr-primary-600));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform var(--dur-fast);
}
.stat-card:hover .stat-icon { transform: scale(1.1); }
.stat-icon svg { width: 32px; height: 32px; }

.stat-label { font-size: 0.75rem; color: var(--clr-text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 0.25rem; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--clr-text); line-height: 1; letter-spacing: -0.02em; }
.stat-sub   { font-size: var(--text-xs); color: var(--clr-text-muted); margin-top: 0.5rem; display: flex; align-items: center; gap: 4px; }
.stat-sub.up { color: var(--clr-success); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.25rem;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.5;
  position: relative;
  overflow: hidden;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--clr-primary-600);
  color: #fff;
  box-shadow: 0 2px 8px rgba(120,41,163,.25);
}
.btn-primary:hover { background: var(--clr-primary-700); box-shadow: 0 4px 12px rgba(90,31,122,.3); color: #fff; }

.btn-secondary {
  background: var(--clr-primary-50);
  color: var(--clr-primary-700);
  border: 1px solid var(--clr-primary-200);
}
.btn-secondary:hover { background: var(--clr-primary-100); color: var(--clr-primary-800); }

.btn-success  { background: var(--clr-success);  color: #fff; }
.btn-success:hover { filter: brightness(1.1); color: #fff; }
.btn-danger   { background: var(--clr-danger);   color: #fff; }
.btn-danger:hover  { filter: brightness(1.1); color: #fff; }
.btn-warning  { background: var(--clr-warning);  color: #fff; }
.btn-ghost    { background: transparent; color: var(--clr-text-muted); }
.btn-ghost:hover { background: var(--clr-border); color: var(--clr-text); }
.btn-sm  { padding: 0.35rem 0.85rem; font-size: var(--text-xs); }
.btn-lg  { padding: 0.75rem 1.75rem; font-size: var(--text-base); }

.btn svg { width: 16px; height: 16px; }
.btn-sm svg { width: 14px; height: 14px; }

/* ── Forms ───────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--clr-text);
  margin-bottom: 0.4rem;
}
.form-label .required { color: var(--clr-danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 0.6rem 0.875rem;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--clr-text);
  background: var(--clr-surface);
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.form-control:focus {
  border-color: var(--clr-primary-400);
  box-shadow: 0 0 0 3px rgba(150,51,204,.12);
}
.form-control.is-invalid  { border-color: var(--clr-danger); }
.form-control:focus.is-invalid { box-shadow: 0 0 0 3px rgba(220,38,38,.12); }
.form-control.is-valid    { border-color: var(--clr-success); }

.form-text   { font-size: var(--text-xs); color: var(--clr-text-muted); margin-top: 0.3rem; }
.form-error  { font-size: var(--text-xs); color: var(--clr-danger);     margin-top: 0.3rem; display: flex; align-items: center; gap: 4px; }

/* Score input in grid (monospace, centred) */
.score-input {
  width: 72px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  padding: 0.4rem 0.5rem;
}

/* ── Tables ─────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--clr-border); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead th {
  background: var(--clr-surface-2);
  color: var(--clr-text-muted);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--clr-border);
  white-space: nowrap;
  text-align: left;
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--clr-border);
  color: var(--clr-text);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover { background: var(--clr-surface-2); }

/* Sticky student name column in score grid */
.col-sticky {
  position: sticky;
  left: 0;
  background: var(--clr-surface);
  z-index: 10;
  box-shadow: 2px 0 6px rgba(0,0,0,.06);
}

thead th.col-sticky { background: var(--clr-surface-2); }

/* ── Badge / Chips ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

/* Proficiency level badges */
.level-hp { background: #dcfce7; color: #15803d; }
.level-p  { background: #dbeafe; color: #1d4ed8; }
.level-ap { background: #ede9fe; color: #6d28d9; }
.level-d  { background: #fef3c7; color: #92400e; }
.level-e  { background: #fee2e2; color: #991b1b; }

/* General status badges */
.badge-success  { background: var(--clr-success-bg); color: var(--clr-success); }
.badge-danger   { background: var(--clr-danger-bg);  color: var(--clr-danger);  }
.badge-warning  { background: var(--clr-warning-bg); color: var(--clr-warning); }
.badge-info     { background: var(--clr-info-bg);    color: var(--clr-info);    }
.badge-purple   { background: var(--clr-primary-50); color: var(--clr-primary-700); }
.badge-gray     { background: #f1f5f9; color: #64748b; }

/* ── Alerts / Toasts ─────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: 1rem;
  border-left: 4px solid;
}
.alert-success { background: var(--clr-success-bg); border-color: var(--clr-success); color: #166534; }
.alert-danger  { background: var(--clr-danger-bg);  border-color: var(--clr-danger);  color: #991b1b; }
.alert-warning { background: var(--clr-warning-bg); border-color: var(--clr-warning); color: #92400e; }
.alert-info    { background: var(--clr-info-bg);    border-color: var(--clr-info);    color: #075985; }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

/* Toast container */
#toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 360px;
  pointer-events: none;
}

.toast {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: var(--text-sm);
  pointer-events: all;
  animation: toastIn var(--dur-slow) var(--ease) both;
}

.toast.hiding { animation: toastOut var(--dur-med) var(--ease) both; }

@keyframes toastIn  { from { opacity:0; transform: translateX(100%); } to { opacity:1; transform: translateX(0); } }
@keyframes toastOut { from { opacity:1; transform: translateX(0); } to { opacity:0; transform: translateX(100%); } }

/* ── Save indicator ──────────────────────────────────────────────── */
.save-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--text-xs);
  color: var(--clr-success);
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease);
}
.save-indicator.visible { opacity: 1; }
.save-indicator svg { width: 14px; height: 14px; }

/* ── Auto-save pulsing dot ───────────────────────────────────────── */
.pulse-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--clr-warning);
  display: inline-block;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); opacity:1; } 50% { transform: scale(1.5); opacity:.5; } }

/* ── Unified Modal System ─────────────────────────────────────────
   Both .modal-overlay (JS-toggle pattern) and .modal-backdrop
   (direct DOM pattern) are now handled by one set of rules.
   Use openModal() / closeModal() from app.js for all modals.
   ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 5, 30, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 600;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  /* Opacity transition driven by .open class */
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease);
}
.modal-overlay.open {
  display: flex;
  opacity: 1;
}

/* Inner modal card */
.modal-overlay > .modal,
.modal-overlay > [class*="modal"] > .modal {
  background: var(--clr-surface);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-xl);
  transform: translateY(24px);
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur-slow) var(--ease);
  opacity: 0;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* clip border-radius — body scrolls internally */
}
.modal-overlay.open > .modal,
.modal-overlay.open > [class*="modal"] > .modal {
  transform: translateY(0);
  opacity: 1;
}

.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.375rem 1.5rem; border-bottom: 1px solid var(--clr-border); flex-shrink: 0; }
.modal-title  { font-size: var(--text-xl); font-weight: 700; margin: 0; }
.modal-close  {
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--clr-border);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--clr-text-muted);
  font-size: 1.1rem; line-height: 1;
  transition: background var(--dur-fast), color var(--dur-fast);
  flex-shrink: 0;
}
.modal-close:hover { background: var(--clr-primary-100); color: var(--clr-primary-700); }

/* ── Auth / Login ────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--clr-surface);
}

.auth-left {
  background: linear-gradient(135deg, var(--clr-primary-700) 0%, var(--clr-primary-950) 100%);
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.auth-left::before {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  background: rgba(255,255,255,.04);
  border-radius: 50%;
  top: -15%; right: -20%;
}

.auth-left::after {
  content: '';
  position: absolute;
  width: 300px; height: 300px;
  background: rgba(255,255,255,.05);
  border-radius: 50%;
  bottom: -10%; left: -10%;
}

.auth-brand { position: relative; z-index: 1; }

.auth-brand-logo {
  width: 80px; height: 80px;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 8px;
  object-fit: contain;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-lg);
}

.auth-brand h1 {
  font-size: var(--text-3xl);
  font-weight: 800;
  color: #fff;
  line-height: 1.2;
  margin-bottom: 0.5rem;
}

.auth-brand p {
  color: var(--clr-primary-200);
  font-size: var(--text-base);
  line-height: 1.6;
}

.auth-features {
  margin-top: 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
  z-index: 1;
}

.auth-feature {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--clr-primary-100);
  font-size: var(--text-sm);
}
.auth-feature-icon {
  width: 32px; height: 32px;
  background: rgba(255,255,255,.1);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.auth-feature-icon svg { width: 16px; height: 16px; color: var(--clr-primary-200); }

.auth-right {
  padding: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-box { width: 100%; max-width: 420px; }

.auth-box h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.auth-box .auth-sub {
  color: var(--clr-text-muted);
  font-size: var(--text-sm);
  margin-bottom: 2rem;
}

/* Role tabs */
.role-tabs {
  display: flex;
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 2rem;
}

.role-tab {
  flex: 1;
  padding: 0.65rem 0.5rem;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--clr-text-muted);
  background: var(--clr-surface);
  border: none;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  text-align: center;
  border-right: 1.5px solid var(--clr-border);
}
.role-tab:last-child { border-right: none; }
.role-tab:hover { background: var(--clr-primary-50); color: var(--clr-primary-700); }
.role-tab.active {
  background: var(--clr-primary-600);
  color: #fff;
}

/* ── OTP input ──────────────────────────────────────────────────── */
.otp-inputs {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin: 1.5rem 0;
}

.otp-digit {
  width: 52px; height: 60px;
  text-align: center;
  font-size: var(--text-xl);
  font-weight: 700;
  font-family: var(--font-mono);
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.otp-digit:focus {
  border-color: var(--clr-primary-500);
  box-shadow: 0 0 0 3px rgba(150,51,204,.15);
}
.otp-digit.filled { border-color: var(--clr-primary-400); background: var(--clr-primary-50); }

.otp-timer {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--clr-text-muted);
  margin-bottom: 1rem;
}
.otp-timer span { font-weight: 700; color: var(--clr-primary-600); font-family: var(--font-mono); }

/* ── Pagination ─────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 1.25rem;
  justify-content: flex-end;
}
.page-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--clr-border);
  background: var(--clr-surface);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  color: var(--clr-text-muted);
}
.page-btn:hover { border-color: var(--clr-primary-400); color: var(--clr-primary-600); }
.page-btn.active { background: var(--clr-primary-600); border-color: var(--clr-primary-600); color: #fff; font-weight: 700; }

/* ── Empty & Loading states ─────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--clr-text-muted);
}
.empty-state svg { width: 56px; height: 56px; margin: 0 auto 1rem; opacity: .3; }
.empty-state h3 { font-size: var(--text-lg); font-weight: 600; color: var(--clr-text); margin-bottom: 0.5rem; }
.empty-state p  { font-size: var(--text-sm); margin-bottom: 1.5rem; }

.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 220px; }
}

/* ── Off-Canvas Sidebar (Mobile) ────────────────────────────────── */
/* Sidebar backdrop overlay */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 5, 30, 0.6);
  backdrop-filter: blur(2px);
  z-index: 98;
  animation: fadeIn var(--dur-med) var(--ease);
}
.sidebar-backdrop.visible { display: block; }

/* Mobile close button inside sidebar */
.sidebar-close {
  display: none;
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.12);
  color: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background var(--dur-fast);
}
.sidebar-close:hover { background: rgba(255,255,255,0.22); }

@media (max-width: 768px) {
  /* Layout collapses to single column */
  .app-layout {
    grid-template-columns: 1fr;
  }

  /* Sidebar becomes off-canvas panel */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-w);
    z-index: 99;
    transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease);
    box-shadow: var(--shadow-xl);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* Show mobile close button */
  .sidebar-close { display: flex; }

  /* Main content fills full width — sidebar is off-canvas (position:fixed, off-screen) */
  .app-content {
    margin-left: 0;
    min-height: 100vh;
  }

  /* Show hamburger in header */
  #sidebar-toggle { display: flex !important; }

  /* Auth page */
  .auth-page  { grid-template-columns: 1fr; }
  .auth-left  { display: none; }
  .auth-right { padding: 2rem 1.25rem; }

  /* Stat cards: 2-column on tablet */
  .stat-grid { grid-template-columns: 1fr 1fr; }

  /* Main content padding */
  .app-main { padding: 1rem; }

  /* Flex-wrap fixes for page headers */
  .flex.justify-between.items-center.flex-wrap {
    flex-direction: column;
    align-items: flex-start;
  }
  .flex.justify-between.items-center.flex-wrap > :last-child {
    align-self: stretch;
    width: 100%;
  }
  .flex.justify-between.items-center.flex-wrap > :last-child .btn {
    width: 100%;
    justify-content: center;
  }

  /* Two-column form grids collapse */
  .grid[style*="grid-template-columns:1fr 1fr"],
  .grid[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* SMS Centre layout */
  div.grid[style*="1.5fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Table overflow containers */
  .table-wrapper,
  div[style*="overflow-x:auto"],
  div[style*="overflow-x: auto"] {
    -webkit-overflow-scrolling: touch;
  }

  /* Modal full-width on mobile (Premium Bottom Sheet UX) */
  .modal-overlay .modal,
  .modal-backdrop .modal,
  .modal-overlay > div[class~="modal"] {
    max-width: 100% !important;
    margin: 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    /* Allow up to 92vh — inner .modal-body handles the scrolling */
    max-height: 92vh;
    position: relative;
    transform: translateY(100%);
  }
  .modal-overlay.open .modal,
  .modal-backdrop.open .modal {
    transform: translateY(0);
  }
  .modal-overlay, .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  /* UX Affordance: Drag Handle for the bottom sheet */
  .modal-overlay .modal::before,
  .modal-backdrop .modal::before,
  .modal-overlay > div[class~="modal"]::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 5px;
    background: var(--clr-border);
    border-radius: var(--radius-full);
    z-index: 10;
    pointer-events: none;
  }

  /* Ensure modal header doesn't scroll away */
  .modal-overlay .modal .modal-header,
  .modal-backdrop .modal .modal-header {
    flex-shrink: 0;
  }

  /* Ensure modal footer stays pinned at bottom */
  .modal-overlay .modal .modal-footer,
  .modal-backdrop .modal .modal-footer {
    flex-shrink: 0;
  }
} /* <--- RESTORED MISSING CLOSING BRACE FOR @media (max-width: 768px) */

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .role-tabs { flex-direction: column; }
  .role-tab  { border-right: none; border-bottom: 1.5px solid var(--clr-border); }
  .role-tab:last-child { border-bottom: none; }
  .app-header { padding: 0 1rem; }
}

/* ── Utility classes ─────────────────────────────────────────────── */
.flex         { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; } .gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; } .gap-4 { gap: 1rem; }
.mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem;   } .mt-6 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1rem;} .mb-6 { margin-bottom: 1.5rem; }
.text-sm   { font-size: var(--text-sm); }
.text-xs   { font-size: var(--text-xs); }
.text-muted { color: var(--clr-text-muted); }
.font-bold  { font-weight: 700; }
.font-semibold { font-weight: 600; }
.w-full    { width: 100%; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.hidden    { display: none !important; }
.rounded-full { border-radius: var(--radius-full); }
.flex-col  { flex-direction: column; }
.justify-end { justify-content: flex-end; }
.m-0 { margin: 0; }
.p-4 { padding: 1rem; }
.mr-2 { margin-right: .5rem; }
.grayscale { filter: grayscale(1); }
.opacity-50 { opacity: 0.5; }
.text-danger { color: var(--clr-danger) !important; }
.text-success { color: var(--clr-success) !important; }
.text-warning { color: var(--clr-warning) !important; }
.text-primary { color: var(--clr-primary-600) !important; }
.shadow-purple { box-shadow: 0 4px 14px 0 rgba(107, 33, 168, 0.3); }
.w-full { width: 100%; }
.m-0 { margin: 0; }
.mt-4 { margin-top: 1rem; }

/* ── Grid utility ─────────────────────────────────────────────── */
.grid { display: grid; }

/* ── Outlined button variant ──────────────────────────────────── */
.btn-outline {
  background: transparent;
  color: var(--clr-primary-600);
  border: 1.5px solid var(--clr-primary-300);
}
.btn-outline:hover {
  background: var(--clr-primary-50);
  border-color: var(--clr-primary-400);
  color: var(--clr-primary-700);
}
.btn-outline.btn-danger {
  color: var(--clr-danger);
  border-color: rgba(220,38,38,.35);
}
.btn-outline.btn-danger:hover {
  background: var(--clr-danger-bg);
  border-color: var(--clr-danger);
}

/* ── .modal-backdrop is now an ALIAS for .modal-overlay ──────────
   Legacy pages that use .modal-backdrop will inherit the same styles.
   Always prefer .modal-overlay for new code.
   ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 5, 30, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 600;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease);
}
.modal-backdrop.open {
  display: flex;
  opacity: 1;
}

.modal-backdrop .modal {
  background: var(--clr-surface);
  border-radius: var(--radius-xl);
  width: auto;
  min-width: 320px;
  max-width: calc(100% - 2rem);
  box-shadow: var(--shadow-xl);
  max-height: calc(100vh - 4rem);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* clip border-radius — body scrolls internally */
  transform: translateY(24px);
  opacity: 0;
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur-slow) var(--ease);
}
.modal-backdrop.open .modal {
  transform: translateY(0);
  opacity: 1;
}

@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* smooth momentum scrolling on iOS */
  overscroll-behavior: contain;      /* prevent scroll chaining to page behind */
  flex: 1;
  min-height: 0;                     /* critical: allows flex child to scroll */
}
.modal-footer {
  padding: 1.125rem 1.5rem;
  border-top: 1px solid var(--clr-border);
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  flex-wrap: wrap;
  flex-shrink: 0;                    /* keep actions visible; body scrolls above */
}

/* Tall modals: stack scrollable body + pinned footer inside remaining column space */
.modal-flex-stack {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
}
.modal-flex-stack > .modal-body {
  flex: 1 1 0%;
  min-height: 0;
}

/* ── Inline alert in forms / pages ────────────────────────────── */
.alert-info {
  display: flex;
  align-items: flex-start;
  gap: .625rem;
  background: var(--clr-info-bg);
  border-left: 4px solid var(--clr-info);
  color: #075985;
  padding: .875rem 1rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.alert-info svg { flex-shrink:0; margin-top:1px; }

/* ── Card without default padding (for table cards) ────────────── */
.card-body { padding: 1.5rem; }
.card-header + .table-wrapper { border-top: none; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ── Global Loader Bar ─────────────────────────────────────────── */
.loader-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--clr-primary-400), var(--clr-primary-600), var(--clr-primary-400));
  background-size: 200% 100%;
  z-index: 1000;
  animation: loaderMove 1.5s linear infinite;
}
@keyframes loaderMove { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ── Entry Animations ─────────────────────────────────────────── */
.animate-fade-in {
  animation: fadeInOpacity var(--dur-slow) var(--ease) forwards;
}
@keyframes fadeInOpacity { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ── Tooltips (Simple CSS) ─────────────────────────────────────── */
[data-tooltip] { position: relative; cursor: help; }
[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%; left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--clr-primary-900);
  color: #fff;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: all var(--dur-fast) var(--ease);
  z-index: 100;
}
[data-tooltip]:hover::before { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ── Premium Effects & Utils ──────────────────────────────────── */
.hover-lift {
  transition: transform var(--dur-med) cubic-bezier(0.34, 1.56, 0.64, 1), 
              box-shadow var(--dur-med) var(--ease) !important;
}
.hover-lift:hover {
  transform: translateY(-5px) scale(1.01);
  box-shadow: var(--shadow-xl) !important;
}

.stat-bubble {
  transition: transform var(--dur-med) cubic-bezier(0.34, 1.56, 0.64, 1);
}
.card:hover .stat-bubble {
  transform: scale(1.05);
}

.glass-card {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.mgmt-card {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(var(--clr-primary-rgb), 0.12);
  border-radius: var(--radius-xl);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--dur-med) cubic-bezier(0.34, 1.56, 0.64, 1), 
              box-shadow var(--dur-med) var(--ease),
              border-color var(--dur-med) var(--ease);
}
.mgmt-card:hover {
  border-color: rgba(var(--clr-primary-rgb), 0.25);
}

/* Sub-total indicator glow */
.progress-glow {
  position: relative;
  overflow: hidden;
}
.progress-glow::after {
  content: "";
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  animation: shine 3s infinite;
}
@keyframes shine {
  to { left: 200%; }
}
