/* Car Mileage Tracker v2
   Road vernacular: asphalt ink, concrete ground, lane-marking amber for action,
   signal teal for "fine", brake red for "overdue". Type: Barlow (highway signage). */

@font-face { font-family: "Barlow"; font-weight: 400; font-display: swap; src: url(../fonts/barlow-400.woff2) format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-display: swap; src: url(../fonts/barlow-500.woff2) format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url(../fonts/barlow-600.woff2) format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 500; font-display: swap; src: url(../fonts/barlow-semi-condensed-500.woff2) format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 600; font-display: swap; src: url(../fonts/barlow-semi-condensed-600.woff2) format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 700; font-display: swap; src: url(../fonts/barlow-semi-condensed-700.woff2) format("woff2"); }

:root {
  --bg: #EEF0F1;          /* concrete */
  --surface: #FFFFFF;
  --surface-2: #F5F6F7;
  --ink: #1F2A33;         /* asphalt */
  --ink-2: #44515B;
  --muted: #66727B;
  --line: #DCE1E4;
  --amber: #F0B323;       /* lane marking */
  --amber-ink: #1F2A33;
  --amber-text: #8F6800;  /* amber that passes contrast on light ground */
  --amber-soft: #FBEBC0;
  --teal: #0F7F81;
  --teal-soft: #D6EEEE;
  --red: #C93A3A;
  --red-soft: #F8DEDE;
  --focus: #2F6FE0;

  --k-trip: #3D6CB9;
  --k-fuel: #C98A00;
  --k-service: #0F7F81;
  --k-repair: #C2571A;
  --k-expense: #7A5BA8;

  --font: "Barlow", system-ui, -apple-system, "Segoe UI", "Noto Sans Sinhala", "Noto Sans Tamil", sans-serif;
  --font-display: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --shadow-sheet: 0 -8px 40px rgba(20, 28, 34, .18);
  --rail: 248px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151C22; --surface: #1D272F; --surface-2: #232F38; --ink: #E7ECEF; --ink-2: #BAC4CB; --muted: #8E9AA3;
    --line: #2E3A43; --amber-text: #F0B323; --amber-soft: #3A3218; --teal: #3DB8B9; --teal-soft: #173638;
    --red: #F07272; --red-soft: #3D2224; --focus: #7EA8FF;
    --k-trip: #7EA4E6; --k-fuel: #F0B323; --k-service: #3DB8B9; --k-repair: #F08A4B; --k-expense: #B49BDC;
    --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151C22; --surface: #1D272F; --surface-2: #232F38; --ink: #E7ECEF; --ink-2: #BAC4CB; --muted: #8E9AA3;
  --line: #2E3A43; --amber-text: #F0B323; --amber-soft: #3A3218; --teal: #3DB8B9; --teal-soft: #173638;
  --red: #F07272; --red-soft: #3D2224; --focus: #7EA8FF;
  --k-trip: #7EA4E6; --k-fuel: #F0B323; --k-service: #3DB8B9; --k-repair: #F08A4B; --k-expense: #B49BDC;
  --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 16px/1.5 var(--font); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; min-height: 100dvh;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: -.005em; }
