:root {
  --navy: #1b2a4a;
  --navy-dark: #121d33;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --green: #15803d;
  --green-light: #dcfce7;
  --red: #b91c1c;
  --red-light: #fee2e2;
  --amber: #b45309;
  --amber-light: #fef3c7;
  --yellow: #a16207;
  --yellow-light: #fef9c3;
  --purple: #7e22ce;
  --purple-light: #f3e8ff;
  --teal: #0f766e;
  --teal-light: #ccfbf1;
  --pink: #be185d;
  --pink-light: #fce7f3;
  --ink: #1f2937;
  --muted: #6b7280;
  --border: #e2e5eb;
  --bg: #f5f6f8;
  --card: #ffffff;
}

* { box-sizing: border-box; }

html {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
html::-webkit-scrollbar { display: none; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: #14161d;
  color: #dfe6f5;
  flex-shrink: 0;
  padding: 0 0 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar .profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 12px 6px;
  padding: 10px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  text-decoration: none;
  transition: background 0.15s;
}
.sidebar .profile-card:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.sidebar .profile-avatar-img {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; object-fit: cover;
}
.sidebar .profile-avatar {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #7e22ce);
  color: #fff; font-weight: 700; font-size: 14px;
}
.sidebar .profile-info { flex: 1; min-width: 0; }
.sidebar .profile-name {
  display: block; color: #fff; font-weight: 600; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar .profile-role { display: block; font-size: 11px; color: #4ade80; font-weight: 500; margin-top: 1px; }
.sidebar .profile-menu { color: #59668a; flex-shrink: 0; }

.sidebar nav { margin-top: 6px; padding: 0 12px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 7px 10px;
  margin: 2px 0;
  border-radius: 10px;
  color: #8996b8;
  font-size: 13px;
  font-weight: 500;
  position: relative;
  transition: background 0.15s, color 0.15s;
}
.sidebar nav a svg { flex-shrink: 0; opacity: 0.75; transition: opacity 0.15s; }
.sidebar nav a:hover { background: rgba(255,255,255,0.05); color: #fff; text-decoration: none; }
.sidebar nav a:hover svg { opacity: 1; }
.sidebar nav a.active { background: rgba(255,255,255,0.07); color: #fff; font-weight: 600; }
.sidebar nav a.active svg { opacity: 1; }
.sidebar nav a.active::before {
  content: '';
  position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 58%; border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.sidebar nav .section-label { padding: 14px 10px 3px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #55628a; font-weight: 700; }

.sidebar nav a.nav-subitem { padding-left: 32px; font-size: 12px; gap: 8px; margin-top: -1px; color: #6d7aa0; }
.sidebar nav a.nav-subitem svg { opacity: 0.6; }

.sidebar nav details.nav-dropdown summary {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; margin: 2px 0; border-radius: 10px;
  color: #8996b8; font-size: 13px; font-weight: 500;
  cursor: pointer; list-style: none;
  transition: background 0.15s, color 0.15s;
}
.sidebar nav details.nav-dropdown summary::-webkit-details-marker { display: none; }
.sidebar nav details.nav-dropdown summary::after { content: '\25BE'; font-size: 10px; color: #55628a; transition: transform 0.15s; flex-shrink: 0; }
.sidebar nav details.nav-dropdown[open] summary::after { transform: rotate(180deg); }
.sidebar nav details.nav-dropdown summary:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidebar nav details.nav-dropdown.active-group summary { color: #fff; font-weight: 600; background: rgba(255,255,255,0.05); }
.sidebar nav .nav-icon-label { display: flex; align-items: center; gap: 11px; }
.sidebar nav .nav-icon-label svg { flex-shrink: 0; opacity: 0.75; }
.sidebar nav details.nav-dropdown a { padding-left: 20px; font-size: 12.5px; gap: 8px; }

.nav-icon-badge {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 9px; flex-shrink: 0;
}
.nav-icon-badge svg { opacity: 1 !important; }
.sidebar nav a:not(.active):not(:hover) .nav-icon-badge { filter: saturate(0.7) brightness(0.85); }
.nav-icon-badge.blue   { background: rgba(37,99,235,0.18);  color: #60a5fa; }
.nav-icon-badge.green  { background: rgba(21,128,61,0.2);   color: #4ade80; }
.nav-icon-badge.orange { background: rgba(180,83,9,0.2);    color: #fb923c; }
.nav-icon-badge.purple { background: rgba(126,34,206,0.2);  color: #c084fc; }
.nav-icon-badge.teal   { background: rgba(15,118,110,0.2);  color: #2dd4bf; }
.nav-icon-badge.pink   { background: rgba(190,24,93,0.2);   color: #f472b6; }
.nav-icon-badge.yellow { background: rgba(161,98,7,0.2);    color: #facc15; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .who { font-size: 13px; color: var(--muted); }
.topbar .who strong { color: var(--ink); }
.topbar .who form { display: inline; }
.topbar-search {
  position: relative;
  display: flex; align-items: center; gap: 8px; flex: 0 1 340px;
  background: #f3f4f6; border: 1px solid transparent; border-radius: 999px;
  padding: 6px 14px; color: var(--muted); transition: border-color 0.15s, background 0.15s;
}
.topbar-search:focus-within { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.topbar-search svg { flex-shrink: 0; }
.topbar-search input {
  border: none; outline: none; background: transparent; font-size: 13px;
  font-family: inherit; color: var(--ink); width: 100%;
}

.search-dropdown {
  display: none;
  position: absolute; top: calc(100% + 8px); left: 0; width: 380px; max-width: calc(100vw - 48px);
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 28px rgba(15,23,42,0.14); max-height: 420px; overflow-y: auto;
  z-index: 50; padding: 6px 0;
}
.search-dropdown.open { display: block; }
.search-dropdown .sd-group-label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); padding: 8px 14px 4px;
}
.search-dropdown .sd-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; cursor: pointer;
  text-decoration: none; color: var(--ink);
}
a.sd-row:hover { background: #f3f4f6; text-decoration: none; }
.search-dropdown .sd-icon {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent-light); color: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.search-dropdown .sd-title { font-size: 13px; font-weight: 600; }
.search-dropdown .sd-desc { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.search-dropdown .sd-empty, .search-dropdown .sd-loading {
  padding: 16px 14px; font-size: 12.5px; color: var(--muted); text-align: center;
}
.search-dropdown .sd-viewall {
  display: block; text-align: center; padding: 10px 14px; font-size: 12.5px; font-weight: 600;
  color: var(--accent); text-decoration: none; border-top: 1px solid var(--border); margin-top: 4px;
}
.search-dropdown .sd-viewall:hover { background: #f3f4f6; text-decoration: none; }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0;
}

.content { padding: 24px; flex: 1; }

.breadcrumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--accent); text-decoration: underline; }
.breadcrumb-sep { color: #c7ccd6; }
.breadcrumb-current { color: var(--ink); font-weight: 600; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.subtitle { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 18px;
}
.card-accent-blue   { border-left: 4px solid var(--accent); }
.card-accent-green  { border-left: 4px solid var(--green); }
.card-accent-orange { border-left: 4px solid var(--amber); }
.card-accent-purple { border-left: 4px solid var(--purple); }
.card-accent-teal   { border-left: 4px solid var(--teal); }
.card-accent-pink   { border-left: 4px solid var(--pink); }
.card-accent-red    { border-left: 4px solid var(--red); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px;
}
.stat-card .num { font-size: 26px; font-weight: 700; color: var(--navy); }
.stat-card .label { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.welcome-banner {
  background: linear-gradient(135deg, var(--navy), var(--navy-dark));
  color: #fff;
  border-radius: 10px;
  padding: 22px 26px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.welcome-banner-text { min-width: 0; }
.welcome-banner h1 { color: #fff; margin: 0 0 4px; font-size: 21px; }
.welcome-banner p { margin: 0 0 12px; color: #cbd5e1; font-size: 13.5px; }
.welcome-banner .pill { background: var(--pink-light); color: var(--pink); font-size: 11px; letter-spacing: 0.04em; }
.welcome-banner-details { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; }
.welcome-banner-details span { font-size: 11.5px; color: #94a3b8; white-space: nowrap; }
.welcome-banner-details strong { color: #e2e8f0; font-weight: 600; }
.welcome-banner-avatar-img {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  border: 3px solid rgba(255,255,255,0.25);
}
.welcome-banner-avatar {
  display: flex; align-items: center; justify-content: center;
  width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,0.12); color: #fff; font-weight: 700; font-size: 24px;
  border: 3px solid rgba(255,255,255,0.25);
}
@media (max-width: 600px) {
  .welcome-banner-avatar-img, .welcome-banner-avatar { display: none; }
}

/* Purple variant - students/view.php's profile banner. Same structure as
   .welcome-banner, just a different gradient. */
.welcome-banner.purple-banner { background: linear-gradient(135deg, var(--purple), #4c1d7a); }

/* Checkable "Assign subjects" dropdown in the purple banner - a plain
   toggle button + an absolutely-positioned checkbox panel, so it pops over
   the banner instead of growing it. */
.banner-multiselect { position: relative; display: inline-block; }
.banner-multiselect-panel {
  display: none; position: absolute; top: 100%; left: 0; margin-top: 6px;
  background: #fff; border-radius: 8px; box-shadow: 0 10px 28px rgba(0,0,0,0.28);
  padding: 10px; min-width: 220px; z-index: 20;
}
.banner-multiselect-panel.open { display: block; }
.banner-multiselect-panel label {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px;
  color: var(--ink); font-size: 13px; font-weight: 400; cursor: pointer;
}

.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-tile {
  border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 10px;
  border: 1px solid transparent;
}
.stat-tile .stat-tile-icon {
  width: 34px; height: 34px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.6);
}
.stat-tile .num { font-size: 24px; font-weight: 700; line-height: 1; }
.stat-tile .label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; margin-top: 2px; opacity: 0.85; }

.stat-tile.compact { padding: 12px 16px; gap: 6px; }
.stat-tile.compact .stat-tile-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; row-gap: 4px; }
.stat-tile.compact .stat-tile-icon { width: 28px; height: 28px; }
.stat-tile.compact .num { font-size: 20px; }
.stat-tile.compact .label { margin-top: 0; }
.stat-tile.blue   { background: var(--accent-light); color: #1d4ed8; }
.stat-tile.green  { background: var(--green-light); color: var(--green); }
.stat-tile.orange { background: var(--amber-light); color: var(--amber); }
.stat-tile.purple { background: var(--purple-light); color: var(--purple); }
.stat-tile.red    { background: var(--red-light); color: var(--red); }
.stat-tile.teal   { background: var(--teal-light); color: var(--teal); }
.stat-tile.pink   { background: var(--pink-light); color: var(--pink); }

.action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; align-items: start; }
.action-grid .extra-tile { display: none; }
.action-grid.show-extra .extra-tile { display: flex; }
.class-edit-panel { display: none; margin-top: 8px; flex-direction: column; gap: 8px; width: 100%; }
.class-edit-panel.open { display: flex; }
.card-edit-toggle { cursor: pointer; color: var(--accent); background: none; border: none; padding: 0; font-size: 12px; width: 100%; text-align: left; }
.action-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px;
  color: var(--ink); text-decoration: none; transition: box-shadow 0.15s, border-color 0.15s;
}
.action-card:hover { text-decoration: none; border-color: var(--accent); box-shadow: 0 2px 10px rgba(37,99,235,0.12); }
.action-card .action-icon {
  width: 38px; height: 38px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-light); color: var(--accent);
}
.action-card .action-title { font-weight: 600; font-size: 13.5px; }
.action-card .action-desc { color: var(--muted); font-size: 12px; margin-top: -6px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #fafbfc; font-weight: 600; color: #374151; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #fafbfe; }
.table-wrap { overflow-x: auto; }

/* Cambridge papers entry table (marks/cambridge_entry.php) - kept compact so
   it fits a phone in portrait without scrolling for the common 2-3 paper case. */
.cam-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); margin: 0 0 12px; }
.cam-table th.cam-col-student { text-align: left; white-space: nowrap; }
.cam-table td.cam-col-student { text-align: left; }
.cam-table .cam-col-paper, .cam-table .cam-col-total, .cam-table .cam-col-grade { white-space: nowrap; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13.5px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { background: #1d4ed8; text-decoration: none; }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f3f4f6; }
.btn.danger { background: var(--red); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

.select-small {
  padding: 4px 8px; font-size: 12.5px; border-radius: 6px; border: 1px solid var(--border);
  font-family: inherit; background: #fff; color: var(--ink);
}

.select-modern {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding: 8px 34px 8px 14px; font-size: 13px; font-weight: 600; font-family: inherit;
  border-radius: 10px; border: 1px solid var(--border); background-color: #fff; color: var(--ink);
  cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 18px;
}
.select-modern:hover { border-color: #c7cbd3; }
.select-modern:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 100px; font-size: 11.5px; font-weight: 600; }
.pill.green { background: var(--green-light); color: var(--green); }
.pill.red { background: var(--red-light); color: var(--red); }
.pill.amber { background: var(--amber-light); color: var(--amber); }
.pill.yellow { background: var(--yellow-light); color: var(--yellow); }
.pill.gray { background: #eef0f3; color: #4b5563; }
.pill.blue { background: var(--accent-light); color: #1d4ed8; }
.pill.purple { background: var(--purple-light); color: var(--purple); }
.pill.teal { background: var(--teal-light); color: var(--teal); }
.pill.orange { background: var(--amber-light); color: var(--amber); }
.pill.pink { background: var(--pink-light); color: var(--pink); }
.pill.mark-status { display: inline-flex; align-items: center; gap: 4px; }
.pill.mark-status svg { flex-shrink: 0; }
a.pill { text-decoration: none; cursor: pointer; transition: filter 0.15s, box-shadow 0.15s, transform 0.1s; }
a.pill:hover { filter: brightness(0.93); box-shadow: 0 1px 5px rgba(0,0,0,0.18); text-decoration: none; transform: translateY(-1px); }

.teaching-summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; }
.teaching-summary::-webkit-details-marker { display: none; }
.teaching-summary::after { content: '\25BE'; font-size: 12px; color: var(--muted); margin-left: auto; transition: transform 0.15s; }
details[open] > .teaching-summary::after { transform: rotate(180deg); }
.teaching-card { position: relative; border-left: 4px solid var(--accent); padding: 12px 14px; gap: 6px; }
.teaching-card.is-class-teacher { border-left-color: var(--amber); }
.teaching-card.is-complete { background: var(--green-light); border-color: var(--green); border-left-color: var(--green); }
.teaching-card.is-complete .action-icon { background: rgba(255,255,255,0.7); color: var(--green); }
.teaching-card.is-complete .action-title,
.teaching-card.is-complete .action-desc { color: #14532d; }

.tile-status-icon {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
}
.tile-status-icon.complete { background: var(--green); color: #fff; }
.tile-status-icon.pending { background: rgba(0,0,0,0.06); color: var(--muted); }
.teaching-card.color-blue   { border-left-color: var(--accent); }
.teaching-card.color-blue .action-icon   { background: var(--accent-light); color: var(--accent); }
.teaching-card.color-green  { border-left-color: var(--green); }
.teaching-card.color-green .action-icon  { background: var(--green-light); color: var(--green); }
.teaching-card.color-orange { border-left-color: var(--amber); }
.teaching-card.color-orange .action-icon { background: var(--amber-light); color: var(--amber); }
.teaching-card.color-purple { border-left-color: var(--purple); }
.teaching-card.color-purple .action-icon { background: var(--purple-light); color: var(--purple); }
.teaching-card.color-teal   { border-left-color: var(--teal); }
.teaching-card.color-teal .action-icon   { background: var(--teal-light); color: var(--teal); }
.teaching-card.color-pink   { border-left-color: var(--pink); }
.teaching-card.color-pink .action-icon   { background: var(--pink-light); color: var(--pink); }
.teaching-card .action-icon { width: 30px; height: 30px; border-radius: 7px; }
.teaching-card .action-title, .teaching-card .action-desc {
  width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.teaching-card .action-title { font-size: 13px; }
.teaching-card .action-desc { margin-top: 0; font-size: 11.5px; }
.teaching-card .tag-row { margin-top: 0 !important; gap: 5px; }
.teaching-card .pill { font-size: 10.5px; padding: 2px 7px; }

/* Department member card (hod/index.php, departments/view.php) - a
   .teaching-card variant centered around a circular avatar instead of the
   usual square icon tile. */
.member-card { align-items: center; text-align: center; }
.member-card .member-avatar-img, .member-card .member-avatar {
  width: 52px; height: 52px; border-radius: 50%; flex-shrink: 0;
}
.member-card .member-avatar-img { object-fit: cover; }
.member-card .member-avatar {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), #7e22ce);
  color: #fff; font-weight: 700; font-size: 18px;
}
.member-card .action-title, .member-card .action-desc { text-align: center; }
.member-card .tag-row { justify-content: center; }
.member-card .card-edit-toggle { text-align: center; }

.card-remove-btn {
  background: none; border: none; cursor: pointer; padding: 5px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  color: #b0b6c2; transition: background 0.15s, color 0.15s;
}
.card-remove-btn:hover { background: var(--red-light); color: var(--red); }

.card-view-btn {
  background: none; border: none; cursor: pointer; padding: 6px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  color: var(--accent); transition: background 0.15s;
}
.card-view-btn:hover { background: var(--accent-light); text-decoration: none; }

.card-icon-btn {
  background: none; border: none; cursor: pointer; padding: 6px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background 0.15s; text-decoration: none;
}
.card-icon-btn:hover { text-decoration: none; }
.card-icon-btn.blue   { color: var(--accent); }
.card-icon-btn.blue:hover   { background: var(--accent-light); }
.card-icon-btn.green  { color: var(--green); }
.card-icon-btn.green:hover  { background: var(--green-light); }
.card-icon-btn.purple { color: var(--purple); }
.card-icon-btn.purple:hover { background: var(--purple-light); }
.card-icon-btn.orange { color: var(--amber); }
.card-icon-btn.orange:hover { background: var(--amber-light); }
.card-icon-btn.teal   { color: var(--teal); }
.card-icon-btn.teal:hover   { background: var(--teal-light); }
.card-icon-btn.pink   { color: var(--pink); }
.card-icon-btn.pink:hover   { background: var(--pink-light); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid.one-col { grid-template-columns: 1fr; }
.history-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 900px) { .history-grid { grid-template-columns: 1fr; } }

.grid-3col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 900px) { .grid-3col { grid-template-columns: 1fr; } }
.history-card { display: flex; flex-direction: column; }
.history-card > a.btn { margin-top: auto; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: #374151; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13.5px; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
/* Create password / Confirm password side by side on the landing page's
   sign-in card (index.php) - keeps the card from growing an extra row. */
.password-row { display: flex; gap: 10px; }
.password-row .field { flex: 1; min-width: 0; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }

.alert { padding: 10px 14px; border-radius: 6px; font-size: 13.5px; margin-bottom: 14px; }
.alert.error { background: var(--red-light); color: var(--red); }
.alert.success { background: var(--green-light); color: var(--green); }

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

.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; }

.text-center { text-align: center; }

.icon-btn { display: inline-flex; align-items: center; gap: 6px; }
.icon-btn svg { flex-shrink: 0; }

/* Soft purple-to-teal gradient stage, shared by login.php, forgot_password.php,
   portal/login.php and portal/forgot_password.php - these classes are only
   used by those four pages. */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #a78bd6 0%, #8bacd9 50%, #52c7cf 100%);
  padding: 16px;
}
.login-card-wrap { position: relative; width: 100%; max-width: 360px; }
.login-box {
  background: #fff; border-radius: 18px; padding: 60px 34px 30px; width: 100%; max-width: 360px;
  box-shadow: 0 30px 70px rgba(31,20,60,0.35);
}
@media (max-width: 400px) { .login-box { padding: 56px 20px 24px; } .login-box h1 { font-size: 22px; } }
.login-box h1 { text-align: center; color: #241242; }
.login-box .subtitle { text-align: center; }
.login-box .field { margin-bottom: 12.5px; }
.login-box .btn {
  background: linear-gradient(135deg, var(--navy), var(--navy-dark));
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
  box-shadow: 0 14px 30px rgba(15,23,42,0.35);
}
.login-box .btn:hover { opacity: 0.92; }
.login-box .field input:focus, .login-box .field select:focus { border-color: #7b2ff7; }
.login-box .link-btn { color: #7b2ff7; }

/* Icon-prefixed input, e.g. a person icon inside the identifier field, a
   lock icon inside the password field - .input-icon-wrap (not .field-icon
   itself, which also contains the label above) is what the icon positions
   against, so it centers on the input, not the label+input pair. */
.login-box .field-icon .input-icon-wrap { position: relative; }
.login-box .field-icon .input-icon-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: #9ca3af; pointer-events: none;
}
.login-box .field-icon input { padding-left: 38px; }

/* The circular badge peeking over the top edge of the card - a generic
   camera/person icon before the account's been identified, that account's
   own profile picture (or initial) once it has (see login.php). */
.login-avatar-badge {
  position: absolute; top: 0; left: 50%; transform: translate(-50%, -50%);
  width: 114px; height: 114px; border-radius: 50%; z-index: 2;
  background: #fff; box-shadow: 0 10px 24px rgba(31,20,60,0.3);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.login-avatar-badge svg { color: #8bacd9; }
.login-avatar-badge img {
  width: 100%; height: 100%; object-fit: cover;
}
.login-avatar-badge .login-avatar-initial {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--purple)); color: #fff;
  font-weight: 700; font-size: 39px;
}

.login-remember-row {
  display: flex; align-items: center; justify-content: flex-end;
  margin-top: 11px; font-size: 12.5px;
}
.login-remember-row a { color: #7b2ff7; font-style: italic; }

.login-home-icon {
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 50%; margin: 16px auto 0;
  background: linear-gradient(135deg, #7b2ff7, #d12fd1); color: #fff;
  box-shadow: 0 10px 24px rgba(123,47,247,0.35);
}
.login-home-icon:hover { opacity: 0.92; }
.login-divider { border: none; border-top: 1px solid #e2d9f2; margin: 16px 0; }

.number-input { width: 40px; text-align: center; padding: 6px 4px; -moz-appearance: textfield; appearance: textfield; }
.number-input::-webkit-outer-spin-button,
.number-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.number-input.invalid { border-color: var(--red); background: var(--red-light); }

.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.chart-box h3 { font-size: 13.5px; margin: 0 0 8px; color: #374151; }
.chart-svg { width: 100%; height: auto; display: block; }

/* Attendance register: clickable status tiles + marking / absent lists. */
button.stat-tile.clickable {
  font: inherit; text-align: left; width: 100%; cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s;
}
button.stat-tile.clickable:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(15,23,42,0.1); }
button.stat-tile.clickable.active { border-color: currentColor; box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.attendance-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; margin-bottom: 4px; }
.att-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 4px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.att-row:last-child { border-bottom: none; }
.att-row input[type=checkbox] { width: 18px; height: 18px; flex-shrink: 0; cursor: pointer; }
.att-row .att-name { flex: 1; min-width: 0; }
.att-row .pill { flex-shrink: 0; }
#markList, #absentList { max-height: 460px; overflow-y: auto; }
@media (max-width: 900px) { .attendance-split { grid-template-columns: 1fr; } }

/* Promotion: the suggested destination class. */
.suggest-box {
  background: var(--accent-light); border: 1px solid #bfdbfe; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px;
}

/* Student portal: details inside the welcome banner. */
/* "Live" pulse next to cards that refresh on their own. */
.live-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #22c55e;
  margin-left: 6px; vertical-align: middle; animation: livePulse 1.8s ease-out infinite;
}
@keyframes livePulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.55); } 100% { box-shadow: 0 0 0 9px rgba(34,197,94,0); } }

/* Results-entry progress bars. */
.entry-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .entry-bars { grid-template-columns: 1fr; } }
.entry-bar-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 6px; }
.entry-bar-head span { color: var(--muted); font-size: 12px; }
.progress { height: 12px; background: #eef0f3; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--purple)); transition: width 0.6s ease; }

.entry-term { padding: 14px 0; border-top: 1px solid var(--border); }
.entry-term:first-child { border-top: none; padding-top: 4px; }
.entry-term-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }

/* Greyed-out action (e.g. report card not ready yet). */
.btn.disabled, a.btn.disabled {
  background: #e5e7eb; color: #9ca3af; box-shadow: none !important; cursor: not-allowed; pointer-events: none;
}

/* Teacher pop-up on the portal Subjects page. */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: #fff; border-radius: 16px; width: 100%; max-width: 380px; padding: 24px 22px 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35); position: relative; text-align: center;
}
.modal-close {
  position: absolute; top: 10px; right: 12px; border: none; background: none; font-size: 22px;
  line-height: 1; color: var(--muted); cursor: pointer;
}
.teacher-avatar, .teacher-avatar-fallback {
  width: 92px; height: 92px; border-radius: 50%; margin: 0 auto 10px; object-fit: cover; border: 1px solid var(--border);
}
.teacher-avatar-fallback {
  display: flex; align-items: center; justify-content: center; font-size: 34px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--purple));
}
.teacher-facts { text-align: left; margin-top: 14px; border-top: 1px solid var(--border); }
.teacher-fact { display: flex; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.teacher-fact span { flex: 0 0 88px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding-top: 1px; }
.teacher-fact strong { font-weight: 600; overflow-wrap: anywhere; }
.action-card.clickable-card { cursor: pointer; }
.action-card.clickable-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Attendance "this week" tiles. */
.stat-tile.gray { background: #eef0f3; color: #4b5563; }
.week-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
a.week-tile { gap: 2px; text-decoration: none; border: 2px solid transparent; transition: transform 0.1s, box-shadow 0.15s; }
a.week-tile:hover { text-decoration: none; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(15,23,42,0.1); }
a.week-tile.selected { border-color: currentColor; }
.week-day { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.8; }
.week-date { font-size: 12px; opacity: 0.75; }
.week-rate { font-size: 26px; font-weight: 800; line-height: 1.1; margin-top: 4px; }
.week-rate.week-none { opacity: 0.4; }
.week-rate.week-holiday { font-size: 17px; margin-top: 8px; }
.week-counts { font-size: 11px; opacity: 0.85; }

/* Read-only detail tiles (My Profile): icon badge, small label, value. */
.detail-tiles { display: grid; grid-template-columns: repeat(var(--cols, 4), 1fr); gap: 10px; margin-bottom: 10px; }
@media (max-width: 600px) { .detail-tiles { grid-template-columns: repeat(2, 1fr); } }
.detail-tile {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 11px 12px; border-radius: 12px; border: 1px solid transparent;
}
.detail-tile .detail-icon {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.75);
}
.detail-tile .detail-text { min-width: 0; }
.detail-tile .detail-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.75; }
.detail-tile .detail-value { font-size: 14px; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.detail-tile.empty .detail-value { font-weight: 500; opacity: 0.55; }
.detail-tile.blue   { background: var(--accent-light); color: #1d4ed8; }
.detail-tile.green  { background: var(--green-light);  color: var(--green); }
.detail-tile.orange { background: var(--amber-light);  color: var(--amber); }
.detail-tile.purple { background: var(--purple-light); color: var(--purple); }
.detail-tile.teal   { background: var(--teal-light);   color: var(--teal); }
.detail-tile.pink   { background: var(--pink-light);   color: var(--pink); }

.avatar-form { flex: 1 1 280px; min-width: 0; padding-left: 24px; border-left: 1px solid var(--border); }
@media (max-width: 700px) { .avatar-form { flex-basis: 100%; padding-left: 0; border-left: none; } }

/* ---- Responsive: phones & tablets ---- */

/* Hamburger + backdrop only exist for the off-canvas sidebar below. */
.nav-toggle {
  display: none; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex-shrink: 0; margin-right: 10px;
  background: #f3f4f6; border: 1px solid var(--border); border-radius: 10px;
  color: var(--ink); cursor: pointer; padding: 0;
}
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }

  /* Sidebar becomes an off-canvas drawer instead of stacking above the page. */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100%; width: 270px; max-width: 84vw;
    z-index: 60; transform: translateX(-100%); transition: transform 0.22s ease;
    box-shadow: none;
  }
  .app-shell.nav-open .sidebar { transform: translateX(0); box-shadow: 8px 0 30px rgba(0,0,0,0.35); }
  .sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,0.5); z-index: 55;
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
  }
  .app-shell.nav-open .sidebar-backdrop { display: block; opacity: 1; pointer-events: auto; }
  body.nav-locked { overflow: hidden; }

  .topbar { padding: 10px 14px; gap: 8px; }
  .topbar-search { display: flex; flex: 1 1 auto; min-width: 0; max-width: 420px; }
  .search-dropdown { width: min(380px, calc(100vw - 28px)); }
  .content { padding: 16px 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .page-header h1 { font-size: 21px; }
}

@media (max-width: 600px) {
  .topbar .who .who-role, .topbar .who .who-name { display: none; }
  .topbar .who { font-size: 12.5px; white-space: nowrap; }
  .content { padding: 14px 12px; }
  .card { padding: 14px; }
  .tile-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .action-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .inline-form, .filters { flex-direction: column; align-items: stretch; }
  .inline-form .field, .filters .field { width: 100%; }
  .inline-form .btn, .filters .btn { width: 100%; justify-content: center; }
  .field input, .field select, .field textarea { font-size: 16px; } /* stops iOS zoom-on-focus */
  .page-header { align-items: flex-start; }
  .page-header > .btn, .page-header > .tag-row { width: 100%; }
  .breadcrumbs { font-size: 12px; }
  th, td { padding: 7px 7px; }
  th { font-size: 11px; }
  table select, table input[type="text"], table input[type="number"] { min-height: 36px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 34px; }
  .search-dropdown { position: fixed; left: 12px; right: 12px; top: 58px; width: auto; max-width: none; }

  /* Cambridge papers entry table: shrink further than the sitewide table
     rules above so 2-3 papers + Total + Grade fit a phone in portrait
     without needing to scroll. Student stays pinned in view if a class with
     more columns (or a very narrow phone) still needs to scroll. */
  .cam-save-btn { width: 100%; justify-content: center; }
  .cam-table th, .cam-table td { padding: 6px 4px; }
  .cam-table th.cam-col-paper, .cam-table th.cam-col-total, .cam-table th.cam-col-grade { font-size: 10px; }
  .cam-table td.cam-col-student { max-width: 84px; white-space: normal; font-size: 12.5px; line-height: 1.25; }
  .cam-table .cam-col-total { font-size: 12px; }
  .cam-table .number-input { width: 32px; padding: 5px 2px; font-size: 12.5px; }
  .cam-table .pill { padding: 1px 6px; font-size: 10.5px; }
  .cam-table th.cam-col-student, .cam-table td.cam-col-student {
    position: sticky; left: 0; background: #fff; z-index: 1;
  }
  .cam-table tr:hover td.cam-col-student { background: #fafbfe; }
  .cam-legend { font-size: 11.5px; gap: 3px 10px; }
}
