@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600;700&family=IBM+Plex+Sans+Condensed:wght@400;500;600;700&display=swap');

/* ===== CSS Custom Properties — Light Default ===== */
:root {
  --bg-base:        #F4F5F7;
  --bg-surface:     #FFFFFF;
  --bg-raised:      #EAECF0;
  --bg-border:      #D0D4DC;
  --text-primary:   #0F1117;
  --text-secondary: #4A5068;
  --text-muted:     #8A91A8;
  --accent-amber:   #D4880A;
  --accent-lime:    #4A8C1C;
  --accent-red:     #C42B26;
  --accent-blue:    #2D6FBF;
  --accent-ghost:   #E8EAEF;
  --font-data: 'IBM Plex Mono', monospace;
  --font-ui: 'IBM Plex Sans Condensed', sans-serif;

  /* Legacy aliases */
  --primary-mid: var(--accent-amber);
  --primary-deep: #B3720A;
  --nav-dark: var(--bg-surface);
  --canvas-neutral: var(--bg-base);
  --neutral-50: var(--bg-surface);
  --neutral-200: var(--bg-border);
  --neutral-400: var(--text-secondary);
  --neutral-600: var(--text-secondary);
  --neutral-900: var(--text-primary);
  --success: var(--accent-lime);
  --warning: var(--accent-amber);
  --danger: var(--accent-red);
  --shadow-card: none;
  --shadow-card-hover: none;
  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;
  --radius-xl: 0;
  --radius-pill: 0;
  --radius-card: 0;
}

