/* ============ Tokens ============ */
:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f4f7fa;
  --ink: #0f1c2e;
  --ink-2: #48586c;
  --muted: #8a97a8;
  --hairline: #e3e9f0;
  --baseline: #c9d3de;
  --brand: #2a78d6;
  --chart: #2a78d6;          /* validado 3:1+ sobre --surface */
  --chart-track: #e8eef5;
  --good-bg: #e7f6ea;  --good-ink: #0e7a33;  --good-dot: #0ca30c;
  --warn-bg: #fdf1df;  --warn-ink: #8a5200;  --warn-dot: #d98a06;
  --bad-bg:  #fdeaea;  --bad-ink:  #a32c2c;  --bad-dot:  #d03b3b;
  --shadow: 0 1px 2px rgba(15, 28, 46, .05), 0 10px 30px rgba(15, 28, 46, .08);
  --radius: 20px;
  --ring-track: rgba(255, 255, 255, .25);
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #16202f;
  --surface-2: #1d2939;
  --ink: #f2f6fb;
  --ink-2: #b8c4d4;
  --muted: #7e8b9d;
  --hairline: #26334a;
  --baseline: #34445e;
  --brand: #3987e5;
  --chart: #3987e5;          /* validado 3:1+ sobre --surface oscura */
  --chart-track: #243349;
  --good-bg: rgba(46, 190, 100, .14);  --good-ink: #5fd688;
  --warn-bg: rgba(230, 160, 30, .14);  --warn-ink: #f3b64b;
  --bad-bg:  rgba(220, 80, 80, .14);   --bad-ink:  #ef7d7d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --surface: #16202f;
    --surface-2: #1d2939;
    --ink: #f2f6fb;
    --ink-2: #b8c4d4;
    --muted: #7e8b9d;
    --hairline: #26334a;
    --baseline: #34445e;
    --brand: #3987e5;
    --chart: #3987e5;
    --chart-track: #243349;
    --good-bg: rgba(46, 190, 100, .14);  --good-ink: #5fd688;
    --warn-bg: rgba(230, 160, 30, .14);  --warn-ink: #f3b64b;
    --bad-bg:  rgba(220, 80, 80, .14);   --bad-ink:  #ef7d7d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

/* ============ Base ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  transition: background .3s ease;
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px clamp(14px, 4vw, 24px) 32px;
  padding-top: max(16px, env(safe-area-inset-top));
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: var(--brand); }

/* ============ Topbar ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  font-size: 26px;
  border-radius: 14px;
  background: linear-gradient(140deg, #2a78d6, #1c5cab);
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.brand-text h1 { font-size: clamp(17px, 4.5vw, 21px); font-weight: 800; letter-spacing: -.02em; }
.brand-text p { font-size: 12.5px; color: var(--muted); margin-top: -2px; }

.topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

.icon-btn {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 18px;
  flex-shrink: 0;
  transition: transform .15s ease;
}
.icon-btn:active { transform: scale(.92); }

.lang-btn { font-size: 13px; font-weight: 800; letter-spacing: .04em; color: var(--brand); }

/* ============ Búsqueda ============ */
.search-row { display: flex; gap: 10px; margin-bottom: 16px; }

.search-box { position: relative; flex: 1; }

.search-icon {
  position: absolute; left: 14px; top: 50%;
  translate: 0 -50%;
  font-size: 14px; opacity: .55;
  pointer-events: none;
}

#searchInput {
  width: 100%;
  padding: 13px 16px 13px 40px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  box-shadow: var(--shadow);
  outline: none;
  transition: border-color .15s ease;
}
#searchInput:focus { border-color: var(--brand); }
#searchInput::placeholder { color: var(--muted); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  z-index: 30;
  list-style: none;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--hairline);
}

.search-results li {
  padding: 11px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}
.search-results li + li { border-top: 1px solid var(--hairline); }
.search-results li:hover, .search-results li.active { background: var(--surface-2); }
.search-results .r-name { font-weight: 600; }
.search-results .r-meta { font-size: 12px; color: var(--muted); text-align: right; }
.search-results .r-empty { color: var(--muted); cursor: default; justify-content: center; }
.search-results .r-empty:hover { background: none; }

.geo-btn {
  width: 48px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 19px;
  flex-shrink: 0;
  transition: transform .15s ease;
}
.geo-btn:active { transform: scale(.92); }

/* ============ Tarjetas ============ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card h3 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.card-sub { font-size: 12.5px; color: var(--muted); margin: 1px 0 14px; }

.results { display: grid; gap: 14px; }

@media (min-width: 960px) {
  .results {
    grid-template-columns: 1.05fr .95fr;
    grid-template-areas:
      "hero   week"
      "chart  week"
      "best   tip"
      "washes washes";
    align-items: start;
  }
  .hero { grid-area: hero; }
  .week-card { grid-area: week; }
  .chart-card { grid-area: chart; }
  .best-day { grid-area: best; }
  .tip-card { grid-area: tip; }
  .wash-card { grid-area: washes; }
  .wash-grid { grid-template-columns: 1.2fr 1fr; }
}

/* ============ Estados ============ */
.empty-state, .loading-state, .error-state {
  text-align: center;
  padding: 44px 24px;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.empty-icon { font-size: 54px; line-height: 1; }
.empty-state h2, .error-state h2 { font-size: 21px; letter-spacing: -.02em; }
.empty-state p, .error-state p { color: var(--ink-2); max-width: 34ch; }

.btn {
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 700;
  transition: transform .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow); }
