/* WrenchLedger — shop-ticket / service-logbook aesthetic */
:root {
  --paper: #f4f1ea;
  --card: #fffdf8;
  --ink: #1d2124;
  --ink-2: #4a5157;
  --ink-3: #5c636a;       /* 6.0:1 on card (was 3.7:1) */
  --rule: #dcd6c8;
  --rule-2: #ebe6da;
  --accent: #c2410c;      /* shop-tag orange — 5.2:1 with white text */
  --accent-ink: #fff;
  --accent-soft: #fde8dc;
  --ok: #237032;
  --ok-soft: #e3f4e6;
  --warn: #8a5a0b;
  --warn-soft: #fbf0d5;
  --bad: #b02525;
  --bad-soft: #fbe2e2;
  --fuel: #1c7ed6;
  --svc: #d9480f;
  /* fixed-dark surfaces (top bar, login hero, odometer) — never flip with the theme */
  --chrome: #1d2124;
  --chrome-ink: #f4f1ea;
  --chrome-ink-2: #c9c5bc;
  --odo-bg: #1d2124;
  --odo-ink: #f4f1ea;
  --odo-edge: transparent;
  /* form fields: white boxes with a visible edge (3.4:1) */
  --field-bg: #fff;
  --field-border: #8f8a7e;
  --shadow: 0 1px 0 rgba(29,33,36,.06), 0 2px 10px rgba(29,33,36,.05);
  --radius: 10px;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151719; --card: #1d2023; --ink: #ece8df; --ink-2: #c4bfb5; --ink-3: #a3a7ab;
    --rule: #3a3f44; --rule-2: #2a2d31; --accent: #f76707; --accent-ink: #1a1208; --accent-soft: #3a2416;
    --chrome: #0f1112; --chrome-ink: #f4f1ea; --chrome-ink-2: #c9c5bc;
    --odo-bg: #0b0c0d; --odo-ink: #f4f1ea; --odo-edge: #4a4f54;
    --field-bg: #111315; --field-border: #6b7075;
    --ok: #51cf66; --ok-soft: #1e3324; --warn: #fcc419; --warn-soft: #3a3118; --bad: #ff6b6b; --bad-soft: #3d2022;
    --fuel: #4dabf7; --svc: #f76707; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.hidden, [hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 10px 24px;
  background: var(--chrome); color: var(--chrome-ink); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { text-decoration: none; padding: 6px 12px; border-radius: 6px; font-size: 14px; color: var(--chrome-ink-2); }
.nav a:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav a.active { color: #fff; background: rgba(255,255,255,.12); }
.avatar { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); background: #555 center/cover; cursor: pointer; color: #fff; font-weight: 600; padding: 0; }
.tabbar { display: none; }

.banner { padding: 10px 24px; background: var(--warn-soft); color: var(--ink); border-bottom: 1px solid var(--rule); font-size: 14px; }
.banner a, .banner button { margin-left: 8px; }

.app { max-width: 1180px; margin: 0 auto; padding: 24px 24px 80px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- primitives ---------- */
.card { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--rule-2); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.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)); }
.stack > * + * { margin-top: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--field-border); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font: 500 14px var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--rule-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: progress; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--rule-2); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- stat tiles ---------- */
.stat { padding: 16px 18px; }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }
.stat .value { font: 600 26px/1.15 var(--mono); margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }

/* odometer readout */
.odo { display: inline-flex; gap: 2px; font: 600 20px var(--mono); }
.odo span { background: var(--odo-bg); color: var(--odo-ink); box-shadow: inset 0 0 0 1px var(--odo-edge); padding: 2px 5px; border-radius: 3px; min-width: 1ch; text-align: center; }
.odo span.unit { background: transparent; box-shadow: none; color: var(--ink-3); font-size: 13px; padding-left: 6px; align-self: flex-end; }

/* ---------- vehicle cards ---------- */
.vcard { display: block; text-decoration: none; padding: 18px 20px; position: relative; overflow: hidden; transition: border-color .15s; }
.vcard:hover { border-color: var(--ink-3); }
.vcard .vtitle { font-weight: 700; font-size: 17px; }
.vcard .vsub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.vcard .vstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--rule); }
.vcard .vstats div { font-size: 12px; color: var(--ink-3); }
.vcard .vstats b { display: block; font: 600 15px var(--mono); color: var(--ink); }
.vcard .tag { position: absolute; top: 14px; right: -1px; background: var(--accent); color: var(--accent-ink); font: 600 11px var(--mono); padding: 3px 10px 3px 12px; border-radius: 4px 0 0 4px; letter-spacing: .04em; }
.vcard.add { display: grid; place-items: center; min-height: 160px; border-style: dashed; color: var(--ink-3); font-weight: 600; background: transparent; box-shadow: none; }

