:root {
  --navy: #0f2742;
  --navy-2: #1b3a5c;
  --teal: #0e9f9a;
  --teal-dark: #0b7f7b;
  --teal-soft: #e3f5f4;
  --bg: #f4f7fa;
  --card: #ffffff;
  --ink: #0f2742;
  --muted: #5b6b7d;
  --line: #dde4ec;
  --good: #0b7f5a;
  --bad: #c0392b;
  --bad-soft: #fdecea;
  --radius: 16px;
  --tabbar-h: 76px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--teal-dark); }
[hidden] { display: none !important; }

/* ── Top bar ── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: calc(60px + var(--safe-t));
  padding: var(--safe-t) 16px 0;
  background: var(--navy); color: #fff;
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: #fff; width: 44px; height: 44px; margin-left: -10px; display: grid; place-items: center; border-radius: 12px; cursor: pointer; }
.icon-btn:active { background: rgba(255,255,255,.12); }
.mode-pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: #f6c453; color: var(--navy); }

/* ── Layout ── */
main { padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 28px); max-width: 640px; margin: 0 auto; outline: none; }
.loading { padding: 48px 0; text-align: center; color: var(--muted); }
.section-title { margin: 24px 4px 10px; font-size: 14px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.section-title:first-child { margin-top: 4px; }
.section-title .count { font-weight: 600; letter-spacing: 0; text-transform: none; }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 18px; color: var(--muted); text-align: center; }

