/* Škoda Mate design system. Dark-first emerald/electric-green, light theme via data-theme or system preference. */
:root {
  --bg: #f7f9f8; --surface: #ffffff; --surface-2: #eef2ef; --surface-3: #e1e7e3;
  --fg: #1b1b1b; --muted: #5c6660; --line: #d9dedb; --control-line: #7d8782;  /* borders of form fields: 3:1 against the surface (WCAG 1.4.11) */
  --accent: #0e3a2f; --accent-ink: #ffffff; --accent-soft: #d6f5e3; --accent-2: #0e3a2f;  /* Škoda docs: dark emerald, electric green #78faae as highlight */
  --good: #0b7a52; --warn: #8a5a00; --bad: #b3261e; --info: #1d5fa8;
  --warn-soft: #fbefd2; --bad-soft: #fbe0dd; --info-soft: #dce9f7;
  --shadow: 0 1px 2px rgba(10, 30, 20, .04);  /* cards are quiet: the hairline does the edge */
  --shadow-float: 0 2px 4px rgba(10, 30, 20, .06), 0 12px 32px rgba(10, 30, 20, .12);  /* dialogs, menus, toasts only */
  --radius: 12px; --radius-sm: 8px; --gap: 16px;
  --sidebar: 248px; --header: 60px;
  --hero-bg: #0e3a2f; --hero-ink: #e9fff4; --hero-muted: #a9cdb9;
  --chart-1: #0b7a52; --chart-2: #1d5fa8; --chart-3: #b86e00; --chart-4: #7a3fa8; --chart-grid: #d4ddd7;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121613; --surface: #181e1a; --surface-2: #1c221e; --surface-3: #272e2a;
    --fg: #e8ebe9; --muted: #9aa5a0; --line: #2c332f; --control-line: #6f7a75;
    --accent: #78faae; --accent-ink: #0e3a2f; --accent-soft: #1a3a2c; --accent-2: #78faae;
    --good: #78faae; --warn: #ffcf70; --bad: #ff8f86; --info: #8fc2ff;
    --warn-soft: #3a2f10; --bad-soft: #3d1a17; --info-soft: #14283f;
    --shadow: none;  /* depth comes from surface steps and hairlines, not fog */
    --shadow-float: 0 16px 40px rgba(0, 0, 0, .55);
    --chart-1: #78faae; --chart-2: #8fc2ff; --chart-3: #ffb454; --chart-4: #c79bff; --chart-grid: #2c332f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121613; --surface: #181e1a; --surface-2: #1c221e; --surface-3: #272e2a;
  --fg: #e8ebe9; --muted: #9aa5a0; --line: #2c332f; --control-line: #6f7a75;
  --accent: #78faae; --accent-ink: #0e3a2f; --accent-soft: #1a3a2c; --accent-2: #78faae;
  --good: #78faae; --warn: #ffcf70; --bad: #ff8f86; --info: #8fc2ff;
  --warn-soft: #3a2f10; --bad-soft: #3d1a17; --info-soft: #14283f;
  --shadow: none;  /* depth comes from surface steps and hairlines, not fog */
  --shadow-float: 0 16px 40px rgba(0, 0, 0, .55);
  --chart-1: #78faae; --chart-2: #8fc2ff; --chart-3: #ffb454; --chart-4: #c79bff; --chart-grid: #2c332f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
.view, .card, .banner, .modal { overflow-wrap: anywhere; }  /* long unbroken names (file names, VINs, URLs) must wrap, not widen the page */
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 600; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 13px; color: var(--muted); font-weight: 600; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.nowrap { white-space: nowrap; } .right { text-align: right; } .center { text-align: center; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.icon { flex: none; vertical-align: -.2em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ------------------------------------------------------------------ shell */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 600; font-size: 17px; color: inherit; text-decoration: none; border-radius: 10px; }
.brand:hover .mark { filter: brightness(1.15); }
.brand .mark { width: 32px; height: 32px; border-radius: 9px; background: #0e3a2f; color: #78faae; display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; letter-spacing: .02em; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--fg); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav .sep { height: 1px; background: var(--line); margin: 10px 8px; }
.sidebar .foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--header); display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar .title { min-width: 0; flex: 1; }
.topbar .title strong { display: block; font-size: 21px; line-height: 1.15; letter-spacing: -.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view { padding: 24px; max-width: 1440px; margin: 0 auto; }
.view > * + *, .page > * + * { margin-top: var(--gap); }
[hidden] { display: none !important; }  /* components that set `display` must not override the hidden attribute */
.tabbar { display: none; }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 0 16px; } .view { padding: 16px 16px 92px; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px;
    color: var(--muted); text-decoration: none; background: none; border: 0; font-family: inherit; cursor: pointer; border-radius: 10px; }
  .tabbar a[aria-current="page"] { color: var(--accent); }
}

/* ------------------------------------------------------------------ building blocks */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card > header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.card > header h2, .card > header h3 { flex: 1; }
.card.flat { box-shadow: none; }
.card.accent { background: var(--hero-bg); color: var(--hero-ink); border-color: transparent; }
.card.accent .muted { color: var(--hero-muted); }
.grid { display: grid; gap: var(--gap); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.auto { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.split { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
@media (max-width: 960px) { .g3, .g4, .split { grid-template-columns: repeat(2, minmax(0, 1fr)); } .split { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .auto { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; } .row.tight { gap: 6px; } .row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 600; line-height: 1.15; margin-top: 4px; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 500;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.good { background: var(--accent-soft); color: var(--good); } .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); } .chip.info { background: var(--info-soft); color: var(--info); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.dot.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot.pulse { animation: none; } * { scroll-behavior: auto !important; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; min-height: 38px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); } .btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); } .btn.ghost:hover { background: var(--surface-2); color: var(--fg); }
.btn.sm { padding: 5px 10px; min-height: 30px; font-size: 13px; border-radius: 8px; }
.btn[disabled], .btn.busy { opacity: .55; cursor: not-allowed; }
.btn.busy .icon { animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn.busy .icon { animation: none; } }

label.field { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
label.field > span { display: block; margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--control-line); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--fg); font: inherit; min-height: 38px; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
input[type="range"] { padding: 0; accent-color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; color: var(--muted); padding: 6px 12px; border-radius: 8px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: var(--surface-2); }
table.t td.num, table.t th.num { text-align: right; }
.scroll-x { overflow-x: auto; }

.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid transparent; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.banner.info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.banner .grow { flex: 1; } .banner a { color: inherit; font-weight: 650; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty .icon { opacity: .6; margin-bottom: 8px; }
.empty strong { display: block; color: var(--fg); margin-bottom: 4px; }

.bar { height: 12px; background: var(--surface-3); border-radius: 6px; overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .5s ease; }
.bar > b { position: absolute; top: -3px; bottom: -3px; width: 3px; background: var(--fg); border-radius: 2px; }
.bar.low > i { background: var(--bad); } .bar.mid > i { background: var(--warn); }

/* modal + toast */
.scrim { position: fixed; inset: 0; z-index: 60; background: rgba(5, 15, 10, .55); display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-float); width: min(520px, 100%); max-height: 88vh; overflow: auto; padding: 24px; }
.modal h2 { margin-bottom: 12px; } .modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
@media (max-width: 960px) { .toasts { bottom: 84px; } }
.toast { background: var(--surface-3); color: var(--fg); border: 1px solid var(--line); padding: 12px 14px; border-radius: 8px; box-shadow: var(--shadow-float); font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.toast.bad { background: var(--bad-soft); border-color: var(--bad); } .toast.good { background: var(--accent-soft); border-color: var(--good); }

/* car view */
.carview { position: relative; display: grid; place-items: center; min-height: 190px; }
.carview img { max-width: 100%; max-height: 240px; object-fit: contain; filter: drop-shadow(0 12px 18px rgba(0, 0, 0, .25)); }
.carview svg.silhouette { width: min(100%, 420px); height: auto; color: var(--muted); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }

/* charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid { stroke: var(--chart-grid); stroke-width: 1; } .chart .axis { stroke: var(--line); }
.chart .gap { fill: var(--chart-grid); opacity: .7; }  /* a stretch without readings: no line is drawn across it */
.chart .tip { position: absolute; pointer-events: none; background: var(--fg); color: var(--bg); padding: 6px 9px; border-radius: 8px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 3; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.map { height: 380px; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.map.tall { height: 560px; } .map.short { height: 240px; }
.map-fallback { height: 100%; display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted); }
.pin { width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--accent); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .4); }
.pin.b { background: #1d5fa8; } .pin.c { background: #b86e00; } .pin.d { background: #7a3fa8; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-weight: 600; word-break: break-word; }
.badge-demo { border: 1px solid var(--line); color: var(--muted); font-weight: 500; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 6px; background: var(--surface); padding: 8px 12px; z-index: 100; border-radius: 8px; } .skip:focus { left: 8px; }

/* ---- UX audit fixes ---- */
::placeholder { color: var(--muted); opacity: 1; }  /* default placeholder grey was 3.7:1 */
::selection { background: var(--accent-soft); color: var(--fg); }
.sr-h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a:not(.btn):not(.brand):not(.skip):not(.a-back):not([class*="nav"]) { text-underline-offset: 3px; }
/* Touch screens: every control reaches the 44 px minimum (WCAG 2.5.5 / platform guidance) */
@media (pointer: coarse) {
  .btn, .btn.sm, .seg button, .topbar button, select, input:not([type=checkbox]):not([type=radio]):not([type=range]) { min-height: 44px; }
  .btn.sm { padding-left: 12px; padding-right: 12px; }
  .seg button { padding: 10px 14px; }
  .b-stepper .btn { min-width: 44px; }
  .a-back { min-height: 44px; }
  .leaflet-bar a { width: 40px !important; height: 40px !important; line-height: 40px !important; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
}
@media (pointer: coarse) { .chip[role], button.chip, button.a-fchip, button.b-chip { min-height: 44px; padding-left: 14px; padding-right: 14px; } }
/* Header: the vehicle name and status must stay readable. Long status text truncates; on phones the request chip moves
   to the System page and Refresh shows its icon only (its title still names it). */

@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .topbar .chip { display: none; }
  .topbar .btn.sm span { display: none; }
  .topbar .btn.sm { padding-left: 12px; padding-right: 12px; }
}

/* ---- Header: name + plate on one line, a status line with a health dot, a self-explaining request meter ---- */
.topbar .title .name { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.topbar .title .name strong { display: block; min-width: 0; flex: 0 1 auto; }
.topbar .plate { flex: none; font-size: 11px; font-weight: 500; letter-spacing: .02em; padding: 1px 7px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); }
.topbar .status { display: flex; align-items: center; gap: 7px; margin-top: 1px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .status .dot { flex: none; }
.topbar a.chip { text-decoration: none; color: var(--muted); }
.topbar a.chip:hover { background: var(--surface-3); color: var(--fg); }
.topbar a.chip.warn { color: var(--warn); }
.topbar .status > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 560px) { .topbar .title strong { font-size: 18px; } }

/* Car card: headline confirmations above the picture, charging line and extras below */
.carcard { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.carcard .badges { margin-top: 0; }
.badges.top { justify-content: space-between; }
@media (max-width: 420px) { .badges.top { justify-content: center; } }

/* Car switcher: a visible pill, only with more than one car */
.carpick { display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; min-height: 36px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--fg); cursor: pointer; flex: none; }
.carpick select { appearance: none; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 600; padding: 0 2px; min-height: 0; width: auto; max-width: 150px; text-overflow: ellipsis; cursor: pointer; }
.carpick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 560px) { .carpick select { max-width: 90px; } }
/* With several cars the switcher pill already names the car: on phones drop the duplicate name, keep plate and status */
@media (max-width: 560px) { .topbar .title.multi .name strong { display: none; } .topbar .title.multi .plate { margin: 0; } }

/* ---- Vehicle status (car card): one summary line + four cells ---- */
.cs-summary { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--muted); text-align: center; }
.cs-summary.ok { color: var(--muted); }
.cs-summary.warn, .cs-summary.bad { padding: 7px 12px; border-radius: 10px; justify-content: flex-start; text-align: left; }
.cs-summary.warn { background: var(--warn-soft); color: var(--warn); }
.cs-summary.bad { background: var(--bad-soft); color: var(--bad); }
.cs-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.cs-cell { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--muted); min-width: 0; }
.cs-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.cs-l { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cs-v { font-size: 13px; font-weight: 500; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cs-cell.unknown .cs-v { color: var(--muted); }
.cs-cell.info .icon { color: var(--info); }  /* lights on: worth a glance, not an alarm */
.cs-cell.warn .icon, .cs-cell.warn .cs-v { color: var(--warn); }
.cs-cell.bad .icon, .cs-cell.bad .cs-v { color: var(--bad); }
@media (max-width: 900px) and (min-width: 561px) { .cs-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .cs-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 961px) { .hero .cs-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }  /* the car sits in half a card */

/* ---- Stat tiles: no orphans on phones; trips totals as an even 3 x 2 ---- */
@media (max-width: 560px) { .view > .grid.auto > :last-child:nth-child(odd) { grid-column: 1 / -1; } }
.a-totals { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 760px) { .a-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
/* Cards that end a row keep their own height instead of stretching into empty boxes */
.grid.g3 { align-items: stretch; }

/* ---- Micro-animations (CSS only). Short, ease-out, transform/opacity/colour only. ---- */
:root { --ease: cubic-bezier(.16, 1, .3, 1); --t-fast: 120ms; --t-med: 200ms; }
.btn, .chip, .nav a, .seg button, .cs-cell, .a-item, .a-fchip, .b-chip, select, input, textarea, .carpick, a.card {
  transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease, box-shadow var(--t-med) var(--ease), transform var(--t-fast) var(--ease), opacity var(--t-fast) ease;
}
@media (prefers-reduced-motion: no-preference) {
  /* one entrance per navigation: the .page container is created per route, so a poll redraw does not replay it */
  .page { animation: page-in var(--t-med) var(--ease) both; }
  @keyframes page-in { from { opacity: 0; transform: translateY(4px); } }
  /* press feedback: the only motion that answers a touch */
  .btn:active:not([disabled]):not(.busy), .seg button:active, .a-fchip:active, .b-chip:active, .carpick:active { transform: scale(.98); }
  /* dialogs and toasts enter from where they are */
  .scrim { animation: scrim-in var(--t-fast) ease both; } @keyframes scrim-in { from { opacity: 0; } }
  .modal { animation: modal-in var(--t-med) var(--ease) both; } @keyframes modal-in { from { opacity: 0; transform: translateY(8px); } }
  .toast { animation: toast-in var(--t-med) var(--ease) both; } @keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
  /* a bar that changes because the data changed, not because time passed */
  .bar > i { transition: width .5s var(--ease); }
}
/* linked cards answer with their edge, not by moving */
a.card:hover { border-color: var(--control-line); }
/* Start/Stop toggle: one wide, thumb-sized button per card */
.b-toggle .btn { width: 100%; min-height: 44px; font-size: 15px; }

/* ---- Forms and card sections: one spacing scale ----
   12px between things that belong together, 28px (plus a hairline) between sections, a section heading sits closer to
   what it introduces (10px) than to what came before. Action buttons keep 18px from the fields they save. */
.card .stack > h3:not(:first-child), .card .stack > .b-section:not(:first-child) { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.card .stack > h3 + * { margin-top: 10px; }
.card .stack > .b-section > h3:first-child { margin-bottom: 0; }
.card .stack > .b-section > h3 + * { margin-top: 10px; }
.stack > .btn { display: inline-flex; width: fit-content; margin-top: 18px; }
.stack > .row:has(> .btn.primary) { margin-top: 18px; }
.stack > .b-sep + .btn, .stack > h3 + .btn { margin-top: 0; }
.stack > .tiny.muted, .stack > .small.muted { line-height: 1.45; }

/* Inline form row: fields grow, buttons keep their size and share the input's bottom edge, everything is one control height */
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.form-row > label.field { flex: 1 1 220px; min-width: 0; max-width: 440px; }
.form-row > .btn { flex: none; height: 38px; min-height: 38px; }
@media (pointer: coarse) { .form-row > .btn { height: 44px; min-height: 44px; } }
@media (max-width: 560px) { .form-row > label.field { flex-basis: 100%; } .form-row > .btn { flex: 1 1 auto; } }
/* Equal-height cards in a row. Content that is shorter than its card sits at the top; the map and lists fill what is left. */
.grid > .card { display: flex; flex-direction: column; }
.grid > .card > :last-child:not(header) { flex: 1 1 auto; }
.b-cards > .card > .stack > .b-toggle:last-child { margin-top: auto; padding-top: 12px; }
.b-cards > .card > .stack { flex: 1 1 auto; display: flex; flex-direction: column; }

/* Sign out: a real menu item at the bottom of the sidebar, same shape as the others, red only on intent */
.sidebar .foot { margin: auto 10px 10px; padding: 0; }
.sidebar .foot .badge-demo { margin-left: 12px; }
.signout { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border: 0; border-radius: 10px; background: none; color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; text-align: left; }
.signout:hover { background: var(--bad-soft); color: var(--bad); }
.signout:focus-visible { outline: 2px solid var(--bad); outline-offset: 2px; }

/* ---- Charge prices page ---- */
.pr-currency { max-width: 160px; }
.pr-rows { display: flex; flex-direction: column; gap: 12px; }
.pr-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.pr-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); }
.pr-row.good .pr-ic { color: var(--good); } .pr-row.info .pr-ic { color: var(--info); } .pr-row.warn .pr-ic { color: var(--warn); }
.pr-row.good > .pr-text > strong { color: var(--good); } .pr-row.info > .pr-text > strong { color: var(--info); } .pr-row.warn > .pr-text > strong { color: var(--warn); }
.pr-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; } .pr-text strong { font-size: 16px; }
.pr-input { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; }
.pr-input input { width: 112px; text-align: right; font-size: 18px; font-weight: 600; color: var(--fg); }
.pr-sym, .pr-unit { white-space: nowrap; }
.pr-bar { position: sticky; bottom: 12px; z-index: 15; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-float); }
.pr-status { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); } .pr-status.dirty { color: var(--warn); }
@media (max-width: 700px) {
  .pr-row { grid-template-columns: auto minmax(0, 1fr); }
  .pr-input { grid-column: 1 / -1; justify-content: flex-end; } .pr-input input { flex: 1; width: auto; max-width: 180px; }
  .pr-bar { bottom: 78px; }
}
/* Map layers must not stack above sticky bars, menus or dialogs: keep their z-indexes inside the map */
.leaflet-container { isolation: isolate; }

