/* ============================================================
 * Consulta de Recomendaciones y Explicabilidad — Tecnofast
 * Estilos (separación de roles desde index.html)
 * Estructura: html/index.html · Scripting: html/js/app.js
 * ============================================================ */

/* 1. ESPECIFICACIONES VISUALES Y REGLAS GENERALES */
:root {
  --bg-page: #f4f6f8;
  --bg-card: #ffffff;
  --border-soft: #cbd5e1;
  --accent-red: #d32f2f;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-radius: 6px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family:
    "Segoe UI",
    -apple-system,
    BlinkMacSystemFont,
    Tahoma,
    Geneva,
    Verdana,
    sans-serif;
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  padding-bottom: 40px;
}

/* 2. ESTRUCTURA Y UX/UI DEL HEADER SUPERIOR */
.top-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background-color: #e2e7ec;
  padding: 12px 35px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
}

.header-left {
  justify-self: start;
  display: flex;
  align-items: center;
}
.header-center {
  justify-self: center;
}
.header-right {
  justify-self: end;
  display: flex;
  align-items: center;
}

.header-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 17px;
  color: #1e293b;
  font-weight: 600;
  margin: 0;
  text-align: center;
}
.entorno-chip {
  display: inline-block;
  background: #ffffff;
  color: #334155;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.entorno-chip--local { border-color: #757575; color: #757575; }
.entorno-chip--test { border-color: #0288d1; color: #0288d1; }
.entorno-chip--dev { border-color: #2e7d32; color: #2e7d32; }
.entorno-chip--qa { border-color: #ed6c02; color: #ed6c02; }

.penta-badge {
  background: #ffffff;
  padding: 4px 14px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  gap: 8px;
}

.penta-badge span {
  color: #64748b;
  font-size: 11px;
  font-weight: 600;
}

/* HEADER INFERIOR (Buscador, Fechas, Período y Botón Más Filtros) */
.sub-header {
  background-color: #ebeff3;
  padding: 10px 35px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid #cbd5e1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  flex-wrap: wrap;
}

.search-box-container {
  position: relative;
  width: 100%;
  max-width: 420px;
}

.search-box-container input {
  width: 100%;
  padding: 8px 16px 8px 36px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
  background-color: #ffffff;
  color: #1e293b;
  font-size: 12.5px;
  outline: none;
  transition: all 0.2s;
  height: 36px;
}

.search-box-container input::placeholder {
  color: #64748b;
}

.search-box-container input:focus {
  border-color: #3b82f6;
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--accent-red);
}

/* SELECTORES E INPUTS EN EL SUB-HEADER CON ESTILO UNIFICADO */
.header-inline-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #475569;
}

.header-inline-filter input[type="date"],
.header-inline-filter select {
  padding: 6px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  background: #ffffff;
  font-size: 12px;
  outline: none;
  color: #1e293b;
  height: 36px;
  cursor: pointer;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.range-separator {
  font-size: 12px;
  color: #475569;
  font-weight: 600;
  padding: 0 2px;
}

/* BOTÓN MÁS FILTROS */
.btn-filtros {
  padding: 7px 18px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  height: 36px;
  white-space: nowrap;
}

.btn-filtros:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-filtros .material-symbols-outlined {
  font-size: 16px;
  color: var(--accent-red);
}

.btn-actualizar {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #334155;
  padding: 7px 18px;
  border-radius: 20px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  height: 36px;
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  box-sizing: border-box;
  white-space: nowrap;
}

.btn-actualizar:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  color: var(--accent-red);
}

.btn-actualizar .material-symbols-outlined {
  font-size: 16px;
  color: var(--accent-red);
}

/* Fechas cambiadas y no aplicadas: consulta pendiente */
.btn-actualizar.pendiente:not(:disabled),
.btn-actualizar.pendiente:not(:disabled):hover {
  border-color: #d32f2f;
  animation: btn-actualizar-respirar 1.8s ease-in-out infinite;
}
@keyframes btn-actualizar-respirar {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(211, 47, 47, 0);
  }
  50% {
    box-shadow: 0 0 14px 4px rgba(211, 47, 47, 0.65);
  }
}
@media (prefers-reduced-motion: reduce) {
  .btn-actualizar.pendiente:not(:disabled),
  .btn-actualizar.pendiente:not(:disabled):hover {
    animation: none;
    box-shadow: 0 0 10px 2px rgba(211, 47, 47, 0.55);
  }
}

/* Customización picker fecha */
input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  filter: invert(18%) sepia(88%) saturate(4854%) hue-rotate(352deg)
    brightness(91%) contrast(92%);
}