/* ===== Dark Theme ===== */
[data-theme="dark"] {
  --bg-base:        #08090C;
  --bg-surface:     #0E1017;
  --bg-raised:      #151821;
  --bg-border:      #1E2230;
  --text-primary:   #E8EAF0;
  --text-secondary: #7A8099;
  --text-muted:     #3D4460;
  --accent-amber:   #F5A623;
  --accent-lime:    #A8CC2B;
  --accent-red:     #E8403A;
  --accent-blue:    #4A8FE8;
  --accent-ghost:   #2A3050;
  --primary-deep:   #D4900E;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }

body {
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

h1 { font-size: 24px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; text-transform: uppercase; font-family: var(--font-ui); }
h2 { font-size: 14px; font-weight: 700; line-height: 1.2; letter-spacing: 0.10em; text-transform: uppercase; font-family: var(--font-ui); }
h3 { font-size: 14px; font-weight: 700; line-height: 1.2; letter-spacing: 0.10em; text-transform: uppercase; font-family: var(--font-ui); }
h4 { font-size: 14px; font-weight: 700; line-height: 1.2; letter-spacing: 0.10em; text-transform: uppercase; font-family: var(--font-ui); }

/* ===== Dashboard Layout ===== */
.dashboard-layout { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: 240px;
  background: var(--bg-surface);
  border-right: 1px solid var(--bg-border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

/* Mobile drawer backdrop — hidden by default, shown only when the sidebar is
   open on small screens (see the responsive block). Sits below the sidebar
   (z-index 100) but above page content. */
.sidebar-overlay { display: none; position: fixed; inset: 0; z-index: 90; background: rgba(8, 9, 12, 0.5); }

.sidebar-header { margin-bottom: 32px; padding: 0 4px; }
.brand-logo { display: block; width: 100%; max-width: 152px; height: auto; margin: 0 auto 6px; }
.brand-logo--dark { display: none; }
[data-theme="dark"] .brand-logo--light { display: none; }
[data-theme="dark"] .brand-logo--dark { display: block; }
.sidebar-subtitle { font-size: 11px; font-weight: 500; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.08em; }
/* SAR currency mark: scales with font-size (em) and inherits text colour via mask. */
.sar { display: inline-block; width: 0.74em; height: 0.92em; vertical-align: -0.12em; background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMTI0LjE0IDEyNTYuMzkiPjxwYXRoIGQ9Ik02OTkuNjIsMTExMy4wMmgwYy0yMC4wNiw0NC40OC0zMy4zMiw5Mi43NS0zOC40LDE0My4zN2w0MjQuNTEtOTAuMjRjMjAuMDYtNDQuNDcsMzMuMzEtOTIuNzUsMzguNC0xNDMuMzdsLTQyNC41MSw5MC4yNFoiLz48cGF0aCBkPSJNMTA4NS43Myw4OTUuOGMyMC4wNi00NC40NywzMy4zMi05Mi43NSwzOC40LTE0My4zN2wtMzMwLjY4LDcwLjMzdi0xMzUuMmwyOTIuMjctNjIuMTFjMjAuMDYtNDQuNDcsMzMuMzItOTIuNzUsMzguNC0xNDMuMzdsLTMzMC42OCw3MC4yN1Y2Ni4xM2MtNTAuNjcsMjguNDUtOTUuNjcsNjYuMzItMTMyLjI1LDExMC45OXY0MDMuMzVsLTEzMi4yNSwyOC4xMVYwYy01MC42NywyOC40NC05NS42Nyw2Ni4zMi0xMzIuMjUsMTEwLjk5djUyNS42OWwtMjk1LjkxLDYyLjg4Yy0yMC4wNiw0NC40Ny0zMy4zMyw5Mi43NS0zOC40MiwxNDMuMzdsMzM0LjMzLTcxLjA1djE3MC4yNmwtMzU4LjMsNzYuMTRjLTIwLjA2LDQ0LjQ3LTMzLjMyLDkyLjc1LTM4LjQsMTQzLjM3bDM3NS4wNC03OS43YzMwLjUzLTYuMzUsNTYuNzctMjQuNCw3My44My00OS4yNGw2OC43OC0xMDEuOTd2LS4wMmM3LjE0LTEwLjU1LDExLjMtMjMuMjcsMTEuMy0zNi45N3YtMTQ5Ljk4bDEzMi4yNS0yOC4xMXYyNzAuNGw0MjQuNTMtOTAuMjhaIi8+PC9zdmc+") center / contain no-repeat;
          mask: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMTI0LjE0IDEyNTYuMzkiPjxwYXRoIGQ9Ik02OTkuNjIsMTExMy4wMmgwYy0yMC4wNiw0NC40OC0zMy4zMiw5Mi43NS0zOC40LDE0My4zN2w0MjQuNTEtOTAuMjRjMjAuMDYtNDQuNDcsMzMuMzEtOTIuNzUsMzguNC0xNDMuMzdsLTQyNC41MSw5MC4yNFoiLz48cGF0aCBkPSJNMTA4NS43Myw4OTUuOGMyMC4wNi00NC40NywzMy4zMi05Mi43NSwzOC40LTE0My4zN2wtMzMwLjY4LDcwLjMzdi0xMzUuMmwyOTIuMjctNjIuMTFjMjAuMDYtNDQuNDcsMzMuMzItOTIuNzUsMzguNC0xNDMuMzdsLTMzMC42OCw3MC4yN1Y2Ni4xM2MtNTAuNjcsMjguNDUtOTUuNjcsNjYuMzItMTMyLjI1LDExMC45OXY0MDMuMzVsLTEzMi4yNSwyOC4xMVYwYy01MC42NywyOC40NC05NS42Nyw2Ni4zMi0xMzIuMjUsMTEwLjk5djUyNS42OWwtMjk1LjkxLDYyLjg4Yy0yMC4wNiw0NC40Ny0zMy4zMyw5Mi43NS0zOC40MiwxNDMuMzdsMzM0LjMzLTcxLjA1djE3MC4yNmwtMzU4LjMsNzYuMTRjLTIwLjA2LDQ0LjQ3LTMzLjMyLDkyLjc1LTM4LjQsMTQzLjM3bDM3NS4wNC03OS43YzMwLjUzLTYuMzUsNTYuNzctMjQuNCw3My44My00OS4yNGw2OC43OC0xMDEuOTd2LS4wMmM3LjE0LTEwLjU1LDExLjMtMjMuMjcsMTEuMy0zNi45N3YtMTQ5Ljk4bDEzMi4yNS0yOC4xMXYyNzAuNGw0MjQuNTMtOTAuMjhaIi8+PC9zdmc+") center / contain no-repeat; }

/* ===== Nav List ===== */
.nav-list { list-style: none; flex: 1; display: flex; flex-direction: column; gap: 2px; }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  font-size: 13px; font-weight: 700;
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-secondary);
  transition: background 0.2s, color 0.2s;
}
.nav-link:hover { background: var(--accent-ghost); color: var(--text-primary); }
.nav-link.active { background: var(--accent-ghost); color: var(--accent-amber); border-left: 2px solid var(--accent-amber); }
.nav-link.active .nav-icon svg { color: var(--accent-amber); }

.nav-icon {
  display: flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; flex-shrink: 0;
}
.nav-icon svg {
  width: 18px; height: 18px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ===== Collapsible Nav Folders ===== */
.nav-group { display: flex; flex-direction: column; }

.nav-group-toggle {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; background: none; border: none; cursor: pointer;
  font-size: 13px; font-weight: 700;
  font-family: var(--font-ui);
  text-transform: uppercase; letter-spacing: 0.10em;
  color: var(--text-secondary); text-align: left;
  transition: background 0.2s, color 0.2s;
}
.nav-group-toggle:hover { background: var(--accent-ghost); color: var(--text-primary); }
.nav-group-label { flex: 1; }
.nav-group.open > .nav-group-toggle { color: var(--text-primary); }

.nav-chevron { display: flex; align-items: center; justify-content: center; width: 16px; height: 16px; flex-shrink: 0; transition: transform 0.28s ease; }
.nav-chevron svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-group.open > .nav-group-toggle .nav-chevron { transform: rotate(180deg); }

/* Smooth expand/collapse without JS height measuring (grid-rows 0fr -> 1fr). */
.nav-group-items { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.28s ease; }
.nav-group.open > .nav-group-items { grid-template-rows: 1fr; }
.nav-group-items > ul { overflow: hidden; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.nav-group.open > .nav-group-items > ul { margin-top: 2px; }

.nav-sublink { padding-left: 40px; font-size: 12px; letter-spacing: 0.08em; }

/* ===== Sidebar Footer ===== */
.sidebar-footer {
  margin-top: auto; padding-top: 24px;
  border-top: 1px solid var(--bg-border);
}
.user-info { display: flex; flex-direction: column; margin-bottom: 8px; }
.user-name { font-size: 14px; font-weight: 500; color: var(--text-primary); font-family: var(--font-data); }
.user-email { font-size: 11px; color: var(--text-muted); font-family: var(--font-data); font-weight: 500; }

.logout-link {
  display: inline-block; font-size: 11px;
  color: var(--accent-red); font-weight: 700; padding: 4px 0;
  text-transform: uppercase; letter-spacing: 0.10em;
  transition: opacity 0.2s;
}
.logout-link:hover { opacity: 0.8; }

/* ===== Main Content ===== */
/* min-width:0 lets this flex item shrink below its content's intrinsic width so
   wide tables scroll inside their own container (overflow-x:auto) instead of
   stretching the page — the default min-width:auto would cause horizontal
   page overflow on mobile. */
.main-content { flex: 1; min-width: 0; margin-left: 240px; padding: 24px; min-height: 100vh; }

.top-bar { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }

.sidebar-toggle {
  display: none; background: none; border: none;
  font-size: 1.5rem; color: var(--text-primary); cursor: pointer; padding: 4px;
}

.page-title { font-size: 24px; font-weight: 700; color: var(--text-primary); font-family: var(--font-ui); text-transform: uppercase; letter-spacing: -0.01em; }

/* ===== Flash Messages ===== */
#flash {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 2000; text-align: center; pointer-events: none;
}

.flash {
  display: inline-block; pointer-events: auto;
  padding: 10px 20px;
  font-size: 14px; font-weight: 700; color: #FFFFFF;
  font-family: var(--font-ui); text-transform: uppercase; letter-spacing: 0.10em;
  animation: flash-fade 4s ease forwards; cursor: pointer;
}
.flash-success { background: var(--accent-lime); }
.flash-error { background: var(--accent-red); }
.flash-warning { background: var(--accent-amber); }
.flash-info { background: var(--accent-blue); }

@keyframes flash-fade { 0%, 70% { opacity: 1; } 100% { opacity: 0; pointer-events: none; } }

/* ===== Content Area ===== */
.content-area { max-width: 1280px; position: relative; z-index: 1; }

/* ===== Report Results ===== */
.report-results { display: flex; flex-direction: column; gap: 28px; }
.report-results .metrics-grid { margin-bottom: 0; }
.report-results .chart-card { margin-bottom: 0; }
.report-results .table-container { margin-bottom: 0; }

/* ===== Metrics Grid ===== */
.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 28px; }

.metric-card {
  background: var(--bg-surface); border: 1px solid var(--bg-border);
  padding: 28px 24px;
}
.metric-card:hover { }
.metric-label { font-size: 14px; font-weight: 700; color: var(--text-secondary); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.10em; font-family: var(--font-ui); }
.metric-value { font-size: 28px; font-weight: 600; color: var(--accent-amber); line-height: 1.2; font-family: var(--font-data); }

/* ===== Charts ===== */
.charts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-bottom: 24px; }

/* Fixed-height chart container so charts fill height instead of ballooning
   taller as the dashboard widens (used with maintainAspectRatio:false). */
.chart-body { height: 240px; position: relative; }

.chart-card {
  background: var(--bg-surface); border: 1px solid var(--bg-border);
  padding: 24px 24px 16px;
  margin-bottom: 24px;
}
.chart-card:hover { }
.chart-card h3 { margin-bottom: 20px; color: var(--text-primary); font-size: 14px; font-weight: 700; letter-spacing: 0.10em; text-transform: uppercase; font-family: var(--font-ui); }

/* ===== Toolbar ===== */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 28px; flex-wrap: wrap;
}
.toolbar-actions { display: flex; align-items: center; gap: 8px; }

.search-box { flex: 1; max-width: 400px; }
.search-box input {
  width: 100%; padding: 10px 16px;
  border: 1px solid var(--bg-border);
  font-family: var(--font-data); font-size: 14px; background: var(--bg-raised);
  color: var(--text-primary);
  transition: border-color 0.2s;
}
.search-box input:focus {
  outline: none; border-color: var(--accent-amber);
}

.filter-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filter-group label { font-size: 13px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.10em; font-family: var(--font-ui); }
.filter-group select,
.filter-group input[type="date"] {
  padding: 8px 12px; border: 1px solid var(--bg-border);
  font-family: var(--font-data); font-size: 14px; background: var(--bg-raised);
  color: var(--text-primary);
  transition: border-color 0.2s;
}
.filter-group select:focus,
.filter-group input[type="date"]:focus {
  outline: none; border-color: var(--accent-amber);
}

/* ===== Data Tables ===== */
.table-container {
  background: var(--bg-surface); border: 1px solid var(--bg-border);
  overflow: hidden; margin-bottom: 24px;
}
/* Wide, dropdown-free tables (e.g. Sessions) scroll horizontally *inside* their
   bordered box instead of overflowing past it — keeps the container intact when
   the table is wider than the available width. */
.table-container--scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-container h3 { padding: 16px 16px 0; color: var(--text-primary); }

.data-table { width: 100%; border-collapse: collapse; }
.data-table thead tr { background: var(--bg-raised); }
.data-table th {
  padding: 12px 16px; text-align: left;
  font-size: 13px; font-weight: 700; color: var(--text-secondary);
  border-bottom: 1px solid var(--bg-border);
  text-transform: uppercase; letter-spacing: 0.12em; font-family: var(--font-ui);
}
.data-table td {
  padding: 12px 16px; font-size: 15px; font-weight: 400;
  color: var(--text-primary); border-bottom: 1px solid var(--bg-border);
  font-family: var(--font-data); line-height: 1.5;
}
.data-table tbody tr:hover { background: var(--accent-ghost); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Inline loading spinner — referenced by audit log + loading cells */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--bg-border);
  border-top-color: var(--accent-amber);
  border-radius: 50%;
  animation: btn-spinner 0.6s linear infinite;
  vertical-align: -2px;
}
.loading-cell::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 2px solid var(--bg-border);
  border-top-color: var(--accent-amber);
  border-radius: 50%;
  animation: btn-spinner 0.6s linear infinite;
  vertical-align: -2px;
}

