/* =========================================================
 * styles.css - Dashboard Epidemiológico GBG (SENASA)
 * Versión 2.0 — Rediseño UI/UX institucional
 * ========================================================= */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&family=Open+Sans:ital,wght@0,400;0,600;1,400&family=Roboto+Mono:wght@400;600&display=swap');

/* ── Variables de color institucional ────────────────────── */
:root {
  /* Institucional MAG / SENASA */
  --mag-azul:          #00529B;
  --senasa-verde:      #005F2B;
  --acento-dorado:     #E8B020;

  /* Sistema epidemiológico (PAHO/CDC) */
  --epi-exito:         #1A7E3C;
  --epi-normal:        #52B788;
  --epi-alerta:        #E8A838;
  --epi-epidemia:      #C0392B;
  --epi-sin-datos:     #BDBDBD;

  /* Neutros */
  --fondo-panel:       #F7F9FC;
  --fondo-sidebar:     #EAEFF5;
  --texto-primario:    #1A2332;
  --texto-secundario:  #595959;
  --borde-sutil:       #DEE2E6;
  --sombra-card:       0 2px 8px rgba(0,0,0,0.08);
}

/* ── Base: tipografía y box-sizing ───────────────────────── */
* {
  box-sizing: border-box;
}

body {
  font-family: 'Open Sans', 'Roboto', sans-serif;
  font-size: 14px;
  color: var(--texto-primario);
  background: var(--fondo-panel);
  padding-bottom: 44px; /* espacio para el footer fijo */
}

h1, h2, h3, h4, h5 {
  font-family: 'Source Sans Pro', 'Open Sans', sans-serif;
  font-weight: 700;
}

/* ── Navbar institucional ────────────────────────────────── */
.navbar {
  background-color: var(--mag-azul) !important;
  border-bottom: 4px solid var(--acento-dorado) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.navbar-brand,
.navbar-brand span,
.navbar .navbar-brand {
  color: #ffffff !important;
  font-family: 'Source Sans Pro', sans-serif;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.3px;
}

.navbar-dark .navbar-nav .nav-link,
.navbar .nav-link {
  color: rgba(255,255,255,0.88) !important;
  font-family: 'Source Sans Pro', sans-serif;
  font-weight: 600;
  font-size: 13px;
  transition: color 0.15s ease, background 0.15s ease;
}

.navbar-dark .navbar-nav .nav-link:hover,
.navbar .nav-link:hover {
  color: #ffffff !important;
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
}

.navbar-dark .navbar-nav .nav-link.active,
.navbar .nav-link.active {
  color: #ffffff !important;
  background: rgba(255,255,255,0.18);
  border-radius: 4px;
}

/* ── Banda institucional (top of content) ────────────────── */
.senasa-header-band {
  background: linear-gradient(90deg, var(--mag-azul) 0%, #003d75 100%);
  color: #ffffff;
  padding: 8px 20px;
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--acento-dorado);
  margin-bottom: 0;
}

.senasa-header-band .inst-left {
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-size: 11px;
  opacity: 0.95;
}

.senasa-header-band .inst-right {
  font-size: 11px;
  opacity: 0.8;
}

/* ── KPI Row horizontal ──────────────────────────────────── */
.kpi-row-top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  align-items: stretch;
}

.kpi-row-top > * {
  flex: 1 1 180px;
  min-width: 150px;
  max-width: 260px;
}

/* ── KPI Cards ───────────────────────────────────────────── */
.kpi-card {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: var(--sombra-card);
  border-top: 3px solid var(--borde-sutil);
  padding: 14px 16px 12px;
  text-align: center;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 110px;
}

.kpi-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.13);
  transform: translateY(-1px);
}

.kpi-card .card-body {
  padding: 0;
  text-align: center;
}

.kpi-value {
  font-size: 42px;
  font-weight: 800;
  line-height: 1.0;
  font-family: 'Source Sans Pro', sans-serif;
  color: var(--mag-azul);
  letter-spacing: -1px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--texto-secundario);   /* #595959 — pasa WCAG AA */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* ── Indicador de tendencia ──────────────────────────────── */
.kpi-trend {
  font-size: 11px;
  font-weight: 600;
  margin-top: 5px;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(0,0,0,0.04);
  display: inline-block;
}

/* ── Semáforo epidemiológico ─────────────────────────────── */
.semaforo-card {
  border-radius: 8px;
  padding: 14px 16px;
  text-align: center;
  box-shadow: var(--sombra-card);
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.2s ease;
}

