/* ==========================================================================
   DELLA CHÀ TRALCAO • DASHBOARD EJECUTIVO & ANALYTICS IA
   Supervisión Gerencial: Agrícola Tralcao & AUBEL Tech Hub
   Estilo: Sleek Executive Dark Slate, Glassmorphism, Micro-animaciones y Alto Rendimiento
   ========================================================================== */

:root {
  /* Paleta Corporativa Ejecutiva */
  --bg-main: #0b0f17;
  --bg-slate: #0f172a;
  --bg-card: #182234;
  --bg-card-hover: #1f2c42;
  --bg-card-elevated: #24344d;

  --border-card: #283953;
  --border-focus: #3b82f6;

  /* Colores Funcionales y Acentos de Marca */
  --aubel-amber: #d9822b;
  --aubel-amber-light: #f59e0b;
  --aubel-amber-glow: rgba(217, 130, 43, 0.35);

  --emerald-aubel: #10b981;
  --emerald-light: #34d399;
  --emerald-glow: rgba(16, 185, 129, 0.3);

  --burgundy-aubel: #6b1d2f;
  --burgundy-light: #9f1239;

  --blue-tech: #38bdf8;
  --blue-tech-dark: #0284c7;

  --rose-danger: #f43f5e;
  --rose-glow: rgba(244, 63, 94, 0.35);

  /* Tipografía y Textos */
  --text-white: #ffffff;
  --text-light: #f1f5f9;
  --text-sub: #94a3b8;
  --text-muted: #64748b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --shadow-exec: 0 10px 30px -5px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border-card);
  --shadow-glow: 0 0 25px rgba(16, 185, 129, 0.15);
}

/* Reset y Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-light);
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   HEADER EJECUTIVO (AUBEL TECH HUB & AGRÍCOLA TRALCAO)
   ========================================================================== */
.exec-header {
  background: linear-gradient(180deg, #131c2c 0%, var(--bg-slate) 100%);
  border-bottom: 1px solid var(--border-card);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.header-brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.aubel-logo-badge {
  width: 42px;
  height: 42px;
  background: radial-gradient(circle at 30% 30%, #1e293b, #0f172a);
  border: 1.5px solid var(--aubel-amber);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px var(--aubel-amber-glow);
}

.brand-text .aubel-tag {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--aubel-amber-light);
  letter-spacing: 0.8px;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-text h1 .divider {
  color: var(--text-muted);
  font-weight: 300;
}

/* Navegación de la Suite ERP */
.erp-suite-nav {
  display: flex;
  align-items: center;
  background: rgba(11, 15, 23, 0.6);
  border: 1px solid var(--border-card);
  padding: 4px;
  border-radius: 999px;
  gap: 4px;
}

.suite-nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-sub);
  text-decoration: none;
  transition: all 0.2s ease;
}

.suite-nav-link:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.05);
}

.suite-nav-link.active {
  background: var(--bg-card-elevated);
  color: var(--emerald-light);
  border: 1px solid var(--emerald-aubel);
  box-shadow: 0 0 12px var(--emerald-glow);
}

/* Meta Derecha: Conexión WHM y Perfil */
.header-right-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

.live-sync-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  color: var(--emerald-light);
}

.live-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--emerald-aubel);
  box-shadow: 0 0 8px var(--emerald-aubel);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.exec-profile-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  padding: 4px 12px 4px 6px;
  border-radius: 999px;
}

.exec-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--aubel-amber) 0%, var(--burgundy-aubel) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.75rem;
  color: #fff;
  border: 1px solid var(--aubel-amber-light);
}

.exec-info {
  display: flex;
  flex-direction: column;
}

.exec-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: #ffffff;
}

.exec-hub {
  font-size: 0.65rem;
  color: var(--aubel-amber-light);
  font-weight: 600;
}

/* ==========================================================================
   VIEWPORT PRINCIPAL DEL DASHBOARD
   ========================================================================== */
.dashboard-viewport {
  flex: 1;
  padding: 24px 28px;
  max-width: 1850px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ==========================================================================
   1. TOP KPI SUMMARY CARDS (4 TARJETAS)
   ========================================================================== */
.kpi-cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

@media (max-width: 1200px) {
  .kpi-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .kpi-cards-grid {
    grid-template-columns: 1fr;
  }
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  gap: 16px;
  box-shadow: var(--shadow-exec);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--aubel-amber);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6), 0 0 20px var(--aubel-amber-glow);
}

