/* Bus Manager -- one stylesheet, themed from the owner's three settings.
   --primary, --accent and the light/dark switch are injected per request in
   base.html; everything else derives from them or from the tokens below. */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --radius: 10px;
  --radius-lg: 14px;
  --gap: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  /* One easing curve and two durations for the whole app, so every hover,
     menu and page entrance moves at the same unhurried pace. */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --t-fast: 120ms;
  --t: 190ms;

  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f1f4f8;
  --surface-3: #e8edf3;
  --border: #dfe4ea;
  --text: #141a21;
  --muted: #5d6874;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg: 0 4px 6px -2px rgba(16, 24, 40, .05), 0 12px 16px -4px rgba(16, 24, 40, .1);

  --ok: #047857;      --ok-bg: #d1fae5;
  --warn: #b45309;    --warn-bg: #fef3c7;
  --danger: #b91c1c;  --danger-bg: #fee2e2;
  --info: #1d4ed8;    --info-bg: #dbeafe;

  /* A data URI cannot read a custom property, so the select chevron is drawn
     once per theme rather than tinted with currentColor. */
  --chevron: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1.75 6 6.25 11 1.75' fill='none' stroke='%235d6874' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #171c23;
  --surface-2: #1e242d;
  --surface-3: #262e38;
  --border: #2c343f;
  --text: #e7ecf2;
  --muted: #98a3b1;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 24px rgba(0, 0, 0, .45);

  --ok: #34d399;      --ok-bg: rgba(16, 185, 129, .16);
  --warn: #fbbf24;    --warn-bg: rgba(245, 158, 11, .16);
  --danger: #f87171;  --danger-bg: rgba(239, 68, 68, .16);
  --info: #60a5fa;    --info-bg: rgba(59, 130, 246, .16);

  --chevron: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1.75 6 6.25 11 1.75' fill='none' stroke='%2398a3b1' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; transition: color var(--t) var(--ease), opacity var(--t) var(--ease); }
a:hover { text-decoration: underline; }
a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px;
}
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
small { font-size: .8125rem; }

/* ---------- layout ---------- */

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

.sidebar {
  width: 236px;
  flex: 0 0 236px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--text);
  min-width: 0;
}
.brand:hover { text-decoration: none; }
.brand img { width: 32px; height: 32px; object-fit: contain; border-radius: 7px; }
.brand .mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; font-size: 1rem; flex: 0 0 32px;
}
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-label {
  font-size: .6875rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 14px 10px 6px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--text); font-size: .9rem; font-weight: 500;
  transition: background-color var(--t) var(--ease), color var(--t) var(--ease);
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary); color: var(--on-primary); }
.nav a .ic { width: 18px; text-align: center; flex: 0 0 18px; }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.who { padding: 6px 10px; }
.who strong { display: block; font-size: .875rem; }
.who small { color: var(--muted); }

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.15rem; }
.topbar .spacer { flex: 1; }

.content { padding: 22px 24px 48px; max-width: 1280px; width: 100%; }

/* A page arrives with a short settle rather than a jump. Chrome (sidebar,
   app bar, tab bar) stays put so the frame feels fixed and only the page
   inside it changes. */
.topbar, .flashes, .content { animation: rise 260ms var(--ease) both; }
.flashes { animation-delay: 30ms; }
.content { animation-delay: 60ms; }
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- phone chrome: app bar and tab bar ---------- */

.appbar, .tabbar { display: none; }

