:root {
  --primary: #1e5f74;
  --primary-dark: #164a5b;
  --accent: #f2a154;
  --bg: #f6f8f9;
  --card-bg: #ffffff;
  --text: #222;
  --muted: #667;
  --border: #e1e6e8;
  --success: #2e8b57;
  --danger: #c0392b;
  --pending: #b8860b;
  --radius: 10px;
  --topbar-h: 58px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

img { max-width: 100%; }

/* ---------- Topbar / nav ---------- */

.topbar {
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
  min-height: var(--topbar-h);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar a { color: #fff; text-decoration: none; }
.topbar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  padding: 12px 0;
  min-width: 0;
}
.topbar .brand span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.topbar nav a {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.92rem;
  white-space: nowrap;
}
.topbar nav a:hover,
.topbar nav a:focus-visible { background: rgba(255,255,255,0.14); }

/* hamburger toggle — CSS only, no script */
.nav-toggle { display: none; }
.nav-toggle-label {
  display: none;
  cursor: pointer;
  padding: 10px;
  margin-left: auto;
}
.nav-toggle-label span,
.nav-toggle-label span::before,
.nav-toggle-label span::after {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  position: relative;
  transition: transform .15s ease, opacity .15s ease;
}
.nav-toggle-label span::before,
.nav-toggle-label span::after { content: ""; position: absolute; }
.nav-toggle-label span::before { top: -7px; }
.nav-toggle-label span::after { top: 7px; }

/* ---------- Layout ---------- */

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  transition: box-shadow .15s ease, transform .15s ease;
}

.card h2, .card h3 { margin-top: 0; }
.card h2 { font-size: 1.15rem; }
.card h3 { font-size: 1.6rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 11px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  text-decoration: none;
  text-align: center;
  min-height: 42px;
  line-height: 1.2;
}

.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--accent); color: #222; }
.btn.danger { background: var(--danger); }
.btn.outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- Forms ---------- */

label { display: block; margin: 12px 0 6px; font-weight: 600; font-size: 0.9rem; }
input, select, textarea {
  width: 100%;
  padding: 11px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,95,116,0.12);
}

.password-wrap { position: relative; }
.password-wrap .toggle-eye {
  position: absolute; right: 10px; top: 38px; cursor: pointer; font-size: 0.85rem; color: var(--muted);
}

/* ---------- Tables ---------- */

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; min-width: 480px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { background: #f0f3f4; }

/* ---------- Badges / alerts ---------- */

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.78rem; font-weight: 600; }
.badge.pending { background: #fdf0d5; color: var(--pending); }
.badge.approved, .badge.active { background: #e2f3e8; color: var(--success); }
.badge.rejected, .badge.expired { background: #fbe4e1; color: var(--danger); }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.alert.success { background: #e2f3e8; color: var(--success); }
.alert.error { background: #fbe4e1; color: var(--danger); }
.alert.info { background: #e6f0f4; color: var(--primary-dark); }

.muted { color: var(--muted); font-size: 0.85rem; }

.spinner {
  display: none;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Hero (landing) ---------- */

.hero {
  text-align: center;
  padding: 56px 16px 44px;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
}
.hero h1 { font-size: 1.8rem; margin-bottom: 12px; max-width: 680px; margin-left: auto; margin-right: auto; }
.hero p { color: rgba(255,255,255,0.85); max-width: 560px; margin: 0 auto 26px; }

.landing-actions { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.landing-actions .btn.outline { color: #fff; border-color: rgba(255,255,255,0.6); }
.landing-actions .btn.outline:hover { background: rgba(255,255,255,0.12); }

/* landing feature cards get a touch more life than dashboard cards */
.container .card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.06); transform: translateY(-2px); }

footer { text-align: center; padding: 24px; color: var(--muted); font-size: 0.82rem; }
footer a { color: var(--primary); text-decoration: none; }
footer a:hover { text-decoration: underline; }
footer .credit { display: block; margin-top: 4px; font-size: 0.78rem; color: #99a3a8; }
footer .credit a { color: #99a3a8; }
footer .admin-link {
  display: block;
  margin-top: 10px;
  font-size: 0.7rem;
  color: #c3cbce;
}
footer .admin-link a { color: #c3cbce; }
footer .admin-link a:hover { color: var(--muted); }

/* ---------- Setup pages: grade tabs & accordion ---------- */

.grade-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin: 14px 0 4px;
  -webkit-overflow-scrolling: touch;
}
.grade-tab {
  flex: 0 0 auto;
  background: #eef2f3;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.grade-tab:hover { background: #e4e9eb; }
.grade-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Info disclosure / collapsible sections ---------- */

.info-toggle {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
  list-style: none;
  padding: 2px 0;
}
.info-toggle::-webkit-details-marker { display: none; }
.info-toggle::before { content: "ℹ️  "; }
details[open] .info-toggle::before { content: "ℹ️  "; }
.info-body { margin-top: 10px; }
.info-body p:first-child { margin-top: 0; }

.stream-toggle {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary-dark);
  list-style: none;
  padding: 6px 0;
}
.stream-toggle::-webkit-details-marker { display: none; }
.stream-toggle::before { content: "▸ "; }
details[open] > .stream-toggle::before { content: "▾ "; }

/* ---------- Terms table ---------- */

tr.current-row { background: #f4faf6; }
tr.current-row td:first-child { border-left: 3px solid var(--success); }

.grade-panel { display: none; }
.grade-panel.active { display: block; }

.stream-block { border-left: 3px solid var(--primary); padding-left: 14px; margin: 14px 0; }
.stream-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; }
.apply-btn { font-size: 0.75rem; padding: 4px 10px; }

@media (max-width: 640px) {
  .subject-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

.subject-picker { margin: 10px 0 16px; }
.subject-search-input { margin-bottom: 10px; }
.subject-group { margin-bottom: 12px; }
.subject-group-title {
  font-weight: 700; font-size: 0.8rem; color: var(--primary-dark);
  margin: 10px 0 6px; text-transform: uppercase; letter-spacing: .3px;
}
.subject-tile {
  display: flex; align-items: center; gap: 8px;
  border: 2px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 6px; cursor: pointer; transition: border-color .15s;
}
.subject-tile.checked { border-color: var(--success); background: #f4faf6; }
.subject-tile input { width: 18px; height: 18px; margin: 0; flex-shrink: 0; }
.subject-tile span { font-size: 0.92rem; }

/* Bounded scroll box for long subject/stream pickers — keeps the page
   itself short even when the list of options is long. */
.picker-scroll {
  max-height: 420px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfc;
}
.picker-scroll .subject-search-input {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fbfcfc;
}

/* ---------- Responsive breakpoints ---------- */

@media (max-width: 700px) {
  .container { padding: 16px 14px 32px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .card { padding: 15px; }
}

@media (max-width: 640px) {
  .nav-toggle-label { display: flex; flex-direction: column; justify-content: center; }
  .topbar nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 6px 0 12px;
  }
  .topbar nav a { padding: 12px 8px; border-radius: 6px; }
  .nav-toggle:checked ~ nav { display: flex; }
  .nav-toggle:checked ~ .nav-toggle-label span { background: transparent; }
  .nav-toggle:checked ~ .nav-toggle-label span::before { top: 0; transform: rotate(45deg); }
  .nav-toggle:checked ~ .nav-toggle-label span::after { top: 0; transform: rotate(-45deg); }

  .btn-row { flex-direction: column; }
  .btn-row .btn { width: 100%; }
  .btn { width: 100%; }
  .landing-actions .btn { width: auto; }
}

@media (max-width: 420px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .card h3 { font-size: 1.4rem; }
}