.kpi-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-amber {
  background: rgba(217, 130, 43, 0.15);
  border: 1px solid var(--aubel-amber);
  color: var(--aubel-amber-light);
}

.icon-emerald {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--emerald-aubel);
  color: var(--emerald-light);
}

.icon-burgundy {
  background: rgba(107, 29, 47, 0.35);
  border: 1px solid var(--burgundy-light);
  color: #fda4af;
}

.icon-blue {
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid var(--blue-tech);
  color: var(--blue-tech);
}

.kpi-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.kpi-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-sub);
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kpi-big-number {
  font-size: 1.85rem;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}

.kpi-big-number.text-emerald { color: var(--emerald-light); }
.kpi-big-number.text-amber { color: var(--aubel-amber-light); }

.kpi-unit {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-footer-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.73rem;
  color: var(--text-muted);
  margin-top: 4px;
  flex-wrap: wrap;
}

.kpi-trend.positive {
  color: var(--emerald-light);
  font-weight: 700;
}

.kpi-equivalent {
  color: var(--emerald-light);
  font-weight: 600;
}

.kpi-formula {
  color: var(--aubel-amber-light);
  font-weight: 500;
}

.kpi-clp-badge {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--blue-tech);
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
}

/* ==========================================================================
   2. CUERPO CENTRAL: LAYOUT SPLIT (GRÁFICOS + SIDEBAR PREDICTIVO)
   ========================================================================== */
.analytics-layout-split {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 24px;
}

@media (max-width: 1180px) {
  .analytics-layout-split {
    grid-template-columns: 1fr;
  }
}

/* Columna de Gráficos */
.charts-column {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.analytics-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-exec);
  position: relative;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-header-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.card-title-group h2 {
  font-size: 1.05rem;
  font-weight: 800;
  color: #ffffff;
}

.card-title-group p {
  font-size: 0.74rem;
  color: var(--text-sub);
}

/* Modos de Unidad del Gráfico de Barras */
.chart-mode-pills {
  display: flex;
  background: var(--bg-main);
  border: 1px solid var(--border-card);
  padding: 3px;
  border-radius: 8px;
  gap: 4px;
}

.chart-toggle-pill {
  background: transparent;
  border: none;
  color: var(--text-sub);
  font-size: 0.74rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chart-toggle-pill.active {
  background: var(--bg-card-elevated);
  color: var(--aubel-amber-light);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.time-range-badge {
  font-size: 0.74rem;
  background: var(--bg-main);
  border: 1px solid var(--border-card);
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--text-sub);
  font-weight: 600;
}

/* Lienzos SVG Interactivos de Gráficos */
.chart-canvas-container {
  width: 100%;
  height: 280px;
  background: #0d1420;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  position: relative;
  overflow: hidden;
}

.interactive-chart-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Tooltip Flotante del Gráfico */
.chart-tooltip {
  position: absolute;
  display: none;
  background: #111a28;
  border: 1px solid var(--aubel-amber);
  border-radius: 8px;
  padding: 10px 14px;
  color: #ffffff;
  font-size: 0.78rem;
  pointer-events: none;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8), 0 0 15px var(--aubel-amber-glow);
  z-index: 50;
  transform: translate(-50%, -110%);
  white-space: nowrap;
}

/* Leyendas de Gráficos */
.chart-legend-row {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 0.76rem;
  color: var(--text-sub);
  padding-top: 4px;
}

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

.legend-color-box {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.bg-broth { background: linear-gradient(135deg, var(--aubel-amber) 0%, var(--burgundy-aubel) 100%); }
.bg-bottled { background: var(--emerald-aubel); }
.bg-production { background: var(--emerald-aubel); }
.bg-dispatch { background: var(--blue-tech); }

/* ==========================================================================
   3. SIDEBAR PREDICTIVO IA (SIDE PREDICTIVE PANEL)
   ========================================================================== */
.predictive-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-header-badge {
  background: linear-gradient(135deg, rgba(217, 130, 43, 0.15) 0%, rgba(107, 29, 47, 0.15) 100%);
  border: 1px solid var(--aubel-amber);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-spark-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--aubel-amber);
  color: #0b0f17;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-header-badge h3 {
  font-size: 0.98rem;
  font-weight: 800;
  color: #ffffff;
}

.sidebar-header-badge p {
  font-size: 0.7rem;
  color: var(--aubel-amber-light);
}

