/* ===== Design tokens (Modernist — dark surface, validated categorical palette) =====
   The surface, text and accent tokens below are defaults only: applyCarTheme()
   in app.js overwrites them on :root with values derived from the selected
   car's colour, so the whole app takes on the colour of the car.
   Shape language borrows from the "Modernist" design system: square corners,
   heavier dividers, and Archivo as a bold display face for headings. */
:root {
  color-scheme: dark;
  --page: #232120;
  --surface-1: #2d2b2b;
  --surface-2: #383635;
  --surface-3: #444141;
  --text-primary: #f3f2f2;
  --text-secondary: #c7c5c3;
  --text-muted: #8f8d8a;
  --gridline: #3a3837;
  --baseline: #4a4746;
  --border: color-mix(in srgb, #f3f2f2 16%, transparent);
  --divider: color-mix(in srgb, #f3f2f2 22%, transparent);

  /* Chart series live in app.js (PALETTE): the primary series follows the
     car's accent, the rest are picked to keep a clear hue gap from it. */

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  /* Car-colour driven accent set (overwritten per car at runtime) */
  --accent: #3987e5;
  --accent-hover: #4c94ea;
  --accent-ink: #ffffff;
  --accent-soft: rgba(57, 135, 229, 0.14);
  --accent-ring: rgba(57, 135, 229, 0.28);
  --accent-glow: rgba(57, 135, 229, 0.45);
  --car-paint: #3987e5;

  --radius-sm: 0px;
  --radius-md: 0px;
  --radius-lg: 0px;
  --shadow-card: 0 1px 2px color-mix(in srgb, #000 30%, transparent), 0 8px 22px color-mix(in srgb, #000 22%, transparent);
  --font-body: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-heading: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-heading-weight: 800;
  --font: var(--font-body);
  --tabbar-h: 64px;
  --header-h: 60px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px; /* keeps iOS from zooming in when a field is focused */
  background: var(--page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  transition: background-color 0.35s ease, color 0.35s ease;
}
/* Nothing should ever push the page sideways. Long words, pasted plate numbers
   and OCR'd garage names all wrap rather than widening their container. */
.banner, .hint, .warn-hint, .list-empty, .import-notes, .status-row .v,
.card p, .field label { overflow-wrap: anywhere; }
/* Switching cars re-tints every surface — ease it instead of snapping. */
.card, .stat-tile, .topbar, .tabbar, .car-bar, .modal, .pin-key,
input, select, textarea, .toggle-row, .lang-btn, .btn-secondary {
  transition: background-color 0.35s ease, border-color 0.35s ease;
}
@media (prefers-reduced-motion: reduce) {
  body, .card, .stat-tile, .topbar, .tabbar, .car-bar, .modal, .pin-key,
  input, select, textarea, .toggle-row, .lang-btn, .btn-secondary { transition: none; }
}
a { color: inherit; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3, h4 {
  margin: 0; font-family: var(--font-heading); font-weight: var(--font-heading-weight);
  letter-spacing: -0.015em; line-height: 1.15;
}
p { margin: 0; }
img { max-width: 100%; display: block; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* ===== App shell ===== */
/* `clip` rather than `hidden`: it contains any stray horizontal overflow
   without turning the shell into a scroll container, which would break the
   sticky top bar. */
.app-shell { min-height: 100%; display: flex; flex-direction: column; overflow-x: clip; }
/* Car-colour hairline across the top of every screen, phone included. */
.app-shell::before {
  content: "";
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 45;
  background: linear-gradient(90deg, var(--accent), var(--car-paint));
  pointer-events: none;
}

.topbar {
  display: none;
  align-items: center;
  gap: 28px;
  height: var(--header-h);
  padding: 0 24px;
  border-bottom: 2px solid var(--divider);
  background: var(--surface-1);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-heading); font-weight: var(--font-heading-weight); font-size: 17px; }
.topbar .brand .dot { width: 10px; height: 10px; background: var(--car-paint); box-shadow: 0 0 0 3px var(--accent-ring); }
.topbar nav { display: flex; gap: 20px; margin-left: 4px; height: 100%; }
.topbar .nav-item {
  display: flex; align-items: center; gap: 8px; height: 100%;
  padding: 0; border-bottom: 2px solid transparent; margin-bottom: -2px;
  color: var(--text-secondary); text-decoration: none; font-size: 14px; font-weight: 600;
  cursor: pointer; border-left: none; border-right: none; border-top: none; background: transparent;
}
.topbar .nav-item:hover { color: var(--text-primary); }
.topbar .nav-item.active { color: var(--accent); border-bottom-color: var(--accent); }
.topbar .spacer { flex: 1; }

.car-bar {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface-1);
  border-bottom: 2px solid var(--accent-ring);
}
.car-switcher {
  width: 100%;
  max-width: 320px;
  padding: 8px 12px;
  font-weight: 600;
}
@media (min-width: 860px) {
  .car-bar { padding: 10px 24px; }
}

main.content {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: var(--tabbar-h);
  background: var(--surface-1);
  border-top: 2px solid var(--divider);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar .tab-item {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; color: var(--text-muted); background: none; border: none; font-size: 11px; font-weight: 500;
  cursor: pointer; padding: 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tabbar .tab-item svg { width: 22px; height: 22px; }
.tabbar .tab-item.active { color: var(--accent); }
.tabbar .tab-item.fab-slot { position: relative; overflow: visible; }
.tabbar .fab {
  position: absolute; top: -22px; left: 50%; transform: translateX(-50%);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: 4px solid var(--page);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px var(--accent-glow);
}
.tabbar .fab svg { width: 26px; height: 26px; }

@media (min-width: 860px) {
  .topbar { display: flex; }
  .tabbar { display: none; }
  main.content { padding: 28px 24px 48px; }
}

/* ===== Page header ===== */
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--text-muted); font-size: 13px; }

/* ===== Dashboard hero (per-car photo + colour accent) ===== */
.hero-card {
  --hero-photo: url('/img/car-hero.png');
  position: relative;
  overflow: hidden;
  min-height: 260px;
  display: flex;
  align-items: flex-end;
  background-image: linear-gradient(90deg, rgba(13,13,13,0.95) 0%, rgba(13,13,13,0.82) 34%, rgba(13,13,13,0.30) 72%, rgba(13,13,13,0.06) 100%), var(--hero-photo);
  background-size: cover;
  background-position: 68% 62%;
  border: 1px solid var(--divider);
  border-left: 4px solid var(--accent);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-bottom: 14px;
}
/* Colour wash tying the hero to the car's paint. */
.hero-card::before {
  content: "";
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg, var(--accent-soft), transparent 62%);
}
.hero-card .hero-content { position: relative; display: flex; flex-direction: column; gap: 10px; max-width: 380px; }
.hero-card .hero-title { font-family: var(--font-heading); font-size: 20px; font-weight: var(--font-heading-weight); }
.hero-card .hero-sub { font-size: 12px; color: var(--text-secondary); margin-top: -6px; }
.hero-card .hero-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hero-card .hero-plate {
  display: inline-flex; align-self: flex-start; align-items: center; gap: 6px;
  background: #f7b500; color: #16181c; font-weight: 700; letter-spacing: 0.02em;
  padding: 3px 10px 3px 6px; border-radius: 2px; font-size: 13px; border: 2px solid #16181c;
}
.hero-card .hero-plate .flag { width: 13px; height: 17px; background: #003399; border-radius: 1px; }
.hero-card .hero-color {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,0.35); color: var(--text-secondary);
  padding: 3px 10px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--border);
}
.hero-card .hero-color .swatch { width: 10px; height: 10px; flex: none; border: 1px solid rgba(255,255,255,0.3); }
.hero-card .hero-stats { display: flex; gap: 26px; margin-top: 6px; flex-wrap: wrap; }
.hero-card .hero-stat .num { font-family: var(--font-heading); font-size: 23px; font-weight: var(--font-heading-weight); line-height: 1.1; }
.hero-card .hero-stat .lbl { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-secondary); margin-top: 2px; }
@media (max-width: 640px) {
  .hero-card {
    min-height: 220px;
    padding: 16px;
    background-image: linear-gradient(180deg, rgba(13,13,13,0.20) 0%, rgba(13,13,13,0.55) 55%, rgba(13,13,13,0.95) 100%), var(--hero-photo);
    background-position: center 30%;
    align-items: flex-end;
  }
  .hero-card .hero-title { font-size: 17px; }
}

/* ===== Cards & grid ===== */
.card {
  background: var(--surface-1);
  padding: 18px;
}
.card + .card { margin-top: 14px; }
main.content > * + * { margin-top: 14px; }
.card h3 {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); font-weight: 700;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }

