/*
 * Cuaderna Dashboard — Estilos responsive y mobile-first
 * Complementa el tema Bootstrap DARKLY de Dash
 */

/* ===================================================================
   VARIABLES
   =================================================================== */
:root {
  --campo-verde:       #2ecc71;
  --campo-verde-dark:  #27ae60;
  --campo-bg-dark:     #1a1a2e;
  --campo-bg-darker:   #0f0f1a;
  --campo-sidebar-w:   220px;
  --campo-sidebar-w-xs: 60px;
  --campo-header-h:    56px;
}

/* ===================================================================
   SIDEBAR — BASE
   =================================================================== */
#sidebar {
  width: var(--campo-sidebar-w);
  min-height: calc(100vh - var(--campo-header-h));
  position: fixed;
  left: 0;
  top: var(--campo-header-h);
  background: var(--campo-bg-dark);
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  transition: width 0.25s ease, transform 0.25s ease;
  overflow: hidden;
  z-index: 1040;
  display: flex;
  flex-direction: column;
}

#sidebar.collapsed {
  width: var(--campo-sidebar-w-xs);
}

#sidebar .sidebar-label {
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.2s;
}

#sidebar.collapsed .sidebar-label {
  opacity: 0;
  width: 0;
}

.sidebar-icon {
  font-size: 1.1rem;
  min-width: 20px;
  text-align: center;
}

.sidebar-link {
  color: #b0b0b0 !important;
  border-radius: 6px;
  margin: 2px 8px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
  background: rgba(46, 204, 113, 0.1) !important;
  color: var(--campo-verde) !important;
}

.sidebar-link.active {
  background: rgba(46, 204, 113, 0.15) !important;
  color: var(--campo-verde) !important;
  border-left: 3px solid var(--campo-verde);
}

/* ===================================================================
   CONTENIDO PRINCIPAL
   =================================================================== */
#page-content {
  margin-left: var(--campo-sidebar-w);
  min-height: 100vh;
  transition: margin-left 0.25s ease;
  padding: 1rem;
}

#page-content.expanded {
  margin-left: var(--campo-sidebar-w-xs);
}

/* ===================================================================
   HEADER
   =================================================================== */
#app-header {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: rgba(26, 26, 46, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  height: var(--campo-header-h);
  padding: 0 1rem;
}

/* ===================================================================
   RESPONSIVE — TABLET (< 992px)
   =================================================================== */
@media (max-width: 991.98px) {
  #sidebar {
    transform: translateX(-100%);
    width: var(--campo-sidebar-w);
  }

  #sidebar.mobile-open {
    transform: translateX(0);
  }

  #page-content {
    margin-left: 0 !important;
  }

  /* Overlay cuando sidebar está abierto en mobile */
  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1035;
  }

  #sidebar-overlay.visible {
    display: block;
  }

  /* Cards: 1 columna en móvil */
  .campo-card-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ===================================================================
   RESPONSIVE — MOBILE (< 768px)
   =================================================================== */
@media (max-width: 767.98px) {
  /* Tablas: scroll horizontal */
  .table-responsive-campo {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Botones de acción: full width en mobile */
  .btn-mobile-full {
    width: 100% !important;
    margin-bottom: 0.5rem;
  }

  /* Charts: altura fija en mobile */
  .chart-mobile {
    height: 260px !important;
  }

  /* Ocultar columnas menos importantes en tablas */
  .col-mobile-hide {
    display: none !important;
  }

  /* Tipografía */
  h3 { font-size: 1.4rem; }
  h4 { font-size: 1.2rem; }

  /* Padding reducido en containers */
  .container, .container-fluid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* ===================================================================
   COMPONENTES Cuaderna — TARJETAS DE MÉTRICAS
   =================================================================== */
.campo-metric-card {
  background: var(--campo-bg-dark);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 1.2rem;
  height: 100%;
  transition: transform 0.2s, border-color 0.2s;
}

.campo-metric-card:hover {
  transform: translateY(-2px);
  border-color: rgba(46, 204, 113, 0.25);
}

.campo-metric-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--campo-verde);
}

.campo-metric-label {
  font-size: 0.82rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 0.3rem;
}

/* ===================================================================
   SEMÁFORO
   =================================================================== */
.semaforo-verde  { color: #2ecc71 !important; }
.semaforo-amarillo { color: #f39c12 !important; }
.semaforo-rojo   { color: #e74c3c !important; }

.badge-semaforo {
  font-size: 0.85rem;
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ===================================================================
   ALERTAS BADGE
   =================================================================== */
.alerta-badge-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #e74c3c;
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

/* ===================================================================
   PWA — STANDALONE MODE
   =================================================================== */
@media (display-mode: standalone) {
  /* En modo PWA (instalada en home screen) ocultar el header del navegador */
  body {
    padding-top: env(safe-area-inset-top);
  }

  #app-header {
    padding-top: env(safe-area-inset-top);
  }
}

/* ===================================================================
   ANIMACIONES
   =================================================================== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in-up {
  animation: fadeInUp 0.3s ease forwards;
}

/* ===================================================================
   PLOTLY CHARTS — DARK THEME OVERRIDES
   =================================================================== */
.js-plotly-plot .plotly .bg {
  fill: transparent !important;
}

.modebar-btn path {
  fill: #666 !important;
}

.modebar-btn:hover path {
  fill: var(--campo-verde) !important;
}
