/* ============ EFI Garage design system ============ */
/* Two themes, LIGHT by default. web/lib/theme.ts sets data-theme="light"|"dark"
   on <html> at boot. Bare :root carries the light palette so the app is light
   even before the script runs. Never hardcode a hex outside these blocks —
   components and charts read the tokens (charts via token() from lib/theme). */

:root,
:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f6f7f9;              /* app canvas — near-white, not pure white */
  --bg-elev: #ffffff;         /* sidebar, topbar, chart plates */
  --surface: #ffffff;         /* cards, modals */
  --surface-2: #f1f3f6;       /* recessed fills, default button, badges */
  --border: #e2e6ec;          /* soft gray hairline */
  --border-strong: #c7d0dc;
  --text: #16202c;            /* dark slate */
  --text-muted: #4a5768;      /* 7.4:1 on white */
  --text-faint: #6b7787;      /* 4.6:1 on white — table heads stay readable */

  --accent: #0f766e;          /* teal-700 — 5.5:1 on white, works as text and as fill */
  --accent-dim: #0d9488;      /* mid teal for hover/focus borders (3.4:1 — UI, not text) */
  --accent-hover: #0b5f57;    /* primary button hover: darkens, not lightens */
  --accent-ink: #ffffff;      /* text on an accent fill */
  --accent-soft: rgba(15, 118, 110, 0.1);

  --amber: #b45309;           /* warnings, knock, highlights — 5.0:1 */
  --red: #c62348;             /* 5.6:1 */
  --blue: #1d6fd0;            /* 5.0:1 */
  --green: #15803d;           /* 5.0:1 */
  --purple: #7c3aed;          /* 5.7:1 */
  --amber-soft: rgba(180, 83, 9, 0.11);
  --red-soft: rgba(198, 35, 72, 0.1);
  --red-border: rgba(198, 35, 72, 0.35);
  --blue-soft: rgba(29, 111, 208, 0.1);

  --hover: #eceff4;           /* row/nav hover on white chrome */
  --row-hover: rgba(15, 23, 42, 0.035);
  --field-bg: #ffffff;
  --grid: rgba(22, 32, 44, 0.12);   /* chart gridlines */
  --scrim: rgba(23, 32, 44, 0.32);  /* modal backdrop */
  --glow: rgba(13, 148, 136, 0.13);

  --shadow: 0 6px 20px rgba(16, 32, 52, 0.1), 0 1px 2px rgba(16, 32, 52, 0.06);
  --shadow-card: 0 1px 2px rgba(16, 32, 52, 0.05);

  /* Car photo placeholders — tinted washes, light enough to sit on a white card. */
  --car-wash-0: linear-gradient(135deg, #d8ece7 0%, #eef4f7 100%);
  --car-wash-1: linear-gradient(135deg, #dde3f5 0%, #eef1f7 100%);
  --car-wash-2: linear-gradient(135deg, #e7ddf3 0%, #f1eef7 100%);
  --car-wash-3: linear-gradient(135deg, #f4e6cf 0%, #f6f2ea 100%);
  --car-wash-4: linear-gradient(135deg, #d6e8f2 0%, #e6f2ef 100%);
  --car-wash-5: linear-gradient(135deg, #f5dde7 0%, #f6eef2 100%);

  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --radius: 10px;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b0e13;
  --bg-elev: #10141c;
  --surface: #141a24;
  --surface-2: #1a2230;
  --border: #232d3d;
  --border-strong: #31405a;
  --text: #e8eef5;
  --text-muted: #93a1b5;
  --text-faint: #5d6b80;

  --accent: #2dd4bf;
  --accent-dim: #14b8a6;
  --accent-hover: #43e0cb;
  --accent-ink: #06281f;
  --accent-soft: rgba(45, 212, 191, 0.12);

  --amber: #f5a623;
  --red: #f4577b;
  --blue: #5aa9fa;
  --green: #4ade80;
  --purple: #b58cf7;
  --amber-soft: rgba(245, 166, 35, 0.12);
  --red-soft: rgba(244, 87, 123, 0.12);
  --red-border: rgba(244, 87, 123, 0.4);
  --blue-soft: rgba(90, 169, 250, 0.12);

  --hover: #141a24;
  --row-hover: rgba(255, 255, 255, 0.03);
  --field-bg: #10141c;
  --grid: rgba(147, 161, 181, 0.15);
  --scrim: rgba(4, 6, 10, 0.7);
  --glow: rgba(45, 212, 191, 0.14);

  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-card: none;

  --car-wash-0: linear-gradient(135deg, #12403a 0%, #0e2233 100%);
  --car-wash-1: linear-gradient(135deg, #1c2a52 0%, #101722 100%);
  --car-wash-2: linear-gradient(135deg, #35244d 0%, #131a26 100%);
  --car-wash-3: linear-gradient(135deg, #4a3418 0%, #141a24 100%);
  --car-wash-4: linear-gradient(135deg, #143c52 0%, #0f2a26 100%);
  --car-wash-5: linear-gradient(135deg, #451f33 0%, #141a24 100%);
}

/* Quick cross-fade while toggling — added by setTheme() for ~200ms only, so
   dense tables aren't carrying a transition on every cell all the time. */
:root.theme-transition,
:root.theme-transition *,
:root.theme-transition *::before,
:root.theme-transition *::after {
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease,
    box-shadow 160ms ease, fill 160ms ease, stroke 160ms ease !important;
  transition-delay: 0s !important;
}
@media (prefers-reduced-motion: reduce) {
  :root.theme-transition,
  :root.theme-transition *,
  :root.theme-transition *::before,
  :root.theme-transition *::after { transition: none !important; }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body, .sidebar, .topbar, .card, .chart-box, .modal, .toast, .badge,
.input, .select, .textarea, .empty, .dropzone, .icon-btn {
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 0.5em; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 26px; } h2 { font-size: 20px; } h3 { font-size: 16px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }

.boot-splash { display: grid; place-items: center; height: 100vh; background: var(--bg); }
.boot-logo { font-size: 28px; font-weight: 800; letter-spacing: 0.04em; color: var(--text); }
.boot-logo span { color: var(--accent); }

/* ---- App layout ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 228px; flex-shrink: 0; background: var(--bg-elev);
  border-right: 1px solid var(--border); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .logo {
  font-size: 19px; font-weight: 800; letter-spacing: 0.04em; padding: 4px 10px 16px;
  color: var(--text); display: block;
}
.sidebar .logo span { color: var(--accent); }
.sidebar .nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); padding: 14px 10px 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-muted); font-weight: 500; font-size: 14px;
}
.nav-link:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link .ico { width: 18px; text-align: center; }
.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--bg-elev);
  position: sticky; top: 0; z-index: 40;
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.content { padding: 24px; max-width: 1400px; margin: 0 auto; }
.content.narrow { max-width: 860px; }

/* ---- Components ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-card);
}
.card.pad-lg { padding: 26px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font-weight: 600; font-size: 13.5px; cursor: pointer;
  font-family: var(--sans); transition: all 0.12s;
}
.btn:hover { border-color: var(--accent-dim); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--red); border-color: var(--red-border); }
.btn.sm { padding: 5px 11px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Square icon button (theme toggle etc.) */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text-muted); cursor: pointer; line-height: 1;
  font-family: var(--sans); font-size: 15px;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent-dim); }
.icon-btn svg { display: block; }
.btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, .nav-link:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--field-bg); color: var(--text); font-family: var(--sans); font-size: 14px;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent-dim); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }

.badge {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.amber { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.badge.red { background: var(--red-soft); color: var(--red); border-color: transparent; }
.badge.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 8px 12px; color: var(--text-faint); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table tr:hover td { background: var(--row-hover); }
.table .num { font-family: var(--mono); font-size: 12.5px; }

.stat-tile { padding: 16px 18px; }
.stat-tile .stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.stat-tile .stat-value { font-size: 26px; font-weight: 700; font-family: var(--mono); margin-top: 2px; }
.stat-tile .stat-sub { font-size: 12px; color: var(--text-faint); }

.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); object-fit: cover; }
.avatar.lg { width: 72px; height: 72px; }
.avatar-fallback {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px;
}

.empty {
  text-align: center; padding: 48px 24px; color: var(--text-muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty .empty-icon { font-size: 34px; margin-bottom: 10px; }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 11px 16px; box-shadow: var(--shadow); font-size: 13.5px; animation: slide-in 0.18s ease;
}
.toast.error { border-color: var(--red); }
.toast.success { border-color: var(--accent-dim); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-backdrop {
  position: fixed; inset: 0; background: var(--scrim); z-index: 90;
  display: grid; place-items: center; padding: 24px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px;
  padding: 24px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal.wide { max-width: 780px; }
/* Tuning maps are wide by nature — give a 22-column table the room to render at
   full cell size instead of scrolling from the first column. */
.modal.xwide { max-width: min(1480px, 96vw); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab {
  padding: 9px 16px; font-weight: 600; font-size: 13.5px; color: var(--text-muted);
  border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; font-family: var(--sans);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--text-muted); font-size: 13.5px; margin-top: 3px; }

.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 40px;
  text-align: center; color: var(--text-muted); cursor: pointer; transition: all 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent-dim); background: var(--accent-soft); color: var(--text); }

.spinner {
  width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Chart containers */
.chart-box {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; overflow-x: auto; box-shadow: var(--shadow-card);
}
.chart-box svg { max-width: 100%; height: auto; }

/* Landing */
.landing-nav { display: flex; align-items: center; justify-content: space-between; padding: 18px 32px; max-width: 1200px; margin: 0 auto; }
.hero { text-align: center; padding: 90px 24px 60px; max-width: 900px; margin: 0 auto; }
.hero h1 { font-size: 46px; line-height: 1.12; letter-spacing: -0.02em; }
.hero .tagline { font-size: 18px; color: var(--text-muted); max-width: 640px; margin: 18px auto 30px; }
.hero-glow {
  position: absolute; top: -120px; left: 50%; transform: translateX(-50%);
  width: 700px; height: 400px; pointer-events: none;
  background: radial-gradient(ellipse, var(--glow), transparent 65%);
}

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
  .hero h1 { font-size: 32px; }
}
