/* ════════════════════════════════════════════════════════════════════
   PEUNEX — Listados de documentos: Ventas (historial), Presupuestos
   y Compras.
   Aditivo a panel-pages.css y panel-lists.css: reutiliza .page-head,
   .kpi-row/.kpi-tile, .btn-act, .status-pill, .list-table, .list-row,
   .row-actions/.row-action y la versión en tarjetas para celular.
   Colores: exclusivamente los tokens existentes (--primary,
   --primary-light, --surface, --surface-hover, --border, --text,
   --text-muted, --success, --danger, --warning); las mezclas usan
   color-mix(in srgb, … N%, transparent) o con --surface/--border.
   Responsive: 360, 768, 1024 y 1440 px. Sin scroll horizontal ≥1024 px.
   ════════════════════════════════════════════════════════════════════ */

/* ── Pestañas y KPIs ──────────────────────────────────────────────── */
.list-tabs {
  margin-bottom: 1rem;
}

.list-kpis--docs {
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
}

.kpi-row--methods {
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
}

.kpi-tile__value--sm {
  font-size: 1.05rem;
}

/* ── Filtros ──────────────────────────────────────────────────────── */
.list-filters-card__body {
  padding: .85rem 1rem 1rem;
}

/* Variante con cabecera propia: la tarjeta no agrega padding externo. */
.list-filters-card--head {
  padding: 0;
}

/* El wrapper sticky ya aporta el espacio inferior. */
.uix-sticky-filters .list-filters-card {
  margin-bottom: 0;
}

.list-filters--docs {
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
}

.list-filters--docs .list-filters__field--search {
  grid-column: span 2;
}

.list-filters--docs .list-filters__actions {
  grid-column: 1 / -1;
  justify-content: flex-end;
}

.list-filters__hint {
  margin-top: .2rem;
  color: var(--text-muted);
  font-size: .68rem;
  line-height: 1.35;
}

/* ── Buscador instantáneo del historial ───────────────────────────── */
.list-quick-filter {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-width: 0;
  margin-bottom: 1rem;
  padding: .55rem .9rem;
  background: color-mix(in srgb, var(--primary) 4%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--border));
  border-radius: .9rem;
}

.list-quick-filter > .bi {
  flex: 0 0 auto;
  color: var(--primary);
  font-size: 1.05rem;
  line-height: 1;
}

.list-quick-filter .form-input {
  flex: 1 1 auto;
  min-width: 0;
  height: auto;
  padding: .15rem 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.list-quick-filter .form-input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: .35rem;
}

.list-quick-filter__count {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── Avisos del historial (pendientes, facturación en lote) ───────── */
.list-callout {
  margin-bottom: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .9rem;
}

.list-callout__body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  padding: .7rem 1rem;
  font-size: .85rem;
  color: var(--text);
}

.list-callout__icon {
  flex: 0 0 auto;
  color: var(--primary);
  font-size: 1.1rem;
  line-height: 1;
}

.list-callout--warn {
  background: color-mix(in srgb, var(--warning) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--warning) 32%, var(--border));
}

.list-callout--warn .list-callout__icon {
  color: var(--warning);
}

.list-callout--info {
  background: color-mix(in srgb, var(--primary) 7%, var(--surface));
  border-color: color-mix(in srgb, var(--primary) 26%, var(--border));
}

/* ── Celdas del documento ─────────────────────────────────────────── */
/* Un poco más compactas que clientes/proveedores: estos listados tienen
   más columnas y deben entrar sin scroll a partir de 1024 px. */
.list-table--docs {
  font-size: .76rem;
}

.list-table--docs thead th {
  padding-right: .4rem;
  padding-left: .4rem;
  font-size: .62rem;
  letter-spacing: .02em;
}

.list-table--docs tbody td {
  padding: .4rem;
}

.list-table--docs .status-pill {
  font-size: .66rem;
}

.list-table--docs .list-chip {
  font-size: .64rem;
}

/* Fecha y hora en dos líneas: conserva el dato completo en una columna
   angosta y evita cortar el año. */
.list-date {
  display: flex;
  flex-direction: column;
  gap: .05rem;
  line-height: 1.2;
  white-space: nowrap;
}

.list-date__time {
  color: var(--text-muted);
  font-size: .68rem;
}

.list-id {
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

.list-link {
  color: var(--primary);
  text-decoration: none;
}

.list-link:hover {
  text-decoration: underline;
}

.list-link:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: .2rem;
}