.loading-cell, .empty-cell {
  text-align: center; padding: 32px 16px !important;
  color: var(--text-muted); font-size: 14px;
}

/* Action cells stay real table-cells (not flex) so they stretch to the row
   height and their border-bottom lines up with the other columns; a flex <td>
   shrinks to content and breaks the row separator. font-size:0 removes inline
   whitespace so sibling margins give an exact, uniform gap. */
.actions-cell { vertical-align: middle; white-space: nowrap; font-size: 0; }
.actions-cell > * + * { margin-left: 6px; }
/* Error pages (403 / 404 / 500 …): error code on the left, logo right-aligned. */
.error-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px; }
.error-container { width: 100%; max-width: 860px; display: flex; align-items: center; justify-content: space-between; gap: 40px;
  background: var(--bg-surface); border: 1px solid var(--bg-border); border-top: 3px solid var(--accent-amber); padding: 48px; }
.error-main { flex: 1 1 auto; min-width: 0; }
.error-code { font-family: var(--font-data); font-size: 76px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; color: var(--accent-amber); }
.error-title { font-size: 22px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-primary); margin: 14px 0 10px; }
.error-message { font-size: 14px; line-height: 1.6; color: var(--text-secondary); max-width: 48ch; margin-bottom: 28px; }
.error-logo { flex: 0 0 auto; text-align: right; }
.error-logo .brand-logo { width: 190px; max-width: 38vw; height: auto; margin: 0; display: inline-block; }
@media (max-width: 680px) {
  .error-container { flex-direction: column; align-items: stretch; padding: 32px 24px; gap: 28px; }
  .error-logo { text-align: right; order: -1; }
  .error-logo .brand-logo { width: 150px; }
  .error-code { font-size: 60px; }
}
/* Per-row "Manage" dropdown (Students / TAs). The container opts out of
   overflow:hidden so the absolutely-positioned menu is not clipped. */
