/* ============================================================================
   VARIABLES Y RESET
   ============================================================================ */
:root {
  --bg1: #001933;
  --bg2: #660000;
  --accent: #ff6600;
  --card: rgba(255, 255, 255, 0.06);
  --white-05: rgba(255, 255, 255, 0.05);
  --white-1: rgba(255, 255, 255, 0.1);
  --white-15: rgba(255, 255, 255, 0.15);
  --black-25: rgba(0, 0, 0, 0.25);
}

/* Reset global: * ya cubre margin/padding, así que no hace falta
   repetirlo en html/body (evita reglas redundantes). */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden; /* evita scroll horizontal si algo se desborda por error */
}

body {
  font-family: system-ui, Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  color: white;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 16px;
}

.main-container,
#mainContainer,
.container-main,
.app-container {
  flex: 1;
  width: 100%;
}

/* ============================================================================
   TABS — visibilidad de pestañas
   ============================================================================ */
.tab-content        { display: none; }
.tab-content.active { display: block; }

/* Oculta el botón de la pestaña "info": el contenido se accede solo
   desde el link del footer, no queremos un tab visible para ella. */
.tab-btn[data-tab="info"] { display: none; }

.tabs-header {
  display: flex;
  gap: 5px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--white-1);
  padding-bottom: 6px;
}

.tab-btn {
  background: var(--white-05);
  border: none;
  border-radius: 8px;
  color: #ccc;
  padding: 8px 20px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.3s ease;
  flex: 1;
  min-width: 120px;
  text-align: center;
}
.tab-btn:hover { background: var(--white-1); color: white; }
.tab-btn.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 12px rgba(255, 102, 0, 0.3);
}

/* ============================================================================
   TÍTULOS Y ENCABEZADOS
   ============================================================================ */
.title-container {
  text-align: center;
  margin: 10px 0 12px;
  padding: 0 15px;
}

.title {
  font: 900 4rem 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(90deg, #FF5F00, #FF2D95, #FF0000);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.subtitle {
  font: 300 1.6rem 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: #FFB6C1;
  margin-top: -5px;
  letter-spacing: 8px;
  opacity: 0.8;
}

.gradient-text {
  background: linear-gradient(90deg, #FF5F00, #FF2D95, #FF0000);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 900;
}

h1, h2 { margin: 0 0 4px 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.3rem; color: var(--accent); margin-bottom: 8px; }

/* Animación de gradiente en el título "🍀" (efecto trébol/arrebol) */
.trebol-arebol {
  background: linear-gradient(
    290deg,
    #1b5e20, #2e7d32, #4caf50, #81c784, #a5d6a7, #c8e6c9,
    #a5d6a7, #81c784, #4caf50, #2e7d32,
    #f06292, #ff8a65, #ff5722, #e53935, #ff5722, #ff8a65, #f06292,
    #2e7d32, #4caf50, #81c784, #a5d6a7, #c8e6c9,
    #a5d6a7, #81c784, #4caf50, #2e7d32, #1b5e20
  );
  background-size: 500% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-block;
  animation: arrebolShift 16s ease-in-out infinite;
}

@keyframes arrebolShift {
  0%   { background-position: 0% 50%; }
  35%  { background-position: 15% 50%; }
  45%  { background-position: 30% 50%; }
  52%  { background-position: 45% 50%; }
  58%  { background-position: 55% 50%; }
  65%  { background-position: 65% 50%; }
  75%  { background-position: 80% 50%; }
  85%  { background-position: 92% 50%; }
  100% { background-position: 100% 50%; }
}

/* ============================================================================
   CONTENEDORES Y ESTRUCTURA
   ============================================================================ */
.container, .tabs-container {
  max-width: 1000px;
  margin: 0 auto 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 14px;
  padding: 5px;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.5);
}

.panel {
  background: var(--card);
  padding: 5px;
  border-radius: 10px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 16px;
  align-items: start;
}

.data-block {
  background: var(--white-05);
  border-radius: 12px;
  padding: 8px;
  margin: 8px 0;
}

/* ============================================================================
   TOGGLE AMANECER / ATARDECER
   ============================================================================ */
.prediction-toggle {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 6px 0;
}
.prediction-toggle button {
  padding: 5px 12px;
  border-radius: 25px;
  border: none;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  line-height: 1.5;
  font-size: 0.85rem;
  min-height: 0;
  transition: all 0.2s ease;
}
.prediction-toggle button.active {
  background: #ff6b35;
  color: white;
}
@media (max-width: 480px) {
  .prediction-toggle button {
    padding: 4px 10px;
    font-size: 0.78rem;
  }
}

/* Botones toggle genéricos (ej. "Ver contribuciones" / "Ver incerteza") */
.toggle-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 6px 14px;
  color: white;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.3s ease;
}
.toggle-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}
.toggle-btn.active {
  background: rgba(255, 165, 0, 0.2);
  border-color: rgba(255, 165, 0, 0.4);
}

