:root {
  --abi:        #1a2b7a;
  --abi-dark:   #0f1a5c;
  --abi-red:    #e31e24;
  --abi-light:  #e8ecf8;
  --kb:         #00aeef;
  --kb-dark:    #0099cc;
  --kb-light:   #e0f5fd;
  --success:    #16a34a;
  --warning:    #d97706;
  --danger:     #dc2626;
  --bg:         #f8fafc;
  --card:       #ffffff;
  --text:       #1e293b;
  --muted:      #64748b;
  --border:     #e2e8f0;
  --sidebar-w:  240px;
  --primary:    var(--abi);
  --primary-dark: var(--abi-dark);
  --primary-light: var(--abi-light);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; font-size: 14px; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: #0d1b4b;
  color: #cbd5e1;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 1.1rem 1rem 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar-brand .logo { font-size: 1.5rem; margin-bottom: 0.2rem; }
.sidebar-brand h1 { font-size: 1.05rem; font-weight: 800; color: #fff; }
.sidebar-brand p { font-size: 0.68rem; color: #64748b; margin-top: 2px; }

/* ── School Switcher ── */
.school-switcher {
  display: flex;
  gap: 0.3rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  background: rgba(0,0,0,0.2);
}
.switch-btn {
  flex: 1;
  padding: 0.35rem 0.3rem;
  border-radius: 0.4rem;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent;
  color: #94a3b8;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.switch-btn:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }
.switch-btn.active-all  { background: #334155; color: #fff; border-color: #475569; }
.switch-btn.active-abi  { background: var(--abi); color: #fff; border-color: var(--abi); }
.switch-btn.active-kb   { background: var(--kb);  color: #fff; border-color: var(--kb); }

/* ── Quick enroll button in sidebar ── */
.sidebar-enroll {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.btn-enroll-quick {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  background: var(--abi-red);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background 0.12s;
}
.btn-enroll-quick:hover { background: #c41920; text-decoration: none; color: #fff; }

/* ── Sidebar Nav ── */
.sidebar-nav { padding: 0.5rem 0; flex: 1; }
.nav-section {
  padding: 0.55rem 1rem 0.25rem;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
  margin-top: 0.2rem;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.825rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all 0.12s;
}
.nav-link:hover { color: #f1f5f9; background: rgba(255,255,255,0.05); }
.nav-link.active { color: #fff; background: rgba(227,30,36,0.15); border-left-color: var(--abi-red); }
.nav-link .icon { font-size: 1rem; width: 1.1rem; text-align: center; }

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.07);
}
.school-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 700;
}
.abi-pill { background: rgba(26,43,122,0.4); color: #a5b4fc; }
.kb-pill  { background: rgba(0,174,239,0.25); color: #7dd3fc; }
.all-pill { background: rgba(255,255,255,0.08); color: #94a3b8; }

/* ── Main ── */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h2 { font-size: 1.1rem; font-weight: 700; }
.content { padding: 1.25rem 1.5rem; flex: 1; }

/* ── Topbar user badge ── */
.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.topbar-user .user-name { font-weight: 600; color: var(--text); }
.topbar-user .role-badge {
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
}
.role-badge.admin { background: var(--abi-light); color: var(--abi); }
.role-badge.assistant { background: #f1f5f9; color: var(--muted); }
.logout-link { font-size: 0.75rem; color: var(--danger); text-decoration: none; }
.logout-link:hover { text-decoration: underline; }

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 0.925rem; font-weight: 700; }

/* ── Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.stat-icon {
  width: 2.75rem; height: 2.75rem;
  border-radius: 0.625rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}
.stat-icon.blue   { background: #eff6ff; }
.stat-icon.purple { background: var(--abi-light); }
.stat-icon.green  { background: #f0fdf4; }
.stat-icon.orange { background: #fff7ed; }
.stat-icon.red    { background: #fef2f2; }
.stat-icon.kb     { background: var(--kb-light); }
.stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: 0.68rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 3px; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 0.6rem 0.875rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 0.65rem 0.875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafc; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-abi    { background: var(--abi-light); color: var(--abi); }
.badge-kb     { background: var(--kb-light);  color: var(--kb-dark); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.45rem 0.875rem;
  border-radius: 0.5rem;
  font-size: 0.825rem;
  font-weight: 600;
  border: none; cursor: pointer;
  text-decoration: none;
  transition: all 0.12s;
  white-space: nowrap;
}
.btn-primary   { background: var(--abi);    color: #fff; }
.btn-primary:hover { background: var(--abi-dark); color: #fff; }
.btn-kb        { background: var(--kb);     color: #fff; }
.btn-kb:hover  { background: var(--kb-dark); }
.btn-danger-solid { background: var(--abi-red); color: #fff; }
.btn-danger-solid:hover { background: #c41920; color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger    { background: #fee2e2; color: var(--danger); }
.btn-danger:hover  { background: #fecaca; }
.btn-success   { background: #dcfce7; color: var(--success); }
.btn-success:hover { background: #bbf7d0; }
.btn-sm  { padding: 0.3rem 0.65rem; font-size: 0.75rem; }
.btn-xs  { padding: 0.2rem 0.5rem;  font-size: 0.7rem; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group.full { grid-column: 1 / -1; }
label {
  font-size: 0.72rem; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
input, select, textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--abi);
  box-shadow: 0 0 0 3px rgba(26,43,122,0.12);
}
textarea { resize: vertical; min-height: 80px; }
.form-actions {
  display: flex; gap: 0.5rem; justify-content: flex-end;
  margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border);
}

/* ── Checkbox group (subjects) ── */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 0;
}
.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: 0.4rem;
  background: #fff;
  transition: all 0.12s;
}
.checkbox-group input[type="checkbox"] {
  width: auto;
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
}
.checkbox-group input[type="checkbox"]:checked + span {
  font-weight: 700;
}
.checkbox-group label:has(input:checked) {
  background: var(--abi-light);
  border-color: var(--abi);
  color: var(--abi);
}
.subject-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.3rem;
  margin-top: 0.5rem;
}

/* ── School radio selector ── */
.school-radio-group { display: flex; gap: 0.5rem; }
.school-radio input { display: none; }
.school-radio label {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: 2px solid var(--border);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  transition: all 0.12s;
  display: flex; align-items: center; gap: 0.35rem;
}
.school-radio input:checked + label.lbl-abi { background: var(--abi-light); border-color: var(--abi); color: var(--abi); }
.school-radio input:checked + label.lbl-kb  { background: var(--kb-light);  border-color: var(--kb);  color: var(--kb-dark); }

/* ── Alerts ── */
.alert {
  padding: 0.7rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.825rem;
  font-weight: 500;
  display: flex; align-items: center; gap: 0.5rem;
}
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* ── Avatar ── */
.avatar {
  width: 2rem; height: 2rem;
  border-radius: 50%;
  background: var(--abi-light);
  color: var(--abi);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 800;
  flex-shrink: 0;
}
.avatar.kb { background: var(--kb-light); color: var(--kb-dark); }

/* ── Progress ── */
.progress { height: 5px; background: var(--border); border-radius: 9999px; overflow: hidden; min-width: 60px; }
.progress-bar        { height: 100%; background: var(--abi);    border-radius: 9999px; }
.progress-bar.green  { background: var(--success); }
.progress-bar.yellow { background: var(--warning); }
.progress-bar.red    { background: var(--danger);  }
.progress-bar.kb     { background: var(--kb); }

/* ── Attendance ── */
.att-row { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.att-row:last-child { border-bottom: none; }
.att-name { flex: 1; font-weight: 600; }
.att-options { display: flex; gap: 0.4rem; }
.att-option input { display: none; }
.att-option label {
  padding: 0.28rem 0.65rem;
  border-radius: 9999px;
  border: 1.5px solid var(--border);
  cursor: pointer;
  font-size: 0.72rem; font-weight: 700;
  color: var(--muted);
  text-transform: none; letter-spacing: 0;
  transition: all 0.12s;
}
.att-option input:checked + label.present { background: #dcfce7; border-color: #16a34a; color: #15803d; }
.att-option input:checked + label.absent  { background: #fee2e2; border-color: #dc2626; color: #b91c1c; }
.att-option input:checked + label.late    { background: #fef9c3; border-color: #ca8a04; color: #92400e; }
.att-option input:checked + label.excused { background: #dbeafe; border-color: #2563eb; color: #1d4ed8; }

/* ── Grade scores ── */
.score-row { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.score-row:last-child { border-bottom: none; }
.score-name { flex: 1; font-weight: 600; }
.score-input { width: 80px; text-align: center; }

/* ── Filter bar ── */
.filter-bar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-bar select, .filter-bar input { padding: 0.38rem 0.65rem; font-size: 0.8rem; }

/* ── Search ── */
.search-wrap { position: relative; }
.search-wrap input { padding-left: 2rem; }
.search-icon { position: absolute; left: 0.6rem; top: 50%; transform: translateY(-50%); color: var(--muted); }

/* ── Empty state ── */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty p { margin-bottom: 1rem; }

/* ── CEFR Level pills ── */
.lv-a1 { background: #f0fdf4; color: #15803d; }
.lv-a2 { background: #dcfce7; color: #166534; }
.lv-b1 { background: #dbeafe; color: #1e40af; }
.lv-b2 { background: #ede9fe; color: #6d28d9; }
.lv-c1 { background: #fef9c3; color: #854d0e; }
.lv-c2 { background: #fee2e2; color: #991b1b; }

/* ── Detail header ── */
.detail-header {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
}
.detail-avatar {
  width: 4rem; height: 4rem;
  border-radius: 50%;
  background: var(--abi-light);
  color: var(--abi);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 800;
  flex-shrink: 0;
}
.detail-avatar.kb { background: var(--kb-light); color: var(--kb-dark); }
.detail-info h1 { font-size: 1.3rem; font-weight: 800; }
.detail-info .meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.35rem; display: flex; flex-wrap: wrap; gap: 0.75rem; }
.meta-item { display: flex; align-items: center; gap: 0.3rem; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1rem; }
.tab-btn {
  padding: 0.6rem 1rem;
  font-size: 0.825rem; font-weight: 600;
  color: var(--muted);
  border: none; background: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.12s;
}
.tab-btn.active { color: var(--abi); border-bottom-color: var(--abi); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Finance summary bar ── */
.finance-bar {
  display: flex; gap: 1rem; align-items: stretch; margin-bottom: 1rem;
}
.finance-box {
  flex: 1; background: #fff; border: 1px solid var(--border);
  border-radius: 0.75rem; padding: 1rem 1.25rem;
}
.finance-box .label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.3rem; }
.finance-box .value { font-size: 1.5rem; font-weight: 800; }
.finance-box.revenue .value { color: var(--success); }
.finance-box.expense .value { color: var(--danger); }
.finance-box.net     .value { color: var(--abi); }

/* ── Due payments card ── */
.due-card {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.due-card .card-title { color: #92400e; }

/* ── DZD tag ── */
.dzd { font-size: 0.65rem; font-weight: 700; color: var(--muted); margin-left: 2px; vertical-align: super; }

/* ── Utility ── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-4 { margin-top: 1rem; }
.text-muted  { color: var(--muted); }
.text-sm     { font-size: 0.8rem; }
.text-xs     { font-size: 0.72rem; }
.font-bold   { font-weight: 700; }
.font-semibold { font-weight: 600; }
.truncate    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full      { width: 100%; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.danger  { color: var(--danger); }
.success { color: var(--success); }
a { color: var(--abi); }
a:hover { text-decoration: underline; }

/* ── Enrollment form payment section ── */
.payment-section {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  background: #f8fafc;
}
.payment-section .payment-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.payment-section .payment-row:last-child { margin-bottom: 0; }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0d1b4b 0%, #1a2b7a 60%, #e31e24 100%);
}
.login-box {
  background: #fff;
  border-radius: 1rem;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-logo .logo-icon { font-size: 2.5rem; }
.login-logo h1 { font-size: 1.4rem; font-weight: 900; color: var(--abi); margin-top: 0.3rem; }
.login-logo p { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }
.login-box .form-group { margin-bottom: 1rem; }
.login-box label { display: block; margin-bottom: 0.3rem; }
.login-box input { width: 100%; }
.login-submit {
  width: 100%;
  padding: 0.65rem;
  font-size: 0.9rem;
  background: var(--abi);
  color: #fff;
  border: none;
  border-radius: 0.5rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: background 0.12s;
}
.login-submit:hover { background: var(--abi-dark); }
.login-accent { display: block; height: 4px; background: var(--abi-red); border-radius: 0 0 1rem 1rem; margin: 0 -2rem -2.5rem; }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2     { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .sidebar { display: none; }
  .main    { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-grid  { grid-template-columns: 1fr; }
}

/* ── Print styles ── */
@media print {
  .sidebar, .topbar, .btn, .btn-primary, .btn-secondary, .btn-danger,
  .btn-success, .btn-kb, .btn-danger-solid, .no-print { display: none !important; }
  .main { margin-left: 0 !important; }
  .print-area { display: block !important; }
  body { background: #fff; font-size: 12pt; }
}
