/* ===== RIGA ADMIN — Components v2 (Bloque I refresh) ===== */
/* Linear / Mercury / Stripe / Vercel inspired — scale moderna con respiro */

/* ============================================================ */
/* BUTTONS                                                      */
/* ============================================================ */
.btn {
  --btn-h: 40px;
  --btn-px: 16px;
  --btn-fs: var(--font-size-md);
  --btn-fw: var(--font-weight-semibold);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--btn-h);
  padding: 0 var(--btn-px);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--btn-fs);
  font-weight: var(--btn-fw);
  line-height: 1;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background-color var(--transition-fast),
              border-color var(--transition-fast),
              box-shadow var(--transition-fast),
              color var(--transition-fast),
              transform var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* Primary */
.btn-primary {
  background: var(--primary);
  color: var(--text-on-primary);
  border-color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 159, 179, 0.18);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 2px 6px rgba(0, 159, 179, 0.22);
}
.btn-primary:active:not(:disabled) { background: var(--primary-active); }

/* Success */
.btn-success {
  background: var(--success);
  color: var(--text-on-primary);
  border-color: var(--success);
  box-shadow: 0 1px 2px rgba(5, 150, 105, 0.18);
}
.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
  border-color: var(--success-hover);
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.22);
}

/* Danger */
.btn-danger {
  background: var(--danger);
  color: var(--text-on-primary);
  border-color: var(--danger);
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.18);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.22);
}

/* Outline — default de segundo nivel */
.btn-outline {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-outline:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

/* Ghost — tercer nivel, sin fondo por defecto */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Tamaños */
.btn-sm {
  --btn-h: 32px;
  --btn-px: 12px;
  --btn-fs: var(--font-size-sm);
}
.btn-lg {
  --btn-h: 48px;
  --btn-px: 24px;
  --btn-fs: var(--font-size-lg);
}
.btn-icon {
  --btn-px: 0;
  width: var(--btn-h);
  padding: 0;
}

/* Lucide SVG inline dentro de botones — vertical-align coherente con texto.
   `display:inline-block` evita el space-line bug del SVG inline. */
.btn svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}
/* Icon + label: gap entre svg y span */
.btn svg + span {
  margin-left: 6px;
}
/* En botones icon-only el SVG se centra perfectamente sin shift por text-baseline. */
.btn-icon svg {
  vertical-align: top;
}

/* Loading state · spinner inline + label original atenuado. Uso:
     <button class="btn btn-primary btn-loading">Guardando...</button>
   El spinner es un círculo dashed que rota. Mismo color que el texto
   del button (currentColor). Sin necesidad de SVG. */
.btn-loading {
  position: relative;
  pointer-events: none;
  color: transparent !important;
}
.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  /* Truco para que el spinner sea visible aunque color sea transparent:
     el border usa currentColor que pickea el VALOR original (no el override
     de transparent). En la práctica funciona en todos los browsers modernos. */
  color: var(--text-primary);
}
.btn-primary.btn-loading::after { color: #fff; }
.btn-success.btn-loading::after { color: #fff; }
.btn-danger.btn-loading::after { color: #fff; }
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* Icono Lucide hidratado en texto inline (Icons.hydrateAllEmojis).
   Pequeño, alineado al texto circundante, hereda color. */
.inline-icon {
  display: inline-block;
  vertical-align: -2px;
  margin-right: 2px;
  flex-shrink: 0;
}
/* Cuando el inline-icon está dentro de un h1/h2/h3 escalado o KPI grande,
   se agranda proporcionalmente. */
h1 .inline-icon, h2 .inline-icon, h3 .inline-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  margin-right: 6px;
}
.kpi-card-icon .inline-icon,
.empty-state-icon .inline-icon {
  width: 22px;
  height: 22px;
  margin: 0;
  vertical-align: middle;
}
.empty-state-icon .inline-icon {
  width: 48px;
  height: 48px;
}

.btn-group {
  display: inline-flex;
  gap: var(--space-sm);
}

/* Text utilities usables en botones ghost */
.btn .text-danger { color: var(--danger); }
.btn .text-success { color: var(--success); }
.btn .text-primary { color: var(--primary); }
.btn .text-warning { color: var(--warning); }

/* Botones con clase de text inline */
.btn.text-danger { color: var(--danger); }
.btn.text-success { color: var(--success); }
.btn.text-primary { color: var(--primary); }
.btn.text-warning { color: var(--warning); }
.btn.text-muted { color: var(--text-muted); }

/* ============================================================ */
/* CARDS                                                        */
/* ============================================================ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  transition: box-shadow var(--transition-fast);
}
.card:hover { box-shadow: var(--shadow-sm); }

.card-header {
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  gap: var(--space-md);
}

.card-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  letter-spacing: var(--letter-spacing-tight);
  line-height: var(--line-height-snug);
  margin: 0;
}

.card-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}

.card-body {
  padding: var(--space-xl);
}

.card-footer {
  padding: var(--space-md) var(--space-xl);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  background: var(--bg-subtle);
}

/* ============================================================ */
/* KPI CARDS                                                    */
/* ============================================================ */
.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: var(--space-lg) var(--space-xl);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
  position: relative;
  overflow: hidden;
}
.kpi-card:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.kpi-card-clickable {
  cursor: pointer;
  user-select: none;
}
.kpi-card-clickable:hover {
  border-color: var(--primary);
}
.kpi-card-clickable:hover .kpi-card-value {
  color: var(--primary);
}
.kpi-card-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--primary-light) 180%);
}
.kpi-card-active::after {
  content: "●";
  position: absolute;
  top: 10px;
  right: 12px;
  color: var(--primary);
  font-size: 10px;
  line-height: 1;
}

.kpi-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-md);
  font-size: 1.3rem;
  background: var(--primary-light);
  color: var(--primary);
}

.kpi-card-label {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  margin-bottom: var(--space-xs);
}

.kpi-card-value {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  line-height: var(--line-height-tight);
  letter-spacing: var(--letter-spacing-tight);
  font-variant-numeric: tabular-nums;
}

.kpi-card-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-top: var(--space-xs);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-lg);
}