.table-container--menus { overflow: visible; }
.manage-menu { position: relative; display: inline-block; }
.manage-menu > summary { list-style: none; cursor: pointer; }
.manage-menu > summary::-webkit-details-marker { display: none; }
.manage-menu > summary::marker { content: ""; }
.manage-dropdown {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 60;
  min-width: 170px; display: flex; flex-direction: column; padding: 4px 0;
  background: var(--bg-surface); border: 1px solid var(--bg-border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.manage-item {
  display: block; width: 100%; text-align: left; white-space: nowrap;
  padding: 8px 16px; background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 12px; color: var(--text-primary);
  text-decoration: none; box-sizing: border-box;
}
.manage-item:hover { background: var(--bg-raised); }
.manage-item--danger { color: var(--accent-red); }
.manage-item--danger:hover { background: rgba(196, 43, 38, 0.12); }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  font-family: var(--font-ui);
}
.badge::before {
  content: ''; display: inline-block;
  width: 6px; height: 6px;
  flex-shrink: 0;
}
.badge-success { color: var(--accent-lime); }
.badge-success::before { background: var(--accent-lime); }
.badge-danger { color: var(--accent-red); }
.badge-danger::before { background: var(--accent-red); }
.badge-secondary { color: var(--text-secondary); }
.badge-secondary::before { background: var(--text-secondary); }
.badge-warning { color: var(--accent-amber); }
.badge-warning::before { background: var(--accent-amber); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-ui); font-size: 13px; font-weight: 700;
  padding: 0 20px; height: 36px;
  border: 1px solid transparent; cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.08em;
  transition: background 0.2s, opacity 0.2s; text-decoration: none;
}
.btn:active { opacity: 0.8; }

