/* ==========================================================================
   OT 360° Client Dashboard — the fleet ledger
   One sheet per question, figures aligned, states stamped.
   Palette: the incumbent's (charcoal spine, blue action, cyan info, grey desk,
   Bootstrap semantics, OT red as the brand mark).
   ========================================================================== */

:root {
  /* surfaces */
  --ground: #f4f6f9;
  --sheet: #ffffff;
  --sheet-2: #f8f9fb;
  --sheet-3: #eef1f5;
  --rule: #e3e6ea;
  --rule-strong: #ccd2d9;

  /* ink */
  --ink: #212529;
  --ink-2: #495057;
  --ink-3: #5f6b78;
  --ink-4: #8a94a0;

  /* spine */
  --spine: #343a40;
  --spine-2: #2c3136;
  --spine-3: #3f464d;
  --spine-ink: #dee2e6;
  --spine-ink-2: #adb5bd;
  --spine-rule: rgba(255, 255, 255, 0.08);

  /* brand + actions */
  --brand: #d6182b;
  --brand-ink: #b3121f;
  --primary: #007bff;
  --primary-hover: #0069d9;
  --primary-ink: #0056b3;
  --primary-soft: #e7f1ff;
  --primary-soft-2: #cfe2ff;
  --info: #17a2b8;
  --info-ink: #117a8b;
  --info-soft: #e0f4f7;
  --success: #28a745;
  --success-ink: #1e7e34;
  --success-soft: #e6f4ea;
  --warning: #ffc107;
  --warning-ink: #8a6100;
  --warning-soft: #fff6d6;
  --danger: #dc3545;
  --danger-ink: #b02a37;
  --danger-soft: #fbe7e9;

  /* territory colours: the index tabs of the ledger, nothing else */
  --tab-home: #d6182b;
  --tab-drivers: #007bff;
  --tab-vehicles: #17a2b8;
  --tab-trips: #6610f2;
  --tab-history: #6610f2;
  --tab-routes: #20c997;
  --tab-employees: #6f42c1;
  --tab-attendance: #fd7e14;

  /* reports: the two directions (primary-ink and info, validated as a pair for colour-blind separation
     and contrast on the sheet) and the recency steps, one blue from light to dark (validated as an
     ordinal ramp, its light end above 2:1 on the sheet); --recency-0 is the faintest seat count */
  --dir-arrival: #0056b3;
  --dir-departure: #17a2b8;
  --recency-1: #003f87;
  --recency-2: #0067d6;
  --recency-3: #2b8fff;
  --recency-4: #73b6ff;
  --recency-0: #cfe2ff;

  /* type */
  --font: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", sans-serif;
  --fs-xs: 11px;
  --fs-sm: 12.5px;
  --fs: 13.5px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 22px;
  --fs-2xl: 30px;

  /* geometry */
  --radius: 6px;
  --radius-sm: 4px;
  --radius-lg: 10px;
  --spine-w: 250px;
  --spine-w-rail: 68px;
  --topbar-h: 56px;
  --page-x: 28px;

  --shadow-sheet: 0 1px 2px rgba(33, 37, 41, 0.05), 0 1px 1px rgba(33, 37, 41, 0.03);
  --shadow-raised: 0 4px 12px rgba(33, 37, 41, 0.08), 0 1px 3px rgba(33, 37, 41, 0.06);
  --shadow-pop: 0 12px 32px rgba(33, 37, 41, 0.18), 0 2px 6px rgba(33, 37, 41, 0.08);

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --t: 160ms;
}

/* ---------- reset + browser surfaces ---------- */

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