.grid { display: grid; gap: 12px; }
/* minmax(0, 1fr) instead of 1fr: grid items default to min-content width, so a
   long money value in one tile would otherwise widen the whole row. */
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid > * { min-width: 0; }
@media (max-width: 640px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
}

/* ===== Stat tiles ===== */
.stat-tile { background: var(--surface-1); border: 1px solid var(--border); padding: 14px 16px; min-width: 0; }
.stat-tile .label { font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; overflow-wrap: anywhere; }
/* Two tiles per row on a 320px phone leaves ~130px for "€ 1.234,56". */
.stat-tile .value { font-family: var(--font-heading); font-size: clamp(18px, 5.4vw, 24px); font-weight: var(--font-heading-weight); line-height: 1.1; overflow-wrap: anywhere; }
.stat-tile .value small { font-family: var(--font-body); font-size: 13px; color: var(--text-secondary); font-weight: 500; margin-left: 4px; }
.stat-tile .delta { margin-top: 6px; font-size: 12px; font-weight: 600; }
.stat-tile .delta.good { color: var(--good); }
.stat-tile .delta.bad { color: var(--critical); }
.stat-tile .delta.neutral { color: var(--text-muted); }

/* ===== Alerts / badges ===== */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; font-size: 13px; border: 1px solid; margin-bottom: 10px; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert.warning { background: rgba(250, 178, 25, 0.10); border-color: rgba(250, 178, 25, 0.35); color: #ffd27a; }
.alert.critical { background: rgba(208, 59, 59, 0.12); border-color: rgba(208, 59, 59, 0.4); color: #ff9d9d; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; font-size: 11px; letter-spacing: 0.02em; font-weight: 700; }
.badge.good { background: rgba(12, 163, 12, 0.16); color: #6fe36f; }
.badge.warning { background: rgba(250, 178, 25, 0.16); color: #ffd27a; }
.badge.critical { background: rgba(208, 59, 59, 0.16); color: #ff9d9d; }
.badge.neutral { background: var(--surface-3); color: var(--text-secondary); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent;
  padding: 10px 16px; font-family: var(--font-heading); font-size: 14px; font-weight: var(--font-heading-weight); cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-3); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: #2f2e2c; }
.btn-danger { background: rgba(208, 59, 59, 0.14); color: #ff9d9d; border-color: rgba(208, 59, 59, 0.35); }
.btn-danger:hover { background: rgba(208, 59, 59, 0.22); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 18px; font-size: 15px; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field label { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.field .hint { font-size: 11px; color: var(--text-muted); }
.field .warn-hint { font-size: 11px; color: var(--warning); }
input[type="text"], input[type="number"], input[type="date"], input[type="time"], input[type="datetime-local"],
select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 11px 12px;
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.25;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
/* Mobile Safari gives date/time inputs an intrinsic width that ignores
   `width: 100%`, which is what pushes them past the edge of a card. Dropping
   the native appearance makes them behave like every other field. */
input[type="date"], input[type="time"], input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}
input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(0.7); }
/* A custom chevron keeps selects the same height and shape everywhere, and
   lets a long car name ellipsis instead of stretching the control. */
select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 34px;
  text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
textarea { resize: vertical; min-height: 70px; }
/* flex-basis rather than min-width, so a pair either sits side by side at a
   readable width or wraps — never squeezed to something unusable. */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > .field { flex: 1 1 140px; min-width: 0; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface-2); border: 1px solid var(--border); padding: 11px 12px; margin-bottom: 14px; }
.toggle-row > span:first-child { min-width: 0; }

/* Marks a field the RDW register fills in by itself. */
.tag-rdw {
  flex: none; font-size: 9px; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 5px; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-ring);
}
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; transition: background 0.15s; }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--text-muted); transition: transform 0.15s, background 0.15s; }
.switch input:checked + .track { background: var(--accent-ring); }
.switch input:checked + .track .thumb { transform: translateX(18px); background: var(--accent); }

.lang-toggle { display: flex; gap: 8px; }
.lang-btn {
  flex: 1; padding: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-secondary); font-family: var(--font-heading); font-weight: 700; font-size: 14px; cursor: pointer;
}
.lang-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ===== Car colour picker ===== */
.color-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.color-chip {
  width: 30px; height: 30px; padding: 0; cursor: pointer;
  background: var(--chip); border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.color-chip.selected {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}
.color-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.color-dot {
  display: inline-block; width: 9px; height: 9px; margin-right: 6px;
  vertical-align: baseline; border: 1px solid rgba(255, 255, 255, 0.3);
}

/* ===== Chart cards ===== */
.chart-wrap { position: relative; height: 220px; }
.chart-legend { display: flex; gap: 16px; margin-top: 10px; flex-wrap: wrap; }
.chart-legend .item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.chart-legend .swatch { width: 10px; height: 10px; }
.chart-empty { display: flex; align-items: center; justify-content: center; height: 220px; color: var(--text-muted); font-size: 13px; text-align: center; padding: 0 20px; }

.table-toggle { margin-top: 10px; }
.table-toggle summary { cursor: pointer; font-size: 12px; color: var(--text-muted); list-style: none; user-select: none; }
.table-toggle summary::-webkit-details-marker { display: none; }
.table-toggle summary:before { content: "▸ "; }
.table-toggle[open] summary:before { content: "▾ "; }
.table-toggle table { margin-top: 8px; }

/* ===== Collapsible form sections (specs, purchase, odometer history) ===== */
.form-section { margin: 16px 0; border: 1px solid var(--border); background: var(--surface-2); }
.form-section > summary {
  cursor: pointer; padding: 11px 12px; font-size: 14px; font-weight: 600;
  list-style: none; user-select: none;
}
.form-section > summary::-webkit-details-marker { display: none; }
.form-section > summary:before { content: "▸ "; color: var(--text-muted); }
.form-section[open] > summary:before { content: "▾ "; }
.form-section > *:not(summary) { padding-left: 12px; padding-right: 12px; }
.form-section > *:last-child { margin-bottom: 12px; }
.form-section .hint { display: block; font-size: 11px; color: var(--text-muted); }
.btn-icon { padding: 6px; flex: none; }
.btn-icon svg { width: 16px; height: 16px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-sm svg { width: 14px; height: 14px; }

/* Sub-groups inside the specification section (identity, engine, body, …). */
.spec-group + .spec-group { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--gridline); }
.spec-group h5 {
  margin: 0 0 10px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
}

/* ===== Vehicle status (RDW register) ===== */
.status-list { display: flex; flex-direction: column; }
.status-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--gridline); font-size: 13px;
}
.status-row:last-child { border-bottom: none; }
.status-row .k { color: var(--text-secondary); min-width: 0; }
.status-row .v { display: flex; align-items: center; gap: 8px; justify-content: flex-end; flex-wrap: wrap; text-align: right; font-weight: 600; }

