/**
 * assets/css/componentes/wolk-filter-panel.css
 *
 * ★ COMPONENTE: FILTER PANEL (FIX-DOC-HIST v3.13 — Julio 2026)
 *
 * Reemplaza toolbars con múltiples inputs por: buscador + botón que
 * abre un popover con TODOS los filtros. Los filtros aplicados se
 * comunican como chips debajo del toolbar. Estados FE en multi-select.
 *
 * Anatomía:
 *   .filter-toolbar             — reemplaza .table-toolbar en la vista
 *     .filter-toolbar-search    — buscador (siempre visible)
 *     .filter-toolbar-btn       — botón "⚙ Filtros" con badge de conteo
 *     .filter-toolbar-clear     — botón ✕ para limpiar todo
 *   .filter-popover-wrap        — container relativo del botón
 *     .filter-popover           — panel flotante con los inputs
 *   .filter-chips-band          — banda debajo del toolbar
 *     .filter-chip              — chip individual con ✕
 *
 * Cuándo usar:
 *   - Vistas con 3+ filtros donde el toolbar horizontal se satura
 *   - Filtros que combinan tipos (fecha + select + multi-checkbox)
 *
 * Cuándo NO usar:
 *   - Vistas con 1-2 filtros simples (usar toolbar horizontal)
 *   - Filtros que se aplican en tiempo real sin apply (ej. búsqueda sola)
 *
 * Heurísticas Nielsen cubiertas:
 *   H1 — chips + badge de conteo hacen visible qué filtros aplican
 *   H3 — cada chip tiene ✕ (deshacer puntual), botón clear (deshacer todo)
 *   H4 — mismo patrón en Facturas / Tiquetes / NC / ND
 *   H6 — los filtros aplicados quedan a la vista (reconocer > recordar)
 */

/* ══════════════════════════════════════════════
   TOOLBAR
   ══════════════════════════════════════════════ */
.filter-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  /* FIX-DOC-HIST v3.13.2: mismo respiro que el estándar .table-toolbar
     del Design System (ds/11-tables.css) — padding 16px/20px y
     border-bottom sutil que delimita dónde termina el toolbar y
     empieza el contenido de la card. Cero Reaprendizaje: el cajero ve
     exactamente la misma anatomía de card que en el resto del sistema. */
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

/* Buscador — siempre visible, acotado en desktop */
.filter-toolbar-search {
  position: relative;
  flex: 1 1 auto;
  min-width: 160px;
  max-width: 340px;
}
.filter-toolbar-search input {
  width: 100%;
  height: 36px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  padding: 0 var(--space-3) 0 32px;
  transition: border-color var(--ease-fast), box-shadow var(--ease-fast);
}
.filter-toolbar-search input:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(0, 200, 212, 0.12);
}
.filter-toolbar-search input::placeholder {
  color: var(--text-muted);
}
.filter-toolbar-search .filter-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: var(--text-sm);
  pointer-events: none;
  line-height: 1;
}

/* Botón "Filtros" con badge de conteo */
.filter-toolbar-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-3);
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--ease-fast);
  flex-shrink: 0;
  white-space: nowrap;
}
.filter-toolbar-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}
.filter-toolbar-btn[aria-expanded="true"] {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  background: rgba(0, 200, 212, 0.08);
}
.filter-toolbar-btn-badge {
  background: var(--brand-primary);
  color: #04222a;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  line-height: 1.4;
}
.filter-toolbar-btn-badge.hidden { display: none; }

/* Botón limpiar (✕) — cuadrado, discreto */
.filter-toolbar-clear {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  height: 36px;
  width: 36px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--ease-fast);
  flex-shrink: 0;
}
.filter-toolbar-clear:hover:not(:disabled) {
  color: var(--brand-danger);
  border-color: var(--brand-danger);
}
.filter-toolbar-clear:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ══════════════════════════════════════════════
   POPOVER
   ══════════════════════════════════════════════ */
.filter-popover-wrap {
  position: relative;
  flex-shrink: 0;
}
/* FIX-DOC-HIST v3.13.1: el popover se reposiciona a position:FIXED desde
   el JS (coords reales del botón) para escapar del clipping por overflow
   de .table-container — mismo patrón que el fix del dropdown ⋮ (R-103).
   Las coords top/left/width/max-height las setea _abrir() inline. */
.filter-popover {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(0,0,0,.35));
  width: min(440px, calc(100vw - 32px));
  padding: var(--space-4);
  z-index: 100;
  display: none;
  flex-direction: column;
  /* FIX-DOC-HIST v3.13.4: gap reducido (era space-4) — con los chips
     compactos el popover ya cabe sin scroll; este ajuste da margen extra. */
  gap: var(--space-3);
}
.filter-popover.open {
  display: flex;
  animation: filter-pop-in 180ms ease-out;
}
/* Cuando el viewport es corto y el contenido no cabe, el JS agrega
   .scrollable: scroll interno y flecha oculta (el overflow la recortaría). */