/* ============================================================ */
/* DATA GRID / TABLE                                            */
/* ============================================================ */
.data-grid-wrapper {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.data-grid-toolbar {
  padding: var(--space-md) var(--space-xl);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.data-grid-search {
  flex: 1;
  min-width: 240px;
  max-width: 320px;
}

.data-grid-filters {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  /* Tabular nums por default en TODAS las celdas: hace que los dígitos
     ocupen el mismo ancho para que columnas de dinero/cantidad alineen
     verticalmente. No afecta letras. Patrón estándar de Stripe/Vercel. */
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

thead th {
  background: var(--bg-subtle);
  padding: 14px var(--space-lg);
  text-align: left;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
  position: sticky;
  top: 0;
  /* z-index alto para que el sticky header se mantenga encima de
     contenido absolute/sticky de las celdas (ej. status chips, dropdowns). */
  z-index: 2;
  /* Shadow sutil al borde inferior. Cuando se scrollea verticalmente
     da feedback visual de que el header está flotando sobre el contenido. */
  box-shadow: inset 0 -1px 0 var(--border-subtle);
}

thead th.sortable {
  cursor: pointer;
  transition: color var(--transition-fast);
}
thead th.sortable:hover { color: var(--text-primary); }
thead th .sort-icon { margin-left: 4px; font-size: 10px; }

tbody td {
  padding: 14px var(--space-lg);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  vertical-align: middle;
}

tbody tr {
  transition: background var(--transition-fast);
  /* Garantizar que cada celda capture el hover sin huecos. Sin esto, en
     algunos browsers/zoom el hover sobre un border o gap entre celdas no
     activa :hover y los botones de acción quedan visualmente "muertos". */
  cursor: default;
}
/* :hover y :focus-within son redundantes intencionalmente: si el cursor
   pasa sobre la celda con tab-focus en un botón interno, la fila se sigue
   marcando como activa. Esto evita el bug "a veces se pinta, a veces no". */
tbody tr:hover,
tbody tr:focus-within {
  background: var(--bg-card-hover);
  /* Magnetismo Linear-style: traslada 2px al hover dando feedback de
     "estás sobre esta fila". Imperceptible solo, evidente al mover el
     mouse. NO se aplica si la fila tiene ya un transform por animation. */
  /* transform: translateX(2px); */
  /* Comentado: en tablas con celdas de monto right-aligned el shift se
     nota raro porque el monto se desalinea visualmente con header.
     Mantenemos solo el bg cambio que es lo importante. */
}
tbody tr:last-child td { border-bottom: none; }

/* Fila seleccionada / destacada */
tbody tr.row-selected {
  background: var(--primary-subtle);
}
tbody tr.row-vencida td {
  background: rgba(239, 68, 68, 0.03);
}

/* La celda de acciones (td) mantiene comportamiento de tabla normal
   (border-bottom, padding) — NO le aplicamos display:flex directo porque
   eso rompe el modelo de tabla y descalibra los borders. */
.table-actions-cell {
  text-align: right;
}
/* El wrapper <div class="table-actions"> dentro de la celda sí es flex. */
.table-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  white-space: nowrap;
}
/* Botones de acción dentro de tablas:
   - pointer-events:auto asegura que respondan al click incluso si algún
     ancestor tiene pointer-events:none por algún hover effect.
   - El * { pointer-events:none } sobre los hijos hace que el e.target del
     click siempre sea el <button> (no un text node interno como un emoji),
     simplificando el matching con [data-action]. */
.table-actions .btn {
  pointer-events: auto;
}
.table-actions .btn > * {
  pointer-events: none;
}

/* ============================================================
   ROW ACTION COLORS (patrón "Mixed/Hover-color" estilo Stripe/QuickBooks)
   ============================================================
   En reposo todos los íconos van en gris medio. La clase semántica
   (text-danger / text-success / text-primary / text-warning) NO pinta
   el ícono — solo dispara el color al hover. Esto evita el ruido
   visual de tener filas con muchos rojos/verdes/azules en reposo.

   Reglas: docs/skills/riga-design-system. */
.table-actions .btn-ghost,
.table-actions .btn-ghost.text-danger,
.table-actions .btn-ghost.text-success,
.table-actions .btn-ghost.text-primary,
.table-actions .btn-ghost.text-warning,
.table-actions .btn-ghost.text-muted {
  color: var(--text-secondary);
  transition: color var(--transition-fast), background var(--transition-fast);
}
.table-actions .btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.table-actions .btn-ghost.text-danger:hover {
  color: var(--danger);
  background: var(--danger-light);
}
.table-actions .btn-ghost.text-success:hover {
  color: var(--success);
  background: var(--success-light);
}
.table-actions .btn-ghost.text-primary:hover {
  color: var(--primary);
  background: var(--primary-light);
}
.table-actions .btn-ghost.text-warning:hover {
  color: var(--warning);
  background: var(--warning-light);
}
.table-actions .btn-ghost.text-muted:hover {
  color: var(--danger);
  background: var(--danger-light);
}

/* ============================================================
   CELL HELPERS — clases utility para celdas comunes
   ============================================================
   Usar dentro de un <td>:
     <td class="cell-money">$1.234,56</td>
     <td class="cell-num">42</td>
     <td class="cell-mono">FC-A-1234</td>
     <td class="cell-truncate">Razón social muy larga…</td>
   También aplicables a <span> dentro del td si la celda mezcla contenido. */

.cell-money,
.cell-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
}
.cell-money {
  font-weight: var(--font-weight-medium, 500);
}
.cell-mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
  color: var(--text-secondary);
}
.cell-truncate {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Para que las celdas con .cell-money apliquen el align-right también
   cuando son <td>, no solo <span>: */
td.cell-money,
td.cell-num,
th.cell-money,
th.cell-num { text-align: right; }

/* ============================================================
   COPYABLE TEXT · click-to-copy (Components.copyableText)
   ============================================================
   Patrón Stripe/Linear/Notion: el texto se ve normal en reposo, al
   hover aparece un ícono clipboard a la derecha y el bg se atenúa.
   Click copia + flash sutil + toast verde "Copiado: X". */
.copyable {
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 4px;
  margin: -1px -4px;
  transition: background var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  /* Permitir selección de texto con drag (usuario que prefiere selección
     manual no se siente bloqueado) — la lógica del click-to-copy detecta
     selección y la respeta. */
  user-select: text;
}
.copyable:hover {
  background: var(--bg-hover);
}
.copyable-icon {
  opacity: 0;
  color: var(--text-muted);
  transition: opacity var(--transition-fast);
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  /* No interferir con la selección de texto del span padre */
  pointer-events: none;
}
.copyable:hover .copyable-icon {
  opacity: 0.65;
}
.copyable-flash {
  background: var(--success-light) !important;
  animation: copyable-flash-pulse 0.6s ease-out;
}
@keyframes copyable-flash-pulse {
  0%   { background: var(--success); color: white; }
  100% { background: var(--success-light); }
}
.copyable-flash .copyable-icon {
  opacity: 1;
  color: var(--success);
}

/* ============================================================
   STATUS CHIPS — pills coloreadas para celdas de estado
   ============================================================ */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: var(--font-weight-semibold, 600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 18px;
  white-space: nowrap;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}
.status-chip.status-borrador,
.status-chip.status-draft,
.status-chip.status-pendiente { background: #FEF3C7; color: #92400E; border-color: #FDE68A; }
.status-chip.status-confirmado,
.status-chip.status-emitido,
.status-chip.status-presentada,
.status-chip.status-procesado { background: var(--info-light); color: var(--info-hover); border-color: var(--info-ring); }
.status-chip.status-pagado,
.status-chip.status-cobrado,
.status-chip.status-conciliado { background: var(--success-light); color: var(--success-hover); border-color: var(--success-ring); }
.status-chip.status-anulado,
.status-chip.status-rechazado,
.status-chip.status-error { background: var(--danger-light); color: var(--danger-hover); border-color: var(--danger-ring); }
.status-chip.status-vencido { background: var(--warning-light); color: var(--warning-hover); border-color: var(--warning-ring); }
/* T-Audit S3.1: aliases adicionales para que statusChip cubra todos los estados
   que tenían las legacy .badge-* y mantenga coherencia visual al migrar */
.status-chip.status-en-cartera,
.status-chip.status-en_cartera { background: var(--badge-en-cartera-bg); color: var(--badge-en-cartera-text); border-color: transparent; }
.status-chip.status-depositado { background: var(--badge-depositado-bg); color: var(--badge-depositado-text); border-color: transparent; }
.status-chip.status-endosado { background: var(--badge-endosado-bg); color: var(--badge-endosado-text); border-color: transparent; }
.status-chip.status-descontado { background: var(--badge-descontado-bg); color: var(--badge-descontado-text); border-color: transparent; }
.status-chip.status-debitado { background: var(--badge-debitado-bg); color: var(--badge-debitado-text); border-color: transparent; }
.status-chip.status-activo,
.status-chip.status-abierto { background: var(--badge-activo-bg); color: var(--badge-activo-text); border-color: transparent; }
.status-chip.status-cerrado { background: var(--badge-cerrado-bg); color: var(--badge-cerrado-text); border-color: transparent; }
.status-chip.status-normal { background: var(--bg-subtle); color: var(--text-secondary); border-color: var(--border-subtle); }
.status-chip.status-anticipo { background: #ede9fe; color: #6d28d9; border-color: #c4b5fd; }

/* ============================================================
   SKELETON LOADER — filas placeholder con shimmer
   ============================================================
   Renderizado por Components.skeletonRows({ cols, rows }). */
.skeleton-row td {
  padding: 14px var(--space-lg);
  border-bottom: 1px solid var(--border-subtle);
}
.skeleton-bar {
  display: block;
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg,
    var(--border-subtle) 0%,
    var(--bg-subtle) 50%,
    var(--border-subtle) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
.skeleton-bar.w-25 { width: 25%; }
.skeleton-bar.w-50 { width: 50%; }
.skeleton-bar.w-75 { width: 75%; }
.skeleton-bar.w-100 { width: 100%; }

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

/* ============================================================
   BULK ACTIONS BAR — barra que emerge al seleccionar filas
   ============================================================
   Pattern: checkbox primer columna → al seleccionar 1+ filas se muestra
   esta barra reemplazando el toolbar normal. Disposición: count a la
   izquierda, acciones masivas a la derecha. */
.bulk-actions-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 10px 16px;
  background: var(--primary-subtle);
  border: 1px solid var(--primary-ring);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  animation: bulk-bar-in 0.18s ease-out;
}
.bulk-actions-bar.is-active { display: flex; }
.bulk-actions-bar .bulk-count {
  font-weight: var(--font-weight-semibold, 600);
  color: var(--primary);
  font-size: var(--font-size-sm);
}
.bulk-actions-bar .bulk-count strong { color: var(--primary-active, var(--primary)); }
.bulk-actions-bar .bulk-actions {
  display: inline-flex;
  gap: 8px;
}
@keyframes bulk-bar-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Checkbox column de selección masiva */
td.row-checkbox-cell,
th.row-checkbox-cell {
  width: 40px;
  text-align: center;
  padding-left: 12px;
  padding-right: 0;
}
tbody tr.row-selected-bulk {
  background: var(--primary-subtle);
}

/* ============================================================
   DATA GRID POPOVERS — column toggle / saved views / faceted filters
   ============================================================ */
.data-grid-wrapper {
  position: relative;
}
.data-grid-popovers {
  position: relative;
}
.dg-popover {
  position: absolute;
  min-width: 240px;
  max-width: 360px;
  max-height: 70vh;
  overflow: hidden;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.06);
  z-index: 100;
  font-size: var(--font-size-sm);
  display: flex;
  flex-direction: column;
  animation: dg-popover-in 0.14s ease-out;
}
@keyframes dg-popover-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.dg-pop-header {
  padding: 10px 14px 8px;
  font-weight: var(--font-weight-semibold, 600);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider, 0.04em);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
}
.dg-pop-subheader {
  padding: 4px 4px 6px;
  font-weight: var(--font-weight-semibold, 600);
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.dg-pop-section + .dg-pop-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}
.dg-pop-body {
  padding: 8px 6px;
  overflow-y: auto;
}
.dg-pop-body-scroll {
  max-height: 50vh;
}
.dg-pop-empty {
  padding: 20px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}
.dg-pop-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
}
.dg-pop-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  user-select: none;
}
.dg-pop-checkbox:hover {
  background: var(--bg-hover);
}
.dg-pop-checkbox input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}
.dg-pop-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}
.dg-pop-item:hover {
  background: var(--bg-hover);
}
.dg-pop-item-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  text-align: left;
}
.dg-pop-item-x {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}
.dg-pop-item-x:hover {
  color: var(--danger);
  background: var(--danger-light);
}