/* ===== Maintenance attachments ===== */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.doc-tile {
  position: relative; border: 1px solid var(--border);
  background: var(--surface-2); overflow: hidden;
}
.doc-tile .doc-open { display: flex; flex-direction: column; text-decoration: none; }
.doc-tile img { width: 100%; height: 92px; object-fit: cover; background: var(--surface-3); }
.doc-tile .doc-icon {
  display: flex; align-items: center; justify-content: center;
  height: 92px; color: var(--accent); background: var(--accent-soft);
}
.doc-tile .doc-icon svg { width: 30px; height: 30px; }
.doc-tile .doc-name {
  display: block; padding: 7px 8px; font-size: 11px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-tile .doc-remove {
  position: absolute; top: 5px; right: 5px; width: 26px; height: 26px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%; cursor: pointer;
  background: rgba(0, 0, 0, 0.62); color: #fff;
}
.doc-tile .doc-remove svg { width: 14px; height: 14px; }
/* Attachment count on a maintenance row. */
.doc-pill { display: inline-flex; align-items: center; gap: 3px; vertical-align: -2px; }
.doc-pill svg { width: 12px; height: 12px; }

/* ===== Import summary ===== */
.import-notes { margin: 0 0 14px 18px; padding: 0; font-size: 13px; color: var(--text-secondary); }
.import-notes li { margin-bottom: 6px; }
.import-notes li:last-child { margin-bottom: 0; }
.table-toggle .import-notes { margin-top: 8px; }
.toggle-row .hint { font-size: 11px; color: var(--text-muted); margin-top: 3px; max-width: min(34ch, 100%); }

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--gridline); font-variant-numeric: tabular-nums; }
th { color: var(--text-muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 2px solid var(--divider); }
tbody tr:hover { background: var(--surface-2); }
/* Wide tables scroll inside their own box instead of widening the page. */
.table-scroll { overflow-x: auto; max-width: 100%; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
.access-select { min-width: 96px; }

/* ===== History list ===== */
.fillup-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--gridline); cursor: pointer; }
.fillup-row:last-child { border-bottom: none; }
.fillup-row:hover { background: var(--surface-2); }
.fillup-row .thumb { width: 44px; height: 44px; object-fit: cover; background: var(--surface-3); flex: none; }
.fillup-row .thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.fillup-row .thumb.placeholder svg { width: 20px; height: 20px; }
.fillup-row .main { flex: 1; min-width: 0; }
.fillup-row .main .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 14px; }
.fillup-row .main .bottom { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-muted); margin-top: 2px; }
/* A garage name or a long description truncates; the amount on the right is
   the one thing that must always stay readable in full. */