/* ---- Home Assistant (MQTT) card ---- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; align-items: start; }
.form-grid.mq-host { grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); }
@media (max-width: 560px) { .form-grid, .form-grid.mq-host { grid-template-columns: 1fr; } }
.mq-actions { justify-content: flex-end; }
.linklike { background: none; border: 0; padding: 0; margin-top: -6px; color: var(--muted); font: inherit; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; justify-self: start; }
.linklike:hover { color: var(--fg); }
.b-guide { border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.b-guide > summary { cursor: pointer; padding: 12px 14px; font-weight: 650; display: flex; align-items: center; gap: 8px; list-style: none; }
.b-guide > summary::-webkit-details-marker { display: none; }
.b-guide > .stack { padding: 4px 16px 16px; }
.b-steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; line-height: 1.5; }
.b-steps li::marker { font-weight: 700; color: var(--accent); }
.card > header .chip { margin-left: auto; }

/* ---- Settings: cards side by side ---- */
.set-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); align-items: start; }
.set-col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.set-col > div { min-width: 0; }
.set-col .grid.g3 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.set-col .grid.g2 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
@media (max-width: 1100px) { .set-cols { grid-template-columns: 1fr; } }
.seg button { white-space: nowrap; }
.set-col .grid.g3:has(.seg) { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }  /* segmented controls need their full width */

