:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --emerald: #059669;
  --emerald-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 14px 34px rgba(15, 23, 42, 0.14);
  --radius: 14px;
}

body.dark {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --border: #293548;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --emerald: #34d399;
  --emerald-soft: rgba(16, 185, 129, 0.15);
  --amber: #fbbf24;
  --amber-soft: rgba(245, 158, 11, 0.15);
  --purple: #a78bfa;
  --purple-soft: rgba(139, 92, 246, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 14px 34px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

body.modal-open {
  overflow: hidden;
}

button,
select,
input,
label {
  touch-action: manipulation;
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 18px;
}

/* Header */
.site-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  color: #fff;
  padding: 20px 0;
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand-badge {
  display: inline-block;
  width: fit-content;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.subtitle {
  margin: 0;
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.82);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  padding: 4px;
  border-radius: 12px;
}

.nav-tab {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
}

.nav-tab.active {
  background: #ffffff;
  color: #0f172a;
}

.tab-pill {
  background: #2563eb;
  color: #fff;
  font-size: 0.75rem;
  padding: 1px 7px;
  border-radius: 999px;
}

.main-content {
  margin-top: 22px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 1.35rem;
  color: var(--text);
}

.kpi-note {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Filters Panel */
.filters-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.filters-top-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.search-box {
  flex: 1 1 320px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.95rem;
}

.mobile-controls-row {
  display: contents;
}

.btn.mobile-filters-btn {
  display: none;
}

.filter-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

.mobile-filters-btn .toggle-chevron {
  transition: transform 0.18s ease;
  display: inline-block;
}

.mobile-filters-btn.open .toggle-chevron {
  transform: rotate(180deg);
}

.mobile-filters-btn.has-active-filters {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.matrix-head-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mobile-swipe-hint {
  display: none;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 999px;
  text-transform: none;
  letter-spacing: 0;
}

.sort-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-box label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.sort-box select,
.filter-field select,
.filter-field input[type="number"] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.9rem;
}

.segment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover {
  border-color: var(--primary);
}

.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filter-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.filters-bottom-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}

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

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.results-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 15px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-outline.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

body .modal .btn-ghost,
body .compare-bar .btn-ghost {
  color: var(--text);
  background: var(--surface-alt);
  border-color: var(--border);
}

/* Cars Grid & Cards */
.cars-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.car-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.car-card-body {
  padding: 14px 16px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  flex: 1;
}

.car-photo-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, #e2e8f0 0%, #f8fafc 100%);
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

body.dark .car-photo-wrap {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

.car-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.car-card:hover .car-photo {
  transform: scale(1.03);
}

.car-photo-overlay {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}

.photo-pill {
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  backdrop-filter: blur(4px);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.photo-pill-official {
  background: rgba(5, 150, 105, 0.9);
  color: #fff;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

/* Matrix table inside car card (Trims x Options) */
.card-matrix-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  overflow: hidden;
}

.card-matrix-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card-matrix-scroll {
  overflow-x: auto;
  max-width: 100%;
}

.card-matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
}

.card-matrix-table th,
.card-matrix-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}

.card-matrix-table th:last-child,
.card-matrix-table td:last-child {
  border-right: none;
}

.card-matrix-table tr:last-child td {
  border-bottom: none;
}

.card-matrix-table th:first-child,
.card-matrix-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface-alt);
  font-weight: 600;
  min-width: 120px;
  max-width: 155px;
  z-index: 1;
}

.card-matrix-table thead th {
  background: var(--surface);
  vertical-align: top;
  min-width: 96px;
}

.matrix-trim-title {
  display: block;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.matrix-trim-price {
  display: block;
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 2px;
  white-space: nowrap;
}

.matrix-calc-mini {
  margin-top: 4px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--primary);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
}

.matrix-calc-mini:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.detail-hero {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 18px;
  align-items: center;
}