/* Chips de filtros activos (debajo del toolbar) */
.data-grid-active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.data-grid-active-filters:empty {
  display: none;
}
.data-grid-active-filters {
  margin: 8px 0 0;
}
.dg-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  background: var(--info-light);
  border: 1px solid var(--info-ring);
  border-radius: 999px;
  font-size: 12px;
  color: var(--info-hover);
}
.dg-filter-chip strong {
  color: var(--info-hover);
  font-weight: var(--font-weight-semibold, 600);
}
.dg-filter-chip-x {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px;
  color: var(--info-hover);
  display: inline-flex;
  border-radius: 50%;
  transition: background var(--transition-fast);
}
.dg-filter-chip-x:hover {
  background: var(--info-ring);
}
.dg-clear-all {
  font-size: 12px;
  padding: 4px 8px;
  color: var(--text-muted);
}
.dg-clear-all:hover {
  color: var(--text-primary);
}

/* ============================================================
   COMMAND PALETTE · Cmd+K (CommandPalette.open)
   ============================================================ */
.cmdk-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  animation: cmdk-overlay-in 0.15s ease-out;
}
@keyframes cmdk-overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.cmdk-modal {
  width: 100%;
  max-width: 640px;
  max-height: 70vh;
  background: var(--bg-card, #fff);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 64px rgba(0,0,0,0.18), 0 8px 20px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: cmdk-modal-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes cmdk-modal-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.cmdk-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.cmdk-search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}
.cmdk-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 18px;
  color: var(--text-primary);
  font-family: var(--font-family);
}
.cmdk-input::placeholder { color: var(--text-muted); }
.cmdk-shortcut {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: var(--text-muted);
  font-weight: 500;
}
.cmdk-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.cmdk-group {
  margin-bottom: 8px;
}
.cmdk-group-label {
  padding: 6px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.cmdk-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  user-select: none;
}
.cmdk-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-secondary);
}
.cmdk-item-label {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}
.cmdk-item-label mark {
  background: var(--primary-light);
  color: var(--primary-active, var(--primary));
  padding: 0;
  border-radius: 2px;
  font-weight: 600;
}
.cmdk-item-hint {
  font-size: 11px;
  color: var(--text-muted);
}
.cmdk-item-selected,
.cmdk-item:hover {
  background: var(--bg-hover);
}
.cmdk-item-selected .cmdk-item-icon {
  color: var(--primary);
}
.cmdk-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.cmdk-empty svg {
  opacity: 0.4;
}
.cmdk-footer {
  display: flex;
  gap: 16px;
  padding: 10px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  font-size: 11px;
  color: var(--text-muted);
}
.cmdk-footer kbd {
  background: var(--bg-card, #fff);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  margin: 0 2px;
}

/* ============================================================
   DROPDOWN MENU · Components.dropdown (row actions / contextuales)
   ============================================================ */
.dd-wrapper {
  position: relative;
  display: inline-block;
}
.dd-menu {
  position: absolute;
  top: calc(100% + 4px);
  min-width: 200px;
  max-width: 280px;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.06);
  padding: 4px;
  z-index: 200;
  animation: dd-menu-in 0.12s ease-out;
}
.dd-menu.dd-align-left { left: 0; }
.dd-menu.dd-align-right { right: 0; }
.dd-menu.dd-menu-up {
  top: auto;
  bottom: calc(100% + 4px);
}
@keyframes dd-menu-in {
  from { opacity: 0; transform: translateY(-2px); }
  to   { opacity: 1; transform: translateY(0); }
}
.dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
}
.dd-item:hover {
  background: var(--bg-hover);
}
.dd-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-secondary);
}
.dd-item:hover .dd-item-icon {
  color: var(--text-primary);
}
.dd-item-label {
  flex: 1;
}
.dd-item-danger {
  color: var(--danger);
}
.dd-item-danger .dd-item-icon { color: var(--danger); }
.dd-item-danger:hover {
  background: var(--danger-light);
  color: var(--danger-hover);
}
.dd-item-danger:hover .dd-item-icon { color: var(--danger-hover); }
.dd-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0;
}