.filter-popover.scrollable {
  overflow-y: auto;
  overscroll-behavior: contain;
}
.filter-popover.scrollable::before { display: none; }
@keyframes filter-pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0);   }
}
.filter-popover::before {
  content: '';
  position: absolute;
  top: -6px;
  /* --fp-arrow-right la calcula el JS para que la flecha apunte al centro
     del botón "Filtros" aunque el popover esté re-anclado con fixed. */
  right: var(--fp-arrow-right, 16px);
  width: 12px;
  height: 12px;
  background: var(--bg-card);
  border-left: 1px solid var(--border-default);
  border-top: 1px solid var(--border-default);
  transform: rotate(45deg);
}

.filter-popover-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.filter-popover-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

/* Rango de fechas */
.filter-date-range {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.filter-date-range input[type="date"] {
  flex: 1 1 0;
  min-width: 0;
  height: 36px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  padding: 0 var(--space-2);
}
.filter-date-range input[type="date"]:focus {
  outline: none;
  border-color: var(--input-focus);
}
.filter-date-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Select de condición */
.filter-popover-section select {
  height: 36px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  padding: 0 var(--space-2);
  cursor: pointer;
}
.filter-popover-section select:focus {
  outline: none;
  border-color: var(--input-focus);
}

/* Multi-toggle de estados FE — chips COMPACTOS en línea.
   FIX-DOC-HIST v3.13.4: antes eran pills grandes en grid 2-col (5 filas
   → forzaban scroll en pantallas de altura media). Ahora son chips que
   fluyen con flex-wrap (~2 filas), el checkbox nativo se oculta y el
   propio chip es el toggle visual (estado :checked → resaltado brand).
   El grid y la clase .wide de "No enviadas" quedan obsoletos. */
.filter-check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.filter-check-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 5px var(--space-3);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: all var(--ease-fast);
}
.filter-check-pill:hover {
  border-color: var(--border-strong);
}
/* El checkbox nativo se oculta accesiblemente — el chip ES el control.
   Sigue en el DOM para _leerPopover()/_hidratarPopover() y para foco/teclado. */
.filter-check-pill input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}
.filter-check-pill:has(input:checked) {
  border-color: var(--brand-primary);
  background: rgba(0, 200, 212, 0.12);
  color: var(--brand-primary);
  font-weight: 600;
}
/* Marca ✓ que aparece solo cuando el chip está activo */
.filter-check-pill::before {
  content: '';
  width: 0;
  opacity: 0;
  transition: width var(--ease-fast), opacity var(--ease-fast);
}
.filter-check-pill:has(input:checked)::before {
  content: '✓';
  width: auto;
  opacity: 1;
  color: var(--brand-primary);
  font-weight: 800;
  font-size: var(--text-xs);
}
/* Foco por teclado en el checkbox oculto → anillo en el chip */
.filter-check-pill:has(input:focus-visible) {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 200, 212, 0.25);
}
.filter-check-pill .filter-check-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
/* FIX-DOC-HIST v3.13.5: estilos de .filter-check-count ELIMINADOS —
   los contadores por estado se quitaron del UI. */

/* Footer del popover — Restablecer + hint (FIX-DOC-HIST v3.13.3:
   botón "Aplicar filtros" eliminado, los cambios aplican en vivo). */
.filter-popover-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-subtle);
}
.filter-btn-link {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  cursor: pointer;
  padding: var(--space-2) 0;
  transition: color var(--ease-fast);
}
.filter-btn-link:hover {
  color: var(--brand-danger);
  text-decoration: underline;
}
/* Hint informativo: recuerda que no hay que "confirmar" nada. Discreto
   (H8: diseño minimalista) pero presente para el primer uso. */
.filter-popover-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
}

/* ══════════════════════════════════════════════
   CHIPS DE FILTROS ACTIVOS
   ══════════════════════════════════════════════
   FIX-DOC-HIST v3.13.1: los chips viven INLINE en la misma fila del
   toolbar (después del botón ✕) — antes ocupaban una fila propia que
   dejaba una banda muerta a la derecha del botón Filtros. Con flex:1
   aprovechan el espacio sobrante; si no caben, el flex-wrap del
   toolbar los baja a una segunda fila automáticamente. */
.filter-chips-band {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  flex: 1 1 auto;
  min-width: 0;
}
.filter-chips-band:empty { display: none; }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: rgba(0, 200, 212, 0.12);
  border: 1px solid var(--border-default);
  color: var(--brand-primary);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px var(--space-2) 3px var(--space-3);
  border-radius: var(--radius-full);
  max-width: 280px;
}
.filter-chip .filter-chip-label {
  color: var(--text-muted);
  margin-right: 2px;
}
.filter-chip .filter-chip-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.filter-chip .filter-chip-x {
  background: transparent;
  border: none;
  color: currentColor;
  cursor: pointer;
  padding: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  transition: background var(--ease-fast);
  flex-shrink: 0;
}
.filter-chip .filter-chip-x:hover {
  background: rgba(224, 59, 59, 0.2);
  color: var(--brand-danger);
}

/* ══════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════ */
@media (max-width: 720px) {
  .filter-toolbar-search {
    min-width: 100%;
    max-width: none;
    order: -1;
  }
  /* Chips a fila completa bajo los controles — en pantallas angostas
     compartir fila con el botón los aplastaba. */
  .filter-chips-band {
    flex-basis: 100%;
    order: 10;
  }
}
@media (prefers-reduced-motion: reduce) {
  .filter-popover.open { animation: none; }
}
