:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b36;
  --text: #e6e9ef;
  --muted: #97a0b0;
  --accent: #4c8bf5;
  --ok: #2faa6a;
  --bad: #d9534f;
  --warn: #d9a441;
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  /* Stay above positioned things on the page, e.g. the ad tiles with an AUKTION badge. */
  z-index: 10;
  background: var(--bg);
}

header h1 { font-size: 18px; margin: 0; letter-spacing: 0.5px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.updated { color: var(--muted); font-size: 13px; }

button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
/* Greyed out while a refresh runs, or when fewer than two models are ticked. */
button:disabled { opacity: 0.55; cursor: default; filter: none; }

main { padding: 24px; max-width: 1100px; margin: 0 auto; }
main:has(.page-my-jakt) { max-width: 96vw; }
main:has(.page-oversikt) { max-width: 1100px; }

.budget-slider { min-width: 240px; }
.budget-slider input[type="range"] { width: 100%; accent-color: var(--accent); }
.budget-readout { display: block; color: var(--text); font-size: 16px; }
.check-label { flex-direction: row !important; align-items: center; gap: 8px; }

.family-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.family-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.family-card .brand { margin: 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.family-card h3 { margin: 2px 0 12px; font-size: 18px; }
.family-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 0 0 12px; }
.family-stats div { margin: 0; }
.family-stats dt { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.family-stats dd { margin: 0; font-size: 14px; }
.example-ads { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.example-ads a { display: flex; gap: 10px; color: inherit; text-decoration: none; }
.example-ads a:hover .ex-title { text-decoration: underline; }
.example-ads img, .example-ads .no-photo {
  width: 88px;
  height: 66px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg);
  flex: 0 0 auto;
}
.example-ads .no-photo { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }
.ex-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ex-text span { color: var(--muted); font-size: 12px; }
.ex-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-more { margin: 12px 0 0; }
/* The card heading is a div, not <header>. The page <header> is sticky and dark. */
.card-head { margin-bottom: 8px; }
.card-head h3 { margin: 2px 0 0; }
.family-blurb { font-size: 14px; line-height: 1.45; margin: 0 0 12px; padding: 10px 12px; background: var(--bg); border-radius: 6px; }
.family-blurb p { margin: 0 0 4px; }
.card-lead { margin: 0 0 12px; font-size: 15px; }
.tco-parts { color: var(--muted); font-size: 12px; margin: 0 0 12px; line-height: 1.4; }
.examples-head { margin: 0 0 6px; }
.ex-tag { color: var(--accent) !important; font-size: 11px !important; text-transform: uppercase; letter-spacing: 0.4px; }

/* (i) headings: click the label to open a short explanation. */
details.info summary { cursor: pointer; list-style: none; display: inline; }
details.info summary::-webkit-details-marker { display: none; }
.info-i {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; margin-left: 3px; border-radius: 50%;
  border: 1px solid var(--muted); color: var(--muted);
  font-size: 10px; font-style: italic; font-weight: 700; text-transform: none; vertical-align: 1px;
}
details.info[open] .info-i { background: var(--accent); border-color: var(--accent); color: #fff; }
/* .info-box is the same box as a div, for (i) texts that hold a table (month_info). */
details.info p, details.info .info-box {
  margin: 6px 0 4px; padding: 8px 10px; background: var(--bg); border-left: 2px solid var(--accent);
  border-radius: 4px; color: var(--text); font-size: 13px; line-height: 1.4;
  text-transform: none; letter-spacing: 0; font-weight: 400;
}

/* Side-by-side table: green = best, red = worst in that row. */
.compare-title { font-size: 16px; margin: 20px 0 8px; }
.compare-title small { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.compare-table th span { color: var(--text); font-size: 13px; text-transform: none; letter-spacing: 0; }
.compare-table tbody th { color: var(--muted); font-weight: 600; font-size: 12px; min-width: 170px; vertical-align: top; }
.compare-table td { white-space: nowrap; font-variant-numeric: tabular-nums; vertical-align: top; }
.compare-table td.cell-best { color: var(--ok); font-weight: 700; }
.compare-table td.cell-worst { color: var(--bad); }
.facts-note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.flash {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 16px;
}

.bucket { margin-bottom: 40px; }
.bucket h2 { font-size: 20px; margin: 0 0 4px; }
.bucket h2 small { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 8px; }

.rec {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  border-radius: 6px;
  margin: 8px 0 16px;
  font-size: 15px;
}

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 8px; overflow: hidden; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th.sort-asc::after { content: " ▲"; font-size: 10px; color: var(--accent); }
th.sort-desc::after { content: " ▼"; font-size: 10px; color: var(--accent); }

.winter-cell { white-space: nowrap; color: var(--muted); font-size: 13px; }

.kpi-cell { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }

.jakt-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 20px;
  margin: 12px 0 8px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.jakt-filters label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.jakt-filters input {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  width: 140px;
}
.jakt-presets { font-size: 13px; color: var(--muted); }
.jakt-presets a { margin-left: 6px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #1d212b; }
.variant { max-width: 260px; }

.f-YES { color: var(--ok); font-weight: 700; text-align: center; }
.f-NO { color: var(--bad); font-weight: 700; text-align: center; }
.f-UNKNOWN { color: var(--warn); font-weight: 700; text-align: center; }

/* Battery SOH column — muted when unknown, warn when KVD could not read. */
.battery-cell { text-align: center; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.battery-cell.battery-ok { color: var(--ok); font-weight: 600; }
.battery-cell.battery-unread { color: var(--warn); }

/* Autopilot computer (HW3 / HW4) from ad text. */
.hw-cell { text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.hw-cell.hw-hw4, .hw-cell.hw-hw4q { color: var(--ok); font-weight: 600; }
.hw-cell.hw-hw3 { color: var(--text); }

.fsd-cell { text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.fsd-cell.fsd-fsd { color: var(--ok); font-weight: 600; }
.fsd-cell.fsd-eap { color: var(--text); font-size: 0.92em; }

.badge-new {
  background: var(--ok);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.empty { color: var(--muted); font-style: italic; }

footer {
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.pill { font-size: 12px; padding: 4px 10px; border-radius: 12px; border: 1px solid var(--line); color: var(--muted); }
.pill.ok { border-color: var(--ok); color: var(--ok); }
.pill.bad { border-color: var(--bad); color: var(--bad); }

/* Custom styles for tables container & headers */
.table-section h3 {
  font-size: 16px;
  margin: 16px 0 8px;
  color: var(--text);
}
.table-section h3 small {
  font-weight: 400;
  color: var(--muted);
  font-size: 13px;
  margin-left: 6px;
}

/* Gemma button styles */
.gemma-btn {
  background: var(--line);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.gemma-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
.modal-content {
  background-color: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 90%;
  max-width: 650px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  animation: modalFadeIn 0.3s ease-out;
}
@keyframes modalFadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
}
.modal-header h3 {
  margin: 0;
  font-size: 18px;
}
.close-btn {
  color: var(--muted);
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
}
.close-btn:hover {
  color: var(--text);
}
.modal-body {
  padding: 24px;
  max-height: 70vh;
  overflow-y: auto;
}

/* Loading state & spinner */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 0;
}
.spinner {
  border: 4px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
.loading-state p {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
}

/* Report rendering styles */
.report-content {
  line-height: 1.6;
  font-size: 15px;
}
.report-content h3 {
  font-size: 18px;
  color: var(--accent);
  margin: 0 0 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.report-content h4 {
  font-size: 15px;
  color: var(--text);
  margin: 16px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.report-content br + br {
  margin-bottom: 12px;
}
.error-msg {
  color: var(--bad);
  margin: 0;
}

/* Top navigation (Bilar / Statistik) */
.logo-link { color: var(--text); text-decoration: none; }
.top-nav { display: flex; gap: 14px; }
.top-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 4px 2px;
  border-bottom: 2px solid transparent;
}
.top-nav a:hover { color: var(--text); border-bottom-color: var(--accent); }

/* Statistics summary cards */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
}
.stat-card h3 { margin: 0 0 8px; font-size: 16px; color: var(--accent); }
.stat-big { font-size: 26px; font-weight: 700; margin: 4px 0 0; }
.stat-sub { color: var(--muted); font-size: 13px; margin: 2px 0 12px; }
.stat-list { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.stat-list li { padding: 3px 0; color: var(--muted); }
.stat-list strong { color: var(--text); }

/* Search form + pagination on the statistics page */
.table-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.search-form { display: flex; align-items: center; gap: 8px; }
.search-form input[type="search"] {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  min-width: 240px;
}
.search-form input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
}
.clear-link { color: var(--muted); font-size: 13px; text-decoration: none; }
.clear-link:hover { color: var(--text); }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 16px;
  font-size: 14px;
}
.pager a { color: var(--accent); text-decoration: none; }
.pager a:hover { text-decoration: underline; }
.pager .disabled { color: var(--line); }
.pager-info { color: var(--muted); }

/* Wide cost tables: allow horizontal scroll on narrow screens */
.table-scroll { overflow-x: auto; }

/* Registration plate cell */
.regnr {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* VAT cell */
.moms-cell small { color: var(--muted); }

/* "Same regnr on other sites" duplicate badge */
.badge-dup {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 11px;
  background: rgba(217, 164, 65, 0.18);
  color: var(--warn);
  border: 1px solid var(--warn);
  white-space: nowrap;
}

/* Fee & VAT explainer box */
.fee-info {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  margin: 0 0 18px;
  font-size: 14px;
}
.fee-info summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}
.fee-info ul { margin: 10px 0 2px; padding-left: 18px; color: var(--muted); }
.fee-info li { padding: 3px 0; }
.fee-info em { color: var(--text); font-style: normal; font-weight: 600; }

/* "Inkom <date>" — when we first discovered the listing (so "NY" has context) */
.seen-at {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

/* Gemma report footer: which engine produced it + timing */
.gemma-footer {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.gemma-footer strong { color: var(--accent); }

/* Price & performance charts grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
  margin-top: 20px;
}
.chart-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.chart-box h4 { margin: 0 0 10px; font-size: 14px; color: var(--text); }
.chart-box canvas { max-height: 280px; }
.muted-cell { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* Public site footer (base.html). */
.footer-note { color: var(--muted); font-size: 13px; }
.footer-nav { display: inline-flex; gap: 16px; margin-left: 16px; font-size: 13px; }
.footer-nav a { color: var(--muted); }
.footer-nav a:hover { color: var(--text); }
@media (max-width: 640px) {
  header { padding: 12px 16px; }
  main { padding: 16px; }
  .footer-nav { display: flex; flex-wrap: wrap; margin: 8px 0 0; }
}
