/* ═══════════════════════════════════════════════════════════════
   base.css — Design Tokens & Shared Components
   AutoGrade AI · v2.0
   ═══════════════════════════════════════════════════════════════ */

/* ── Google Fonts fallback stack ─────────────────────────── */
/* Syne (display), DM Sans (body), DM Mono (numbers/code)    */

/* ── Design Tokens ───────────────────────────────────────── */
:root {
  /* Brand */
  --brand:        #5B6AF0;
  --brand-light:  #8B96F7;
  --brand-dim:    rgba(91,106,240,.12);
  --brand-glow:   rgba(91,106,240,.25);

  /* Semantic */
  --green:        #10B981;
  --green-dim:    rgba(16,185,129,.12);
  --amber:        #F59E0B;
  --amber-dim:    rgba(245,158,11,.12);
  --red:          #EF4444;
  --red-dim:      rgba(239,68,68,.12);
  --teal:         #06B6D4;
  --teal-dim:     rgba(6,182,212,.12);

  /* Neutral (light base) */
  --bg-page:      #F4F5FB;
  --bg-surface:   #FFFFFF;
  --bg-raised:    #F9FAFF;
  --border:       #E4E6F0;
  --border-strong:#C9CCE0;

  --text-900:     #0F1022;
  --text-700:     #3D4168;
  --text-500:     #737CA1;
  --text-300:     #A8AECB;

  /* Layout */
  --sidebar-w:    240px;
  --topbar-h:     60px;
  --radius-sm:    8px;
  --radius-md:    12px;
  --radius-lg:    18px;
  --radius-full:  999px;

  /* Shadows */
  --shadow-xs:    0 1px 3px rgba(15,16,34,.06);
  --shadow-sm:    0 2px 8px rgba(15,16,34,.08);
  --shadow-md:    0 4px 20px rgba(15,16,34,.10);
  --shadow-lg:    0 8px 40px rgba(15,16,34,.14);
  --shadow-brand: 0 4px 20px var(--brand-glow);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg-page);
  color: var(--text-700);
  line-height: 1.6;
  min-height: 100dvh;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; border: none; }
input, textarea, select { font-family: inherit; }
img { display: block; max-width: 100%; }

/* ── Typography ──────────────────────────────────────────── */
h1, h2, h3, h4, h5 {
  font-family: 'Syne', sans-serif;
  color: var(--text-900);
  line-height: 1.25;
}
.mono { font-family: 'DM Mono', monospace; }

/* ── App Shell ───────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100dvh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--text-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-logo-mark {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif;
  font-weight: 800; font-size: .85rem;
  color: #fff; flex-shrink: 0;
  box-shadow: var(--shadow-brand);
}
.sidebar-logo-name {
  font-family: 'Syne', sans-serif;
  font-weight: 700; font-size: 1rem;
  color: #fff;
  letter-spacing: -.01em;
}
.sidebar-logo-name span {
  display: block;
  font-size: .68rem; font-weight: 400;
  color: rgba(255,255,255,.4);
  letter-spacing: .04em; text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
}
.nav-section-label {
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: 14px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.55);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
  user-select: none;
  text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.9); text-decoration: none; }
.nav-item.active { background: var(--brand); color: #fff; box-shadow: var(--shadow-brand); }
.nav-item .nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 10px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.05);
}
.sidebar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--brand-dim);
  border: 2px solid var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif;
  font-weight: 700; font-size: .8rem;
  color: var(--brand-light);
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: .82rem; font-weight: 600;
  color: rgba(255,255,255,.9);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role { font-size: .72rem; color: rgba(255,255,255,.4); }
.sidebar-school { padding: 6px 12px 10px; }
.sidebar-school-name {
  font-size: .8rem; font-weight: 600;
  color: rgba(255,255,255,.7);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-school-tier {
  font-size: .7rem; color: rgba(255,255,255,.35);
}

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky; top: 0;
  z-index: 50;
}
.topbar-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700; font-size: 1rem;
  color: var(--text-900);
}
.topbar-subtitle { font-weight: 400; color: var(--text-300); font-size: .88rem; }
.topbar-spacer { flex: 1; }
.topbar-logout {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-500);
  font-size: .82rem;
  transition: all .15s;
}
.topbar-logout:hover { border-color: var(--red); color: var(--red); background: var(--red-dim); }

/* ── Page Content ────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 28px;
}

/* Section visibility */
.section { display: none; }
.section.active { display: block; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}
.card-header {
  padding: 18px 22px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700; font-size: .95rem;
  color: var(--text-900);
}
.card-body { padding: 18px 22px; }
.card-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow .2s, transform .2s;
}
.stat-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.stat-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-300); }
.stat-value {
  font-family: 'Syne', sans-serif;
  font-size: 2rem; font-weight: 800;
  color: var(--text-900);
  line-height: 1.1;
  margin: 6px 0 2px;
}
.stat-sub { font-size: .78rem; color: var(--text-500); }
.stat-icon { font-size: 1.4rem; margin-bottom: 6px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 600;
  transition: all .15s;
  cursor: pointer; border: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover { background: #4B5AE0; box-shadow: 0 6px 24px var(--brand-glow); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  background: var(--bg-raised);
  color: var(--text-700);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-dim); }
