:root {
  --bg: #14181D;
  --surface: #1B2027;
  --surface-2: #232A32;
  --border: #2E3641;
  --accent: #E8A23D;
  --accent-dim: #6B5330;
  --accent-2: #4FB6A8;
  --accent-2-dim: #2C4E49;
  --danger: #D9564A;
  --text: #EDEFF1;
  --text-muted: #8B94A1;
  --text-faint: #5C6572;
  --radius: 14px;
  --font-display: 'IBM Plex Mono', ui-monospace, monospace;
  --font-body: 'Manrope', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select {
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
}

a { color: var(--accent); }

::selection { background: var(--accent-dim); color: var(--text); }

/* ---------- Focus visibility ---------- */
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ================= AUTH SCREEN ================= */
.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% -10%, rgba(232,162,61,0.08), transparent 45%),
    radial-gradient(circle at 100% 110%, rgba(79,182,168,0.08), transparent 45%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 36px;
}

.brand-mark {
  font-size: 34px;
  color: var(--accent);
  line-height: 1;
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.5px;
}

.brand-text p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.auth-tabs {
  display: flex;
  background: var(--surface);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 0;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}

.auth-tab.active {
  background: var(--accent);
  color: #1A140A;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form label,
.sheet-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.auth-form input,
.sheet-form input,
.sheet-form select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
}

.auth-form input:focus,
.sheet-form input:focus,
.sheet-form select:focus {
  border-color: var(--accent);
}

#invite-field { display: none; }

.form-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
  margin: 0;
}

.btn-primary {
  background: var(--accent);
  color: #1A140A;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-weight: 700;
  font-size: 15px;
  margin-top: 4px;
}

.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 13px;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 14px;
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  padding: 4px;
}

/* ================= APP SHELL ================= */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.vehicle-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font-display);
  padding: 6px 0;
}

.vehicle-switch .chevron {
  color: var(--text-muted);
  font-size: 14px;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 96px);
}

.tab-panel { animation: fadein 0.18s ease; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Odometer (signature element) ---------- */
.odometer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  text-align: center;
  margin-bottom: 16px;
}

.odometer-label {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.odometer {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 10px;
}

.odometer .digit {
  background: #0F1216;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 30px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(232,162,61,0.45);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.6);
}

.odometer .digit.sep {
  background: transparent;
  border: none;
  box-shadow: none;
  width: 12px;
  color: var(--text-faint);
  text-shadow: none;
  font-size: 16px;
}

/* ---------- Gauge grid ---------- */
.gauge-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.gauge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  position: relative;
  overflow: hidden;
}

.gauge-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
}

.gauge-card.accent-teal::before { background: var(--accent-2); }

.gauge-icon { font-size: 18px; opacity: 0.85; margin-bottom: 8px; }

.gauge-value {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.gauge-card.accent-teal .gauge-value { color: var(--accent-2); }

.gauge-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ---------- Alert card ---------- */
.alert-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(90deg, rgba(217,86,74,0.12), transparent);
  border: 1px solid rgba(217,86,74,0.35);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.alert-icon { font-size: 20px; }
.alert-title { font-weight: 700; font-size: 14px; }
.alert-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---------- Panels / charts ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.panel h3 {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 90px;
}

.bar-chart .bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 4px;
}

.bar-chart .bar {
  width: 100%;
  max-width: 22px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
}

.bar-chart.accent-teal .bar { background: var(--accent-2); }

.bar-chart .bar-month {
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
}

.stat-row {
  display: flex;
  justify-content: space-between;
}

.stat-row > div { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.stat-val { font-family: var(--font-display); font-size: 17px; font-weight: 600; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-glyph { font-size: 40px; color: var(--accent); margin: 0 0 12px; }
.empty-state h2 { color: var(--text); font-size: 18px; margin: 0 0 8px; }
.empty-state p { font-size: 14px; margin: 0 0 20px; }
.empty-state .btn-primary { display: inline-block; padding: 12px 28px; }

/* ---------- Section head / lists ---------- */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-head h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0;
}

.btn-fab-inline {
  background: var(--accent);
  color: #1A140A;
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 700;
  font-size: 13px;
}

.record-list { display: flex; flex-direction: column; gap: 10px; }

.record-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.record-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.record-title { font-weight: 700; font-size: 14.5px; }
.record-sub { font-size: 12px; color: var(--text-muted); }
.record-sub b { color: var(--text); font-weight: 600; }

.record-side { text-align: right; flex-shrink: 0; }
.record-value { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: var(--accent); }
.record-tag { font-size: 10px; color: var(--accent-2); text-transform: uppercase; letter-spacing: 0.4px; margin-top: 3px; }

.record-empty {
  text-align: center;
  color: var(--text-faint);
  padding: 40px 20px;
  font-size: 14px;
}

/* ---------- Vehicle detail ---------- */
.vehicle-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}

.vehicle-photo {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}

.vehicle-photo-placeholder {
  width: 100%;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: var(--text-faint);
  background: var(--surface-2);
}

.vehicle-info { padding: 16px; }
.vehicle-info h3 { margin: 0 0 4px; font-family: var(--font-display); font-size: 19px; }
.vehicle-info .plate {
  display: inline-block;
  font-family: var(--font-display);
  background: #0F1216;
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.vehicle-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.vehicle-meta-grid div { font-size: 13px; }
.vehicle-meta-grid .m-label { color: var(--text-faint); font-size: 11px; text-transform: uppercase; display: block; }

.vehicle-actions { display: flex; gap: 10px; margin-top: 16px; }
.vehicle-actions button { flex: 1; }

/* ================= TAB BAR ================= */
.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 6px calc(env(safe-area-inset-bottom) + 8px);
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 700;
  padding: 6px 0;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.tab-btn span { font-size: 18px; }

.tab-btn.active { color: var(--accent); }

/* ================= SHEETS ================= */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10,12,15,0.6);
  z-index: 20;
}

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px);
  z-index: 21;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.4);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 6px auto 14px;
}

.sheet h3 {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0 0 16px;
}

.sheet-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.checkbox-row {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}

.checkbox-row input { width: 18px; height: 18px; }

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.picker-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.picker-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.picker-item.active { border-color: var(--accent); }
.picker-item-name { font-weight: 700; font-size: 14.5px; }
.picker-item-sub { font-size: 12px; color: var(--text-muted); }

/* ================= TOAST ================= */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 30;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.toast.danger { border-color: var(--danger); color: var(--danger); }

/* ================= RESPONSIVE (wider viewports) ================= */
@media (min-width: 640px) {
  .app-shell { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .tabbar, .topbar { max-width: 480px; margin: 0 auto; left: 0; right: 0; }
  .sheet { max-width: 480px; margin: 0 auto; }
}