h1 { font-size: 30px; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
p { margin: 0 0 .75em; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.num { font-family: var(--font-display); font-weight: 600; font-variant-numeric: tabular-nums; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------- Boot ---------- */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot-lane { width: 120px; height: 6px; background: repeating-linear-gradient(90deg, var(--amber) 0 22px, transparent 22px 34px); background-size: 34px 6px; animation: lane 0.6s linear infinite; }
@keyframes lane { to { background-position: 34px 0; } }

/* ---------- Shell ---------- */
.shell { min-height: 100dvh; }
.rail { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar .spacer { flex: 1; }
.main { padding: 4px 16px calc(var(--tabbar) + var(--safe-b) + 28px); max-width: 1120px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 10px 0 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 30; height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 12px; font-weight: 500;
  color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] svg { color: var(--amber-text); }
.tab-add { justify-self: center; }
.fab {
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer; margin-top: -26px;
  background: var(--amber); color: var(--amber-ink); display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(201, 138, 0, .35), 0 0 0 5px var(--bg);
  transition: transform .15s ease;
}
.fab:active { transform: scale(.94); }
.fab svg { width: 28px; height: 28px; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: var(--rail) 1fr; }
  .tabbar, .topbar .vehicle-switch { display: none; }
  .rail {
    display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100dvh; padding: 20px 14px;
    background: var(--surface); border-right: 1px solid var(--line);
  }
  .rail .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font: 600 18px var(--font-display); }
  .rail .brand img { width: 30px; height: 30px; border-radius: 8px; }
  .rail .nav-link {
    display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: var(--r-sm); text-decoration: none;
    color: var(--ink-2); font-weight: 500;
  }
  .rail .nav-link svg { width: 20px; height: 20px; color: var(--muted); }
  .rail .nav-link:hover { background: var(--surface-2); }
  .rail .nav-link[aria-current="page"] { background: var(--amber-soft); color: var(--ink); }
  .rail .nav-link[aria-current="page"] svg { color: var(--amber-text); }
  .rail .btn-primary { margin: 6px 0 14px; }
  .rail .rail-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
  .topbar { padding: 16px 32px 8px; }
  .main { padding: 4px 32px 48px; }
  h1 { font-size: 36px; }
}

/* ---------- Vehicle switcher ---------- */
.vehicle-switch {
  display: flex; align-items: center; gap: 10px; min-width: 0; padding: 6px 10px 6px 6px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer; text-align: left;
}
.vehicle-switch .dot { width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #1F2A33; font: 700 13px var(--font-display); }
.vehicle-switch .label { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.vehicle-switch svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.rail .vehicle-switch { border-radius: var(--r-md); width: 100%; padding: 8px; }
.rail .vehicle-switch .label { max-width: none; flex: 1; }

.icon-btn {
  position: relative; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2); text-decoration: none; flex: none;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn .badge {
  position: absolute; top: -3px; right: -3px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  background: var(--red); color: #fff; font: 600 11px/19px var(--font); text-align: center; border: 2px solid var(--bg);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); }
.btn-primary:hover { background: #E2A615; border-color: #E2A615; }
.btn-danger { color: var(--red); }
.btn-danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: progress; }
.link-btn { background: none; border: 0; padding: 0; color: var(--amber-text); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Hero: plate + odometer ---------- */
.hero {
  position: relative; display: grid; gap: 18px; padding: 22px 20px 20px; border-radius: var(--r-lg);
  background: var(--ink); color: #F3F5F6; overflow: hidden; isolation: isolate;
}
:root[data-theme="dark"] .hero { background: #0F151A; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero { background: #0F151A; } }
.hero-photo { position: absolute; inset: 0; z-index: -1; background-size: cover; background-position: center; opacity: .28; filter: grayscale(.3); }
.hero-photo::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(15, 21, 26, .2), rgba(15, 21, 26, .85)); }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hero-name { font: 600 22px/1.1 var(--font-display); }
.hero-sub { color: #AEB8BF; font-size: 14px; margin-top: 2px; }
.plate {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px; border-radius: 6px; background: #FDFDFB; color: #111;
  border: 2px solid #111; box-shadow: inset 0 0 0 2px #FDFDFB, inset 0 0 0 3px #9AA3A9;
  font: 700 20px/1.3 var(--font-display); letter-spacing: .06em; white-space: nowrap;
}
.plate.sm { font-size: 14px; padding: 1px 8px; border-width: 1.5px; }
.plate.empty { background: transparent; color: #AEB8BF; border-style: dashed; border-color: #6B7780; box-shadow: none; font-weight: 500; letter-spacing: 0; font-size: 15px; }

.odo-wrap { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.odo { display: inline-flex; gap: 3px; padding: 6px; border-radius: 10px; background: #0A0F13; box-shadow: inset 0 2px 6px rgba(0,0,0,.6); }
.odo-d {
  position: relative; width: .72em; height: 1.18em; overflow: hidden; border-radius: 4px;
  background: linear-gradient(180deg, #050708, #20282E 30%, #20282E 70%, #050708); color: #F3F5F6;
  font: 600 44px/1 var(--font-display); text-align: center;
}
.odo-d.tenth { background: linear-gradient(180deg, #8F6800, var(--amber) 30%, var(--amber) 70%, #8F6800); color: #1F2A33; }
.odo-strip { display: flex; flex-direction: column; transform: translateY(calc(var(--n, 0) * -1.18em)); transition: transform 1.1s cubic-bezier(.2, .8, .2, 1); }
.odo-strip span { height: 1.18em; line-height: 1.18em; }
.odo-sep { width: 3px; }
.odo-unit { color: #AEB8BF; font: 500 15px var(--font-display); padding-bottom: 10px; }
@media (min-width: 600px) { .odo-d { font-size: 56px; } }
@media (prefers-reduced-motion: reduce) { .odo-strip { transition: none; } .boot-lane { animation: none; } }

.hero-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; }
.hero-stats > div { padding-right: 10px; }
.hero-stats > div + div { padding-left: 14px; border-left: 1px solid rgba(255,255,255,.12); }
.hero-stats dt { color: #AEB8BF; font-size: 13px; }
.hero-stats dd { margin: 2px 0 0; font: 600 21px/1.2 var(--font-display); }
.hero-stats dd small { font: 500 13px var(--font); color: #AEB8BF; }
.delta { font: 500 13px var(--font); }
.delta.up { color: #F4A3A3; } .delta.down { color: #8FD6C9; }

/* ---------- Layout blocks ---------- */
.stack { display: grid; gap: 22px; }
.cols { display: grid; gap: 22px; }
@media (min-width: 900px) { .cols { grid-template-columns: 1.25fr 1fr; align-items: start; } .cols.even { grid-template-columns: 1fr 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel-head a, .panel-head button { font-size: 14px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 10px; }

.figures { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.figures > div { background: var(--surface); padding: 14px 16px; }
.figures dt { color: var(--muted); font-size: 14px; }
.figures dd { margin: 2px 0 0; font: 600 24px/1.2 var(--font-display); }
.figures dd small { font: 500 14px var(--font); color: var(--muted); }
@media (min-width: 700px) { .figures.four { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ---------- Alerts / reminders ---------- */
.alert-list { display: grid; gap: 10px; }
.alert {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit;
}
.alert.overdue { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); background: color-mix(in srgb, var(--red-soft) 55%, var(--surface)); }
.alert.soon { border-color: color-mix(in srgb, var(--amber) 55%, var(--line)); background: color-mix(in srgb, var(--amber-soft) 55%, var(--surface)); }
.alert .title { font-weight: 600; }
.alert .meta { color: var(--muted); font-size: 14px; }
.alert .when { text-align: right; font: 600 15px var(--font-display); white-space: nowrap; }
.alert.overdue .when { color: var(--red); }
.alert.soon .when { color: var(--amber-text); }
.status-ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); }
.status-ico svg { width: 18px; height: 18px; }
.overdue .status-ico { background: var(--red); color: #fff; }
.soon .status-ico { background: var(--amber); color: #1F2A33; }
.all-clear { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--r-md); background: var(--teal-soft); color: var(--ink); }
.all-clear svg { width: 22px; height: 22px; color: var(--teal); flex: none; }

/* Road progress bar: the lane you've driven so far toward the next service */
.road { position: relative; height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.road::after { content: ""; position: absolute; left: 0; right: 0; top: 5px; height: 1px; background: repeating-linear-gradient(90deg, var(--muted) 0 8px, transparent 8px 16px); opacity: .45; }
.road > i { position: absolute; inset: 0 auto 0 0; width: var(--p, 0%); background: var(--teal); border-radius: 6px; }
.road.soon > i { background: var(--amber); }
.road.overdue > i { background: var(--red); }

.rem-card { display: grid; gap: 10px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.rem-card .top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.rem-card .name { font: 600 18px var(--font-display); }
.rem-card .facts { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 14px; }
.rem-card .facts b { color: var(--ink); font-weight: 600; }
.rem-grid { display: grid; gap: 12px; }
@media (min-width: 760px) { .rem-grid { grid-template-columns: 1fr 1fr; } }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--teal-soft); color: var(--teal); }
.pill.soon { background: var(--amber-soft); color: var(--amber-text); }
.pill.overdue { background: var(--red-soft); color: var(--red); }
.pill.unknown, .pill.done, .pill.plain { background: var(--surface-2); color: var(--muted); }

/* ---------- Logbook rows ---------- */
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.rows > li + li { border-top: 1px solid var(--line); }
.row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; width: 100%; padding: 12px 14px;
  background: none; border: 0; text-align: left; cursor: pointer; color: inherit;
}
.row:hover { background: var(--surface-2); }
.kind-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; color: #fff; flex: none; }
.kind-ico svg { width: 20px; height: 20px; }
.k-trip { background: var(--k-trip); } .k-fuel { background: var(--k-fuel); } .k-service { background: var(--k-service); }
.k-repair { background: var(--k-repair); } .k-expense { background: var(--k-expense); }
:root[data-theme="dark"] .kind-ico { color: #10161B; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .kind-ico { color: #10161B; } }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .m { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { text-align: right; font: 600 16px var(--font-display); white-space: nowrap; }
.row .amt small { display: block; font: 400 13px var(--font); color: var(--muted); }
.row > div { min-width: 0; }
.day-head { padding: 14px 4px 6px; font: 600 15px var(--font-display); color: var(--ink-2); display: flex; justify-content: space-between; }
.day-head span:last-child { color: var(--muted); font-weight: 500; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; color: var(--ink-2);
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip .sw { width: 9px; height: 9px; border-radius: 50%; }
.search { display: flex; gap: 8px; margin-bottom: 10px; }
.search input { flex: 1; }

.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 10px; }
.empty-art { width: 140px; height: 18px; margin: 0 auto 18px; background: repeating-linear-gradient(90deg, var(--amber) 0 26px, transparent 26px 40px); border-radius: 2px; opacity: .8; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 14px; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.grid-3 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 420px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--muted); font-size: 13px; }
.field .err { color: var(--red); font-size: 13px; font-weight: 500; }
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 16px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--red); }
.input-affix { position: relative; }
.input-affix input { padding-right: 52px; }
.input-affix .affix { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.big-input input { font: 600 26px var(--font-display) !important; min-height: 56px !important; }
fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; margin: 0; display: grid; gap: 12px; }
legend { padding: 0 6px; font-weight: 600; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 6px 0; cursor: pointer; }
.switch .txt { display: grid; }
.switch .txt small { color: var(--muted); font-size: 13px; }
.switch input { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .2s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked { background: var(--teal); }
.switch input:checked::after { transform: translateX(18px); }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); }
.segmented button { border: 0; background: transparent; border-radius: 9px; padding: 8px 4px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; display: grid; justify-items: center; gap: 2px; }
.segmented button svg { width: 20px; height: 20px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.segmented button[aria-pressed="true"] svg { color: var(--kc, var(--amber-text)); }
.segmented.small button { padding: 6px 4px; }

.suggest { display: flex; gap: 6px; flex-wrap: wrap; }
.suggest button { padding: 5px 11px; border-radius: 999px; border: 1px dashed var(--line); background: transparent; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.suggest button:hover { border-style: solid; }
.calc-line { font-size: 14px; color: var(--muted); }
.calc-line b { color: var(--ink); }
.warning { padding: 10px 12px; border-radius: var(--r-sm); background: var(--amber-soft); color: var(--ink); font-size: 14px; }
.form-error { padding: 10px 12px; border-radius: var(--r-sm); background: var(--red-soft); color: var(--red); font-size: 14px; font-weight: 500; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.form-actions .btn-danger { margin-right: auto; }
.color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.color-row label { position: relative; cursor: pointer; }
.color-row input { position: absolute; opacity: 0; }
.color-row span { display: block; width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.color-row input:checked + span { box-shadow: 0 0 0 2px var(--ink); }
.color-row input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Sheet / dialog ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15, 21, 26, .45); opacity: 0; transition: opacity .2s; }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; z-index: 51; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-sheet);
  padding: 8px 18px calc(18px + var(--safe-b)); transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { font-size: 22px; }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: min(600px, calc(100vw - 48px)); max-height: 88dvh; border-radius: var(--r-lg);
    transform: translate(-50%, -46%); opacity: 0; transition: transform .2s ease, opacity .2s ease; padding: 20px 24px 24px; }
  .sheet.open { transform: translate(-50%, -50%); opacity: 1; }
  .sheet .grab { display: none; }
  .sheet.wide { width: min(860px, calc(100vw - 48px)); }
}
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { transition: none; } }

.menu-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.menu-list a, .menu-list button {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 10px; border-radius: var(--r-sm); text-decoration: none;
  background: none; border: 0; cursor: pointer; font-size: 16px; font-weight: 500; color: inherit; text-align: left;
}
.menu-list a:hover, .menu-list button:hover { background: var(--surface-2); }
.menu-list svg { width: 22px; height: 22px; color: var(--muted); flex: none; }
.menu-list .sel { margin-left: auto; color: var(--teal); }

/* ---------- Toast ---------- */
.toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + var(--safe-b) + 16px); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); }
@media (min-width: 900px) { .toasts { bottom: 24px; } }
.toast { padding: 12px 16px; border-radius: var(--r-md); background: var(--ink); color: var(--bg); font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,.25); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.toast.error { background: var(--red); color: #fff; }
.toast button { background: none; border: 0; color: var(--amber); font-weight: 700; cursor: pointer; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font: 12px var(--font); }
.chart .grid line { stroke: var(--line); }
.chart .axis-base { stroke: var(--muted); stroke-opacity: .5; }
.chart .line { fill: none; stroke: var(--teal); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--teal); opacity: .1; }
.chart .dot { fill: var(--surface); stroke: var(--teal); stroke-width: 2; }
.chart .avg { stroke: var(--amber-text); stroke-dasharray: 5 5; stroke-width: 1.5; }
.chart .avg-label { fill: var(--amber-text); font-weight: 600; }
.chart .val { fill: var(--ink); font-weight: 600; font-family: var(--font-display); }
.chart .budget { stroke: var(--red); stroke-dasharray: 4 4; stroke-width: 1.5; }
.chart-wrap { position: relative; }
.chart-tip { position: absolute; pointer-events: none; padding: 6px 10px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 13px; white-space: nowrap; transform: translate(-50%, -110%); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; color: var(--ink-2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.cat-bars { display: grid; gap: 12px; }
.cat-bar .lbl { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 4px; }
.cat-bar .lbl b { font: 600 15px var(--font-display); }
.cat-bar .lbl small { color: var(--muted); margin-left: 6px; }
.cat-bar .bar { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.cat-bar .bar i { display: block; height: 100%; border-radius: 5px; }

.budget-meter { display: grid; gap: 6px; }
.budget-meter .bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.14); overflow: hidden; }
.budget-meter .bar i { display: block; height: 100%; background: var(--amber); }
.budget-meter .bar i.over { background: #F07272; }
.budget-meter small { color: #AEB8BF; font-size: 13px; }

/* ---------- Documents ---------- */
.doc-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.doc { display: grid; grid-template-rows: 120px auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; text-align: left; cursor: pointer; padding: 0; color: inherit; }
.doc .thumb { background: var(--surface-2) center / cover no-repeat; display: grid; place-items: center; color: var(--muted); }
.doc .thumb svg { width: 36px; height: 36px; }
.doc .info { padding: 10px 12px; display: grid; gap: 4px; }
.doc .info .t { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc .info .m { color: var(--muted); font-size: 13px; }
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(5, 8, 10, .92); display: grid; place-items: center; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 82dvh; border-radius: 8px; }
.lightbox .lb-bar { position: absolute; top: calc(env(safe-area-inset-top, 0px) + 12px); right: 12px; display: flex; gap: 8px; }
.lightbox .icon-btn { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; }
.drop { border: 2px dashed var(--line); border-radius: var(--r-md); padding: 20px; text-align: center; color: var(--muted); cursor: pointer; display: grid; gap: 6px; justify-items: center; }
.drop.has-file { border-style: solid; border-color: var(--teal); color: var(--ink); }
.drop svg { width: 28px; height: 28px; }

/* ---------- Garage ---------- */
.garage { display: grid; gap: 14px; }
@media (min-width: 760px) { .garage { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); } }
.car { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; display: grid; }
.car .stripe { height: 6px; }
.car .body { padding: 16px; display: grid; gap: 10px; }
.car .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.car .head h3 { font-size: 20px; }
.car .facts { color: var(--muted); font-size: 14px; display: flex; gap: 4px 14px; flex-wrap: wrap; }
.car .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.car.archived { opacity: .7; }
.car-photo { aspect-ratio: 16 / 7; background: var(--surface-2) center / cover; }

/* ---------- Settings ---------- */
.settings { display: grid; gap: 18px; max-width: 760px; }
.settings .panel h2 { margin-bottom: 4px; }
.settings .panel > p.muted { margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.members { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.members li { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.offline-bar { position: sticky; top: 0; z-index: 25; padding: 8px 16px; background: var(--ink); color: var(--bg); font-size: 14px; text-align: center; }
.offline-bar b { color: var(--amber); }

/* ---------- Auth / install ---------- */
.auth { min-height: 100dvh; display: grid; grid-template-rows: 1fr auto; }
.auth-inner { display: grid; align-content: center; gap: 20px; width: min(420px, 100%); margin: 0 auto; padding: 32px 20px; }
.auth-mark { display: flex; align-items: center; gap: 12px; }
.auth-mark img { width: 48px; height: 48px; border-radius: 12px; }
.auth-mark b { font: 600 22px var(--font-display); }
.auth h1 { font-size: 34px; }
.auth .lead { color: var(--muted); margin-top: -10px; }
.lane-rule { height: 8px; background: repeating-linear-gradient(90deg, var(--amber) 0 40px, transparent 40px 64px); }
.auth-alt { text-align: center; color: var(--muted); }
.auth-alt a, .auth-alt button { color: var(--ink); font-weight: 600; }

body.install { padding: 24px 16px 48px; }
.install-card { width: min(640px, 100%); margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; padding: 0 24px 28px; }
.install-card .lane-rule { margin: 0 -24px 22px; }
.install-card h1 { margin-bottom: 12px; }
.install-card .lead { font-size: 18px; }
.checks { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 4px; font-size: 15px; }
.checks li::before { display: inline-block; width: 22px; font-weight: 700; }
.checks .ok::before { content: "✓"; color: var(--teal); }
.checks .bad::before { content: "✕"; color: var(--red); }
.checks .opt::before { content: "–"; color: var(--muted); }
.note { padding: 10px 12px; border-radius: var(--r-sm); font-size: 15px; }
.note.bad { background: var(--red-soft); color: var(--red); }
.note.warn { background: var(--amber-soft); }
.choice { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: 15px; }
.choice input { margin-top: 5px; accent-color: var(--ink); }
.when-import, .when-fresh { display: grid; gap: 12px; padding-left: 26px; }
form:has(input[value="fresh"]:checked) .when-import, form:has(input[value="import"]:checked) .when-fresh { display: none; }
.install-report { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; margin: 0 0 14px; }
.install-report div { background: var(--surface); padding: 10px 12px; }
.install-report dt { color: var(--muted); font-size: 13px; }
.install-report dd { margin: 0; font: 600 22px var(--font-display); }

/* ---------- Print (reports) ---------- */
@media print {
  .rail, .tabbar, .topbar, .no-print, .toasts { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
  .panel, .rows { break-inside: avoid; }
}
.chart-slot { min-height: 40px; }
.hero-stats dd { white-space: nowrap; }
@media (max-width: 420px) { .hero-stats dd { font-size: 18px; } .hero-stats > div + div { padding-left: 10px; } }
@media (min-width: 900px) { .odo-d { font-size: 64px; } }
