:root {
  --primary: #1a6b3c;
  --primary-dark: #0f4526;
  --primary-light: #2d9c5a;
  --accent: #f5a623;
  --accent2: #e84040;
  --gold: #d4a017;
  --cream: #fdf8f0;
  --sidebar-bg: #0f2d1c;
  --sidebar-text: #b8d4c2;
  --sidebar-active: #1a6b3c;
  --card-shadow: 0 4px 24px rgba(26,107,60,0.10);
  --text-main: #1a2e22;
  --text-muted: #6b8c7a;
  --border: #d4e8db;
  --white: #ffffff;
  --radius: 14px;
  --transition: 0.22s cubic-bezier(.4,0,.2,1);
  /* Safe area for notched devices (phones/tablets) */
  --safe-top: env(safe-area-inset-top, 0);
  --safe-right: env(safe-area-inset-right, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-left: env(safe-area-inset-left, 0);
  /* Touch target minimum (accessibility) */
  --touch-min: 44px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
}

/* ── APP LAYOUT (post-login) ── */
.app-body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--text-main);
  min-height: 100vh;
}
.app-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  padding-top: calc(16px + var(--safe-top));
}
.app-header__inner {
  max-width: 1400px;
  margin: 0 auto;
}
.app-header__title {
  font-family: 'Playfair Display', serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 0;
}
.app-main {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ── APP NAV (top bar) ── */
.app-nav {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-nav__inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.app-nav__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--primary-dark);
}
.app-nav__logo-icon {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.app-nav__logo-icon svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}
.app-nav__logo-text {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.app-nav__links {
  display: flex;
  align-items: center;
  gap: 6px;
}
.app-nav__link {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition);
}
.app-nav__link:hover {
  color: var(--primary-dark);
  background: rgba(26,107,60,0.06);
}
.app-nav__link--active {
  color: var(--primary);
  background: rgba(26,107,60,0.1);
}
.app-nav__user {
  position: relative;
}
.app-nav__user-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--white);
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-main);
}
.app-nav__user-btn:hover {
  border-color: var(--primary-light);
  background: rgba(26,107,60,0.04);
}
.app-nav__user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
}
.app-nav__user-name {
  font-weight: 600;
  color: var(--text-main);
}
.app-nav__user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  padding: 6px;
  z-index: 200;
}
.app-nav__user-dropdown a,
.app-nav__user-dropdown button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-main);
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.app-nav__user-dropdown a:hover,
.app-nav__user-dropdown button:hover {
  background: rgba(26,107,60,0.08);
  color: var(--primary-dark);
}
.app-nav__user-dropdown .divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.app-nav__mobile-toggle {
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
}
@media (max-width: 768px) {
  .app-nav__links { display: none; }
  .app-nav__user .app-nav__user-name { display: none; }
  .app-nav__mobile-toggle { display: flex; }
}

/* ── DASHBOARD (post-login home) ── */
.dashboard-header__title {
  font-family: 'Playfair Display', serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 0;
}
.dashboard-welcome {
  max-width: 800px;
}
.dashboard-welcome__card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  margin-bottom: 28px;
}
.dashboard-welcome__heading {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 0 0 8px 0;
}
.dashboard-welcome__text {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}
.dashboard-quick__title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.dashboard-quick__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.dashboard-quick__card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 20px;
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  text-decoration: none;
  color: var(--text-main);
  transition: var(--transition);
}
.dashboard-quick__card:hover {
  border-color: var(--primary-light);
  box-shadow: 0 8px 28px rgba(26,107,60,0.12);
  transform: translateY(-2px);
}
.dashboard-quick__card--muted {
  opacity: 0.85;
}
.dashboard-quick__icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(26,107,60,0.1);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.dashboard-quick__card--muted .dashboard-quick__icon {
  background: rgba(107,140,122,0.15);
  color: var(--text-muted);
}
.dashboard-quick__label {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 2px;
}
.dashboard-quick__desc {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ── SIDEBAR ── */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 260px;
  background: var(--sidebar-bg);
  z-index: 1000;
  display: flex; flex-direction: column;
  transition: var(--transition);
  box-shadow: 4px 0 24px rgba(0,0,0,0.18);
}
#sidebar .brand {
  padding: 26px 24px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