.btn-primary { background: var(--accent-amber); color: var(--bg-base); border-color: var(--accent-amber); }
.btn-primary:hover { background: var(--primary-deep); border-color: var(--primary-deep); }

.btn-secondary { background: transparent; color: var(--text-secondary); border-color: var(--bg-border); }
.btn-secondary:hover { background: var(--accent-ghost); }

.btn-danger { background: transparent; color: var(--accent-red); border-color: var(--accent-red); }
.btn-danger:hover { background: rgba(232,64,58,0.08); }

.btn-warning { background: transparent; color: var(--accent-amber); border-color: var(--accent-amber); }
.btn-warning:hover { background: rgba(245,166,35,0.08); }

.btn-success { background: transparent; color: var(--accent-lime); border-color: var(--accent-lime); }
.btn-success:hover { background: rgba(168,204,43,0.08); }

/* ===== Split button (primary action + dropdown of related actions) ===== */
.btn-split { position: relative; display: inline-flex; }
.btn-split-toggle { padding: 0 10px; border-left: 1px solid rgba(0,0,0,0.18); }
.btn-split-menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 50;
  min-width: 200px; background: var(--bg-surface); border: 1px solid var(--bg-border);
}
.btn-split-menu[hidden] { display: none; }
.btn-split-item {
  display: block; width: 100%; text-align: left;
  padding: 11px 14px; background: none; border: none; cursor: pointer;
  font-family: var(--font-ui); font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-primary);
}
.btn-split-item:hover { background: var(--accent-ghost); }

.btn-sm { font-size: 12px; padding: 0 12px; height: 28px; }
.btn-block { width: 100%; }

/* ===== Modals ===== */
.modal {
  display: none; position: fixed; inset: 0; z-index: 3000;
  align-items: center; justify-content: center;
}
.modal.open { display: flex; }

.modal-backdrop { position: absolute; inset: 0; background: rgba(8,9,12,0.80); }

.modal-content {
  position: relative; background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  max-width: 480px; width: 90%; padding: 32px; z-index: 1;
}
.modal-content h3 { margin-bottom: 16px; }

.modal-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 24px;
}

.warning-text { font-size: 14px; color: var(--accent-red); line-height: 1.5; font-family: var(--font-data); }