.detail-photo {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.compare-col-photo {
  width: 100%;
  max-width: 180px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 6px;
  display: block;
}

.calc-dropdown-thumb {
  width: 56px;
  height: 34px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.calc-selected-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.calc-selected-thumb {
  width: 96px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

@media (max-width: 680px) {
  .detail-hero {
    grid-template-columns: 1fr;
  }
}

.car-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.car-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.car-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.25;
}

.car-trims {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-emerald { background: var(--emerald-soft); color: var(--emerald); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-slate { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }

.car-price-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.car-price {
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--text);
}

.car-monthly {
  font-size: 0.8rem;
  color: var(--emerald);
  font-weight: 600;
  margin-top: 2px;
}

.car-specs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-size: 0.83rem;
}

.spec-item {
  display: flex;
  flex-direction: column;
}

.spec-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.spec-val {
  font-weight: 600;
}

.car-review-preview {
  border-top: 1px dashed var(--border);
  padding-top: 9px;
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pros-line { color: var(--emerald); }
.cons-line { color: var(--amber); }

.car-card-actions {
  margin-top: auto;
  display: flex;
  gap: 8px;
  padding-top: 6px;
}

.car-card-actions .btn {
  flex: 1;
}

/* Price list inside card */
.card-pricelist {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  overflow: hidden;
}

.card-pricelist-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.pricelist-rows {
  display: flex;
  flex-direction: column;
}

.pricelist-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.pricelist-row:last-child {
  border-bottom: none;
}

.pricelist-row:hover {
  background: var(--primary-soft);
}

.pricelist-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pricelist-sub {
  display: block;
  font-size: 0.71rem;
  font-weight: 400;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pricelist-price {
  font-weight: 700;
  white-space: nowrap;
  color: var(--text);
}

.pricelist-calc-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.12s;
}

.pricelist-calc-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.pricelist-toggle {
  width: 100%;
  border: none;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--primary);
  padding: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.pricelist-toggle:hover {
  background: var(--primary-soft);
}

/* Option tags */
.option-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.option-tag {
  font-size: 0.73rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 999px;
}

.option-yes {
  color: var(--emerald);
  font-weight: 700;
}

.option-no {
  color: var(--text-muted);
  opacity: 0.55;
}

.compare-section-row td {
  background: var(--primary-soft) !important;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.compare-trim-select {
  margin-top: 6px;
  width: 100%;
  max-width: 240px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
}

/* Calculator searchable picker & trim pills */
.calc-picker-wrap {
  position: relative;
}

.calc-search-row {
  position: relative;
  display: flex;
  align-items: center;
}

.calc-search-row input {
  width: 100%;
  padding: 10px 36px 10px 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.94rem;
}

.calc-clear-btn {
  position: absolute;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 7px;
  border-radius: 6px;
}

.calc-clear-btn:hover {
  background: var(--border);
  color: var(--text);
}

.calc-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 290px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 30;
}

.calc-dropdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.88rem;
}

.calc-dropdown-item:last-child {
  border-bottom: none;
}

.calc-dropdown-item:hover {
  background: var(--primary-soft);
}

.calc-dropdown-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.calc-trim-section {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.calc-trim-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.calc-trim-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s;
}

.calc-trim-pill:hover {
  border-color: var(--primary);
}

.calc-trim-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.calc-trim-info {
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

/* Empty State */
.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
}

.hidden {
  display: none !important;
}

/* Compare Floating Bar */
.compare-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 2px solid var(--primary);
  box-shadow: var(--shadow-lg);
  padding: 10px 0;
  z-index: 40;
}

.compare-bar-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.compare-bar-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.compare-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.compare-chip {
  background: var(--primary-soft);
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.compare-chip button {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-weight: 700;
  padding: 0;
}

.compare-bar-actions {
  display: flex;
  gap: 8px;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  position: relative;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  z-index: 1;
}

.modal-dialog-wide {
  max-width: 1100px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
}

.detail-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.detail-section h4 {
  margin: 0 0 8px 0;
  font-size: 0.96rem;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: var(--surface-alt);
  font-weight: 700;
}

.compare-table th:first-child,
.compare-table td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface-alt);
  font-weight: 700;
  min-width: 160px;
}

/* Calculator & Dealers */
.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-panel h2,
.card-panel h3 {
  margin-top: 0;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.calc-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
}

.calc-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.calc-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.calc-warnings {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.warning-box {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 500;
}

.warning-ok { background: var(--emerald-soft); color: var(--emerald); }
.warning-warn { background: var(--amber-soft); color: var(--amber); }
.warning-danger { background: var(--danger-soft); color: var(--danger); }

.calc-results-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 10px;
}

.calc-stat {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calc-stat.highlight {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.calc-stat span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.calc-stat strong {
  font-size: 1.08rem;
}

.cond-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cond-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.cond-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.cond-item p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.dealers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.info-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
}

.dealer-clusters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.cluster-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.cluster-box h4 {
  margin: 0 0 10px 0;
}

.cluster-box ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.site-footer {
  margin-top: 32px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.card-matrix-scroll,
.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.card-matrix-table th:first-child,
.card-matrix-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface-alt);
  font-weight: 600;
  min-width: 120px;
  max-width: 155px;
  z-index: 1;
  box-shadow: 2px 0 6px rgba(15, 23, 42, 0.05);
}

/* Range slider touch ergonomics */
input[type="range"] {
  accent-color: var(--primary);
  height: 28px;
  cursor: pointer;
}

