:root {
  --bg: #eef1f8;
  --surface: #ffffff;
  --ink: #16223a;
  --muted: #687793;
  --line: #e4e8f1;
  --brand: #4338ca;
  --brand-deep: #312e81;
  --brand-soft: #eef0fe;
  --present: #16a34a;
  --late: #d97706;
  --absent: #dc2626;
  --shadow: 0 1px 2px rgba(22, 34, 58, .06), 0 8px 24px rgba(22, 34, 58, .06);
  --radius: 14px;
  --font-size: 15px;
  --font-body: "Heebo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { overflow-x: hidden; } /* iOS Safari respects this; body alone is insufficient */

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--font-size);
  line-height: 1.55;
  overflow-x: hidden; /* fallback for other browsers */
}

a { color: inherit; }

/* ---------- Header ---------- */
.topbar {
  background: linear-gradient(120deg, var(--brand-deep), var(--brand));
  color: #fff;
  overflow: hidden; /* prevents topbar content from widening the page on mobile */
}
.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: rgba(255,255,255,.14);
  display: grid; place-items: center;
  font-size: 21px;
  flex: none;
}
.brand-text h1 {
  font-family: "Rubik", system-ui, sans-serif;
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -.01em;
}
.brand-text p { margin: 0; font-size: 13px; opacity: .8; }

.topbar-user {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}
.user-name { font-size: 14px; font-weight: 600; }
.logout-link {
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  background: rgba(255,255,255,.14);
  padding: 7px 14px;
  border-radius: 9px;
}
.logout-link:hover { background: rgba(255,255,255,.24); }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand) 60%, var(--brand));
  padding: 24px;
}
.login-card {
  background: var(--surface);
  width: 100%;
  max-width: 380px;
  padding: 36px 32px 32px;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(20, 20, 60, .35);
  text-align: center;
}
.login-mark {
  width: 56px; height: 56px;
  margin: 0 auto 16px;
  border-radius: 15px;
  background: var(--brand-soft);
  display: grid; place-items: center;
  font-size: 28px;
}
.login-title {
  font-family: "Rubik", system-ui, sans-serif;
  font-size: 22px; font-weight: 600; margin: 0 0 4px;
}
.login-sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.login-card .field { text-align: right; }
.login-error {
  background: #fef2f2;
  color: var(--absent);
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 18px;
}
.login-btn { width: 100%; margin-top: 22px; padding: 12px; font-size: 16px; }

/* ---------- Layout ---------- */
.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.section-head h2 {
  font-family: "Rubik", system-ui, sans-serif;
  font-size: 24px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -.015em;
}
.count-pill {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 999px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Search ---------- */
.searchbar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}
.searchbar input {
  flex: 1;
}