/* ===== Concourse info (sidebar trigger + modal) ===== */
.sidebar-info {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: none; cursor: pointer;
  padding: 8px 4px; margin-bottom: 4px;
  font-family: var(--font-ui); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.10em;
  color: var(--text-muted); transition: color 0.2s;
}
.sidebar-info:hover { color: var(--accent-blue); }
.sidebar-info .sidebar-info-icon { display: inline-flex; }
.sidebar-info .sidebar-info-icon svg {
  width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

.concourse-info { text-align: center; max-width: 420px; }
/* The inline SVG draws with currentColor, so `color` themes it for light/dark. */
.concourse-logo { display: block; width: 140px; height: 140px; margin: 4px auto 20px; color: var(--accent-blue); }
/* Logo links to the maker's site without altering the mark: no underline, keep
   the accent colour (so the SVG's currentColor stays blue), subtle hover only. */
.concourse-logo-link { display: block; line-height: 0; text-decoration: none; color: var(--accent-blue); transition: opacity 0.2s; }
.concourse-logo-link:hover { opacity: 0.85; }
.concourse-title {
  font-size: 24px; font-weight: 700; color: var(--text-primary);
  margin-bottom: 6px; text-align: center;
  font-family: var(--font-ui); text-transform: uppercase; letter-spacing: -0.01em;
}
.concourse-subtitle {
  font-size: 12px; font-weight: 700; color: var(--text-secondary);
  text-align: center; font-family: var(--font-ui);
  text-transform: uppercase; letter-spacing: 0.14em; line-height: 1.5;
}

/* ===== Demo Mode toggle (inside the Concourser modal) ===== */
.demo-mode-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; margin: 20px 0 4px; padding: 10px 14px;
  border: 1px solid var(--bg-border); background: none; cursor: pointer;
  font-family: var(--font-ui); font-size: 13px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.demo-mode-row:hover { color: var(--text-primary); }
.demo-mode-switch {
  position: relative; width: 34px; height: 18px; border-radius: 9px; flex-shrink: 0;
  background: var(--bg-border); transition: background-color 0.15s ease;
}
.demo-mode-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--bg-surface); transition: left 0.15s ease;
}
[data-demo-on="true"] .demo-mode-switch { background: var(--accent-amber); }
[data-demo-on="true"] .demo-mode-switch::after { left: 18px; }
.demo-mode-hint {
  font-size: 11px; color: var(--text-muted); font-family: var(--font-ui);
  text-transform: none; letter-spacing: normal; line-height: 1.4; text-align: left;
  margin: 0 0 4px;
}

/* Replace institution branding with a generic-looking product identity while
   Demo Mode is on -- a screenshot/recording shouldn't reveal which real
   institution this data belongs to, but an empty gap where a logo used to be
   reads as broken, not intentional, so a placeholder brand fills it instead. */
[data-demo-on="true"] .brand-logo { display: none; }
.demo-brand { display: none; }
[data-demo-on="true"] .demo-brand {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 4px 0 2px;
}
.demo-brand-logo { display: block; width: 44px; height: 44px; color: var(--accent-blue); }
.demo-brand-logo svg { display: block; }
.demo-brand-text { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.demo-brand-name {
  font-family: var(--font-ui); font-weight: 700; font-size: 15px; color: var(--text-primary);
  text-transform: uppercase; letter-spacing: 0.02em; line-height: 1;
}
.demo-brand-sub {
  font-family: var(--font-ui); font-weight: 500; font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.1em; line-height: 1;
}

/* ===== Modal Close Button ===== */
.modal-close {
  position: absolute; top: 12px; right: 16px; background: none; border: none;
  font-size: 1.5rem; cursor: pointer; color: var(--text-secondary); line-height: 1;
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text-primary); }

/* ===== Password Display ===== */
.password-display {
  display: flex; align-items: center; gap: 12px; margin: 16px 0;
  padding: 12px 16px; background: var(--bg-raised);
  border: 1px solid var(--bg-border);
}
.password-display code {
  font-family: var(--font-data); font-size: 16px; font-weight: 600;
  color: var(--accent-amber); flex: 1; user-select: all;
}

/* ===== Forms ===== */
.form-card {
  background: var(--bg-surface); border: 1px solid var(--bg-border);
  padding: 32px; max-width: 640px;
}
.form-card--wide { max-width: 100%; }

#preview-section { margin-top: 16px; }
#preview-section .table-scroll-wrapper {
  overflow-x: auto;
  border: 1px solid var(--bg-border);
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 13px; font-weight: 700;
  color: var(--text-secondary); margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.10em; font-family: var(--font-ui);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 10px 16px;
  border: 1px solid var(--bg-border);
  font-family: var(--font-data); font-size: 14px; background: var(--bg-raised);
  color: var(--text-primary);
  transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none; border-color: var(--accent-amber);
}

.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 24px; }

.inline-form { display: flex; align-items: center; gap: 6px; }

.input-sm {
  padding: 6px 10px !important; font-size: 11px !important;
  border: 1px solid var(--bg-border);
  font-family: var(--font-data); font-weight: 500;
  background: var(--bg-raised); color: var(--text-primary);
}
.input-sm:focus {
  outline: none; border-color: var(--accent-amber);
}

/* ===== Upload ===== */
.upload-instructions {
  background: var(--bg-raised); border: 1px solid var(--bg-border);
  padding: 16px; margin-bottom: 24px;
}
.upload-instructions h3 { margin-bottom: 8px; color: var(--text-primary); }
.upload-instructions p { font-size: 14px; color: var(--text-secondary); margin-bottom: 4px; font-family: var(--font-data); }
.upload-instructions code {
  background: var(--bg-border); padding: 2px 6px; font-size: 14px; font-family: var(--font-data); color: var(--accent-amber);
}
.upload-form { margin-bottom: 24px; }