html { -webkit-text-size-adjust: 100%; scrollbar-color: #c3cad2 transparent; scrollbar-width: thin; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.5;
  color: var(--ink);
  background: var(--ground);
  accent-color: var(--primary);
  caret-color: var(--primary);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--primary-soft-2); color: var(--ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #c3cad2; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #aab3bd; }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--radius-sm); }

a { color: var(--primary-ink); text-decoration: none; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; text-wrap: balance; }
h2 { font-size: var(--fs-md); font-weight: 650; letter-spacing: -0.005em; line-height: 1.3; }
h3 { font-size: var(--fs); font-weight: 650; }

img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
table { border-collapse: separate; border-spacing: 0; }
[hidden] { display: none !important; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.rtl { direction: rtl; unicode-bidi: isolate; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.mono-id { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; color: var(--ink-2); }

.icon { flex: none; vertical-align: -0.2em; }

/* ---------- shell ---------- */

.app-shell { display: grid; grid-template-columns: var(--spine-w) minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns 220ms var(--ease); }
body.spine-rail .app-shell { grid-template-columns: var(--spine-w-rail) minmax(0, 1fr); }

.spine {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--spine); color: var(--spine-ink);
  overflow: hidden;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 14px 16px; height: var(--topbar-h); color: #fff; border-bottom: 1px solid var(--spine-rule); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 36px; height: 36px; border-radius: 50%; background: #fff; padding: 3px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.01em; }
.brand-sub { font-size: var(--fs-xs); color: var(--spine-ink-2); letter-spacing: 0.06em; text-transform: uppercase; }

.station-plate { display: flex; align-items: center; gap: 10px; margin: 14px 12px 6px; padding: 10px 12px; background: var(--spine-2); border: 1px solid var(--spine-rule); border-radius: var(--radius); color: var(--spine-ink); min-width: 0; }
.station-icon { color: var(--spine-ink-2); }
.station-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.station-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--spine-ink-2); }
.station-name { font-weight: 600; font-size: var(--fs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }

.nav { display: flex; flex-direction: column; padding: 8px 8px 16px; flex: 1; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--spine-3) transparent; }
.nav-group { padding: 14px 12px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--spine-ink-2); white-space: nowrap; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--radius); color: var(--spine-ink);
  font-weight: 500; white-space: nowrap;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.nav-item:hover { background: var(--spine-3); color: #fff; text-decoration: none; }
.nav-item.is-active { background: rgba(255, 255, 255, 0.1); color: #fff; font-weight: 600; }
.nav-icon { color: var(--spine-ink-2); transition: color var(--t); }
.nav-item:hover .nav-icon, .nav-item.is-active .nav-icon { color: #fff; }
/* the index tab: a small drawn tab on the sheet edge, in the section's territory colour */
.nav-tab { position: absolute; right: -8px; top: 50%; width: 5px; height: 22px; margin-top: -11px; border-radius: 3px 0 0 3px; background: transparent; transition: background var(--t), transform 220ms var(--ease); transform: translateX(6px); }
.nav-item.is-active .nav-tab { transform: translateX(0); }
.nav-item.is-active[data-section="home"] .nav-tab { background: var(--tab-home); }
.nav-item.is-active[data-section="drivers"] .nav-tab { background: var(--tab-drivers); }
.nav-item.is-active[data-section="vehicles"] .nav-tab { background: var(--tab-vehicles); }
.nav-item.is-active[data-section="trips"] .nav-tab { background: var(--tab-trips); }
.nav-item.is-active[data-section="history"] .nav-tab { background: var(--tab-history); }
.nav-item.is-active[data-section="routes"] .nav-tab { background: var(--tab-routes); }
.nav-item.is-active[data-section="employees"] .nav-tab { background: var(--tab-employees); }
.nav-item.is-active[data-section="attendance"] .nav-tab { background: var(--tab-attendance); }
.nav-item.is-active[data-section="reports"] .nav-tab { background: var(--tab-employees); }

.spine-foot { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--spine-rule); background: var(--spine-2); }
.spine-user { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.spine-user-name { font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--fs); }
.spine-signout { display: inline-flex; align-items: center; gap: 5px; color: var(--spine-ink-2); font-size: var(--fs-sm); }
.spine-signout:hover { color: #fff; text-decoration: none; }

.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: 0.02em; flex: none; }
.avatar-sm { width: 28px; height: 28px; font-size: 11.5px; }

/* rail (collapsed) */
body.spine-rail .brand-text, body.spine-rail .station-text, body.spine-rail .nav-label, body.spine-rail .nav-group span, body.spine-rail .spine-user { display: none; }
body.spine-rail .brand { justify-content: center; padding: 10px; }
body.spine-rail .station-plate { justify-content: center; padding: 10px 0; margin: 14px 12px 6px; }
body.spine-rail .nav-item { justify-content: center; padding: 10px; }
body.spine-rail .nav-group { padding: 10px 0 4px; height: 24px; }
body.spine-rail .nav-group::after { content: ""; display: block; width: 24px; height: 1px; margin: 4px auto; background: var(--spine-rule); }
body.spine-rail .spine-foot { justify-content: center; padding: 12px 8px; }

.spine-backdrop { position: fixed; inset: 0; background: rgba(33, 37, 41, 0.5); z-index: 39; backdrop-filter: blur(1px); }

.app-main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  height: var(--topbar-h); padding: 0 var(--page-x) 0 16px;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid transparent; border-radius: var(--radius); background: transparent; color: var(--ink-2); transition: background var(--t), color var(--t), border-color var(--t); }
.icon-btn:hover { background: var(--sheet-3); color: var(--ink); }

.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: var(--fs-sm); color: var(--ink-3); flex: 1; overflow: hidden; white-space: nowrap; }
.crumbs a { color: var(--ink-3); display: inline-flex; align-items: center; gap: 4px; }
.crumbs a:hover { color: var(--ink); text-decoration: none; }
.crumbs [aria-current] { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.crumb-sep { color: var(--ink-4); }

.topbar-right { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.today { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }

.page { flex: 1; width: 100%; max-width: 1480px; padding: 24px var(--page-x) 40px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
.page-sub { margin-top: 4px; color: var(--ink-3); font-size: var(--fs); max-width: 70ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.app-foot { display: flex; justify-content: space-between; gap: 12px; padding: 14px var(--page-x); border-top: 1px solid var(--rule); color: var(--ink-3); font-size: var(--fs-sm); background: var(--sheet-2); }
.app-foot-version { font-variant-numeric: tabular-nums; }

/* ---------- sheets ---------- */

.sheet { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow-sheet); }
.sheet + .sheet { margin-top: 20px; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.sheet-head h2 { display: flex; align-items: center; gap: 8px; }
.sheet-head .count { color: var(--ink-3); font-weight: 500; font-variant-numeric: tabular-nums; }
.sheet-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.sheet-body { padding: 18px; }
.sheet-body.is-flush { padding: 0; }
.sheet-foot { padding: 12px 18px; border-top: 1px solid var(--rule); background: var(--sheet-2); border-radius: 0 0 var(--radius) var(--radius); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.grid-2 > .sheet, .grid-3 > .sheet { margin-top: 0; }
.stack > * + * { margin-top: 20px; }

/* ---------- summary line (home) ---------- */

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow-sheet); overflow: hidden; }
.summary-cell { display: block; padding: 18px 20px 16px; color: inherit; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin-bottom: -1px; transition: background var(--t); }
.summary-cell:hover { background: var(--sheet-2); text-decoration: none; }
.summary-value { font-size: var(--fs-2xl); font-weight: 650; line-height: 1.1; letter-spacing: -0.02em; color: var(--ink); font-variant-numeric: tabular-nums; min-width: 3ch; }
.summary-label { margin-top: 6px; font-size: var(--fs); font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.summary-note { margin-top: 6px; font-size: var(--fs-sm); color: var(--ink-3); display: flex; align-items: center; gap: 5px; }
.summary-note.is-warn { color: var(--warning-ink); }
.summary-note.is-danger { color: var(--danger-ink); }
.summary-note.is-good { color: var(--success-ink); }
.summary-note.is-info { color: var(--primary-ink); }

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

.ledger-wrap { overflow-x: auto; overscroll-behavior-x: contain; }
.ledger { width: 100%; font-size: var(--fs); }
.ledger th {
  position: sticky; top: 0; z-index: 1;
  padding: 10px 9px; background: var(--sheet-2);
  font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3);
  text-align: left; white-space: nowrap; border-bottom: 1px solid var(--rule-strong);
}
.ledger th.num, .ledger td.num { text-align: right; font-variant-numeric: tabular-nums; }
.ledger td { padding: 9px 9px; border-bottom: 1px solid var(--rule); vertical-align: middle; white-space: nowrap; }
.ledger td.wrap { white-space: normal; min-width: 220px; max-width: 420px; }
.ledger td.col-name { min-width: 160px; }
.ledger td.col-point { white-space: normal; min-width: 150px; max-width: 300px; }
.ledger tbody tr:last-child td { border-bottom-color: transparent; }
.ledger .export-only { display: none; }   /* in the CSV only : the visible cell keeps its sub-line */
.ledger .col-line { width: 1px; color: var(--ink-3); font-variant-numeric: tabular-nums; border-right: 1px solid var(--rule); background: var(--sheet); }
.ledger th.col-line { background: var(--sheet-2); }
.ledger tbody tr { transition: background var(--t); }
.ledger tbody tr:hover td { background: #f3f8ff; }
.ledger tr[data-href] { cursor: pointer; }
.ledger tr[data-href]:hover .row-link { text-decoration: underline; }
.ledger .row-actions { white-space: nowrap; text-align: right; padding-left: 4px; }
.ledger .row-actions form { display: inline-block; }
.ledger .cell-primary { font-weight: 600; color: var(--ink); }
.ledger .cell-sub { display: block; font-size: var(--fs-sm); color: var(--ink-3); font-weight: 400; margin-top: 1px; }
.ledger th[data-sort] { cursor: pointer; user-select: none; }
.ledger th[data-sort]:hover { color: var(--ink); }
.ledger th[data-sort]::after { content: ""; display: inline-block; width: 0; height: 0; margin-left: 6px; border: 4px solid transparent; border-top-color: var(--ink-4); vertical-align: -3px; opacity: 0.6; }
.ledger th[aria-sort="ascending"]::after { border-top-color: transparent; border-bottom-color: var(--primary); vertical-align: 2px; opacity: 1; }
.ledger th[aria-sort="descending"]::after { border-top-color: var(--primary); opacity: 1; }
.ledger.is-compact td { padding: 7px 10px; }
.ledger .empty-row td { padding: 40px 18px; text-align: center; color: var(--ink-3); }

.table-toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.table-toolbar .search { position: relative; flex: 1 1 220px; max-width: 360px; }
.table-toolbar .search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-4); pointer-events: none; }
.table-toolbar .search input { padding-left: 32px; width: 100%; }
.table-toolbar .spacer { flex: 1; }
.table-count { color: var(--ink-3); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }

.pager { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.pager button { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 8px; border: 1px solid var(--rule-strong); background: var(--sheet); border-radius: var(--radius-sm); color: var(--ink-2); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.pager button:hover:not([disabled]) { background: var(--sheet-2); color: var(--ink); }
.pager button[disabled] { opacity: 0.4; cursor: default; }
.pager button.is-current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager .pager-info { font-size: var(--fs-sm); color: var(--ink-3); font-variant-numeric: tabular-nums; margin-right: 6px; }

/* filter tabs (the ledger's thumb index) */
.tabs { display: flex; gap: 2px; padding: 0 18px; border-bottom: 1px solid var(--rule); overflow-x: auto; overflow-y: hidden; }   /* the tabs' -1px overlap no longer raises a vertical scrollbar */
.tab { display: inline-flex; align-items: center; gap: 8px; padding: 12px 12px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--ink-3); font-weight: 600; font-size: var(--fs); white-space: nowrap; transition: color var(--t), border-color var(--t); }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--primary); }
.tab .tab-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--sheet-3); color: var(--ink-2); font-size: var(--fs-xs); font-weight: 700; font-variant-numeric: tabular-nums; }
.tab.is-active .tab-count { background: var(--primary-soft); color: var(--primary-ink); }
.tab .tab-count.is-warn { background: var(--warning-soft); color: var(--warning-ink); }
.tab .tab-count.is-danger { background: var(--danger-soft); color: var(--danger-ink); }