.btn-ghost { color: var(--brand); padding: 6px 12px; }

.spinner {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 4px solid var(--chart-track);
  border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state p { color: var(--muted); }

/* ============ Hero / veredicto ============ */
.hero {
  position: relative;
  overflow: hidden;
  color: #fff;
  padding: 20px 22px 18px;
}
.hero.v-yes   { background: linear-gradient(140deg, #0fa76f, #0a7a55); }
.hero.v-maybe { background: linear-gradient(140deg, #dd8d08, #a85e03); }
.hero.v-no    { background: linear-gradient(140deg, #41618f, #263c5e); }

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  position: relative;
  z-index: 2;
}

.hero-loc { font-size: 13px; opacity: .92; font-weight: 600; min-width: 0; }

.share-btn {
  font-size: 12.5px;
  font-weight: 700;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  backdrop-filter: blur(4px);
  flex-shrink: 0;
  transition: background .15s ease;
}
.share-btn:hover { background: rgba(255, 255, 255, .28); }

.hero-main {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  margin: 18px 0 16px;
  position: relative;
  z-index: 2;
}

.hero-icon {
  font-size: 58px;
  line-height: 1;
  animation: float 3.6s ease-in-out infinite;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .2));
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

.verdict-kicker {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .12em;
  opacity: .8;
}

.hero-verdict h2 {
  font-size: clamp(23px, 6vw, 30px);
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.15;
  margin: 2px 0 4px;
}

.hero-verdict p { font-size: 13.5px; opacity: .92; max-width: 36ch; }

/* Anillo del índice */
.score-ring { position: relative; width: 84px; height: 84px; flex-shrink: 0; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--ring-track); stroke-width: 7; }
.ring-fill {
  fill: none;
  stroke: #fff;
  stroke-width: 7;
  stroke-linecap: round;
  stroke-dasharray: 213.6;
  stroke-dashoffset: 213.6;
  transition: stroke-dashoffset .9s cubic-bezier(.22, 1, .36, 1);
}
.ring-label {
  position: absolute; inset: 0;
  display: grid; place-content: center;
  text-align: center;
}
.ring-label strong { font-size: 22px; font-weight: 800; line-height: 1; }
.ring-label span { font-size: 8px; text-transform: uppercase; letter-spacing: .06em; opacity: .85; line-height: 1.3; }

.hero-stats {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  position: relative;
  z-index: 2;
}
.hero-stats li {
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
  backdrop-filter: blur(4px);
}

/* Lluvia animada en el hero */
.rain-fx { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.rain-fx span {
  position: absolute;
  top: -14px;
  width: 2px;
  height: 12px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .35);
  animation: drop 1.4s linear infinite;
}
@keyframes drop {
  to { transform: translateY(280px); opacity: 0; }
}

/* ============ Mejor día ============ */
.best-day {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
}
.best-star { font-size: 26px; flex-shrink: 0; }
.best-day p { font-size: 14px; color: var(--ink-2); }
.best-day b { color: var(--ink); }

/* ============ Gráfica horaria ============ */
.chart-card { position: relative; }

.chart { position: relative; height: 150px; }

.chart-grid {
  position: absolute;
  inset: 0 0 22px 0;
  pointer-events: none;
}
.chart-grid .gl {
  position: absolute; left: 0; right: 0;
  border-top: 1px solid var(--hairline);
}
.chart-grid .gl small {
  position: absolute;
  right: 0; top: -15px;
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chart-grid .gl-base { border-top: 1px solid var(--baseline); }

.chart-bars {
  position: absolute;
  inset: 0 0 22px 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}
.bar-col {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: relative;
  cursor: default;
}
.bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--chart);
  min-height: 2px;
  transition: opacity .12s ease;
}
.bar.bar-zero { background: var(--chart-track); }
.bar-col:hover .bar { opacity: .75; }

.bar-peak {
  position: absolute;
  top: -17px;
  left: 50%;
  translate: -50%;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-x {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 2px;
}
.chart-x span {
  flex: 1;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-tooltip {
  position: absolute;
  z-index: 20;
  padding: 6px 10px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow);
}

/* ============ Semana ============ */
.week-list { list-style: none; }

.week-list li {
  display: grid;
  grid-template-columns: minmax(86px, 1.1fr) 30px 52px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 8px;
  border-radius: 12px;
}
.week-list li + li { border-top: 1px solid var(--hairline); }

.week-list li.is-best {
  background: var(--good-bg);
  border-top-color: transparent;
}
.week-list li.is-best + li { border-top-color: transparent; }

.wd-day { font-weight: 700; font-size: 13.5px; text-transform: capitalize; line-height: 1.2; }
.wd-day small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); text-transform: none; }
.wd-icon { font-size: 20px; text-align: center; }
.wd-pop { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.wd-temp { font-size: 12.5px; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wd-temp b { color: var(--ink); }

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.score-pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.tier-good { background: var(--good-bg); color: var(--good-ink); }
.tier-good .dot { background: var(--good-dot, currentColor); }
.tier-warn { background: var(--warn-bg); color: var(--warn-ink); }
.tier-warn .dot { background: var(--warn-dot, currentColor); }
.tier-bad { background: var(--bad-bg); color: var(--bad-ink); }
.tier-bad .dot { background: var(--bad-dot, currentColor); }
.week-list li.is-best .score-pill { background: var(--surface); }

/* ============ Consejo ============ */
.tip-card p { font-size: 13.5px; color: var(--ink-2); margin-top: 8px; }

/* ============ Lavaderos cercanos ============ */
.wash-grid { display: grid; gap: 14px; }

.wash-map {
  height: 280px;
  border-radius: 14px;
  z-index: 0; /* los controles de Leaflet no deben tapar el dropdown de búsqueda */
  background: var(--surface-2);
}
.wash-map.is-empty { display: none; }

.wash-pin {
  font-size: 20px;
  line-height: 28px;
  text-align: center;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .35));
}

.wash-list ul { list-style: none; }

.wash-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
}
.wash-list li + li { border-top: 1px solid var(--hairline); }

.wl-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-dist { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.wl-dir { font-size: 12.5px; font-weight: 700; white-space: nowrap; text-decoration: none; }
.wl-dir:hover { text-decoration: underline; }

.wash-msg { font-size: 13.5px; color: var(--ink-2); }
.wash-fallback { display: inline-block; margin-top: 12px; text-decoration: none; font-size: 13.5px; }

/* Mapa en modo oscuro: filtro sobre las teselas claras de OSM */
[data-theme="dark"] .wash-map .leaflet-tile {
  filter: brightness(.6) invert(1) contrast(3) hue-rotate(200deg) saturate(.3) brightness(.7);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .wash-map .leaflet-tile {
    filter: brightness(.6) invert(1) contrast(3) hue-rotate(200deg) saturate(.3) brightness(.7);
  }
}

/* ============ Footer ============ */
.footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
  font-size: 12px;
  color: var(--muted);
}
.footer a { color: var(--muted); }

.link-btn {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: var(--brand); }

/* ============ Modal "Acerca de" ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(11, 18, 32, .55);
  backdrop-filter: blur(3px);
  animation: overlay-in .18s ease;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: min(640px, 88vh);
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 24px 22px;
  animation: modal-in .22s cubic-bezier(.22, 1, .36, 1);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 32px; height: 32px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
  color: var(--ink-2);
  transition: background .15s ease;
}
.modal-close:hover { background: var(--hairline); }

.modal-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-right: 30px;
  margin-bottom: 18px;
}
.modal-brand h2 { font-size: 19px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.modal-brand p { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.modal-section { padding: 16px 0; border-top: 1px solid var(--hairline); }
.modal-section:first-of-type { border-top: 1px solid var(--hairline); }
.modal-section h3 { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.modal-section p { font-size: 13.5px; color: var(--ink-2); line-height: 1.6; }

.about-steps {
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: 10px;
}
.about-steps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.5;
}
.about-steps li::before {
  content: counter(step);
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.author-card { border-bottom: none; }
.author-name { font-size: 15px; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
.author-links { display: flex; flex-wrap: wrap; gap: 10px; }
.author-links a {
  font-size: 13px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
  transition: background .15s ease;
}
.author-links a:hover { background: var(--hairline); }

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  translate: -50%;
  z-index: 100;
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in .25s ease;
}
@keyframes toast-in {
  from { opacity: 0; translate: -50% 12px; }
  to { opacity: 1; translate: -50% 0; }
}

/* ============ Animación de entrada ============ */
.results > .card {
  animation: rise .45s cubic-bezier(.22, 1, .36, 1) backwards;
}
.results > .card:nth-child(2) { animation-delay: .06s; }
.results > .card:nth-child(3) { animation-delay: .12s; }
.results > .card:nth-child(4) { animation-delay: .18s; }
.results > .card:nth-child(5) { animation-delay: .24s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ Movimiento reducido ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ============ Móvil pequeño ============ */
@media (max-width: 400px) {
  .hero-main { grid-template-columns: auto 1fr; }
  .score-ring { grid-column: 1 / -1; justify-self: center; }
  .week-list li { grid-template-columns: minmax(76px, 1fr) 26px 46px 1fr auto; gap: 6px; padding: 10px 4px; }
}