/* ===== Detail Pages ===== */
.detail-header { margin-bottom: 24px; }
.back-link a {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; color: var(--accent-amber);
  text-transform: uppercase; letter-spacing: 0.10em; font-family: var(--font-ui);
  margin-bottom: 16px;
}
.back-link a:hover { opacity: 0.8; }

.detail-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-top: 16px;
  padding: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
}
.detail-meta-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.detail-meta-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-family: var(--font-ui);
}
.detail-meta-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-data);
}

.detail-section { margin-bottom: 32px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px;
}

/* ===== Dropdown ===== */
.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; top: 100%; right: 0;
  background: var(--bg-surface); border: 1px solid var(--bg-border);
  min-width: 200px; z-index: 50;
  padding: 4px 0; margin-top: 4px;
}
.dropdown.open .dropdown-menu { display: block; }

.dropdown-item {
  display: block; padding: 8px 16px; font-size: 14px;
  color: var(--text-primary); cursor: pointer; transition: background 0.15s;
  font-family: var(--font-ui);
}
.dropdown-item:hover { background: var(--accent-ghost); }

/* ===== Pagination ===== */
.pagination {
  display: flex; align-items: center; justify-content: center; gap: 4px; padding: 16px;
}
.pagination a, .pagination span {
  padding: 6px 12px;
  font-size: 14px; font-weight: 500; color: var(--text-secondary);
  font-family: var(--font-data);
  transition: background 0.2s;
}
.pagination a:hover { background: var(--accent-ghost); }
.pagination .active { background: var(--accent-amber); color: var(--bg-base); }

/* ===== JSON Details (Audit Log) ===== */
.json-details { overflow: hidden; transition: max-height 0.3s ease; }
.json-details.collapsed { max-height: 0; }

/* ===== Login Page ===== */
.login-container {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg-base); padding: 24px;
}
.login-card {
  background: var(--bg-surface); border: 1px solid var(--bg-border);
  max-width: 400px; width: 100%; padding: 40px;
}
.login-title {
  font-size: 24px; font-weight: 700; color: var(--text-primary);
  margin-bottom: 4px; text-align: center;
  font-family: var(--font-ui); text-transform: uppercase; letter-spacing: -0.01em;
}
.login-subtitle {
  font-size: 12px; font-weight: 700; color: var(--text-secondary);
  margin-bottom: 24px; text-align: center;
  font-family: var(--font-ui); text-transform: uppercase; letter-spacing: 0.14em;
}
.login-form { margin-top: 8px; }
.login-form .form-group { margin-bottom: 16px; }
.login-form .btn-block { margin-top: 8px; height: 36px; }

.login-redirect {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  font-size: 0.8125rem; color: var(--text-secondary);
}
.login-redirect a { color: var(--accent-amber); font-weight: 500; }

/* ===== Loading States ===== */
@keyframes btn-spinner {
  to { transform: rotate(360deg); }
}

.btn.htmx-request,
.btn.loading,
form.htmx-request .btn[type="submit"] {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.btn.htmx-request > *,
.btn.loading > *,
form.htmx-request .btn[type="submit"] > * {
  visibility: visible;
}

.btn.htmx-request,
.btn.loading,
form.htmx-request .btn[type="submit"] {
  color: transparent !important;
}

.btn.htmx-request::after,
.btn.loading::after,
form.htmx-request .btn[type="submit"]::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-top: -8px;
  margin-left: -8px;
  border: 2.5px solid #fff;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spinner 0.6s linear infinite;
}

.btn-danger.htmx-request::after,
.btn-danger.loading::after {
  border-color: var(--danger);
  border-right-color: transparent;
}

.btn-warning.htmx-request::after,
.btn-warning.loading::after {
  border-color: var(--warning);
  border-right-color: transparent;
}

.btn-success.htmx-request::after,
.btn-success.loading::after {
  border-color: var(--success);
  border-right-color: transparent;
}

