/* --- Variables (tema oscuro por defecto) --- */
:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #243044;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3b9b7a;
  --accent-light: #52c99d;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --tooltip-bg: rgba(26, 35, 50, 0.95);
  --tooltip-border: rgba(255, 255, 255, 0.12);
}

/* --- Tema claro --- */
body.theme-light {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-hover: #e8ecf1;
  --text: #1a2332;
  --text-muted: #5a6578;
  --border: rgba(0, 0, 0, 0.1);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --tooltip-bg: rgba(255, 255, 255, 0.98);
  --tooltip-border: rgba(0, 0, 0, 0.15);
}

body.theme-light .station-error,
body.theme-light .error {
  color: #b84a4a;
  border-color: rgba(180, 70, 70, 0.35);
}

body.theme-light .theme-toggle {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

body.theme-light .theme-toggle:hover {
  background: var(--surface-hover);
}

/* --- Reset y base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* --- Layout app --- */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.25rem;
  width: 100%;
}

/* --- Header --- */
.header {
  text-align: center;
  margin-bottom: 2rem;
  position: relative;
}

.header h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.location {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 400;
}

.theme-toggle-wrap {
  position: absolute;
  top: 0;
  right: 0;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  font-family: var(--font);
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.theme-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.theme-toggle svg {
  width: 1.1rem;
  height: 1.1rem;
  opacity: 0.9;
}

/* --- Main --- */
.main {
  flex: 1;
}

/* --- Estación local --- */
.station {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 2rem;
}

.station-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

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

.station-error {
  color: #e8a0a0;
}

.station-error code {
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

.station-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem 1.25rem;
}

.station-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

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

.station-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

@media (min-width: 600px) {
  .station-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 900px) {
  .station-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* --- Histórico de hoy --- */
.history-section {
  margin-bottom: 2rem;
}

.history-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 1rem;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow: hidden;
}

.history-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.history-card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.history-chart-wrap {
  width: 100%;
  height: 200px;
  position: relative;
}

.history-chart-wrap canvas {
  display: block;
}

/* --- Error --- */
.error {
  background: var(--surface);
  border: 1px solid rgba(220, 80, 80, 0.3);
  color: #e8a0a0;
  padding: 1.5rem;
  border-radius: var(--radius);
  text-align: center;
}

/* --- Forecast --- */
.forecast {
  margin-bottom: 2rem;
}

.forecast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: background 0.2s, border-color 0.2s, grid-column 0.25s ease, padding 0.25s ease;
  cursor: pointer;
}

.card:hover {
  background: var(--surface-hover);
  border-color: rgba(255, 255, 255, 0.12);
}

.card--expanded {
  grid-column: 1 / -1;
  padding: 1.5rem;
}

/* --- Polen --- */
.pollen-section {
  margin-bottom: 2rem;
}

.pollen-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 0.35rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.pollen-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.pollen-error {
  color: #e8a0a0;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.pollen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.pollen-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.pollen-card-date {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.pollen-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
}

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

.pollen-type {
  color: var(--text-muted);
}

.pollen-value {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.pollen-attribution {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

.pollen-attribution a {
  color: var(--accent-light);
  text-decoration: none;
}

.pollen-attribution a:hover {
  text-decoration: underline;
}

@media (min-width: 900px) {
  .pollen-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1200px) {
  .pollen-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.card-date {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.card-weather {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.card-weather-emoji {
  font-size: 1.5rem;
  line-height: 1;
}

.card-weather-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.card-temp {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 1rem;
  letter-spacing: -0.03em;
}

.card-temp span {
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-muted);
}

.card-details {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.card-detail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.card-detail strong {
  color: var(--text);
  font-weight: 600;
  margin-left: 0.5rem;
}

/* --- Pronóstico por horas: gráfico (tarjeta expandida) --- */
.card-hourly {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.card-hourly-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 0.75rem;
}

.hourly-chart-wrap {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.15);
  padding: 0.75rem;
}

.hourly-chart {
  width: 100%;
  height: auto;
  min-height: 180px;
  display: block;
}

.chart-grid-line {
  stroke: var(--border);
  stroke-width: 0.5;
}

.chart-axis-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-family: var(--font);
}

.chart-axis-y {
  font-size: 9px;
}

.chart-axis-x {
  font-size: 9px;
}

.chart-line {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  fill: var(--accent);
}

.chart-emoji {
  font-size: 10px;
  pointer-events: none;
}

/* --- Diagramas externos --- */
.diagrams-section {
  margin-top: 2rem;
  margin-bottom: 2rem;
}

.diagrams-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.diagram-link,
.diagram-slot {
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.diagram-link {
  display: block;
  height: 100%;
  min-height: 0;
  text-decoration: none;
  transition: border-color 0.2s, background 0.2s;
}

.diagram-link:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.diagram-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.diagram-slot {
  background: var(--surface);
}

.diagram-iframe-wrap {
  padding: 0;
}

.diagram-iframe {
  width: 100%;
  height: 100%;
  min-height: 200px;
  border: none;
  display: block;
}

@media (max-width: 600px) {
  .diagrams-row {
    grid-template-columns: 1fr;
  }
}

/* --- Footer --- */
.footer {
  text-align: center;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer a {
  color: var(--accent-light);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* --- Responsive: móvil pequeño --- */
@media (max-width: 380px) {
  .app {
    padding: 1rem;
  }

  .forecast-grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 1rem;
  }

  .card-temp {
    font-size: 1.5rem;
  }
}

/* --- Responsive: tablet y desktop --- */
@media (min-width: 600px) {
  .forecast-grid {
    gap: 1.25rem;
  }

  .card {
    padding: 1.5rem;
  }

  .card-temp {
    font-size: 2rem;
  }
}

@media (min-width: 900px) {
  .forecast-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .history-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1400px) {
  .app {
    padding: 1.25rem 1rem;
  }
}
