/* ────────── reset y tokens ────────── */
:root {
  --bg:        #f5f6f8;
  --panel:    #ffffff;
  --ink:      #0d1117;
  --ink-soft: #4a5260;
  --line:     #e5e7eb;
  --line-2:   #d1d5db;
  --shadow:   0 1px 2px rgba(0,0,0,.04), 0 6px 18px rgba(13,17,23,.06);
  --shadow-h: 0 6px 24px rgba(13,17,23,.12);
  --accent:   #001e50;
  --accent-2: #0066ff;
  --good:     #16a34a;
  --radius:   12px;

  --audi:   #bb0a30;
  --cupra:  #b87333;
  --skoda:  #0e3a2f;
  --vw:     #001e50;
}
* { box-sizing: border-box; }
html, body { margin:0; padding:0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
a { color: inherit; }
button { font: inherit; cursor: pointer; }
input, select, button { font-family: inherit; }

/* ────────── topbar ────────── */
.topbar {
  display: grid;
  grid-template-columns: 320px 1fr 320px;
  gap: 16px;
  align-items: center;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar-right {
  display: flex; align-items: center; gap: 12px; justify-content: flex-end;
}
.last-update { text-align: right; line-height: 1.3; }
.last-update #last-update-text { display: block; font-size: 12.5px; color: var(--ink); font-weight: 600; }
.last-update .muted { color: var(--ink-soft); font-size: 11.5px; }
.btn-novedades {
  background: white; color: var(--ink);
  border: 1px solid var(--line-2);
  padding: 9px 14px;
  border-radius: 999px; font-weight: 600; font-size: 12.5px;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .15s, border-color .15s;
}
.btn-novedades:hover { background: #f4f5f7; border-color: #b5bcc6; }
.btn-novedades .nov-badge {
  background: var(--good); color: white;
  font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
  min-width: 18px; text-align: center;
}
.btn-refresh {
  background: var(--ink); color: white;
  border: none; padding: 9px 14px;
  border-radius: 999px; font-weight: 600; font-size: 12.5px;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .15s, opacity .15s;
}
.btn-refresh:hover:not(:disabled) { background: #22272f; }
.btn-refresh:disabled { opacity: .55; cursor: wait; }
.btn-refresh .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--good); display: inline-block;
  box-shadow: 0 0 0 0 rgba(22,163,74,.7);
}
.btn-refresh.running .dot {
  background: #f59e0b;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(245,158,11,.7); }
  70%  { box-shadow: 0 0 0 8px rgba(245,158,11,0); }
  100% { box-shadow: 0 0 0 0 rgba(245,158,11,0); }
}
.warning-banner {
  background: #fef3c7; color: #78350f;
  border-bottom: 1px solid #fde68a;
  padding: 10px 22px;
  font-size: 13px;
}
.warning-banner b { color: #7c2d12; }
.brand { display:flex; align-items:center; gap: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 10px;
  background: linear-gradient(135deg, var(--vw), #0a3a8a);
  color: white; font-weight: 900; font-size: 18px;
  display:flex; align-items:center; justify-content:center;
  letter-spacing: -0.5px;
}
.logo span { font-size: 12px; opacity:.85; margin-left: 1px; }
.brand-text strong { font-size: 15px; display:block; }
.brand-text small { color: var(--ink-soft); font-size: 11.5px; }
.search input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: #fafbfc;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.search input:focus {
  border-color: var(--accent-2);
  background: white;
  box-shadow: 0 0 0 3px rgba(0,102,255,.15);
}
.stats { text-align:right; color: var(--ink-soft); font-size: 12.5px; }

/* ────────── layout ────────── */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 22px;
  padding: 22px;
  align-items: start;
}
@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
}

/* ────────── filtros ────────── */
.filters {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 4px 14px 14px;
  box-shadow: var(--shadow);
  position: sticky; top: 88px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}
.filter-section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.filter-section:last-child { border-bottom: none; }
.filter-section h3 {
  font-size: 12px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-soft);
  margin: 0 0 8px;
}
.chips { display:flex; flex-wrap:wrap; gap: 6px; }
.chip {
  display:inline-flex; align-items:center; gap: 6px;
  background: #f4f5f7;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  transition: background .15s, border-color .15s, color .15s;
}
.chip .n { color: var(--ink-soft); font-size: 11px; }
.chip:hover { background:#eef0f2; }
.chip.on {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.chip.on .n { color: rgba(255,255,255,.75); }
.chip[data-marca="Audi"].on    { background: var(--audi);  border-color: var(--audi); }
.chip[data-marca="Cupra"].on   { background: var(--cupra); border-color: var(--cupra); }
.chip[data-marca="Skoda"].on   { background: var(--skoda); border-color: var(--skoda); }
.chip[data-marca="Volkswagen"].on { background: var(--vw); border-color: var(--vw); }

/* Filtro modelo agrupado por marca cuando hay varias seleccionadas */
.modelo-group { margin-top: 8px; }
.modelo-group:first-child { margin-top: 0; }
.modelo-group-h {
  font-size: 10.5px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-soft); margin: 0 0 6px 2px;
}
.modelo-group .chips { margin-bottom: 4px; }

.range { display:flex; gap:8px; }
.range input {
  width: 50%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line-2); outline:none;
}
.range input:focus { border-color: var(--accent-2); }
.select {
  width: 100%; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--line-2); background:white;
}
.filter-clear {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: #fafbfc;
  color: var(--ink-soft); transition: background .15s;
  margin-top: 8px;
}
.filter-clear:hover { background: #f0f1f3; color: var(--ink); }

/* ────────── results bar + grid ────────── */
.results-bar {
  display:flex; align-items:center; justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 12px;
}
.count { font-weight: 700; font-size: 15px; }
.sort select {
  padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line-2); background: white;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.card {
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex; flex-direction: column;
  transition: transform .12s ease, box-shadow .12s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-h); }