/* ---------- Table ---------- */
.table-card { padding: 6px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 14px; text-align: right; white-space: nowrap; }
thead th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
  border-bottom: 1px solid var(--line);
}
tbody tr { border-bottom: 1px solid var(--line); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8f9fd; }
.name-cell { font-weight: 600; }
.class-tag {
  display: inline-block;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-weight: 600;
  font-size: 12.5px;
  padding: 3px 10px;
  border-radius: 8px;
}
.muted { color: var(--muted); }
.dash { color: #c2cadb; }

/* ---------- Buttons & forms ---------- */
input, select {
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--brand-deep); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 8px 14px;
  font-size: 13px;
}
.btn-ghost:hover { background: #f1f3f9; color: var(--ink); }
.link-remove {
  background: none; border: none; cursor: pointer;
  color: var(--absent); font-size: 13px; font-weight: 600; font-family: inherit;
  opacity: .65;
}
.link-remove:hover { opacity: 1; }

/* ---------- Add form ---------- */
.add-card { padding: 22px; margin-top: 22px; }
.add-card h3 {
  font-family: "Rubik", system-ui, sans-serif;
  margin: 0 0 16px; font-size: 17px; font-weight: 600;
}
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}
.form-actions { margin-top: 18px; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

/* ---------- Sub navigation ---------- */
.subnav {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.subnav-inner {
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  gap: 3px;
}
.navlink {
  padding: 9px 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2.5px solid transparent;
  white-space: nowrap;
}
.navlink:hover { color: var(--ink); }
.navlink.active { color: var(--brand); border-bottom-color: var(--brand); }
.nav-sep {
  display: inline-block;
  width: 1px;
  height: 14px;
  background: var(--line);
  align-self: center;
  margin: 0 2px;
  flex-shrink: 0;
}

/* ---------- Attendance picker ---------- */
.picker {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.picker .field { flex: 1; min-width: 150px; }
.picker .btn { flex: none; }

.save-banner {
  background: #f0fdf4;
  color: var(--present);
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  margin-bottom: 18px;
}

.roll-actions { margin-bottom: 12px; }
.roll-card { padding: 6px; }

.roll-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.roll-row:last-child { border-bottom: none; }
.roll-name { font-weight: 600; font-size: 15.5px; }

/* segmented control */
.seg { display: inline-flex; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); flex: none; }
.seg input { display: none; }
.seg label {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  background: #fff;
  border-inline-start: 1px solid var(--line);
  transition: background .12s, color .12s;
}
.seg label:first-of-type { border-inline-start: none; }
.seg label:hover { background: #f4f6fb; }
.seg input:checked + label.seg-present { background: var(--present); color: #fff; }
.seg input:checked + label.seg-late    { background: var(--late);    color: #fff; }
.seg input:checked + label.seg-absent  { background: var(--absent);  color: #fff; }

/* save bar */
.save-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.save-bar .btn { padding: 12px 28px; font-size: 16px; }
.save-hint { color: var(--muted); font-size: 13px; }

@media (max-width: 560px) {
  .roll-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .seg { width: 100%; }
  .seg label { flex: 1; text-align: center; }
}

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .wrap { padding: 20px 16px 56px; }
}

/* ═══════════════════════════════════════
   RESPONSIVE — mobile-first improvements
   ══════════════════════════════════════ */

/* ── Header on mobile ── */
@media (max-width: 600px) {
  .topbar-inner { padding: 12px 16px; gap: 10px; }
  .brand-text h1 { font-size: 16px; }
  .brand-text p  { display: none; }
  .user-name     { display: none; }
  .logout-link   { padding: 6px 12px; font-size: 12px; }
}

/* ── Sub-navigation: overflow fallback (visible scrollbar on desktop, hidden on mobile) ── */
.subnav-inner {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap;
}

@media (max-width: 600px) {
  .subnav-inner { padding: 0 8px; gap: 1px; scrollbar-width: none; }
  .subnav-inner::-webkit-scrollbar { display: none; }
  .navlink { padding: 8px 7px; font-size: 12px; }
}

/* ── Tables: always scrollable ── */
.table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Section head on narrow screens ── */
@media (max-width: 600px) {
  .section-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .section-head h2 { font-size: 20px; }
}

/* ── Buttons: full-width on very small screens when stacked ── */
@media (max-width: 400px) {
  .save-bar { flex-direction: column; }
  .save-bar .btn { width: 100%; text-align: center; }
}

/* ── Picker form on mobile (attendance date/class selector) ── */
@media (max-width: 540px) {
  .picker { flex-direction: column; gap: 10px; }
  .picker .field { min-width: unset; width: 100%; }
  .picker .btn   { width: 100%; }
}

/* ── Cards: full-width padding on mobile ── */
@media (max-width: 480px) {
  .card { border-radius: 10px; }
  .add-card { padding: 16px; }
  .login-card { padding: 28px 20px 24px; }
}

/* ── Roll actions (bulk buttons) on mobile ── */
@media (max-width: 540px) {
  .roll-actions { flex-direction: column !important; }
  .roll-actions button { width: 100%; }
}

/* ════════════════════════════════════════════════════════════════
   HAMBURGER / MOBILE NAV DRAWER
   ════════════════════════════════════════════════════════════════ */

/* Hidden on desktop */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: rgba(255,255,255,.14);
  border: none;
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  margin-inline-start: auto;
  flex-shrink: 0;
}
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Mobile nav drawer */
.mobile-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px 12px;
}
.mobile-nav-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mobile-nav-inner .navlink {
  padding: 11px 12px;
  border-bottom: none;
  border-radius: 9px;
  font-size: 14px;
}
.mobile-nav-inner .navlink:hover,
.mobile-nav-inner .navlink.active {
  background: var(--brand-soft);
  color: var(--brand);
  border-bottom: none;
}
.mobile-nav-inner .nav-sep {
  width: 100%;
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

/* footer of the mobile drawer — shows user name + logout */
.mobile-nav-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 2px;
  border-top: 1px solid var(--line);
  margin-top: 6px;
}
.mobile-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mobile-logout-btn {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--absent);
  text-decoration: none;
  padding: 6px 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fef2f2;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .hamburger { display: flex; }
  /* hide desktop subnav — hamburger drawer replaces it */
  .subnav { display: none; }
  /* hide user block from topbar — logout moves into the drawer */
  .topbar-user { display: none; }
  /* allow brand text to shrink on narrow screens without pushing siblings off-screen */
  .brand-text { flex: 1; min-width: 0; }
  .brand-text h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ════════════════════════════════════════════════════════════════
   TOUCH TARGETS — minimum 44px height on interactive elements
   ════════════════════════════════════════════════════════════════ */
.btn { min-height: 44px; }
input, select { min-height: 44px; }

/* ════════════════════════════════════════════════════════════════
   INLINE GRID OVERRIDE — force 1-col on mobile
   (students.html uses inline style="grid-template-columns:repeat(3,1fr)")
   ════════════════════════════════════════════════════════════════ */
@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr !important; }
}

/* ════════════════════════════════════════════════════════════════
   ADMIN TEACHERS — action column: remove hardcoded width
   ════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  th[style*="width:200px"],
  th[style*="width: 200px"] { width: auto !important; }
}

/* ════════════════════════════════════════════════════════════════
   REPORTS PAGE — filter bar & quick-range buttons
   ════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .quick-ranges { flex-wrap: wrap !important; }
  .quick-ranges .btn { font-size: 12px; padding: 8px 10px; min-height: 40px; }
}

/* ════════════════════════════════════════════════════════════════
   SUSPENSION FORM (students.html inline form)
   ════════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .suspend-form { flex-direction: column !important; }
  .suspend-form .field { min-width: unset !important; width: 100% !important; }
  .suspend-form .btn  { width: 100%; }
}

/* ════════════════════════════════════════════════════════════════
   SECTION HEAD ACTION ROW (flex row with buttons)
   ════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .section-head-actions { flex-direction: column !important; align-items: stretch !important; }
  .section-head-actions .btn,
  .section-head-actions a.btn { width: 100%; text-align: center; }
}

/* ════════════════════════════════════════════════════════════════
   STUDENT DETAIL / EDIT PAGE — keep 2-col on tablet, 1-col on phone
   ════════════════════════════════════════════════════════════════ */
@media (max-width: 520px) {
  .grid-2 { grid-template-columns: 1fr !important; }
}

/* ── Flash messages ── */
.flash {
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-weight: 600;
  font-size: 14px;
}
.flash-ok  { background: #f0fdf4; color: var(--present); border: 1px solid #bbf7d0; }
.flash-err { background: #fef2f2; color: var(--absent);  border: 1px solid #fecaca; }

/* ── btn-sm and btn-danger (used in admin pages) ── */
.btn-sm { font-size: 13px; padding: 6px 14px; }
.btn-danger {
  background: #fee2e2;
  color: var(--absent);
  border: 1px solid #fecaca;
}
.btn-danger:hover { background: #fecaca; }

/* ── Error banner ── */
.error-banner {
  background: #fef2f2;
  color: var(--absent);
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 18px;
}
