/* Onsight Monitoring — site styles.
 * Built on wwwroot/css/tokens.css. Rules: design-system/remote-monitoring/MASTER.md.
 * No raw colours below this line except inside tokens; nothing is set under 13px.
 */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
  margin: 0;
  font: var(--weight-regular) var(--text-base)/var(--leading-normal) var(--font-body);
  color: var(--color-foreground);
  background: var(--color-background);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: lining-nums;
}
h1, h2, h3, p, dl, dd, ul { margin: 0; }
h1, h2, h3 { font-family: var(--font-heading); font-weight: var(--weight-semibold); line-height: var(--leading-tight); text-wrap: balance; }
a { color: var(--color-primary-strong); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { color: var(--color-primary-hover); text-decoration-thickness: 2px; }
button, input, select { font: inherit; color: inherit; }
button, a, input, select, summary { touch-action: manipulation; -webkit-tap-highlight-color: rgb(0 60 113 / 0.15); }
time { white-space: nowrap; }
::selection { background: var(--color-primary-soft); color: var(--color-foreground); }
:root { accent-color: var(--color-primary-strong); caret-color: var(--color-primary-strong); scrollbar-color: var(--color-border-strong) transparent; }
.sidebar { scrollbar-color: var(--color-on-sidebar-muted) transparent; }
svg.icon { width: 16px; height: 16px; flex: none; }
/* The transparent outline becomes visible in Windows forced-colours mode, where box-shadow is dropped. */
:focus-visible { outline: 2px solid transparent; outline-offset: 2px; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-xl); top: -100px; z-index: 100;
  padding: var(--space-md) var(--space-xl);
  background: var(--color-card); color: var(--color-foreground);
  border: 2px solid var(--color-primary-strong); border-radius: var(--radius-sm);
  font-weight: var(--weight-semibold);
}
.skip-link:focus { top: var(--space-xl); }

.mono { font-family: var(--font-mono); font-size: var(--text-base); font-weight: var(--weight-semibold); letter-spacing: 0; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.quiet { color: var(--color-muted-foreground); }
.health { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm) var(--space-md); }
.tbl th:first-child, .tbl td:first-child { padding-left: var(--space-xl); }
.tbl th:last-child, .tbl td:last-child { padding-right: var(--space-xl); }
.last-known { color: var(--color-muted-foreground); font-size: var(--text-sm); font-weight: var(--weight-regular); }
.num { font-variant-numeric: tabular-nums lining-nums; }
.hint { font-size: var(--text-sm); color: var(--color-muted-foreground); max-width: 70ch; }
.text-bad { color: var(--color-bad); }
.text-warn { color: var(--color-warn); }
.text-good { color: var(--color-good); }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--color-sidebar); color: var(--color-on-sidebar);
  overflow-y: auto;
}
/* The Compumedics logo (Pages/Shared/_Logo.cshtml) is drawn in currentColor. Per the brand guide it appears only
   in Dark Blue on light backgrounds or reversed out in white on dark ones, at its own aspect ratio. */
svg.logo { display: block; height: auto; flex: none; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-lg); padding: 24px var(--space-xl) var(--space-xl); }
.logo-sidebar { width: 172px; color: var(--color-on-sidebar); }
.brand-name { font: var(--weight-semibold) var(--text-base)/var(--leading-tight) var(--font-heading); }
.brand-sub { font-size: var(--text-sm); color: var(--color-on-sidebar-muted); overflow-wrap: anywhere; }