.fillup-row .main .top > span,
.fillup-row .main .bottom > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fillup-row .main .top > span:last-child,
.fillup-row .main .bottom > span:last-child { flex: 0 1 auto; text-align: right; }
.fillup-row .main .top > span:first-child,
.fillup-row .main .bottom > span:first-child { flex: 1 1 auto; }
/* The attachment count must survive a long description, so the text truncates
   inside its own element and the badge sits outside the clipped box. */
.fillup-row .main .bottom > .trailing { display: flex; align-items: center; gap: 6px; overflow: visible; }
.fillup-row .main .bottom > .trailing .ellip { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fillup-row .main .bottom > .trailing .doc-pill { flex: none; }
.list-empty { padding: 40px 10px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ===== Modal / lightbox ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50; padding: 0;
}
.modal {
  background: var(--surface-1); border: 1px solid var(--border);
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}
/* dvh follows the on-screen keyboard, so a focused field at the bottom of a
   long form stays reachable on a phone. */
@supports (height: 100dvh) {
  .modal { max-height: 92dvh; }
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { max-height: 86vh; }
  @supports (height: 100dvh) {
    .modal { max-height: 86dvh; }
  }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 2px solid var(--divider); }
.modal-head h3 { font-family: var(--font-heading); font-size: 18px; font-weight: var(--font-heading-weight); color: var(--text-primary); }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; }
.modal-close svg { width: 20px; height: 20px; }
.receipt-full { width: 100%; margin-bottom: 14px; }

