:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --card: #ffffff;
  --field: #ffffff;
  --text: #172033;
  --muted: #637083;
  --line: #dce2ea;
  --accent: #0050e0;
  --accent-contrast: #ffffff;
  --secondary-bg: #e8eef8;
  --table-header: #eef2f7;
  --table-stripe: #fafbfd;
  --table-hover: #edf4ff;
  --table-selected: #dbeafe;
  --disabled-bg: #eef2f7;
  --disabled-text: #98a2b3;
  --tag-bg: #eef4ff;
  --warning-bg: #fef0c7;
  --warning: #b54708;
  --danger-bg: #fee4e2;
  --danger: #b42318;
  --success-bg: #e7f8ef;
  --success-line: #abefc6;
  --success-text: #067647;
  --shadow: rgba(23, 32, 51, 0.14);
  --chart-bg: #ffffff;
  --chart-gridline: #eef2f7;
  /* Aliases for shared mobile/desktop components */
  --mgp-surface: var(--card);
  --mgp-bg: var(--bg);
  --mgp-text: var(--text);
  --mgp-muted: var(--muted);
  --mgp-line: var(--line);
  --mgp-accent: var(--accent);
  /* Shared radius scale */
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  /* Shared vehicle accent (purple) */
  --shared-accent: #7c3aed;
  --shared-accent-bg: #ede9fe;
  --shared-accent-muted: #8b5cf6;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1724;
  --card: #151f2e;
  --field: #101827;
  --text: #e6edf7;
  --muted: #9aa8ba;
  --line: #2a3748;
  --accent: #0050e0;
  --accent-contrast: #ffffff;
  --secondary-bg: #223047;
  --table-header: #1d2a3c;
  --table-stripe: #111c2b;
  --table-hover: #22344f;
  --table-selected: #24466f;
  --disabled-bg: #1d2838;
  --disabled-text: #6f7d8f;
  --tag-bg: #1e3a5f;
  --warning-bg: #3b2b0d;
  --warning: #f5c451;
  --danger-bg: #461a1d;
  --danger: #ff9b94;
  --success-bg: #102f23;
  --success-line: #1f6d4d;
  --success-text: #7ee0ad;
  --shadow: rgba(0, 0, 0, 0.35);
  --chart-bg: #101827;
  --chart-gridline: #263447;
  --mgp-surface: var(--card);
  --mgp-bg: var(--bg);
  --mgp-text: var(--text);
  --mgp-muted: var(--muted);
  --mgp-line: var(--line);
  --mgp-accent: var(--accent);
  /* radius and shared-accent reuse light values in dark block */
  --shared-accent: #a78bfa;
  --shared-accent-bg: #2e1b5b;
  --shared-accent-muted: #c4b5fd;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.screen-reader-only {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

html {
  overflow-x: clip;
}