/* 3. COMPONENTES DE LA INTERFAZ - CONTENEDOR ANCHO COMPLETO */
.main-container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 20px 35px;
}

/* Panel de Filtros Adicionales (2 Filas x 5 Columnas) */
.filter-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--border-radius);
  padding: 20px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px 20px;
  align-items: flex-end;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}

@media (max-width: 1200px) {
  .filter-panel {
    grid-template-columns: repeat(3, 1fr);
  }
}
@media (max-width: 768px) {
  .filter-panel {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 480px) {
  .filter-panel {
    grid-template-columns: 1fr;
  }
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}

.filter-panel label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.filter-panel select {
  padding: 7px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  background: #fff;
  color: #1e293b;
  width: 100%;
  height: 36px;
}

.btn-limpiar {
  padding: 8px 16px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: #334155;
  height: 36px;
  white-space: nowrap;
  width: 100%;
}

.btn-limpiar:hover {
  background: #e2e8f0;
}

/* CAJA BLANCA CONTENEDORA PRINCIPAL DE LA TABLA Y ENCABEZADO */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--border-radius);
  padding: 20px 24px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
  margin-bottom: 20px;
}

/* FILA DE ENCABEZADO CON TÍTULO, ORDENAMIENTO Y SELECTOR DE PÁGINAS */
.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
  gap: 12px;
}

.section-title {
  font-size: 16.5px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 4px solid var(--accent-red);
  padding-left: 10px;
  margin: 0;
}