.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid transparent;
}
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-lg { padding: 12px 28px; font-size: .95rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-full { width: 100%; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .8rem; font-weight: 600;
  color: var(--text-700);
  margin-bottom: 6px;
}
.form-label .required { color: var(--red); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text-900);
  font-size: .875rem;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-control:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-dim);
  background: var(--bg-surface);
}
.form-control::placeholder { color: var(--text-300); }
textarea.form-control { resize: vertical; min-height: 80px; line-height: 1.6; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23A8AECB' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.form-hint { font-size: .75rem; color: var(--text-300); margin-top: 4px; }
.form-error { font-size: .78rem; color: var(--red); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.alert-error   { background: var(--red-dim);   color: var(--red);   border: 1px solid rgba(239,68,68,.2); }
.alert-success { background: var(--green-dim);  color: var(--green); border: 1px solid rgba(16,185,129,.2); }
.alert-info    { background: var(--brand-dim);  color: var(--brand); border: 1px solid rgba(91,106,240,.2); }

/* ── Badges & Pills ──────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  font-size: .72rem; font-weight: 700;
  letter-spacing: .02em;
}
.badge-brand   { background: var(--brand-dim);  color: var(--brand); }
.badge-green   { background: var(--green-dim);  color: var(--green); }
.badge-amber   { background: var(--amber-dim);  color: var(--amber); }
.badge-red     { background: var(--red-dim);    color: var(--red); }
.badge-teal    { background: var(--teal-dim);   color: var(--teal); }

.status-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: .73rem; font-weight: 600;
}
.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  display: inline-block;
}
.status-pill.completed { background: var(--green-dim); color: var(--green); }
.status-pill.completed .status-dot { background: var(--green); }
.status-pill.pending   { background: var(--amber-dim); color: var(--amber); }
.status-pill.pending   .status-dot { background: var(--amber); animation: pulse 1.4s infinite; }
.status-pill.failed    { background: var(--red-dim);   color: var(--red); }
.status-pill.failed    .status-dot { background: var(--red); }
.status-pill.active    { background: var(--green-dim); color: var(--green); }
.status-pill.inactive  { background: var(--red-dim);   color: var(--red); }

.type-pill { padding: 2px 9px; border-radius: var(--radius-full); font-size: .72rem; font-weight: 700; }
.type-pill.general { background: var(--brand-dim); color: var(--brand); }
.type-pill.coding  { background: var(--teal-dim);  color: var(--teal); }
.type-pill.mc      { background: var(--amber-dim); color: var(--amber); }

/* ── Score Badge ─────────────────────────────────────────── */
.score-badge {
  font-family: 'DM Mono', monospace;
  font-size: .82rem; font-weight: 500;
  padding: 3px 10px;
  border-radius: var(--radius-full);
}
.score-badge.excellent { background: var(--green-dim);  color: var(--green); }
.score-badge.good      { background: var(--teal-dim);   color: var(--teal); }
.score-badge.average   { background: var(--amber-dim);  color: var(--amber); }
.score-badge.poor      { background: var(--red-dim);    color: var(--red); }
.score-badge.pending   { background: var(--border);     color: var(--text-300); }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
table { width: 100%; border-collapse: collapse; background: var(--bg-surface); }
thead th {
  background: var(--bg-raised);
  padding: 11px 16px;
  text-align: left;
  font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-300);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px;
  font-size: .875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-raised); }