/* ============================================================
   MULTI-SELECT (typeahead + chips) · Components.multiSelect
   ============================================================ */
.ms-wrapper {
  position: relative;
  display: block;
  width: 100%;
}
.ms-control {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-height: 38px;
  padding: 4px 8px 4px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}
.ms-control:hover {
  border-color: var(--border-strong, #94a3b8);
}
.ms-wrapper.open .ms-control {
  border-color: var(--primary);
  box-shadow: var(--shadow-focus, 0 0 0 3px rgba(34,197,94,0.15));
}
.ms-chips {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  min-height: 26px;
}
.ms-placeholder {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}
.ms-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--primary-subtle);
  color: var(--primary);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.ms-chip-x {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  margin-left: 2px;
  padding: 0 2px;
  border-radius: 50%;
  transition: background var(--transition-fast);
}
.ms-chip-x:hover {
  background: rgba(0,0,0,0.1);
}
.ms-arrow {
  color: var(--text-muted);
  font-size: 12px;
  user-select: none;
}
.ms-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md, 0 4px 12px rgba(0,0,0,0.15));
  z-index: 100;
  max-height: 320px;
  overflow: hidden;
  flex-direction: column;
}
.ms-wrapper.open .ms-dropdown {
  display: flex;
}
.ms-search {
  margin: 8px;
  width: calc(100% - 16px);
}
.ms-options {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  max-height: 220px;
}
.ms-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: background var(--transition-fast);
}
.ms-option:hover {
  background: var(--bg-hover);
}
.ms-option.selected {
  background: var(--primary-subtle);
  color: var(--primary);
  font-weight: 500;
}
.ms-option input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary);
}
.ms-actions {
  display: flex;
  justify-content: space-between;
  padding: 8px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-page);
}

.table-empty {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

/* Paginación */
.data-grid-pagination {
  padding: var(--space-md) var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  background: var(--bg-card);
  gap: var(--space-md);
  flex-wrap: wrap;
}

.pagination-info {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}
.pagination-info strong {
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.pagination-pagesize {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}
.pagination-pagesize select {
  height: 32px;
  padding: 0 var(--space-sm);
  font-size: var(--font-size-sm);
  width: auto;
  min-width: 64px;
}

.pagination-buttons {
  display: flex;
  gap: 4px;
}

.pagination-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}
.pagination-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.pagination-btn.active {
  background: var(--primary);
  color: var(--text-on-primary);
  border-color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 159, 179, 0.2);
}
.pagination-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ============================================================ */
/* FILTER BAR                                                   */
/* ============================================================ */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg) var(--space-xl);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-xs);
}

.filter-bar-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
  align-items: end;
}
.filter-bar-row + .filter-bar-row { margin-top: var(--space-md); }

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.filter-field label {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  color: var(--text-muted);
  font-weight: var(--font-weight-semibold);
}
.filter-field .form-input,
.filter-field .form-select {
  height: 38px;
  font-size: var(--font-size-sm);
}
.filter-field-btn {
  align-self: end;
}