/* ============================================================================
   TARJETAS DE CIUDADES/OBSERVATORIOS
   ============================================================================ */
/* Ciudades: grid fijo de 4 columnas, se bajan a 3 y luego a 2 a medida que hay menos espacio horizontal. */
#cityMenu {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 8px 15px;
}

.city-card {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  text-align: left;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  overflow: hidden;
}

#observatoryMenu .city-card { width: 100%; margin: 0; }
#observatoryMenu .city-card:hover { transform: translateY(-2px); }

.city-card:hover {
  transform: translateY(-4px);
  background: rgba(255, 255, 255, 0.1);
}

/* Fila superior: región + nombre a la izquierda, % a la derecha */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  min-width: 0; /* mismo motivo que en .city-card */
}

.card-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1 1 auto;
  min-width: 0;
}

.card-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.city-region {
  font-size: 0.6rem;
  font-weight: 400;
  opacity: 0.5;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

.probability-big {
  font-size: 1.7rem;
  font-weight: 400;
  line-height: 1;
}

.probability-uncertainty {
  font-size: 0.65rem;
  opacity: 0.6;
  margin-top: 1px;
}

/* Nombre: fila propia que reclama todo el espacio vertical libre
   (flex: 1 1 auto, ya que .city-card es flex-column), quedando
   centrada entre el header (%) y el meta (hora/visibilidad). */
.city-name-row {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.05;
  padding: 0;
}

.city-name {
  font-weight: 500;
  line-height: 1.2;
  white-space: normal;
  word-break: keep-all;    /* nunca parte una palabra a la mitad */
  overflow-wrap: normal;
  display: -webkit-box;
  -webkit-line-clamp: 1;   /* si no cabe en 1 línea, se corta ahí (ver escalones abajo) */
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Escalones de tamaño según el largo del nombre (aplicados vía JS) */
.city-name--lg { font-size: 1.2rem; }
.city-name--md { font-size: 0.95rem; }
.city-name--sm { font-size: 0.78rem; }
.city-name--xs { font-size: 0.68rem; }

.card-meta {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.meta-row {
  font-size: 0.75rem;
  opacity: 0.75;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* aceptable acá: es texto secundario (hora/visibilidad) */
}

.probability-bar {
  height: 6px;
  border-radius: 3px;
  margin-top: 2px;
  background: linear-gradient(90deg, #4CAF50, #FFC107, #F44336);
  transition: width 0.4s ease;
}

/* Observatorios: mismo grid que ciudades, con scroll propio si la
   lista es más larga que el alto disponible del panel. */
#observatoryMenu {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* default: 2 columnas cuando el mapa ocupa la mitad del ancho */
  gap: 12px;
  padding: 20px 10px 20px 0;
  overflow-y: auto;
  max-height: 100%;
}

#observatoryMenu::-webkit-scrollbar { width: 6px; }
#observatoryMenu::-webkit-scrollbar-track {
  background: var(--white-1);
  border-radius: 3px;
}
#observatoryMenu::-webkit-scrollbar-thumb {
  background: rgba(255, 152, 0, 0.5);
  border-radius: 3px;
}
#observatoryMenu::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 152, 0, 0.7);
}