.semaforo-icon {
  font-size: 26px;
  line-height: 1;
  margin-bottom: 4px;
}

.semaforo-label {
  font-family: 'Source Sans Pro', sans-serif;
  font-weight: 700;
  font-size: 13px !important;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Footer institucional ────────────────────────────────── */
.footer-institucional {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1030;
  background: var(--mag-azul);
  color: rgba(255,255,255,0.85);
  padding: 8px 24px;
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 11px;
  border-top: 3px solid var(--acento-dorado);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.20);
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1400px;
  margin: 0 auto;
}

.footer-inner strong {
  color: #ffffff;
}

/* ── LAYOUT PRINCIPAL ────────────────────────────────────── */
.main-flex-container {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  width: 100%;
}

/* ── Cards mejorados ─────────────────────────────────────── */
.card {
  border-radius: 8px;
  border: 1px solid var(--borde-sutil);
  box-shadow: var(--sombra-card);
}

.card-header {
  background: var(--fondo-panel);
  border-bottom: 1px solid var(--borde-sutil);
  font-family: 'Source Sans Pro', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: var(--texto-primario);
  padding-top: .55rem;
  padding-bottom: .55rem;
}

.card-body {
  padding-top: .8rem;
  padding-bottom: .8rem;
}

/* ── Panel de contenido ──────────────────────────────────── */
.content-panel {
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.bslib-sidebar-layout {
  width: 100%;
  max-width: 100%;
  background: var(--fondo-sidebar);
}

/* ── Leaflet / Mapas ─────────────────────────────────────── */
.leaflet-control.leaflet-legend {
  max-width: 180px !important;
  padding: 6px 8px !important;
  font-size: 11px !important;
  border-radius: 6px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.15);
}

/* ── Gráficos responsive ─────────────────────────────────── */
.plot-output,
.leaflet {
  width: 100% !important;
  max-width: 100%;
}

.shiny-plot-output {
  max-width: 100%;
  width: 100% !important;
  height: auto;
}

/* ── Imágenes responsive ─────────────────────────────────── */
img {
  max-width: 100%;
  height: auto;
}

/* ── DataTables responsive ───────────────────────────────── */
.dataTables_wrapper {
  overflow-x: auto;
  width: 100%;
}

table {
  width: 100% !important;
  max-width: 100%;
}

/* ── Botones ─────────────────────────────────────────────── */
.btn {
  white-space: normal;
  word-wrap: break-word;
  border-radius: 6px;
  font-family: 'Source Sans Pro', sans-serif;
  font-weight: 600;
}

.btn-primary {
  background-color: var(--mag-azul) !important;
  border-color: var(--mag-azul) !important;
}

.btn-primary:hover {
  background-color: #003d75 !important;
  border-color: #003d75 !important;
}

/* ── Alertas y notificaciones ────────────────────────────── */
.alert-box {
  padding: 12px 15px;
  border-radius: 6px;
  margin-bottom: 15px;
}

.alert-success {
  background: #E8F5E9;
  border-left: 4px solid var(--epi-exito);
  color: #155724;
}

.alert-warning {
  background: #FFF3CD;
  border-left: 4px solid var(--epi-alerta);
  color: #5D4037;   /* mejorado de #856404 — pasa WCAG AA */
}

.alert-danger {
  background: #FFEBEE;
  border-left: 4px solid var(--epi-epidemia);
  color: #721c24;
}

.alert-info {
  background: #E3F2FD;
  border-left: 4px solid var(--mag-azul);
  color: #0c5460;
}

/* ── RESPONSIVE: Large tablets (1200px) ─────────────────── */
@media (max-width: 1200px) {
  .kpi-value {
    font-size: 34px;
  }

  .kpi-row-top > * {
    min-width: 130px;
  }
}

/* ── RESPONSIVE: Tablets (1024px) ───────────────────────── */
@media (max-width: 1024px) {
  .main-flex-container {
    flex-direction: column;
  }

  .kpi-row-top {
    flex-wrap: wrap;
  }

  .kpi-row-top > * {
    flex: 1 1 calc(50% - 6px);
    max-width: 100%;
  }

  .kpi-value {
    font-size: 30px;
  }

  .content-panel {
    width: 100%;
  }

  .bslib-sidebar-layout {
    flex-direction: column !important;
  }

  .bslib-sidebar-layout > .sidebar {
    max-width: 100% !important;
    width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--borde-sutil);
    margin-bottom: 15px;
  }

  .leaflet {
    height: 500px !important;
  }
}

