:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #e8efff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #16a34a;
  --warn: #d97706;
  --warn-soft: #fff4e0;
  --c-service: #2563eb;
  --c-fuel: #059669;
  --c-event: #9333ea;
  --c-odometer: #64748b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #131a2b;
    --surface-2: #182136;
    --border: #253049;
    --text: #e8ecf4;
    --muted: #94a0b8;
    --primary: #5b8cff;
    --primary-ink: #0b1020;
    --primary-soft: #1c2a4d;
    --danger: #f87171;
    --danger-soft: #3a1a1f;
    --warn-soft: #3a2a10;
    --c-service: #5b8cff;
    --c-fuel: #34d399;
    --c-event: #c084fc;
    --c-odometer: #94a3b8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon { width: 42px; padding: 0; }
.btn.block { width: 100%; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.field.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-weight: 500; font-size: 15px; }
input, select, textarea {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 18px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; }
.brand .logo svg { width: 20px; height: 20px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100%; }
.content-col { min-width: 0; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 20px;
}
.side-section { display: flex; flex-direction: column; gap: 2px; }
.side-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; padding: 6px 10px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 550; min-width: 0;
}
.nav-link span { overflow: hidden; text-overflow: ellipsis; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-thumb { width: 28px; height: 28px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); object-fit: cover; flex: none; display: grid; place-items: center; color: var(--muted); }
.nav-thumb svg { width: 16px; height: 16px; }
.side-foot { margin-top: auto; font-size: 13px; color: var(--muted); padding: 0 10px; overflow-wrap: anywhere; }

.main { min-width: 0; padding: 28px clamp(20px, 3vw, 48px) 48px; max-width: 1600px; width: 100%; margin: 0 auto; }
.topbar { display: none; }
.bottom-nav { display: none; }

@media (max-width: 899px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .main { padding: 16px 16px calc(96px + var(--safe-bottom)); }
  .topbar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 20;
    background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
    padding: 10px 12px; border-bottom: 1px solid var(--border); min-height: 56px;
  }
  .topbar .title { flex: 1; font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom);
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0 8px;
    color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
  }
  .bottom-nav a.active { color: var(--primary); }
}

/* ---------- page pieces ---------- */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .grow { flex: 1; min-width: 0; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }
.section { margin-top: 24px; }
.section > .section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty > svg { width: 44px; height: 44px; stroke-width: 1.5; opacity: .6; }

/* vehicle cards */
.vehicle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.vcard { overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; }
.vcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.vcard .photo { aspect-ratio: 16 / 9; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }
.vcard .photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vcard .photo svg { width: 54px; height: 54px; stroke-width: 1.3; opacity: .5; }
.vcard .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.vcard .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 13px; }
.vcard .meta b { display: block; font-size: 15px; }
.plate { display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; font-weight: 700; border: 1.5px solid var(--border); border-radius: 5px; padding: 1px 6px; letter-spacing: .04em; }

/* vehicle detail */
.hero { display: grid; grid-template-columns: clamp(220px, 24vw, 340px) 1fr; gap: 20px; padding: 16px; align-items: center; }
.hero .photo { aspect-ratio: 4 / 3; border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.hero .photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero .photo svg { width: 60px; height: 60px; stroke-width: 1.3; opacity: .5; }
.hero .info { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); font-weight: 600; overflow-wrap: anywhere; }
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; } .hero .photo { aspect-ratio: 16 / 9; } }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.stat { padding: 14px 16px; }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .sub { font-size: 12px; color: var(--muted); }
@media (max-width: 899px) { .stats { grid-template-columns: 1fr 1fr; } .stat .value { font-size: 19px; } }

.tabs { display: flex; gap: 4px; margin-top: 24px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 14px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .count { font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; margin-left: 4px; }

.toolbar { display: flex; gap: 8px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }

/* entries list */
.entries { display: flex; flex-direction: column; }
.entry { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: flex-start; }
.entry:last-child { border-bottom: 0; }
.entry:hover { background: var(--surface-2); }
.entry .dot { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; color: #fff; }
.entry .dot svg { width: 18px; height: 18px; }
.entry .dot.service { background: var(--c-service); }
.entry .dot.fuel { background: var(--c-fuel); }
.entry .dot.event { background: var(--c-event); }
.entry .dot.odometer { background: var(--c-odometer); }
.entry .main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.entry .title { font-weight: 600; overflow-wrap: anywhere; }
.entry .desc { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.entry .right { text-align: right; flex: none; display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }
.entry .right .amt { font-weight: 650; }
.entry .right .date { color: var(--muted); font-size: 13px; }

.reminder { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.reminder:last-child { border-bottom: 0; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.overdue { background: var(--danger-soft); color: var(--danger); }
.badge.soon { background: var(--warn-soft); color: var(--warn); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 899px) { .two-col { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.fab {
  display: none; position: fixed; right: 16px; bottom: calc(76px + var(--safe-bottom)); z-index: 25;
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--primary); color: var(--primary-ink);
  box-shadow: var(--shadow-lg); cursor: pointer; place-items: center;
}
.fab svg { width: 26px; height: 26px; }
@media (max-width: 899px) { .fab { display: grid; } .hide-mobile { display: none !important; } }
@media (min-width: 900px) { .hide-desktop { display: none !important; } }

/* settings */
.settings { display: flex; flex-direction: column; gap: 16px; max-width: 720px; }
.setting-row { display: flex; align-items: center; gap: 16px; padding: 16px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.setting-row:last-child { border-bottom: 0; }
.setting-row .grow { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 2px; }
.setting-row select { width: auto; min-width: 160px; }

/* ---------- modal / sheet ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8, 12, 24, .5); z-index: 100;
  display: grid; place-items: center; padding: 16px; animation: fade .15s ease-out;
}
.modal {
  background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .18s ease-out;
}
.modal header { display: flex; align-items: center; gap: 8px; padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.modal header h2 { flex: 1; }
.modal .content { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal footer { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 18px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal footer .spacer { flex: 1; }
@media (max-width: 640px) {
  .modal-backdrop { place-items: end stretch; padding: 0; }
  .modal { max-width: none; border-radius: 20px 20px 0 0; max-height: 92vh; animation: slide-up .22s ease-out; }
  .modal footer { padding-bottom: calc(16px + var(--safe-bottom)); }
  .modal footer .btn { flex: 1; }
  .modal footer .spacer { display: none; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }
@keyframes slide-up { from { transform: translateY(100%); } }

.type-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-picker button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.type-picker button:hover { border-color: var(--primary); background: var(--primary-soft); }
.type-picker .dot { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; }
.type-picker .dot svg { width: 18px; height: 18px; }

.photo-picker { display: flex; align-items: center; gap: 14px; }
.photo-picker .preview { width: 96px; height: 72px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; display: grid; place-items: center; color: var(--muted); flex: none; }
.photo-picker .preview img { width: 100%; height: 100%; object-fit: cover; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translate(-50%, 150%);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; font-size: 14px;
  z-index: 200; transition: transform .25s ease, opacity .25s; opacity: 0; max-width: calc(100% - 32px); box-shadow: var(--shadow-lg); pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
@media (max-width: 899px) { #toast { bottom: calc(84px + var(--safe-bottom)); } }

.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 80px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