/* ---------- stamps ---------- */

.stamp { display: inline-flex; align-items: center; gap: 5px; padding: 1px 7px; border-radius: var(--radius-sm); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; line-height: 18px; white-space: nowrap; border: 1px solid transparent; }
.stamp-success { color: var(--success-ink); background: var(--success-soft); border-color: rgba(40, 167, 69, 0.35); }
.stamp-danger { color: var(--danger-ink); background: var(--danger-soft); border-color: rgba(220, 53, 69, 0.35); }
.stamp-warning { color: var(--warning-ink); background: var(--warning-soft); border-color: rgba(255, 193, 7, 0.55); }
.stamp-info { color: var(--info-ink); background: var(--info-soft); border-color: rgba(23, 162, 184, 0.35); }
.stamp-primary { color: var(--primary-ink); background: var(--primary-soft); border-color: rgba(0, 123, 255, 0.35); }
.stamp-muted { color: var(--ink-3); background: var(--sheet-3); border-color: var(--rule-strong); }
.stamp-dashed { color: var(--ink-3); background: transparent; border: 1px dashed var(--rule-strong); }
.stamp-lg { font-size: var(--fs-sm); padding: 4px 10px; line-height: 20px; }

.expiry { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ledger .expiry { flex-direction: column; align-items: flex-start; gap: 3px; }
.ledger .col-decision { min-width: 140px; }
.ledger .cell-reason { display: none; white-space: normal; max-width: 220px; color: var(--danger-ink); }
.ledger td.col-reason { white-space: normal; min-width: 130px; max-width: 200px; color: var(--danger-ink); }
.ledger td.col-reason .muted { color: var(--ink-4); }
.expiry.is-expired .expiry-date { color: var(--danger-ink); text-decoration: line-through; text-decoration-color: rgba(220, 53, 69, 0.5); }
.expiry.is-expiring .expiry-date { color: var(--warning-ink); font-weight: 600; }
.expiry.is-valid .expiry-date { color: var(--ink-2); }

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

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border: 1px solid transparent; border-radius: var(--radius); font-weight: 600; font-size: var(--fs); line-height: 1; white-space: nowrap; text-decoration: none; transition: background var(--t) var(--ease), border-color var(--t), color var(--t), box-shadow var(--t), transform var(--t); }
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--sheet); color: var(--ink-2); border-color: var(--rule-strong); }
.btn-secondary:hover { background: var(--sheet-2); color: var(--ink); border-color: #b9c1ca; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #218838; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c82333; }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger-ink); border-color: rgba(220, 53, 69, 0.25); }
.btn-danger-soft:hover { background: #f8d7da; }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-ink); }
.btn-ghost { background: transparent; color: var(--primary-ink); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-sm); gap: 6px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5); border-top-color: #fff; animation: spin 0.7s linear infinite; }
.btn-secondary.is-loading::after { border-color: rgba(0, 0, 0, 0.2); border-top-color: var(--ink-2); }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-group { display: inline-flex; gap: 8px; flex-wrap: wrap; }

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

.form { display: grid; gap: 16px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.field .req { color: var(--danger); margin-left: 2px; }
.input, .select, .textarea { width: 100%; min-height: 38px; padding: 0 12px; border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--sheet); color: var(--ink); transition: border-color var(--t), box-shadow var(--t); }
.textarea { padding: 9px 12px; min-height: 96px; resize: vertical; line-height: 1.5; }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235f6b78' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px; }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:hover, .select:hover, .textarea:hover { border-color: #b9c1ca; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input[disabled], .select[disabled] { background: var(--sheet-2); color: var(--ink-3); cursor: not-allowed; }
.field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .textarea { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.hint { font-size: var(--fs-sm); color: var(--ink-3); }
.error-text { font-size: var(--fs-sm); color: var(--danger-ink); display: flex; align-items: center; gap: 5px; }
.form-foot { display: flex; align-items: center; gap: 10px; padding-top: 6px; flex-wrap: wrap; }
.input-inline { display: inline-flex; align-items: center; gap: 8px; }
.input-sm { min-height: 32px; padding: 0 10px; font-size: var(--fs-sm); }
.input-date { max-width: 170px; font-variant-numeric: tabular-nums; }

.file-drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 26px 18px; border: 1.5px dashed var(--rule-strong); border-radius: var(--radius); background: var(--sheet-2); color: var(--ink-3); text-align: center; cursor: pointer; transition: border-color var(--t), background var(--t); }
.file-drop:hover, .file-drop.is-over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-ink); }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-drop strong { color: var(--ink); }
.file-drop .file-name { font-weight: 600; color: var(--ink); }
.file-drop.has-file { border-style: solid; border-color: var(--success); background: var(--success-soft); color: var(--success-ink); }

