:root {
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);

  --series-1: #2a78d6; /* blue   - default single-series bars */
  --series-2: #1baf7a; /* aqua   */
  --series-3: #eda100; /* yellow */
  --series-4: #008300; /* green  */
  --series-5: #4a3aa7; /* violet */
  --series-6: #e34948; /* red    */
  --series-7: #e87ba4; /* magenta */
  --series-8: #eb6834; /* orange */

  --series-1-wash: rgba(42,120,214,0.10);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);

    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #c98500;
    --series-4: #008300;
    --series-5: #9085e9;
    --series-6: #e66767;
    --series-7: #d55181;
    --series-8: #d95926;

    --series-1-wash: rgba(57,135,229,0.14);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page-plane);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */

.site-header {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
}

.brand-tag {
  display: block;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.vin-search {
  position: relative;
  width: 320px;
  max-width: 100%;
}

#vin-search-input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
}

#vin-search-input:focus {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

.vin-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
}

.vin-search-result {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.vin-search-result:last-child { border-bottom: none; }
.vin-search-result:hover, .vin-search-result.active { background: var(--series-1-wash); }
.vin-search-result .vin { font-weight: 600; }
.vin-search-result .meta { color: var(--text-secondary); margin-left: 8px; }
.vin-search-empty { padding: 12px 14px; color: var(--text-muted); font-size: 13.5px; }

/* ---------- layout ---------- */

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

/* ---------- stat tiles ---------- */

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.15;
}

.stat-sub {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.stat-sub .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

/* ---------- filter bar ---------- */

.filter-bar[hidden] { display: none; }

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 20px;
}

.filter-bar-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

.filter-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--series-1-wash);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 5px 6px 5px 12px;
  font-size: 13px;
}

.filter-chip button {
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 50%;
}
.filter-chip button:hover { background: var(--border); color: var(--text-primary); }

.btn-clear-all {
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
}
.btn-clear-all:hover { color: var(--text-primary); }

/* ---------- charts ---------- */

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.chart-wide { grid-column: span 2; }

@media (max-width: 860px) {
  .charts-grid { grid-template-columns: 1fr; }
  .chart-wide { grid-column: span 1; }
}

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 12px;
}

.chart-card h2 {
  font-size: 14.5px;
  font-weight: 600;
  margin: 0 0 2px;
}

.chart-sub {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.chart-canvas-wrap { position: relative; height: 220px; }
.chart-canvas-short { height: 160px; }
.chart-canvas-tall { height: 300px; }

/* ---------- table ---------- */

.table-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 40px;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.table-header h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 8px 10px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--gridline);
  cursor: pointer;
  white-space: nowrap;
}
thead th:hover { color: var(--text-primary); }
thead th.sorted::after { content: " \25BE"; }
thead th.sorted.desc::after { content: " \25B4"; }

tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--series-1-wash); }

.table-pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.table-pagination button {
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
}
.table-pagination button:disabled { opacity: 0.4; cursor: default; }

/* ---------- modal ---------- */

.modal-backdrop[hidden] { display: none; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
}

.modal-panel {
  background: var(--surface-1);
  border-radius: var(--radius);
  padding: 26px 26px 20px;
  max-width: 640px;
  width: 100%;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
}
.modal-close:hover { color: var(--text-primary); }

.detail-vin {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 2px;
}

.detail-model-line {
  color: var(--text-secondary);
  font-size: 13.5px;
  margin-bottom: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px 20px;
  margin-bottom: 20px;
}

.detail-field-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.detail-field-value { font-size: 14px; }

.detail-options h3 {
  font-size: 13px;
  margin: 0 0 8px;
  color: var(--text-secondary);
}

.option-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.option-list li {
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--page-plane);
  display: flex;
  gap: 8px;
}

.option-code {
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--text-muted);
  flex-shrink: 0;
}