.appbar .brand { padding: 0; flex: 1; }
.appbar .menu { position: relative; }
.appbar .menu > summary {
  list-style: none; cursor: pointer; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 999px;
  transition: background-color var(--t) var(--ease);
}
.appbar .menu > summary::-webkit-details-marker { display: none; }
.appbar .menu > summary:hover, .appbar .menu[open] > summary { background: var(--surface-2); }
.appbar .avatar {
  width: 32px; height: 32px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; font-weight: 700; font-size: .9rem;
}
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  min-width: 212px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: menu-in 150ms var(--ease) both;
}
.menu-panel .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-panel a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 9px;
  color: var(--text); font-size: .9rem; font-weight: 500;
  transition: background-color var(--t) var(--ease);
}
.menu-panel a:hover { background: var(--surface-2); text-decoration: none; }
.menu-panel a .ic { width: 18px; text-align: center; }
@keyframes menu-in {
  from { opacity: 0; transform: translateY(-6px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.tabbar a {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px; color: var(--muted); font-weight: 600;
}
.tabbar a:hover { text-decoration: none; }
.tabbar a .ic {
  width: 46px; height: 28px; border-radius: 999px;
  display: grid; place-items: center; font-size: 1.05rem;
  transition: background-color var(--t) var(--ease), transform var(--t) var(--ease);
}
.tabbar a .lbl {
  font-size: .6875rem; letter-spacing: .01em;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tabbar a.active { color: var(--text); }
.tabbar a.active .ic { background: var(--primary); }
.tabbar a:active .ic { transform: scale(.94); }

/* ---------- cards & grids ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: var(--gap);
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: -2px 0 14px;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 16px 18px 0; margin-bottom: 12px; }

.grid { display: grid; gap: var(--gap); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 16px; box-shadow: var(--shadow);
  transition: box-shadow var(--t) var(--ease), border-color var(--t) var(--ease);
}
.stat .label {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600;
}
.stat .value { font-size: 1.5rem; font-weight: 680; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .value.ok { color: var(--ok); }
.stat .value.warn { color: var(--warn); }
.stat .value.danger { color: var(--danger); }
.stat .sub { font-size: .8125rem; color: var(--muted); margin-top: 2px; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
  text-align: left; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); font-weight: 650;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color var(--t) var(--ease); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr.retired { opacity: .55; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.name { font-weight: 570; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }
.empty .big { font-size: 1.75rem; display: block; margin-bottom: 6px; }

/* ---------- badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 620; white-space: nowrap;
  background: var(--surface-3); color: var(--muted);
}
.badge.paid, .badge.on_time, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.due, .badge.info { background: var(--info-bg); color: var(--info); }
.badge.grace, .badge.warn, .badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.overdue, .badge.late, .badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.waived { background: var(--surface-3); color: var(--muted); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 15px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: .875rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; line-height: 1.3;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--t) var(--ease), border-color var(--t) var(--ease),
              color var(--t) var(--ease), box-shadow var(--t) var(--ease),
              filter var(--t) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.08); box-shadow: var(--shadow); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.accent:hover { filter: brightness(1.08); box-shadow: var(--shadow); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-bg); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 5px 11px; font-size: .8125rem; }
.btn.lg { padding: 12px 22px; font-size: 1rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn[disabled]:active { transform: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- forms ---------- */

.field { margin-bottom: 14px; }
.field label, .field > .lbl {
  display: block; font-size: .8125rem; font-weight: 600;
  margin-bottom: 5px; color: var(--text);
}
.hint { font-size: .78rem; color: var(--muted); margin-top: 5px; }
input[type="text"], input[type="password"], input[type="tel"], input[type="number"],
input[type="date"], input[type="email"], input[type="file"], select, textarea {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 9px;
  background-color: var(--surface); color: var(--text);
  font-family: inherit; font-size: .9rem;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease),
              background-color var(--t) var(--ease);
}
input:hover:not([disabled]), select:hover:not([disabled]), textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
input[disabled], select[disabled], textarea[disabled] {
  background-color: var(--surface-2); color: var(--muted); cursor: not-allowed;
}
::placeholder { color: var(--muted); opacity: .75; }
textarea { min-height: 72px; resize: vertical; }
/* One chevron on every platform, instead of each browser's own control. */
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px; cursor: pointer;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 12px center;
}
input[type="color"] {
  width: 52px; height: 38px; padding: 3px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface); cursor: pointer;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--gap); }
