:root {
  --bg: #0f1216;
  --bg-elev: #171c22;
  --bg-elev2: #1e242c;
  --border: #2a323c;
  --text: #e7ecf1;
  --muted: #93a1b0;
  --accent: #ff6a2b;         /* moto-orange */
  --accent-2: #ffa049;
  --ok: #35c46e;
  --warn: #ffc93c;
  --danger: #ff5a52;
  --radius: 14px;
  --shadow: 0 6px 22px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent-2); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1rem; padding-top: calc(.7rem + env(safe-area-inset-top));
  background: rgba(15,18,22,.92);
  backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: .3px; }
/* The logo tile stands in for the capital "D" so the wordmark reads "Digilog". */
.brand-logo { height: 1.7em; width: 1.7em; border-radius: 5px; margin-right: 1px; display: block; }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.topbar-user { color: var(--muted); font-size: .85rem; }

.container { max-width: 760px; margin: 0 auto; padding: 1rem 1rem 4rem; }

/* Buttons */
button { font-family: inherit; cursor: pointer; }
.btn-primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #241100; border: none; border-radius: 11px;
  padding: .7rem 1.1rem; font-weight: 700; font-size: .95rem;
  box-shadow: 0 3px 12px rgba(255,106,43,.32);
}
.btn-primary.big { width: 100%; padding: .9rem; font-size: 1.02rem; }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost {
  background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .9rem; font-size: .88rem;
}
.link-btn { background: none; border: none; color: var(--accent-2); padding: 0; font-size: .85rem; }
.link-btn.danger { color: var(--danger); }

/* Flash */
.flash-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.flash { padding: .7rem .9rem; border-radius: 10px; font-size: .9rem; border: 1px solid var(--border); }
.flash-ok { background: rgba(53,196,110,.12); border-color: rgba(53,196,110,.4); }
.flash-error { background: rgba(255,90,82,.12); border-color: rgba(255,90,82,.4); }

/* Page head */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; }
.back-link { display: inline-block; margin-bottom: .8rem; color: var(--muted); font-size: .9rem; }

/* Empty state */
.empty { text-align: center; padding: 3rem 1rem; }
.empty-icon { font-size: 3rem; }
.empty p { margin: .6rem 0 1rem; }