/* ── RESPONSIVE: Mobile landscape (768px) ───────────────── */
@media (max-width: 768px) {
  .main-flex-container {
    gap: 10px;
  }

  .kpi-row-top {
    gap: 8px;
  }

  .kpi-row-top > * {
    flex: 1 1 calc(50% - 4px);
    min-width: 130px;
  }

  .kpi-value {
    font-size: 26px;
    letter-spacing: -0.5px;
  }

  .leaflet-control.leaflet-legend {
    max-width: 140px !important;
    font-size: 10px !important;
  }

  .navbar-brand {
    font-size: 14px !important;
  }

  .nav-link {
    font-size: 13px !important;
    padding: 8px 10px !important;
  }

  .btn {
    font-size: 13px !important;
    padding: 8px 12px !important;
  }

  select.form-select,
  input.form-control {
    font-size: 14px !important;
  }

  .card-header {
    font-size: 14px;
  }

  .leaflet {
    height: 450px !important;
  }

  .nav-tabs {
    flex-wrap: wrap;
  }

  .nav-tabs .nav-link {
    font-size: 12px;
    padding: 6px 10px;
  }

  .footer-inner {
    flex-direction: column;
    text-align: center;
    gap: 4px;
  }

  .senasa-header-band {
    flex-direction: column;
    gap: 2px;
    text-align: center;
  }
}

/* ── RESPONSIVE: Small mobile (480px) ───────────────────── */
@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  .kpi-value {
    font-size: 22px;
    letter-spacing: 0;
  }

  .kpi-sub {
    font-size: 11px;
  }

  .kpi-card {
    min-height: 90px;
    padding: 10px 12px;
  }

  .kpi-row-top > * {
    flex: 1 1 100%;
    min-width: 100%;
    max-width: 100%;
  }

  .card-header {
    font-size: 13px;
    padding: 8px 10px;
  }

  .card-body {
    padding: 10px;
  }

  .navbar-brand {
    font-size: 12px !important;
  }

  .nav-link {
    font-size: 11px !important;
    padding: 6px 8px !important;
  }

  .btn {
    font-size: 12px !important;
    padding: 6px 10px !important;
  }

  .leaflet {
    height: 400px !important;
  }

  input[type='number'],
  input[type='text'],
  select {
    font-size: 14px !important;
  }

  .nav-tabs .nav-link {
    font-size: 11px;
    padding: 5px 8px;
  }

  h1 { font-size: 20px; }
  h2 { font-size: 18px; }

  .stat-grid { gap: 10px; }
}

/* ── RESPONSIVE: Extra small (360px) ────────────────────── */
@media (max-width: 360px) {
  .container-fluid {
    padding-left: 8px;
    padding-right: 8px;
  }

  .card {
    margin-bottom: 10px;
  }

  .kpi-value {
    font-size: 18px;
  }

  .btn {
    font-size: 11px !important;
    padding: 5px 8px !important;
  }
}

/* ── Componentes específicos del dashboard ───────────────── */

/* Encabezado de conclusiones */
.conclusiones-header {
  background: linear-gradient(135deg, var(--mag-azul) 0%, #0066c2 100%);
  padding: 25px;
  border-radius: 8px;
  color: white;
  margin-bottom: 25px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
}

/* Secciones de análisis */
.analisis-section {
  background: white;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: var(--sombra-card);
}

.analisis-section.situacion   { border-left: 5px solid #3498db; }
.analisis-section.hallazgos   { border-left: 5px solid var(--epi-epidemia); }
.analisis-section.operativo   { border-left: 5px solid var(--epi-exito); }
.analisis-section.recomendaciones { border-left: 5px solid var(--epi-alerta); }

/* Badges de actualización */
.badge-actualizacion {
  background: rgba(255,255,255,0.2);
  padding: 5px 12px;
  border-radius: 15px;
  font-size: 13px;
}

/* Indicadores de estado */
.status-indicator {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
}

.status-indicator.success { background: var(--epi-exito); }
.status-indicator.warning { background: var(--epi-alerta); }
.status-indicator.danger  { background: var(--epi-epidemia); }

/* Tabla de resumen compacta */
.tabla-resumen { font-size: 13px; }
.tabla-resumen th { background: #e9ecef; padding: 8px; }
.tabla-resumen td { padding: 8px; }

/* Loading spinner */
.loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
}

.loading-spinner::after {
  content: "";
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--mag-azul);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