.form-grid .full { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }
.check {
  display: flex; align-items: center; gap: 7px;
  font-size: .875rem; font-weight: 500; cursor: pointer;
}
.check input { width: auto; }
.month-picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.month-picker label {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 6px 2px; border: 1px solid var(--border); border-radius: 7px;
  font-size: .78rem; font-weight: 600; cursor: pointer; background: var(--surface);
  transition: background-color var(--t) var(--ease), border-color var(--t) var(--ease),
              color var(--t) var(--ease);
}
.month-picker label:hover { border-color: var(--muted); }
.month-picker input { display: none; }
.month-picker input:checked + span { color: var(--danger); }
.month-picker label:has(input:checked) { border-color: var(--danger); background: var(--danger-bg); }

/* ---------- filters ---------- */

.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  padding: 14px 18px; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.filters .field { margin: 0; min-width: 150px; flex: 0 1 auto; }
.filters .grow { flex: 1 1 200px; }
.filter-actions { display: flex; gap: 8px; }

/* Only the month fields belonging to the chosen period mode are shown; the
   inline script in the dashboard toggles them. */
.filters .field[hidden] { display: none; }

/* What the roster is showing, and the two ways to take a copy of it. Sits
   between the filters and the table so the period and its downloads read as
   one line. */
.card.flush .card-head.report-head {
  padding: 12px 18px; margin: 0;
  border-bottom: 1px solid var(--border);
}

/* The school selector in the owner's top bar: the frame for that whole
   screen, so it reads as a label and a control rather than a form. */
.school-picker { display: flex; align-items: center; gap: 10px; }
.school-picker label { margin: 0; font-size: .8125rem; font-weight: 600; color: var(--muted); }
.school-picker select { min-width: 230px; font-weight: 600; }

/* ---------- flash ---------- */

.flashes { padding: 14px 24px 0; max-width: 1280px; }
.flash {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: 10px; margin-bottom: 10px;
  font-size: .9rem; border: 1px solid transparent;
}
.flash.success { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 28%, transparent); }
.flash.error { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.flash.info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 28%, transparent); }
.flash strong { font-family: var(--mono); }

/* ---------- score panel ---------- */

.score {
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--accent) 65%, var(--primary)));
  color: var(--on-primary);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-lg);
}
.score .tier-row { display: flex; align-items: center; gap: 14px; }
.score .emoji { font-size: 2.6rem; line-height: 1; }
.score .tier-name { font-size: 1.2rem; font-weight: 700; }
.score .pts { font-size: .875rem; opacity: .9; }
.score .bar {
  height: 9px; border-radius: 999px; margin: 14px 0 7px;
  background: rgba(255, 255, 255, .28); overflow: hidden;
}
[data-theme="dark"] .score .bar { background: rgba(0, 0, 0, .28); }
.score .bar span {
  display: block; height: 100%; border-radius: 999px;
  background: currentColor;
  animation: fill 700ms var(--ease) both;
  animation-delay: 160ms;
}
@keyframes fill { from { width: 0; } }
.score .bar-note { font-size: .8rem; opacity: .9; display: flex; justify-content: space-between; gap: 10px; }
.score .streak {
  margin-top: 14px; padding-top: 13px; font-size: .875rem;
  border-top: 1px solid rgba(255, 255, 255, .25);
  display: flex; align-items: center; gap: 8px;
}