/* notes / callouts */
.note { display: flex; gap: 10px; padding: 12px 14px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--sheet-2); color: var(--ink-2); font-size: var(--fs); }
.note .icon { margin-top: 2px; flex: none; }
.note-info { background: var(--primary-soft); border-color: rgba(0, 123, 255, 0.2); color: var(--primary-ink); }
.note-warning { background: var(--warning-soft); border-color: rgba(255, 193, 7, 0.4); color: var(--warning-ink); }
.note-danger { background: var(--danger-soft); border-color: rgba(220, 53, 69, 0.25); color: var(--danger-ink); }
.note-success { background: var(--success-soft); border-color: rgba(40, 167, 69, 0.25); color: var(--success-ink); }
.note ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- record (detail) layouts ---------- */

.record { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start; }
.record > .sheet { margin-top: 0; }
.record-aside { position: sticky; top: calc(var(--topbar-h) + 20px); }

.profile { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 24px 18px 18px; border-bottom: 1px solid var(--rule); }
.profile-photo { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; border: 3px solid var(--sheet); box-shadow: 0 0 0 1px var(--rule-strong); margin-bottom: 12px; background: var(--sheet-3); }
.profile-avatar { width: 84px; height: 84px; font-size: 26px; margin-bottom: 12px; background: var(--sheet-3); color: var(--ink-2); box-shadow: 0 0 0 1px var(--rule-strong); }
.profile h2 { font-size: var(--fs-lg); }
.profile .profile-id { margin-top: 2px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.profile .stamp { margin-top: 10px; }

.facts { margin: 0; padding: 6px 18px; }
.facts > div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--rule); }
.facts > div:last-child { border-bottom: 0; }
.facts dt { color: var(--ink-3); font-size: var(--fs-sm); font-weight: 500; }
.facts dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }

.decision { padding: 14px 18px 18px; border-top: 1px solid var(--rule); background: var(--sheet-2); border-radius: 0 0 var(--radius) var(--radius); }
.decision-title { font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 10px; }
.decision .btn-group { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.decision-note { margin-top: 10px; font-size: var(--fs-sm); color: var(--ink-3); }
.decision-reason { margin-top: 10px; padding: 10px 12px; background: var(--danger-soft); border-radius: var(--radius-sm); color: var(--danger-ink); font-size: var(--fs); }

/* document gallery */
.doc-group { padding: 18px; border-bottom: 1px solid var(--rule); }
.doc-group:last-child { border-bottom: 0; }
.doc-group-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.doc-group-head h3 { font-size: var(--fs-md); }
.doc-group-head .doc-arabic { color: var(--ink-3); font-size: var(--fs); }
.doc-group-head .expiry { margin-left: auto; }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.doc { position: relative; display: block; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; background: var(--sheet-2); transition: box-shadow var(--t), transform var(--t), border-color var(--t); }
.doc:hover { box-shadow: var(--shadow-raised); transform: translateY(-1px); border-color: var(--rule-strong); }
.doc img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--sheet-3); }
.doc-cap { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); border-top: 1px solid var(--rule); background: var(--sheet); }
.doc-cap .icon { color: var(--ink-4); }
.doc.is-missing { border-style: dashed; cursor: default; }
.doc.is-missing:hover { box-shadow: none; transform: none; }
.doc-missing { display: grid; place-items: center; aspect-ratio: 4 / 3; color: var(--ink-4); font-size: var(--fs-sm); gap: 6px; }

/* ---------- stop-line diagram ---------- */

.line { list-style: none; margin: 0; padding: 0; }
.line li { position: relative; display: grid; grid-template-columns: 62px 30px minmax(0, 1fr) auto; gap: 0 12px; align-items: start; padding: 10px 0; }
.line .stop-time { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 600; padding-top: 2px; font-size: var(--fs); }
.line .stop-time .planned { display: block; color: var(--ink-4); font-weight: 400; font-size: var(--fs-xs); text-decoration: line-through; }
.line .node { position: relative; height: 100%; min-height: 24px; }
.line .node::before { content: ""; position: absolute; left: 14px; top: -10px; bottom: -10px; width: 2px; background: var(--spine); }
.line li:first-child .node::before { top: 12px; }
.line li:last-child .node::before { bottom: auto; height: calc(100% - 4px); }
.line li:only-child .node::before { display: none; }
.line .dot { position: absolute; left: 9px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--sheet); border: 2px solid var(--spine); z-index: 1; }
.line .dot.is-done { background: var(--spine); }
.line .dot.is-terminal { left: 7px; top: 4px; width: 16px; height: 16px; border-width: 3px; }
.line .dot.is-skipped { border-color: var(--ink-4); border-style: dashed; }
.line .dot.is-current { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.line-legend i.is-current { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.trip-line { padding: 6px 18px 10px; }
.trip-line .stop-name { color: var(--ink); }
.trip-line .stop-name:hover { color: var(--primary-ink); }
.trip-line li { padding: 8px 0; }
.line .stop-body { min-width: 0; }
.line .stop-name { font-weight: 600; overflow-wrap: anywhere; }
.line .stop-meta { color: var(--ink-3); font-size: var(--fs-sm); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.line .stop-side { text-align: right; padding-top: 2px; }
.line.is-compact li { padding: 6px 0; grid-template-columns: 52px 26px minmax(0, 1fr) auto; }
.line.is-compact .node::before { left: 12px; }
.line.is-compact .dot { left: 7px; }
.line.is-compact .dot.is-terminal { left: 5px; }
.line.no-time li { grid-template-columns: 26px minmax(0, 1fr) auto; }
.line-legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--ink-3); font-size: var(--fs-sm); }
.line-legend span { display: inline-flex; align-items: center; gap: 6px; }
.line-legend i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--spine); background: var(--sheet); display: inline-block; }
.line-legend i.is-done { background: var(--spine); }

/* review list */
.review-list { display: flex; flex-direction: column; }
.review-list a { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--rule); color: inherit; transition: background var(--t); }
.review-list a:last-child { border-bottom: 0; }
.review-list a:hover { background: var(--sheet-2); text-decoration: none; }
.review-list .review-body { min-width: 0; flex: 1; }
.review-list .review-name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.review-list .review-meta { display: block; font-size: var(--fs-sm); color: var(--ink-3); }
.review-list .review-kind { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius); background: var(--sheet-3); color: var(--ink-2); flex: none; }
.review-list .icon-arrow { color: var(--ink-4); }

/* ---------- bars chart ---------- */

