/* ============================================================
   SISTEMA DE DISEÑO — ESTACIÓN METEOROLÓGICA ESPADAÑA
   Coherencia y armonía visual con Ganaderos Campo PWA
   ============================================================ */

:root {
  /* Paleta Corporativa Ganaderos */
  --brand-primary: #1e3a2b;
  --brand-primary-hover: #162c20;
  --accent: #2d6a4f;
  --accent-light: rgba(45, 106, 79, 0.1);

  /* Fondos y Superficies */
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-subtle: #f1f5f9;
  --bg-hover: #f1f5f9;

  /* Bordes y Sombras */
  --border-color: #e2e8f0;
  --border-color-subtle: #f1f5f9;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.03);

  /* Tipografía */
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  /* Estados Dinámicos del Clima */
  --temp-hot: #ea580c;
  --temp-mild: #16a34a;
  --temp-cold: #0284c7;
  --wind-color: #2d6a4f;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* ============================================================
   CABECERA PRINCIPAL (ESTILO GANADEROS CAMPO)
   ============================================================ */
.app-header {
  background: var(--brand-primary);
  color: #ffffff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  padding-top: env(safe-area-inset-top, 0px);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 14px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.brand-text h1 {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  margin-top: 1px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Enlace discreto a Ganaderos Campo */
.nav-campo-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-campo-link:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}

.nav-campo-link:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.28);
}

.nav-campo-link i {
  font-size: 0.85rem;
  opacity: 0.95;
}

/* Pestañas de navegación */
.desktop-nav {
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(0, 0, 0, 0.2);
  padding: 3px;
  border-radius: 8px;
  height: 32px;
  box-sizing: border-box;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-tab:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.nav-tab.active {
  background: #ffffff;
  color: var(--brand-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.nav-tab i {
  font-size: 0.82rem;
}

/* ============================================================
   CONTENEDOR PRINCIPAL
   ============================================================ */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px;
  width: 100%;
}

.main-content {
  flex: 1;
}

/* Barra de última actualización */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.last-update-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.82rem;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}

.last-update-wrapper strong {
  color: var(--text-main);
  font-weight: 600;
}

.pulse-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--temp-mild);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(1.3);
  }
}

/* ============================================================
   REJILLA METEOROLÓGICA (WEATHER GRID)
   ============================================================ */
.weather-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}

.weather-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.weather-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-label {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.card-icon {
  font-size: 1.35rem;
  color: var(--accent);
  opacity: 0.85;
}

.card-body {
  display: flex;
  align-items: baseline;
}

.card-value {
  font-size: 2.3rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: -0.03em;
  color: var(--text-main);
  line-height: 1.1;
}

.card-value:empty::before {
  content: '--';
  color: var(--text-dim);
}

/* Tarjeta de Dirección de Viento */
.wind-direction-card .wind-body {
  display: flex;
  align-items: center;
  gap: 20px;
}

.compass-container {
  width: 52px;
  height: 52px;
  border: 2px solid var(--border-color);
  background: var(--bg-surface-subtle);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

.wind-arrow {
  position: absolute;
  font-size: 1.35rem;
  color: var(--wind-color);
  transform: rotate(0deg);
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.wind-arrow::before {
  display: block;
  transform: rotate(45deg);
}

/* Colores Dinámicos de Temperatura */
.temp-cold {
  color: var(--temp-cold) !important;
}

.temp-mild {
  color: var(--temp-mild) !important;
}

.temp-hot {
  color: var(--temp-hot) !important;
}

/* ============================================================
   ESTADO DEL SISTEMA (WIFI Y UPTIME)
   ============================================================ */
.system-status-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  box-shadow: var(--shadow-sm);
  color: var(--text-muted);
  font-size: 0.88rem;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-item i {
  color: var(--accent);
  font-size: 1rem;
}

.status-item strong {
  color: var(--text-main);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
}

.status-divider {
  width: 1px;
  height: 20px;
  background: var(--border-color);
}

/* ============================================================
   VISTA DE ANÁLISIS / DESCARGA HISTÓRICA
   ============================================================ */
.analysis-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 440px;
}

.export-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 44px 36px;
  max-width: 520px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.export-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
}

.export-card h2 {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

.export-card p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 28px;
}

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 26px;
  border-radius: var(--radius-md);
  background: var(--brand-primary);
  color: #ffffff;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.btn-download:hover {
  background: var(--brand-primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ============================================================
   RESPONSIVE (MÓVILES Y PANTALLAS PEQUEÑAS)
   ============================================================ */
@media (max-width: 768px) {
  .header-container {
    padding: 8px 14px;
    height: 54px;
  }

  .brand-sub {
    display: none;
  }

  .nav-tab span {
    display: none;
  }

  .nav-tab {
    padding: 0 8px;
    height: 26px;
  }

  .weather-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .system-status-card {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .status-divider {
    display: none;
  }

  .export-card {
    padding: 28px 20px;
    margin: 10px;
  }
}

@media (max-width: 480px) {
  .header-container {
    padding: 6px 12px;
  }

  .brand-text h1 {
    font-size: 0.95rem;
    max-width: 155px;
  }

  .nav-campo-link span {
    display: none;
  }

  .nav-campo-link {
    width: 32px;
    padding: 0;
    justify-content: center;
  }
}

@media (min-width: 769px) {
  .header-container {
    padding: 10px 24px;
    height: 60px;
    gap: 16px;
  }

  .brand-icon {
    width: 38px;
    height: 38px;
    font-size: 1.25rem;
  }

  .brand-text h1 {
    font-size: 1.15rem;
  }

  .brand-sub {
    font-size: 0.78rem;
  }

  .nav-campo-link {
    height: 34px;
    padding: 0 12px;
    font-size: 0.82rem;
    gap: 6px;
  }

  .desktop-nav {
    height: 36px;
    padding: 3px 4px;
    gap: 4px;
  }

  .nav-tab {
    height: 30px;
    padding: 0 12px;
    font-size: 0.82rem;
  }
}