/* ============================================================================
   CONTENIDO PRINCIPAL (vista detallada de una ciudad/observatorio)
   ============================================================================ */
#appContainer {
  display: none;
  padding: 8px;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

.main-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}

#cityTitle {
  display: flex;
  align-items: center;
  gap: 10px;
}

button.back {
  background: transparent;
  border: 1px solid var(--white-15);
  border-radius: 8px;
  color: white;
  padding: 8px 15px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 1rem;
}

/* ============================================================================
   TEXTO DESTACADO (intro / lead)
   ============================================================================ */
.lead, .lead-with-bg, p.lead {
  margin: 0 auto 10px;
  max-width: calc(100% - 40px);
  opacity: 0.95;
  font-size: 0.95rem;
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid var(--white-15);
  line-height: 1.7;
  box-shadow:
    0 6px 20px var(--black-25),
    inset 0 1px 1px var(--white-1);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(8px);
  color: white;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.lead { background: linear-gradient(135deg, rgba(0, 25, 51, 0.7), rgba(102, 0, 0, 0.5)); }
.lead-with-bg {
  background:
    linear-gradient(rgba(0, 25, 51, 0.75), rgba(102, 0, 0, 0.65)),
    url('https://as2.ftcdn.net/jpg/04/31/52/97/220_F_431529701_P3LDLj8D32MgRZZ565xmaJaVByjifQ8v.jpg') center/cover no-repeat;
  min-height: 180px;
  display: flex;
  align-items: center;
  backdrop-filter: blur(2px);
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.lead-content { position: relative; z-index: 2; width: 100%; }

.lead:after, .lead-with-bg:after {
  content: "ⓘ";
  position: absolute;
  top: 12px; right: 15px;
  opacity: 0.5;
  font-size: 0.9rem;
  z-index: 3;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* Override específico para p.lead: más compacto y sin fondo/blur del lead genérico */
p.lead {
  margin: 0 0 8px;
  padding: 12px 20px;
  background: var(--white-05);
  box-shadow: none;
  backdrop-filter: none;
}

/* ============================================================================
   GRID DE DATOS METEOROLÓGICOS
   ============================================================================ */
.data-grid {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px !important;
  margin-top: 6px !important;
  width: 100% !important;
}

.data-item {
  background: #2a2a2a;
  padding: 8px;
  border-radius: 6px;
  font-size: 14px;
}

.sun-times {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
  margin: 3px 0;
}

.sun-time {
  background: rgba(255, 255, 255, 0.04);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
}

.sun-time-clouds {
  font-size: 1rem;
  font-weight: 600;
  opacity: 0.85;
  margin-top: 3px;
}

/* ============================================================================
   PREDICCIONES (amanecer/atardecer, vista detallada)
   ============================================================================ */
.predictions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.probability {
  font-size: 32px;
  font-weight: bold;
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  margin-top: 6px;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  line-height: 1.2;
}
.probability span { font-size: 40px; }
.high-prob   { background: rgba(255, 204, 0, 0.18); color: #ffd24d; }
.medium-prob { background: rgba(255, 153, 102, 0.12); color: #ffb07a; }
.low-prob    { background: rgba(204, 102, 51, 0.12); color: #e09b79; }

.probability .mc-percent {
  font-size: 2.2rem !important;
  font-weight: bold;
  line-height: 1.1;
}

#result { min-height: 0px; }
#log {
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 8px;
  font-size: 0.8rem;
  max-height: 100px;
  overflow-y: auto;
  margin-top: 6px;
  white-space: pre-wrap;
}

/* ============================================================================
   INCERTEZA MONTE CARLO
   ============================================================================ */
.uncertainty-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 8px;
}
.uncertainty-high   { background: #F44336; color: white; }
.uncertainty-medium { background: #FFC107; color: #333; }
.uncertainty-low    { background: #4CAF50; color: white; }

.confidence-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin: 6px 0;
  position: relative;
  overflow: hidden;
}
.confidence-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}
.confidence-bar-marker {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 10px;
  background: white;
  border-radius: 1px;
  transform: translateX(-50%);
}

.mc-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  gap: 15px;
  margin-top: 6px;
  width: 100%;
}
.mc-box {
  min-width: 0;
  padding: 15px;
  border-radius: 12px;
}
.mc-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  width: 100%;
}
.mc-unc { opacity: 0.7; }

@media (max-width: 600px) {
  .probability .mc-percent { font-size: 1.6rem !important; }
  .mc-grid { gap: 8px; }
  .mc-box { padding: 10px; }
}

/* ============================================================================
   CONTROLES Y FORMULARIOS
   ============================================================================ */
.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0;
}

select, button, input, textarea {
  padding: 12px;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  min-height: 44px;
}

select, input {
  background: var(--white-05);
  color: #fff;
  width: 100%;
}

button {
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  flex: 1;
  min-width: 140px;
}

.map-toggle {
  background: rgba(0, 0, 0, 0.8);
  color: white;
  border: none;
  padding: 8px;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.map-toggle.active { background: #4CAF50; }

/* ============================================================================
   DÍA SELECTOR
   ============================================================================ */
.day-selector {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr)); /* minmax(0,..): permite que la columna se achique de verdad */
  gap: 3px;
  margin: 6px 0 4px;
  width: 100%;
  box-sizing: border-box;
}
/* Especificidad #daySelector .day-btn (id + clase) para ganarle a
   cualquier regla tipo ".tabs-container button" del CSS externo, que
   tiene más especificidad que un simple ".day-btn" y por eso el padding
   no se aplicaba antes. */
#daySelector.day-selector .day-btn {
  min-width: 2px !important;   /* clave: sin esto el botón nunca se achica más que su texto */
  box-sizing: border-box !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 2px !important;
  padding: 0 2px !important;
  height: 35px !important;
  min-height: 0 !important;
  max-height: 35px !important;
  border-radius: 6px !important;
  border: 1px solid rgba(255,255,255,0.15) !important;
  background: rgba(255,255,255,0.05) !important;
  color: #fff !important;
  cursor: pointer !important;
  overflow: hidden !important;
  line-height: 1 !important;
  font-family: inherit !important;
  transition: background 0.15s ease;
}
#daySelector.day-selector .day-btn:hover { background: rgba(255,255,255,0.12) !important; }
#daySelector.day-selector .day-btn.active {
  background: linear-gradient(135deg, #ff6600, #ff9800) !important;
  border-color: transparent !important;
  font-weight: 600 !important;
}

.day-btn-top {
  font-size: 0.5rem;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  opacity: 0.85;
}
.day-btn-bottom {
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.1;
}

.day-selector--locked {
  opacity: 0.5;
  pointer-events: none;   /* refuerzo visual/táctil: ni el hover responde */
}
.day-selector--locked .day-btn.active::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: dayBtnPulse 0.9s ease-in-out infinite;
}
@keyframes dayBtnPulse {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}

