:root {
  --bg: #10161c;
  --bg-card: #161d25;
  --text: #f2f4f7;
  --text-dim: #9aa3b2;
  --accent: #3aa6ff;
  --accent-dim: #1f4a70;
  --green: #33c481;
  --amber: #d99a2b;
  --red: #e5484d;
  --border: #262e38;
  --nav-height: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- App shell ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; }
.btn-icon {
  background: none; border: none; font-size: 19px; line-height: 1; padding: 6px;
  cursor: pointer; border-radius: 8px; color: var(--text);
}
.btn-icon:active { background: var(--bg); }

.view {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.view.active { display: flex; }

.detail-scroll {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 0 14px 24px;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Bottom navigation ---------- */
.bottom-nav {
  display: flex;
  flex-shrink: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px 6px;
  min-height: var(--nav-height);
  font-family: inherit;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 21px; line-height: 1; }
.nav-label { font-size: 10px; font-weight: 600; letter-spacing: 0.01em; }

/* ---------- Floating add button ---------- */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 14px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  font-weight: 400;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.45);
  z-index: 500;
  padding: 0;
}

.fab-menu-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.fab-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 12px 6px;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  font-family: inherit;
}
.fab-menu-item:last-child { border-bottom: none; }
.fab-menu-icon { font-size: 19px; width: 24px; text-align: center; }

/* ---------- Buttons ---------- */
.controls {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.btn {
  flex: 1;
  min-width: 100px;
  border: none;
  border-radius: 12px;
  padding: 16px 10px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  font-family: inherit;
}
.btn-start { background: var(--accent); }
.btn-danger { background: var(--red); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  flex: 0 0 auto;
  padding: 10px 14px;
  font-size: 13px;
}
.btn-sm { padding: 6px 12px; font-size: 12px; flex: none; }
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  padding: 4px 0;
  font-family: inherit;
}

.hidden { display: none !important; }

/* ---------- Stat bar ---------- */
.stat-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
}
.stat-bar-3 { grid-template-columns: repeat(3, 1fr); }

.trend-chart { width: 100%; display: block; }
.trend-chart-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.stat {
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
}
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* ---------- Sub-tabs / filter chips ---------- */
.subtabs { display: flex; align-items: center; gap: 6px; padding: 10px 14px 0; flex-shrink: 0; flex-wrap: wrap; }
.subtab { background: transparent; border: 1px solid var(--border); color: var(--text-dim); padding: 6px 12px; border-radius: 20px; font-size: 13px; font-weight: 600; font-family: inherit; }
.subtab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.filter-chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 14px 0; flex-shrink: 0; }
.chip { flex-shrink: 0; background: var(--bg-card); border: 1px solid var(--border); color: var(--text-dim); padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; font-family: inherit; }
.chip-active { background: var(--accent); border-color: var(--accent); color: #fff; }

.category-select {
  margin: 0 0 10px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  width: 100%;
}

.cat-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 7px;
  vertical-align: middle;
}

.empty-msg { text-align: center; color: var(--text-dim); margin-top: 40px; }
.empty-msg-sm { color: var(--text-dim); font-size: 13px; }
.delight-banner { background: rgba(51,196,129,0.12); border: 1px solid rgba(51,196,129,0.3); border-radius: 12px; padding: 10px 14px; margin: 0 0 4px; }
.delight-banner p { margin: 2px 0; font-size: 13px; font-weight: 600; color: var(--green); }
.hint { font-size: 12px; color: var(--text-dim); }
.backup-overdue { color: var(--amber); font-weight: 600; }

