/* ===================== RESET Y GUARDAS GLOBALES ===================== */
* { box-sizing: border-box; }
.hidden { display: none !important; }
svg { max-width: 100%; height: auto; }

body {
  background-image:
    radial-gradient(ellipse 1200px 500px at 20% -10%, rgba(37, 99, 235, 0.04), transparent 60%),
    radial-gradient(ellipse 900px 500px at 100% 0%, rgba(14, 165, 233, 0.04), transparent 55%);
  background-attachment: fixed;
}

/* ===================== HEADER ===================== */
.app-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 26px;
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-header));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card), var(--shadow-glow);
  max-width: 1760px;
  margin: 16px auto 0;
  flex-wrap: wrap;
  overflow: hidden;
}

.app-header::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-cyan), transparent);
  background-size: 200% 100%;
  animation: scanline 6s linear infinite;
  opacity: 0.9;
}

@keyframes scanline {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-badge {
  background: var(--brand-navy);
  color: #FFFFFF;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  letter-spacing: -0.02em;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25);
}

.brand-title { display: flex; flex-direction: column; }

.brand-title h1 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0;
}

.brand-title p {
  font-size: 10.5px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  margin: 2px 0 0;
}

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.periodo-badge {
  display: flex;
  align-items: center;
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-card-header);
  border: 1px solid var(--border-color);
  padding: 7px 14px;
  border-radius: 999px;
}

.db-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--success);
  background: var(--success-soft);
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid rgba(22, 163, 74, 0.3);
}

.status-dot {
  width: 7px;
  height: 7px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.6);
  animation: pulseDot 1.8s ease-out infinite;
}

@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.btn-ghost:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-border);
}

.user-tag {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--bg-card-header);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
}

/* ===================== CONTENEDOR PRINCIPAL ===================== */
.content-wrap { max-width: 1760px; margin: 20px auto 32px; padding: 0 var(--report-margin); }

/* ===================== PANEL DE FILTROS ===================== */
.panel-filtros {
  margin: 0 0 20px;
  padding: 18px 22px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filtro-grupo { display: flex; flex-direction: column; gap: 6px; flex: 1 1 150px; min-width: 140px; }

.filtro-grupo label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 700;
}

.filtro-grupo select, .filtro-grupo input {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card-header);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-body);
  height: 38px;
  box-sizing: border-box;
}

.filtro-acciones { display: flex; gap: 8px; }

.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
  border: none;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 14px -4px rgba(37, 99, 235, 0.40);
}

.btn-primary:hover { background: var(--accent-dark); transform: translateY(-1px); }

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover { color: var(--text-primary); border-color: var(--text-muted); background: var(--bg-hover); }

/* ===================== GRID KPIS ===================== */
.kpis-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--grid-gap);
  margin-bottom: 20px;
}

.card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  transition: var(--transition);
}

.card:hover { border-color: var(--accent-border); box-shadow: var(--shadow-card-hover); transform: translateY(-2px); }

.kpi-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
}

.kpi-card::before {
  content: '';
  position: absolute;
  left: 0; top: 16px; bottom: 16px;
  width: 4px;
  border-radius: 999px;
  background: var(--kpi-accent, var(--accent));
}

.kpi-card:nth-child(1) { --kpi-accent: var(--accent); }
.kpi-card:nth-child(2) { --kpi-accent: #0EA5E9; }
.kpi-card:nth-child(3) { --kpi-accent: #8B5CF6; }
.kpi-card:nth-child(4) { --kpi-accent: #10B981; }

.kpi-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-border);
}

.kpi-info { min-width: 0; flex: 1; }

.kpi-info h3 {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 0 0 4px;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.kpi-desc { font-size: 11.5px; color: var(--text-muted); margin: 4px 0 0; }

/* ===================== GRÁFICOS GRID ===================== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--grid-gap);
  margin-bottom: 24px;
}

@media (max-width: 1024px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.chart-card {
  display: flex;
  flex-direction: column;
  min-height: 380px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.chart-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.chart-body {
  position: relative;
  flex: 1;
  width: 100%;
  height: 300px;
}

/* ===================== TABLA DETALLADA ===================== */
.table-card {
  padding: 0;
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-card-header);
  border-bottom: 1px solid var(--border-color);
  gap: 14px;
  flex-wrap: wrap;
}

.table-toolbar h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0;
}

.table-actions { display: flex; align-items: center; gap: 10px; }

.table-search {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 12.5px;
  min-width: 220px;
}

.btn-export {
  background: #16A34A;
  color: #FFFFFF;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}

.btn-export:hover { background: #15803D; }

.table-container {
  overflow-x: auto;
  max-height: 520px;
  overflow-y: auto;
}

table.financial-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  white-space: nowrap;
}

table.financial-table th {
  position: sticky;
  top: 0;
  background: var(--bg-card-header);
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 10.5px;
  padding: 12px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border-color);
  cursor: pointer;
  user-select: none;
  z-index: 2;
}

table.financial-table th:hover { color: var(--text-primary); }

table.financial-table th.num, table.financial-table td.num {
  text-align: right;
  font-family: var(--font-mono);
}

table.financial-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

table.financial-table tbody tr:hover { background: var(--bg-hover); }

/* Paginador */
.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg-card-header);
  border-top: 1px solid var(--border-color);
  font-size: 12.5px;
  color: var(--text-muted);
}

.pagination-controls { display: flex; align-items: center; gap: 8px; }

.pagination-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 700;
}

.pagination-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===================== SECCIONES GERENCIALES Y RECOMENDACIONES ===================== */
.conc-bar {
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: var(--bg-hover);
  margin-bottom: 16px;
  border: 1px solid var(--border-color);
}
.conc-seg {
  height: 100%;
  transition: width 0.3s ease;
}
.conc-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.conc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
}
.conc-item .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.conc-item .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
  font-weight: 500;
}
.conc-item .pct {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-primary);
}

.mover-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 12.5px;
}
.mover-row .m-name {
  width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.mover-row .m-track {
  flex: 1;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 999px;
  overflow: hidden;
}
.mover-row .m-fill { height: 100%; border-radius: 999px; }
.mover-row .m-fill.up { background: #EF4444; }
.mover-row .m-fill.down { background: #10B981; }
.mover-row .m-pct {
  width: 70px;
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
}
.mover-row .m-pct.pos { color: #EF4444; }
.mover-row .m-pct.neg { color: #10B981; }

.rec-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--grid-gap);
  margin-bottom: 24px;
}
@media (max-width: 900px) {
  .rec-grid { grid-template-columns: 1fr; }
}

.rec-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 20px;
}
.rec-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.rec-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; flex-shrink: 0;
}
.rec-icon.danger { background: rgba(239, 68, 68, 0.15); color: #EF4444; }
.rec-icon.warning { background: rgba(245, 158, 11, 0.15); color: #F59E0B; }
.rec-icon.info { background: rgba(37, 99, 235, 0.15); color: #2563EB; }
.rec-icon.success { background: rgba(16, 185, 129, 0.15); color: #10B981; }

.rec-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}
.rec-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}
.rec-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border-color);
  font-size: 12.5px;
}
.rec-list li b {
  color: var(--text-primary);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rec-list li span {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.rec-action {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
  background: var(--bg-card-header);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}