/* ============================================================================
   GRÁFICOS
   ============================================================================ */
.charts {
  display: flex;
  flex-direction: column;
  margin-top: 8px;
  height: 400px;
  width: 100%;
  position: relative;
  overflow: hidden;
}

canvas {
  background: var(--white-05);
  border-radius: 12px;
  padding: 8px;
  max-width: 100%;
  flex: 1;
  min-height: 0;
  width: 100% !important;
  height: 100% !important;
}

.chart-time-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin: 3px 0 6px;
  padding: 6px 12px;
  background: var(--white-05);
  border-radius: 8px;
  border: 1px solid var(--white-1);
  font-size: 0.85rem;
  z-index: 5;
  order: 1;
}

.irr-cell {
  font-size: 0.75rem;
  white-space: nowrap;
}
.irr-cell .subline {
  display: block;
  font-size: 0.62rem;
  opacity: 0.6;
}

/* ============================================================================
   MAPA Y LEYENDA
   ============================================================================ */
.map-wrapper {
  position: relative;
  height: 662px !important;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  margin: 6px 0;
}

#map, #observatoriesMap {
  height: 100% !important;
  width: 100% !important;
}

.observatories-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 8px;
  height: calc(100vh - 120px);
  min-height: 700px;
}

.map-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.map-loading {
  display: none;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px;
  border-radius: 8px;
}