.tips { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.tips li {
  display: flex; gap: 10px; padding: 11px 13px;
  border-radius: 10px; font-size: .875rem;
  background: var(--surface-2); border-left: 3px solid var(--border);
}
.tips li .ic { flex: 0 0 auto; font-size: 1rem; line-height: 1.4; }
.tips li.urgent { background: var(--danger-bg); border-left-color: var(--danger); }
.tips li.warn { background: var(--warn-bg); border-left-color: var(--warn); }
.tips li.good { background: var(--ok-bg); border-left-color: var(--ok); }
.tips li.info { background: var(--info-bg); border-left-color: var(--info); }

/* ---------- due card ---------- */

.due-card {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px; background: var(--surface); box-shadow: var(--shadow);
}
.due-card.overdue { border-color: var(--danger); }
.due-card.grace { border-color: var(--warn); }
.due-card .period { font-size: .8125rem; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; }
.due-card .amount { font-size: 2.25rem; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.due-card .lines { font-size: .875rem; color: var(--muted); margin: 10px 0 16px; }
.due-card .lines div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.due-card .lines .total { color: var(--text); font-weight: 650; border-top: 1px solid var(--border);
  margin-top: 6px; padding-top: 8px; }

/* ---------- misc ---------- */

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .875em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: var(--gap); }
.mb0 { margin-bottom: 0; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
details.section > summary {
  cursor: pointer; font-weight: 650; padding: 10px 0; list-style: revert;
}
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; text-align: right; }

/* ---------- auth ---------- */

.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--bg), color-mix(in srgb, var(--primary) 12%, var(--bg)));
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 30px 28px; box-shadow: var(--shadow-lg);
  animation: rise 320ms var(--ease) both;
}
.auth-card .mark {
  width: 46px; height: 46px; border-radius: 12px; background: var(--primary);
  color: var(--on-primary); display: grid; place-items: center;
  font-size: 1.4rem; margin-bottom: 16px;
}
.auth-card h1 { font-size: 1.35rem; }
.auth-card .sub { color: var(--muted); font-size: .9rem; margin-bottom: 22px; }

/* ---------- mock gateway ---------- */