.filter-summary {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px dashed var(--border);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}
.filter-summary:empty { display: none; }
.filter-summary-count strong {
  color: var(--primary);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
}
.filter-summary-tags {
  font-style: italic;
  color: var(--text-muted);
}
.filter-summary-total {
  margin-left: auto;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.filter-summary-total strong { font-size: var(--font-size-md); }

@media (max-width: 900px) {
  .filter-bar-row { grid-template-columns: 1fr 1fr; }
}

/* ============================================================ */
/* FAB GLOBAL — acciones rápidas (patrón Material / Odoo)       */
/* ============================================================ */
.fab-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-sm);
  /* CRÍTICO: el container es transparente y mide ~214x279px (botón + menú
     colapsado). Sin pointer-events:none, captura todos los clicks en su zona
     y bloquea los iconos de tablas que estén abajo a la derecha. Solo los
     elementos hijos VISIBLES (botón + items del menú abierto) reciben events. */
  pointer-events: none;
}
.fab-container > .fab,
.fab-container.open .fab-menu .fab-item {
  pointer-events: auto;
}
.fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}
.fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.fab .fab-icon-plus,
.fab .fab-icon-close {
  position: absolute;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.fab .fab-icon-close { opacity: 0; transform: rotate(-90deg); }
.fab-container.open .fab { background: var(--danger, #dc2626); transform: rotate(45deg); }
.fab-container.open .fab .fab-icon-plus { opacity: 0; }
.fab-container.open .fab .fab-icon-close { opacity: 1; transform: rotate(0deg); }

.fab-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.fab-container.open .fab-menu {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.fab-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  transition: all 0.12s ease;
}
.fab-item:hover {
  text-decoration: none;
  border-color: var(--primary);
  color: var(--primary);
  transform: translateX(-2px);
}
.fab-icon {
  font-size: 18px;
  line-height: 1;
}
@media print {
  .fab-container { display: none !important; }
}

/* Row actions de la Bandeja de Cobranzas (mismo patrón que .table-actions) */
.bc-row-actions {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  /* Evita que el contenido fuerce el td a expandirse u overflowee.
     Si en algún momento hay más botones, el flex respeta la columna. */
  flex-wrap: nowrap;
  white-space: nowrap;
}
.bc-row-actions .btn {
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1;
  min-width: 28px;
  white-space: nowrap;
  transition: color var(--transition-fast), background var(--transition-fast);
}
/* Padding reducido en la celda de acciones: el padding global de <td>
   es 14px×24px que come 48px lateral. Para columnas con 2-3 botones
   ese espacio no alcanza. Bajamos a 8px lateral solo en la celda
   marcada con .bc-actions-cell. */
td.bc-actions-cell { padding-left: 8px; padding-right: 8px; }
th.bc-actions-th   { padding-left: 8px; padding-right: 8px; }
.bc-row-actions .btn-ghost { color: var(--text-secondary); }
.bc-row-actions .btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.bc-row-actions .bc-act-mail:hover  { color: var(--primary); background: var(--primary-light); }
.bc-row-actions .bc-act-wa:hover    { color: var(--success); background: var(--success-light); }
.bc-row-actions .bc-act-nota:hover  { color: var(--warning); background: var(--warning-light); }

/* ============================================================ */
/* FILTER BAR COMPACT (chips + segmented + expandable)         */
/* Versión densa de filter-bar, usada en listados donde los    */
/* filtros secundarios se ocultan por default bajo "+ filtros". */
/* ============================================================ */
.filter-bar-compact {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-xs);
}
.fb-primary {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}
.fb-primary .fb-search {
  flex: 0 1 300px;
  min-width: 180px;
  height: 36px;
  font-size: var(--font-size-sm);
}
.fb-primary .fb-select {
  flex: 0 0 auto;
  height: 36px;
  font-size: var(--font-size-sm);
  padding: 0 32px 0 var(--space-md);
  min-width: 160px;
  width: auto;
}
.fb-segmented {
  display: inline-flex;
  background: var(--bg-muted, #f3f4f6);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}
.fb-segmented button {
  background: transparent;
  border: 0;
  padding: 6px 12px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  border-radius: calc(var(--radius-md) - 3px);
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
}
.fb-segmented button:hover { color: var(--text-primary); }
.fb-segmented button.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
  font-weight: var(--font-weight-semibold);
}
.fb-actions {
  margin-left: auto;
  display: flex;
  gap: var(--space-xs);
  align-items: center;
}
.fb-more-btn {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-xs);
  cursor: pointer;
  font-weight: var(--font-weight-medium);
  transition: all 0.12s ease;
}
.fb-more-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  border-style: solid;
}
.fb-more-btn.active {
  border-style: solid;
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.fb-secondary {
  display: none;
  gap: var(--space-md);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px dashed var(--border);
  flex-wrap: wrap;
  align-items: end;
}
.fb-secondary.show { display: flex; }
.fb-secondary .fb-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}
.fb-secondary .fb-field label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  color: var(--text-muted);
  font-weight: var(--font-weight-semibold);
}
.fb-secondary .fb-field .form-input,
.fb-secondary .fb-field .form-select {
  height: 34px;
  font-size: var(--font-size-sm);
}
/* Chips de filtros activos */
.fb-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.fb-chips:empty { display: none; }
.fb-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  border: 1px solid transparent;
  transition: all 0.12s ease;
}
.fb-chip .fb-chip-close {
  background: transparent;
  border: 0;
  color: inherit;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  opacity: 0.7;
  padding: 0;
}
.fb-chip .fb-chip-close:hover {
  background: rgba(0, 0, 0, 0.12);
  opacity: 1;
}
.fb-clear-all {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  cursor: pointer;
  padding: 4px 8px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.fb-clear-all:hover { color: var(--danger); }
.fb-summary {
  margin-top: var(--space-sm);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}
.fb-summary:empty { display: none; }
.fb-summary strong { color: var(--text-primary); font-weight: var(--font-weight-semibold); }
.fb-summary .fb-summary-total { margin-left: auto; }

@media (max-width: 800px) {
  .fb-actions { margin-left: 0; width: 100%; }
  .fb-segmented { flex-wrap: wrap; }
}

/* ============================================================ */
/* FORMS                                                        */
/* ============================================================ */
.form-group {
  margin-bottom: var(--space-md);
  display: flex;
  flex-direction: column;
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.005em;
}

.form-label .required { color: var(--danger); margin-left: 2px; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  color: var(--text-primary);
  background: var(--bg-input);
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast),
              background var(--transition-fast);
  line-height: 1.5;
  box-shadow: var(--shadow-xs);
}

.form-textarea {
  height: auto;
  padding: 12px 14px;
  min-height: 90px;
  resize: vertical;
  line-height: var(--line-height-normal);
}

.form-input:hover:not(:disabled):not(:focus),
.form-select:hover:not(:disabled):not(:focus),
.form-textarea:hover:not(:disabled):not(:focus) {
  border-color: var(--border-strong);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
  background: var(--bg-input-disabled);
  color: var(--text-disabled);
  cursor: not-allowed;
  border-color: var(--border);
}

.form-select { cursor: pointer; padding-right: 36px; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}
.form-row:last-child { margin-bottom: 0; }
.form-row .form-group { margin-bottom: 0; }

.form-help {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 6px;
  line-height: var(--line-height-snug);
}
.form-error {
  font-size: var(--font-size-xs);
  color: var(--danger);
  margin-top: 6px;
  font-weight: var(--font-weight-medium);
}
.form-input.error,
.form-select.error,
.form-textarea.error {
  border-color: var(--danger);
}
.form-input.error:focus,
.form-select.error:focus,
.form-textarea.error:focus {
  box-shadow: var(--shadow-focus-danger);
}

/* Esconder spinner up/down en inputs type=number — molesta visualmente y
   facilita errores de tipeo (clicks accidentales en las flechas) */
.form-input[type="number"]::-webkit-inner-spin-button,
.form-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.form-input[type="number"] {
  -moz-appearance: textfield;
}

/* Inputs de monto · alineación a la derecha + tabular nums + font monospace
   para que los miles queden alineados visualmente */
.money-input,
.form-input.money-input {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono, 'SF Mono', Monaco, 'Inconsolata', monospace);
}

.form-checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: var(--font-size-md);
  user-select: none;
}
.form-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-inline {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
}

/* Tabla de líneas de gasto/productiva — densa, selects compactos */
.fg-lineas-table td,
.fg-lineas-table th {
  padding: 6px 6px !important;
}
.fg-lineas-table .form-select,
.fg-lineas-table .form-input {
  padding: 4px 6px !important;
  font-size: 12px !important;
  height: 30px !important;
  min-height: 30px !important;
}
/* Selects nativos con flecha del browser (no custom): mantener padding default */
.fg-lineas-table .form-select {
  background-image: none !important;
}
.fg-lineas-table .form-input {
  padding: 4px 8px !important;
}

/* Inputs dentro de tablas: más compactos */
td .form-input,
td .form-select {
  height: 34px;
  padding: 0 10px;
  font-size: var(--font-size-sm);
  box-shadow: none;
}

/* ============================================================ */
/* BADGES                                                       */
/* ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1;
}

.badge-borrador   { background: var(--badge-borrador-bg);   color: var(--badge-borrador-text); }
.badge-confirmado { background: var(--badge-confirmado-bg); color: var(--badge-confirmado-text); }
.badge-anulado    { background: var(--badge-anulado-bg);    color: var(--badge-anulado-text); }
.badge-pendiente  { background: var(--badge-pendiente-bg);  color: var(--badge-pendiente-text); }
.badge-en-cartera, .badge-en_cartera { background: var(--badge-en-cartera-bg); color: var(--badge-en-cartera-text); }
.badge-depositado { background: var(--badge-depositado-bg); color: var(--badge-depositado-text); }
.badge-cobrado    { background: var(--badge-cobrado-bg);    color: var(--badge-cobrado-text); }
.badge-rechazado  { background: var(--badge-rechazado-bg);  color: var(--badge-rechazado-text); }
.badge-endosado   { background: var(--badge-endosado-bg);   color: var(--badge-endosado-text); }
.badge-descontado { background: var(--badge-descontado-bg); color: var(--badge-descontado-text); }
.badge-emitido    { background: var(--badge-emitido-bg);    color: var(--badge-emitido-text); }
.badge-debitado   { background: var(--badge-debitado-bg);   color: var(--badge-debitado-text); }
.badge-activo     { background: var(--badge-activo-bg);     color: var(--badge-activo-text); }
.badge-abierto    { background: var(--badge-abierto-bg);    color: var(--badge-abierto-text); }
.badge-cerrado    { background: var(--badge-cerrado-bg);    color: var(--badge-cerrado-text); }

/* ============================================================ */
/* MODAL                                                        */
/* ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 18, 32, 0.50);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity var(--transition-normal);
  padding: var(--space-lg);
}
.modal-overlay.visible { opacity: 1; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  transform: translateY(16px) scale(0.96);
  opacity: 0;
  transition: transform var(--transition-normal), opacity var(--transition-normal);
}
.modal-overlay.visible .modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-header {
  padding: var(--space-xl) var(--space-xl) var(--space-md);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
}

.modal-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-tight);
  line-height: var(--line-height-snug);
  margin: 0;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  margin: -4px -8px;
}
.modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.modal-body {
  padding: 0 var(--space-xl) var(--space-xl);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: var(--space-md) var(--space-xl);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  border-bottom-left-radius: var(--radius-xl);
  border-bottom-right-radius: var(--radius-xl);
}

.modal-wide { max-width: 880px; }
.modal-full { max-width: 96%; }

/* ============================================================ */
/* SLIDE-OVER PANEL · Components.slideOver                      */
/* ============================================================ */
/* Patrón Linear/Stripe/Pipedrive: panel lateral derecho que entra
   desde el borde con la lista detrás visible.
   Backdrop sutil que NO oculta el contenido principal — solo lo
   atenúa para indicar foco. */