.list-chip {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  box-sizing: border-box;
  max-width: 100%;
  padding: .1rem .5rem;
  overflow: hidden;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: .66rem;
  font-weight: 650;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-cell--muted {
  color: var(--text-muted);
}

.list-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
}

/* ── Paginación propia de Compras ─────────────────────────────────── */
.list-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .8125rem;
}

.list-pager__text {
  font-variant-numeric: tabular-nums;
}

.list-pager__actions {
  display: flex;
  align-items: center;
  gap: .4rem;
}

.list-table .list-cell--amount,
.list-table .list-cell--total {
  text-align: right;
}

.list-amount--money {
  color: var(--success);
}

.list-table--docs .list-cell--amount .list-amount,
.list-table--docs .list-cell--total .list-amount {
  font-size: .8rem;
}

.list-table--docs .list-cell--date .list-ellipsis,
.list-table--docs .list-cell--id .list-ellipsis {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* La columna fiscal muestra píldoras y, si corresponde, un checkbox. */
.list-fiscal-check {
  cursor: pointer;
}

.list-fiscal-check input[type="checkbox"] {
  flex: 0 0 auto;
  margin: 0;
}

.list-table .list-check {
  width: 1rem;
  height: 1rem;
  margin: 0;
  vertical-align: middle;
  accent-color: var(--primary);
}

/* ── Acciones: iconos neutros, color sólo al interactuar ──────────── */
.row-action--ship:hover,
.row-action--ship:focus-visible {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
  color: var(--primary);
}

.row-action--print:hover,
.row-action--print:focus-visible {
  border-color: color-mix(in srgb, var(--warning) 45%, var(--border));
  background: color-mix(in srgb, var(--warning) 10%, var(--surface));
  color: var(--warning);
}

/* Un poco más compactas que en clientes/proveedores para que entren
   todas las acciones en una sola fila también a 1024 px. */
@media (min-width: 700px) {
  .list-table--docs .row-action {
    width: 2rem;
    height: 2rem;
    font-size: .9rem;
  }
}

/* ── Ancho de columnas en escritorio ──────────────────────────────── */
/* Ventas de hoy */
.list-table--ventas-hoy .list-col--id { width: 7%; }
.list-table--ventas-hoy .list-col--date { width: 9%; }
.list-table--ventas-hoy .list-col--customer { width: 27%; }
.list-table--ventas-hoy .list-col--type { width: 11%; }
.list-table--ventas-hoy .list-col--method { width: 13%; }
.list-table--ventas-hoy .list-col--amount { width: 15%; }
.list-table--ventas-hoy .list-col--actions { width: 18%; }

/* Ventas — historial */
.list-table--ventas .list-col--id { width: 5%; }
.list-table--ventas .list-col--date { width: 10.5%; }
.list-table--ventas .list-col--branch { width: 7%; }
.list-table--ventas .list-col--customer { width: 14%; }
.list-table--ventas .list-col--type { width: 8.2%; }
.list-table--ventas .list-col--status { width: 9%; }
.list-table--ventas .list-col--method { width: 7.5%; }
.list-table--ventas .list-col--amount { width: 9.5%; }
.list-table--ventas .list-col--fiscal { width: 12.3%; }
.list-table--ventas .list-col--actions { width: 17%; }

/* Presupuestos */
.list-table--presupuestos .list-col--id { width: 6%; }
.list-table--presupuestos .list-col--customer { width: 34%; }
.list-table--presupuestos .list-col--date { width: 16%; }
.list-table--presupuestos .list-col--status { width: 14%; }
.list-table--presupuestos .list-col--amount { width: 17%; }
.list-table--presupuestos .list-col--actions { width: 13%; }

/* Compras */
.list-table--compras .list-col--id { width: 6%; }
.list-table--compras .list-col--date { width: 12%; }
.list-table--compras .list-col--supplier { width: 25%; }
.list-table--compras .list-col--doc { width: 13%; }
.list-table--compras .list-col--status { width: 13%; }
.list-table--compras .list-col--amount { width: 14%; }
.list-table--compras .list-col--actions { width: 17%; }

/* ── Tablet / escritorio angosto ──────────────────────────────────── */
@media (min-width: 700px) and (max-width: 1023.98px) {
  /* Entre 700 y 1023 px la tabla conserva columnas legibles y permite
     desplazamiento horizontal dentro de la tarjeta. */
  .list-table-wrap .list-table--docs {
    min-width: 1000px;
  }
}

@media (min-width: 1024px) {
  /* La tabla se ajusta al ancho disponible: nada de scroll horizontal. */
  .list-table-wrap {
    overflow-x: visible;
  }

  .list-table--docs {
    min-width: 0;
  }
}

/* ── Celular: cada fila se convierte en tarjeta apilada ───────────── */
@media (max-width: 699.98px) {
  .list-filters--docs .list-filters__field--search {
    grid-column: 1 / -1;
  }

  .list-filters--docs .list-filters__actions {
    justify-content: stretch;
  }

  .list-table tbody tr.list-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .list-table tbody td[data-label] .list-ellipsis,
  .list-table tbody td[data-label] .list-amount {
    font-size: .78rem;
  }

  .list-table tbody td[data-label] .list-ellipsis {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
  }

  .list-table--docs .list-cell--actions {
    margin-top: .15rem;
    padding-top: .55rem;
    border-top: 1px solid var(--border);
  }

  .list-table--docs .list-cell--actions .row-actions {
    justify-content: flex-end;
  }

  /* Ventas — historial */
  .list-table--ventas .list-cell--id { grid-area: 1 / 1; }
  .list-table--ventas .list-cell--status {
    grid-area: 1 / 2;
    align-self: center;
    justify-self: end;
  }
  .list-table--ventas .list-cell--customer { grid-area: 2 / 1 / 3 / -1; }
  .list-table--ventas .list-cell--date { grid-area: 3 / 1; }
  .list-table--ventas .list-cell--branch { grid-area: 3 / 2; }
  .list-table--ventas .list-cell--type { grid-area: 4 / 1; }
  .list-table--ventas .list-cell--method { grid-area: 4 / 2; }
  .list-table--ventas .list-cell--amount { grid-area: 5 / 1 / 6 / -1; }
  .list-table--ventas .list-cell--fiscal { grid-area: 6 / 1 / 7 / -1; }
  .list-table--ventas .list-cell--actions { grid-area: 7 / 1 / 8 / -1; }

  /* Ventas de hoy */
  .list-table--ventas-hoy .list-cell--id { grid-area: 1 / 1; }
  .list-table--ventas-hoy .list-cell--date {
    grid-area: 1 / 2;
    justify-self: end;
  }
  .list-table--ventas-hoy .list-cell--customer { grid-area: 2 / 1 / 3 / -1; }
  .list-table--ventas-hoy .list-cell--type { grid-area: 3 / 1; }
  .list-table--ventas-hoy .list-cell--method { grid-area: 3 / 2; }
  .list-table--ventas-hoy .list-cell--amount { grid-area: 4 / 1 / 5 / -1; }
  .list-table--ventas-hoy .list-cell--actions { grid-area: 5 / 1 / 6 / -1; }

  /* Presupuestos */
  .list-table--presupuestos .list-cell--id { grid-area: 1 / 1; }
  .list-table--presupuestos .list-cell--status {
    grid-area: 1 / 2;
    align-self: center;
    justify-self: end;
  }
  .list-table--presupuestos .list-cell--customer { grid-area: 2 / 1 / 3 / -1; }
  .list-table--presupuestos .list-cell--date { grid-area: 3 / 1; }
  .list-table--presupuestos .list-cell--amount {
    grid-area: 3 / 2;
    justify-content: flex-end;
  }
  .list-table--presupuestos .list-cell--actions { grid-area: 4 / 1 / 5 / -1; }

  /* Compras */
  .list-table--compras .list-cell--id { grid-area: 1 / 1; }
  .list-table--compras .list-cell--status {
    grid-area: 1 / 2;
    align-self: center;
    justify-self: end;
  }
  .list-table--compras .list-cell--supplier { grid-area: 2 / 1 / 3 / -1; }
  .list-table--compras .list-cell--date { grid-area: 3 / 1; }
  .list-table--compras .list-cell--doc { grid-area: 3 / 2; }
  .list-table--compras .list-cell--amount { grid-area: 4 / 1 / 5 / -1; }
  .list-table--compras .list-cell--actions { grid-area: 5 / 1 / 6 / -1; }
}

/* En pantallas muy angostas (360 px) la etiqueta va sobre el valor
   para que el dato conserve ancho útil. */
@media (max-width: 399.98px) {
  .list-table tbody td[data-label] {
    display: block;
  }

  .list-table tbody td[data-label]::before {
    display: block;
    margin-bottom: .05rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .list-link,
  .list-chip {
    transition: none;
  }
}