.nav { flex: 1; padding: 0 var(--space-md) var(--space-xl); }
.nav-section { padding: var(--space-xl) var(--space-lg) var(--space-sm); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-on-sidebar-muted); }
.nav-item {
  display: flex; align-items: center; gap: var(--space-lg);
  min-height: 40px; padding: 0 var(--space-lg); margin-bottom: var(--space-xs);
  border-radius: var(--radius-sm);
  color: var(--color-on-sidebar); text-decoration: none; font-weight: var(--weight-medium);
  transition: background var(--duration-fast) var(--ease-out);
}
.nav-item:hover { background: rgb(255 255 255 / 0.10); color: var(--color-on-sidebar); }
.nav-item[aria-current="page"] { background: rgb(255 255 255 / 0.18); font-weight: var(--weight-semibold); }
.nav-item:focus-visible, .sidebar .btn:focus-visible { box-shadow: 0 0 0 2px var(--color-sidebar), 0 0 0 4px var(--color-on-sidebar); }
.nav-item .icon { color: var(--color-on-sidebar-muted); }
.nav-item[aria-current="page"] .icon { color: var(--color-on-sidebar); }
.nav-badge {
  margin-left: auto; min-width: 24px; padding: 0 var(--space-md);
  border-radius: var(--radius-full);
  background: var(--color-bad-soft); color: var(--color-bad);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); line-height: 22px; text-align: center;
  font-variant-numeric: tabular-nums;
}

.user-card { padding: var(--space-xl); border-top: 1px solid rgb(255 255 255 / 0.16); display: flex; flex-direction: column; gap: var(--space-lg); }
.user-name { font-weight: var(--weight-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card > div { min-width: 0; }
.menu-close { display: none; }
.user-role { font-size: var(--text-sm); color: var(--color-on-sidebar-muted); }
.sidebar .btn { background: transparent; color: var(--color-on-sidebar); border-color: rgb(255 255 255 / 0.5); }
.sidebar .btn:hover { background: rgb(255 255 255 / 0.10); }
.sidebar .btn:active { background: rgb(255 255 255 / 0.2); }

/* Mobile bar: only under 768px */
.mobilebar { display: none; }
.logo-mobile { display: none; }
.nav-backdrop { display: none; }

.main { min-width: 0; }
.page { display: flex; flex-direction: column; gap: var(--space-2xl); padding: var(--space-3xl); max-width: 1480px; }

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-xl); }
.page-header > :first-child { flex: 1; min-width: min(100%, 280px); }
.page-title { font-size: var(--text-xl); letter-spacing: -0.01em; }
.page-subtitle { margin-top: var(--space-sm); color: var(--color-muted-foreground); max-width: 70ch; }
.page-actions { display: flex; align-items: center; gap: var(--space-md); }
.updated { font-size: var(--text-sm); color: var(--color-muted-foreground); }

/* ---------- Layout helpers ---------- */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--space-xl); align-items: start; }
/* Wide tables: the table takes the full width and its forms sit in a row underneath. */
.split.split-stack { grid-template-columns: minmax(0, 1fr); }
.split-stack > .forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 400px)); gap: var(--space-xl); align-items: start; }
.stack { display: flex; flex-direction: column; gap: var(--space-xl); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-lg); }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-md); }
.notice { max-width: 640px; }
.notice p { max-width: 65ch; }
.filter-note { margin-top: calc(var(--space-md) - var(--space-2xl)); color: var(--color-muted-foreground); }
.inline { display: inline; margin: 0; }

/* ---------- Cards ---------- */
.card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg); min-width: 0; }
.card-head { display: flex; align-items: center; gap: var(--space-lg); padding: var(--space-lg) var(--space-xl); border-bottom: 1px solid var(--color-divider); }
.card-title { font: var(--weight-semibold) var(--text-md)/var(--leading-tight) var(--font-heading); }
.card-title.mono { font-family: var(--font-mono); font-size: 16px; }
.card-sub { font-size: var(--text-sm); color: var(--color-muted-foreground); }
.card-pad { padding: var(--space-xl); }
.empty { padding: var(--space-2xl) var(--space-xl); color: var(--color-muted-foreground); max-width: 70ch; }