/* ── Quota Bar ───────────────────────────────────────────── */
.quota-bar { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; margin: 6px 0; }
.quota-bar-fill { height: 100%; background: var(--brand); border-radius: 99px; transition: width .6s ease; }
.quota-bar-fill.warn   { background: var(--amber); }
.quota-bar-fill.danger { background: var(--red); }

/* ── Bar Chart ───────────────────────────────────────────── */
.bar-chart {
  display: flex; align-items: flex-end;
  gap: 6px; height: 80px;
  padding: 0 4px;
}
.bar-chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; }
.bar-chart-bar {
  width: 100%;
  background: var(--brand-dim);
  border-radius: 4px 4px 0 0;
  transition: background .15s;
  cursor: default;
}
.bar-chart-bar:hover { background: var(--brand); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  animation: modalIn .22s ease;
}
.modal-header {
  padding: 22px 24px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700; font-size: 1rem;
  color: var(--text-900);
}
.modal-close {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-500);
  font-size: 1.1rem; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.modal-close:hover { background: var(--red-dim); color: var(--red); border-color: var(--red); }
.modal-body  { padding: 22px 24px; }
.modal-footer {
  padding: 14px 24px 20px;
  display: flex; gap: 10px; justify-content: flex-end;
  border-top: 1px solid var(--border);
}

/* ── Toast ───────────────────────────────────────────────── */
#toastContainer {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 11px 18px;
  border-radius: var(--radius-md);
  font-size: .875rem; font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn .22s ease;
  min-width: 200px; max-width: 340px;
}
.toast.success { background: var(--green-dim);  color: var(--green); border: 1px solid rgba(16,185,129,.25); }
.toast.error   { background: var(--red-dim);    color: var(--red);   border: 1px solid rgba(239,68,68,.25); }
.toast.info    { background: var(--brand-dim);  color: var(--brand); border: 1px solid rgba(91,106,240,.25); }

/* ── Login Page ──────────────────────────────────────────── */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: var(--text-900);
  position: relative;
  overflow: hidden;
}
.login-page::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--brand-glow) 0%, transparent 70%);
  top: -200px; right: -200px;
  pointer-events: none;
}
.login-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 38px;
  width: 100%; max-width: 420px;
  position: relative; z-index: 1;
}
.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 28px;
}
.login-logo-mark {
  width: 42px; height: 42px;
  border-radius: var(--radius-md);
  background: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif;
  font-weight: 800; font-size: 1.1rem; color: #fff;
  box-shadow: var(--shadow-brand);
}
.login-logo-text .name { font-family: 'Syne', sans-serif; font-weight: 800; font-size: 1.25rem; color: var(--text-900); }
.login-logo-text .sub  { font-size: .75rem; color: var(--text-300); }
.login-title { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 1.4rem; color: var(--text-900); margin-bottom: 6px; }
.login-sub   { font-size: .875rem; color: var(--text-500); margin-bottom: 26px; }

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--text-300);
}
.empty-icon { font-size: 2.2rem; margin-bottom: 8px; }
.empty-text { font-size: .875rem; }

/* ── Misc ────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; flex-wrap: wrap; gap: 10px;
}
.section-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700; font-size: 1.05rem;
  color: var(--text-900);
}
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.filter-bar .form-control { min-width: 0; }
.loading-text { color: var(--text-500); font-size: .875rem; }
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.loader-center {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 32px;
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes pulse   { 0%,100% { opacity:1; } 50% { opacity:.4; } }
@keyframes toastIn { from { opacity:0; transform: translateY(10px); } to { opacity:1; transform: translateY(0); } }
@keyframes modalIn { from { opacity:0; transform: scale(.95); } to { opacity:1; transform: scale(1); } }
@keyframes fadeIn  { from { opacity:0; } to { opacity:1; } }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; }
  .main-content { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .page-content { padding: 16px; }
}