/* ===== Banner / toast ===== */
.banner { padding: 12px 14px; font-size: 13px; margin-bottom: 14px; border: 1px solid; }
.banner.info { background: var(--accent-soft); border-color: var(--accent-ring); color: var(--accent); }
.banner.error { background: rgba(208, 59, 59, 0.12); border-color: rgba(208, 59, 59, 0.4); color: #ff9d9d; }

.loading-block { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 40px 0; color: var(--text-muted); font-size: 13px; }

/* ===== Car loader (fill-up animation) — a pump drips fuel into the car
   emoji while a gauge bar underneath fills and resets. Replaces the old
   plain spinner wherever the app is waiting on something (initial load, OCR). */
.car-loader { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.car-loader .cl-emoji-row { position: relative; display: flex; align-items: center; gap: 2px; font-size: 30px; line-height: 1; }
.car-loader .cl-car { animation: cl-car-bounce 1.1s ease-in-out infinite; }
.car-loader .cl-drop { position: absolute; left: 32px; top: 0; font-size: 13px; opacity: 0; animation: cl-drop-fall 1.2s ease-in infinite; }
.car-loader .cl-drop-2 { animation-delay: 0.4s; }
.car-loader .cl-drop-3 { animation-delay: 0.8s; }
.car-loader .cl-gauge-track { width: 96px; height: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.car-loader .cl-gauge-fill { display: block; height: 100%; background: var(--accent); transform-origin: left; animation: cl-fill 2.4s ease-in-out infinite; }
@keyframes cl-drop-fall {
  0%   { opacity: 0; transform: translate(0, 0); }
  20%  { opacity: 1; }
  70%  { opacity: 1; transform: translate(10px, 14px); }
  100% { opacity: 0; transform: translate(13px, 17px); }
}
@keyframes cl-car-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}
@keyframes cl-fill {
  0%, 6%   { transform: scaleX(0); }
  70%, 82% { transform: scaleX(1); }
  100%     { transform: scaleX(0); }
}
@media (prefers-reduced-motion: reduce) {
  .car-loader .cl-car { animation: none; }
  .car-loader .cl-drop { animation: none; opacity: 0.85; }
  .car-loader .cl-gauge-fill { animation: none; transform: scaleX(0.55); }
}

/* ===== Add fill-up: capture ===== */
.capture-hero { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 30px 16px; text-align: center; }
.capture-hero .icon-circle { width: 84px; height: 84px; border: 2px solid var(--accent); display: flex; align-items: center; justify-content: center; color: var(--accent); }
.capture-hero .icon-circle svg { width: 38px; height: 38px; }
.capture-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; }
.capture-hero input[type="file"] { display: none; }

/* ===== Utility ===== */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.mono-num { font-variant-numeric: tabular-nums; }
.mt-0 { margin-top: 0; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hidden { display: none !important; }
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

/* ===== PIN pad (login) ===== */
.pin-screen {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; gap: 30px; text-align: center;
}
.pin-screen .brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pin-screen .brand .icon-circle { width: 56px; height: 56px; border: 2px solid var(--text-primary); display: flex; align-items: center; justify-content: center; color: var(--text-primary); }
.pin-screen .brand .icon-circle svg { width: 26px; height: 26px; }
.pin-screen .brand h1 { font-family: var(--font-heading); font-size: 22px; font-weight: var(--font-heading-weight); }
.pin-screen .brand p { font-size: 13px; color: var(--text-muted); }

.pin-dots { display: flex; gap: 14px; height: 14px; }
.pin-dots .dot { width: 14px; height: 14px; border: 2px solid var(--text-primary); transition: background 0.1s, border-color 0.1s; }
.pin-dots .dot.filled { background: var(--accent); border-color: var(--accent); }
.pin-dots.shake { animation: shake 0.4s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.pin-status { font-size: 12px; color: var(--text-muted); min-height: 16px; }
.pin-status.locked { color: var(--critical); }

.pin-keypad { display: grid; grid-template-columns: repeat(3, 64px); gap: 14px; }
.pin-key {
  width: 64px; height: 64px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); font-family: var(--font-heading); font-size: 20px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.pin-key:hover:not(:disabled) { background: var(--surface-3); }
.pin-key:active { background: var(--surface-3); }
.pin-key:disabled { opacity: 0.35; cursor: not-allowed; }
.pin-key.ghost { background: transparent; border: none; cursor: default; }
.pin-key.ghost:active { background: transparent; }

/* ===== Phones =====
   Everything below is about the app being used one-handed on a phone in a
   petrol station forecourt: nothing clipped, nothing below the thumb, and
   tap targets you can actually hit. */
@media (max-width: 640px) {
  main.content { padding-left: 12px; padding-right: 12px; }
  .card { padding: 14px; border-radius: var(--radius-md); }
  .stat-tile { padding: 12px 13px; }

  .page-head { margin-bottom: 14px; }
  .page-head h1 { font-size: 20px; }
  .page-head .btn { flex: none; }

  .hero-card .hero-stats { gap: 16px; }
  .hero-card .hero-stat .num { font-size: 20px; }

  /* Comfortable thumb targets — 44px is the smallest that reliably works. */
  .btn { min-height: 44px; padding: 11px 14px; }
  .btn-sm { min-height: 34px; }
  .btn-icon { min-height: 38px; min-width: 38px; }
  .color-chip { width: 34px; height: 34px; }
  .modal-close { min-width: 40px; min-height: 40px; display: flex; align-items: center; justify-content: center; }

  .modal { padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); }
  .form-section > *:not(summary) { padding-left: 10px; padding-right: 10px; }

  /* Label above value reads better than a squeezed two-column row. */
  .status-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .status-row .v { justify-content: flex-start; text-align: left; }

  .doc-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }

  .chart-wrap, .chart-empty { height: 200px; }
  th, td { padding: 7px 8px; }
}

/* Very narrow phones (iPhone SE and similar): one field per row everywhere. */
@media (max-width: 380px) {
  .form-row > .field { flex-basis: 100%; }
  .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .capture-actions { max-width: none; }
}

/* Landscape on a phone leaves almost no vertical room — give the sheet the
   full height and let it scroll rather than squashing the form. */
@media (max-height: 460px) and (orientation: landscape) {
  .modal { max-height: 100vh; border-radius: 0; }
  .capture-hero { padding: 16px; }
  .capture-hero .icon-circle { width: 56px; height: 56px; }
  .capture-hero .icon-circle svg { width: 26px; height: 26px; }
}