/* ---------- Fleet strip (Unit status) ---------- */
.fleet { padding: var(--space-xl) var(--space-2xl) var(--space-2xl); }
.fleet-counts { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--space-xl); }
.fleet-count { min-width: 0; }
.fleet-count + .fleet-count { padding-left: var(--space-xl); border-left: 1px solid var(--color-border); }
.fleet-num { font: var(--weight-semibold) var(--text-2xl)/1.1 var(--font-heading); font-variant-numeric: tabular-nums lining-nums; }
.fleet-label { display: flex; align-items: center; gap: var(--space-md); margin-top: var(--space-sm); font-weight: var(--weight-semibold); }
.fleet-note { font-size: var(--text-sm); color: var(--color-muted-foreground); }
.fleet-urgent { display: block; color: var(--color-bad); font-size: var(--text-base); font-weight: var(--weight-semibold); }
.fleet-key { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--color-neutral); }
.fleet-key.good, .fleet-bar .good { background: var(--color-good); }
.fleet-key.info, .fleet-bar .info { background: var(--color-primary); }
.fleet-key.bad, .fleet-bar .bad { background: var(--color-bad); }
.fleet-key.neutral, .fleet-bar .neutral {
  background: repeating-linear-gradient(135deg, var(--color-neutral) 0 2px, var(--color-neutral-soft) 2px 5px);
}
.fleet-bar { display: flex; gap: 2px; height: 12px; margin-top: var(--space-xl); border-radius: var(--radius-full); overflow: hidden; background: var(--color-muted); }
.fleet-bar span { min-width: 6px; }
a.fleet-count { display: block; color: inherit; text-decoration: none; border-radius: var(--radius-sm); }
a.fleet-count .fleet-label { color: var(--color-primary-strong); text-decoration: underline; text-underline-offset: 2px; }
a.fleet-count:hover .fleet-label { color: var(--color-foreground); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--space-xs); border-bottom: 1px solid var(--color-border-strong); overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: var(--space-md);
  min-width: 44px; min-height: 44px; padding: 0 var(--space-xl); margin-bottom: -1px; justify-content: center;
  border-bottom: 3px solid transparent;
  color: var(--color-muted-foreground); font-weight: var(--weight-medium); text-decoration: none; white-space: nowrap;
}
.tab:hover { color: var(--color-foreground); background: var(--color-muted); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tab[aria-current="page"] { color: var(--color-foreground); font-weight: var(--weight-semibold); border-bottom-color: var(--color-primary-strong); }
.tab .count {
  min-width: 24px; padding: 0 var(--space-md); border-radius: var(--radius-full);
  background: var(--color-muted); color: var(--color-foreground);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); line-height: 22px; text-align: center; font-variant-numeric: tabular-nums;
}
.tab[aria-current="page"] .count { background: var(--color-primary-soft); }