body {
  margin: 0;
  max-width: 100%;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

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

a:hover {
  text-decoration: underline;
}

header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.wrap {
  box-sizing: border-box;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding-bottom: 14px;
  padding-top: 14px;
}

.brand-heading {
  align-items: center;
  display: flex;
  gap: 18px;
  min-width: 0;
}

.brand-logo {
  display: block;
  height: 48px;
  max-height: 48px;
  max-width: min(280px, 44vw);
  object-fit: contain;
  width: auto;
}

.brand-logo-dark {
  display: none;
}

.header-context {
  align-items: center;
  display: flex;
  flex: 1 1 0;
  gap: 10px;
  justify-content: flex-end;
  min-width: 0;
}

:root[data-theme="dark"] .brand-logo-light {
  display: none;
}

:root[data-theme="dark"] .brand-logo-dark {
  display: block;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
  margin-bottom: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.muted {
  color: var(--muted);
}

.page-header {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  padding-top: 20px;
}

.page-header-text {
  min-width: 0;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 750;
  letter-spacing: -0.3px;
  line-height: 1.1;
  margin-bottom: 4px;
  overflow: visible;
  white-space: normal;
}

/* ── Help popover ─────────────────────────────────────────── */
.help-menu .help-popover {
  width: 340px;
  max-height: 80vh;
  overflow-y: auto;
  right: 0;
  left: auto;
  padding: 0;
}

.help-popover-heading {
  font-size: .875rem;
  font-weight: 700;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
}

.help-popover-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.help-popover-section-title {
  font-size: .8rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.help-popover-section-body {
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

.help-popover-footer {
  display: flex;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--secondary-bg);
}
.help-popover-footer a {
  font-size: .8rem;
  color: var(--primary, #0050e0);
  text-decoration: none;
  font-weight: 500;
}
.help-popover-footer a:hover { text-decoration: underline; }

.help-popover-index {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
}

.help-popover-index-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: .875rem;
  color: var(--text);
  text-decoration: none;
  transition: background .1s;
}
.help-popover-index-link:hover { background: var(--secondary-bg); }

.page-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 0;
  margin-top: 0;
}

.page-subtitle:empty {
  display: none;
}

.actions,
.menu-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.menu-bar {
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.menu {
  position: relative;
}

.menu summary {
  cursor: pointer;
  list-style: none;
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu-content {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 30px var(--shadow);
  display: grid;
  gap: 6px;
  min-width: 210px;
  padding: 8px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
}

.menu-content .button,
.menu-content form,
.menu-content form .button {
  justify-content: flex-start;
  width: 100%;
}

/* The garage switcher lives in the sidebar footer, near the bottom of the viewport —
   opening downward like other .menu-content instances pushes it past the page edge
   and forces a scroll. Open upward instead. */
.org-switcher .menu-content {
  top: auto;
  bottom: calc(100% + 6px);
}

.submenu {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 6px;
  padding-top: 6px;
}

.submenu summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  padding: 6px;
}

.theme-options {
  display: grid;
  gap: 6px;
}

.theme-option.is-active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.sso-actions {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.button {
  align-items: center;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  color: var(--accent-contrast);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 650;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
}

.button:hover {
  text-decoration: none;
}

.button.secondary {
  background: var(--secondary-bg);
  color: var(--text);
}

.button.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.icon-button {
  font-size: 20px;
  line-height: 1;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 10px;
}

.inbox-has-items {
  color: var(--warning);
}

.grid {
  display: grid;
  gap: 16px;
}

.summary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 24px;
}

@media (max-width: 600px) {
  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.two-column {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  margin-top: 16px;
}

.single-column {
  margin: 24px auto 0;
  max-width: 520px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  border-top: 3px solid var(--accent);
  padding: 18px;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  width: 100%;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 720px;
  width: 100%;
}

thead th {
  background: var(--table-header);
  border-bottom: 2px solid var(--line);
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
  position: sticky;
  text-align: left;
  top: 0;
  z-index: 1;
}

th,
td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 9px 10px;
  vertical-align: top;
}

th:last-child,
td:last-child {
  border-right: 0;
}

tbody tr:nth-child(even) td {
  background: var(--table-stripe);
}

tbody tr:hover td {
  background: var(--table-hover);
}

tbody tr.is-selected td,
tbody tr.is-selected:nth-child(even) td,
tbody tr.is-selected:hover td {
  background: var(--table-selected);
}

tbody tr:last-child td {
  border-bottom: 0;
}

th input[type="checkbox"],
td input[type="checkbox"] {
  margin: 0;
}

.quick-view {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.quick-count {
  background: var(--secondary-bg);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}

.quick-count .value {
  font-size: 22px;
  line-height: 1.1;
}

.quick-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.quick-item {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  list-style: none;
  min-width: min(100%, 260px);
  padding: 8px 10px;
}

.quick-item a {
  font-weight: 700;
}

.notification-toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.notification-summary {
  align-items: center;
  display: inline-flex;
  flex: 1 1 360px;
  gap: 8px;
  min-width: 0;
}

.notification-summary-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.value {
  font-size: 26px;
  font-weight: 750;
}

.list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
}

.item {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 3px;
  list-style: none;
  padding-top: 12px;
}

.item:first-child {
  border-top: 0;
  padding-top: 0;
}

.tag {
  background: var(--tag-bg);
  border-radius: 999px;
  color: var(--text);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 8px;
  width: fit-content;
}

.tag.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.tag.warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.empty {
  color: var(--muted);
  margin-bottom: 0;
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-row {
  display: grid;
  gap: 6px;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: normal;
}
.checkbox-inline input[type="checkbox"] {
  margin: 0;
  flex-shrink: 0;
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
}

.chart-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 40px 0;
  text-align: center;
}

/* ── Skip link ──────────────────────────────────── */
.skip-link {
  background: var(--accent);
  border-radius: 0 0 6px 6px;
  color: var(--accent-contrast, #fff);
  font-size: 14px;
  font-weight: 600;
  left: 50%;
  padding: 8px 20px;
  position: fixed;
  top: 0;
  transform: translateX(-50%) translateY(-100%);
  transition: transform 0.15s;
  z-index: 9999;
}
.skip-link:focus {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  transform: translateX(-50%) translateY(0);
}

/* ── Visually hidden (screen-reader only) ────────── */
.sr-only {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

/* ── Focus visible ───────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
}

.field-help {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

select:not([multiple]) {
  height: 40px;
  min-height: 40px;
}

select[multiple],
select[size]:not([size="1"]) {
  height: auto;
  min-height: 120px;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

input[type="checkbox"],
input[type="radio"] {
  min-height: auto;
  width: auto;
}

input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"] {
  max-width: 100%;
  min-width: 0;
}

.errorlist {
  color: var(--danger);
  margin: 0;
  padding-left: 18px;
}

.messages {
  display: none; /* rendered as fixed banner via JS; hidden here */
}

/* Fixed top notification bar */
#toast-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.message {
  align-items: center;
  background: var(--success-bg);
  border-bottom: 1px solid var(--success-line);
  color: var(--success-text);
  display: flex;
  font-size: 14px;
  font-weight: 500;
  gap: 10px;
  justify-content: space-between;
  list-style: none;
  padding: 11px 20px;
}

.message.error {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.message.warning {
  background: var(--warning-bg);
  border-color: var(--warning);
  color: var(--warning-text, #92400e);
}

.message .undo-link {
  background: var(--success-text);
  border-radius: 4px;
  color: var(--success-bg);
  font-weight: 600;
  margin-left: 10px;
  padding: 2px 8px;
  text-decoration: none;
}

.message .undo-link:hover {
  opacity: 0.85;
}

.message-close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1;
  opacity: 0.6;
  padding: 0 0 0 8px;
}

.message-close:hover { opacity: 1; }

.alert {
  border-radius: 6px;
  padding: 10px 14px;
}

.alert.danger {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
}

.alert.warning {
  background: var(--warning-bg);
  border: 1px solid var(--warning);
  color: var(--warning);
}

.error-summary {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: 6px;
  color: var(--danger);
  padding: 10px 12px;
}

.vehicle-nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  width: 100%;
}

.vehicle-selector-label {
  margin: 0;
}

.vehicle-selector {
  min-width: min(360px, 70vw);
  width: min(520px, 100%);
}

.vehicle-nav-count {
  color: var(--muted);
  font-size: 13px;
  padding: 0 4px;
}

.button.disabled {
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
}

.chart-panel {
  margin-top: 16px;
}

.chart-panel summary {
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  list-style-position: inside;
}

.chart-panel[open] summary {
  margin-bottom: 16px;
}

.chart-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chart-block h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

.chart-meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.chart {
  background: var(--chart-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  height: auto;
  min-height: 220px;
  width: 100%;
}

.chart polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.chart circle,
.chart rect {
  fill: var(--accent);
}

.chart-axis {
  stroke: var(--line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart-gridline {
  stroke: var(--chart-gridline);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart-label {
  fill: var(--muted);
  font-size: 3.8px;
  font-weight: 650;
}

.chart-label.y-axis {
  text-anchor: end;
}

.chart-label.x-axis-start {
  text-anchor: start;
}

.chart-label.x-axis-end {
  text-anchor: end;
}

.chart-empty {
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  min-height: 120px;
  text-align: center;
}

.bokeh-chart {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 300px;
  overflow: hidden;
  width: 100%;
}

.bokeh-chart .bk,
.bokeh-chart .bk * {
  box-sizing: content-box;
}

/* ── Sidebar layout ─────────────────────────────── */

/* Sidebar always in DOM; hidden unless body.has-sidebar */
.sidebar { display: none; }
.sidebar-overlay { display: none; }
.sidebar-topbar { display: none; }
.main-body { display: flex; flex-direction: column; min-height: 100vh; overflow-x: clip; width: 100%; }

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

.has-sidebar .sidebar {
  display: flex;
}

.has-sidebar .topbar-header {
  display: none;
}

.has-sidebar .main-body {
  margin-left: 232px;
}

.sidebar {
  background: var(--card);
  border-right: 1px solid var(--line);
  bottom: 0;
  flex-direction: column;
  left: 0;
  overflow-y: auto;
  position: fixed;
  top: 0;
  width: 232px;
  z-index: 100;
}

.sidebar-brand {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  min-height: 64px;
  padding: 12px 16px;
}

.sidebar-logo {
  display: block;
  height: 36px;
  max-width: 170px;
  object-fit: contain;
  width: auto;
}

.sidebar-logo-dark {
  display: none;
}

:root[data-theme="dark"] .sidebar-logo-light {
  display: none;
}

:root[data-theme="dark"] .sidebar-logo-dark {
  display: block;
}

.sidebar-nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  padding: 10px 8px;
}

.sidebar-section-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  margin: 10px 0 3px;
  padding: 0 10px;
  text-transform: uppercase;
}

.sidebar-link {
  align-items: center;
  border-radius: 6px;
  color: var(--text);
  display: flex;
  font-size: 14px;
  font-weight: 500;
  gap: 10px;
  padding: 8px 10px;
  text-decoration: none;
}

.sidebar-link:hover {
  background: var(--secondary-bg);
  text-decoration: none;
}

.sidebar-link svg {
  flex-shrink: 0;
  opacity: 0.65;
}

/* + Add — compact primary control replacing the persistent write links */
.sidebar-add {
  margin-bottom: 2px;
}
.sidebar-add-summary {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-weight: 600;
}
.sidebar-add-summary svg { opacity: 1; }
.sidebar-add-summary:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.sidebar-add[open] .sidebar-add-summary { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.sidebar-add-menu {
  left: 0;
  right: auto;
  top: calc(100% + 4px);
  bottom: auto;
  min-width: 200px;
}
.sidebar-add-item {
  align-items: center;
  border-radius: 6px;
  color: var(--text);
  display: flex;
  font-size: 14px;
  gap: 8px;
  padding: 8px 10px;
  text-decoration: none;
  white-space: nowrap;
}
.sidebar-add-item:hover { background: var(--secondary-bg); text-decoration: none; }
/* Collapsed rail: keep the add dropdown usable, anchored to the icon */
.sidebar.is-collapsed .sidebar-add-summary { justify-content: center; padding: 10px; }
.sidebar.is-collapsed .sidebar-add-menu { left: calc(100% + 6px); right: auto; top: 0; bottom: auto; }

.sidebar-badge {
  background: var(--warning);
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  margin-left: 10px;
  padding: 3px 7px;
}

.sidebar-footer {
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 8px;
}

.sidebar-theme-row {
  display: flex;
  gap: 4px;
  padding: 4px 10px 6px;
}

.sidebar-theme-row .button {
  flex: 1;
  justify-content: center;
  min-height: 32px;
  padding: 4px 6px;
}

.sidebar-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  margin-left: 232px;
  min-height: 100vh;
  min-width: 0;
}

.sidebar-topbar {
  align-items: center;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: none;
  gap: 12px;
  min-height: 56px;
  padding: 8px 14px;
  position: relative;
}

.sidebar-topbar > a {
  left: 50%;
  position: absolute;
  transform: translateX(-50%);
}

.sidebar-topbar-logo {
  height: 36px;
  max-width: 220px;
  object-fit: contain;
  width: auto;
}

.sidebar-overlay {
  background: rgba(0, 0, 0, 0.45);
  bottom: 0;
  display: none;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 99;
}

.sidebar-overlay.is-open {
  display: block;
}

@media (max-width: 820px) {
  .has-sidebar .sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }

  .has-sidebar .sidebar.is-open {
    transform: translateX(0);
  }

  .has-sidebar .sidebar-overlay.is-open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 99;
  }

  .has-sidebar .main-body {
    margin-left: 0;
  }

  .has-sidebar .sidebar-topbar {
    display: flex;
  }

  .sidebar-collapse-btn {
    display: none;
  }
}

.sidebar-collapse-btn {
  align-items: center;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  margin-left: auto;
  padding: 6px;
  transition: color 0.15s;
}

.sidebar-collapse-btn:hover {
  background: var(--secondary-bg);
  color: var(--text);
}

.sidebar-link.is-active {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
.sidebar-link.is-active svg { opacity: 1; }

.sidebar-user {
  align-items: center;
  display: flex;
  gap: 10px;
  padding: 6px 10px 2px;
}
.sidebar-avatar {
  align-items: center;
  background: var(--accent);
  border-radius: 999px;
  color: var(--accent-contrast);
  display: flex;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  height: 30px;
  justify-content: center;
  width: 30px;
}
.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar.is-collapsed .sidebar-user { justify-content: center; }
.sidebar.is-collapsed .sidebar-user-name { display: none; }

.sidebar.is-collapsed {
  width: 52px;
}

.sidebar.is-collapsed .sidebar-link-text,
.sidebar.is-collapsed .sidebar-section-label {
  display: none;
}

.sidebar.is-collapsed .sidebar-badge {
  display: none;
}

.sidebar.is-collapsed .sidebar-logo {
  display: none !important;
}

.sidebar.is-collapsed .sidebar-brand {
  justify-content: center;
  padding: 12px 8px;
}

.sidebar.is-collapsed .sidebar-link {
  justify-content: center;
  padding: 10px;
}

.sidebar.is-collapsed .sidebar-theme-row {
  flex-direction: column;
  padding: 4px 8px;
}

.sidebar.is-collapsed .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}

@media (min-width: 821px) {
  .has-sidebar.sidebar-is-collapsed .main-body {
    margin-left: 52px;
  }
}
/* ── End sidebar ─────────────────────────────────── */

footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  margin-top: 24px;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  flex-wrap: wrap;
}

.footer-copy {
  font-size: 13px;
  color: var(--muted);
}

.footer-right {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.footer-right a {
  color: var(--accent);
  text-decoration: none;
}

.footer-right a:hover {
  text-decoration: underline;
}

.footer-sep {
  color: var(--line);
}

.footer-help {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  margin-left: 4px;
}

.footer-help:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}

.nav-toggle {
  align-items: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: none;
  flex-direction: column;
  flex-shrink: 0;
  gap: 5px;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 10px;
}

.nav-toggle span {
  background: currentColor;
  border-radius: 2px;
  display: block;
  height: 2px;
  width: 18px;
}

/* Mobile view toggle — only visible on mobile */
.mv-toggle-form { display: none; }
.mv-toggle {
  align-items: center;
  background: var(--secondary-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  gap: 5px;
  min-height: 36px;
  padding: 4px 10px;
  white-space: nowrap;
}
.mv-toggle:hover { background: var(--line); }
/* In sidebar-topbar the form has no display:none default — hide on desktop */
.sidebar-topbar .mv-toggle-form { display: flex; }

@media (max-width: 820px) {
  .mv-toggle-form { display: flex; }
}

@media (min-width: 821px) {
  .sidebar-topbar .mv-toggle-form { display: none; }
}

@media (max-width: 820px) {
  .wrap {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .brand-heading {
    align-items: center;
    flex-direction: row;
    gap: 12px;
    justify-content: space-between;
    width: 100%;
  }

  .page-header {
    flex-direction: column;
    gap: 10px;
    padding-top: 14px;
  }

  .page-header h1 {
    font-size: 22px;
    white-space: normal;
  }

  .nav-toggle {
    display: flex;
  }

  .header-context {
    flex: none;
    justify-content: flex-start;
    min-width: 0;
    width: 100%;
  }

  .brand-logo {
    height: 40px;
    max-height: 40px;
    max-width: 100%;
    object-position: left center;
    width: 100%;
  }

  .brand-heading > a {
    flex: 1;
    min-width: 0;
  }

  .menu-bar {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    width: 100%;
  }

  .menu-bar.is-open {
    display: flex;
  }

  .button {
    padding: 7px 10px;
  }

  .card {
    padding: 14px;
  }

  .table-wrap {
    border-radius: 6px;
    margin-left: -2px;
    margin-right: -2px;
    max-width: calc(100vw - 24px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    font-size: 13px;
    min-width: 680px;
  }

  th,
  td {
    padding: 7px 8px;
  }

  th:first-child,
  td:first-child {
    left: 0;
    position: sticky;
    z-index: 1;
  }

  thead th:first-child {
    background: var(--table-header);
    z-index: 2;
  }

  tbody tr td:first-child {
    background: var(--card);
  }

  tbody tr:nth-child(even) td:first-child {
    background: var(--table-stripe);
  }

  tbody tr:hover td:first-child {
    background: var(--table-hover);
  }

  tbody tr.is-selected td:first-child,
  tbody tr.is-selected:nth-child(even) td:first-child,
  tbody tr.is-selected:hover td:first-child {
    background: var(--table-selected);
  }

  .summary,
  .two-column,
  .form-grid,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .quick-view {
    grid-template-columns: 1fr;
  }

  .vehicle-nav,
  .vehicle-selector,
  .menu,
  .menu-content {
    position: static;
    width: 100%;
  }

  .vehicle-nav {
    justify-content: flex-start;
  }

  .menu-content {
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .actions,
  .menu-bar {
    align-items: stretch;
  }

  .actions .button,
  .menu-bar > .button,
  .menu-bar > .menu,
  .menu summary {
    width: 100%;
  }

  table {
    min-width: 620px;
  }
}

/* ── Confirm modal ───────────────────────────────── */
.confirm-backdrop {
  align-items: center;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 500;
}
.confirm-backdrop.is-open { display: flex; }
.confirm-modal {
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  padding: 24px;
  width: 90%;
}
.confirm-modal p {
  font-size: 15px;
  margin: 0 0 20px;
}
.confirm-modal .actions {
  justify-content: flex-end;
}

/* ── Baseline prompt (inline schedule form) ─────── */
.baseline-prompt summary {
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  list-style: none;
  white-space: nowrap;
}
.baseline-prompt summary::-webkit-details-marker { display: none; }
.baseline-prompt summary::before { content: "+ "; }
.baseline-prompt[open] summary::before { content: "— "; }
.baseline-prompt form {
  display: grid;
  gap: 4px;
  margin-top: 6px;
}
.baseline-prompt input {
  font-size: 12px;
  min-height: 28px;
  padding: 2px 6px;
  width: 100%;
}
.baseline-prompt .button {
  font-size: 12px;
  min-height: 28px;
  padding: 0 10px;
}

/* ── Async button states ─────────────────────────── */
button[aria-busy="true"],
button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  pointer-events: none;
}
button[aria-busy="true"]::after {
  content: " \2026";
}

/* ── Data table ──────────────────────────────────── */
.data-table {
  border-collapse: collapse;
  width: 100%;
}
.data-table th {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  vertical-align: top;
}

/* ── Required field indicator ────────────────────── */
.form-row:has(input:required) > label::after,
.form-row:has(select:required) > label::after,
.form-row:has(textarea:required) > label::after {
  color: var(--danger);
  content: " *";
}
.form-submit {
  margin: 16px 0 0;
}

/* ── Service Code Badges ─────────────────────────── */
.svc-code-badge {
  background: var(--accent-bg, #e8f0fe);
  border-radius: 4px;
  color: var(--accent, #1a73e8);
  font-family: monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  text-transform: uppercase;
  vertical-align: middle;
}

/* ── Service History Grouping ────────────────────── */
.svc-group { border-bottom: 1px solid var(--line); padding: 6px 0; }
.svc-group:last-child { border-bottom: none; }
.svc-group-primary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.svc-group-meta { color: var(--muted); font-size: 12px; }
.svc-group-children-count { color: var(--muted); font-size: 11px; font-style: italic; }
.svc-group-children { list-style: none; margin: 4px 0 0 16px; padding: 0; }
.svc-group-children li { color: var(--muted); font-size: 12px; padding: 1px 0; }
.svc-group-children li a { color: var(--muted); }

/* ── Shared insight-page chips (Costs, Fuel Economy, Maintenance) ── */
.insight-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 14px; border-radius: 20px; font-size: 0.83rem; font-weight: 500;
  text-decoration: none; color: var(--muted);
  background: var(--secondary-bg); border: 1px solid var(--line);
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap; cursor: pointer;
}
.insight-chip:hover { color: var(--accent); border-color: var(--accent); }
.insight-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.insight-chip-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ── Shared search/filter bar (Service Log, Maintenance, Service Library) ── */
.sl-filter-bar {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 16px;
}
.sl-filter-item { display: flex; flex-direction: column; gap: 4px; }
.sl-filter-item.grow { flex: 1; min-width: 160px; }
.sl-filter-label {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted);
}
.sl-filter-item input,
.sl-filter-item select {
  border: 1px solid var(--line); border-radius: 8px; background: var(--secondary-bg);
  color: var(--text); font-size: 0.875rem; padding: 7px 10px;
  transition: border-color .15s; outline: none; width: 100%;
}
.sl-filter-item input:focus,
.sl-filter-item select:focus { border-color: var(--accent); }
.sl-filter-clear {
  padding: 7px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--secondary-bg); color: var(--muted); font-size: 0.875rem;
  cursor: pointer; transition: color .15s, border-color .15s; align-self: flex-end;
  text-decoration: none; display: inline-block;
}
.sl-filter-clear:hover { color: var(--accent); border-color: var(--accent); }
@media (max-width: 640px) {
  .sl-filter-bar { flex-direction: column; align-items: stretch; }
  .sl-filter-item.grow { min-width: 0; }
}

/* ── Hover utility classes (replace onmouseover/onmouseout) ── */
.hover-muted { color: var(--muted); text-decoration: none; }
.hover-muted:hover { color: var(--text); }
.hover-accent { color: var(--text); text-decoration: none; }
.hover-accent:hover { color: var(--accent); }

/* ─── Bounded-polling delayed state ─────────────────── */
.mgp-poll-delayed {
  background: var(--card, #fff); border: 1px solid var(--border, #e5e9f0);
  border-radius: 12px; padding: 24px; text-align: center; max-width: 520px; margin: 24px auto;
}
.mgp-poll-delayed-title { font-size: 18px; font-weight: 700; margin: 0 0 8px; }
.mgp-poll-delayed-msg,
.mgp-poll-delayed-net { font-size: 14px; color: var(--muted, #637083); margin: 0 0 4px; }
.mgp-poll-delayed-actions {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px;
}
