/* Trip Mileage - mobile-first styles. Light + dark via prefers-color-scheme. */
:root {
  color-scheme: light dark;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #121826;
  --muted: #4b5568;        /* >= 4.5:1 on --surface and --bg */
  --border: #cfd6e4;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --accent-soft: #e3ebff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #067647;
  --warn-bg: #fff4d6;
  --warn-text: #5c3d00;
  --bar: #1d4ed8;
  --bar-text: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 14px;
  --tap: 52px;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #171c26;
    --surface-2: #202737;
    --text: #eef1f7;
    --muted: #aab3c5;
    --border: #323b4f;
    --accent: #6ea0ff;
    --accent-text: #08101f;
    --accent-soft: #1b2a4a;
    --danger: #ff8a80;
    --danger-soft: #3a1a1a;
    --ok: #5fd39a;
    --warn-bg: #3b2f10;
    --warn-text: #ffe2a0;
    --bar: #111827;
    --bar-text: #eef1f7;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  /* keep focused/scrolled-to controls clear of the sticky bar and fixed tab bar */
  scroll-padding-top: calc(64px + env(safe-area-inset-top));
  scroll-padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
}
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-text); padding: 10px 14px; z-index: 100; }
.skip-link:focus { left: 8px; top: 8px; }
.noscript { padding: 16px; }

/* Keyboard / switch-access focus is always visible */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
main:focus { outline: none; }

/* ---- App bar ---- */
.app-bar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bar); color: var(--bar-text);
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px calc(16px + env(safe-area-inset-left));
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.app-bar h1 { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: .2px; }
.app-bar-sub { font-size: .85rem; opacity: .9; }

main {
  max-width: 720px; margin: 0 auto;
  padding: 16px calc(14px + env(safe-area-inset-right)) 16px calc(14px + env(safe-area-inset-left));
}

/* ---- Tab bar ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; min-height: var(--tabbar-h); background: none; border: 0; color: var(--muted);
  font: inherit; font-size: .8rem; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--accent); }

/* ---- Cards & typography ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin: 0 0 14px;
}
.card h2, .section-title { margin: 0 0 10px; font-size: 1.1rem; }
.card h3 { margin: 14px 0 6px; font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
p { margin: 0 0 10px; }

/* ---- Hero total ---- */
.hero { background: var(--accent-soft); border-color: transparent; }
.hero .label { font-size: .85rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.hero .total { font-size: 3rem; font-weight: 800; line-height: 1.1; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.hero .total .unit { font-size: 1.2rem; font-weight: 600; color: var(--muted); margin-left: 4px; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .9rem; }
.hero .title { font-weight: 700; font-size: 1.1rem; margin-bottom: 8px; overflow-wrap: anywhere; }

/* ---- Forms ---- */
.field { margin: 0 0 14px; }
.field label, .field .lbl, legend { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
.hint { font-size: .85rem; color: var(--muted); margin: 5px 0 0; }
input[type="text"], input[type="search"], textarea, select {
  width: 100%; min-height: var(--tap); padding: 12px 14px; font: inherit; font-size: 1rem; /* 16px+ stops iOS zoom */
  color: var(--text); background: var(--surface); border: 2px solid var(--border); border-radius: 12px;
}
textarea { min-height: 96px; resize: vertical; }
input.big { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
.error { color: var(--danger); font-weight: 600; font-size: .92rem; margin: 6px 0 0; }
.error:empty { display: none; }
.preview { color: var(--ok); font-weight: 700; margin: 6px 0 0; min-height: 1.3em; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }

/* Segmented control (radio buttons styled as a toggle) */
.seg { display: flex; border: 2px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.seg label { flex: 1; margin: 0; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 6px 8px; text-align: center; font-weight: 600; font-size: .95rem; color: var(--muted); }
.seg input:checked + span { background: var(--accent); color: var(--accent-text); }
.seg input:focus-visible + span { outline: 3px solid var(--text); outline-offset: -4px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 12px 18px; font: inherit; font-weight: 700; font-size: 1rem;
  border-radius: 12px; border: 2px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 44px; padding: 8px 14px; font-size: .92rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.btn-row > .btn { flex: 1 1 140px; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 700; padding: 10px 6px; min-height: 44px; cursor: pointer; }

/* ---- Lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.stop { border-top: 1px solid var(--border); padding: 12px 0; }
.stop:first-child { border-top: 0; }
.stop-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.stop-name { font-weight: 700; overflow-wrap: anywhere; }
.stop-miles { font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stop-sub { color: var(--muted); font-size: .9rem; }
.stop-notes { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .95rem; }
.stop-actions { display: flex; gap: 8px; margin-top: 8px; }

.trip-item {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 0 10px; cursor: pointer; box-shadow: var(--shadow);
}
.trip-item .row { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.trip-item .name { font-weight: 700; overflow-wrap: anywhere; }
.trip-item .miles { font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.trip-item .sub { color: var(--muted); font-size: .9rem; }
.trip-item .note { color: var(--muted); font-size: .9rem; margin-top: 4px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }

.banner { border-radius: 12px; padding: 12px 14px; margin: 0 0 14px; font-size: .95rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.err { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.banner .btn-row { margin-top: 8px; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 10px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.export-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); }
.export-row:first-of-type { border-top: 0; }
.export-row .what { flex: 1 1 100%; }
.export-row .what b { display: block; }
.export-row .btn { flex: 1 1 120px; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(5, 10, 20, .6);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface); color: var(--text); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.modal h2 { margin: 0 0 12px; font-size: 1.2rem; }
.modal h3 { margin: 14px 0 4px; font-size: 1rem; }
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 20px; }
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 600; max-width: 90vw; text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .trip-item { transition: transform .08s ease; }
}
@media print {
  .tabbar, .app-bar, .btn, .btn-row { display: none !important; }
}

/* ---- Tesla (optional) ---- */
.tesla-block { margin: 4px 0 14px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: 12px; background: var(--surface-2); }
.tesla-card .tesla-block { margin: 0; padding: 0; border: 0; background: none; }
.tesla-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.tesla-block .btn { margin-top: 8px; }
.tesla-block .btn:first-of-type { margin-top: 2px; }
a.btn { text-decoration: none; }

/* Odometer-needed modal: checkbox row with a big tap target */
.field label.check, .check { display: flex; align-items: flex-start; gap: 12px; font-weight: 600; min-height: 44px; padding: 6px 0; cursor: pointer; }
.check input[type=checkbox] { width: 28px; height: 28px; flex: 0 0 28px; margin: 0; }
input:disabled { opacity: .5; cursor: not-allowed; }