.slide-over-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
}
.slide-over-overlay.visible { pointer-events: auto; }

.slide-over-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0);
  transition: background 0.25s ease-out;
}
.slide-over-overlay.visible .slide-over-backdrop {
  background: rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(2px);
}

.slide-over-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-card, #fff);
  box-shadow: -8px 0 32px rgba(15,23,42,0.10), -2px 0 8px rgba(15,23,42,0.04);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  /* width viene como inline style */
  max-width: 92vw;
}
.slide-over-overlay.visible .slide-over-panel {
  transform: translateX(0);
}

.slide-over-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.slide-over-header-text {
  flex: 1;
  min-width: 0;
}
.slide-over-title {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold, 600);
  color: var(--text-primary);
  line-height: 1.3;
}
.slide-over-subtitle {
  margin-top: 2px;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slide-over-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.slide-over-close {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.slide-over-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.slide-over-tabs {
  display: flex;
  gap: 4px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card, #fff);
  flex-shrink: 0;
}
.slide-over-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium, 500);
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}
.slide-over-tab:hover { color: var(--text-primary); }
.slide-over-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.slide-over-tab-content,
.slide-over-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
  /* scroll suave */
  scroll-behavior: smooth;
}

/* Helpers internos del slide-over para layouts de detalle consistentes.
   Usados en `verRecibo` / `verOP` y futuras vistas de detalle. */
.so-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 0 0 18px;
  padding: 14px 16px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
}
.so-meta dt {
  font-weight: var(--font-weight-medium, 500);
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}
.so-meta dd {
  margin: 0;
  color: var(--text-primary);
}
.so-section-title {
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: var(--font-weight-semibold, 600);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
/* Mini-tablas dentro del panel: más compactas que las globales */
.so-mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  margin-bottom: 8px;
}
.so-mini-table thead th {
  padding: 6px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: transparent;
  position: static;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: var(--font-weight-semibold, 600);
}
.so-mini-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
  vertical-align: top;
}
.so-mini-table tbody tr:last-child td { border-bottom: none; }

/* ============================================================ */
/* ASIENTO LÍNEAS · layout vertical estilo Xero/QuickBooks       */
/* ============================================================ */
/* Cada línea es una "card" horizontal con:
   - sidebar coloreado izquierda con DEBE/HABER
   - body con cuenta + nombre + auxiliar/CC + detalle
   - monto destacado a la derecha
   Más legible que tabla apretada con 5 columnas. */
.asiento-lineas {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 16px;
}
.asiento-linea {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: stretch;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition-fast);
}
.asiento-linea:hover {
  border-color: var(--border);
}
.asiento-linea-side {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: white;
  padding: 0 4px;
}
.asiento-linea-side.side-debe  { background: var(--info, #2563EB); }
.asiento-linea-side.side-haber { background: var(--success, #059669); }

.asiento-linea-body {
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.asiento-linea-cuenta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.asiento-linea-cuenta .cell-mono {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 13px;
}
.asiento-linea-nombre {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
}
.asiento-linea-detalle {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
}
.asiento-linea-cc {
  font-size: 11px;
  color: var(--text-muted);
}
.asiento-linea-monto {
  display: flex;
  align-items: center;
  padding: 0 16px 0 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

/* ============================================================ */
/* ASIENTO TOTALES · destacados al pie con check de cuadre       */
/* ============================================================ */
.asiento-totales {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  border-top: 2px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.asiento-totales-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.asiento-totales-label {
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
}
.asiento-totales-val {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.asiento-totales-diff {
  border-top: 1px solid var(--border-subtle);
  padding-top: 8px;
  margin-top: 2px;
}
.asiento-totales-check {
  display: inline-flex;
  align-items: center;
  font-weight: 700;
  font-size: 14px;
}
.asiento-totales-ok .asiento-totales-check {
  color: var(--success);
}
.asiento-totales-err {
  background: var(--danger-light);
  border-top-color: var(--danger);
}
.asiento-totales-err .asiento-totales-check {
  color: var(--danger);
}

/* ============================================================ */
/* ASIENTO ORIGEN tab                                             */
/* ============================================================ */
.asiento-origen .so-meta { margin-bottom: 0; }
.asiento-origen .mt-md { margin-top: 16px; }

/* ============================================================ */
/* ACTIVITY FEED · Components.activityFeed                      */
/* ============================================================ */
.activity-feed {
  display: flex;
  flex-direction: column;
  gap: 0;
  /* La línea vertical que conecta los eventos del timeline */
  position: relative;
}
.activity-feed::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 14px;
  bottom: 14px;
  width: 2px;
  background: var(--border-subtle);
  z-index: 0;
}
.activity-item {
  display: flex;
  gap: 14px;
  padding: 10px 0;
  position: relative;
  z-index: 1;
}
.activity-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* color y bg vienen como inline style según el tipo de evento */
  border: 2px solid var(--bg-card, #fff);
}
.activity-body {
  flex: 1;
  min-width: 0;
  padding-top: 4px;
}
.activity-title {
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  line-height: 1.4;
}
.activity-title strong {
  font-weight: var(--font-weight-semibold, 600);
}
.activity-meta {
  margin-top: 2px;
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}
.activity-feed-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

/* ============================================================ */
/* TABS                                                         */
/* ============================================================ */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-xl);
  gap: 2px;
}

.tab {
  padding: 12px 20px;
  cursor: pointer;
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-medium);
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--transition-fast);
  white-space: nowrap;
  background: transparent;
  border-left: none;
  border-right: none;
  border-top: none;
  border-radius: 0;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: var(--font-weight-semibold);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============================================================ */
/* WIZARD / STEPPER                                             */
/* ============================================================ */
.wizard-steps {
  display: flex;
  align-items: center;
  margin-bottom: var(--space-2xl);
  padding: 0 var(--space-md);
  gap: 0;
}

.wizard-step {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: 1;
  position: relative;
}

.wizard-step:not(:last-child)::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0 var(--space-md);
  border-radius: 1px;
  transition: background var(--transition-slow);
}
.wizard-step.completed:not(:last-child)::after { background: var(--success); }
.wizard-step.active:not(:last-child)::after {
  background: linear-gradient(90deg, var(--primary) 50%, var(--border) 50%);
}

.wizard-step-number {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  border: 2px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-card);
  flex-shrink: 0;
  transition: all var(--transition-normal);
}

.wizard-step.active .wizard-step-number {
  border-color: var(--primary);
  color: var(--text-on-primary);
  background: var(--primary);
  box-shadow: var(--shadow-focus);
  transform: scale(1.05);
}

.wizard-step.completed .wizard-step-number {
  border-color: var(--success);
  color: var(--text-on-primary);
  background: var(--success);
}

.wizard-step-label {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
}
.wizard-step.active .wizard-step-label {
  color: var(--primary);
  font-weight: var(--font-weight-semibold);
}
.wizard-step.completed .wizard-step-label { color: var(--success); }

.wizard-content { min-height: 320px; }

.wizard-footer {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border);
  gap: var(--space-md);
}

/* Resumen en paso final del wizard */
.wizard-summary {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  border: 1px solid var(--border);
}
.wizard-summary-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  font-size: var(--font-size-md);
}
.wizard-summary-row:last-child { border-bottom: none; }
.wizard-summary-row.total {
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-lg);
  color: var(--text-primary);
  padding-top: var(--space-md);
  margin-top: var(--space-sm);
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.wizard-item {
  padding: var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  transition: border-color var(--transition-fast);
}
.wizard-item:hover { border-color: var(--border-strong); }