/* ---------- Tables ---------- */
.card:has(> .tbl) { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums lining-nums; }
.tbl th {
  padding: var(--space-lg);
  background: var(--color-muted); color: var(--color-muted-foreground);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
}
.tbl thead tr:first-child th:first-child { border-top-left-radius: calc(var(--radius-lg) - 1px); }
.tbl thead tr:first-child th:last-child { border-top-right-radius: calc(var(--radius-lg) - 1px); }
.card-head + .tbl th { border-radius: 0; }
.tbl td { height: var(--row-h); padding: var(--space-md) var(--space-lg); border-bottom: 1px solid var(--color-divider); vertical-align: middle; }
.tbl a.mono { text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 4px; }
.tbl a.mono:hover { text-decoration-color: currentColor; }
/* The serial link covers its whole row, so the row is the target; other links and buttons stay on top. */
.tbl tr { position: relative; }
.tbl .row-link::after { content: ""; position: absolute; inset: 0; }
.tbl td a:not(.row-link), .tbl td form { position: relative; z-index: 1; }
.pill-link { display: inline-flex; border-radius: var(--radius-full); text-decoration: none; }
.pill-link:hover .pill { box-shadow: inset 0 0 0 1px currentColor; }
.pill-link:focus-visible { border-radius: var(--radius-full); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--color-muted); }
.tbl tr.selected td, .tbl tr.selected:hover td { background: var(--color-primary-soft); }
.tbl tr.selected td:first-child, .tbl tr.selected td:first-child a { font-weight: var(--weight-semibold); }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl td.actions { text-align: right; white-space: nowrap; }
.tbl td.actions > * + * { margin-left: var(--space-sm); }
.tbl td.wrap { min-width: 200px; overflow-wrap: break-word; }
.tbl td.nowrap { white-space: nowrap; }
.person-name { font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.person-email { font-size: var(--text-sm); color: var(--color-muted-foreground); overflow-wrap: anywhere; }

/* ---------- Pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: var(--radius-full);
  background: var(--color-neutral-soft); color: var(--color-neutral);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); line-height: 20px; white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.pill svg.icon { width: 14px; height: 14px; }
.pill.good { background: var(--color-good-soft); color: var(--color-good); }
.pill.warn { background: var(--color-warn-soft); color: var(--color-warn); }
.pill.bad { background: var(--color-bad-soft); color: var(--color-bad); }
.pill.info { background: var(--color-info-soft); color: var(--color-info); }
.pill.outline { background: var(--color-card); color: var(--color-foreground); box-shadow: inset 0 0 0 1px var(--color-border-strong); }
.pill.outline .dot { background: var(--color-primary-strong); }
.pill.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 10em; border-radius: var(--radius-lg); } /* min-width keeps words whole; long emails still break */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-md);
  min-height: var(--control-h); padding: 0 14px;
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
  background: var(--color-card); color: var(--color-foreground);
  font-size: var(--text-base); font-weight: var(--weight-medium); line-height: 1.2; text-decoration: none; white-space: nowrap;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
}
.btn:hover { background: var(--color-muted); color: var(--color-foreground); }
.btn:active { background: var(--color-primary-soft); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--color-primary-strong); border-color: var(--color-primary-strong); color: var(--color-on-primary-strong); }
.btn-primary:hover, .btn-primary:active { background: var(--color-primary-hover); border-color: var(--color-primary-hover); color: var(--color-on-primary-strong); }
.btn-danger { background: var(--color-destructive); border-color: var(--color-destructive); color: var(--color-on-destructive); }
.btn-danger:hover, .btn-danger:active { background: var(--color-bad); border-color: var(--color-bad); color: var(--color-on-destructive); }
.btn-ghost { border-color: transparent; background: transparent; }
/* Quiet in the row so a table isn't a column of red; red arrives on hover and in the confirmation. */
.btn-danger-ghost:hover, .btn-danger-ghost:focus-visible { background: var(--color-bad-soft); color: var(--color-bad); }
.btn[aria-busy="true"] { cursor: progress; }
.btn-block { width: 100%; min-height: var(--control-h-touch); }
@media (pointer: coarse) { .btn { min-height: var(--control-h-touch); } }

/* ---------- Forms ---------- */
.form-field { display: flex; flex-direction: column; gap: var(--space-sm); }
.form-label { font-size: 14px; font-weight: var(--weight-semibold); }
.form-input {
  width: 100%; min-width: 0; min-height: 40px; padding: 0 var(--space-lg);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
  background: var(--color-card); color: var(--color-foreground);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease-out);
}
.form-input::placeholder { color: var(--color-muted-foreground); opacity: 1; }
.form-input:hover { border-color: var(--color-foreground); }
.form-input:focus-visible { border-color: var(--color-primary-strong); }
.form-input[aria-invalid="true"] { border-color: var(--color-bad); }
select.form-input { cursor: pointer; }
@media (pointer: coarse) { .form-input { min-height: var(--control-h-touch); font-size: 16px; } }

/* ---------- Banners ---------- */
.banner {
  display: flex; align-items: flex-start; gap: var(--space-lg);
  padding: var(--space-lg) var(--space-xl);
  border-radius: var(--radius-md);
  background: var(--color-info-soft); color: var(--color-info);
  font-weight: var(--weight-medium);
}
.banner svg.icon { width: 20px; height: 20px; margin-top: 1px; }
.banner > div { min-width: 0; overflow-wrap: anywhere; }
.banner.good { background: var(--color-good-soft); color: var(--color-good); }
.banner.warn { background: var(--color-warn-soft); color: var(--color-warn); }
.banner.bad { background: var(--color-bad-soft); color: var(--color-bad); }
/* A platform admin working inside a clinic: always visible, with the way back beside it. */
.banner.acting { align-items: center; flex-wrap: wrap; }
.banner.acting > div { flex: 1 1 240px; }
.banner.acting .btn { color: var(--color-foreground); }