/* Vehicle grid */
.vehicle-grid { display: grid; grid-template-columns: 1fr; gap: .9rem; }
@media (min-width: 620px) { .vehicle-grid { grid-template-columns: 1fr 1fr; } }
.vehicle-card {
  display: block; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; color: var(--text); box-shadow: var(--shadow);
  transition: border-color .15s, transform .1s;
}
.vehicle-card:active { transform: scale(.99); }
.vehicle-card-top { display: flex; align-items: center; gap: .7rem; }
.vehicle-emoji { font-size: 1.7rem; }
.vehicle-name { display: flex; flex-direction: column; }
.vehicle-name strong { font-size: 1.08rem; }
.vehicle-meta { display: flex; gap: .5rem; flex-wrap: wrap; margin: .7rem 0 .2rem; }
.chip { background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 999px; padding: .18rem .6rem; font-size: .78rem; color: var(--muted); }
.alert-row { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.last-line { margin-top: .5rem; }

.badge { border-radius: 999px; padding: .2rem .55rem; font-size: .74rem; font-weight: 700; border: 1px solid transparent; white-space: nowrap; }
.badge-ok { background: rgba(53,196,110,.18); color: #57dc90; border-color: rgba(53,196,110,.7); }
.badge-snart { background: rgba(255,201,60,.16); color: var(--warn); border-color: rgba(255,201,60,.55); }
.badge-forfalt { background: rgba(255,90,82,.18); color: var(--danger); border-color: rgba(255,90,82,.6); }
.badge-ukjent { background: var(--bg-elev2); color: var(--muted); border-color: var(--border); }

/* Vehicle detail */
.veh-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.stat-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
.stat { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: .7rem; text-align: center; }
.stat-label { display: block; font-size: .72rem; color: var(--muted); }
.stat-value { display: block; font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .link-btn { margin-top: .2rem; }

.action-bar { display: flex; gap: .6rem; margin-bottom: 1.2rem; align-items: center; }
.action-bar .btn-primary.big { flex: 1; }

.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1.1rem; box-shadow: var(--shadow); }

/* Due list */
.due-list { display: flex; flex-direction: column; gap: .55rem; }
.due-item { border: 1px solid var(--border); border-radius: 11px; padding: .6rem .75rem; background: var(--bg-elev2); }
.due-item.due-forfalt { border-color: rgba(255,90,82,.5); }
.due-item.due-snart { border-color: rgba(255,201,60,.45); }
.due-main { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.due-name { font-weight: 600; }
/* Rounded pill badge in the service overview (was an unstyled square). */
.due-badge { border-radius: 999px; padding: .24rem .8rem; font-size: .74rem; font-weight: 700;
  border: 1.5px solid transparent; white-space: nowrap; letter-spacing: .02em; line-height: 1.35; }
.due-sub { margin-top: .2rem; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item { display: flex; gap: .7rem; padding: .2rem 0; }
.tl-item:not(:last-child) .tl-dot::after {
  content: ""; position: absolute; left: 50%; top: 30px; bottom: -8px; width: 2px; background: var(--border); transform: translateX(-50%);
}
.tl-dot { position: relative; flex: 0 0 30px; height: 30px; border-radius: 50%; background: var(--bg-elev2); border: 1px solid var(--border); display: grid; place-items: center; font-size: .95rem; }
.tl-body { flex: 1; padding-bottom: 1rem; min-width: 0; }
.tl-top { display: flex; justify-content: space-between; gap: .6rem; align-items: baseline; }
.tl-date { color: var(--muted); font-size: .8rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tl-notes { margin-top: .3rem; font-size: .9rem; color: var(--text); white-space: pre-wrap; word-wrap: break-word; }
.tl-actions { display: flex; gap: 1rem; margin-top: .4rem; align-items: center; }
.tl-actions form { display: inline; }

.archive-form { text-align: center; margin: 1.5rem 0; }
.interval-list { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .8rem; display: flex; flex-direction: column; gap: .4rem; }
.interval-row { display: flex; justify-content: space-between; gap: .5rem; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: .8rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font-family: inherit; font-size: 1rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: .65rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,106,43,.18); }
textarea { resize: vertical; }
/* iOS renders native chrome on date/number inputs (a nested, taller inner box) that
   made fields look like they overlapped. Flatten it and force a consistent height. */
input:not([type="checkbox"]):not([type="file"]) { -webkit-appearance: none; appearance: none; }
.row2 input, .row2 select { min-height: 2.9rem; }
input[type="date"] { text-align: left; min-height: 2.9rem; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="date"]::-webkit-datetime-edit { padding: 0; }

/* Auth */
.auth-wrap { min-height: 70vh; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 380px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 18px; padding: 1.6rem; box-shadow: var(--shadow); text-align: center; }
.auth-logo { font-size: 2.6rem; }
.auth-logo-img { width: 72px; height: 72px; border-radius: 16px; display: block; margin: 0 auto; box-shadow: 0 4px 16px rgba(255,106,43,.35); }
.auth-card h1 { margin: .3rem 0; }
.auth-card .stack { margin-top: 1.2rem; text-align: left; }
.auth-card .btn-primary { width: 100%; margin-top: .3rem; }
.auth-alt { margin-top: 1rem; font-size: .9rem; color: var(--muted); }

/* Dialogs */
.dialog-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 50; padding: 0; }
/* The hidden attribute must win over display:flex, or dialogs never close / show on load. */
.dialog-backdrop[hidden] { display: none !important; }
@media (min-width: 620px) { .dialog-backdrop { align-items: center; padding: 1rem; } }
.dialog {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 18px 18px 0 0; width: 100%; max-width: 480px; overflow-y: auto;
  /* Cap the height so a tall bottom-sheet never slides up under the iPhone status
     bar (where the ✕ would collide with the battery/clock). */
  max-height: 92vh;
  max-height: calc(100dvh - env(safe-area-inset-top) - 0.5rem);
  padding: 1.1rem 1.1rem calc(1.4rem + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(0,0,0,.5);
  animation: slideUp .22s ease;
}
@media (min-width: 620px) { .dialog { border-radius: 18px; animation: pop .18s ease; max-height: 90vh; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.dialog-head h2 { margin: 0; }

/* ---- Vehicle photos ---- */
.vehicle-photo { margin: -1rem -1rem .8rem; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; aspect-ratio: 16/9; background: var(--bg-elev2); }
.vehicle-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.veh-photo { position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem; background: var(--bg-elev2); aspect-ratio: 16/9; }
.veh-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.veh-photo-edit { position: absolute; right: .6rem; bottom: .6rem; background: rgba(15,18,22,.82); }
.veh-header-btns { display: flex; gap: .5rem; flex-shrink: 0; }

/* ---- Image picker ---- */
.imgpick-label { font-size: .85rem; color: var(--muted); font-weight: 600; margin-top: .2rem; }
.imgpick { display: flex; flex-direction: column; gap: .6rem; border: 1px dashed var(--border); border-radius: 12px; padding: .8rem; }
.imgpick-searchrow { display: flex; gap: .5rem; }
.imgpick-searchrow .imgpick-search { flex: 1; }
.imgpick-searchrow .btn-ghost { flex-shrink: 0; }
.imgpick-results { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.imgpick-results:empty { display: none; }
.imgpick-thumb { padding: 0; border: 2px solid var(--border); background: var(--bg-elev2); border-radius: 10px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.imgpick-thumb img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.imgpick-thumb span { font-size: .62rem; color: var(--muted); padding: .2rem .3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imgpick-thumb.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,106,43,.3); }
.imgpick-preview-wrap:has(img[hidden]) { display: none; }
.imgpick-preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: 10px; }
.imgpick-upload { font-size: .82rem; }

/* Vehicle spec chips (tyre size / pressure / power) */
.spec-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; align-items: center; }
.spec-chip { background: var(--bg-elev2); border-color: var(--border); color: var(--text); font-weight: 600; }
.spec-fetch { font-size: .78rem; }

/* Service receipt link + edit-dialog checkbox row */
.tl-receipt { display: inline-flex; align-items: center; gap: .3rem; margin-top: .4rem; font-size: .85rem;
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 8px; padding: .25rem .6rem; }
.checkbox-row { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; color: var(--text); }
.checkbox-row input { width: auto; }

/* Full-screen in-app receipt viewer (so it's always closeable in a standalone PWA) */
.receipt-viewer { z-index: 60; align-items: stretch; padding: 0; }
@media (min-width: 620px) { .receipt-viewer { align-items: center; padding: 1rem; } }
.receipt-modal { display: flex; flex-direction: column; width: 100%; height: 100%; max-width: 900px;
  background: var(--bg-elev); overflow: hidden; }
@media (min-width: 620px) { .receipt-modal { height: 90vh; border-radius: 16px; border: 1px solid var(--border); } }
.receipt-bar { display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: calc(.6rem + env(safe-area-inset-top)) .8rem .6rem; border-bottom: 1px solid var(--border); }
.receipt-title { font-weight: 700; }
.receipt-bar-btns { display: flex; gap: .5rem; }
.receipt-content { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center;
  background: #0b0d10; padding: .5rem; padding-bottom: calc(.5rem + env(safe-area-inset-bottom)); }
.rv-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.rv-frame { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