/* ============================================================ */
/* TOAST                                                        */
/* ============================================================ */
.toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-medium);
  border-left: 4px solid var(--primary);
  min-width: 320px;
  max-width: 440px;
  animation: toastIn 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast strong {
  font-size: var(--font-size-lg);
  line-height: 1;
}
.toast-success {
  border-left-color: var(--success);
}
.toast-success strong { color: var(--success); }
.toast-error {
  border-left-color: var(--danger);
}
.toast-error strong { color: var(--danger); }
.toast-warning {
  border-left-color: var(--warning);
}
.toast-warning strong { color: var(--warning); }
.toast-info {
  border-left-color: var(--info);
}
.toast-info strong { color: var(--info); }

@keyframes toastIn {
  from { transform: translateX(110%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================================ */
/* CALLOUTS (alerts inline)                                     */
/* ============================================================ */
.callout {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  border-left: 4px solid;
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}
.callout-info {
  background: var(--info-light);
  border-color: var(--info);
  color: #1E3A8A;
}
.callout-success {
  background: var(--success-light);
  border-color: var(--success);
  color: #065F46;
}
.callout-warning {
  background: var(--warning-light);
  border-color: var(--warning);
  color: #92400E;
}
.callout-danger {
  background: var(--danger-light);
  border-color: var(--danger);
  color: #991B1B;
}

/* ============================================================ */
/* TREE VIEW (plan de cuentas)                                  */
/* ============================================================ */
.tree-view { font-size: var(--font-size-md); }

.tree-node-content {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 6px var(--space-sm);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}
.tree-node-content:hover { background: var(--bg-hover); }

.tree-toggle {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}
.tree-toggle.expanded { transform: rotate(90deg); }
.tree-toggle.leaf { visibility: hidden; }

.tree-node-code {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  min-width: 68px;
}

.tree-node-name { color: var(--text-primary); }
.tree-node-name.imputable { font-weight: var(--font-weight-medium); }
.tree-node-saldo {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: var(--font-size-sm);
}

.tree-children {
  padding-left: 20px;
  overflow: hidden;
  max-height: 0;
  transition: max-height var(--transition-normal);
}
.tree-children.open { max-height: 99999px; }

/* ============================================================ */
/* SEARCH SELECT                                                */
/* ============================================================ */
.search-select {
  position: relative;
}

.search-select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  display: none;
  padding: 4px;
}
.search-select-dropdown.open { display: block; }

.search-select-option,
.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: var(--font-size-md);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}
.search-select-option:hover,
.autocomplete-item:hover {
  background: var(--bg-hover);
}
.search-select-option .option-subtitle,
.autocomplete-item .option-subtitle {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================ */
/* LAYOUT UTILS                                                 */
/* ============================================================ */
.grid { display: grid; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-md); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-md); }

.flex-between { display: flex; justify-content: space-between; align-items: center; gap: var(--space-md); }
.flex-center { display: flex; align-items: center; gap: var(--space-sm); }
.flex-end { display: flex; justify-content: flex-end; gap: var(--space-sm); align-items: center; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-left { text-align: left; }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info { color: var(--info); }
.text-sm { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }

.font-bold { font-weight: var(--font-weight-bold); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-medium { font-weight: var(--font-weight-medium); }

.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }

/* `.amount` es legacy — alias del nuevo `.cell-money` para que los ~79 usos
   existentes hereden el upgrade visual sin migración. Cuando se toque cada
   archivo, preferir `class="cell-money"` (más explícito sobre el contexto).
   El alineamiento right viene del `align: 'right'` del column del dataGrid
   (que pone text-align: right en el <td>); el span hereda. */
.amount {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
  font-weight: var(--font-weight-medium, 500);
}
.amount-positive { color: var(--success); }
.amount-negative { color: var(--danger); }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-xl) 0;
}

/* ============================================================ */
/* EMPTY STATE                                                  */
/* ============================================================ */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
}
.empty-state-icon {
  font-size: 3rem;
  opacity: 0.4;
  line-height: 1;
}
.empty-state-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  margin: 0;
}
.empty-state-text {
  font-size: var(--font-size-md);
  color: var(--text-muted);
  max-width: 360px;
}

/* Empty state ILUSTRADO · Components.emptyState({ illustration, title, ... }) */
.empty-state-illustration {
  width: 160px;
  height: 160px;
  margin-bottom: var(--space-md);
  /* La ilustración usa currentColor → hereda este color */
  color: var(--primary);
  opacity: 0.85;
}
.empty-state-illustration.muted { color: var(--text-muted); opacity: 0.5; }
.empty-state-illustration.success { color: var(--success); }
.empty-state-illustration.warning { color: var(--warning); }
.empty-state-illustration svg {
  width: 100%;
  height: 100%;
  display: block;
}

.empty-state-actions {
  margin-top: var(--space-sm);
  display: inline-flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  justify-content: center;
}
.empty-state-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin-top: -4px;
}

/* ============================================================ */
/* CLIENT INFO BANNER (banner de cliente/proveedor en wizards)  */
/* ============================================================ */
.client-info-banner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--space-lg) var(--space-xl);
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--bg-subtle) 100%);
  border: 1px solid var(--primary-subtle);
  border-radius: var(--radius-lg);
  gap: var(--space-lg);
}
.client-info-name {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: 4px;
}
.client-info-detail {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}
.client-info-balance {
  text-align: right;
  flex-shrink: 0;
}
.client-info-balance-label {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  font-weight: var(--font-weight-semibold);
  margin-bottom: 4px;
}
.client-info-balance-value {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--letter-spacing-tight);
}