.probability-legend {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 0.8rem;
  z-index: 1000;
  min-width: 250px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.legend-title { margin-bottom: 8px; font-weight: bold; }

.legend-gradient {
  height: 8px;
  width: 100%;
  background: linear-gradient(to right, #2b83ba, #abdda4, #ffffbf, #fdae61, #d7191c);
  margin-bottom: 8px;
  border-radius: 6px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  opacity: 0.9;
}

.map-legend {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.7);
  padding: 8px 12px;
  border-radius: 6px;
  color: white;
  font-size: 0.85rem;
}

.observatory-icon {
  background: transparent !important;
  border: none !important;
}
.observatory-popup .leaflet-popup-content {
  min-width: 200px !important;
}

/* ============================================================================
   CÁMARA METEOROLÓGICA
   ============================================================================ */
.weather-camera-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #2c3e50, #1a1a2e);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 8px 16px;
  margin: 10px 0;
  color: white;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.3s ease;
}
.weather-camera-btn:hover {
  background: linear-gradient(135deg, #3e5a6b, #2a2a3e);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.weather-camera-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
}
.weather-camera-modal.active { display: flex; }

.weather-camera-content {
  background: #1e1e2e;
  border-radius: 20px;
  width: 90%;
  max-width: 1200px;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: modalSlideIn 0.3s ease;
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(-30px); }
  to   { opacity: 1; transform: translateY(0); }
}