.btn-secondary.htmx-request::after,
.btn-secondary.loading::after {
  border-color: var(--neutral-600);
  border-right-color: transparent;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  /* Off-canvas sidebar as a drawer with a tap-to-close backdrop. */
  .sidebar { transform: translateX(-100%); width: 84vw; max-width: 300px; box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main-content { margin-left: 0; padding: 16px 14px; }
  .sidebar-toggle { display: block; }

  .top-bar { gap: 10px; margin-bottom: 18px; }
  .page-title { font-size: 18px; }

  .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
  .metric-card { padding: 16px 14px; }
  .metric-value { font-size: 24px; }
  .chart-card { padding: 18px 16px 12px; }

  /* Toolbars/filters stack and go full-width so controls are easy to tap. */
  .toolbar { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 18px; }
  .toolbar-actions { flex-wrap: wrap; }
  .search-box { max-width: none; width: 100%; }
  /* Two-column grid keeps each label beside its own control instead of
     letting flex-wrap strand a label at the end of the previous line. */
  .filter-group {
    width: 100%;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 10px;
    align-items: center;
  }
  .filter-group select,
  .filter-group input[type="date"] { width: 100%; min-width: 0; }
  /* Compound items (e.g. the sessions "No-attendance only" checkbox label)
     take a full row. */
  .filter-group > label:has(input) { grid-column: 1 / -1; }

  /* Tables scroll horizontally instead of clipping columns. The base rule used
     overflow:hidden, which silently cut off columns on narrow screens — the
     single biggest mobile problem here. A min-width keeps columns readable. */
  .table-container,
  .table-container--menus { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 560px; }
  .data-table th,
  .data-table td { padding: 10px 12px; font-size: 13px; }

  /* Modals: near-full width, scroll if tall, lighter padding. */
  .modal-content { width: 94%; padding: 20px; max-height: 90vh; overflow-y: auto; }
  .modal-actions { flex-wrap: wrap; }

  .pagination { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 16px; }
  #live-clock { display: none; }
  .data-table { min-width: 520px; }
}

/* ===== Scale up on large / high-resolution displays =====
   Base sizing targets ~1280px; on wide, high-DPI monitors the dashboard would
   otherwise sit as a small fixed column (hence reaching for browser zoom).
   These tiers widen the content and enlarge the key typography/spacing so it
   fills and reads well. Additive only — nothing below 1600px changes. */
@media (min-width: 1600px) {
  .content-area { max-width: 1600px; margin: 0 auto; }
  .page-title, h1 { font-size: 28px; }
  .metric-value { font-size: 34px; }
  .chart-body { height: 280px; }
  .data-table td { font-size: 16px; }
}

@media (min-width: 2200px) {
  .content-area { max-width: 1960px; }
  .page-title, h1 { font-size: 34px; }
  .metric-card { padding: 32px 28px; }
  .metric-value { font-size: 42px; }
  .chart-body { height: 340px; }
  .data-table td { font-size: 18px; }
  .sidebar { width: 300px; }
  .main-content { margin-left: 300px; }
  .nav-link, .nav-group-toggle { font-size: 15px; }
  .nav-sublink { font-size: 14px; }
}

/* ===== List Styles ===== */
ul:not(.nav-list):not(.pagination):not(.nav-sub-list) {
  list-style: none; padding-left: 0; margin: 0;
}
ul:not(.nav-list):not(.pagination):not(.nav-sub-list) > li {
  position: relative; padding: 10px 0 10px 15px;
  border-bottom: 1px solid var(--bg-border);
  font-family: var(--font-data); font-size: 14px; color: var(--text-primary);
}
ul:not(.nav-list):not(.pagination):not(.nav-sub-list) > li:last-child { border-bottom: none; }
ul:not(.nav-list):not(.pagination):not(.nav-sub-list) > li::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 14px; background: var(--accent-amber);
}

ol {
  list-style: none; padding-left: 0; margin: 0; counter-reset: step-counter;
}
ol > li {
  counter-increment: step-counter; display: flex; gap: 12px;
  padding: 8px 0; font-family: var(--font-data); font-size: 14px;
  color: var(--text-primary); line-height: 1.6;
}
ol > li::before {
  content: counter(step-counter); display: flex; align-items: flex-start;
  justify-content: flex-end; min-width: 24px;
  font-family: var(--font-data); font-size: 11px; font-weight: 700;
  color: var(--accent-amber);
}

/* ===== Dark Theme Specifics ===== */
[data-theme="dark"] .btn-primary { color: var(--bg-base); }
[data-theme="dark"] .flash { color: var(--bg-base); }
[data-theme="dark"] .pagination .active { color: var(--bg-base); }
[data-theme="dark"] .modal-backdrop { background: rgba(8,9,12,0.80); }

/* ===== Theme Toggle ===== */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 12px; height: 28px; cursor: pointer;
  background: none; border: 1px solid var(--bg-border);
  font-family: var(--font-ui); font-size: 11px; font-weight: 700;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.10em;
  transition: color 0.2s, border-color 0.2s;
}
.theme-toggle:hover { color: var(--text-primary); border-color: var(--text-secondary); }