/* 1. Tarjeta de Alerta de Umbral Crítico (< 500 L) */
.alert-threshold-card {
  background: linear-gradient(180deg, rgba(244, 63, 94, 0.12) 0%, var(--bg-card) 100%);
  border: 1px solid var(--rose-danger);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 0 20px var(--rose-glow);
}

.alert-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alert-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(244, 63, 94, 0.2);
  border: 1px solid var(--rose-danger);
  color: #fca5a5;
  font-size: 0.74rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
}

.live-dot-red {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--rose-danger);
  box-shadow: 0 0 8px var(--rose-danger);
  animation: pulse-dot 1.5s infinite;
}

.alert-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.alert-title {
  font-size: 1rem;
  font-weight: 800;
  color: #ffffff;
}

.alert-description {
  font-size: 0.8rem;
  color: var(--text-sub);
  line-height: 1.4;
}

.alert-description strong {
  color: #fca5a5;
}

.alert-metrics-box {
  background: rgba(11, 15, 23, 0.6);
  border: 1px solid rgba(244, 63, 94, 0.3);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.metric-col {
  display: flex;
  flex-direction: column;
}

.m-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
}

.m-val.text-red {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--rose-danger);
}

.metric-arrow {
  color: var(--aubel-amber);
  font-size: 1.2rem;
  font-weight: 900;
}

/* 2. Motor de Recomendación IA */
.recommendation-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-left: 4px solid var(--aubel-amber);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-exec);
}

.recom-badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.recom-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--aubel-amber-light);
  letter-spacing: 0.5px;
}

.recom-confidence {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--emerald-aubel);
  color: var(--emerald-light);
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
}

.recom-headline {
  font-size: 0.95rem;
  font-weight: 800;
  color: #ffffff;
}

.recom-quote-box {
  background: #0d1420;
  border: 1px solid rgba(217, 130, 43, 0.3);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 0.84rem;
  color: #ffffff;
  line-height: 1.45;
}

.recom-quote-box strong {
  color: var(--aubel-amber-light);
}

.recom-bullets {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--text-sub);
}

.bullet-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.check-icon {
  color: var(--emerald-light);
  font-weight: 900;
}

.btn-execute-recommendation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  background: linear-gradient(135deg, var(--aubel-amber) 0%, #b45309 100%);
  border: none;
  border-radius: var(--radius-md);
  color: #0b0f17;
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 4px 15px rgba(217, 130, 43, 0.3);
  transition: all 0.15s ease;
  margin-top: 4px;
}

.btn-execute-recommendation:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* 3. Botones de Exportación y Respaldo Técnico */
.export-actions-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.export-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: #ffffff;
}

.export-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.export-buttons-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-export-sql {
  height: 42px;
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-export-sql:hover {
  background: #2e4160;
  border-color: var(--blue-tech);
  color: var(--blue-tech);
}

.btn-backup-whm {
  height: 42px;
  background: linear-gradient(135deg, #065f46 0%, #047857 100%);
  border: 1px solid var(--emerald-light);
  border-radius: var(--radius-md);
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.25);
  transition: all 0.15s ease;
}

.btn-backup-whm:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.backup-status-tag {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
}

.backup-status-tag strong {
  color: var(--emerald-light);
}

/* ==========================================================================
   MODAL DE REPORTE Y BACKUP
   ========================================================================== */
.dash-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 23, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 20px;
}

.dash-modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.dash-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  max-width: 580px;
  width: 100%;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dash-modal-header {
  padding: 16px 20px;
  background: var(--bg-card-elevated);
  border-bottom: 1px solid var(--border-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dash-modal-header h4 {
  font-size: 1rem;
  font-weight: 800;
  color: #ffffff;
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}

.dash-modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-light);
}

.dash-modal-footer {
  padding: 14px 20px;
  background: var(--bg-slate);
  border-top: 1px solid var(--border-card);
  display: flex;
  justify-content: flex-end;
}

.btn-modal-action {
  height: 40px;
  padding: 0 20px;
  background: var(--aubel-amber);
  border: none;
  border-radius: var(--radius-md);
  color: #000;
  font-weight: 800;
  cursor: pointer;
}

/* Toasts */
.dash-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}

.dash-toast {
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-card);
  border-left: 4px solid var(--emerald-aubel);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  font-size: 0.85rem;
  color: #ffffff;
  font-weight: 600;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(15px);
  transition: all 0.2s ease;
}

.dash-toast.show {
  opacity: 1;
  transform: translateY(0);
}
