:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ee;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgb(15 23 42 / .04), 0 6px 20px rgb(15 23 42 / .06);
  --c-blue: #2563eb;
  --c-orange: #ea580c;
  --c-green: #16a34a;
  --c-purple: #9333ea;
  --c-gray: #64748b;
  --radius: 16px;
  /* Logo colours (from the banner); orange slightly darker in light mode for contrast */
  --logo-a: #14161a;
  --logo-b: #ea5a0c;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f19;
    --surface: #131a2a;
    --surface-2: #1b2336;
    --border: #253049;
    --text: #e6e9f2;
    --muted: #8b95ab;
    --accent: #7c74ff;
    --accent-hover: #918aff;
    --accent-soft: #1f2347;
    --danger: #f87171;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    --c-blue: #60a5fa;
    --c-orange: #fb923c;
    --c-green: #4ade80;
    --c-purple: #c084fc;
    --c-gray: #94a3b8;
    --logo-a: #f2efe8;
    --logo-b: #ff6b1a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0f19;
  --surface: #131a2a;
  --surface-2: #1b2336;
  --border: #253049;
  --text: #e6e9f2;
  --muted: #8b95ab;
  --accent: #7c74ff;
  --accent-hover: #918aff;
  --accent-soft: #1f2347;
  --danger: #f87171;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
  --c-blue: #60a5fa;
  --c-orange: #fb923c;
  --c-green: #4ade80;
  --c-purple: #c084fc;
  --c-gray: #94a3b8;
  --logo-a: #f2efe8;
  --logo-b: #ff6b1a;
  color-scheme: dark;
}