.weather-camera-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: linear-gradient(135deg, #2c3e50, #1a1a2e);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.weather-camera-header h3 { color: white; font-size: 1.2rem; }

.close-camera {
  background: none;
  border: none;
  color: white;
  font-size: 28px;
  cursor: pointer;
  padding: 0 8px;
  transition: all 0.2s;
}
.close-camera:hover { color: #ff6b6b; transform: scale(1.1); }

.weather-camera-body {
  padding: 20px;
  min-height: 400px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.weather-camera-iframe {
  width: 100%;
  height: 60vh;
  border: none;
  border-radius: 12px;
  background: #0a0a0a;
}

.weather-camera-fallback { text-align: center; color: #ccc; padding: 40px; }
.weather-camera-fallback i { font-size: 48px; margin-bottom: 16px; display: block; }
.weather-camera-fallback a { color: #ff9800; text-decoration: none; }
.weather-camera-fallback a:hover { text-decoration: underline; }

/* ============================================================================
   PESTAÑAS ESPECÍFICAS (info, ranking, observatorios)
   ============================================================================ */
.info-section {
  margin: 8px 0;
  padding: 5px;
  background: var(--white-05);
  border-radius: 10px;
  border-left: 4px solid var(--accent);
}
.info-section h3 {
  margin-top: 0;
  color: var(--accent);
  font-size: 1.2rem;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 8px;
  margin: 8px 0;
}

.info-card, .observatory-card {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 10px;
  border: 1px solid var(--white-1);
  transition: all 0.3s ease;
}
.observatory-card:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.info-card h4, .observatory-card h4 { margin-top: 0; font-size: 1.1rem; }
.info-card h4 { color: #ffcc00; }
.observatory-card h4 { color: #4fc3f7; }

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}
.ranking-table th {
  background: var(--white-1);
  padding: 12px;
  text-align: left;
  font-weight: 600;
  color: var(--accent);
}
.ranking-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--white-1);
}
.ranking-table tr:hover { background: var(--white-05); }
.ranking-table .rank { font-weight: bold; color: #ffcc00; width: 50px; }

/* ============================================================================
   ENLACES DE CONTACTO
   ============================================================================ */
.contact-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.contact-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--white-1);
  border-radius: 6px;
  color: white;
  text-decoration: none;
  transition: all 0.3s ease;
  font-size: 0.95rem;
}
.contact-link:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.contact-link.email      { background: rgba(234, 67, 53, 0.15);  border-color: rgba(234, 67, 53, 0.3); }
.contact-link.email:hover      { background: rgba(234, 67, 53, 0.25); }
.contact-link.github     { background: rgba(36, 41, 46, 0.15);   border-color: rgba(36, 41, 46, 0.3); }
.contact-link.github:hover     { background: rgba(36, 41, 46, 0.25); }
.contact-link.instagram  { background: linear-gradient(45deg, rgba(225, 48, 108, 0.15), rgba(245, 96, 64, 0.15)); border-color: rgba(225, 48, 108, 0.3); }
.contact-link.instagram:hover  { background: linear-gradient(45deg, rgba(225, 48, 108, 0.25), rgba(245, 96, 64, 0.25)); }
.contact-link.youtube    { background: rgba(255, 0, 0, 0.15);    border-color: rgba(255, 0, 0, 0.3); }
.contact-link.youtube:hover    { background: rgba(255, 0, 0, 0.25); }
.contact-link.twitter    { background: rgba(29, 161, 242, 0.15); border-color: rgba(29, 161, 242, 0.3); }
.contact-link.twitter:hover    { background: rgba(29, 161, 242, 0.25); }
.contact-link.linkedin   { background: rgba(10, 102, 194, 0.15); border-color: rgba(10, 102, 194, 0.3); }
.contact-link.linkedin:hover   { background: rgba(10, 102, 194, 0.25); }

.link-icon {
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
}
.link-text { font-weight: 400; flex-grow: 1; }

.contact-note {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--white-05);
  border-radius: 6px;
  border-left: 4px solid var(--accent);
}
.contact-note p { margin: 0; font-size: 0.9rem; opacity: 0.9; }
.contact-note strong { color: var(--accent); font-weight: 500; }

/* ============================================================================
   BADGES
   ============================================================================ */
.location-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
  margin-left: 8px;
  vertical-align: middle;
  color: white;
}
.badge-observatory { background: linear-gradient(135deg, #ff9800, #ff6600); }
.badge-park        { background: linear-gradient(135deg, #4CAF50, #2E7D32); }
.badge-city         { background: linear-gradient(135deg, #2196F3, #0D47A1); }

/* ============================================================================
   LOADING
   ============================================================================ */
.loading {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
   FOOTER
   ============================================================================ */
.footer {
  background-color: #0a0a0a !important;
  color: #e0e0e0;
  text-align: center;
  padding: 4px 2px !important;
  width: 100% !important;
  position: relative;
  bottom: 0; left: 0; right: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.footer-content { max-width: 1000px; margin: 0 auto; }

.footer p {
  margin: 0 0 3px 0 !important;
  font-size: 14px !important;
  line-height: 1.3;
  padding: 0 !important;
}
.footer nav { margin: 3px 0 0 0 !important; padding: 0; }
.footer nav a {
  color: #aaa;
  text-decoration: none;
  margin: 0 4px;
  font-size: 12px !important;
  transition: color 0.3s ease, text-decoration 0.3s ease;
}
.footer nav a:hover { color: #1e90ff; text-decoration: underline; }
.footer nav a:active { color: #f39c12; }
.footer nav .fa-instagram:hover { color: #e4405f; }
.footer nav a.fa {
  font-size: 18px !important;
  margin: 0 6px !important;
  transition: transform 0.3s ease;
}
.footer nav a.fa:hover { transform: scale(1.2); }

.trebol-wrap {
  position: relative;
  display: inline-block;
}

.arrebol-percent {
  position: absolute;
  bottom: -0.85em;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.62rem;
  font-weight: 700;
  color: #f5f5f5;
  -webkit-text-fill-color: #f5f5f5; /* rompe la herencia de transparent que viene de .title */
  background: none; /* por si acaso hereda algún background-clip */
  opacity: 0.9;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); /* un poco de contraste extra sobre el fondo */
}

.prediction-panel {
  position: relative;
}

/* --- Red de seguridad: evita que nada se salga del ancho de pantalla --- */
.tabs-container, .container, .main-grid, .panel,
.prediction-panel, .map-panel, .chart-panel, .log-panel {
  max-width: 100%;
  box-sizing: border-box;
}
#map, .map-wrapper, .charts, #cloudChart,
img, iframe, table {
  max-width: 100%;
}
.data-grid, .predictions, .location-header-row {
  max-width: 100%;
}

.location-header-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 8px;
  min-width: 0;
}
.location-header-row > div:first-child {
  min-width: 0;
}
.location-header-row .weather-camera-btn {
  white-space: nowrap;
  font-size: 0.8rem;
  padding: 6px 10px;
}

/* ============================================================================
   MEDIA QUERIES — RESPONSIVE
   ============================================================================ */
@media (max-width: 1024px) {
/* El mapa baja debajo de la lista; observatorios ya no comparte
   ancho, así que sube de 2 a 4 columnas igual que ciudades. */
  .observatories-grid { grid-template-columns: 1fr; height: auto; min-height: 0; }
  #observatoryMenu {
    grid-template-columns: repeat(4, 1fr);
    max-height: none;
    overflow-y: visible;
  }   
  .main-grid { display: flex; flex-direction: column; gap: 15px; }
  .map-wrapper { height: 600px !important; }
  .chart-panel .charts { height: 350px; }
}

@media (min-width: 1025px) {
  .main-grid {
    display: grid;
    grid-template-areas:
      "prediction map"
      "chart map"
      "log log";
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 20px;
  }
  .prediction-panel { grid-area: prediction; min-height: 200px; }
  .map-panel { grid-area: map; height: auto; min-height: 620px !important; }
  .chart-panel { grid-area: chart; min-height: 350px; }
  .log-panel { grid-area: log; margin-top: 0; }
  .data-grid { grid-template-columns: repeat(4, 1fr) !important; }
}

@media (max-width: 768px) {
  body { font-size: 14px; }

  #cityMenu, #observatoryMenu {
    grid-template-columns: repeat(3, 1fr); /* menos espacio: baja a 3 columnas */
    gap: 12px;
    padding: 15px 10px;
  }

  .container, .tabs-container { padding: 12px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .panel { padding: 12px; }

  h1 { font-size: 1.3rem; }
  .title {
    font-size: 3.6rem !important;
    letter-spacing: 7px !important;
    margin: 25px 0 20px !important;
  }
  .subtitle { font-size: 1.3rem; letter-spacing: 5px; }
  p.lead { font-size: 0.9rem; }

  .controls { flex-direction: column; }
  button { width: 100%; }

  .tab-btn { min-width: 100px; padding: 10px 15px; font-size: 0.9rem; }

  .data-grid { grid-template-columns: 1fr; gap: 8px; }
  .predictions { flex-direction: column; }

  .probability { width: 100%; min-width: auto; font-size: 28px; }
  .probability span { font-size: 32px; }
  .sun-times { justify-content: space-between; }
  .sun-time { flex: 1; text-align: center; padding: 8px 10px; font-size: 0.9rem; }

  .map-wrapper { height: 570px !important; }
  .probability-legend { min-width: 220px; font-size: 0.75rem; padding: 8px 12px; }
  .legend-labels { font-size: 0.65rem; }
  .charts { height: 350px; }

  .lead-with-bg {
    padding: 25px 20px;
    min-height: 160px;
    font-size: 0.9rem;
    max-width: calc(100% - 30px);
  }

  .chart-time-legend { gap: 8px; margin: 3px 0 8px; padding: 6px 10px; font-size: 0.8rem; }
  .contact-links { grid-template-columns: 1fr; }

  .footer { padding: 3px 1px !important; }
  .footer p { font-size: 13px !important; }
  .footer nav a { font-size: 13px !important; }
  .footer nav a.fa { font-size: 16px !important; margin: 0 5px !important; }

  .main-grid { display: block !important; } /* fuerza apilado, sea grid o flex */
  .main-grid > * {
    width: 100% !important;
    max-width: 100% !important;
    margin-bottom: 16px;
  }
  .predictions { grid-template-columns: 1fr !important; } /* amanecer y atardecer apilados */
  .predictions span[style*="2.5rem"],
  .predictions [style*="font-size:2.5rem"] {
    font-size: 1.8rem !important;
  }
  pre#log {
    white-space: pre-wrap;
    word-break: break-word;
  }

  /* Tarjetas de ciudades/observatorios: layout compacto para mobile.
     El tamaño de .probability-big/.probability-value ya NO se fija aquí:
     se calcula por tarjeta en JS (ver _probabilityFontSize en
     test_tarjetas.js), este bloque solo deja un tope máximo de
     seguridad para el estado inicial ("--"). */
  .city-card {
    padding: 6px 8px;
    min-height: 0;
  }
  .card-header {
    margin-bottom: 1px;
  }
  .probability-big {
    max-height: 1.3rem;
    line-height: 1.1;
  }
  .probability-uncertainty {
    font-size: 0.58rem;
    line-height: 1;
  }
  .city-region {
    font-size: 0.6rem;
    line-height: 1.1;
  }
  .city-name-row {
    margin: 0;
  }
  .city-name,
  .city-name--lg,
  .city-name--md,
  .city-name--sm,
  .city-name--xs {
    font-size: 0.76rem;
    line-height: 1.1;
  }
  .card-meta {
    margin-top: 1px;
    gap: 0;
  }
  .meta-row,
  .time-row,
  .visibility-row {
    font-size: 0.63rem;
    line-height: 1.15;
  }
  .probability-bar {
    height: 2px;
    margin-top: 2px;
  }
  .webcam-link {
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .container, .tabs-container { padding: 10px; }
  .panel { padding: 10px; }
  h1 { font-size: 1.2rem; }

  .title {
    font-size: 3.3rem !important;
    letter-spacing: 0.5px !important;
    margin: 20px 0 15px !important;
  }
  .subtitle { font-size: 1.7rem; letter-spacing: 3px; }
  .data-item { padding: 8px; font-size: 0.85rem; }

  .probability { padding: 10px; font-size: 24px; }
  .probability span { font-size: 28px; }

  .map-wrapper { height: 550px !important; }
  .probability-legend { min-width: 200px; font-size: 0.7rem; padding: 8px 12px; }
  .legend-labels { font-size: 0.6rem; }

  .map-toggle { padding: 6px 10px; font-size: 0.75rem; min-width: 60px; max-width: 100px; width: auto; }
  .charts { height: 350px; margin-top: 12px; }
  .chart-time-legend { gap: 6px; margin: 2px 0 6px; padding: 5px 8px; font-size: 0.75rem; }
  .tab-btn { min-width: 80px; padding: 8px 12px; font-size: 0.85rem; }

  .contact-link { padding: 0.6rem 1rem; font-size: 0.9rem; }
  .link-icon { font-size: 1rem; width: 20px; }

  .footer { padding: 2px 1px !important; }
  .footer p { font-size: 12px !important; margin: 0 0 2px 0 !important; }
  .footer nav a { font-size: 12px !important; margin: 0 3px; }
  .footer nav a.fa { font-size: 15px !important; margin: 0 4px !important; }

  .city-card { padding: 6px 4px; }
  .city-region { font-size: 0.5rem; }

  .location-header-row { grid-template-columns: 1fr; }
  .location-header-row .weather-camera-btn { justify-self: start; margin-top: 6px; }
}

@media (max-width: 400px) {
  .day-btn-top    { font-size: 0.58rem; }
  .day-btn-bottom { font-size: 0.75rem; }

  .probability .mc-percent { font-size: 1.3rem !important; }

  .city-card {
    padding: 5px 7px;
  }
  .city-name,
  .city-name--lg,
  .city-name--md,
  .city-name--sm,
  .city-name--xs {
    font-size: 0.7rem;
  }
  .meta-row,
  .time-row,
  .visibility-row {
    font-size: 0.58rem;
  }
}

@media (max-width: 350px) {
  #cityMenu, #observatoryMenu { grid-template-columns: repeat(2, 1fr); }
}
