/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface2:    #22263a;
  --border:      #2e3250;
  --text:        #e8eaf6;
  --text-muted:  #8892b0;
  --accent:      #6c63ff;
  --accent2:     #00d4aa;
  --radius:      12px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
}

[data-theme="light"] {
  --bg:          #f0f2f8;
  --surface:     #ffffff;
  --surface2:    #e8ecf5;
  --border:      #d0d5e8;
  --text:        #1a1d27;
  --text-muted:  #5a6080;
  --shadow:      0 4px 24px rgba(0,0,0,0.10);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

/* ─── Typography ───────────────────────────────────────────────────────────── */
h1 { font-size: clamp(1.3rem, 3vw, 1.9rem); font-weight: 700; letter-spacing: -0.5px; }
h2 { font-size: clamp(0.95rem, 2vw, 1.15rem); font-weight: 600; color: var(--text); margin-bottom: 0.25rem; }
h3 { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 0.5rem; }

/* ─── Header ───────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }
.header-icon { font-size: 1.7rem; }
.header-sub  { font-size: 0.75rem; color: var(--text-muted); margin-top: 1px; }

.theme-toggle {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s;
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--border); }

/* ─── Layout ───────────────────────────────────────────────────────────────── */
.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ─── Controls Panel ───────────────────────────────────────────────────────── */
.controls-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.4rem;
  box-shadow: var(--shadow);
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.9rem 1.4rem;
  margin-top: 0.75rem;
}

.control-item { display: flex; flex-direction: column; gap: 0.3rem; }
.control-item label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.control-item .value-display {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent2);
  min-width: 80px;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* ─── Filter Buttons ───────────────────────────────────────────────────────── */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.filter-btn {
  padding: 0.3rem 0.85rem;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}
.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ─── Car Search ───────────────────────────────────────────────────────────── */
.car-search-wrapper {
  position: relative;
  max-width: 520px;
  margin-top: 0.4rem;
}

.car-search-input {
  width: 100%;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}
.car-search-input:focus { border-color: var(--accent); }
.car-search-input::placeholder { color: var(--text-muted); }

.car-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  max-height: 280px;
  overflow-y: auto;
  z-index: 300;
  display: none;
}
.car-dropdown.open { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font-size: 0.83rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--surface2); }
.dropdown-item.selected { background: rgba(108,99,255,0.1); }
.dropdown-item .item-name { flex: 1; font-weight: 600; }
.dropdown-item .item-meta { font-size: 0.72rem; color: var(--text-muted); }
.dropdown-item .item-check { color: var(--accent2); font-weight: 700; margin-left: 0.25rem; }
.dropdown-empty { padding: 0.75rem 1rem; color: var(--text-muted); font-size: 0.82rem; }

/* ─── Selected Cars Chips ──────────────────────────────────────────────────── */
.selected-cars {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.4rem;
  min-height: 36px;
  align-items: center;
}

.car-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 20px;
  border: 1.5px solid transparent;
  font-size: 0.78rem;
  font-weight: 600;
  user-select: none;
}
.car-chip .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.car-chip .chip-remove {
  cursor: pointer;
  margin-left: 0.2rem;
  opacity: 0.7;
  font-size: 0.7rem;
  transition: opacity 0.15s;
}
.car-chip .chip-remove:hover { opacity: 1; }

/* ─── Summary Cards ────────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 1rem;
}

.tco-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}
.tco-card:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(0,0,0,0.5); }

.tco-card .car-name {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.tco-card .tco-total {
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 0.2rem;
}
.tco-card .tco-per-km { font-size: 0.78rem; color: var(--text-muted); }
.tco-card .tco-per-km span { font-weight: 700; color: var(--accent2); }

.tco-card .badge {
  position: absolute;
  top: 0.55rem; right: 0.65rem;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.12rem 0.4rem;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-winner { background: #00d4aa22; color: #00d4aa; border: 1px solid #00d4aa55; }
.badge-ev     { background: #3498db22; color: #3498db; border: 1px solid #3498db55; }
.badge-hybrid { background: #2ecc7122; color: #2ecc71; border: 1px solid #2ecc7155; }
.badge-petrol { background: #e74c3c22; color: #e74c3c; border: 1px solid #e74c3c55; }
.badge-diesel { background: #f39c1222; color: #f39c12; border: 1px solid #f39c1255; }

/* ─── Charts Grid ──────────────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.1rem;
}
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}
.chart-card .chart-sub { font-size: 0.74rem; color: var(--text-muted); margin-bottom: 0.9rem; }
.chart-wrapper { position: relative; width: 100%; }

/* ─── Comparison Breakdown Table ───────────────────────────────────────────── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }

thead th {
  padding: 0.55rem 0.8rem;
  text-align: right;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
thead th:first-child { text-align: left; }

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.12s; }
tbody tr:hover { background: var(--surface2); }
tbody tr.total-row { border-top: 2px solid var(--border); font-weight: 700; }
tbody tr.total-row td { padding-top: 0.75rem; }

tbody td { padding: 0.5rem 0.8rem; text-align: right; white-space: nowrap; }
tbody td:first-child { text-align: left; color: var(--text-muted); font-size: 0.77rem; }

.col-header-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.winner-cell { color: var(--accent2); font-weight: 700; }

/* ─── Browse All Table ─────────────────────────────────────────────────────── */
.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
.sortable:hover { color: var(--text); }

.browse-row { cursor: pointer; }
.browse-row.row-selected { background: rgba(108,99,255,0.08) !important; }
.browse-row:hover { background: var(--surface2); }

.compare-btn {
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.compare-btn:hover { border-color: var(--accent); color: var(--accent); }
.compare-btn.active { background: rgba(0,212,170,0.15); border-color: var(--accent2); color: var(--accent2); }

/* ─── Fuel Badges ──────────────────────────────────────────────────────────── */
.fuel-badge {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.fuel-ev     { background: #3498db22; color: #3498db; border: 1px solid #3498db55; }
.fuel-petrol { background: #e74c3c22; color: #e74c3c; border: 1px solid #e74c3c55; }
.fuel-diesel { background: #f39c1222; color: #f39c12; border: 1px solid #f39c1255; }
.fuel-hybrid { background: #2ecc7122; color: #2ecc71; border: 1px solid #2ecc7155; }

/* ─── Section Title ────────────────────────────────────────────────────────── */
.section-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Footer ───────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
footer code {
  background: var(--surface2);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.72rem;
}

/* ─── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .container { padding: 0.9rem; gap: 0.9rem; }
  .controls-grid { grid-template-columns: 1fr 1fr; }
  .cards-grid { grid-template-columns: 1fr 1fr; }
  header { padding: 0.65rem 1rem; }
}
@media (max-width: 420px) {
  .cards-grid { grid-template-columns: 1fr; }
  .controls-grid { grid-template-columns: 1fr; }
}

.hidden { display: none !important; }
