/* ---------- Base ---------- */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning-soft: #fef3c7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 0 0 .35rem; }
h3 { font-size: 1.05rem; margin: 0; }
p { margin: .25rem 0; }
.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.icon {
  width: 18px; height: 18px; flex: none;
  stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 30;
  width: 250px; display: flex; flex-direction: column;
  background: var(--sidebar); color: var(--sidebar-text);
  transition: transform .2s ease;
}
.brand {
  display: flex; align-items: center; gap: .7rem;
  padding: 1.25rem; font-weight: 700; font-size: 1.02rem; line-height: 1.25;
  color: #fff; border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.brand-mark {
  width: 34px; height: 34px; flex: none; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 800;
}
.nav { flex: 1; overflow-y: auto; padding: .75rem; }
.nav-label {
  padding: .9rem .75rem .35rem; font-size: .7rem;
  text-transform: uppercase; letter-spacing: .08em; color: #64748b;
}
.nav a {
  display: flex; align-items: center; gap: .65rem;
  padding: .6rem .75rem; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav a.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255, 255, 255, .08); }
.user-chip { display: flex; align-items: center; gap: .65rem; margin-bottom: .75rem; }
.avatar {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: #334155; color: #fff; font-weight: 700;
}
.user-name { color: #fff; font-weight: 600; font-size: .9rem; line-height: 1.2; }
.user-role { color: #94a3b8; font-size: .75rem; }
.main { flex: 1; min-width: 0; margin-left: 250px; display: flex; flex-direction: column; }
.topbar {
  display: none; align-items: center; gap: .75rem;
  position: sticky; top: 0; z-index: 20;
  padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.menu-btn {
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer;
}
.content { width: 100%; max-width: 1100px; padding: 1.75rem 2rem 3rem; }
.overlay { display: none; position: fixed; inset: 0; z-index: 25; background: rgba(15, 23, 42, .5); }

/* ---------- Page pieces ---------- */
.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.head-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.section-title { margin: 1.75rem 0 .75rem; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.25rem; margin-bottom: 1.25rem;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.narrow { max-width: 520px; }
.two-col {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  gap: 1.25rem; align-items: start;
}
.two-col .card { margin: 0; }
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.stats .card { margin: 0; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-label { margin-top: .25rem; color: var(--muted); font-size: .9rem; }
.actions-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem;
}
.action { display: flex; flex-direction: column; gap: .25rem; margin: 0; color: var(--text); }
.action:hover { border-color: var(--primary); text-decoration: none; }
.action span { color: var(--muted); font-size: .9rem; }
.empty { text-align: center; padding: 2.5rem 1.25rem; color: var(--muted); }
.error-code { font-size: 3.5rem; font-weight: 800; color: var(--primary); line-height: 1; margin-bottom: .5rem; }

/* ---------- Buttons, badges, alerts ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem 1rem; border: 1px solid transparent; border-radius: 8px;
  font: inherit; font-weight: 600; line-height: 1.2; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: rgba(255, 255, 255, .08); color: #e2e8f0; }
.btn-ghost:hover { background: rgba(255, 255, 255, .14); }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }
.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-success { background: var(--success-soft); color: #166534; }
.badge-warning { background: var(--warning-soft); color: #92400e; }
.badge-primary { background: var(--primary-soft); color: #1e40af; }
.badge-muted { background: #e2e8f0; color: #475569; }
.alert { padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid; border-radius: 8px; font-size: .92rem; }
.alert-success { background: var(--success-soft); border-color: #86efac; color: #166534; }
.alert-error { background: var(--danger-soft); border-color: #fca5a5; color: #991b1b; }
.alert-warning { background: var(--warning-soft); border-color: #fcd34d; color: #92400e; }
.alert .errorlist { margin: 0; padding: 0; list-style: none; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: .3rem; font-size: .875rem; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid #cbd5e1; border-radius: 8px;
  background: #fff; color: var(--text); font: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus,
.score-table input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.helptext { margin-top: .25rem; color: var(--muted); font-size: .8rem; }
.errorlist { margin: .3rem 0 0; padding: 0; list-style: none; color: var(--danger); font-size: .85rem; }
.form-actions { display: flex; gap: .6rem; align-items: center; margin-top: 1rem; }
.filter-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem; align-items: end;
}
.filter-grid .field { margin: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
  padding: .65rem .85rem; background: #f8fafc; border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: .75rem; text-align: left;
  text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
}
.table td { padding: .65rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #f8fafc; }
.score-table input {
  width: 5.5rem; padding: .4rem .5rem; border: 1px solid #cbd5e1; border-radius: 6px;
  text-align: center; font: inherit;
}

/* ---------- Login page ---------- */
.auth-body {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
}
.auth-card {
  width: 100%; max-width: 400px; padding: 2rem;
  background: #fff; border-radius: 14px; box-shadow: 0 20px 40px rgba(0, 0, 0, .3);
}
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand .brand-mark { width: 48px; height: 48px; margin: 0 auto .75rem; font-size: 1.3rem; }
.auth-brand h1 { font-size: 1.3rem; }

/* ---------- Report card ---------- */
.report { padding: 2rem; }
.report-head { text-align: center; padding-bottom: 1rem; margin-bottom: 1.25rem; border-bottom: 2px solid var(--text); }
.report-school { font-size: 1.4rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.report-title { margin-top: .25rem; font-weight: 600; }
.report-term { color: var(--muted); }
.report-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .75rem 1.5rem; margin: 0 0 1.25rem;
}
.report-meta dt { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.report-meta dd { margin: 0; font-weight: 600; }
.report-table th, .report-table td { text-align: center; }
.report-table th:first-child, .report-table td:first-child { text-align: left; }
.report-table th:last-child, .report-table td:last-child { text-align: left; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin-top: 1.25rem; }
.summary div { padding: .75rem; border: 1px solid var(--border); border-radius: 8px; text-align: center; }
.summary strong { display: block; font-size: 1.25rem; }
.summary span { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
.signatures { display: flex; justify-content: space-between; gap: 2rem; margin-top: 3rem; }
.signatures div { flex: 1; padding-top: .35rem; border-top: 1px solid var(--text); text-align: center; font-size: .85rem; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .overlay { display: block; }
  .main { margin-left: 0; }
  .topbar { display: flex; }
  .content { padding: 1.25rem 1rem 2.5rem; }
  .two-col { grid-template-columns: 1fr; }
  .report { padding: 1.25rem; }
}

/* ---------- Print ---------- */
@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .overlay, .alert, .no-print { display: none; }
  .main { margin-left: 0; }
  .content { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .report { padding: 0; }
  .table th {
    background: #f1f5f9;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