.gateway-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: #1f2937; color: #f9fafb;
}
.gateway-card {
  width: 100%; max-width: 420px; background: #ffffff; color: #111827;
  border-radius: 14px; padding: 26px; box-shadow: 0 20px 40px rgba(0, 0, 0, .35);
  animation: rise 320ms var(--ease) both;
}
.gateway-card .test-banner {
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
  border-radius: 8px; padding: 9px 12px; font-size: .8125rem;
  font-weight: 600; margin-bottom: 18px;
}
.gateway-card .amount { font-size: 2rem; font-weight: 700; margin: 6px 0 2px; }
.gateway-card .rows { font-size: .875rem; color: #4b5563; margin: 16px 0 22px; }
.gateway-card .rows div { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0;
  border-bottom: 1px solid #f3f4f6; }
.gateway-card .rows span + span { min-width: 0; text-align: right; overflow-wrap: anywhere; }
.gateway-card .btn { border-color: #d1d5db; background: #fff; color: #111827; }
.gateway-card .btn:hover { background: #f3f4f6; }
.gateway-card .btn.pay { background: #059669; border-color: #059669; color: #fff; }
.gateway-card .btn.fail { background: #fff; border-color: #dc2626; color: #dc2626; }

/* ---------- receipt ---------- */

.receipt { max-width: 560px; }
.receipt .head { display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; padding-bottom: 16px; border-bottom: 2px solid var(--border); }
.receipt .stamp { font-size: 2.2rem; }

@media print {
  .sidebar, .topbar, .appbar, .tabbar, .no-print { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border: none; }
  .topbar, .flashes, .content, .auth-card, .score .bar span { animation: none !important; }
}

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.side { grid-template-columns: minmax(0, 1fr); }
}

/* Phones. The sidebar gives way to an app bar at the top and a tab bar at the
   bottom; wide tables fold into one labelled card per row. */
@media (max-width: 760px) {
  .sidebar { display: none; }

  .appbar {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 30;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top));
  }
  .appbar .brand span { font-size: .98rem; }

  .tabbar {
    display: flex; gap: 2px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 5px 6px; padding-bottom: calc(5px + env(safe-area-inset-bottom));
    box-shadow: 0 -1px 2px rgba(16, 24, 40, .04);
  }

  .topbar {
    position: static;
    padding: 12px 16px;
    gap: 8px 10px;
  }
  .topbar h1 { font-size: 1.2rem; width: 100%; }
  .content, .flashes { padding-left: 16px; padding-right: 16px; }
  .content { padding-top: 18px; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .grid { gap: 12px; }
  .stat { padding: 12px 14px; }
  .stat .label { font-size: .7rem; letter-spacing: .04em; }
  .stat .value { font-size: 1.3rem; }
  .stat .sub { font-size: .75rem; }

  .card { padding: 16px; }
  .card.flush .card-head { padding: 14px 16px 0; }

  /* Comfortable thumb targets and, at 16px, no zoom-on-focus in iOS Safari. */
  input[type="text"], input[type="password"], input[type="tel"], input[type="number"],
  input[type="date"], input[type="email"], select, textarea {
    font-size: 16px; padding: 11px 13px; min-height: 46px;
  }
  select { padding-right: 38px; background-position: right 14px center; }
  input[type="color"] { width: 58px; height: 46px; }
  .btn { padding: 11px 16px; min-height: 46px; }
  .btn.sm { padding: 8px 12px; min-height: 38px; font-size: .84rem; }
  .btn.lg { min-height: 52px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .month-picker { grid-template-columns: repeat(4, 1fr); }
  .month-picker label { padding: 10px 2px; font-size: .82rem; }

  .school-picker { width: 100%; }
  .school-picker select { flex: 1; min-width: 0; }

  .filters { padding: 12px 16px; gap: 10px; }
  .filters .field { min-width: 0; flex: 1 1 calc(50% - 5px); }
  .filters .grow { flex: 1 1 100%; }
  .filter-actions { flex: 1 1 100%; }
  .filter-actions .btn { flex: 1; }

  .due-card .amount { font-size: 2rem; }
  .score .emoji { font-size: 2.2rem; }
  .score .bar-note { flex-direction: column; gap: 2px; }
}

/* Dense tables fold into cards earlier than the chrome does: an eight-column
   payment history has already outgrown a tablet next to the sidebar. */
@media (max-width: 860px) {
  /* A row per card: the first cell is the heading, the rest are labelled
     lines. A wider screen keeps the real table. */
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr {
    position: relative;
    padding: 13px 16px; border-bottom: 1px solid var(--border);
  }
  table.stack tr:last-child { border-bottom: none; }
  /* The label holds the left edge and every value sits together on the right,
     wrapping under itself rather than stretching across the row. */
  table.stack td {
    border: none; padding: 3px 0;
    display: flex; flex-wrap: wrap; align-items: baseline;
    justify-content: flex-end; gap: 2px 10px;
    text-align: right;
  }
  table.stack td::before {
    content: attr(data-label);
    flex: 0 0 auto; margin-right: auto; text-align: left;
    font-family: var(--font); font-size: .75rem; font-weight: 600;
    letter-spacing: 0; color: var(--muted);
  }
  table.stack td.name {
    display: block; text-align: left; font-size: 1rem; font-weight: 650;
    padding-right: 22px; padding-bottom: 7px;
  }
  table.stack td.name::before { display: none; }
  table.stack tr.clickable td.name::after {
    content: "\203A";
    position: absolute; right: 16px; top: 12px;
    color: var(--muted); font-size: 1.35rem; line-height: 1;
  }
  table.stack td.actions {
    justify-content: flex-end; padding-top: 10px;
  }
  table.stack td.actions::before { display: none; }
  table.stack td.actions form { display: inline-block; }
  table.stack td.empty { display: block; text-align: center; padding: 30px 16px; }
  table.stack td.empty::before { display: none; }
  table.stack td .muted { font-weight: 500; }
}

@media (max-width: 340px) {
  .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .tabbar a .lbl { font-size: .64rem; }
}

/* Motion is decoration here -- when the reader has asked for less of it,
   everything still lands in the same place, just immediately. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