/* ---------- Radio choices (Alert emails) ---------- */
.choice-list { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-md); }
.choice-list legend { margin-bottom: var(--space-md); }
.choice { display: flex; gap: var(--space-lg); align-items: flex-start; padding: var(--space-lg) var(--space-xl);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); cursor: pointer; }
.choice:has(input:checked) { border-color: var(--color-primary-strong); background: var(--color-primary-soft); }
.choice input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
.choice strong { display: block; font-weight: var(--weight-semibold); }
.choice .hint { display: block; }

/* ---------- Activity (audit trail) ---------- */
.audit-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: var(--space-lg); align-items: end; }
.audit-filters .audit-search { grid-column: span 2; }
.audit-filter-actions { display: flex; gap: var(--space-md); }
.tbl.audit td { vertical-align: top; padding-top: var(--space-lg); padding-bottom: var(--space-lg); }
.tbl.audit .person .pill { margin-top: var(--space-sm); }
.audit-pager { display: flex; justify-content: flex-end; gap: var(--space-md); }
.audit-pager:empty { display: none; }
@media (max-width: 560px) { .audit-filters .audit-search { grid-column: auto; } }

/* ---------- Key/value list ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--space-md) var(--space-xl); align-items: baseline; }
.kv dt { color: var(--color-muted-foreground); }
.kv dd { font-weight: var(--weight-medium); font-variant-numeric: tabular-nums lining-nums; text-align: right; }

/* ---------- Enrolment code ---------- */
.code-box {
  padding: var(--space-xl) var(--space-md);
  border-radius: var(--radius-md); background: var(--color-muted);
  font: var(--weight-semibold) 30px/1.2 var(--font-mono); letter-spacing: 0.1em; text-align: center;
  user-select: all; overflow-wrap: anywhere;
}

/* ---------- Alert list (unit detail) ---------- */
.alert-list { list-style: none; padding: 0; display: flex; flex-direction: column; }
.alert-list li { display: grid; grid-template-columns: auto 1fr; gap: var(--space-xs) var(--space-lg); align-items: start; padding: var(--space-lg) 0; border-top: 1px solid var(--color-divider); }
.alert-list li:first-child { border-top: 0; padding-top: 0; }
.alert-list .alert-time { grid-column: 2; font-size: var(--text-sm); color: var(--color-muted-foreground); }
.alert-list .alert-msg { overflow-wrap: anywhere; }

/* ---------- Confirmation dialog ---------- */
dialog.confirm {
  width: min(440px, calc(100vw - 32px)); padding: var(--space-2xl);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-lg);
  background: var(--color-card); color: var(--color-foreground);
  box-shadow: var(--shadow-lg);
  overscroll-behavior: contain;
}
dialog.confirm::backdrop { background: rgb(15 23 42 / 0.4); }
dialog.confirm h2 { font-size: var(--text-lg); overflow-wrap: anywhere; }
dialog.confirm p { margin-top: var(--space-md); color: var(--color-muted-foreground); }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--space-md); margin-top: var(--space-2xl); }
.dialog-actions .btn { min-height: var(--control-h-touch); }

/* ---------- Signed-out screens ---------- */
.login-screen { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--space-2xl) var(--space-xl); }
.login-card {
  width: 100%; max-width: 420px; padding: var(--space-3xl);
  display: flex; flex-direction: column; gap: var(--space-xl);
  background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
}
.login-brand { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-xl); }
.logo-login { width: 220px; max-width: 100%; color: var(--brand-dark-blue); }
.login-title { font-size: var(--text-lg); }
.divider-text { display: flex; align-items: center; gap: var(--space-lg); font-size: var(--text-sm); color: var(--color-muted-foreground); }
.divider-text::before, .divider-text::after { content: ""; flex: 1; height: 1px; background: var(--color-border-strong); }

/* ---------- Responsive ---------- */
@media (max-width: 1279px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .split > .split-aside-first { order: -1; }
}