/* ── Summary banner ── */
.banner { background: linear-gradient(135deg, var(--navy), var(--navy-2)); color: #fff; border-radius: var(--radius); padding: 16px 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-decoration: none; }
.banner .label { font-size: 14px; opacity: .85; }
.banner .value { font-size: 24px; font-weight: 800; }
.banner .go { background: var(--teal); color: #fff; font-weight: 700; padding: 10px 14px; border-radius: 12px; white-space: nowrap; }

/* ── Car cards ── */
.cards { display: grid; gap: 12px; }
.car-card { display: block; background: var(--card); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; color: inherit; box-shadow: 0 1px 2px rgba(15,39,66,.06), 0 4px 14px rgba(15,39,66,.05); border: 1px solid transparent; }
.car-card:active { border-color: var(--teal); }
.car-card .head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.car-card h3 { margin: 0; font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
.pill { flex: none; font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--teal-soft); color: var(--teal-dark); }
.pill.sold { background: #e6ebf1; color: var(--navy-2); }
.pill.ready { background: #fff4d6; color: #8a5a00; }
.pill.listed { background: #e9e4ff; color: #4b3aa8; }
.figs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.fig .k { font-size: 13px; color: var(--muted); }
.fig .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ── Car pictures ── */
.car-art { display: block; margin: -16px -18px 12px; padding: 10px 18px 2px; border-radius: var(--radius) var(--radius) 0 0; background: linear-gradient(180deg, #eef3f8 0%, #dde6ef 100%); }
.car-art svg { display: block; width: 100%; height: auto; max-height: 130px; }
.car-art.hero { margin: 0 0 12px; padding: 18px 16px 6px; border-radius: var(--radius); }
.car-art.hero svg { max-height: 180px; }

/* colour swatches */
fieldset.field { border: 0; padding: 0; margin: 0; min-width: 0; }
.swatch-row { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { position: relative; width: 44px; height: 44px; cursor: pointer; }
.swatch input[type=radio] { position: absolute; opacity: 0; pointer-events: none; }
.swatch i { position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid rgba(15,39,66,.25); }
.swatch input[type=radio]:checked + i { box-shadow: 0 0 0 3px #fff, 0 0 0 5.5px var(--teal); }
.swatch input[type=radio]:focus-visible + i { outline: 2px solid var(--navy); outline-offset: 4px; }
.swatch.custom input[type=color] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Detail totals ── */
.totals { background: var(--navy); color: #fff; border-radius: var(--radius); padding: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.totals .fig .k { color: rgba(255,255,255,.75); }
.totals .fig .v { font-size: 20px; }
.totals .fig.wide { grid-column: 1 / -1; }
.totals .fig.hero .v { font-size: 28px; }
.totals .pos { color: #5ee0c4; }
.totals .neg { color: #ff9b8f; }
.totals .note { grid-column: 1 / -1; font-size: 14px; color: rgba(255,255,255,.8); border-top: 1px solid rgba(255,255,255,.15); padding-top: 10px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.actions .btn.full { grid-column: 1 / -1; }

/* ── Lists ── */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(15,39,66,.06); }
.item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; text-decoration: none; color: inherit; cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--teal-soft); }
.item .main { flex: 1; min-width: 0; }
.item .desc { font-weight: 600; overflow-wrap: anywhere; }
.item .sub { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.item .amt { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.item .chev { flex: none; color: #a8b4c2; }
.item .clip { display: inline-block; margin-left: 4px; }

/* ── Forms ── */
.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: 15px; }
.field > span .opt { font-weight: 400; color: var(--muted); }
.field .hint { font-size: 14px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=date], input[inputmode], select, textarea {
  width: 100%; min-height: 54px; padding: 12px 14px; font-size: 18px;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff; appearance: none; -webkit-appearance: none;
}
input[type=date] { min-width: 0; display: block; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%235b6b7d' stroke-width='2'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; padding-right: 44px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,159,154,.2); }
.money-input { position: relative; }
.money-input::before { content: "£"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 18px; font-weight: 600; color: var(--muted); pointer-events: none; }
.money-input input { padding-left: 32px; font-variant-numeric: tabular-nums; }
.field.invalid input, .field.invalid select { border-color: var(--bad); }
.err { color: var(--bad); font-size: 14px; font-weight: 600; }
.callout { background: var(--teal-soft); border-radius: 12px; padding: 12px 14px; font-size: 15px; }
.callout.warn { background: var(--bad-soft); color: #7a1f14; }
.callout strong { font-variant-numeric: tabular-nums; }

/* receipt */
.receipt-box { display: grid; gap: 10px; }
.receipt-box img { width: 100%; max-height: 320px; object-fit: contain; background: #eef2f6; border-radius: 12px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 54px; padding: 12px 18px; border-radius: 14px; border: 0; font-weight: 700; font-size: 17px; text-decoration: none; cursor: pointer; background: var(--teal); color: #fff; width: 100%; text-align: center; }
.btn:active { background: var(--teal-dark); }
.btn.secondary { background: #fff; color: var(--navy); border: 1.5px solid var(--line); }
.btn.secondary:active { background: #eef2f6; }
.btn.navy { background: var(--navy); }
.btn.danger { background: var(--bad); }
.btn.ghost-danger { background: none; color: var(--bad); border: 1.5px solid #f1c3bd; }
.btn.small { min-height: 40px; padding: 8px 12px; font-size: 15px; width: auto; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack { display: grid; gap: 10px; }

/* ── Bottom tab bar ── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 1.35fr 1fr 1fr; align-items: end;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding: 0 6px var(--safe-b);
  background: #fff; border-top: 1px solid var(--line);
}
.tabbar a { display: grid; justify-items: center; gap: 2px; padding: 10px 0 12px; font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none; }
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a.active { color: var(--teal-dark); }
.tabbar .tab-add { color: var(--navy); }
.tabbar .tab-add .plus { display: grid; place-items: center; width: 60px; height: 60px; margin-top: -26px; border-radius: 50%; background: var(--teal); color: #fff; font-size: 36px; line-height: 1; font-weight: 400; box-shadow: 0 6px 16px rgba(14,159,154,.4); border: 4px solid #fff; }
.tabbar .tab-add:active .plus { background: var(--teal-dark); }

/* ── Dialog + toast ── */
dialog { border: 0; border-radius: 20px; padding: 22px; width: min(92vw, 420px); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15,39,66,.55); }
dialog h2 { margin: 0 0 8px; font-size: 20px; }
dialog p { margin: 0 0 20px; color: var(--muted); }
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 30; margin: 0 auto; max-width: 480px; padding: 14px 16px; border-radius: 14px; background: var(--navy); color: #fff; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; transform: none; }
#toast.error { background: var(--bad); }

/* ── Auth ── */
.auth { max-width: 420px; margin: 24px auto 0; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 12px; display: block; }
.auth h2 { text-align: center; margin: 0 0 4px; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 22px; }
.linkish { background: none; border: 0; color: var(--teal-dark); font-weight: 600; padding: 10px; cursor: pointer; text-decoration: underline; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small-text { font-size: 14px; }
