/* ==========================================================================
   Gestión de Cobranzas — pestaña "Tablero KPIs" (sin panel propio: usa los filtros de la Lista y su "Hasta el mes (X)")
   y las 5 tarjetas acumuladas hasta ese mes (Radar de Recaudación: 1 Meta general, 2 Eficiencia, 3 Mora vieja;
   Consolidado y Alertas: 4 Caja, 5 Riesgo). Cada moneda va en su propia línea y ningún monto se corta: el tamaño de la letra lo ajusta cobranzasKpis.js
   al ancho real de la tarjeta. El diseño se adapta al ANCHO REAL del panel (container query): con los filtros abiertos
   hay menos espacio y las tarjetas pasan a una columna en vez de apretarse o cortarse.
   ========================================================================== */
.cobranzas-page [hidden] { display: none !important; }

/* ----- Barra de herramientas ----- */
#cobranzasPaneTablero .facturas-toolbar,
#cobranzasPaneTablero .facturas-toolbar-left,
#cobranzasPaneTablero .facturas-toolbar-right {
  flex-wrap: wrap;
}

#cobranzasPaneTablero .facturas-toolbar-right { margin-left: auto; }
#cobranzasPaneTablero .facturas-btn:disabled { cursor: not-allowed; opacity: .5; }

.tablero-cobros { font-size: 13px; }