@media (max-width: 900px) {
  .fleet-counts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-xl) var(--space-xl); }
  .fleet-count + .fleet-count { padding-left: 0; border-left: 0; }
  .fleet-count:first-child { grid-column: 1 / -1; }
}

@media (max-width: 767px) {
  .shell { display: block; }
  .mobilebar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: var(--space-lg);
    min-height: 56px; padding: env(safe-area-inset-top, 0px) max(var(--space-xl), env(safe-area-inset-right, 0px)) 0 max(var(--space-xl), env(safe-area-inset-left, 0px));
    background: var(--color-sidebar); color: var(--color-on-sidebar);
  }
  .logo-mobile { display: block; width: 112px; color: var(--color-on-sidebar); }
  .mobilebar-title { font: var(--weight-semibold) var(--text-base)/1 var(--font-heading); padding-left: var(--space-lg); border-left: 1px solid rgb(255 255 255 / 0.3); }
  .menu-btn {
    display: inline-grid; place-items: center; width: 44px; height: 44px; margin-left: -10px;
    border: 0; border-radius: var(--radius-sm); background: transparent; color: inherit; cursor: pointer;
  }
  .menu-btn:hover { background: rgb(255 255 255 / 0.12); }
  .menu-btn:focus-visible { box-shadow: 0 0 0 2px var(--color-on-sidebar); }
  .menu-btn svg.icon { width: 22px; height: 22px; }

  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(300px, 86vw);
    transform: translateX(-100%); visibility: hidden;
    transition: transform var(--duration-base) var(--ease-out), visibility 0s linear var(--duration-base);
    overscroll-behavior: contain;
  }
  .nav-open .sidebar { transform: none; visibility: visible; transition: transform var(--duration-base) var(--ease-out); }
  .nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 30; background: rgb(15 23 42 / 0.4); }
  .nav-item { min-height: 44px; }

  .page { padding: var(--space-xl); gap: var(--space-xl); }
  .page-title { font-size: 22px; }
  .page-actions, .page-actions form, .page-actions .btn { width: 100%; }
  .fleet { padding: var(--space-xl); }
  .fleet-num { font-size: 28px; }
  .login-card { padding: var(--space-2xl) var(--space-xl); }
  .code-box { font-size: 26px; }
  .tab { padding: 0 var(--space-lg); }

  /* Tables become a list of labelled blocks so nothing sits off-screen. */
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; }
  .tbl thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .tbl tr { padding: var(--space-lg) var(--space-xl); border-bottom: 1px solid var(--color-divider); }
  .tbl td:first-child a { display: inline-flex; align-items: center; min-height: 44px; }
  /* The 44px link already supplies the space around the heading. */
  .tbl td:first-child:has(a) { padding-top: 0; padding-bottom: 0; }
  /* In a stacked row every action is an outlined button, so a lone quiet action doesn't look indented. */
  .tbl td.actions .btn-ghost { border-color: var(--color-border-strong); background: var(--color-card); }
  /* The alert message is the headline of its block, not a right-aligned value. */
  .tbl td.wrap { display: block; text-align: left; font-weight: var(--weight-medium); }
  .tbl td.wrap::before { display: none; }
  .menu-close { display: inline-grid; position: absolute; top: var(--space-md); right: var(--space-md); margin: 0; }
  .brand { padding-right: 56px; }
  .tbl tbody tr:last-child { border-bottom: 0; }
  .tbl tbody tr:hover td { background: transparent; }
  .tbl tr.selected { background: var(--color-primary-soft); }
  .tbl tr.selected td, .tbl tr.selected:hover td { background: transparent; }
  .tbl td, .tbl td.num {
    display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-xl);
    height: auto; padding: var(--space-sm) 0; border: 0; text-align: right;
  }
  .tbl td::before { content: attr(data-label); flex: none; color: var(--color-muted-foreground); font-size: var(--text-sm); font-weight: var(--weight-medium); text-align: left; }
  .tbl td:first-child { justify-content: flex-start; padding-bottom: var(--space-md); font-size: 16px; font-weight: var(--weight-semibold); text-align: left; }
  .tbl td:first-child::before { display: none; }
  .tbl th:first-child, .tbl td:first-child { padding-left: 0; }
  .tbl th:last-child, .tbl td:last-child { padding-right: 0; }
  .tbl td.person { display: block; }
  .tbl td.person .person-email { font-weight: var(--weight-regular); }
  .tbl td.mono:first-child, .tbl td:first-child .mono { font-size: 16px; }
  .tbl td.wrap { min-width: 0; }
  .tbl td.actions { justify-content: flex-start; flex-wrap: wrap; gap: var(--space-md); padding-top: var(--space-lg); white-space: normal; }
  .tbl td.actions > * + * { margin-left: 0; }
  .tbl td.actions::before, .tbl td.actions:empty { display: none; }
  .card-head + .tbl tr:first-child { border-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; scroll-behavior: auto !important; }
}