#sidebar .brand h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.35rem; font-weight: 900;
  color: var(--white); letter-spacing: -0.5px;
  line-height: 1.1;
}
#sidebar .brand p { color: #7fa98a; font-size: 0.72rem; margin-top: 4px; letter-spacing: 1.5px; text-transform: uppercase; }
#sidebar .brand .flag { font-size: 1.3rem; }
#sidebar nav { flex: 1; padding: 14px 0; overflow-y: auto; }
#sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 24px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.88rem; font-weight: 500;
  border-left: 3px solid transparent;
  transition: var(--transition);
  cursor: pointer;
}
#sidebar nav a:hover { background: rgba(255,255,255,0.05); color: #fff; }
#sidebar nav a.active {
  background: rgba(45,156,90,0.18);
  color: #fff;
  border-left-color: var(--accent);
}
#sidebar nav a i { width: 20px; text-align: center; font-size: 0.95rem; }
#sidebar .nav-section {
  padding: 12px 24px 4px;
  font-size: 0.63rem; letter-spacing: 2px; text-transform: uppercase;
  color: #4a6b55;
  font-weight: 600;
}
#sidebar .sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,0.07);
  color: #4a6b55; font-size: 0.75rem;
}

/* ── MAIN CONTENT ── */
#main {
  margin-left: 260px;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* ── TOPBAR ── */
#topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 14px 32px;
  padding-top: calc(14px + var(--safe-top));
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}
.topbar-left {
  display: flex; align-items: center; gap: 14px;
}
.topbar-title {
  font-family: 'Playfair Display', serif; font-size: 1.3rem; font-weight: 700; color: var(--primary-dark);
  margin: 0;
}
.topbar-right { display: flex; align-items: center; gap: 18px; }
.topbar-right .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem; cursor: pointer;
}
.topbar-right .badge-notif {
  background: var(--accent2); color: #fff; border-radius: 50%;
  width: 20px; height: 20px; font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center;
  position: absolute; top: -4px; right: -4px;
}
.notif-wrap { position: relative; cursor: pointer; color: var(--text-muted); }

/* Hamburger button (hidden on desktop) */
.hamburger-btn {
  display: none;
  flex-direction: column; justify-content: center; gap: 5px;
  min-width: var(--touch-min); min-height: var(--touch-min);
  width: 44px; height: 44px;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
  color: var(--primary-dark);
}
.hamburger-btn:hover { background: rgba(26,107,60,0.08); border-color: var(--primary); }
.hamburger-line {
  display: block; height: 2px; background: currentColor; border-radius: 1px;
  transition: var(--transition);
}
.hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(2) {
  opacity: 0;
}
.hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Search */
.search-wrap { position: relative; display: flex; align-items: center; }
.search-toggle {
  width: 40px; height: 40px;
  display: none; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-muted);
  cursor: pointer; transition: var(--transition);
}
.search-toggle:hover { color: var(--primary); border-color: var(--primary); background: rgba(26,107,60,0.06); }
.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--cream); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 8px 14px;
  min-width: 220px; transition: var(--transition);
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,107,60,0.1); }
.search-box-icon { color: var(--text-muted); font-size: 0.9rem; flex-shrink: 0; }
.search-input {
  border: none; background: transparent; flex: 1;
  font-size: 0.9rem; font-family: 'DM Sans', sans-serif;
  color: var(--text-main); outline: none;
}
.search-input::placeholder { color: var(--text-muted); }
.search-close {
  display: none;
  width: 28px; height: 28px; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 6px;
  color: var(--text-muted); cursor: pointer; transition: var(--transition);
}
.search-close:hover { background: rgba(0,0,0,0.06); color: var(--text-main); }

/* ── CONTENT AREA ── */
#content { padding: 30px 32px; flex: 1; }

/* ── CARDS ── */
.stat-card {
  background: var(--white); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  position: relative; overflow: hidden;
  transition: var(--transition);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 8px 32px rgba(26,107,60,0.15); }