.metric-header-pill {
  background: #ffffff;
  color: #334155;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.header-controls-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.sort-container,
.rows-per-page-container {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.sort-header-icon {
  width: 15px;
  height: 15px;
  fill: var(--accent-red);
  flex-shrink: 0;
}

.sort-container select,
.rows-per-page-container select {
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 12px;
  outline: none;
  background: #ffffff;
  cursor: pointer;
  color: var(--text-main);
  font-weight: 600;
}

/* GRUPO DE OPORTUNIDADES Y ENCABEZADO OPTIMIZADO EN 2 FILAS DE 7 COLUMNAS */
.opportunity-group {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--border-radius);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
  margin-bottom: 16px;
  overflow: hidden;
  width: 100%;
}

.opportunity-group:last-child {
  margin-bottom: 0;
}

.opportunity-header {
  background: #f8fafc;
  border-bottom: 1px solid var(--border-soft);
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.opportunity-header:hover {
  background-color: #f1f5f9;
}

/* Grilla de 7 Columnas x 2 Filas para los 14 campos */
.header-fields-grid-2rows {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px 14px;
  flex-grow: 1;
}

@media (max-width: 1400px) {
  .header-fields-grid-2rows {
    grid-template-columns: repeat(4, 1fr);
  }
}
@media (max-width: 900px) {
  .header-fields-grid-2rows {
    grid-template-columns: repeat(2, 1fr);
  }
}

.opp-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.opp-label {
  font-size: 9.5px;
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.opp-value {
  font-size: 12px;
  color: #0f172a;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Ícono del acordeón en rojo */
.toggle-icon {
  font-size: 18px;
  color: var(--accent-red);
  transition: transform 0.3s ease;
  margin-left: 10px;
  flex-shrink: 0;
}

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

.opportunity-group.collapsed .toggle-icon {
  transform: rotate(-90deg);
}
.opportunity-group.collapsed .opportunity-body {
  display: none;
}
.opportunity-group.collapsed .opportunity-header {
  border-bottom: none;
}

/* TABLA DE PRODUCTOS / LÍNEAS DE COTIZACIÓN */
.table-container {
  width: 100%;
  overflow-x: auto;
}
/* Anchos por clase de <col>; min-width = columnas base sin caracterización */
.products-table {
  --w-producto: 200px;
  --w-num: 68px;
  --w-pct: 68px;
  --w-pbb: 50px;
  --w-toggle: 40px;
  --w-icono: 90px;
  --w-texto: 130px;
  --w-vars: 120px;
  --w-justif: 200px;
  --w-tech-justif: 200px;
  width: 100%;
  min-width: 1222px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 11.5px;
}

.products-table col.col-w-producto { width: var(--w-producto); }
.products-table col.col-w-num { width: var(--w-num); }
.products-table col.col-w-pct { width: var(--w-pct); }
.products-table col.col-w-pbb { width: var(--w-pbb); }
.products-table col.col-w-toggle { width: var(--w-toggle); }
.products-table col.col-w-icono { width: var(--w-icono); }
.products-table col.col-w-texto { width: var(--w-texto); }
.products-table col.col-w-vars { width: var(--w-vars); }
.products-table col.col-w-justif { width: var(--w-justif); }
.products-table col.col-w-tech-justif { width: var(--w-tech-justif); }
.products-table th {
  background-color: #ffffff;
  text-align: left;
  padding: 8px 8px;
  border-bottom: 2px solid var(--border-soft);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 10px;
  white-space: normal;
}
.products-table th.char-col,
.products-table td.char-col {
  background-color: #f8fafc;
}
.products-table td {
  padding: 6px 8px;
  overflow-wrap: anywhere;
  border-bottom: 1px solid var(--border-soft);
  color: #334155;
  vertical-align: top;
}
.products-table tr:last-child td {
  border-bottom: none;
}
.products-table tfoot td {
  border-top: 2px solid var(--border-soft);
  background-color: #f8fafc;
  color: #0f172a;
  font-weight: 600;
}

.products-table th.col-vars,
.products-table td.col-vars,
.products-table th.col-justif,
.products-table td.col-justif,
.products-table th.col-tech-justif,
.products-table td.col-tech-justif {
  white-space: normal;
}

/* BOTÓN E ÍCONO ROJO CENTRADO PERFECTO EN CABECERA */
.btn-col-toggle {
  background: #ffffff;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.btn-col-toggle:hover {
  border-color: var(--accent-red);
  background: #fff5f5;
}

.icon-red-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: var(--accent-red);
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  line-height: 0;
  flex-shrink: 0;
  text-align: center;
}

.var-relev-list {
  list-style-type: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.var-relev-list li {
  position: relative;
  padding-left: 12px;
  line-height: 1.35;
  font-size: 11.5px;
}
.var-relev-list li::before {
  content: "•";
  color: var(--accent-red);
  position: absolute;
  left: 0;
  top: 0;
  font-weight: bold;
}
.justification-text {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #14532d;
  padding: 9px 12px;
  border-radius: 4px;
  line-height: 1.45;
  font-size: 11.5px;
}
.val-number {
  font-family: "Consolas", "Courier New", monospace;
  font-weight: 600;
  white-space: nowrap;
}
.val-highlight {
  color: #047857;
  font-weight: 700;
}

/* Chips de cabecera de cotización */
.chip-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.chip-grupo-cotizacion,
.chip-estado-cotizacion,
.chip-segmento-cliente {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 10px;
  border-radius: 100px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
  color: #ffffff;
  white-space: nowrap;
}
.chip-segmento-cliente .material-symbols-outlined {
  font-size: 14px;
  padding-left: 2px;
  margin-right: -3px;
}

/* Grupos de cotización */
.chip-grupo-cotizacion--control {
  background: #3b82f6;
}
.chip-grupo-cotizacion--recomendado {
  background: #16a34a;
}
.chip-grupo-cotizacion--sin-grupo {
  background: #475569;
}

/* Estados de cotización */
.chip-estado-cotizacion--ganada {
  background: #16a34a;
}
.chip-estado-cotizacion--abierta {
  background: #f59e0b;
}
.chip-estado-cotizacion--perdida {
  background: #dc2626;
}

/* Segmentos de cliente */
.chip-segmento-cliente--CA { /* Campeones */
  background: #172f73;
}
.chip-segmento-cliente--BA { /* Ballenas */
  background: #1e4fd0;
}
.chip-segmento-cliente--LE { /* Leales */
  background: #3b78ec;
  color: #050917;
}
.chip-segmento-cliente--OA { /* Otros activos */
  background: #5a8ef0;
  color: #050917;
}
.chip-segmento-cliente--NU { /* Nuevos */
  background: #7eabf4;
  color: #050917;
}
.chip-segmento-cliente--ER { /* En Riesgo */
  background: #92400e;
}
.chip-segmento-cliente--DO { /* Dormidos */
  background: #c2650a;
  color: #1d0d03;
}
.chip-segmento-cliente--UV { /* Una sola vez */
  background: #d9922a;
  color: #1d0d03;
}
.chip-segmento-cliente--PR { /* Prospectos */
  background: #94a3b8;
  color: #1e2125;
}
.chip-segmento-cliente--SA { /* Sin actividad */
  background: #cbd5e1;
  color: #1e2125;
}

.card-pill-tag--control {
  background: #dbeafe;
  color: #1e40af;
  border-color: #bfdbfe;
}
.card-pill-tag--recomendado {
  background: #dcfce7;
  color: #166534;
  border-color: #bbf7d0;
}
.card-pill-tag--sin-grupo {
  background: #f1f5f9;
  color: #334155;
  border-color: #cbd5e1;
}

.prob-pct-value--control {
  color: #1d4ed8;
}
.prob-pct-value--recomendado {
  color: #047857;
}
.prob-pct-value--sin-grupo {
  color: #334155;
}

.prob-result-badge--control {
  color: #1d4ed8;
  background: #eff6ff;
  border-color: #bfdbfe;
}
.prob-result-badge--recomendado {
  color: #047857;
  background: #ecfdf5;
  border-color: #a7f3d0;
}
.prob-result-badge--sin-grupo {
  color: #334155;
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.justification-text--control {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e3a8a;
}
.justification-text--recomendado {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #14532d;
}
.justification-text--sin-grupo {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #334155;
}

.val-highlight--control {
  color: #1d4ed8;
  font-weight: 700;
}
.val-highlight--recomendado {
  color: #047857;
  font-weight: 700;
}
.val-highlight--sin-grupo {
  color: #334155;
  font-weight: 700;
}
.col-highlight-control {
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
}
.col-highlight-recomendacion {
  background: #f0fdf4;
  color: #047857;
  font-weight: 700;
}
.products-table th.col-highlight-control {
  background-color: #dbeafe;
  color: #1e40af;
}
.products-table td.col-highlight-control {
  background-color: #eff6ff;
  color: #1e3a8a;
}
.products-table th.col-highlight-recomendacion {
  background-color: #dcfce7;
  color: #166534;
}
.products-table td.col-highlight-recomendacion {
  background-color: #f0fdf4;
  color: #14532d;
}

/* Estilos para la paginación */
.pagination-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 28px;
}
.pagination-ellipsis {
  color: var(--text-muted);
  font-weight: 600;
  padding: 6px 8px;
  font-size: 13px;
}

.pagination-jump-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 16px;
}

.pagination-jump-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.pagination-jump-input {
  width: 60px;
  padding: 6px 8px;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  font-size: 12px;
  text-align: center;
  outline: none;
}

.pagination-jump-input:focus {
  border-color: var(--accent-red);
  box-shadow: 0 0 0 2px rgba(211, 47, 47, 0.1);
}

.page-btn.active:disabled {
  background: var(--accent-red);
  color: #ffffff;
  border-color: var(--accent-red);
  cursor: default;
  opacity: 1;
  font-weight: 700;
}

.page-btn.active:disabled:hover {
  background: var(--accent-red);
  transform: none;
  box-shadow: none;
}

.page-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-soft);
  background: #ffffff;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.page-btn:hover {
  background: #f1f5f9;
}
.page-btn.active {
  background: var(--accent-red);
  color: #ffffff;
  border-color: var(--accent-red);
}
.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.page-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.page-nav .material-symbols-outlined {
  font-size: 16px;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------- */
/* VISTA DE TARJETAS (GRILLA DINÁMICA 2 O 4 COLUMNAS)    */
/* ---------------------------------------------------- */

/* Botones de conmutación de vista (lista / tarjetas) */
.view-toggle {
  display: flex;
  gap: 2px;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 6px;
}
.view-btn {
  border: none;
  background: transparent;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  color: #64748b;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.view-btn:hover {
  color: #334155;
}
.view-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.view-btn.active {
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  color: var(--accent-red);
}
.view-btn .material-symbols-outlined {
  font-size: 16px;
}

/* Botonera de estado de oportunidad (filtro multiple) */
.estado-toggle {
  display: flex;
  gap: 2px;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 6px;
}
.estado-btn {
  border: none;
  background: transparent;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  transition: all 0.2s;
}
.estado-btn:hover {
  color: #334155;
}
.estado-btn.active {
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  color: var(--accent-red);
}
.estado-btn.active[data-estado="Abierta"] {
  background: #f59e0b;
  color: #ffffff;
}
.estado-btn.active[data-estado="Ganada"] {
  background: #16a34a;
  color: #ffffff;
}
.estado-btn.active[data-estado="Perdida"] {
  background: #dc2626;
  color: #ffffff;
}

/* Contenedor de la grilla de tarjetas */
.cards-grid-container {
  display: grid;
  gap: 16px;
  width: 100%;
}

/* 2 tarjetas por fila ocupando todo el ancho */
.cards-grid-cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* 4 tarjetas por fila */
.cards-grid-cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1280px) {
  .cards-grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 680px) {
  .cards-grid-cols-2,
  .cards-grid-cols-4 {
    grid-template-columns: 1fr;
  }
}

/* Tarjeta individual */
.custom-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--border-radius);
  padding: 15px 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: all 0.2s ease;
  min-width: 0;
}
.custom-card:hover {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
  border-color: #94a3b8;
}