@media print {
  .sidebar, .mobilebar, .page-actions, .tbl td.actions, .skip-link { display: none !important; }
  .shell { display: block; }
  body { background: var(--color-card); }
}

/* --- Unit detail, reports, fleet pages --- */
.crumbs { font-size: var(--text-sm); color: var(--color-muted-foreground); margin-bottom: var(--space-sm); }
.crumbs a { color: var(--color-primary-strong); }
.unit-pills { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-md); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-lg); }
.stat { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-lg) var(--space-xl); min-width: 0; }
.stat-label { font-size: var(--text-sm); color: var(--color-muted-foreground); }
.stat-value { margin-top: var(--space-sm); font-size: var(--text-lg); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-value.mono { font-size: var(--text-md); white-space: normal; }
.seg { display: flex; flex-wrap: wrap; gap: var(--space-xs); padding: var(--space-xs); background: var(--color-muted); border-radius: var(--radius-sm); }
.seg-item { padding: var(--space-sm) var(--space-md); border-radius: var(--radius-sm); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-foreground); text-decoration: none; min-height: 32px; display: inline-flex; align-items: center; }
.seg-item:hover { background: var(--color-card); }
.seg-item[aria-current="page"] { background: var(--color-card); color: var(--color-primary-strong); box-shadow: 0 0 0 1px var(--color-border); }
.chart-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2xl); }
.chart-fig { margin: 0; min-width: 0; }
.chart-fig figcaption { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-md); margin-bottom: var(--space-md); }
.chart-title { font-weight: var(--weight-semibold); }
.legend { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm) var(--space-md); font-size: var(--text-sm); color: var(--color-muted-foreground); }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: 2px; }
.key-recording { background: var(--brand-dark-blue); }
.key-online { background: var(--brand-light-blue); opacity: .45; }
.key-disk { background: var(--color-warn); height: 3px; }
.key-signal { background: var(--color-good); height: 3px; }
.chart { display: block; width: 100%; height: auto; }
.chart-grid { stroke: var(--color-divider); stroke-width: 1; }
.chart-axis { fill: var(--color-muted-foreground); font-size: 11px; font-family: var(--font-body); }
.chart-online { fill: var(--brand-light-blue); fill-opacity: .45; }
.chart-recording { fill: var(--brand-dark-blue); }
.chart-disk, .chart-signal { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-disk { stroke: var(--color-warn); }
.chart-signal { stroke: var(--color-good); }
.chart-disk-dot { fill: var(--color-warn); }
.chart-signal-dot { fill: var(--color-good); }
.timeline { list-style: none; margin: 0; padding: var(--space-md) var(--space-xl) var(--space-lg); }
.timeline-item { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: var(--space-lg); padding: var(--space-md) 0 var(--space-md) var(--space-lg); border-left: 2px solid var(--color-divider); position: relative; }
.timeline-item::before { content: ""; position: absolute; left: -6px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--color-card); border: 2px solid var(--color-border-strong); }
.timeline-item.ev-fault::before { border-color: var(--color-bad); background: var(--color-bad-soft); }
.timeline-item.ev-software::before { border-color: var(--color-info); }
.timeline-item.ev-enrolled::before, .timeline-item.ev-serviced::before, .timeline-item.ev-received::before { border-color: var(--color-good); }
.timeline-when { font-size: var(--text-sm); color: var(--color-muted-foreground); font-variant-numeric: tabular-nums; }
.cmd-result details { max-width: 420px; }
.cmd-result summary { cursor: pointer; overflow-wrap: anywhere; }
.cmd-result pre { margin: var(--space-md) 0; padding: var(--space-md); max-height: 320px; overflow: auto; background: var(--color-muted); border-radius: var(--radius-sm); font: 12px/1.45 var(--font-mono); white-space: pre-wrap; }
.cmd-result > * + * { margin-left: var(--space-md); }
.report-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-md); }
.check { display: flex; align-items: flex-start; gap: var(--space-md); }
.check input { width: 18px; height: 18px; margin-top: 2px; flex: none; }
@media (max-width: 900px) {
  .chart-grid-2 { grid-template-columns: minmax(0, 1fr); }
  .timeline-item { grid-template-columns: minmax(0, 1fr); gap: var(--space-xs); }
}
@media print {
  .seg, .no-print, form { display: none !important; }
  .card, .stat { break-inside: avoid; }
}.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-sm); }.chart-grid-2 { grid-template-columns: minmax(0, 1fr); }
.timeline-more { padding: 0 var(--space-xl) var(--space-lg); }
.timeline-more summary { cursor: pointer; color: var(--color-primary-strong); font-weight: var(--weight-medium); padding: var(--space-sm) 0; }
.timeline-more .timeline { padding: 0; }.card-head:has(.seg) { flex-wrap: wrap; }
.card-head:has(.seg) .grow { min-width: 220px; }
a.user-name { display: block; color: inherit; text-decoration: none; }
a.user-name:hover { text-decoration: underline; }
/* File inputs: the browser's button sits at the top of a padded box, so size it to fill the box evenly instead. */
input[type="file"].form-input { padding: 3px; line-height: 32px; cursor: pointer; }
input[type="file"].form-input::file-selector-button {
  height: 32px; margin-right: var(--space-lg); padding: 0 var(--space-lg);
  border: 1px solid var(--color-border-strong); border-radius: 4px;
  background: var(--color-muted); color: var(--color-foreground);
  font: inherit; font-weight: var(--weight-semibold); cursor: pointer;
}
input[type="file"].form-input::file-selector-button:hover { background: var(--color-primary-soft); }
@media (pointer: coarse) {
  input[type="file"].form-input { line-height: 36px; }
  input[type="file"].form-input::file-selector-button { height: 36px; }
}
/* --- Remote console (Pages/UnitConsole.cshtml) --- */
.console-page { margin: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: #0F1B2A; }
.console-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-md) var(--space-xl); padding: var(--space-md) var(--space-xl); background: var(--color-card); border-bottom: 1px solid var(--color-border); }
.console-back { display: inline-flex; align-items: center; gap: var(--space-md); color: var(--color-foreground); text-decoration: none; font-weight: var(--weight-semibold); min-height: 36px; }
.console-back:hover { color: var(--color-primary-strong); }
.console-status { font-weight: var(--weight-medium); }
.console-status[data-kind="good"] { color: var(--color-good); }
.console-status[data-kind="warn"] { color: var(--color-warn); }
.console-status[data-kind="bad"] { color: var(--color-bad); }
.console-timer { font-variant-numeric: tabular-nums; font-size: var(--text-sm); }
.console-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-md); margin-left: auto; }
.console-actions .seg-item { border: 0; background: transparent; cursor: pointer; font: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium); }
.console-actions .seg-item[aria-pressed="true"] { background: var(--color-card); color: var(--color-primary-strong); box-shadow: 0 0 0 1px var(--color-border); }
.console-note { padding: var(--space-md) var(--space-xl); background: var(--color-info-soft); color: var(--color-info); font-size: var(--text-sm); }
.console-screen { flex: 1; min-height: 0; position: relative; }
@media (max-width: 767px) { .console-actions { margin-left: 0; width: 100%; } }.console-bar [hidden] { display: none !important; }