.stat-card .stat-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; margin-bottom: 14px;
}
.stat-card .stat-value { font-family: 'Playfair Display', serif; font-size: 2rem; font-weight: 900; color: var(--text-main); }
.stat-card .stat-label { color: var(--text-muted); font-size: 0.82rem; margin-top: 2px; }
.stat-card .stat-change { font-size: 0.75rem; margin-top: 8px; }
.stat-card .stat-change.up { color: var(--primary-light); }
.stat-card .stat-change.down { color: var(--accent2); }
.stat-card::before {
  content: ''; position: absolute; top: -30px; right: -20px;
  width: 90px; height: 90px; border-radius: 50%;
  opacity: 0.06;
}
.stat-card.green .stat-icon { background: rgba(26,107,60,0.12); color: var(--primary); }
.stat-card.green::before { background: var(--primary); }
.stat-card.gold .stat-icon { background: rgba(245,166,35,0.12); color: var(--gold); }
.stat-card.gold::before { background: var(--gold); }
.stat-card.red .stat-icon { background: rgba(232,64,64,0.12); color: var(--accent2); }
.stat-card.red::before { background: var(--accent2); }
.stat-card.blue .stat-icon { background: rgba(37,99,235,0.10); color: #2563eb; }
.stat-card.blue::before { background: #2563eb; }
.stat-card.purple .stat-icon { background: rgba(124,58,237,0.12); color: #7c3aed; }
.stat-card.purple::before { background: #7c3aed; }

.section-card {
  background: var(--white); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--card-shadow);
  border: 1px solid var(--border); margin-bottom: 24px;
}
.section-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem; font-weight: 700; color: var(--primary-dark);
  margin-bottom: 18px; display: flex; align-items: center; gap: 10px;
}
.section-title .badge {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.7rem; background: var(--primary); color: #fff;
  border-radius: 20px; padding: 2px 10px; font-weight: 600;
}

/* ── TABLES ── */
.table-ugandan th {
  background: var(--primary-dark); color: #fff; font-weight: 600;
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 12px 14px; border: none;
}
.table-ugandan td { padding: 11px 14px; font-size: 0.87rem; vertical-align: middle; border-color: var(--border); }
.table-ugandan tr:hover td { background: rgba(26,107,60,0.04); }

/* ── GRADE BADGES ── */
.grade-D1 { background: #1a6b3c; color: #fff; }
.grade-D2 { background: #2d9c5a; color: #fff; }
.grade-C3 { background: #5bba7c; color: #fff; }
.grade-C4 { background: #82cc8f; color: #fff; }
.grade-C5 { background: #a8d5a2; color: var(--text-main); }
.grade-C6 { background: #f5a623; color: #fff; }
.grade-P7 { background: #f97316; color: #fff; }
.grade-P8 { background: #e84040; color: #fff; }
.grade-F9 { background: #7f1d1d; color: #fff; }
.grade-badge { padding: 3px 10px; border-radius: 20px; font-size: 0.73rem; font-weight: 700; }

/* ── FORMS ── */
.form-label { font-weight: 600; font-size: 0.83rem; color: var(--text-main); margin-bottom: 5px; }
.form-control, .form-select {
  border: 1.5px solid var(--border); border-radius: 9px;
  font-size: 0.87rem; padding: 9px 13px;
  transition: var(--transition);
  font-family: 'DM Sans', sans-serif;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,107,60,0.12);
}

/* ── BUTTONS ── */
.btn-primary-ug {
  background: var(--primary); color: #fff; border: none;
  border-radius: 9px; padding: 9px 20px; font-weight: 600;
  font-size: 0.87rem; transition: var(--transition);
  font-family: 'DM Sans', sans-serif; cursor: pointer;
}
.btn-primary-ug:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; border: none; border-radius: 9px; padding: 9px 20px; font-weight: 600; font-size: 0.87rem; transition: var(--transition); cursor: pointer; }
.btn-accent:hover { background: #d4891a; }
.btn-outline-ug {
  background: transparent; border: 1.5px solid var(--primary); color: var(--primary);
  border-radius: 9px; padding: 8px 18px; font-weight: 600; font-size: 0.87rem;
  transition: var(--transition); cursor: pointer;
}
.btn-outline-ug:hover { background: var(--primary); color: #fff; }
.btn-danger-ug { background: var(--accent2); color: #fff; border: none; border-radius: 9px; padding: 8px 14px; font-size: 0.82rem; cursor: pointer; }

/* ── ATTENDANCE ── */
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.att-card {
  border: 1.5px solid var(--border); border-radius: 10px; padding: 14px;
  display: flex; align-items: center; justify-content: space-between;
  transition: var(--transition);
}
.att-card:hover { border-color: var(--primary); }
.att-name { font-size: 0.82rem; font-weight: 600; }
.att-roll { font-size: 0.72rem; color: var(--text-muted); }
.att-btns { display: flex; gap: 6px; }
.att-btn {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid; font-size: 0.75rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition); background: transparent;
}
.att-btn.present { border-color: var(--primary-light); color: var(--primary-light); }
.att-btn.present.active, .att-btn.present:hover { background: var(--primary-light); color: #fff; }
.att-btn.absent { border-color: var(--accent2); color: var(--accent2); }
.att-btn.absent.active, .att-btn.absent:hover { background: var(--accent2); color: #fff; }

/* ── TIMETABLE ── */
.timetable { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.timetable th { background: var(--primary-dark); color: #fff; text-align: center; padding: 10px; font-weight: 600; }
.timetable td { border: 1px solid var(--border); padding: 10px; text-align: center; vertical-align: top; min-width: 100px; }
.tt-period { background: var(--cream); padding: 6px 8px; border-radius: 6px; font-weight: 600; color: var(--primary-dark); }
.tt-subject { font-weight: 700; color: var(--primary-dark); }
.tt-teacher { font-size: 0.72rem; color: var(--text-muted); }
.tt-cell.math { background: rgba(26,107,60,0.07); border-left: 3px solid var(--primary); }
.tt-cell.science { background: rgba(37,99,235,0.07); border-left: 3px solid #2563eb; }
.tt-cell.english { background: rgba(245,166,35,0.07); border-left: 3px solid var(--accent); }
.tt-cell.ssa { background: rgba(168,85,247,0.07); border-left: 3px solid #9333ea; }
.tt-cell.ire { background: rgba(232,64,64,0.07); border-left: 3px solid var(--accent2); }
.tt-cell.break { background: #f3f4f6; color: var(--text-muted); font-style: italic; font-size: 0.8rem; }
.tt-cell.pe { background: rgba(251,146,60,0.07); border-left: 3px solid #fb923c; }

/* ── FEE PROGRESS ── */
.fee-progress { height: 8px; border-radius: 20px; background: var(--border); overflow: hidden; }
.fee-bar { height: 100%; border-radius: 20px; transition: width 0.6s ease; }
.fee-bar.paid { background: var(--primary-light); }
.fee-bar.partial { background: var(--accent); }
.fee-bar.unpaid { background: var(--accent2); }

/* ── PERFORMANCE CHART ── */
.perf-bar-wrap { margin-bottom: 12px; }
.perf-label { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 4px; }
.perf-bar-bg { height: 10px; background: var(--border); border-radius: 20px; overflow: hidden; }
.perf-bar-fill { height: 100%; border-radius: 20px; }

/* ── MODAL ── */
.modal-header { background: var(--primary-dark); color: #fff; border-radius: var(--radius) var(--radius) 0 0; }
.modal-header .btn-close { filter: invert(1); }
.modal-content { border-radius: var(--radius); border: none; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }

/* ── PILL NAV ── */
.pill-nav { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.pill-nav button {
  padding: 7px 18px; border-radius: 20px; border: 1.5px solid var(--border);
  background: var(--white); color: var(--text-muted); font-size: 0.83rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.pill-nav button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── ALERT STRIP ── */
.alert-strip {
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  color: #fff; padding: 12px 20px; border-radius: 10px;
  display: flex; align-items: center; gap: 12px; font-size: 0.85rem;
  margin-bottom: 24px;
}

/* ── UGANDA FLAG STRIPE ── */
.ug-stripe { height: 4px; background: linear-gradient(90deg, #000 33%, #ffd700 33% 66%, #c8102e 66%); }

/* ── SIDEBAR OVERLAY (mobile) ── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,45,28,0.5);
  backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  transition: opacity var(--transition);
}
.sidebar-overlay.is-open {
  opacity: 1;
}

/* ── RESPONSIVE: DEVICES ── */
/* Tablet / small desktop */
@media (max-width: 992px) {
  .topbar-term { display: none; }
  .search-box { min-width: 180px; }
  #content { padding: 24px 24px; }
}

/* Tablet portrait / large phone */
@media (max-width: 768px) {
  .hamburger-btn { display: flex; }
  #sidebar {
    width: 280px; max-width: 85vw;
    transform: translateX(-100%);
    box-shadow: 8px 0 32px rgba(0,0,0,0.25);
    left: var(--safe-left);
  }
  #sidebar.is-open { transform: translateX(0); }
  .sidebar-overlay { display: block; pointer-events: none; }
  .sidebar-overlay.is-open { pointer-events: auto; }
  #main { margin-left: 0; }
  #topbar {
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
    gap: 10px;
  }
  .topbar-left { flex: 1; min-width: 0; gap: 10px; }
  .topbar-title {
    font-size: 1.05rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar-right { gap: 8px; flex-shrink: 0; }
  #content {
    padding: 20px 16px;
    padding-bottom: calc(20px + var(--safe-bottom));
  }
  .section-card { padding: 18px; }
  .stat-card { padding: 18px; }
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-ugandan { font-size: 0.8rem; }
  .table-ugandan th, .table-ugandan td { padding: 10px 12px; }
  .att-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .att-btn { width: 36px; height: 36px; min-width: var(--touch-min); min-height: var(--touch-min); }
  .pill-nav { gap: 6px; margin-bottom: 16px; }
  .pill-nav button { padding: 10px 16px; min-height: var(--touch-min); }

  /* Mobile search: pill expands to full bar on tap */
  .search-wrap { position: relative; }
  .search-toggle { display: none; }
  .search-box {
    position: absolute; top: 50%; right: 0; transform: translateY(-50%);
    width: 44px; min-width: var(--touch-min); height: 44px; padding: 0;
    border-radius: 22px; overflow: hidden;
    z-index: 15; cursor: pointer;
  }
  .search-box.is-expanded { cursor: default; }
  .search-box .search-box-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); }
  .search-box .search-input {
    width: 0; min-width: 0; padding: 0; opacity: 0;
    padding-left: 44px; cursor: pointer;
  }
  .search-box.is-expanded .search-input { cursor: text; }
  .search-box .search-close {
    display: flex; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    min-width: var(--touch-min); min-height: var(--touch-min);
  }
  .search-box.is-expanded {
    width: calc(100vw - 80px - var(--safe-left) - var(--safe-right));
    max-width: 280px; min-width: 0;
    border-radius: 12px; padding: 0 44px 0 44px; height: 48px;
  }
  .search-box.is-expanded .search-input { width: 100%; min-width: 0; opacity: 1; padding-left: 8px; }
  .search-box.is-expanded .search-box-icon { left: 12px; }
  .search-box.is-expanded .search-close { display: flex; }
  .modal-dialog { margin: calc(var(--safe-top) + 0.5rem) 0.5rem 0.5rem; max-width: calc(100vw - 1rem - var(--safe-left) - var(--safe-right)); }
  .modal-content { border-radius: 12px; }
}

/* Medium phone */
@media (max-width: 576px) {
  #topbar { padding: 10px 12px; padding-top: calc(10px + var(--safe-top)); }
  .topbar-title { font-size: 1rem; }
  #content { padding: 16px 12px; padding-bottom: calc(16px + var(--safe-bottom)); }
  .section-card { padding: 16px; margin-bottom: 16px; }
  .stat-card { padding: 16px; }
  .stat-card .stat-value { font-size: 1.65rem; }
  .stat-card .stat-icon { width: 44px; height: 44px; font-size: 1.2rem; }
  .section-title { font-size: 1rem; margin-bottom: 14px; }
  .btn-primary-ug, .btn-outline-ug, .btn-accent { padding: 10px 18px; min-height: var(--touch-min); }
  .form-control, .form-select { padding: 12px 14px; min-height: var(--touch-min); font-size: 16px; }
  .timetable { font-size: 0.75rem; }
  .timetable th, .timetable td { padding: 8px 6px; min-width: 70px; }
  .cal-day { font-size: 0.75rem; }
  .cal-header-day { font-size: 0.65rem; }
  .att-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .search-box.is-expanded { width: calc(100vw - 56px - var(--safe-left) - var(--safe-right)); max-width: none; }
  .modal-dialog { margin: var(--safe-top) 0 0; max-width: 100%; }
  .modal-content { border-radius: 12px 12px 0 0; min-height: calc(100vh - var(--safe-top) - var(--safe-bottom)); }
}

/* Small phone */
@media (max-width: 480px) {
  #sidebar { width: 100%; max-width: 100%; }
  .topbar-title { font-size: 0.95rem; }
  .topbar-right .avatar { width: 36px; height: 36px; font-size: 0.8rem; }
  #content { padding: 14px 12px; padding-bottom: calc(14px + var(--safe-bottom)); }
  .stat-card .stat-value { font-size: 1.5rem; }
  .grade-badge { padding: 4px 8px; font-size: 0.7rem; }
  .tag { font-size: 0.68rem; padding: 3px 8px; }
  .alert-strip { padding: 10px 14px; font-size: 0.8rem; flex-wrap: wrap; }
  .report-header, .report-body { padding: 12px 14px; }
  .report-header h2 { font-size: 1rem; }
  .perf-label { font-size: 0.78rem; }
  .search-box.is-expanded { width: calc(100vw - 48px - var(--safe-left) - var(--safe-right)); }
}

/* Extra small / compact phone */
@media (max-width: 400px) {
  #topbar { padding: 8px 10px; padding-top: calc(8px + var(--safe-top)); gap: 6px; }
  .topbar-left { gap: 8px; }
  .hamburger-btn { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
  .topbar-title { font-size: 0.9rem; }
  #content { padding: 12px 10px; padding-bottom: calc(12px + var(--safe-bottom)); }
  .section-card { padding: 14px; margin-bottom: 12px; }
  .stat-card { padding: 14px; }
  .stat-card .stat-value { font-size: 1.35rem; }
  .stat-card .stat-icon { width: 40px; height: 40px; font-size: 1.1rem; }
  .att-grid { grid-template-columns: 1fr; }
  .att-card { padding: 12px; }
  .pill-nav button { padding: 8px 12px; font-size: 0.8rem; }
  .search-box { width: 40px; min-width: 40px; height: 40px; }
  .search-box.is-expanded { height: 44px; width: calc(100vw - 40px - var(--safe-left) - var(--safe-right)); }
}

/* Very compact (e.g. iPhone SE, small Android) */
@media (max-width: 360px) {
  .topbar-title { font-size: 0.85rem; }
  .section-title { font-size: 0.95rem; }
  .stat-card .stat-value { font-size: 1.25rem; }
  .table-ugandan th, .table-ugandan td { padding: 8px 6px; font-size: 0.75rem; }
}

/* Landscape phone: reduce vertical padding, keep touch targets */
@media (max-width: 768px) and (max-height: 420px) {
  #topbar { padding-top: calc(8px + var(--safe-top)); }
  #content { padding-top: 12px; padding-bottom: calc(12px + var(--safe-bottom)); }
  .section-card { padding: 12px; margin-bottom: 12px; }
  .stat-card { padding: 12px; }
}

/* Tablet: show sidebar as overlay but use more horizontal space */
@media (min-width: 769px) and (max-width: 992px) {
  .hamburger-btn { display: flex; }
  #sidebar {
    width: 260px;
    transform: translateX(-100%);
    box-shadow: 8px 0 32px rgba(0,0,0,0.2);
  }
  #sidebar.is-open { transform: translateX(0); }
  .sidebar-overlay { display: block; pointer-events: none; }
  .sidebar-overlay.is-open { pointer-events: auto; }
  #main { margin-left: 0; }
}

/* ── ANIMATIONS ── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ── CALENDAR ── */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; font-size: 0.82rem; font-weight: 500; cursor: pointer;
  transition: var(--transition);
}
.cal-day:hover { background: rgba(26,107,60,0.1); }
.cal-day.today { background: var(--primary); color: #fff; font-weight: 700; }
.cal-day.event { position: relative; }
.cal-day.event::after { content: ''; width: 5px; height: 5px; background: var(--accent); border-radius: 50%; position: absolute; bottom: 4px; right: 4px; }
.cal-day.holiday { color: var(--accent2); font-weight: 700; }
.cal-header-day { text-align: center; font-size: 0.72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; padding-bottom: 6px; }

/* ── REPORT CARD ── */
.report-card-preview {
  border: 2px solid var(--primary);
  border-radius: 12px; overflow: hidden;
  font-size: 0.83rem;
}
.report-header {
  background: var(--primary-dark); color: #fff; padding: 16px 20px;
  text-align: center;
}
.report-header h2 { font-family: 'Playfair Display', serif; font-size: 1.15rem; }
.report-body { padding: 16px 20px; }
.report-grade-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.report-grade-row:last-child { border-bottom: none; }

/* TAG */
.tag { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.tag-green { background: rgba(26,107,60,0.12); color: var(--primary); }
.tag-gold { background: rgba(245,166,35,0.15); color: #9a6c00; }
.tag-red { background: rgba(232,64,64,0.12); color: var(--accent2); }
.tag-blue { background: rgba(37,99,235,0.10); color: #1d4ed8; }

/* ── AUTH PAGES (Login, Register, etc.) ── */
.auth-page {
  font-family: 'DM Sans', sans-serif;
  min-height: 100vh;
  color: var(--text-main);
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  position: relative;
  overflow-x: hidden;
}
.auth-page__bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(26,107,60,0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(45,156,90,0.08), transparent),
    radial-gradient(ellipse 50% 30% at 0% 80%, rgba(26,107,60,0.06), transparent);
  pointer-events: none;
}
.auth-page__inner {
  position: relative;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: inherit;
  margin-bottom: 28px;
}
.auth-brand__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  background: var(--primary);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(26,107,60,0.25);
  margin-bottom: 12px;
}
.auth-brand__svg {
  width: 36px;
  height: 36px;
  fill: #fff;
}
.auth-brand__name {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-dark);
  letter-spacing: -0.02em;
}
.auth-brand__tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 0.5px;
}
.auth-card {
  width: 100%;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  padding: 32px 28px;
}
.auth-card__header {
  margin-bottom: 24px;
}
.auth-card__title {
  font-family: 'Playfair Display', serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin: 0 0 4px 0;
}
.auth-card__subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
}
.auth-card__status {
  font-size: 0.875rem;
  color: var(--primary);
  margin-bottom: 16px;
  padding: 10px 12px;
  background: rgba(26,107,60,0.08);
  border-radius: 8px;
  border: 1px solid rgba(26,107,60,0.15);
}
.auth-card__footer {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
}
.auth-form__group {
  margin-bottom: 18px;
}
.auth-form__label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}
.auth-form__input {
  width: 100%;
  padding: 12px 14px;
  font-size: 0.95rem;
  color: var(--text-main);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: var(--transition);
  font-family: inherit;
}
.auth-form__input::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}
.auth-form__input:hover {
  border-color: var(--primary-light);
}
.auth-form__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,107,60,0.12);
}
.auth-form__error {
  font-size: 0.8rem;
  color: var(--accent2);
  margin-top: 6px;
}
.auth-form__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 22px;
}
.auth-form__checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.auth-form__checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}
.auth-form__link {
  font-size: 0.875rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}
.auth-form__link:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}
.auth-form__link--bold {
  font-weight: 600;
}
.auth-form__submit {
  width: 100%;
  padding: 14px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  letter-spacing: 0.02em;
}
.auth-form__submit:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 14px rgba(26,107,60,0.3);
}
.auth-form__submit:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(26,107,60,0.25);
}
.auth-form__submit:active {
  transform: translateY(1px);
}