/* ---------- lists / tables ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: 14px; align-items: center; padding: 12px 20px; border-top: 1px solid var(--rule-2); }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.list .s { color: var(--ink-3); font-size: 13px; }
.list .amt { font: 600 15px var(--mono); text-align: right; white-space: nowrap; }
.empty { padding: 28px 20px; text-align: center; color: var(--ink-3); }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--rule-2); vertical-align: top; }
table.data td.n, table.data th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--rule-2); }
.table-wrap { overflow-x: auto; }

/* ---------- vehicle detail ---------- */
.vhead { padding: 22px 24px; display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; }
.vhead .vin { font: 500 13px var(--mono); color: var(--ink-2); letter-spacing: .06em; margin-top: 6px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); margin: 20px 0; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font: 500 14px var(--sans); color: var(--ink-3); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabs .count { font: 500 11px var(--mono); background: var(--rule-2); border-radius: 999px; padding: 1px 6px; margin-left: 4px; }

.spec { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px 20px; }
.spec div { font-size: 13px; color: var(--ink-3); }
.spec b { display: block; color: var(--ink); font-weight: 500; font-size: 14px; }

/* chart */
.chart { width: 100%; height: auto; display: block; }
.chart text { font: 11px var(--mono); fill: var(--ink-3); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-3); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; margin: 6px 0; }
.bar-row .track { height: 8px; background: var(--rule-2); border-radius: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.bar-row .n { font-family: var(--mono); text-align: right; }

/* reminders */
.rem-meter { height: 6px; background: var(--rule-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.rem-meter > div { height: 100%; }

/* ---------- forms ---------- */
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; letter-spacing: .02em; }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--field-border); border-radius: 8px; background: var(--field-bg);
  font: 16px var(--sans); color: var(--ink); -webkit-text-fill-color: var(--ink); opacity: 1; }