.card .photo {
  position: relative;
  width: 100%; aspect-ratio: 16/10;
  background: #eef0f2 center/cover no-repeat;
  display:flex; align-items:center; justify-content:center;
}
.card .photo img {
  width:100%; height:100%; object-fit: cover; display:block;
  background:#eef0f2;
}
.card .photo .no-img {
  color: var(--ink-soft); font-size: 13px;
}
.badge {
  position: absolute; top: 10px; left: 10px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(6px);
  font-weight: 700; font-size: 11px;
  letter-spacing: .04em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 999px;
  color: var(--ink);
}
.badge.audi   { color: var(--audi); }
.badge.cupra  { color: var(--cupra); }
.badge.skoda  { color: var(--skoda); }
.badge.vw     { color: var(--vw); }

.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .title {
  font-weight: 700; font-size: 14.5px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 38px;
}
.card .price {
  font-size: 19px; font-weight: 800; color: var(--ink);
  margin-top: 2px;
}
.card .price .strike {
  font-size: 12px; font-weight: 500;
  color: var(--ink-soft); text-decoration: line-through;
  margin-left: 6px;
}
.card .specs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px;
  font-size: 12.5px; color: var(--ink-soft);
  margin-top: 4px;
}
.card .specs span::before {
  content:""; display:inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--line-2); margin-right: 6px; vertical-align: middle;
}
.card .dealer {
  border-top: 1px dashed var(--line);
  margin-top: 8px; padding-top: 8px;
  font-size: 12px; color: var(--ink-soft);
  display: flex; justify-content: space-between; gap: 8px;
}
.card .dealer b { color: var(--ink); font-weight: 600; }

