/* === BASE === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f0f2f5;
  color: #333;
  transition: background 0.5s, color 0.5s;
}

body.dark-mode {
  background: #121212;
  color: #e0e0e0;
}

/* === NAVBAR === */
.nav {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

body.dark-mode .nav {
  background: rgba(20, 30, 45, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
}

.nav-buttons {
  display: flex;
  gap: 0.5rem;
}

.nav-btn {
  padding: 0.5rem 1rem;
  text-decoration: none;
  color: #555;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

body.dark-mode .nav-btn {
  color: #bbb;
}

.nav-btn.active, .nav-btn:hover {
  background: #0078d4;
  color: white;
}

/* === SWITCH DE GALAHAD === */
.theme-switch {
  cursor: pointer;
}

.theme-switch__checkbox {
  display: none;
}

.theme-switch__container {
  position: relative;
  width: 50px;
  height: 25px;
  overflow: hidden;
  border-radius: 13px;
  background: #e0e0e0;
  transition: background 0.3s ease;
}

body.dark-mode .theme-switch__container {
  background: #333;
}

.theme-switch__clouds {
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, #fff 0%, #f0f0f0 100%);
  border-radius: 13px;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
}

.theme-switch__stars-container {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.3s ease;
}

body.dark-mode .theme-switch__stars-container {
  opacity: 1;
}

.theme-switch__circle-container {
  position: absolute;
  width: 23px;
  height: 23px;
  left: 1px;
  bottom: 1px;
  border-radius: 50%;
  background: #fff;
  transition: all 0.3s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

body.dark-mode .theme-switch__circle-container {
  left: 26px;
  background: #fdd835;
}

.theme-switch__moon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fdd835;
  position: relative;
}

.theme-switch__moon .theme-switch__spot {
  position: absolute;
  width: 4px;
  height: 4px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  opacity: 0.6;
}

.theme-switch__moon .theme-switch__spot:nth-child(1) {
  top: 6px;
  left: 8px;
}

.theme-switch__moon .theme-switch__spot:nth-child(2) {
  top: 10px;
  left: 12px;
}

.theme-switch__moon .theme-switch__spot:nth-child(3) {
  top: 7px;
  right: 6px;
}

/* === EFECTOS === */
.particles, .rain {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #aaa;
  border-radius: 50%;
  opacity: 0.3;
  animation: float linear infinite;
}

@keyframes float {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  10% { opacity: 0.8; }
  90% { opacity: 0.8; }
  100% { transform: translateY(-100vh) rotate(360deg); opacity: 0; }
}

.raindrop {
  position: absolute;
  width: 2px;
  height: 15px;
  background: linear-gradient(transparent, rgba(135, 206, 250, 0.6));
  box-shadow: 0 0 5px rgba(135, 206, 250, 0.5);
  animation: fall linear infinite;
}

@keyframes fall {
  0% { transform: translateY(-20px); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translateY(100vh); opacity: 0; }
}

/* === CONTENEDOR PRINCIPAL === */
.container {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}

header {
  margin-bottom: 2rem;
  text-align: center;
}

header h1 {
  font-size: 2rem;
  color: #0078d4;
}

body.dark-mode header h1 {
  color: #4dabf7;
}

/* === ESTADO DE CONEXIÓN MQTT === */
.connection-status-small {
  background: #fff3cd;
  color: #856404;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

body.dark-mode .connection-status-small {
  background: #856404;
  color: #fff3cd;
}

.connection-status-small.connected {
  background: #d4edda;
  color: #155724;
}

body.dark-mode .connection-status-small.connected {
  background: #155724;
  color: #d4edda;
}

.status-dot {
  width: 10px;
  height: 10px;
  background: #ffc107;
  border-radius: 50%;
  display: inline-block;
}

.connection-status-small.connected .status-dot {
  background: #28a745;
}

.last-update {
  margin-left: auto;
  font-size: 0.8rem;
  opacity: 0.7;
}

/* === DATOS EN VIVO (tarjetas) === */
#weather-data {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.data-card {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

body.dark-mode .data-card {
  background: rgba(30, 40, 55, 0.9);
  border: 1px solid rgba(93, 173, 226, 0.3);
}

.data-card span {
  display: block;
  font-size: 0.9rem;
  opacity: 0.8;
  margin-bottom: 0.5rem;
}

.data-card strong {
  font-size: 1.2rem;
  font-weight: 600;
}

/* === GRÁFICOS (1 COLUMNA, ANCHO COMPLETO) === */
.chart-wrapper-full {
  width: 100%;
  height: 400px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  margin-bottom: 2rem;
}

body.dark-mode .chart-wrapper-full {
  background: rgba(20, 30, 45, 0.9);
  border: 1px solid rgba(93, 173, 226, 0.3);
}

#charts-container canvas {
  width: 100% !important;
  height: 350px !important;
}

/* === FOOTER === */
footer {
  text-align: center;
  margin-top: 3rem;
  padding: 2rem 0;
  color: #666;
  font-size: 0.9rem;
  border-top: 1px solid #ddd;
}

body.dark-mode footer {
  color: #aaa;
  border-top: 1px solid #444;
}

footer a {
  color: #0078d4;
  text-decoration: none;
}

body.dark-mode footer a {
  color: #4dabf7;
}

/* === SWITCH DE GALAHAD (UIVERSE.IO) === */
.theme-switch {
  --toggle-size: 16px;
  --container-width: 5.625em;
  --container-height: 2.5em;
  --container-radius: 6.25em;
  --container-light-bg: #3D7EAE;
  --container-night-bg: #1D1F2C;
  --circle-container-diameter: 3.375em;
  --sun-moon-diameter: 2.125em;
  --sun-bg: #ECCA2F;
  --moon-bg: #C4C9D1;
  --spot-color: #959DB1;
  --circle-container-offset: calc((var(--circle-container-diameter) - var(--container-height)) / 2 * -1);
  --stars-color: #fff;
  --clouds-color: #F3FDFF;
  --back-clouds-color: #AACADF;
  --transition: .5s cubic-bezier(0, -0.02, 0.4, 1.25);
  --circle-transition: .3s cubic-bezier(0, -0.02, 0.35, 1.17);
}

.theme-switch, .theme-switch *, .theme-switch *::before, .theme-switch *::after {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-size: var(--toggle-size);
}

.theme-switch__container {
  width: var(--container-width);
  height: var(--container-height);
  background-color: var(--container-light-bg);
  border-radius: var(--container-radius);
  overflow: hidden;
  cursor: pointer;
  -webkit-box-shadow: 0em -0.062em 0.062em rgba(0, 0, 0, 0.25), 0em 0.062em 0.125em rgba(255, 255, 255, 0.94);
  box-shadow: 0em -0.062em 0.062em rgba(0, 0, 0, 0.25), 0em 0.062em 0.125em rgba(255, 255, 255, 0.94);
  -webkit-transition: var(--transition);
  transition: var(--transition);
  position: relative;
}

.theme-switch__container::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  -webkit-box-shadow: 0em 0.05em 0.187em rgba(0, 0, 0, 0.25) inset, 0em 0.05em 0.187em rgba(0, 0, 0, 0.25) inset;
  box-shadow: 0em 0.05em 0.187em rgba(0, 0, 0, 0.25) inset, 0em 0.05em 0.187em rgba(0, 0, 0, 0.25) inset;
  border-radius: var(--container-radius)
}

.theme-switch__checkbox {
  display: none;
}

.theme-switch__circle-container {
  width: var(--circle-container-diameter);
  height: var(--circle-container-diameter);
  background-color: rgba(255, 255, 255, 0.1);
  position: absolute;
  left: var(--circle-container-offset);
  top: var(--circle-container-offset);
  border-radius: var(--container-radius);
  -webkit-box-shadow: inset 0 0 0 3.375em rgba(255, 255, 255, 0.1), inset 0 0 0 3.375em rgba(255, 255, 255, 0.1), 0 0 0 0.625em rgba(255, 255, 255, 0.1), 0 0 0 1.25em rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 0 3.375em rgba(255, 255, 255, 0.1), inset 0 0 0 3.375em rgba(255, 255, 255, 0.1), 0 0 0 0.625em rgba(255, 255, 255, 0.1), 0 0 0 1.25em rgba(255, 255, 255, 0.1);
  display: flex;
  -webkit-transition: var(--circle-transition);
  transition: var(--circle-transition);
  pointer-events: none;
}

.theme-switch__sun-moon-container {
  pointer-events: auto;
  position: relative;
  z-index: 2;
  width: var(--sun-moon-diameter);
  height: var(--sun-moon-diameter);
  margin: auto;
  border-radius: var(--container-radius);
  background-color: var(--sun-bg);
  -webkit-box-shadow: 0.062em 0.062em 0.062em 0em rgba(254, 255, 239, 0.61) inset, 0em -0.062em 0.062em 0em #a1872a inset;
  box-shadow: 0.062em 0.062em 0.062em 0em rgba(254, 255, 239, 0.61) inset, 0em -0.062em 0.062em 0em #a1872a inset;
  -webkit-filter: drop-shadow(0.062em 0.125em 0.125em rgba(0, 0, 0, 0.25)) drop-shadow(0em 0.062em 0.125em rgba(0, 0, 0, 0.25));
  filter: drop-shadow(0.062em 0.125em 0.125em rgba(0, 0, 0, 0.25)) drop-shadow(0em 0.062em 0.125em rgba(0, 0, 0, 0.25));
  overflow: hidden;
  -webkit-transition: var(--transition);
  transition: var(--transition);
}

.theme-switch__moon {
  -webkit-transform: translateX(100%);
  -ms-transform: translateX(100%);
  transform: translateX(100%);
  width: 100%;
  height: 100%;
  background-color: var(--moon-bg);
  border-radius: inherit;
  -webkit-box-shadow: 0.062em 0.062em 0.062em 0em rgba(254, 255, 239, 0.61) inset, 0em -0.062em 0.062em 0em #969696 inset;
  box-shadow: 0.062em 0.062em 0.062em 0em rgba(254, 255, 239, 0.61) inset, 0em -0.062em 0.062em 0em #969696 inset;
  -webkit-transition: var(--transition);
  transition: var(--transition);
  position: relative;
}

.theme-switch__spot {
  position: absolute;
  top: 0.75em;
  left: 0.312em;
  width: 0.75em;
  height: 0.75em;
  border-radius: var(--container-radius);
  background-color: var(--spot-color);
  -webkit-box-shadow: 0em 0.0312em 0.062em rgba(0, 0, 0, 0.25) inset;
  box-shadow: 0em 0.0312em 0.062em rgba(0, 0, 0, 0.25) inset;
}

.theme-switch__spot:nth-of-type(2) {
  width: 0.375em;
  height: 0.375em;
  top: 0.937em;
  left: 1.375em;
}

.theme-switch__spot:nth-last-of-type(3) {
  width: 0.25em;
  height: 0.25em;
  top: 0.312em;
  left: 0.812em;
}

.theme-switch__clouds {
  width: 1.25em;
  height: 1.25em;
  background-color: var(--clouds-color);
  border-radius: var(--container-radius);
  position: absolute;
  bottom: -0.625em;
  left: 0.312em;
  -webkit-box-shadow: 0.937em 0.312em var(--clouds-color), -0.312em -0.312em var(--back-clouds-color), 1.437em 0.375em var(--clouds-color), 0.5em -0.125em var(--back-clouds-color), 2.187em 0 var(--clouds-color), 1.25em -0.062em var(--back-clouds-color), 2.937em 0.312em var(--clouds-color), 2em -0.312em var(--back-clouds-color), 3.625em -0.062em var(--clouds-color), 2.625em 0em var(--back-clouds-color), 4.5em -0.312em var(--clouds-color), 3.375em -0.437em var(--back-clouds-color), 4.625em -1.75em 0 0.437em var(--clouds-color), 4em -0.625em var(--back-clouds-color), 4.125em -2.125em 0 0.437em var(--back-clouds-color);
  box-shadow: 0.937em 0.312em var(--clouds-color), -0.312em -0.312em var(--back-clouds-color), 1.437em 0.375em var(--clouds-color), 0.5em -0.125em var(--back-clouds-color), 2.187em 0 var(--clouds-color), 1.25em -0.062em var(--back-clouds-color), 2.937em 0.312em var(--clouds-color), 2em -0.312em var(--back-clouds-color), 3.625em -0.062em var(--clouds-color), 2.625em 0em var(--back-clouds-color), 4.5em -0.312em var(--clouds-color), 3.375em -0.437em var(--back-clouds-color), 4.625em -1.75em 0 0.437em var(--clouds-color), 4em -0.625em var(--back-clouds-color), 4.125em -2.125em 0 0.437em var(--back-clouds-color);
  -webkit-transition: 0.5s cubic-bezier(0, -0.02, 0.4, 1.25);
  transition: 0.5s cubic-bezier(0, -0.02, 0.4, 1.25);
}

.theme-switch__stars-container {
  position: absolute;
  color: var(--stars-color);
  top: -100%;
  left: 0.312em;
  width: 2.75em;
  height: auto;
  -webkit-transition: var(--transition);
  transition: var(--transition);
}

/* === ACCIONES === */
.theme-switch__checkbox:checked + .theme-switch__container {
  background-color: var(--container-night-bg);
}

.theme-switch__checkbox:checked + .theme-switch__container .theme-switch__circle-container {
  left: calc(100% - var(--circle-container-offset) - var(--circle-container-diameter));
}

.theme-switch__checkbox:checked + .theme-switch__container .theme-switch__moon {
  -webkit-transform: translate(0);
  transform: translate(0);
}

.theme-switch__checkbox:checked + .theme-switch__container .theme-switch__clouds {
  bottom: -4.062em;
}

.theme-switch__checkbox:checked + .theme-switch__container .theme-switch__stars-container {
  top: 50%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
}

/* === TRANSICIONES SINCRONIZADAS PARA ANALISIS.HTML === */
/* Asegura que TODOS los elementos cambien de tema al mismo tiempo */
body.analisis-page, 
body.analisis-page * {
  transition: background-color 0.3s ease, 
               color 0.3s ease, 
               border-color 0.3s ease, 
               box-shadow 0.3s ease !important;
  transition-property: background-color, color, border-color, box-shadow;
  transition-duration: 0.3s;
  transition-timing-function: ease;
}

/* Asegurar que los gráficos también tengan transición */
body.analisis-page .chart-wrapper-full {
  transition: background-color 0.3s ease, border-color 0.3s ease !important;
}

body.analisis-page.dark-mode .chart-wrapper-full {
  transition: background-color 0.3s ease, border-color 0.3s ease !important;
}

/* Asegurar que el switch cambie al mismo tiempo */
body.analisis-page .theme-switch__container,
body.analisis-page .theme-switch__clouds,
body.analisis-page .theme-switch__stars-container,
body.analisis-page .theme-switch__circle-container,
body.analisis-page .theme-switch__moon {
  transition: all 0.3s ease !important;
}

/* Elimina cualquier transición adicional que pueda causar retrasos */
body.analisis-page .particles, 
body.analisis-page .rain {
  transition: none !important;
}
