/* ── Variables ────────────────────────────────────────────── */
:root {
  --green:   #16a34a;
  --green-l: #dcfce7;
  --red:     #dc2626;
  --red-l:   #fee2e2;
  --yellow:  #ca8a04;
  --yellow-l:#fef9c3;
  --bg:      #f8fafc;
  --card:    #ffffff;
  --text:    #1e293b;
  --muted:   #64748b;
  --border:  #e2e8f0;
  --radius:  10px;
  --shadow:  0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ── Layout ───────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }

/* ── Header ───────────────────────────────────────────────── */
header {
  background: var(--green);
  color: #fff;
  padding: .75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.logo { font-size: 1.4rem; font-weight: 800; color: #fff; }
.logo span { opacity: .7; }
nav { margin-left: auto; display: flex; gap: 1rem; align-items: center; }
nav a { color: rgba(255,255,255,.85); font-size: .9rem; }
nav a:hover { color: #fff; }

/* Botón hamburguesa (solo visible en móvil) */
.hamburger {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  padding: .4rem;
  flex-direction: column;
  gap: 5px;
}
.hamburger span {
  display: block;
  width: 24px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform .25s, opacity .25s;
}
/* Menú móvil desplegado */
nav.open {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--green);
  padding: .75rem 1rem 1rem;
  gap: .75rem;
  box-shadow: var(--shadow-md);
  z-index: 999;
  border-top: 1px solid rgba(255,255,255,.2);
}
nav a:hover { color: #fff; text-decoration: none; }

/* ── Ad: banner top ───────────────────────────────────────── */
#ad-banner-top {
  width: 728px; height: 90px;
  background: #f0fdf4;
  border: 1px dashed var(--green);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .8rem;
  margin: .5rem auto;
  max-width: 100%;
}

/* ── Hero ─────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, #15803d 0%, #166534 100%);
  color: #fff;
  padding: 2rem 1rem 1.5rem;
  text-align: center;
}
.hero h1 { font-size: clamp(1.4rem, 4vw, 2.2rem); margin-bottom: .4rem; }
.hero p  { opacity: .85; margin-bottom: 1.5rem; font-size: 1rem; }

/* Fuel selector */
.fuel-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: center;
  margin-bottom: 1.2rem;
}
.fuel-tab {
  padding: .45rem 1rem;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.4);
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: .9rem;
  transition: background .15s, border-color .15s;
}
.fuel-tab.active, .fuel-tab:hover {
  background: rgba(255,255,255,.2);
  border-color: #fff;
}

/* Search bar */
.search-bar {
  display: flex;
  max-width: 520px;
  margin: 0 auto .8rem;
  border-radius: var(--radius);
  /* SIN overflow:hidden — lo necesita el dropdown de autocompletado */
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.search-bar input {
  flex: 1;
  padding: .75rem 1rem;
  border: none;
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: 1rem;
  outline: none;
}
.search-bar button {
  padding: .75rem 1.2rem;
  background: #fff;
  border: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  color: var(--green);
  font-size: 1rem;
}
.btn-location {
  background: rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.5);
  color: #fff;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .9rem;
  transition: background .15s;
}
.btn-location:hover { background: rgba(255,255,255,.25); }

/* ── Stats bar ────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}
.stat-item {
  flex: 1;
  min-width: 140px;
  background: var(--card);
  padding: .8rem 1rem;
  text-align: center;
}
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.stat-value.green { color: var(--green); }
.stat-value.red   { color: var(--red); }
.stat-diff { font-size: .8rem; margin-top: .1rem; }
.stat-diff.up   { color: var(--red); }
.stat-diff.down { color: var(--green); }

/* ── Main layout ──────────────────────────────────────────── */
.main-layout {
  display: flex;
  height: clamp(420px, 65vh, 640px);
  min-height: 420px;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: 360px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.sidebar-header h2 { font-size: .95rem; flex: 1; }
.filter-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .3rem .7rem;
  font-size: .8rem;
  cursor: pointer;
}
.filter-btn:hover { background: var(--border); }

/* Filtros panel */
.filters-panel {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: none;
  flex-direction: column;
  gap: .5rem;
}
.filters-panel.open { display: flex; }
.filters-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.filter-select {
  padding: .3rem .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: .8rem;
  flex: 1;
  min-width: 100px;
}

/* Ad sidebar */
#ad-sidebar {
  width: 300px; height: 250px;
  background: #f0fdf4;
  border: 1px dashed var(--green);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .75rem;
  margin: .5rem auto;
  flex-shrink: 0;
}

