/* Atlas Solar del Perú — tema oscuro. Tokens de color validados (dataviz). */
:root {
  --page: #0a0a0e;
  --surface: #101015;          /* superficie de tarjetas y gráficos (validada) */
  --surface-2: #16161d;
  --border: rgba(255, 255, 255, 0.10);
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --series-1: #3987e5;         /* azul   — global horizontal */
  --series-2: #199e70;         /* aqua   — difusa */
  --series-3: #c98500;         /* ámbar  — directa */
  --series-4: #9085e9;         /* violeta — plano inclinado */
  --accent: #ffc233;
  --good: #0ca30c;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--series-1); }

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 8px;
  flex-wrap: wrap;
}

.app-header h1 { margin: 0; font-size: 1.5rem; }
.subtitle { margin: 4px 0 0; color: var(--text-secondary); font-size: 0.9rem; }

.header-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  white-space: nowrap;
}
.header-status.ok { color: var(--good); border-color: rgba(12, 163, 12, 0.4); }
.header-status.warn { color: #ec835a; border-color: rgba(236, 131, 90, 0.4); }

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

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.card-head h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.hint { color: var(--text-muted); font-size: 0.75rem; }

/* ── Controles ─────────────────────────────────────────── */
.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px 16px;
  margin: 12px 24px;
}

.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-group label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.value-badge {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

select, input[type="number"] {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  width: 100%;
}
select:focus, input:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }

input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
  margin: 8px 0 2px;
}

.control-actions {
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.ghost-btn:disabled { opacity: 0.5; cursor: wait; }
.ghost-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(255, 194, 51, 0.4);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}
.ghost-btn:hover { background: rgba(255, 194, 51, 0.1); }

/* ── Layout principal ──────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(220px, 1fr);
  gap: 16px;
  margin: 0 24px 16px;
}

.scene-card { display: flex; flex-direction: column; }
.scene-canvas {
  width: 100%;
  height: 460px;
  border-radius: 8px;
  overflow: hidden;
  background: #05060d;
  position: relative;
}
.scene-canvas canvas { display: block; }

.scene-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.play-btn {
  background: var(--accent);
  color: #201500;
  border: none;
  border-radius: 999px;
  width: 38px;
  height: 38px;
  font-size: 0.95rem;
  cursor: pointer;
  flex: none;
}

.scene-controls input[type="range"] { flex: 1; }

.time-readout { display: flex; flex-direction: column; align-items: flex-end; min-width: 150px; }
.time-label { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.sun-readout { font-size: 0.72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.live-btn { padding: 6px 12px; flex: none; color: var(--text-secondary); border-color: var(--border); }
.live-btn.active {
  color: #ff5c5c;
  border-color: rgba(255, 92, 92, 0.5);
  animation: livePulse 1.6s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 92, 92, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(255, 92, 92, 0); }
}

/* Irradiancia a la hora seleccionada */
.instant-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.instant-bar .chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.instant-bar .chip b { color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 600; }
.instant-bar .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.level-badge {
  margin-left: auto;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}
.level-badge.level-night { color: #898781; border-color: rgba(137, 135, 129, 0.5); }
.level-badge.level-low { color: #0ca30c; border-color: rgba(12, 163, 12, 0.5); }
.level-badge.level-mod { color: #fab219; border-color: rgba(250, 178, 25, 0.5); }
.level-badge.level-high { color: #ec835a; border-color: rgba(236, 131, 90, 0.5); }
.level-badge.level-crit { color: #d03b3b; border-color: rgba(208, 59, 59, 0.55); }

.accent-datum { color: var(--accent); font-weight: 600; cursor: help; }

/* ── Tiles de estadísticas ─────────────────────────────── */
.stats-column { display: flex; flex-direction: column; gap: 12px; }

.stat-tile { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; flex: 1; }
.stat-label { font-size: 0.72rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.7rem; font-weight: 700; }
.stat-value-small { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat-unit { font-size: 0.72rem; color: var(--text-muted); }
.stat-delta { color: var(--good); font-weight: 600; }
.stat-delta.neg { color: #e66767; }

/* ── Gráficos ──────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  margin: 0 24px 16px;
}

.chart-holder { position: relative; height: 300px; }

/* ── Mapa ──────────────────────────────────────────────── */
.map-holder { display: flex; gap: 16px; align-items: stretch; }
#peruMap {
  width: min(100%, 460px);
  height: auto;
  border-radius: 8px;
  cursor: crosshair;
  background: var(--surface-2);
}
.map-legend {
  display: flex;
  flex-direction: column-reverse;
  justify-content: center;
  gap: 2px;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.map-legend .swatch { display: flex; align-items: center; gap: 6px; }
.map-legend .swatch i { width: 18px; height: 14px; border-radius: 3px; display: inline-block; }

.info-body { color: var(--text-secondary); font-size: 0.88rem; }
.info-body p { margin: 0 0 10px; }
.info-body strong { color: var(--text-primary); }
.fine-print { color: var(--text-muted); font-size: 0.75rem; }

.app-footer {
  margin: 8px 24px 24px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .stats-column { flex-direction: row; flex-wrap: wrap; }
  .stat-tile { min-width: 150px; }
  .scene-canvas { height: 360px; }
  .scene-controls { flex-wrap: wrap; }
  .scene-controls input[type="range"] { flex: 1 1 100%; order: 3; }
  .time-readout { margin-left: auto; min-width: 0; }
  .level-badge { margin-left: 0; flex-basis: 100%; text-align: center; }
}