/* overview hero: battery number with range on the same baseline, striped "still to charge" stretch, one charging block */
.row-base { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.row-base .range { font-size: 14px; font-weight: 600; color: var(--muted); }
.bar > u { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(115deg, color-mix(in srgb, var(--accent) 55%, transparent) 0 6px, color-mix(in srgb, var(--accent) 20%, transparent) 6px 12px); background-size: 17px 100%; }
.limit-lbl { position: relative; height: 20px; font-size: 12px; color: var(--muted); }
.limit-lbl span { position: absolute; top: 5px; transform: translateX(-50%); white-space: nowrap; }
.limit-lbl span::before { content: ""; position: absolute; left: 50%; top: -6px; height: 5px; width: 1px; background: var(--muted); }
.limit-lbl span.end { right: 0; transform: none; } .limit-lbl span.end::before { left: auto; right: 6px; }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--good); }
.status-line .sep { color: var(--muted); font-weight: 400; } .status-line .meta { color: var(--muted); }
.figs { display: grid; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.fig { padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fig + .fig { border-left: 1px solid var(--line); }
.fig .n { font-size: 22px; font-weight: 600; line-height: 1.15; white-space: nowrap; }
.fig .l { font-size: 12px; color: var(--muted); }
.fig.lead .n { color: var(--good); }
@media (max-width: 520px) { .figs { grid-template-columns: 1fr !important; } .fig + .fig { border-left: 0; border-top: 1px solid var(--line); } }