.info-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 10px 0 4px;
}
.info-box b { color: var(--text); }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-card h3 { margin-top: 0; }
.modal-card label { display: block; font-size: 13px; color: var(--text-dim); margin: 12px 0 6px; }
.modal-card label:first-of-type { margin-top: 0; }
.modal-card input,
.modal-card select,
.modal-card textarea {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.modal-card textarea { resize: vertical; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.modal-card-lg { max-width: 460px; }

/* ---------- Section headers ---------- */
.section-header { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
.section-header h3 { margin: 0; font-size: 15px; }

/* ---------- File upload ---------- */
.btn-file-label { position: relative; cursor: pointer; display: inline-flex; align-items: center; }
.file-hidden { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.gallery-thumb-btn { padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: none; cursor: pointer; aspect-ratio: 1; }
.gallery-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.lightbox-img { width: 100%; border-radius: 10px; display: block; }

.photo-preview-row { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-thumb-wrap { position: relative; width: 72px; height: 72px; }
.photo-thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.photo-remove {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; border: none; background: var(--red); color: #fff;
  font-size: 13px; line-height: 1; padding: 0;
}

/* ---------- Bike / Garage ---------- */
.bike-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.bike-card-active { border-color: var(--accent); }
.bike-thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.bike-thumb-placeholder { display: flex; align-items: center; justify-content: center; font-size: 28px; background: var(--bg); }
.bike-card-info h3 { margin: 0 0 2px; font-size: 15px; }

.bike-header { text-align: center; padding: 16px 14px 4px; }
.bike-hero { width: 120px; height: 120px; border-radius: 16px; object-fit: cover; margin: 0 auto 10px; }
.bike-header h2 { margin: 0; font-size: 19px; }
.bike-header .hint { margin-top: 2px; }

.badge-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.badge { font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 20px; border: 1px solid var(--border); }
.badge-ok { background: rgba(51,196,129,0.15); color: var(--green); border-color: transparent; }
.badge-soon { background: rgba(217,154,43,0.18); color: var(--amber); border-color: transparent; }
.badge-overdue { background: rgba(229,72,77,0.18); color: var(--red); border-color: transparent; }
.badge-attention { background: rgba(58,166,255,0.18); color: var(--accent); border-color: transparent; }
.badge-tracked { background: var(--bg); color: var(--text-dim); }
.badge-done { background: rgba(51,196,129,0.15); color: var(--green); border-color: transparent; }

.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.info-grid > div { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; }

.vin-value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.02em; }

.pressure-row { display: flex; gap: 10px; }
.pressure-field { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.pressure-field label { font-size: 12px; color: var(--text-dim); }
.pressure-field input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text); font-size: 16px; }

/* ---------- Documents ---------- */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-row { display: flex; align-items: center; justify-content: space-between; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; gap: 10px; }
.doc-link { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; overflow: hidden; }
.doc-icon { font-size: 20px; flex-shrink: 0; }
.doc-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Maintenance ---------- */
.maint-cards { display: flex; flex-direction: column; gap: 10px; }
.maint-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.maint-card.status-ok { border-left-color: var(--green); }
.maint-card.status-soon { border-left-color: var(--amber); }
.maint-card.status-overdue { border-left-color: var(--red); }
.maint-card.status-done { border-left-color: var(--green); }

.maint-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 8px; }
.maint-label { font-weight: 700; font-size: 14px; }
.maint-badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 20px; flex-shrink: 0; }
.maint-badge.badge-ok { background: rgba(51,196,129,0.15); color: var(--green); }
.maint-badge.badge-soon { background: rgba(217,154,43,0.18); color: var(--amber); }
.maint-badge.badge-overdue { background: rgba(229,72,77,0.18); color: var(--red); }
.maint-badge.badge-tracked, .maint-badge.badge-done { background: var(--bg); color: var(--text-dim); }
.maint-msg { font-size: 13px; color: var(--text-dim); margin: 0 0 8px; line-height: 1.4; }

.maint-history { display: flex; flex-direction: column; gap: 8px; }
.maint-record { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.maint-record-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; gap: 8px; }
.maint-record-bottom { display: flex; gap: 12px; font-size: 12px; color: var(--text-dim); flex-wrap: wrap; }
.maint-record-notes { font-size: 13px; margin: 6px 0 0; color: var(--text-dim); }
.maint-record-photos { margin-top: 8px; }
.maint-record-actions { display: flex; gap: 14px; margin-top: 6px; }

.interval-details { margin-top: 14px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.interval-details summary { font-size: 13px; color: var(--text-dim); cursor: pointer; }
.interval-list { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.interval-row { display: grid; grid-template-columns: 1fr 64px 64px 64px; gap: 6px; align-items: center; font-size: 12px; }
.interval-row input, .interval-row select { padding: 6px; font-size: 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 100%; }

/* ---------- Dashboard ---------- */
.dash-section { margin-bottom: 6px; }
.streak-row { display: flex; gap: 10px; margin-bottom: 4px; }
.streak-card { flex: 1; background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; text-align: center; }
.streak-value { font-size: 24px; font-weight: 700; }
.streak-label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.bar-row { display: grid; grid-template-columns: 90px 1fr 64px; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px; }
.bar-label { color: var(--text-dim); }
.bar-track { background: var(--bg-card); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 6px; min-width: 2px; }
.bar-value { text-align: right; font-weight: 600; }

.odo-row { display: flex; justify-content: space-between; align-items: center; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; font-size: 14px; }

/* ---------- Ownership report (full-screen overlay, printable) ---------- */
#report-view {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 900;
  overflow-y: auto;
  padding: 12px 16px 0;
}
.report-toolbar {
  display: flex; gap: 8px; margin-top: 14px;
  position: sticky; bottom: 0;
  background: var(--bg); border-top: 1px solid var(--border);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}
.report-page h2 { margin: 6px 0 2px; }
.report-page h3 { margin: 20px 0 6px; font-size: 15px; }
.report-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.report-table td, .report-table th { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
.report-table th { color: var(--text-dim); font-weight: 600; }

@media print {
  .topbar, .bottom-nav, .fab, .view, .modal, .report-toolbar { display: none !important; }
  #report-view { position: static; overflow: visible; background: #fff; color: #000; padding: 0; }
  .report-table td, .report-table th { border-bottom: 1px solid #ccc; }
}