/* Cabecera de tarjeta: píldora + ID */
.custom-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-pill-tag {
  background: #dcfce7;
  color: #166534;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid #bbf7d0;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.card-top-id {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  font-family: "Consolas", monospace;
}

/* Título y sub-info de la tarjeta */
.card-main-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
  line-height: 1.35;
  border-left: 3px solid var(--accent-red);
  padding-left: 8px;
  word-break: break-word;
}
.card-sub-info {
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: -3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 11px;
}

/* Bloque de probabilidad */
.card-prob-box {
  background: #f8fafc;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 7px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.prob-left {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.prob-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.prob-pct-value {
  font-size: 18px;
  font-weight: 800;
  color: #047857;
  font-family: "Consolas", monospace;
  line-height: 1;
}
.prob-result-badge {
  font-size: 11.5px;
  font-weight: 700;
  color: #047857;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 2px 7px;
  border-radius: 4px;
}

/* Matriz de resumen 2x2 */
.card-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
  font-size: 11px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 8px 10px;
}
.meta-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.meta-label {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.meta-val {
  font-weight: 600;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Etiqueta de sección dentro de la tarjeta */
.card-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.3px;
  margin-bottom: 5px;
  margin-top: 2px;
}

/* Lista de factores con barras */
.factors-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.factor-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.factor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: #334155;
}
.factor-impact {
  font-weight: 700;
  font-family: "Consolas", monospace;
  font-size: 11px;
}
.factor-impact.positive {
  color: #047857;
}
.factor-impact.negative {
  color: #b91c1c;
}
.precio-ok {
  font-size: 18px;
  font-weight: 700;
  vertical-align: middle;
}
.precio-ok--si {
  color: #047857;
}
.precio-ok--no {
  color: #b91c1c;
}
.factor-bar-track {
  width: 100%;
  height: 5px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}