/* Lista gasolineras */
.station-list {
  flex: 1;
  overflow-y: auto;
  padding: .5rem;
}
.station-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem;
  margin-bottom: .5rem;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
}
.station-card:hover, .station-card.active {
  box-shadow: var(--shadow-md);
  border-color: var(--green);
}
.station-card-top {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
}
.station-rank {
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 1.2rem;
  padding-top: .1rem;
}
.station-name { font-weight: 600; font-size: .9rem; flex: 1; }
.station-price {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--green);
  white-space: nowrap;
}
.station-price.avg  { color: var(--yellow); }
.station-price.high { color: var(--red); }
.station-info { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.station-dist { font-size: .78rem; color: var(--muted); }
.station-vs {
  font-size: .72rem;
  padding: .1rem .4rem;
  border-radius: 999px;
  display: inline-block;
  margin-top: .2rem;
}
.station-vs.cheap { background: var(--green-l); color: var(--green); }
.station-vs.pricey { background: var(--red-l); color: var(--red); }
.station-affiliate {
  font-size: .72rem;
  color: var(--green);
  border-top: 1px solid var(--border);
  margin-top: .5rem;
  padding-top: .4rem;
}

/* ── Mapa ─────────────────────────────────────────────────── */
#map {
  flex: 1;
  z-index: 1;
  position: relative;
}

/* Leyenda de colores del mapa (control de Leaflet, ver map.js) */
.map-legend {
  background: rgba(255,255,255,.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .5rem .7rem;
  font-size: .76rem;
  line-height: 1.6;
  margin: 0 10px 10px 0;
}
.map-legend-title { font-weight: 700; margin-bottom: .2rem; }
.map-legend-item { display: flex; align-items: center; gap: .4rem; }
.map-legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15);
}

/* Popup Leaflet */
.popup-content { min-width: 160px; }
.popup-price { font-size: 1.4rem; font-weight: 800; color: var(--green); }
.popup-name  { font-weight: 600; font-size: .9rem; margin-bottom: .2rem; }
.popup-btn {
  display: block;
  margin-top: .5rem;
  background: var(--green);
  color: #fff;
  padding: .35rem .7rem;
  border-radius: var(--radius);
  text-align: center;
  font-size: .85rem;
}

/* ── Loading overlay ──────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
#loading-overlay.hidden { display: none; }
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin-bottom: 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Cache warning banner ─────────────────────────────────── */
#cache-warning {
  background: #fef3c7;
  border-bottom: 1px solid #f59e0b;
  padding: .4rem 1rem;
  text-align: center;
  font-size: .82rem;
  display: none;
}

/* ── Footer ───────────────────────────────────────────────── */
#ad-footer {
  width: 728px; height: 90px;
  background: #f0fdf4;
  border: 1px dashed var(--green);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .8rem;
  margin: 1rem auto 0;
  max-width: 100%;
}
footer {
  background: var(--text);
  color: rgba(255,255,255,.7);
  text-align: center;
  padding: 1rem;
  font-size: .82rem;
  margin-top: .5rem;
}
footer a { color: rgba(255,255,255,.7); }

/* ── Ficha gasolinera ─────────────────────────────────────── */
.ficha-header {
  background: var(--card);
  padding: 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.ficha-header h1 { font-size: 1.4rem; margin-bottom: .2rem; }
.ficha-brand { color: var(--muted); font-size: .9rem; }
.prices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .75rem;
  padding: 1rem;
}
.price-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.price-card-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.price-card-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--green);
  margin: .2rem 0;
}
.price-card-value.null { color: var(--muted); font-size: 1rem; }
.price-card-diff { font-size: .75rem; }
.chart-container { background: var(--card); padding: 1rem; border-radius: var(--radius); margin: 1rem; box-shadow: var(--shadow); }
.chart-title { font-size: 1rem; font-weight: 600; margin-bottom: .75rem; }
.nearby-section { padding: 1rem; }
.nearby-section h2 { font-size: 1rem; font-weight: 600; margin-bottom: .75rem; }

/* ── Autocomplete ─────────────────────────────────────────── */
.autocomplete-dropdown {
  position: absolute;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 2000;
  max-height: 240px;
  overflow-y: auto;
  width: 100%;
  top: 100%;
  left: 0;
  text-align: left;
}
.autocomplete-item {
  padding: .6rem 1rem;
  cursor: pointer;
  font-size: .9rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.focused { background: var(--bg); }
.autocomplete-item small { display: block; color: var(--muted); font-size: .75rem; }
.search-wrap { position: relative; flex: 1; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .main-layout { flex-direction: column-reverse; height: auto; }
  #map { height: 60vw; min-height: 300px; }
  .sidebar { width: 100%; height: auto; border-right: none; border-top: 1px solid var(--border); }
  .station-list { max-height: 40vh; }
  #ad-sidebar { display: none; }
  #ad-banner-top, #ad-footer { width: 100%; height: 60px; }
  .stats-bar .stat-item:nth-child(n+4) { display: none; }
  nav { display: none; }
  nav.open { display: flex; }
  .hamburger { display: flex; }
}

/* ── Utilidades ───────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
}
.badge-green  { background: var(--green-l); color: var(--green); }
.badge-red    { background: var(--red-l);   color: var(--red);   }
.badge-yellow { background: var(--yellow-l);color: var(--yellow);}
.text-muted   { color: var(--muted); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.flex { display: flex; }
.gap-1 { gap: .5rem; }
.align-center { align-items: center; }

/* ── Ruta comparador ──────────────────────────────────────── */
.route-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
  box-shadow: var(--shadow);
}
.route-inputs { display: flex; gap: .5rem; flex-wrap: wrap; }
.route-inputs input {
  flex: 1; min-width: 160px;
  padding: .6rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
}
.btn-primary {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: .6rem 1.2rem;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: #15803d; }
