/* Fonts are vendored (OFL-1.1, via @fontsource) so the app works offline and
   doesn't ping Google on every page load. */
@font-face { font-family: "Onest"; font-weight: 400; font-display: swap; src: url("../vendor/fonts/onest-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Onest"; font-weight: 500; font-display: swap; src: url("../vendor/fonts/onest-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Onest"; font-weight: 600; font-display: swap; src: url("../vendor/fonts/onest-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Onest"; font-weight: 700; font-display: swap; src: url("../vendor/fonts/onest-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Doto"; font-weight: 800; font-display: swap; src: url("../vendor/fonts/doto-latin-800-normal.woff2") format("woff2"); }

/* --- Tokens ----------------------------------------------------------
   Palette borrows from the Ioniq 5: Cyber Gray body, Digital Teal accent,
   Gravity Gold for energy/money. Light mode ("Atlas White") follows the OS. */
:root {
  color-scheme: dark;
  --bg: #1b1e22;
  --surface: #23272c;
  --surface-2: #2b3036;
  --line: #353b42;
  --text: #edf0ee;
  --muted: #99a1a8;
  --accent: #4fc7b4;
  --accent-ink: #0b2a25;
  --accent-soft: rgba(79, 199, 180, 0.14);
  --energy: #d6b06a;
  --energy-soft: rgba(214, 176, 106, 0.16);
  --good: #4fc7b4;
  --warn: #e3a34a;
  --bad: #ee6f63;
  --bad-soft: rgba(238, 111, 99, 0.14);
  --pixel-off: #30353b;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 12px 32px -18px rgba(0, 0, 0, 0.6);
  --map-filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.4);
  /* chart series for the consumption breakdown */
  --s-drive: #4fc7b4;
  --s-climate: #d6b06a;
  --s-electronics: #7f9cc7;
  --s-care: #b495d8;

  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-pixel: "Doto", "Onest", monospace;
  --r-lg: 16px;
  --r-md: 10px;
  --r-sm: 7px;
  --sidebar: 232px;
  --tabbar: 64px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #eceeed;
    --surface: #ffffff;
    --surface-2: #f4f5f5;
    --line: #dadedd;
    --text: #1c2024;
    --muted: #5d666c;
    --accent: #0f8575;
    --accent-ink: #ffffff;
    --accent-soft: rgba(15, 133, 117, 0.1);
    --energy: #94702a;
    --energy-soft: rgba(148, 112, 42, 0.12);
    --good: #0f8575;
    --warn: #b36b0c;
    --bad: #c43d33;
    --bad-soft: rgba(196, 61, 51, 0.1);
    --pixel-off: #dfe3e2;
    --shadow: 0 1px 2px rgba(20, 30, 30, 0.05), 0 10px 30px -20px rgba(20, 30, 30, 0.25);
    --map-filter: saturate(0.55) contrast(0.95);
    --s-drive: #0f8575;
    --s-climate: #b08433;
    --s-electronics: #4d6c9c;
    --s-care: #7d58a8;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }

.muted { color: var(--muted); font-weight: 400; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { text-align: right; }

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

/* --- Buttons & form controls ------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn .icon { width: 16px; height: 16px; }
.btn-quiet { background: transparent; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.06); }
.btn.is-busy .icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

input:not([type="checkbox"]), select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* >= 16px keeps iOS from zooming into the field */
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
select { width: auto; padding-right: 30px; }

/* --- Login -------------------------------------------------------- */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 32px 28px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.login-card .brand-mark { width: 28px; height: 28px; margin-bottom: 6px; }
.login-card h1 { margin: 0; font-size: 1.45rem; }
.login-card p { margin: -8px 0 8px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.login-card .btn { min-height: 44px; margin-top: 6px; font-size: 1rem; }
.error { color: var(--bad); font-size: 0.88rem; margin: 0; }

/* --- Phone trip recorder (track.html) ------------------------------- */
.track-body main.track {
  margin: 0 auto;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.track-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.track-header .btn { padding-left: 0; }
.track-warning { margin: 0; padding: 12px 14px; border-radius: var(--r-md); background: var(--bad-soft); color: var(--text); font-size: 0.9rem; }
.track-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 16px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.track-speed { display: flex; align-items: baseline; gap: 10px; font-family: var(--font-pixel); font-size: clamp(4.5rem, 26vw, 7rem); line-height: 1; color: var(--accent); }
.track-speed.is-empty { font-family: var(--font); font-weight: 600; color: var(--muted); }
.track-speed small { font-family: var(--font); font-size: 1rem; font-weight: 400; color: var(--muted); }
.track-elapsed { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.track-figures { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.track-figures div { padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); min-width: 0; }
.track-figures dt { color: var(--muted); font-size: 0.78rem; }
.track-figures dd { margin: 2px 0 0; font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.track-toggle { min-height: 60px; font-size: 1.15rem; justify-content: center; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.track-status { margin: -6px 0 0; text-align: center; font-size: 0.9rem; min-height: 1.3em; }
.track-status.ok { color: var(--good); }
.track-status.error { color: var(--bad); }
.track-help { font-size: 0.88rem; color: var(--muted); }
.track-help summary { cursor: pointer; color: var(--text); }
.track-help code { font-size: 0.82rem; }

/* --- Trip detail (5 s GPS track) ------------------------------------ */
.trip-detail { margin-bottom: 14px; }
.trip-detail[hidden] { display: none; }
.trip-detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px 14px; flex-wrap: wrap; margin-bottom: 12px; }
.trip-detail-title { font-weight: 600; overflow-wrap: anywhere; }
.trip-detail .figures dd { font-weight: 600; }
.map-legend[hidden] { display: none; }
.speed-legend .swatch { height: 5px; }
tr.is-selected td { background: var(--accent-soft); }
.gps-flag { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 0.72rem; font-weight: 600; vertical-align: 1px; }

/* --- App shell: sidebar on desktop, top bar + bottom tabs on mobile ---- */
.app { min-height: 100vh; }

.topbar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 1100; /* above Leaflet's panes/controls (up to 1000) */
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-mark { width: 22px; height: 22px; fill: var(--accent); flex: 0 0 auto; }
.brand-mark .dim { opacity: 0.35; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-name { font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-size: 0.8rem; }
.brand-sub:empty { display: none; }

.tabs { display: flex; flex-direction: column; gap: 2px; }
.tab-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--r-md);
  background: none;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.tab-btn:hover { color: var(--text); background: var(--surface-2); }
.tab-btn.active { color: var(--text); background: var(--surface-2); }
.tab-btn.active .icon { color: var(--accent); }
.tab-btn.active::before {
  /* a single lit "pixel" marks the current section */
  content: "";
  position: absolute;
  left: -16px;
  top: 50%;
  width: 4px;
  height: 18px;
  margin-top: -9px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.lbl-short { display: none; }

.topbar-actions { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.topbar-actions .btn { justify-content: flex-start; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  line-height: 1.3;
  color: var(--muted);
}
.badge:empty { display: none; }
.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 2px;
  background: currentColor;
}
.badge.ok::before { background: var(--good); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }

main {
  margin-left: var(--sidebar);
  padding: 32px 36px 48px;
  max-width: calc(var(--sidebar) + 1180px);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Hero: the battery as a field of parametric pixels ---------------- */
.hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px 40px;
  align-items: end;
  padding: 28px 30px 26px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.hero:empty { display: none; }
.hero-soc { display: flex; flex-direction: column; gap: 4px; }
.hero-soc-value {
  font-family: var(--font-pixel);
  font-weight: 800;
  font-size: 116px;
  line-height: 0.82;
  letter-spacing: -0.02em;
  color: var(--text);
}
.hero-soc-value small { font-family: var(--font); font-weight: 500; font-size: 0.3em; margin-left: 0.14em; color: var(--muted); letter-spacing: 0; }
.hero-caption { color: var(--muted); font-size: 0.9rem; }
.hero-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.hero-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 26px; }
.hero-range { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.02em; }
.hero-range span { font-size: 0.95rem; font-weight: 400; color: var(--muted); margin-left: 6px; letter-spacing: 0; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 9px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.chip .icon { width: 15px; height: 15px; }
.chip.charging { background: var(--energy-soft); color: var(--energy); }
.chip.plugged { background: var(--accent-soft); color: var(--accent); }

.pixels {
  --cols: 20;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-auto-rows: 1fr;
  gap: 4px;
  width: 100%;
  max-width: 640px;
  padding-top: 14px;
}
.pixel { aspect-ratio: 1; border-radius: 3px; background: var(--pixel-off); }
.pixel.on { background: var(--level-color, var(--accent)); }
.pixels[data-level="warn"] { --level-color: var(--warn); }
.pixels[data-level="bad"] { --level-color: var(--bad); }
.pixels.charging .pixel.next { animation: pixel-charge 1.6s ease-in-out infinite; }
@keyframes pixel-charge {
  0%, 100% { background: var(--pixel-off); }
  50% { background: var(--energy); }
}
.pixel-limit {
  position: absolute;
  top: 0;
  bottom: -4px;
  width: 0;
  border-left: 2px dashed var(--muted);
  transform: translateX(-3px);
}
.pixel-limit span {
  position: absolute;
  top: -4px;
  left: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1;
}

/* --- Tiles: stats share one surface, split by hairlines ---------------- */
.stats-option { display: flex; align-items: center; gap: 10px; margin: -4px 0 18px; color: var(--muted); font-size: 0.88rem; cursor: pointer; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card-grid:empty { display: none; }
/* Each tile draws its own top and left hairline and is pulled 1px up/left,
   so lines at the grid's outer edge get clipped by overflow:hidden and a
   half-empty last row stays plain surface instead of showing a grey gap. */
.stat-card {
  background: var(--surface);
  padding: 16px 18px 18px;
  margin: -1px 0 0 -1px;
  min-width: 0;
  box-shadow: inset 1px 0 0 var(--line), inset 0 1px 0 var(--line);
}
.stat-card .label { color: var(--muted); font-size: 0.82rem; margin-bottom: 6px; }
.stat-card .value {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.stat-card .value.good { color: var(--good); }
.stat-card .value.warn { color: var(--warn); }
.stat-card .value.bad { color: var(--bad); }
.stat-card .sub { margin-top: 4px; color: var(--muted); font-size: 0.86rem; }
.panel .card-grid { box-shadow: none; }

.period-grid { grid-template-columns: repeat(3, 1fr); }

/* --- Panels & tables ----------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel h2 { margin: 0 0 14px; font-size: 1.02rem; }
.panel-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin-bottom: 14px; }
.panel-header h2 { margin: 0; }
.panel-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-note { margin: 0 0 16px; font-size: 0.9rem; max-width: 70ch; }
.footnote { margin: 12px 0 0; color: var(--muted); font-size: 0.8rem; }

.dash-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; align-items: start; }
.dash-grid .panel { margin-bottom: 0; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line); }
.range-btn {
  border: none;
  background: none;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}
.range-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }

.chart-box { position: relative; height: 260px; }
.chart-box-tall { height: 300px; }
.chart-empty { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 0.9rem; text-align: center; }

.map-tall { height: 440px; }
.map-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; font-size: 0.82rem; color: var(--muted); }
.map-legend span { display: inline-flex; align-items: center; gap: 7px; }
.swatch { display: inline-block; width: 18px; height: 4px; border-radius: 2px; }
.swatch.dashed { background: repeating-linear-gradient(90deg, var(--muted) 0 5px, transparent 5px 9px); }
#trips-map-panel { scroll-margin-top: 16px; }
.stat-card .sub-good { color: var(--good); }
.stat-card .sub-good .muted { color: var(--muted); }

/* --- Ladeplanung ------------------------------------------------------ */
.plan-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; color: var(--muted); font-size: 0.92rem; }
.plan-form label { display: inline-flex; align-items: center; gap: 8px; }
.plan-form input[type="time"] { width: 136px; }
.plan-form input[type="number"] { width: 80px; }
.plan-form select { max-width: 200px; }
.plan-result { margin-top: 14px; }
.plan-result:empty { display: none; }
.plan-result p { margin: 0; }
.plan-headline { font-size: 1.3rem; font-weight: 600; letter-spacing: -0.015em; color: var(--text); }
.plan-headline.good { color: var(--good); }
.plan-headline.warn { color: var(--warn); }
.plan-details { margin-top: 6px !important; font-size: 0.92rem; max-width: 70ch; }
.plan-note { margin-top: 8px !important; font-size: 0.88rem; color: var(--warn); }
.plan-footnote { margin-top: 10px !important; font-size: 0.8rem; color: var(--muted); }

/* --- Rückblick ---------------------------------------------------------- */
#review-body .card-grid { margin-bottom: 14px; }
.review-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.review-trips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 24px; }
.review-trip { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 0.9rem; }
.review-trip-label { color: var(--muted); font-size: 0.8rem; }
.review-trip-route { font-weight: 500; overflow-wrap: anywhere; }
.review-trip b { color: var(--text); font-weight: 600; }
.stat-card .sub-bad { color: var(--bad); }

/* --- Wofür der Strom draufgeht ------------------------------------------- */
.breakdown-cards { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.swatch-dot { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 2px; vertical-align: 0; }
.swatch-dot.line { height: 0; border-top: 2px dashed var(--text); border-radius: 0; vertical-align: 3px; }

.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 4px; font-size: 0.9rem; color: var(--muted); }
.inline-form label { display: inline-flex; align-items: center; gap: 8px; }
.inline-form input { width: 84px; min-height: 36px; padding: 6px 9px; }
.inline-form .btn { min-height: 36px; }
.inline-form input[type="date"] { width: 160px; }

.map { height: 340px; border-radius: var(--r-md); overflow: hidden; background: var(--surface-2); }
.map .leaflet-tile-pane { filter: var(--map-filter); }
.leaflet-container { font-family: var(--font); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface-2); color: var(--text); }
.leaflet-control-attribution { background: var(--surface) !important; background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }

.car-marker {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* Tables can be wider than the screen (many columns); scroll horizontally
   inside the panel instead of breaking the page layout. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -22px; padding: 0 22px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.data-table th { color: var(--muted); font-weight: 500; font-size: 0.8rem; padding-top: 4px; }
.data-table th.num, .data-table td.num { text-align: right; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:not(.trip-group-header):hover td { background: var(--surface-2); }
.data-table td.empty { color: var(--muted); text-align: center; padding: 36px 12px; white-space: normal; }
.cell-strong { font-weight: 500; }
.only-sm { display: none !important; }
.cell-sub { display: block; color: var(--muted); font-size: 0.8rem; }
.cell-wrap { white-space: normal !important; min-width: 180px; }
.cell-actions { text-align: right !important; width: 1%; }
.soc-range { }
.soc-range b { font-weight: 500; }
.live { display: inline-flex; align-items: center; gap: 5px; color: var(--energy); font-weight: 500; }
.live .icon { width: 14px; height: 14px; }
.est { color: var(--muted); margin-left: 2px; }
.home-flag { display: inline-flex; align-items: center; gap: 5px; color: var(--accent); }
.home-flag .icon { width: 15px; height: 15px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--r-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }
.icon-btn .icon { width: 17px; height: 17px; }

.data-table tr.trip-group-header td {
  padding: 22px 12px 8px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: normal;
}
.data-table tr.trip-group-header:first-child td { padding-top: 6px; }
.trip-day-summary { display: inline-block; margin-left: 10px; color: var(--muted); font-weight: 400; }
.trip-day-summary .muted { margin-left: 4px; }
.route { display: inline-flex; align-items: center; gap: 8px; }
.route-arrow { color: var(--muted); }

/* --- Vehicle status (car diagram) ------------------------------------ */
.vehicle-layout {
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr;
  gap: 40px;
  align-items: start;
}
.vehicle-side { min-width: 0; }
.car-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 14px; font-size: 0.85rem; color: var(--muted); }
.car-legend .dot { width: 10px; height: 10px; border-radius: 3px; }
.car-legend .dot.ok { background: var(--good); }
.car-legend .dot.bad { background: var(--bad); margin-left: 8px; }

.car-diagram {
  position: relative;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 220 / 400;
  margin: 8px auto;
}
.car-svg { width: 100%; height: 100%; display: block; }
.car-body { fill: var(--surface-2); stroke: var(--line); stroke-width: 2; }
.car-wheel { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; }
.car-glass { fill: var(--accent-soft); stroke: var(--accent); stroke: color-mix(in srgb, var(--accent) 45%, transparent); stroke-width: 1.5; }
.car-mirror { fill: var(--line); }
.car-pixels rect { fill: var(--muted); opacity: 0.5; rx: 1.5; }

.car-badge {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--surface);
  color: var(--good);
  border: 1.5px solid var(--good);
  cursor: default;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.car-badge .icon { width: 17px; height: 17px; }
.car-badge.warn-state { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.car-badge.tire { width: 26px; height: 26px; border-radius: 7px; opacity: 0; pointer-events: none; }
.car-badge.tire .icon { width: 14px; height: 14px; }
.car-badge.tire.warn-state { opacity: 1; pointer-events: auto; background: var(--surface); }

.car-badge::after {
  content: attr(data-label);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 5;
}
.car-badge:hover::after { opacity: 1; }

.vehicle-status-list { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

/* --- Dialogs --------------------------------------------------------- */
dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px;
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.5);
}
dialog[open] { animation: dialog-in 0.18s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px); } }
dialog::backdrop { background: rgba(10, 12, 14, 0.55); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 4px; font-size: 1.15rem; }
dialog > p { margin: 6px 0 14px; font-size: 0.9rem; }
dialog.dialog-wide { width: 680px; }
dialog form { display: flex; flex-direction: column; gap: 14px; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
dialog label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 0.92rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
#use-current-location-btn { align-self: flex-start; font-size: 0.85rem; color: var(--accent); padding: 0 10px; }

/* --- OBD import & BMS readings ------------------------------------------ */
.reading-list { list-style: none; margin: 12px 0 16px; padding: 0; font-size: 0.9rem; }
.reading-list:empty { display: none; }
.reading-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.reading-list li:last-child { border-bottom: none; }
.reading-list li > span { min-width: 0; }
.reading-list .muted { margin-left: 6px; }

.howto { margin: 4px 0 16px; font-size: 0.9rem; color: var(--muted); }
.howto summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.howto ol { margin: 10px 0 0; padding-left: 20px; line-height: 1.55; }
.howto li + li { margin-top: 4px; }
.field-hint { font-size: 0.78rem; color: var(--muted); }
input[type="file"] { min-height: 0; padding: 8px; font-size: 0.9rem; }

.obd-result { padding: 14px 16px; border-radius: var(--r-md); background: var(--surface-2); font-size: 0.9rem; }
.obd-result p { margin: 0 0 12px; }
.ok-line { display: flex; gap: 8px; align-items: flex-start; }
.ok-line .icon { color: var(--energy); margin-top: 2px; }
.figures { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 16px; margin: 0; }
.figures dt { color: var(--muted); font-size: 0.78rem; }
.figures dd { margin: 0; font-weight: 600; }
.sensor-map { margin-top: 12px; font-size: 0.82rem; }
.sensor-map summary { cursor: pointer; color: var(--muted); }
.sensor-map p { margin: 8px 0 0; line-height: 1.5; overflow-wrap: anywhere; }
.obd-history-title { margin: 22px 0 0; font-size: 0.95rem; }

/* --- Laptop / tablet ------------------------------------------------- */
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: 1fr; }
  main { padding: 28px 24px 40px; }
}

/* --- Mobile: compact header, bottom tab bar, tables become cards -----
   Also for phones in landscape: wide but too short for the sidebar. */
@media (max-width: 760px), (max-height: 500px) {
  body { font-size: 15px; }

  .topbar {
    inset: 0 0 auto 0;
    width: auto;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    border-right: none;
    border-bottom: 1px solid var(--line);
    /* no backdrop-filter here: it would become the containing block of the
       fixed bottom tab bar (a child of this header) and pin it to the top */
    background: var(--surface);
  }
  .brand { padding: 0; gap: 10px; min-width: 0; flex: 1; }
  .brand-mark { width: 18px; height: 18px; }
  .brand-name { font-size: 0.95rem; }
  .brand-sub { font-size: 0.75rem; }

  .topbar-actions { margin: 0; flex-direction: row; align-items: center; gap: 4px; }
  .topbar-actions .btn { width: 40px; min-height: 40px; padding: 0; border-color: transparent; background: transparent; justify-content: center; }
  .topbar-actions .btn .icon { width: 19px; height: 19px; }
  .btn-label { display: none; }
  /* When all is well only the colored square stays (text is in the tooltip);
     problems like "OTP benötigt" keep their text. */
  .badge { padding: 6px 8px; font-size: 0.72rem; }
  .badge.ok { font-size: 0; gap: 0; }
  .badge::before { width: 9px; height: 9px; }

  .tabs {
    position: fixed;
    inset: auto 0 0 0;
    flex-direction: row;
    gap: 0;
    padding: 6px 4px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    background: var(--surface);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(14px);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    border-top: 1px solid var(--line);
  }
  .tab-btn {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
    padding: 6px 2px 4px;
    font-size: 0.68rem;
    text-align: center;
    border-radius: var(--r-sm);
  }
  .tab-btn .icon { width: 22px; height: 22px; }
  .tab-btn:hover, .tab-btn.active { background: none; }
  .tab-btn.active { color: var(--accent); }
  .tab-btn.active::before { left: 50%; top: -6px; width: 22px; height: 3px; margin: 0 0 0 -11px; border-radius: 0 0 3px 3px; }
  .tab-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }

  main {
    margin-left: 0;
    padding: 16px 12px;
    padding-top: calc(76px + env(safe-area-inset-top));
    padding-bottom: calc(var(--tabbar) + 28px + env(safe-area-inset-bottom));
  }

  .hero { grid-template-columns: 1fr; gap: 14px; padding: 20px 18px; border-radius: var(--r-md); }
  .hero-soc { flex-direction: row; align-items: baseline; justify-content: space-between; gap: 12px; }
  .hero-soc-value { font-size: 84px; }
  .hero-range { font-size: 1.4rem; }
  .pixels { gap: 3px; }
  .pixel { border-radius: 2px; }

  .card-grid { grid-template-columns: repeat(2, 1fr); border-radius: var(--r-md); }
  .stat-card { padding: 13px 14px 14px; }
  .stat-card .label { font-size: 0.78rem; }
  .stat-card .value { font-size: 1.12rem; }
  .period-grid { grid-template-columns: repeat(3, 1fr); }
  .period-grid .stat-card { padding: 12px 11px; }
  .period-grid .stat-card .value { font-size: 1rem; }
  .period-grid .stat-card .sub { font-size: 0.76rem; }

  .panel { padding: 16px 14px; border-radius: var(--r-md); }
  .panel h2 { font-size: 0.98rem; }
  .map { height: 260px; }
  .map-tall { height: 360px; }
  #trips-map-panel { scroll-margin-top: calc(76px + env(safe-area-inset-top)); }
  .inline-form-title { flex-basis: 100%; }
  #cost-cards { grid-template-columns: 1fr; }
  .review-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .review-trips { grid-template-columns: 1fr; }
  .breakdown-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plan-headline { font-size: 1.12rem; }
  .plan-form { gap: 10px 12px; }
  #cost-cards .stat-card .value { font-size: 1.12rem; }
  #cost-cards .stat-card .sub { font-size: 0.86rem; }
  .chart-box { height: 220px; }
  .chart-box-tall { height: 260px; }
  .vehicle-layout { grid-template-columns: 1fr; gap: 16px; }
  .car-diagram { max-width: 230px; }

  /* Rows become stacked cards; each cell labels itself via data-label. */
  .table-scroll { overflow: visible; margin: 0; padding: 0; }
  .data-table, .data-table tbody { display: block; }
  .data-table thead { display: none; }
  .data-table tbody tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
  }
  .data-table tbody tr:last-child { border-bottom: none; }
  .data-table td { display: block; padding: 0; border: none; white-space: normal; min-width: 0; font-size: 0.9rem; }
  .data-table td.num { text-align: left; }
  .data-table tbody tr:not(.trip-group-header):hover td { background: none; }
  .data-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 1px;
    color: var(--muted);
    font-size: 0.74rem;
  }
  .data-table td.cell-main { grid-column: 1 / -1; grid-row: 1; padding-right: 110px; font-size: 0.98rem; }
  .data-table td.cell-main::before { display: none; }
  .data-table td.cell-actions { grid-column: 3; grid-row: 1; justify-self: end; align-self: start; width: auto; margin: -6px -6px 0 0; }
  .data-table td.cell-hide-sm { display: none; }
  .data-table td.cell-span { grid-column: 1 / -1; }
  .data-table td.empty { grid-column: 1 / -1; padding: 24px 0; }
  .cell-wrap { min-width: 0; }
  .only-sm { display: block !important; }

  .data-table tr.trip-group-header { display: block; padding: 18px 0 4px; }
  .data-table tr.trip-group-header:first-child { padding-top: 0; }
  .data-table tr.trip-group-header td { padding: 0; border: none; font-size: 0.86rem; }
  .trip-day-summary { display: block; margin: 2px 0 0; font-size: 0.8rem; }
  .route { display: flex; flex-wrap: wrap; gap: 2px 6px; }

  .panel-actions select { max-width: 180px; }

  /* Dialogs slide up as bottom sheets. */
  dialog {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: none;
    padding: 22px 18px;
    padding-bottom: max(22px, env(safe-area-inset-bottom));
    max-height: 92dvh;
  }
  dialog.dialog-wide { width: 100%; }
  dialog[open] { animation: sheet-in 0.22s ease-out; }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0.4; } }
  .dialog-actions .btn { flex: 1; min-height: 44px; }
}

/* Phone in landscape: side-by-side hero, slimmer tab bar. */
@media (max-height: 500px) and (min-width: 600px) {
  .hero { grid-template-columns: auto 1fr; gap: 12px 32px; }
  .hero-soc { flex-direction: column; align-items: flex-start; }
  .pixels { max-width: 460px; }
  .card-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .tabs { padding-top: 3px; }
  .tab-btn { flex-direction: row; justify-content: center; gap: 6px; font-size: 0.78rem; }
  .tab-btn .icon { width: 18px; height: 18px; }
  main { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); padding-bottom: calc(52px + 20px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
  .hero-soc-value { font-size: 72px; }
  .data-table tbody tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .data-table td.cell-actions { grid-column: 2; }
  .period-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* track.html has no sidebar: keep its status badge readable on phones */
.track-header .badge,
.track-header .badge.ok { padding: 6px 0; font-size: 0.85rem; gap: 8px; }