.bars { width: 100%; height: auto; display: block; font-family: var(--font); }
.bars .grid line { stroke: var(--rule); stroke-width: 1; }
.bars .axis text { fill: var(--ink-3); font-size: 11px; }
.bars .bar { fill: var(--primary); }
.bars .bar.is-today { fill: var(--primary-ink); }
.bars .bar.is-zero { fill: var(--sheet-3); }
.bars .bar-hit { fill: transparent; }
.bars .bar-hit:hover + .bar, .bars g:hover .bar { fill: var(--primary-hover); }
.bars .value { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
.chart-tip { position: fixed; z-index: 60; pointer-events: none; padding: 6px 10px; background: var(--ink); color: #fff; font-size: var(--fs-sm); border-radius: var(--radius-sm); box-shadow: var(--shadow-pop); white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); opacity: 0; transition: opacity var(--t); }
.chart-tip.is-visible { opacity: 1; }
.chart-tip.data-tip { display: grid; gap: 1px; padding: 8px 11px; line-height: 1.35; }
.chart-tip.data-tip.is-below { transform: translate(-50%, 18px); }
.chart-tip .tip-title { margin-bottom: 3px; color: rgba(255, 255, 255, 0.72); font-size: var(--fs-xs); font-weight: 600; }
.chart-tip .tip-row { color: rgba(255, 255, 255, 0.86); }
.chart-tip .tip-row b { color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- dialogs ---------- */

.dlg { border: 0; padding: 0; width: min(480px, calc(100vw - 32px)); border-radius: var(--radius-lg); background: var(--sheet); color: var(--ink); box-shadow: var(--shadow-pop); }
.dlg::backdrop { background: rgba(33, 37, 41, 0.45); backdrop-filter: blur(2px); }
.dlg[open] { animation: dlg-in 180ms var(--ease); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(6px) scale(0.985); } to { opacity: 1; transform: none; } }
.dlg-head { padding: 18px 20px 6px; }
.dlg-title { font-size: var(--fs-lg); font-weight: 650; }
.dlg-body { padding: 10px 20px 16px; display: grid; gap: 14px; }
.dlg-text { color: var(--ink-2); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.dlg-lightbox { width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 32px); background: #14171a; padding: 0; }
.dlg-lightbox img { width: 100%; max-height: calc(100vh - 32px); object-fit: contain; }
.lightbox-close { position: absolute; top: 10px; right: 10px; background: rgba(255, 255, 255, 0.12); color: #fff; }
.lightbox-close:hover { background: rgba(255, 255, 255, 0.24); color: #fff; }
.lightbox-open { position: absolute; left: 12px; bottom: 12px; }

/* ---------- toast ---------- */

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 70; display: flex; align-items: center; gap: 10px; max-width: min(420px, calc(100vw - 48px)); padding: 12px 14px; border-radius: var(--radius); background: var(--ink); color: #fff; box-shadow: var(--shadow-pop); animation: toast-in 220ms var(--ease); }
.toast .icon { flex: none; }
.toast-success .icon-check-circle { color: #6fd58c; }
.toast-error .icon-alert-circle { color: #ff8a95; }
.toast-info .icon-info { color: #7cc0ff; }
.toast-text { flex: 1; }
.toast-close { background: transparent; border: 0; color: rgba(255, 255, 255, 0.7); display: grid; place-items: center; width: 24px; height: 24px; border-radius: 4px; }
.toast-close:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }
.toast.is-leaving { animation: toast-out 220ms var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- empty states ---------- */

.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 44px 24px; text-align: center; color: var(--ink-3); }
.empty .icon { color: var(--ink-4); }
.empty h3 { color: var(--ink-2); font-size: var(--fs-md); }
.empty p { max-width: 44ch; }

/* ---------- inline lists ---------- */

.kv { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: var(--fs); color: var(--ink-2); }
.kv span b { color: var(--ink); font-weight: 600; }

.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.check-list li { display: flex; align-items: center; gap: 8px; }
.check-list .icon-check { color: var(--success-ink); }
.check-list .icon-x { color: var(--danger-ink); }

/* ---------- login ---------- */

body.bare { min-height: 100vh; }
body.login { display: grid; place-items: center; padding: 24px; background: linear-gradient(-135deg, #d6182b, #000); }
.login-sheet { width: min(940px, 100%); display: grid; grid-template-columns: 1.05fr 1fr; background: var(--sheet); border-radius: 14px; overflow: hidden; box-shadow: 0 28px 70px rgba(0, 0, 0, 0.42); }
.login-side { position: relative; display: flex; flex-direction: column; justify-content: space-between; padding: 40px; background: #1b1e21; color: #fff; overflow: hidden; }
.login-side::before { content: ""; position: absolute; inset: auto -120px -160px auto; width: 420px; height: 420px; border-radius: 50%; border: 56px solid rgba(214, 24, 43, 0.14); }
.login-side::after { content: ""; position: absolute; left: 40px; right: 40px; top: 118px; height: 1px; background: rgba(255, 255, 255, 0.1); }
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-brand img { width: 52px; height: 52px; border-radius: 50%; background: #fff; padding: 4px; }
.login-brand-name { font-size: 20px; font-weight: 700; letter-spacing: 0.01em; }
.login-brand-sub { display: block; font-size: var(--fs-sm); color: #adb5bd; letter-spacing: 0.08em; text-transform: uppercase; }
.login-pitch { position: relative; margin-top: 56px; }
.login-pitch h2 { font-size: 24px; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; max-width: 18ch; }
.login-pitch .line { margin-top: 26px; }
.login-pitch .line li { padding: 6px 0; grid-template-columns: 26px minmax(0, 1fr); }
.login-pitch .line .node::before { background: rgba(255, 255, 255, 0.35); left: 11px; }
.login-pitch .line .dot { left: 6px; border-color: #fff; background: #1b1e21; }
.login-pitch .line .dot.is-done { background: var(--brand); border-color: var(--brand); }
.login-pitch .line .stop-name { color: #fff; font-weight: 500; }
.login-pitch .line .stop-meta { color: #adb5bd; }
.login-foot { position: relative; color: #868e96; font-size: var(--fs-sm); }
.login-form-wrap { padding: 44px 44px 36px; display: flex; flex-direction: column; justify-content: center; }
.login-form-wrap h1 { font-size: var(--fs-xl); }
.login-form-wrap .lead { margin-top: 6px; color: var(--ink-3); }
.login-form { margin-top: 26px; }
.login-form .btn-brand { margin-top: 6px; }
.login-note { margin-top: 22px; color: var(--ink-3); font-size: var(--fs-sm); }

/* ---------- error pages ---------- */

body.errorpage { display: grid; place-items: center; padding: 24px; }
.error-sheet { width: min(520px, 100%); padding: 36px 34px; text-align: center; }
.error-sheet .error-code { font-size: 46px; font-weight: 700; letter-spacing: -0.03em; color: var(--ink-4); line-height: 1; }
.error-sheet h1 { margin-top: 10px; }
.error-sheet p { margin-top: 10px; color: var(--ink-3); }
.error-sheet .btn { margin-top: 22px; }
.error-sheet pre { margin-top: 18px; text-align: left; font-size: 12px; white-space: pre-wrap; background: var(--sheet-2); padding: 12px; border-radius: var(--radius); color: var(--ink-2); overflow: auto; }

/* ---------- map ---------- */

.map { width: 100%; height: 440px; background: var(--sheet-3); border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- reports ---------- */

/* the period switch: the one filter row, above everything it scopes */
.report-bar { display: flex; align-items: center; gap: 10px 18px; flex-wrap: wrap; margin: -4px 0 16px; }
.periods { display: inline-flex; gap: 2px; padding: 3px; background: var(--sheet); border: 1px solid var(--rule-strong); border-radius: var(--radius); }
.period { display: inline-flex; align-items: center; justify-content: center; height: 30px; padding: 0 12px; border-radius: var(--radius-sm); color: var(--ink-2); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; transition: background var(--t), color var(--t); }
.period:hover { background: var(--sheet-2); color: var(--ink); text-decoration: none; }
.period.is-active { background: var(--primary); color: #fff; }
.report-range { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--ink-3); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.report-range b { color: var(--ink-2); font-weight: 600; }

/* keys: the swatches legends and notes share */
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.key-arrival { background: var(--dir-arrival); }
.key-departure { background: var(--dir-departure); }
.key-ahead { background: rgba(0, 86, 179, 0.12); border: 1px dashed var(--dir-arrival); }
.key-notrip { background: var(--warning); }
.key-requested { border: 1px dashed var(--dir-arrival); }
.key-off { background: var(--sheet); border: 1px solid var(--rule); }
.summary-note .key { margin-right: 1px; }
.summary-note.dir-split { flex-wrap: wrap; gap: 2px 12px; }
.dir-split > span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0; padding: 0; list-style: none; color: var(--ink-3); font-size: var(--fs-sm); }
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.report-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 20px; align-items: start; margin-top: 20px; }
.report-grid > .sheet { margin-top: 0; }
.report-grid + .sheet { margin-top: 20px; }

/* the seats sheet shows one view at a time: per day (or week), or by weekday and time */
.view-switch { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--sheet); }
.view-switch button { height: 26px; padding: 0 10px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; transition: background var(--t), color var(--t); }
.view-switch button:hover { background: var(--sheet-2); color: var(--ink); }
.view-switch button[aria-selected="true"] { background: var(--primary-soft); color: var(--primary-ink); }

/* seats per day: arrival under departure, a 2px sheet gap between them, the booked-ahead zone dashed */
.chart-body { padding: 12px 14px 6px; }
.bars .seg-arrival { fill: var(--dir-arrival); }
.bars .seg-departure { fill: var(--dir-departure); }
.bars .is-ahead .seg-arrival { fill: rgba(0, 86, 179, 0.12); stroke: var(--dir-arrival); stroke-width: 1; stroke-dasharray: 3 2; }
.bars .is-ahead .seg-departure { fill: rgba(23, 162, 184, 0.14); stroke: var(--dir-departure); stroke-width: 1; stroke-dasharray: 3 2; }
.bars .bar-zero { fill: var(--sheet-3); }
.bars .seg-notrip { fill: var(--warning); }
.bars .baseline { stroke: var(--rule-strong); stroke-width: 1; }
.bars .zone-rule { stroke: var(--rule-strong); stroke-width: 1; }
.bars .zone-label { fill: var(--ink-3); font-size: 11px; font-weight: 600; }
.bars .tick { fill: var(--ink-3); font-size: 11px; }
.bars .tick.is-today { fill: var(--ink); font-weight: 650; }
.bars .col { outline: none; cursor: default; }
.bars .col:hover .bar-hit, .bars .col:focus-visible .bar-hit { fill: rgba(0, 123, 255, 0.06); }
.bars .col:focus-visible .bar-hit { stroke: var(--primary); stroke-width: 1.5; }
.bars .col:hover .seg, .bars .col:focus-visible .seg { filter: brightness(1.15); }

.table-view { display: block; padding: 0; }
.table-view > summary { display: inline-flex; align-items: center; gap: 6px; padding: 11px 18px; color: var(--primary-ink); font-size: var(--fs-sm); font-weight: 600; cursor: pointer; list-style: none; }
.table-view > summary::-webkit-details-marker { display: none; }
.table-view > summary:hover { text-decoration: underline; }
.table-view .ledger-wrap { max-height: 300px; overflow: auto; border-top: 1px solid var(--rule); background: var(--sheet); border-radius: 0 0 var(--radius) var(--radius); }

/* by weekday and time: shaded on the seat-count ramp, counts in the cells; days without service ruled off */
.heat { width: 100%; padding: 8px 12px 12px; border-collapse: separate; border-spacing: 3px; font-size: var(--fs-sm); }
.heat th { padding: 4px 6px; color: var(--ink-3); font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.06em; text-align: center; text-transform: uppercase; white-space: nowrap; }
.heat th abbr { text-decoration: none; }
.heat thead th.is-off { color: var(--ink-4); text-decoration: line-through; text-decoration-color: var(--rule-strong); }
.heat tbody th, .heat tfoot th { padding-left: 0; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 600; letter-spacing: 0; text-align: left; text-transform: none; }
.heat tbody th .key { margin-right: 7px; }
.heat tbody th .muted { font-weight: 400; }
.heat td { height: 26px; min-width: 36px; padding: 0 4px; border-radius: var(--radius-sm); background: var(--sheet-2); color: var(--ink); font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums; text-align: center; }
.heat td.is-off { background: transparent; box-shadow: inset 0 0 0 1px var(--rule); }
.heat td.h1 { background: var(--recency-0); }
.heat td.h2 { background: var(--recency-4); }
.heat td.h3 { background: var(--recency-3); }
.heat td.h4 { background: var(--recency-2); color: #fff; }
.heat td.h5 { background: var(--recency-1); color: #fff; }
.heat td[data-tip]:hover { box-shadow: inset 0 0 0 2px var(--ink); }
.heat td.total, .heat tfoot td { background: transparent; color: var(--ink-2); text-align: right; box-shadow: none; }
.heat tr.heat-gap td { height: 4px; padding: 0; background: transparent; box-shadow: none; }
.heat tfoot th, .heat tfoot td { padding-top: 6px; color: var(--ink); font-weight: 650; }

/* routes ranked by seats; a route opens to its stop-line with the seats at each stop */
.route-rank { list-style: none; margin: 0; padding: 0; }
.route-rank > li + li { border-top: 1px solid var(--rule); }
.rr > summary { list-style: none; }
.rr > summary::-webkit-details-marker { display: none; }
.rr-head { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto 16px; align-items: center; gap: 12px; padding: 9px 18px; cursor: pointer; transition: background var(--t); }
.rr-head:hover, .rr[open] > .rr-head { background: var(--sheet-2); }
.rr-head:focus-visible { outline-offset: -2px; }
.rr-rank { color: var(--ink-4); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; text-align: right; }
.rr-main { display: grid; gap: 4px; min-width: 0; }
.rr-name { overflow: hidden; color: var(--ink); font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.rr-bar { display: flex; gap: 2px; height: 8px; }
.rr-bar i { display: block; height: 100%; }
.rr-bar i:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.rr-bar .is-arrival { background: var(--dir-arrival); }
.rr-bar .is-departure { background: var(--dir-departure); }
.rr-meta { overflow: hidden; color: var(--ink-3); font-size: var(--fs-sm); white-space: nowrap; text-overflow: ellipsis; }
.rr-figs { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.rr-seats { color: var(--ink); font-size: var(--fs-md); font-weight: 650; font-variant-numeric: tabular-nums; }
.rr-change { color: var(--ink-3); font-size: var(--fs-xs); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rr-change.is-good { color: var(--success-ink); }
.rr-chevron { color: var(--ink-4); transition: transform var(--t) var(--ease); }
.rr[open] .rr-chevron { transform: rotate(180deg); }
.rr-body { padding: 2px 18px 12px 48px; background: var(--sheet-2); border-top: 1px solid var(--rule); }
.rr-facts { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 0 2px; color: var(--ink-3); font-size: var(--fs-sm); }
.rr-facts > span { display: inline-flex; align-items: center; gap: 6px; }
.rr-facts b { color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; }
.route-more { border-top: 1px solid var(--rule); }
.route-more > summary { display: flex; align-items: center; gap: 6px; padding: 10px 18px; color: var(--primary-ink); font-size: var(--fs-sm); font-weight: 600; cursor: pointer; list-style: none; }
.route-more > summary::-webkit-details-marker { display: none; }
.route-more > summary:hover { text-decoration: underline; }
.route-more[open] > summary { display: none; }
.route-more > .route-rank { border-top: 0; }
.line.stop-bars li { grid-template-columns: 26px minmax(0, 1fr) minmax(110px, 38%); }
.stop-bars .stop-side { padding-top: 3px; }
.pair { display: grid; gap: 3px; width: 100%; }
.pair-row { display: grid; grid-template-columns: minmax(0, 1fr) 28px; align-items: center; gap: 6px; }
.pair-row i { display: block; height: 6px; border-radius: 0 2px 2px 0; }
.pair-row .is-arrival { background: var(--dir-arrival); }
.pair-row .is-departure { background: var(--dir-departure); }
.pair-row b { color: var(--ink-2); font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }

/* the register: the ladder, its people as squares, the weekly count, then one row per active account */
.register-overview { display: grid; grid-template-columns: 300px minmax(0, 1fr) 300px; gap: 28px; padding: 18px; border-bottom: 1px solid var(--rule); align-items: start; }
.register-overview h3 { color: var(--ink); font-size: var(--fs); }
.ladder-sub, .riders-week figcaption span { display: block; margin-top: 2px; color: var(--ink-3); font-size: var(--fs-sm); }
.ladder-list { display: grid; margin-top: 12px; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.ladder-chip { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto 34px; align-items: center; gap: 9px; min-height: 34px; padding: 6px 10px; border: 0; background: var(--sheet); color: var(--ink-2); font-size: var(--fs-sm); text-align: left; transition: background var(--t), color var(--t); }
.ladder-chip + .ladder-chip { border-top: 1px solid var(--rule); }
.ladder-chip:hover:not([disabled]) { background: var(--sheet-2); color: var(--ink); }
.ladder-chip.is-active { background: var(--primary-soft); color: var(--primary-ink); box-shadow: inset 2px 0 0 var(--primary); }
.ladder-chip[disabled] { cursor: default; }
.ladder-chip[disabled] .ladder-chip-label, .ladder-chip[disabled] b { color: var(--ink-4); }
.ladder-chip .tile { width: 14px; height: 14px; }
.ladder-chip b { color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.ladder-chip-pct { color: var(--ink-3); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; text-align: right; }
.mosaic-wrap { min-width: 0; padding-top: 2px; }
.mosaic { display: flex; flex-wrap: wrap; gap: 3px; padding: 4px; margin: -4px; border-radius: var(--radius); }
.mosaic:focus-visible { outline-offset: 0; }
.mosaic-hint { margin-top: 10px; color: var(--ink-3); font-size: var(--fs-sm); }
.tile { display: inline-block; flex: none; width: 14px; height: 14px; border-radius: var(--radius-sm); }
.mosaic.is-roomy .tile { width: 18px; height: 18px; }
.mosaic.is-dense { gap: 2px; }
.mosaic.is-dense .tile { width: 11px; height: 11px; border-radius: 2px; }
.step-recent { background: var(--recency-1); }
.step-quiet_week { background: var(--recency-2); }
.step-quiet_month { background: var(--recency-3); }
.step-quiet_long { background: var(--recency-4); }
.step-never_booked { background: var(--sheet-3); border: 1px solid var(--rule-strong); }
.step-never_signed_in { background: var(--sheet); border: 1.5px dashed var(--ink-4); }
.mosaic .tile { cursor: pointer; transition: opacity 200ms var(--ease), transform var(--t) var(--ease); }
.mosaic .tile:hover { transform: scale(1.25); }
.mosaic .tile.is-cursor, .reg i.is-cursor { outline: 2px solid var(--ink); outline-offset: 1px; }
.mosaic.is-narrowed .tile:not(.is-match) { opacity: 0.18; }
.riders-week { margin: 0; }
.week-chart { margin-top: 12px; }
.week-chart .seg-week { fill: var(--primary); }
.week-chart .col.is-today .seg-week { fill: var(--primary-ink); }
.week-chart .ref { stroke: var(--ink-4); stroke-width: 1; }
.week-chart .ref-label { fill: var(--ink-3); font-size: 11px; }

.tab .tab-new { display: inline-grid; place-items: center; height: 20px; margin-left: -4px; padding: 0 7px; border-radius: 10px; background: var(--primary); color: #fff; font-size: var(--fs-xs); font-weight: 700; }
.table-toolbar .reg-legend { order: 5; flex-basis: 100%; gap: 4px 14px; font-size: var(--fs-xs); }   /* its own line: the search keeps its width */
.register-table .col-name { min-width: 170px; }
.register-table .cell-primary { display: block; }
.register-table .stamp .tile { width: 9px; height: 9px; border-radius: 2px; }
.register-table .lit-note { color: var(--primary-ink); font-weight: 600; }
.register-table .no-app { color: var(--ink-3); }
.register-table .stamp-inline { display: none; }
.register-table td.reg-cell, .register-table th.reg-head { padding-top: 7px; padding-bottom: 7px; }
.reg { --cw: 8px; display: grid; grid-template-columns: repeat(var(--n), var(--cw)); gap: 2px; }
.reg.is-d7 { --cw: 24px; }
.reg.is-weeks { --cw: 16px; }
.reg-cell .reg { padding: 2px; margin: -2px; border-radius: var(--radius-sm); }
.reg i { position: relative; display: block; height: 20px; }
.reg i::before, .reg i::after { content: ""; position: absolute; left: 0; right: 0; height: 9px; border-radius: 2px; background: var(--sheet-3); }
.reg i::before { top: 0; }
.reg i::after { bottom: 0; }
.reg i.off::before, .reg i.off::after { background: var(--sheet); box-shadow: inset 0 0 0 1px var(--rule); }
.reg i.a1::before { background: var(--dir-arrival); box-shadow: none; }
.reg i.d1::after { background: var(--dir-departure); box-shadow: none; }
.reg i.a0::before { border: 1px dashed var(--dir-arrival); background: var(--sheet); box-shadow: none; }
.reg i.d0::after { border: 1px dashed var(--dir-departure); background: var(--sheet); box-shadow: none; }
.reg i.ax::before, .reg i.dx::after { background: var(--warning); box-shadow: none; }
.reg.is-weeks i::before { height: 100%; }
.reg.is-weeks i::after { display: none; }
.reg i.w1::before, .reg-legend i.w1 { background: var(--recency-0); }
.reg i.w2::before, .reg-legend i.w2 { background: var(--recency-4); }
.reg i.w3::before, .reg-legend i.w3 { background: var(--recency-3); }
.reg i.w4::before, .reg-legend i.w4 { background: var(--recency-2); }
.reg i.w5::before, .reg-legend i.w5 { background: var(--recency-1); }
.reg-cell .reg i:hover::before, .reg-cell .reg i:hover::after { filter: brightness(1.12); }
.reg-head-label { display: block; margin-bottom: 5px; }
.reg-axis i, .reg-axis span { overflow: visible; color: var(--ink-3); font-size: 10.5px; font-weight: 600; letter-spacing: 0; text-transform: none; white-space: nowrap; }
.reg-axis .is-end { display: flex; justify-content: flex-end; color: var(--ink); }
.reg-legend .scale { gap: 3px; }
.reg-legend .scale i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; }
.reg-legend .scale span { margin: 0 4px; }
/* a row that crossed a quiet line in the last three days: tinted until looked at, and worded in its status */
.register-table tr.is-lit td { background: var(--primary-soft); transition: background 700ms var(--ease); }
.register-table tr.is-lit.is-seen td { background: transparent; }
.register-table tr.is-lit.is-seen:hover td { background: #f3f8ff; }
/* on the tint the empty halves would melt into the row: they turn white and keep a hairline, so the blank run reads */
.register-table tr.is-lit:not(.is-seen) .reg i:not(.a1):not(.a0):not(.ax)::before,
.register-table tr.is-lit:not(.is-seen) .reg i:not(.d1):not(.d0):not(.dx)::after { background: var(--sheet); box-shadow: inset 0 0 0 1px var(--rule-strong); }

@media (max-width: 1180px) {
  .report-grid { grid-template-columns: minmax(0, 1fr); }
  .register-overview { grid-template-columns: 280px minmax(0, 1fr); }
  .riders-week { grid-column: 1 / -1; max-width: 560px; }
}

@media (max-width: 640px) {
  .report-bar { margin-top: 0; }
  .periods { display: flex; width: 100%; }
  .period { flex: 1; padding: 0 6px; }
  .seats-sheet .sheet-head { row-gap: 10px; }
  .chart-body { padding: 10px 6px 4px; }
  .rr-head { grid-template-columns: 16px minmax(0, 1fr) auto 14px; gap: 10px; padding: 9px 14px; }
  .rr-body { padding: 2px 14px 12px; }
  .register-overview { grid-template-columns: minmax(0, 1fr); gap: 22px; padding: 14px; }
  .mosaic, .mosaic.is-roomy { gap: 2px; }
  .mosaic .tile, .mosaic.is-roomy .tile { width: 12px; height: 12px; }
  /* the wide chart is drawn at about 45% on a phone: its labels are set larger to come out readable, and the
     in-plot zone label gives way to the legend */
  .stack-chart .tick, .stack-chart .axis text, .stack-chart .value { font-size: 22px; }
  .stack-chart .zone-label { display: none; }
  .heat { padding: 6px 8px 10px; border-spacing: 2px; }
  .heat td { min-width: 0; padding: 0 2px; }
  .heat th { padding: 4px 2px; }
  .heat tbody th .muted { display: none; }
  /* the register keeps name, status and the whole strip on screen: the stamp moves under the name */
  .register-table .col-status { display: none; }
  .register-table .stamp-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 5px; }
  .register-table .stamp-inline .lit-note { font-size: var(--fs-xs); }
  .register-table td.col-name { min-width: 128px; max-width: 150px; }
  .reg { --cw: 5px; gap: 1px; }
  .reg.is-d7 { --cw: 18px; }
  .reg.is-weeks { --cw: 11px; }
  /* the strip is a third as wide here: its date ticks keep only the day of the month */
  .reg-axis span[data-short] { font-size: 0; }
  .reg-axis span[data-short]::after { content: attr(data-short); font-size: 10.5px; }
}

@media print {
  .report-bar .period:not(.is-active), .table-view, .ladder-list, .mosaic-wrap, .view-switch { display: none !important; }
  .rr-chevron { display: none; }
  .register-table tr.is-lit td { background: transparent; }
}

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

@media (max-width: 1180px) {
  .record { grid-template-columns: 280px minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1000px) {
  .record { grid-template-columns: minmax(0, 1fr); }
  .record-aside { position: static; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 991px) {
  :root { --page-x: 16px; }
  .app-shell, body.spine-rail .app-shell { grid-template-columns: minmax(0, 1fr); }
  .spine { position: fixed; top: 0; left: 0; width: var(--spine-w); transform: translateX(-100%); transition: transform 220ms var(--ease); box-shadow: none; }
  body.spine-open .spine { transform: none; box-shadow: var(--shadow-pop); }
  body.spine-rail .brand-text, body.spine-rail .station-text, body.spine-rail .nav-label, body.spine-rail .nav-group span, body.spine-rail .spine-user { display: flex; }
  body.spine-rail .nav-item { justify-content: flex-start; padding: 9px 12px; }
  body.spine-rail .brand { justify-content: flex-start; padding: 14px 16px; }
  body.spine-rail .station-plate { justify-content: flex-start; padding: 10px 12px; }
  body.spine-rail .spine-foot { justify-content: flex-start; padding: 12px 16px; }
  body.spine-rail .nav-group::after { display: none; }
  body.spine-rail .nav-group { height: auto; padding: 14px 12px 6px; }
  .topbar { padding-left: 12px; }
  .today { display: none; }
  .user-chip-name { display: none; }
  .page { padding-top: 18px; }
  .login-sheet { grid-template-columns: 1fr; }
  .login-side { padding: 28px; }
  .login-pitch { margin-top: 28px; }
  .login-side::after { top: 96px; }
  .login-form-wrap { padding: 30px 28px; }
}

@media (max-width: 640px) {
  h1 { font-size: 20px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-cell:last-child:nth-child(odd) { grid-column: span 2; }
  .summary-value { font-size: 26px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .sheet-head, .table-toolbar { padding: 12px 14px; }
  .sheet-body { padding: 14px; }
  .tabs { padding: 0 8px; }
  .tab { padding: 10px 8px; }
  .line li { grid-template-columns: 52px 26px minmax(0, 1fr); }
  .line .stop-side { grid-column: 3; text-align: left; padding-top: 6px; }
  .decision .btn-group { grid-template-columns: 1fr; }
  .docs { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .ledger .col-line { display: none; }
  .ledger td.col-name { min-width: 120px; max-width: 150px; white-space: normal; }
  .ledger .col-decision { min-width: 136px; }
  .ledger .cell-reason { display: block; max-width: 136px; }
  .ledger .col-reason { display: none; }
  .toast { right: 12px; bottom: 12px; left: 12px; max-width: none; }
  .login-side { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media print {
  .spine, .topbar, .app-foot, .page-actions, .table-toolbar, .pager, .row-actions, .decision, .toast, .tabs { display: none !important; }
  .app-shell { display: block; }
  .page { max-width: none; padding: 0; }
  .sheet { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
  .ledger th { position: static; }
}