.factor-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}
.factor-bar-fill.positive {
  background: #047857;
}
.factor-bar-fill.negative {
  background: #dc2626;
}
.factor-subcaption {
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Desglose colapsable dentro de la tarjeta */
.card-detail-drawer {
  border-top: 1px dashed var(--border-soft);
  padding-top: 8px;
  margin-top: 2px;
}
.btn-card-details {
  background: #f8fafc;
  border: 1px solid var(--border-soft);
  color: #334155;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  width: 100%;
  justify-content: space-between;
  transition: all 0.2s ease;
}
.btn-card-details:hover {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #94a3b8;
}
.btn-card-details .arrow {
  color: var(--accent-red);
  font-size: 9px;
  font-weight: 800;
}
.card-details-content {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  font-size: 11px;
  background: #f8fafc;
  padding: 10px;
  border-radius: 4px;
  border: 1px solid var(--border-soft);
}
.card-details-content.open {
  display: flex;
}
.details-subgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  font-size: 11px;
}
.det-lbl {
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 700;
}
.det-val {
  font-weight: 600;
  color: #0f172a;
  margin-left: 2px;
}

/* 4. PANTALLA DE CARGA Y PANTALLA DE ERROR (OVERLAYS) */
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 420px;
  background-color: var(--bg-card);
  max-width: 1050px;
  width: 100%;
  margin: 25px auto;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
  padding: 40px 20px;
  text-align: center;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--border-soft);
  border-top: 4px solid var(--accent-red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 18px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0 0 6px 0;
}

.loading-subtext {
  font-size: 13px;
  color: var(--text-muted);
}

/* ----- INDICADOR DE ERROR (ERROR OVERLAY) ----- */
.error-overlay {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 420px;
  background-color: var(--bg-card);
  max-width: 1050px;
  width: 100%;
  margin: 25px auto;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
  padding: 40px 20px;
  text-align: center;
}

.error-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
}

.error-icon {
  font-size: 24px;
  color: var(--accent-red);
  vertical-align: middle;
  margin-right: 6px;
}

.error-subtext {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 32px;
}
