:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c1f26;
  --muted: #6b7280;
  --border: #e3e5e9;
  --accent: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1e2128;
    --text: #e8e9ec;
    --muted: #9aa0aa;
    --border: #2c303a;
    --accent: #5b8def;
    --green: #34d399;
    --red: #f87171;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

main { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }

.nav-links { display: flex; gap: 18px; margin-right: auto; margin-left: 24px; }
.nav-links a { color: var(--muted); text-decoration: none; font-size: 14px; }
.nav-links a:hover { color: var(--text); }

.btn {
  background: var(--accent);
  color: white;
  padding: 8px 14px;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 14px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--red); }
.btn.small { padding: 5px 10px; font-size: 12px; }

.flash {
  background: #dbeafe;
  color: #1e3a8a;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  .flash { background: #1e3a5f; color: #bfdbfe; }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-card .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-card .value { font-size: 22px; font-weight: 700; }
.stat-card .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.value.positive { color: var(--green); }
.value.negative { color: var(--red); }

.status-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.status-col h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 10px;
}

.car-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  text-decoration: none;
  color: var(--text);
}
.car-card:hover { border-color: var(--accent); }
.car-card .name { font-weight: 600; font-size: 14px; }
.car-card .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }

.empty { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.card h2 { margin-top: 0; font-size: 16px; }

form .field { margin-bottom: 12px; }
form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
form input, form select, form textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
form textarea { min-height: 70px; resize: vertical; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.inline-form { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; flex: 1; min-width: 100px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
td.amount { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }

.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.header-row h1 { margin: 0; }

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--border);
}

.photo-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.photo-grid .photo { position: relative; }
.photo-grid img { width: 130px; height: 100px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.photo-grid form { position: absolute; top: 4px; right: 4px; }

.notes-text { white-space: pre-wrap; font-size: 14px; color: var(--text); }

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

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

/* Yes/No radio groups */
.yn-group { display: flex; align-items: center; gap: 14px; padding: 8px 0; }
.yn-group .yn-label { font-size: 13px; color: var(--muted); flex: 1; }
.yn-group .yn-options { display: flex; gap: 12px; }
.yn-group label.opt { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text); }
.yn-group input[type="radio"] { width: auto; }

fieldset.section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
fieldset.section legend { padding: 0 6px; font-weight: 600; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

.notice-card-list .notice-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.notice-card-list .notice-row:last-child { border-bottom: none; }

details summary { cursor: pointer; color: var(--accent); font-size: 13px; }
details[open] summary { margin-bottom: 4px; }

/* ---------- Printable Consumer Information Notice ---------- */
.cin-page {
  background: #fff;
  color: #111;
  max-width: 820px;
  margin: 0 auto 20px;
  padding: 28px 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
}
.cin-page h1 { font-size: 18px; margin: 0 0 2px; }
.cin-page .cin-sub { font-size: 12px; color: #555; margin-bottom: 14px; }
.cin-page .cin-box {
  border: 1px solid #999; border-radius: 4px; padding: 10px 12px; margin-bottom: 10px;
}
.cin-page .cin-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.cin-page .cin-field { flex: 1; min-width: 140px; }
.cin-page .cin-field .l { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.03em; color: #555; margin-bottom: 2px; }
.cin-page .cin-field .v { font-size: 14px; font-weight: 600; border-bottom: 1px solid #ccc; min-height: 18px; padding-bottom: 2px; }
.cin-page .cin-yn { display: inline-flex; gap: 10px; font-size: 12px; margin-left: 6px; }
.cin-page .cin-yn .box { display: inline-flex; align-items: center; gap: 3px; }
.cin-page .cin-yn .sq { display: inline-block; width: 11px; height: 11px; border: 1px solid #333; text-align: center; line-height: 10px; font-size: 10px; }
.cin-page .cin-yn .sq.checked { background: #111; color: #fff; }
.cin-page .cin-section-title { font-weight: 700; font-size: 13px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 0.02em; border-bottom: 2px solid #111; padding-bottom: 2px; }
.cin-page .cin-warning { font-size: 11px; color: #444; background: #f6f6f6; padding: 6px 8px; border-radius: 4px; margin-bottom: 10px; }
.cin-page .cin-confirm { display: flex; gap: 24px; margin-top: 16px; }
.cin-page .cin-confirm .col { flex: 1; }
.cin-page .cin-sig-line { border-bottom: 1px solid #333; height: 30px; margin-top: 18px; }
.cin-page .cin-back h2 { font-size: 15px; border-bottom: 2px solid #111; padding-bottom: 4px; }
.cin-page .cin-back h3 { font-size: 12.5px; margin-bottom: 2px; }
.cin-page .cin-back p { font-size: 11px; color: #333; margin: 0 0 8px; }
.cin-page .cin-back .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.print-actions { max-width: 820px; margin: 0 auto 14px; display: flex; gap: 10px; justify-content: flex-end; }

@media print {
  .topbar, .print-actions, .flash, .header-row .actions-row { display: none !important; }
  main { max-width: none; padding: 0; margin: 0; }
  body { background: #fff; }
  .cin-page { border: none; border-radius: 0; box-shadow: none; margin: 0; page-break-after: always; }
  .cin-page:last-child { page-break-after: auto; }
}

/* ---------- Added for the hosted version ---------- */
.logout-form { margin: 0 0 0 8px; }
.topbar { gap: 8px; }

.login-box { max-width: 380px; margin: 60px auto; }
.login-box h1 { margin-top: 0; }

.key-box { border-color: var(--accent); }
.key-value {
  display: block; padding: 12px; border-radius: 8px; background: var(--bg);
  border: 1px dashed var(--border); font-size: 18px; letter-spacing: 0.04em;
  word-break: break-all; user-select: all;
}

.file-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 130px; height: 100px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-weight: 700; font-size: 18px; text-decoration: none;
}
.photo a { text-decoration: none; }
.file-tile small { font-weight: 400; font-size: 11px; color: var(--muted); }

.card { overflow-x: auto; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .brand { margin-right: auto; }
  .nav-links { order: 3; width: 100%; margin: 4px 0 0; flex-wrap: wrap; gap: 14px; }
  main { padding: 16px 14px 48px; }
  .yn-group { flex-direction: column; align-items: flex-start; gap: 6px; }
}

@media print {
  .logout-form { display: none !important; }
}

/* ---------- Owner sections ---------- */
.owner-heading { font-size: 20px; margin: 4px 0 14px; }
.owner-section-next { margin-top: 44px; padding-top: 28px; border-top: 2px solid var(--border); }
.owner-badge { background: var(--accent); color: #fff; }

/* ---------- All Cars list, days in stock, monthly chart ---------- */
.nav-links { gap: 16px; flex-wrap: wrap; }
.filter-bar { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.filter-bar .field { margin-bottom: 0; min-width: 120px; }
.filter-bar .filter-search { flex: 1 1 220px; }
.filter-bar input[type="search"] { width: 100%; }
.filter-buttons { display: flex; gap: 8px; }
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { color: var(--accent); }
.car-table td, .car-table th { white-space: nowrap; }
td.muted-cell, td.muted-cell span { color: var(--muted); }

.days-badge { font-variant-numeric: tabular-nums; }
.days-slow, .value.warn { color: #b45309; font-weight: 600; }
.days-very-slow { color: var(--red); font-weight: 700; }
@media (prefers-color-scheme: dark) { .days-slow, .value.warn { color: #fbbf24; } }

.chart-scroll { overflow-x: auto; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { stroke: var(--muted); stroke-width: 1.5; }
.chart-tick { fill: var(--muted); font-size: 11px; }
.chart-sub { fill: var(--muted); font-size: 10px; }
.chart-bar-0 { fill: var(--accent); background: var(--accent); }
.chart-bar-1 { fill: #d97706; background: #d97706; }
.chart-legend { display: flex; gap: 16px; font-size: 13px; margin-bottom: 8px; }
.chart-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