.loadmore {
  display: block; margin: 22px auto;
  padding: 12px 28px;
  background: var(--ink); color: white;
  border: none; border-radius: 999px;
  font-weight: 600;
}
.loadmore:hover { background:#22272f; }
.foot { padding: 30px 6px; text-align:center; color: var(--ink-soft); }
.empty {
  padding: 60px 20px; text-align:center; color: var(--ink-soft);
  grid-column: 1 / -1;
}

/* ────────── modal detalle ────────── */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed; inset: 0;
  background: rgba(13,17,23,.55);
  z-index: 50;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 28px 16px;
  overflow-y: auto;
}
.modal-inner {
  background: var(--panel);
  width: 100%; max-width: 1100px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.m-head { display:flex; justify-content: space-between; align-items: start;
  padding: 22px 24px 8px; gap: 16px; }
.m-head .m-title { flex: 1; }
.m-head .m-title h2 { margin: 0 0 4px; font-size: 22px; }
.m-head .m-title small { color: var(--ink-soft); font-size: 13px; }
.m-head .m-close {
  width: 34px; height: 34px;
  border: 1px solid var(--line); background: white;
  border-radius: 50%; font-size: 18px; line-height: 1;
}
.m-gallery {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 4px;
  padding: 0 24px;
}
.m-gallery img {
  width: 100%; aspect-ratio: 16/10; object-fit: cover;
  border-radius: 8px; background: #eef0f2;
}
.m-gallery img.main { grid-row: span 2; aspect-ratio: 4/3; }
.m-body {
  display: grid; grid-template-columns: 2fr 1fr;
  gap: 24px;
  padding: 22px 24px 30px;
}
@media (max-width: 720px) {
  .m-body { grid-template-columns: 1fr; }
  .m-gallery { grid-template-columns: 1fr 1fr; }
  .m-gallery img.main { grid-column: span 2; grid-row: auto; aspect-ratio: 16/10; }
}
.m-specs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px;
}
.m-specs > div { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.m-specs > div b { color: var(--ink-soft); font-weight: 500; margin-right: 8px; }
.m-side {
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.m-side h3 { margin: 0 0 6px; font-size: 14px; }
.m-side .price-big {
  font-size: 28px; font-weight: 900; color: var(--ink);
  letter-spacing: -.5px;
}
.m-side .price-strike { color: var(--ink-soft); text-decoration: line-through; font-size: 14px; }
.m-side .dealer-block { margin-top: 14px; font-size: 13px; line-height: 1.55; }
.m-side a.cta {
  display:block; text-align:center; margin-top: 14px;
  padding: 12px; background: var(--ink); color: white;
  border-radius: 10px; text-decoration: none; font-weight: 600;
}
.m-side a.cta:hover { background:#22272f; }

/* ────────── refresh modal ────────── */
.refresh-modal-inner { max-width: 820px; }
.refresh-progress { padding: 8px 24px 16px; }
.bar {
  width: 100%; height: 6px; background: var(--line);
  border-radius: 999px; overflow: hidden;
}
.bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent-2), #38bdf8);
  transition: width .3s ease;
}
.stages {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 10px; font-size: 11.5px;
}
.stages span {
  padding: 4px 9px; border-radius: 999px;
  background: #f4f5f7; color: var(--ink-soft);
  border: 1px solid var(--line);
  transition: background .15s, color .15s, border-color .15s;
}
.stages span.active { background: #fef3c7; color: #78350f; border-color: #fde68a; }
.stages span.done   { background: #dcfce7; color: #14532d; border-color: #bbf7d0; }
.stages span.fail   { background: #fee2e2; color: #7f1d1d; border-color: #fecaca; }
.refresh-log {
  margin: 0 24px 24px;
  background: #0d1117; color: #c9d1d9;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px; line-height: 1.55;
  padding: 14px 16px; border-radius: 10px;
  max-height: 380px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-all;
}
.refresh-log .line-ok   { color: #4ade80; }
.refresh-log .line-fail { color: #f87171; }
.refresh-log .line-info { color: #93c5fd; }
.refresh-done { color: var(--good); font-weight: 700; }
.refresh-fail { color: #b91c1c; font-weight: 700; }

/* ────────── badge "NUEVO" en cards ────────── */
.badge-nuevo {
  position: absolute; top: 10px; right: 10px;
  background: var(--good); color: white;
  font-weight: 800; font-size: 10.5px;
  letter-spacing: .06em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 6px;
  box-shadow: 0 2px 6px rgba(22,163,74,.35);
}

/* ────────── novedades modal ────────── */
.novedades-modal-inner { max-width: 980px; }
.nov-tabs {
  display: flex; gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
}
.nov-tab {
  background: none; border: none;
  padding: 12px 16px;
  border-bottom: 3px solid transparent;
  font-size: 13.5px; color: var(--ink-soft); font-weight: 500;
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.nov-tab:hover { color: var(--ink); }
.nov-tab.on { color: var(--ink); border-bottom-color: var(--accent-2); font-weight: 700; }
.nov-tab .n {
  background: #f4f5f7; color: var(--ink-soft);
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
}
.nov-tab.on .n { background: var(--accent-2); color: white; }
.nov-content { padding: 18px 24px 28px; max-height: 60vh; overflow-y: auto; }
.nov-list { display: grid; grid-template-columns: 1fr; gap: 8px; }
.nov-item {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 12px; align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.nov-item:hover { background: #fafbfc; border-color: var(--line-2); }
.nov-item img {
  width: 80px; height: 56px; object-fit: cover;
  border-radius: 6px; background: #eef0f2;
}
.nov-item .nov-info { font-size: 13px; line-height: 1.4; }
.nov-item .nov-info b { display: block; font-size: 13.5px; }
.nov-item .nov-info small { color: var(--ink-soft); }
.nov-item .nov-price { text-align: right; font-weight: 700; font-size: 14.5px; }
.nov-item .nov-price small { display: block; color: var(--ink-soft); font-weight: 400; font-size: 11px; }
.nov-item .nov-delta {
  display: inline-block; padding: 2px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 700;
  margin-top: 4px;
}
.nov-delta.up   { background: #fee2e2; color: #991b1b; }
.nov-delta.down { background: #dcfce7; color: #14532d; }
.nov-empty { text-align: center; color: var(--ink-soft); padding: 40px 20px; }

.m-equip { padding: 0 24px 28px; }
.m-equip h3 { font-size: 14px; margin: 0 0 8px; }
.m-equip .equip-list {
  columns: 2; column-gap: 24px;
  font-size: 12.5px; color: var(--ink-soft);
}
.m-equip li { break-inside: avoid; margin-bottom: 4px; }
@media (max-width: 720px) { .m-equip .equip-list { columns: 1; } }

/* ════════════════════════════════════════════════════════════════════
   RESPONSIVE — tablet (≤980px) y móvil (≤640px)
   ════════════════════════════════════════════════════════════════════ */

/* Botón "Filtros" móvil. Solo visible en pantallas pequeñas. */
.btn-filters {
  display: none;
  background: white;
  border: 1px solid var(--line-2);
  padding: 9px 14px;
  border-radius: 999px;
  font-weight: 600; font-size: 12.5px;
  color: var(--ink);
  align-items: center; gap: 6px;
}

@media (max-width: 980px) {
  /* Topbar: la búsqueda ocupa el ancho completo, los botones debajo. */
  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px 14px;
  }
  .brand-text small { display: none; }   /* el subtítulo larguísimo no cabe */
  .topbar-right { flex-wrap: wrap; justify-content: stretch; gap: 8px; }
  .last-update { text-align: left; flex: 1; min-width: 0; }
  .btn-novedades, .btn-refresh { flex: 0 0 auto; }

  /* Layout: una columna, sin sidebar pegado. */
  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }

  /* Sidebar de filtros: colapsable en móvil. Se muestra al pulsar el botón. */
  .filters {
    position: static;
    max-height: none;
    overflow-y: visible;
    display: none;
  }
  .filters.open { display: block; }
  .btn-filters { display: inline-flex; }

  /* Cards: minmax más estrecho para que entren bien. */
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
  .card .body { padding: 10px 12px 12px; }
  .card .title { font-size: 13.5px; min-height: 36px; -webkit-line-clamp: 2; }
  .card .price { font-size: 17px; }
  .card .specs { font-size: 12px; }
}

@media (max-width: 640px) {
  /* Móvil: una sola columna de cards a ancho completo del viewport. */
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card .photo { aspect-ratio: 16/9; }

  /* Botones del topbar: mejor sin texto largo. */
  .btn-refresh, .btn-novedades { font-size: 12px; padding: 8px 12px; }

  /* Modal de detalle ocupa pantalla casi entera, sin scroll horizontal. */
  .modal { padding: 0; }
  .modal-inner { border-radius: 0; min-height: 100vh; max-width: 100%; }
  .m-head { padding: 16px 14px 6px; }
  .m-head .m-title h2 { font-size: 18px; }
  .m-head .m-title small { font-size: 12px; }
  .m-gallery {
    grid-template-columns: 1fr;   /* foto principal a ancho completo, sin thumbs */
    padding: 0 14px;
  }
  .m-gallery img { aspect-ratio: 16/10; }
  .m-gallery img.main { aspect-ratio: 16/10; grid-row: auto; }
  .m-gallery img:not(.main) { display: none; }   /* en móvil, solo la principal */
  .m-body { grid-template-columns: 1fr; gap: 18px; padding: 18px 14px 24px; }
  .m-specs { grid-template-columns: 1fr; gap: 0; }
  .m-equip { padding: 0 14px 24px; }

  /* Modal de novedades */
  .nov-tabs { padding: 0 14px; overflow-x: auto; }
  .nov-tab { padding: 12px 10px; font-size: 12.5px; white-space: nowrap; }
  .nov-content { padding: 14px; }
  .nov-item {
    grid-template-columns: 64px 1fr;   /* foto + info; precio salta abajo */
    gap: 10px;
  }
  .nov-item .nov-price { grid-column: 2; text-align: left; }

  /* Modal de refresh log */
  .refresh-log { margin: 0 14px 18px; font-size: 11px; max-height: 280px; }

  /* Card: la foto un poco más alta proporcionalmente */
  .card .specs { grid-template-columns: 1fr 1fr; }
}