@media (max-width: 900px) {
  .calc-layout,
  .dealers-grid {
    grid-template-columns: 1fr;
  }
}

/* === FULL MOBILE ADAPTATION (Smartphones & Small Tablets <= 768px) === */
@media (max-width: 768px) {
  .container {
    padding: 0 12px;
  }

  /* Compact Mobile Header */
  .site-header {
    padding: 12px 0 10px 0;
    position: relative;
  }

  .header-inner {
    gap: 10px;
    align-items: stretch;
  }

  .brand {
    width: 100%;
    padding-right: 92px; /* room for theme toggle */
  }

  .brand-badge {
    font-size: 11px;
    padding: 2px 8px;
  }

  .brand h1 {
    font-size: 1.15rem;
    line-height: 1.2;
  }

  .subtitle {
    font-size: 0.76rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .header-actions {
    width: 100%;
    gap: 0;
  }

  #theme-toggle {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 6px 10px;
    font-size: 0.78rem;
    min-height: 34px;
    border-radius: 999px;
  }

  .nav-tabs {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 4px;
    padding: 3px;
  }

  .nav-tabs::-webkit-scrollbar {
    display: none;
  }

  .nav-tab {
    flex: 1 1 0;
    justify-content: center;
    padding: 8px 6px;
    font-size: 0.78rem;
    white-space: nowrap;
    min-height: 38px;
  }

  .tab-label-long {
    display: none;
  }

  .main-content {
    margin-top: 12px;
  }

  /* Compact 2x2 KPI Strip */
  .kpi-strip {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 12px;
  }

  .kpi-card {
    padding: 10px 11px;
    border-radius: 12px;
    gap: 2px;
  }

  .kpi-label {
    font-size: 0.71rem;
  }

  .kpi-value {
    font-size: 1.05rem;
    line-height: 1.2;
  }

  .kpi-note {
    font-size: 0.7rem;
    line-height: 1.25;
  }

  /* Mobile Filters Panel with Collapsible Drawer */
  .filters-panel {
    padding: 12px;
    border-radius: 14px;
    margin-bottom: 14px;
  }

  .filters-top-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 10px;
  }

  .search-box {
    flex: 1 1 auto;
    width: 100%;
  }

  /* 16px prevents iOS Safari auto-zoom on focus */
  .search-box input,
  .sort-box select,
  .filter-field select,
  .filter-field input[type="number"],
  .calc-search-row input {
    font-size: 16px;
    min-height: 42px;
  }

  .mobile-controls-row {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    align-items: center;
  }

  .btn.mobile-filters-btn {
    display: inline-flex;
    min-height: 42px;
    padding: 8px 12px;
    font-size: 0.86rem;
    white-space: nowrap;
  }

  .sort-box {
    width: 100%;
    min-width: 0;
  }

  .sort-box label {
    display: none;
  }

  .sort-box select {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
  }

  /* Swipeable single-row segment chips */
  .segment-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    margin: 0 -12px 10px -12px;
    padding: 2px 12px;
  }

  .segment-chips::-webkit-scrollbar {
    display: none;
  }

  .chip {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 7px 12px;
    font-size: 0.82rem;
    min-height: 36px;
  }

  /* Collapsible secondary filters */
  .filters-collapsible {
    display: none;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
    margin-bottom: 8px;
  }

  .filters-collapsible.open {
    display: block;
  }

  .filters-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
  }

  .filter-field select,
  .filter-field input[type="number"] {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
  }

  .toggle-chips {
    gap: 6px;
  }

  .toggle-chip {
    padding: 7px 10px;
    font-size: 0.78rem;
    min-height: 36px;
  }

  .filters-bottom-row {
    margin-top: 6px;
    padding-top: 8px;
    gap: 8px;
  }

  .results-meta {
    width: 100%;
    justify-content: space-between;
    font-size: 0.84rem;
  }

  /* Cards Grid & Mobile Card Layout */
  .cars-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .car-card {
    border-radius: 14px;
  }

  .car-card-body {
    padding: 12px;
    gap: 10px;
  }

  .car-title {
    font-size: 1.08rem;
  }

  .car-price {
    font-size: 1.08rem;
  }

  .car-specs {
    gap: 6px 8px;
    font-size: 0.8rem;
  }

  .mobile-swipe-hint {
    display: inline-block;
  }

  /* Mobile Matrix Table inside Card */
  .card-matrix-head {
    padding: 6px 8px;
    font-size: 0.7rem;
  }

  .card-matrix-table {
    font-size: 0.73rem;
  }

  .card-matrix-table th,
  .card-matrix-table td {
    padding: 5px 6px;
  }

  .card-matrix-table th:first-child,
  .card-matrix-table td:first-child {
    min-width: 110px;
    max-width: 130px;
    font-size: 0.71rem;
    line-height: 1.25;
  }

  .card-matrix-table thead th {
    min-width: 84px;
  }

  .matrix-calc-mini {
    min-width: 34px;
    min-height: 28px;
    padding: 3px 8px;
    font-size: 0.78rem;
  }

  .pricelist-toggle {
    padding: 10px 8px;
    font-size: 0.82rem;
  }

  .car-card-actions {
    gap: 8px;
  }

  .car-card-actions .btn {
    min-height: 42px;
    font-size: 0.85rem;
    padding: 8px 10px;
  }

  /* Bottom-Sheet Modals on Mobile */
  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-dialog,
  .modal-dialog-wide {
    max-width: 100%;
    width: 100%;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    padding: 16px 12px calc(22px + env(safe-area-inset-bottom, 0px)) 12px;
  }

  .modal-close {
    position: sticky;
    top: 0;
    float: right;
    z-index: 5;
    width: 38px;
    height: 38px;
    box-shadow: var(--shadow);
  }

  .detail-hero {
    grid-template-columns: 1fr;
    gap: 12px;
    clear: none;
  }

  .detail-hero h2 {
    font-size: 1.25rem;
    padding-right: 42px;
  }

  .detail-photo {
    aspect-ratio: 16 / 9;
    max-height: 220px;
  }

  /* Stacked trim cards in Detail Modal on Mobile */
  .detail-trims-table thead {
    display: none;
  }

  .detail-trims-table,
  .detail-trims-table tbody,
  .detail-trims-table tr,
  .detail-trims-table td {
    display: block;
    width: 100%;
  }

  .detail-trims-table tr {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }

  .detail-trims-table td {
    padding: 3px 0;
    border-bottom: none;
  }

  .detail-trims-table td:last-child {
    margin-top: 8px;
  }

  .detail-trims-table td:last-child .btn {
    width: 100%;
    min-height: 40px;
  }

  /* Mobile Compare Modal Table */
  .compare-table {
    font-size: 0.78rem;
  }

  .compare-table th,
  .compare-table td {
    padding: 7px 8px;
  }

  .compare-table th:first-child,
  .compare-table td:first-child {
    min-width: 108px;
    max-width: 122px;
    font-size: 0.74rem;
    line-height: 1.25;
    box-shadow: 2px 0 6px rgba(15, 23, 42, 0.08);
    z-index: 2;
  }

  .compare-table thead th:not(:first-child) {
    min-width: 148px;
  }

  .compare-col-photo {
    max-width: 136px;
  }

  .compare-trim-select {
    font-size: 13px;
    max-width: 142px;
    min-height: 36px;
    padding: 4px 6px;
  }

  /* Mobile Floating Compare Bar */
  .compare-bar {
    padding: 8px 0 calc(10px + env(safe-area-inset-bottom, 0px)) 0;
  }

  .compare-bar-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .compare-bar-info {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
  }

  .compare-bar-info::-webkit-scrollbar {
    display: none;
  }

  .compare-bar-info > span:first-child {
    white-space: nowrap;
    font-size: 0.82rem;
  }

  .compare-chips {
    flex-wrap: nowrap;
  }

  .compare-chip {
    white-space: nowrap;
    font-size: 0.76rem;
    padding: 4px 8px;
  }

  .compare-bar-actions {
    width: 100%;
  }

  .compare-bar-actions #open-compare {
    flex: 1;
    min-height: 40px;
  }

  .compare-bar-actions #clear-compare {
    min-height: 40px;
  }

  /* Mobile Calculator & Dealers */
  .card-panel {
    padding: 14px 12px;
    border-radius: 14px;
  }

  .card-panel h2 {
    font-size: 1.18rem;
  }

  .calc-row-2 {
    grid-template-columns: 1fr;
  }

  .calc-results-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .calc-stat {
    padding: 10px;
  }

  .calc-stat strong {
    font-size: 0.98rem;
  }

  .calc-dropdown {
    max-height: 50vh;
  }

  .calc-dropdown-item {
    padding: 10px;
  }

  .calc-trim-pill {
    min-height: 36px;
    padding: 6px 10px;
  }

  .calc-selected-thumb {
    width: 76px;
    height: 46px;
  }

  .data-table {
    font-size: 0.8rem;
  }

  .data-table th,
  .data-table td {
    padding: 8px;
  }
}

@media (max-width: 380px) {
  .brand h1 {
    font-size: 1.05rem;
  }

  .kpi-value {
    font-size: 0.96rem;
  }

  .calc-results-grid {
    grid-template-columns: 1fr;
  }
}