.tablero-hasta strong { color: #17324d; font-weight: 800; }
.tablero-hasta i { color: #27ae60; }

/* Sin panel propio, el tablero ocupa todo el ancho. */
.cobranzas-tablero-workspace {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

.tablero-actualizado {
  color: #64748b;
  font-size: 12px;
  white-space: nowrap;
}

.tablero-actualizado strong { color: #334155; font-weight: 700; }
.tablero-actualizado i { color: #94a3b8; margin-right: 3px; }

/* Aviso de filtros activos: sin filtros es discreto; con filtros se resalta para que no se olvide que las cifras son parciales. */
#tableroFiltrosActivos.con-filtros,
#grfFiltrosActivos.con-filtros,
#cobranzasFiltrosActivos.con-filtros {
  background: #fff7e6;
  border: 1px solid #f5c26b;
  border-radius: 999px;
  color: #8a5a00;
  font-weight: 700;
  padding: 4px 12px;
}

#tableroFiltrosActivos.con-filtros i,
#cobranzasFiltrosActivos.con-filtros i,
#grfFiltrosActivos.con-filtros i { color: #d97706; }

/* ----- "Hasta el mes (X)" del Tablero y los Gráficos: primero en el panel de filtros de la Lista ----- */
.cobranzas-mes-corte {
  background: #eafaf1;
  border: 1px solid #2ecc71;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 14px;
  padding: 10px 12px 12px;
}

.cobranzas-mes-corte-titulo {
  align-items: center;
  color: #1e8449;
  display: flex;
  font-size: 14px;
  font-weight: 800;
  gap: 6px;
}

.cobranzas-mes-corte-controles {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) minmax(84px, auto);
}

.cobranzas-mes-corte-controles .form-control {
  color: #2980b9;
  font-weight: 700;
  min-width: 0;
}

.cobranzas-mes-corte-nota {
  color: #4b6b58;
  font-size: 11.5px;
  line-height: 1.35;
}

/* ----- Contenedor ----- */
.cobranzas-tablero-card {
  background: linear-gradient(180deg, #fcfdff, #f6f9fe);
  border-radius: 14px;
  container-name: tablero;
  container-type: inline-size;
  overflow: auto;
  padding: 12px 18px 18px;
}

/* Fondo apenas azulado para que las tarjetas resalten (con dos clases para ganar a la tarjeta general). */
.cobranzas-body .facturas-results-card.cobranzas-tablero-card {
  background: linear-gradient(180deg, #fcfdff, #f5f8fe);
}

.tablero-estado {
  align-items: center;
  color: #475569;
  display: flex;
  flex: 1 1 auto;
  font-size: 14px;
  gap: 10px;
  justify-content: center;
  min-height: 160px;
  text-align: center;
}

.tablero-estado.error { color: #b42318; }

.tablero-kpis { transition: opacity .15s ease; }
.tablero-kpis.actualizando { opacity: .55; pointer-events: none; }

.tablero-periodo {
  align-items: center;
  background: #fff;
  border: 1px solid #dbe7f6;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(16, 42, 86, 0.05);
  color: #475569;
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 6px;
  margin: 0;
  padding: 3px 14px;
  width: fit-content;
}

.tablero-periodo i { color: #27ae60; }
.tablero-periodo strong { color: #17324d; font-size: 14px; }
.tablero-periodo-hoy { color: #7f8c8d; }

/* Título de sección: ícono en recuadro y una línea que se desvanece. */
.tablero-seccion {
  align-items: center;
  color: #12294a;
  display: flex;
  font-size: 17px;
  font-weight: 800;
  gap: 10px;
  margin: 10px 0 10px;
}

.tablero-seccion i {
  align-items: center;
  background: linear-gradient(145deg, #4a97f5, #2b74de);
  border-radius: 9px;
  box-shadow: 0 8px 14px -6px rgba(43, 116, 222, 0.7);
  color: #fff;
  display: inline-flex;
  flex: 0 0 28px;
  font-size: 13px;
  height: 28px;
  justify-content: center;
}

.tablero-seccion::after {
  background: linear-gradient(90deg, #c9dcf7, rgba(201, 220, 247, 0));
  content: "";
  flex: 1 1 40px;
  height: 2px;
}

.tablero-fila {
  align-items: stretch;
  display: grid;
  gap: 18px;
}

.tablero-fila-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tablero-fila-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ----- Tarjeta (colores de la app: azul, verde, ámbar, violeta y rojo). Cada una define su acento y su tinte. ----- */
.tablero-kpi {
  --tk-acento: #17324d;
  --tk-acento-claro: #3f72ab;
  --tk-tinte: #eef4fc;
  --tk-borde: #dfe8f4;
  background: linear-gradient(180deg, var(--tk-tinte) 0, #fff 84px);
  border: 1px solid var(--tk-borde);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(16, 42, 86, 0.04), 0 14px 28px -18px rgba(16, 42, 86, 0.28);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  padding: 15px 20px 14px;
  position: relative;
  transition: box-shadow .2s ease, border-color .2s ease;
}

/* Franja superior con el color de la tarjeta. */
.tablero-kpi::before {
  background: linear-gradient(90deg, var(--tk-acento), var(--tk-acento-claro));
  content: "";
  height: 4px;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
}

.tablero-kpi:hover { box-shadow: 0 1px 2px rgba(16, 42, 86, 0.05), 0 22px 38px -18px rgba(16, 42, 86, 0.36); }

.tk-eficiencia { --tk-acento: #128a5a; --tk-acento-claro: #3ccf97; --tk-tinte: #ecfaf3; --tk-borde: #d4efe2; }
.tk-atrasos { --tk-acento: #e08600; --tk-acento-claro: #ffc04d; --tk-tinte: #fff6e5; --tk-borde: #f6e5c4; }
.tk-caja { --tk-acento: #6d28d9; --tk-acento-claro: #a276ff; --tk-tinte: #f4eefe; --tk-borde: #e6dcfa; }
.tk-riesgo { --tk-acento: #d4373c; --tk-acento-claro: #ff7a7d; --tk-tinte: #fff0f0; --tk-borde: #f8cfd0; }

/* La alerta de riesgo "late" suavemente solo cuando hay cuotas en riesgo. */
@keyframes tk-latido {
  0% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.35); }
  70% { box-shadow: 0 0 0 9px rgba(229, 72, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0); }
}

.tk-riesgo.tk-alerta-activa { animation: tk-latido 2.2s infinite; }

@media (prefers-reduced-motion: reduce) {
  .tk-riesgo.tk-alerta-activa { animation: none; box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.18); }
  .tablero-kpi, .tablero-kpis { transition: none; }
}

.tk-cabecera {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.tk-titulo {
  color: #1d3557;
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: 0.045em;
  line-height: 1.3;
  text-transform: uppercase;
}

/* Con dos clases para ganar a Font Awesome (se carga después y dejaba el dibujo en una esquina). */
.tk-cabecera .tk-icono {
  align-items: center;
  background: linear-gradient(145deg, var(--tk-acento-claro), var(--tk-acento));
  border-radius: 11px;
  box-shadow: 0 9px 16px -8px var(--tk-acento);
  color: #fff;
  display: inline-flex;
  flex: 0 0 36px;
  font-size: 16px;
  height: 36px;
  justify-content: center;
}

.tk-descripcion {
  color: #6e8199;
  font-size: 12px;
  line-height: 1.4;
  margin: -5px 0 0;
}

.tk-cuerpo {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

/* Montos: cifras alineadas (tabulares) y nunca recortadas con "...". */
.tk-monto {
  color: #102a43;
  display: block;
  flex: 0 1 auto;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1.3;
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: clip;
  white-space: nowrap;
}

.tk-moneda {
  color: #7b8da3;
  flex: 0 0 auto;
  font-size: 11.5px;
  font-weight: 800;
}

.tk-cant {
  background: #f1f5fa;
  border-radius: 999px;
  color: #5f748d;
  flex: 0 0 auto;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1.3;
  padding: 1px 8px;
  white-space: nowrap;
}

.tk-monto.verde, .tk-moneda.verde { color: #087f5b; }
.tk-monto.rojo, .tk-moneda.rojo { color: #c0392b; }
.tk-monto.naranja, .tk-moneda.naranja { color: #b45309; }
.tk-monto.morado, .tk-moneda.morado { color: #6d28d9; }

/* Tarjeta 1: recibido y pendiente en grande, cada uno en su franja. */
.tk-bloque { display: flex; flex-direction: column; gap: 5px; }

.tk-destacado {
  align-items: center;
  background: #fff;
  border: 1px solid #e3ecf7;
  border-radius: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  justify-content: space-between;
  padding: 2px 11px;
}

.tk-destacado.tk-secundario { background: #f7f9fc; border-style: dashed; }

.tk-destacado-etiqueta {
  color: #4a5d73;
  flex: 1 1 160px;
  font-size: 13px;
  font-weight: 600;
}

.tk-destacado-etiqueta b { color: #17324d; font-weight: 800; white-space: nowrap; }

.tk-destacado-monto {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-left: auto;
  max-width: 100%;
  min-width: 0;
}

.tk-destacado-monto .tk-moneda { color: #17324d; font-size: 14px; }
.tk-monto-grande { font-size: 22px; letter-spacing: -0.01em; }
.tk-secundario .tk-monto, .tk-secundario .tk-destacado-monto .tk-moneda { color: #61758f; }

.tk-pie {
  border-top: 1px dashed #d5dee8;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
}

/* Fila "etiqueta: cantidad + monto". Si no caben juntas, los valores bajan debajo de la etiqueta (nunca se salen). */
.tk-linea {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  justify-content: space-between;
}

.tk-linea.tk-separada { border-top: 1px dashed #e3e9f0; padding-top: 8px; }

.tk-etiqueta {
  color: #4a5d73;
  flex: 1 1 170px;
  font-size: 12.5px;
  line-height: 1.4;
  min-width: 0;
}

.tk-etiqueta b { color: #17324d; font-weight: 800; }
.tk-etiqueta small { color: #7b8da3; font-size: 12px; }

.tk-linea.tk-alerta {
  background: #fff5f5;
  border: 1px solid #fbdcdc;
  border-radius: 12px;
  margin: 0 -9px;
  padding: 5px 8px;
}

.tk-alerta .tk-etiqueta, .tk-alerta .tk-etiqueta b, .tk-alerta .tk-etiqueta small { color: #c0392b; }
.tk-alerta .tk-cant { background: #fde8e8; color: #a8362d; }

.tk-valores {
  align-items: flex-end;
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  gap: 4px;
  margin-left: auto;
  max-width: 100%;
  min-width: 0;
}

.tk-valor {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  max-width: 100%;
  min-width: 0;
}

/* "% Eficiencia: 56.8%" — alineado a la derecha, cada porcentaje en su píldora. */
.tk-pct-linea {
  align-items: center;
  color: #4a5d73;
  display: flex;
  flex-wrap: wrap;
  font-size: 12.5px;
  gap: 4px 10px;
  justify-content: flex-end;
  margin: -2px 0 0;
}

.tk-pct-valor { align-items: center; display: inline-flex; gap: 5px; }

.tk-pct-valor strong {
  background: #e7f2fe;
  border-radius: 999px;
  color: #1467c4;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  padding: 1px 10px;
}

.tk-pct-valor small { color: #7b8da3; font-weight: 700; }
.tk-meta .tk-pct-linea { font-size: 14px; justify-content: center; }
.tk-meta .tk-pct-valor strong { font-size: 18px; padding: 0 14px; }

/* Tarjetas 3 y 4: avisos. */
.tk-aviso {
  align-items: center;
  background: #fff8e6;
  border: 1px solid #f5d27a;
  border-radius: 12px;
  color: #92400e;
  display: flex;
  font-size: 13px;
  font-weight: 700;
  gap: 8px;
  justify-content: center;
  margin: 4px 0 0;
  padding: 7px 12px;
  text-align: center;
}

.tk-atrasos .tk-aviso { margin-top: auto; }
.tk-atrasos .tk-aviso b { font-size: 15px; }

/* Tarjeta 4: total del mes en grande, en su propio panel. */
.tk-total {
  align-items: flex-end;
  background: linear-gradient(135deg, #f1e9ff, #fbf9ff);
  border: 1px solid #e3d6fc;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 6px 14px;
}

.tk-total-monto {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  max-width: 100%;
  min-width: 0;
}

.tk-total-monto .tk-moneda { font-size: 15px; }
.tk-total-monto .tk-monto-grande { font-size: 26px; }
.tk-caja .tk-pie { border-top: 0; margin-top: 2px; padding-top: 0; }
.tk-caja .tk-pie .tk-linea + .tk-linea { border-top: 1px dashed #e6e0f5; padding-top: 8px; }

/* Tarjeta 5: cantidad y monto en riesgo, centrados y en rojo. */
.tk-riesgo-centro {
  align-items: center;
  background: radial-gradient(closest-side, rgba(229, 72, 77, 0.09), rgba(229, 72, 77, 0));
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
  text-align: center;
}

.tk-conteo {
  color: #c0392b;
  font-size: 27px;
  font-weight: 800;
  line-height: 1.1;
  margin: 2px 0;
}

.tk-conteo strong { font-size: 38px; letter-spacing: -0.02em; margin-right: 2px; }

.tk-riesgo-etiqueta { color: #4a5d73; font-size: 13.5px; margin: 6px 0 0; }
.tk-riesgo-etiqueta i { color: #e5484d; }

.tk-riesgo-monto {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: center;
  max-width: 100%;
  min-width: 0;
}

.tk-riesgo-monto .tk-moneda { font-size: 15px; }

.tk-leyenda {
  background: #fde9e9;
  border: 1px solid #f9caca;
  border-radius: 999px;
  color: #b42318;
  font-size: 12px;
  font-weight: 700;
  margin: 8px 0 0;
  padding: 5px 14px;
}

/* ----- Panel angosto (filtros abiertos, pantallas medianas): una tarjeta por fila ----- */
@container tablero (max-width: 980px) {
  .tablero-fila-3,
  .tablero-fila-2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 759px) {
  .tablero-fila-3,
  .tablero-fila-2 { grid-template-columns: minmax(0, 1fr); }
  .tablero-kpi { padding: 14px 16px; }
  .tk-monto-grande { font-size: 19px; }
  .tk-total-monto .tk-monto-grande { font-size: 22px; }
}

@media print {
  .tablero-kpi { break-inside: avoid; }
}