.field input[type=number], .field input[inputmode=decimal] { font-family: var(--mono); font-variant-numeric: tabular-nums; }
input::placeholder, textarea::placeholder { color: var(--ink-3); -webkit-text-fill-color: var(--ink-3); opacity: 1; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field textarea { min-height: 80px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--ink-3); margin-top: 3px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; padding-top: 22px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.vin-input { font-family: var(--mono) !important; letter-spacing: .08em; text-transform: uppercase; }

.lines { width: 100%; border-collapse: collapse; font-size: 13px; }
.lines td, .lines th { padding: 4px; }
.lines th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.lines input, .lines select { width: 100%; padding: 6px 8px; border: 1px solid var(--field-border); border-radius: 6px; background: var(--field-bg); font: 14px var(--sans); color: var(--ink); -webkit-text-fill-color: var(--ink); }
.lines .n input { font-family: var(--mono); text-align: right; }

/* ---------- modal / toast ---------- */
.modal { border: 0; padding: 0; border-radius: 14px; width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px);
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(20,22,24,.55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--rule-2); position: sticky; top: 0; background: var(--card); z-index: 1; }
.modal-body { padding: 18px 20px 20px; }
/* keep Save/Cancel reachable no matter how long the form is */
.modal .form-actions { position: sticky; bottom: 0; z-index: 1; margin: 18px -20px -20px; padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--rule); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }
.toast.err { background: #b02525; color: #fff; }

/* ---------- scan ---------- */
.drop { display: block; border: 2px dashed var(--rule); border-radius: 14px; padding: 40px 20px; text-align: center; background: var(--card); cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .big { font-size: 40px; line-height: 1; }
.scan-grid { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.preview { width: 100%; border-radius: 10px; border: 1px solid var(--rule); background: #fff; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--rule); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.warnbox { background: var(--warn-soft); border-radius: 8px; padding: 10px 14px; font-size: 13px; }
.warnbox ul { margin: 4px 0 0; padding-left: 18px; }
.confidence { height: 6px; border-radius: 3px; background: var(--rule-2); overflow: hidden; width: 120px; display: inline-block; vertical-align: middle; }
.confidence > div { height: 100%; background: var(--ok); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login .hero { background: var(--chrome); color: var(--chrome-ink); padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login .hero h1 { font-size: 44px; line-height: 1.05; max-width: 12ch; }
.login .hero p { color: #b9b4aa; max-width: 44ch; font-size: 16px; }
.login .ticket { font: 13px var(--mono); border: 1px dashed rgba(244,241,234,.3); border-radius: 8px; padding: 16px 18px; max-width: 420px; line-height: 1.8; white-space: nowrap; overflow: hidden; }
.login .ticket .ln { display: flex; gap: 6px; }
.login .ticket .ln i { flex: 1; border-bottom: 1px dotted rgba(244,241,234,.35); margin-bottom: 6px; }
.login .ticket b { color: #ff8c4a; font-weight: 600; }
.login .panel { display: grid; place-items: center; padding: 40px; }
.login .box { max-width: 360px; width: 100%; }
.gbtn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 12px; border: 1px solid var(--field-border); border-radius: 8px; background: #fff; color: #1f1f1f; font: 500 15px var(--sans); text-decoration: none; }
.gbtn:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.features { list-style: none; padding: 0; margin: 24px 0 0; font-size: 14px; color: var(--ink-2); }
.features li { padding: 6px 0 6px 24px; position: relative; }
.features li::before { content: '✓'; position: absolute; left: 0; color: var(--ok); font-weight: 700; }

/* ---------- legal pages ---------- */
.legal { max-width: 760px; margin: 0 auto; padding: 40px 20px 80px; line-height: 1.65; }
.legal h1 { font-size: 32px; margin-bottom: 4px; }
.legal h2 { font-size: 19px; margin: 34px 0 10px; padding-top: 18px; border-top: 1px solid var(--rule); }
.legal h3 { font-size: 13px; margin: 20px 0 6px; }
.legal p, .legal li { color: var(--ink-2); }
.legal ul { padding-left: 22px; }
.legal li { margin: 4px 0; }
.legal b { color: var(--ink); font-weight: 600; }
.legal a { color: var(--accent); }
.legal table.data { margin: 10px 0; font-size: 14px; }
.legal .legal-foot { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--rule); font-size: 14px; }
.login a { color: var(--accent); }

/* ---------- share page ---------- */
.share-wrap { max-width: 900px; margin: 0 auto; padding: 32px 20px 60px; }
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 2px; background: var(--rule); }
.timeline li { position: relative; padding: 0 0 18px 30px; }
.timeline li::before { content: ''; position: absolute; left: 1px; top: 6px; width: 14px; height: 14px; border-radius: 50%; background: var(--card); border: 3px solid var(--accent); }

@media (max-width: 900px) {
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .scan-grid { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login .hero { padding: 36px 24px; min-height: auto; gap: 28px; }
  .login .hero h1 { font-size: 34px; }
  .login .ticket { font-size: 12px; }
}
@media (max-width: 680px) {
  .nav { display: none; }
  .topbar { padding: 10px 16px; justify-content: space-between; }
  .app { padding: 16px 16px calc(104px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--rule); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar[hidden] { display: none; }
  .tabbar a { text-decoration: none; text-align: center; font-size: 11px; min-height: 44px; justify-content: flex-end; color: var(--ink-3); display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .tabbar a.active { color: var(--accent); }
  .tabbar .ti { font-size: 18px; line-height: 1.1; }
  .tabbar .scan-fab .ti { background: var(--accent); color: #fff; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; margin-top: -18px; box-shadow: 0 4px 12px rgba(194,65,12,.35); }
  .tabbar .scan-fab .ti { color: var(--accent-ink); }
  /* the on-screen keyboard pushes the fixed tab bar over the form — hide it while typing */
  body:has(.app input:focus, .app select:focus, .app textarea:focus) .tabbar { display: none; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

  /* touch targets + no iOS zoom-on-focus (needs >=16px text) */
  .btn { min-height: 44px; padding: 10px 16px; font-size: 15px; }
  .btn.sm { min-height: 38px; padding: 7px 12px; font-size: 14px; }
  input.btn { font-size: 16px; }
  .form-actions .btn { flex: 1 1 auto; }
  .form-actions .btn.primary { flex: 2 1 auto; }
  .form-actions .btn.danger { flex: 0 0 auto; margin-right: auto; }
  .vhead > div:last-child { text-align: left !important; }
  .vhead .row { justify-content: flex-start !important; }

  /* line items: stack each row as a mini card instead of a 6-column table */
  .lines, .lines tbody { display: block; }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr auto; grid-template-areas: "desc desc del" "part type type" "qty amt amt";
    gap: 6px; padding: 10px 0; border-bottom: 1px dashed var(--rule); }
  .lines td { display: block; width: auto !important; padding: 0; }
  .lines td:nth-child(1) { grid-area: desc; } .lines td:nth-child(2) { grid-area: part; } .lines td:nth-child(3) { grid-area: type; }
  .lines td:nth-child(4) { grid-area: qty; } .lines td:nth-child(5) { grid-area: amt; } .lines td:nth-child(6) { grid-area: del; }
  .lines input, .lines select { font-size: 16px; min-height: 42px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .vhead { grid-template-columns: 1fr; }
  h1 { font-size: 22px; }
  .stat .value { font-size: 21px; }
  .list > li { padding: 12px 14px; }
  .card-head { padding: 12px 14px; }
  .bar-row { grid-template-columns: 90px 1fr 74px; }
  /* full-screen sheet sized to the *visible* viewport (100vh on iOS includes the area under the toolbar) */
  .modal { width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .modal-head { padding: calc(12px + env(safe-area-inset-top)) 16px 12px; }
  .modal-body { padding: 16px 16px 20px; }
  .modal .form-actions { margin: 18px -16px -20px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .hide-sm { display: none; }
}