/* Logo font: Anton (SIL OFL, see fonts/Anton-OFL.txt), subset to A–Z */
@font-face {
  font-family: 'Anton';
  src: url('fonts/anton-az.woff2') format('woff2');
  font-display: swap;
  unicode-range: U+41-5A;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; font-weight: 700; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.container { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: .85rem; }
.center { text-align: center; padding: 32px 0; }

.ic {
  width: 18px; height: 18px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.logo {
  font-family: 'Anton', 'Arial Narrow', Impact, sans-serif;
  font-weight: 400; text-transform: uppercase; letter-spacing: .01em; line-height: 1;
}
.logo-a { color: var(--logo-a); }
.logo-b { color: var(--logo-b); }
.brand { display: flex; align-items: center; font-size: 1.6rem; }
.topbar-actions { display: flex; gap: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px; border-radius: 11px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border-radius: 10px; border: 0; background: transparent; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm .ic { width: 16px; height: 16px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Hero */
.hero {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin: 28px 0 20px;
}
.hero-title { display: flex; align-items: center; gap: 14px; min-width: 0; }
.hero-title h1 { overflow-wrap: anywhere; }
.hero-actions { display: flex; align-items: center; gap: 4px; }
.hero-actions .btn { margin-left: 8px; }

.back {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 20px;
  color: var(--muted); font-weight: 500; font-size: .9rem;
}
.back:hover { color: var(--text); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; padding-bottom: 40px; }

.car-card { position: relative; display: flex; flex-direction: column; overflow: hidden; transition: border-color .15s; }
/* The title link covers the whole card; the wrench button sits on top of it. */
.card-link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.card-link:focus-visible { outline: none; }
.card-link:focus-visible::after { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius); }
.car-card-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.car-card-title > div { min-width: 0; }
.car-card-title h3 { overflow-wrap: anywhere; }
.quick-add {
  position: relative; z-index: 2; flex-shrink: 0;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
}
.quick-add:hover { background: var(--accent); color: #fff; }
.car-card:hover { border-color: var(--accent); }
.car-card h3 { font-size: 1.05rem; }
.car-media {
  display: grid; place-items: center; aspect-ratio: 16 / 9; overflow: hidden;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface-2)); color: var(--accent);
}
.car-media .ic { width: 48px; height: 48px; stroke-width: 1.5; opacity: .7; }
.car-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.car-card-body { display: flex; flex-direction: column; gap: 14px; padding: 16px 18px 18px; flex: 1; }

.avatar {
  display: grid; place-items: center; width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 12px; background: var(--accent-soft); color: var(--accent);
}
.avatar .ic { width: 22px; height: 22px; }
.avatar { overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.lg { width: 56px; height: 56px; border-radius: 15px; }
.avatar.lg .ic { width: 28px; height: 28px; }

.stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.stats div { flex: 1 1 auto; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stats dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stats dd { margin: 0; font-weight: 600; font-size: .92rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.card-foot { font-size: .85rem; border-top: 1px solid var(--border); padding-top: 12px; margin-top: auto; overflow-wrap: anywhere; }
.card-foot .nowrap { white-space: nowrap; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.tile { padding: 14px 16px; }
.tile span { display: block; font-size: .78rem; color: var(--muted); }
.tile strong { font-size: 1.15rem; }

/* Sections & photos */
.section-head { display: flex; align-items: center; gap: 8px; min-height: 32px; margin: 8px 0 12px; }
.section-head h2 { font-size: 1.1rem; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 28px; }
.thumb {
  position: relative; aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.thumb-img { all: unset; display: block; width: 100%; height: 100%; cursor: zoom-in; }
.thumb-img:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.thumb-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.thumb:hover .thumb-actions, .thumb:focus-within .thumb-actions { opacity: 1; }
@media (hover: none) { .thumb-actions { opacity: 1; } }
.thumb-actions .icon-btn, .thumb-actions .icon-btn:hover { background: rgb(0 0 0 / .55); color: #fff; backdrop-filter: blur(4px); }
.thumb-actions .icon-btn:hover { background: rgb(0 0 0 / .75); }
.cover-badge {
  position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px;
  background: rgb(0 0 0 / .55); color: #fff; font-size: .7rem; font-weight: 600;
}
.thumb.add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed var(--border); background: transparent; color: var(--muted);
  font-size: .85rem; font-weight: 500; cursor: pointer; transition: border-color .15s, color .15s;
}
.thumb.add:hover { border-color: var(--accent); color: var(--accent); }

/* Photos + info box */
.car-overview { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; margin-bottom: 28px; }
.car-overview .photo-grid { margin-bottom: 0; }
/* overflow + margin-top:-1px hide the top divider of the first visible row */
.infobox { padding: 0 18px; overflow: hidden; }
.info-list { margin: -1px 0 0; }
.info-list div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 10px 0; border-top: 1px solid var(--border); font-size: .9rem; }
.info-list dt { color: var(--muted); flex-shrink: 0; }
.info-list dd { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; margin: 0; text-align: right; font-weight: 500; overflow-wrap: anywhere; min-width: 0; }
.infobox-actions { display: flex; gap: 2px; margin: 0 -6px 0 auto; }
.info-toggle .ic { transition: transform .2s; }
.collapsed .info-toggle .ic { transform: rotate(-90deg); }
.collapsed .info-list div:not(.pinned) { display: none; }
.info-more {
  display: none; width: 100%; padding: 10px 0 12px; border: 0; border-top: 1px solid var(--border);
  background: none; color: var(--accent); font-size: .85rem; font-weight: 600; text-align: left; cursor: pointer;
}
.info-more:hover { text-decoration: underline; }
.collapsed .info-more { display: block; }
.infobox-empty { display: flex; flex-direction: column; gap: 12px; padding: 14px 0 16px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85rem; }
[data-color="red"] { --c: var(--danger); }

#infoFields { display: flex; flex-direction: column; gap: 18px; }
.form-group h3 { margin-bottom: 10px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }

@media (max-width: 820px) {
  .car-overview { grid-template-columns: 1fr; }
}

/* Settings */
.settings { padding: 4px 20px; margin-bottom: 8px; }
.setting-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.section-head .sm-btn { margin-left: auto; padding: 6px 12px; font-size: .85rem; }
.version { text-align: center; padding: 24px 0 40px; }

.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.user-row + .user-row { border-top: 1px solid var(--border); }
.user-row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.user-avatar {
  display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700;
}

/* Login */
.logged-out .auth-only { display: none; }
.login { display: grid; place-items: center; min-height: calc(100dvh - 61px); padding: 32px 0; }
.login-card { display: flex; flex-direction: column; gap: 16px; width: min(380px, 100%); padding: 32px 28px; }
.login-card h1.logo-lg { font-size: 3rem; margin-bottom: 10px; letter-spacing: .01em; }
.lang-switch { display: flex; justify-content: center; gap: 4px; }
.lang-switch button {
  padding: 4px 10px; border: 0; border-radius: 8px; background: none;
  color: var(--muted); font-size: .8rem; font-weight: 600; letter-spacing: .04em; cursor: pointer;
}
.lang-switch button:hover { color: var(--text); }
.lang-switch button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; justify-content: center; margin-top: 4px; }

.form-error {
  margin: 0; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger);
  font-size: .88rem; font-weight: 500;
}
.form-error[hidden], .field[hidden] { display: none; }
.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 16px 24px;
  flex-wrap: wrap; padding: 18px 0;
}
.setting + .setting { border-top: 1px solid var(--border); }
.setting h3 { font-size: 1rem; margin-bottom: 2px; }
.segmented { display: inline-flex; padding: 4px; gap: 4px; border-radius: 12px; background: var(--surface-2); }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; padding: 7px 16px; border-radius: 9px;
  font-weight: 600; font-size: .9rem; color: var(--muted); transition: background .15s, color .15s;
}
.segmented label:hover span { color: var(--text); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Toolbar */
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: .85rem; font-weight: 500; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.search {
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  color: var(--muted); flex: 0 1 240px;
}
.search input { border: 0; background: transparent; padding: 9px 0; outline: none; width: 100%; color: var(--text); }
.search:focus-within { border-color: var(--accent); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 40px; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 11px; top: 8px; bottom: 40px;
  width: 2px; background: var(--border); border-radius: 2px;
}
.timeline .year { font-weight: 700; font-size: .85rem; color: var(--muted); padding: 8px 0 8px 36px; }
.entry { position: relative; padding-left: 36px; margin-bottom: 12px; }
.entry-dot {
  position: absolute; left: 5px; top: 20px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--c);
}
.entry-body { padding: 14px 16px; }
.entry-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .85rem; margin-bottom: 6px; }
.entry-head time { font-weight: 500; }
.entry-cost { margin-left: auto; font-weight: 700; font-size: .95rem; }
.entry h4 { font-size: 1rem; font-weight: 600; }
.entry .muted.small { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.entry .muted.small .ic { width: 14px; height: 14px; }
.entry-notes { margin: 8px 0 0; white-space: pre-wrap; font-size: .9rem; color: var(--muted); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.att {
  width: 64px; height: 64px; padding: 0; overflow: hidden; cursor: zoom-in;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
}
.att img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att.file {
  display: inline-flex; align-items: center; gap: 6px; width: auto; max-width: 220px;
  padding: 0 12px; font-size: .82rem; color: var(--text); cursor: pointer;
}
.att.file:hover { border-color: var(--accent); }
.att.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-actions { display: flex; gap: 2px; justify-content: flex-end; margin: 4px -8px -8px 0; opacity: .6; transition: opacity .15s; }
.entry:hover .entry-actions, .entry-actions:focus-within { opacity: 1; }

[data-color="blue"]   { --c: var(--c-blue); }
[data-color="orange"] { --c: var(--c-orange); }
[data-color="green"]  { --c: var(--c-green); }
[data-color="purple"] { --c: var(--c-purple); }
[data-color="gray"]   { --c: var(--c-gray); }

.badge {
  padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent);
}

/* Empty state */
.empty { text-align: center; padding: 56px 24px; }
.empty .avatar { margin: 0 auto 16px; width: 64px; height: 64px; border-radius: 18px; }
.empty .avatar .ic { width: 30px; height: 30px; }
.empty h3 { margin-bottom: 4px; }
.empty .btn { margin-top: 20px; }

/* Dialog */
dialog {
  width: min(520px, calc(100% - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--border); border-radius: 20px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgb(0 0 0 / .25);
}
dialog[open] { animation: pop .18s ease-out; }
dialog::backdrop { background: rgb(15 23 42 / .45); backdrop-filter: blur(3px); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

dialog form { display: flex; flex-direction: column; gap: 14px; padding: 24px; }
dialog h2 { font-size: 1.2rem; margin-bottom: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-weight: 400; font-size: .95rem; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.dialog-actions .btn:disabled { opacity: .6; cursor: progress; }

.file-btn { align-self: flex-start; padding: 8px 14px; font-size: .88rem; color: var(--text); }
.att-editor { display: flex; flex-direction: column; gap: 6px; }
.att-editor:empty { display: none; }
.draft-item {
  display: flex; align-items: center; gap: 10px; padding: 6px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  font-weight: 400; color: var(--text);
}
.draft-item img, .draft-item > .ic { width: 40px; height: 40px; border-radius: 7px; object-fit: cover; flex-shrink: 0; }
.draft-item > .ic { padding: 9px; background: var(--surface); color: var(--muted); }
.draft-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }

/* Lightbox */
dialog.lightbox {
  width: 100%; height: 100%; max-width: 100%; max-height: 100%;
  border: 0; border-radius: 0; background: transparent; box-shadow: none;
}
dialog.lightbox[open] { display: flex; align-items: center; justify-content: center; }
.lightbox::backdrop { background: rgb(0 0 0 / .88); backdrop-filter: none; }
.lightbox img { max-width: calc(100% - 32px); max-height: calc(100% - 120px); border-radius: 12px; object-fit: contain; }
.lb-btn, .lb-btn:hover { position: absolute; width: 44px; height: 44px; color: #fff; background: rgb(255 255 255 / .12); }
.lb-btn:hover { background: rgb(255 255 255 / .24); }
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; top: 50%; translate: 0 -50%; }
.lb-next { right: 16px; top: 50%; translate: 0 -50%; }
.lightbox.single .lb-prev, .lightbox.single .lb-next { display: none; }
#lbCaption { position: absolute; left: 0; right: 0; bottom: 20px; margin: 0; text-align: center; color: rgb(255 255 255 / .8); font-size: .9rem; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px;
  border-radius: 12px; font-weight: 500; font-size: .9rem;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  h1 { font-size: 1.4rem; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .row { grid-template-columns: 1fr; }
  .search { flex: 1 1 100%; }
  .hero-actions { width: 100%; }
  .hero-actions .btn { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