.rb-summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
}
.rb-summary-label {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-xs);
}
.rb-summary-value {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* ============================================================ */
/* ADJUNTOS (Bloque E)                                          */
/* ============================================================ */
.adjuntos-box {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  background: var(--bg-subtle);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.adjuntos-box:hover { border-color: var(--primary); background: var(--primary-subtle); }

.adj-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}
.adj-header strong {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
}

.adj-empty {
  padding: var(--space-md) 0;
  text-align: center;
  font-style: italic;
  color: var(--text-muted);
}

.adj-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-bottom: var(--space-sm);
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-xs);
}
.adj-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.adj-item:last-child { margin-bottom: 0; }

.adj-icon {
  font-size: 32px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
}
.adj-info {
  flex: 1;
  min-width: 0;
}
.adj-name {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}
.adj-meta {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.adj-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.adj-upload-zone {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
  margin-top: var(--space-md);
}

/* ============================================================ */
/* CODE inline                                                  */
/* ============================================================ */
code {
  font-family: var(--font-mono);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 1px 6px;
  font-size: 0.92em;
  color: var(--text-primary);
}

/* ============================================================ */
/* ACCESSIBILITY — focus visible uniforme                       */
/* ============================================================ */
.btn:focus-visible,
.form-input:focus-visible,
.form-select:focus-visible,
.form-textarea:focus-visible,
.tab:focus-visible,
.pagination-btn:focus-visible,
.tree-node-content:focus-visible,
.search-select-option:focus-visible,
.adj-item:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* ============================================================ */
/* BANDEJA DE PAGOS (Bloque J)                                  */
/* ============================================================ */

/* Barra de aging — 5 segmentos horizontales */
.aging-bar {
  display: flex;
  width: 100%;
  height: 56px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.aging-seg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  min-width: 0;
  flex-shrink: 1;
  transition: filter var(--transition-fast);
  overflow: hidden;
}
.aging-seg:hover { filter: brightness(1.05); }
.aging-seg-label {
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  opacity: 0.85;
  font-size: 10px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aging-seg-value {
  font-variant-numeric: tabular-nums;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aging-seg-pct {
  opacity: 0.7;
  font-size: 10px;
}
.aging-seg-current  { background: var(--success-light); color: var(--success); }
.aging-seg-0-30     { background: var(--warning-light); color: var(--warning); }
.aging-seg-31-60    { background: #FEE4E2; color: #B42318; }
.aging-seg-61-90    { background: #FECDCA; color: #912018; }
.aging-seg-90plus   { background: #FDA29B; color: #7A0C0C; }
.aging-seg-empty    {
  background: transparent;
  color: var(--text-muted);
  border-right: 1px dashed var(--border);
  min-width: 60px;
}
.aging-seg-empty:last-child { border-right: none; }

.aging-bar-legend {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-sm);
  margin-top: var(--space-sm);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-align: center;
}
.aging-bar-legend .legend-label {
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  font-weight: var(--font-weight-semibold);
}

/* Footer sticky del batch de selección */
.selection-footer {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 2px solid var(--primary);
  box-shadow: 0 -4px 12px rgba(15, 23, 42, 0.08);
  padding: var(--space-md) var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  z-index: 20;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin-top: var(--space-lg);
  animation: footerSlideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.selection-footer-info {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}
.selection-count {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}
.selection-count strong {
  color: var(--primary);
  font-size: var(--font-size-lg);
}
.selection-total {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  padding-left: var(--space-lg);
  border-left: 1px solid var(--border);
}
@keyframes footerSlideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Badges de días (aging individual por fila) */
.badge-dias {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.badge-dias-al-dia   { background: var(--success-light); color: var(--success); }
.badge-dias-proximo  { background: var(--warning-light); color: var(--warning); }
.badge-dias-hoy      { background: #FEF3C7; color: #B45309; }
.badge-dias-vencido  { background: #FEE4E2; color: #B42318; }
.badge-dias-critico  { background: #FDA29B; color: #7A0C0C; font-weight: var(--font-weight-bold); }
/* Bloque M: pendiente de presentación (en Riga Farma) */
.badge-dias-pre-presentacion { background: #ede9fe; color: #6d28d9; font-weight: var(--font-weight-semibold); }

/* Fila con check seleccionado */
tbody tr.bp-selected {
  background: var(--primary-subtle);
}
tbody tr.bp-selected:hover {
  background: var(--primary-light);
}

/* Bloque M: fila pendiente de presentación — fondo tenue púrpura */
tbody tr.bc-fila-pendiente-pres {
  background: #fbfaff;
}
tbody tr.bc-fila-pendiente-pres:hover {
  background: #f5f3ff;
}
tbody tr.bc-fila-pendiente-pres td {
  opacity: 0.85;
}

/* ============================================================ */
/* AI UPLOAD INLINE (Bloque L) — embedded en cada form          */
/* ============================================================ */
.ai-upload-box {
  background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
  border: 1px dashed #c4b5fd;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  transition: all var(--transition-base);
}
.ai-upload-box:hover {
  border-color: #8b5cf6;
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.08);
}

.ai-upload-header {
  margin-bottom: var(--space-md);
}
.ai-upload-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: #5b21b6;
  margin-bottom: 4px;
}
.ai-upload-subtitle {
  font-size: var(--font-size-sm);
  color: #6d28d9;
  opacity: 0.85;
}

.ai-upload-body {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}
.ai-upload-btn {
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  border: none;
  color: white;
  font-weight: var(--font-weight-semibold);
}
.ai-upload-btn:hover {
  background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
  transform: translateY(-1px);
}
.ai-upload-hint {
  font-size: var(--font-size-xs);
  color: #6d28d9;
  opacity: 0.75;
  flex: 1;
  min-width: 200px;
}

.ai-upload-status {
  margin-top: var(--space-md);
}
.ai-upload-status:empty {
  display: none;
}

.ai-upload-processing {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  background: white;
  padding: var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid #ddd6fe;
}

.spinner-inline {
  width: 22px;
  height: 22px;
  border: 2.5px solid #e9d5ff;
  border-top-color: #8b5cf6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.ai-upload-result {
  background: white !important;
  margin: 0;
}

/* Variante compacta para usarse dentro del wizard de medio de pago */
.ai-upload-box.ai-upload-compact {
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}
.ai-upload-box.ai-upload-compact .ai-upload-title {
  font-size: var(--font-size-sm);
}
.ai-upload-box.ai-upload-compact .ai-upload-subtitle {
  font-size: var(--font-size-xs);
}

/* ============================================================ */
/* RESPONSIVE                                                   */
/* ============================================================ */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .wizard-step-label { display: none; }
  .card-body { padding: var(--space-lg); }
  .modal { max-width: 100%; border-radius: var(--radius-md); }
  .modal-header, .modal-body, .modal-footer { padding-left: var(--space-lg); padding-right: var(--space-lg); }
  .dash-metrics { grid-template-columns: 1fr 1fr; }
  .dash-grid-2col { grid-template-columns: 1fr; }
  .dash-hero-row { grid-template-columns: 1fr; }
  .dash-hero { text-align: center; padding: var(--space-lg); }
  .dash-hero-side { border-left: none; border-top: 1px solid rgba(255,255,255,0.1); padding-left: 0; padding-top: var(--space-md); text-align: center; }
  .dash-hero-value { font-size: 1.75rem; }
  .dash-quick-actions { grid-template-columns: repeat(2, 1fr); }
}
