/* ============================================================
   HIMA — Componentes adicionales
   ============================================================ */

/* ── Tabla de cotización / venta (formulario dinámico) ─────── */
.items-table-wrap { overflow-x: auto; margin-bottom: 16px; }

.items-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.items-table th { background: var(--color-navy); color: white; padding: 9px 10px; text-align: left; white-space: nowrap; }
.items-table td { padding: 8px 10px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.items-table tr:hover td { background: #fafafa; }
.items-table .qty-input   { width: 70px; text-align: center; }
.items-table .price-input { width: 100px; }

.items-totals {
  background: var(--color-navy-lt);
  border-radius: var(--border-radius);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.total-row { display: flex; gap: 12px; font-size: 0.9rem; }
.total-row .label { color: var(--color-text-muted); min-width: 130px; text-align: right; }
.total-row .value { font-weight: 600; min-width: 100px; text-align: right; }
.total-row.grand-total .label,
.total-row.grand-total .value { font-size: 1.1rem; color: var(--color-navy); font-weight: 700; }

/* ── Producto card (búsqueda / QR scan result) ─────────────── */
.producto-card-preview {
  display: flex;
  gap: 14px;
  background: white;
  border: 2px solid var(--color-primary);
  border-radius: var(--border-radius-lg);
  padding: 14px;
  margin-bottom: 12px;
}
.producto-card-img {
  width: 72px; height: 72px;
  border-radius: var(--border-radius);
  object-fit: cover;
  border: 1px solid #eee;
  flex-shrink: 0;
  background: #f5f5f5;
}
.producto-card-info { flex: 1; }
.producto-card-nombre { font-weight: 700; color: var(--color-navy); }
.producto-card-codigo { font-size: 0.78rem; color: var(--color-text-muted); font-family: monospace; }
.producto-card-precio { font-size: 1.1rem; font-weight: 700; color: var(--color-primary); }
.producto-card-stock  { font-size: 0.82rem; }
.stock-ok  { color: var(--color-success); }
.stock-low { color: var(--color-warning); }
.stock-out { color: var(--color-danger); }

/* ── Scanner QR ─────────────────────────────────────────────── */
.qr-reader-wrapper {
  max-width: 380px;
  margin: 0 auto;
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  border: 2px solid var(--color-primary);
}
#qr-reader { width: 100%; }
.qr-result {
  padding: 14px;
  background: var(--color-primary-lt);
  border-radius: var(--border-radius);
  margin-top: 12px;
}

/* ── Etiquetas QR (generador) ───────────────────────────────── */
.qr-label-preview {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border: 1px dashed #ccc;
  border-radius: var(--border-radius);
  width: 120px;
  text-align: center;
  font-size: 0.75rem;
}
.qr-label-preview canvas { width: 90px; height: 90px; }

/* ── Plan de cuotas ─────────────────────────────────────────── */
.cuotas-table-wrap { overflow-x: auto; }
.cuotas-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.cuotas-table th { background: var(--color-navy-lt); color: var(--color-navy); padding: 8px 12px; text-align: left; font-weight: 600; }
.cuotas-table td { padding: 8px 12px; border-bottom: 1px solid #f0f0f0; }
.cuotas-table tr.vencida td { background: #fff5f5; color: var(--color-danger); }
.cuotas-table tr.pagada  td { background: #f5fff5; color: #555; opacity: 0.7; }

/* ── Timeline de despacho ───────────────────────────────────── */
.timeline { padding: 8px 0; }
.timeline-item {
  display: flex;
  gap: 14px;
  padding-bottom: 20px;
  position: relative;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: 11px; top: 24px;
  bottom: 0; width: 2px;
  background: #e0e0e0;
}
.timeline-item:last-child::before { display: none; }
.timeline-dot {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  z-index: 1;
}
.timeline-dot.pending { background: #ddd; }
.timeline-body { flex: 1; }
.timeline-title { font-weight: 600; font-size: 0.9rem; }
.timeline-time  { font-size: 0.78rem; color: var(--color-text-muted); }

/* ── Formas de pago (pago mixto) ────────────────────────────── */
.pago-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #fafafa;
  border-radius: var(--border-radius);
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.pago-row .btn-icon-sm {
  background: var(--color-danger);
  color: white;
  border: none;
  border-radius: 50%;
  width: 26px; height: 26px;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

/* ── Nota de venta (vista web antes de imprimir) ────────────── */
.nota-venta-preview {
  max-width: 700px;
  margin: 0 auto;
  background: white;
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px;
}
.nota-empresa-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--color-primary);
}
.nota-numero {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-navy);
  margin-bottom: 8px;
}

/* ── KPI comparativa locales ────────────────────────────────── */
.comparativa-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.comparativa-label { width: 120px; font-size: 0.85rem; text-align: right; }
.comparativa-track { flex: 1; height: 12px; background: #eee; border-radius: 6px; overflow: hidden; }
.comparativa-fill  { height: 100%; background: var(--color-primary); border-radius: 6px; transition: width 0.8s ease; }
.comparativa-value { width: 80px; font-size: 0.82rem; font-weight: 600; }

/* ── Dashboard chart wrapper ────────────────────────────────── */
.chart-wrapper {
  background: white;
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.chart-wrapper canvas { max-height: 280px; }

/* ── Historial cliente (tabs) ───────────────────────────────── */
.cliente-header {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  background: white;
  border-radius: var(--border-radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.cliente-avatar-lg {
  width: 64px; height: 64px;
  background: var(--color-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 700; color: white;
  flex-shrink: 0;
}
.cliente-info h2 { color: var(--color-navy); }
.cliente-meta { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 8px; }
.cliente-meta-item { display: flex; gap: 6px; align-items: center; font-size: 0.85rem; color: var(--color-text-muted); }

/* ── Alerta crítica de stock ────────────────────────────────── */
.stock-alerta-list { display: flex; flex-direction: column; gap: 6px; }
.stock-alerta-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #fff8e1;
  border-left: 3px solid var(--color-warning);
  border-radius: var(--border-radius);
  font-size: 0.85rem;
}
.stock-alerta-item.critico { background: #fdecea; border-left-color: var(--color-danger); }

/* ── Selector de vista activa (dropdown en navbar) ──────────── */
/* (ya definido en main.css, aquí sólo complementos de estado) */
.vista-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(255,255,255,0.15);
  color: white;
}

/* ── Step wizard (formas de pago / crédito) ─────────────────── */
.wizard-steps {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 2px solid #eee;
}
.wizard-step {
  flex: 1;
  text-align: center;
  padding: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.wizard-step.active    { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 700; }
.wizard-step.completed { color: var(--color-success); }

/* ── Despacho: items con stock visual ───────────────────────── */
.despacho-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border: 1px solid #eee;
  border-radius: var(--border-radius);
  margin-bottom: 8px;
  background: white;
}
.despacho-item.sin-stock { border-color: var(--color-danger); background: #fff5f5; }
.despacho-item.con-stock { border-color: var(--color-success); background: #f5fff5; }
.despacho-qty { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; min-width: 60px; }
.despacho-qty .qty-num  { font-size: 1.3rem; font-weight: 700; color: var(--color-navy); }
.despacho-qty .qty-label{ font-size: 0.72rem; color: var(--color-text-muted); }

/* ============================================================
   RESPONSIVE OVERRIDES — Componentes específicos
   ============================================================ */

/* ── Tablet (≤768px) ────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Tabla de items cotización/venta */
  .items-table-wrap { 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch;
  }
  .items-table { min-width: 600px; }
  .items-table th,
  .items-table td { padding: 7px 8px; font-size: 0.85rem; }
  
  /* Totales */
  .items-totals { padding: 14px 16px; }
  .total-row { font-size: 0.85rem; }
  .total-row .label { min-width: 110px; }
  .total-row .value { min-width: 90px; }
  .total-row.grand-total .label,
  .total-row.grand-total .value { font-size: 1rem; }

  /* Cliente header */
  .cliente-header { flex-direction: column; gap: 14px; padding: 18px; }
  .cliente-meta { flex-direction: column; gap: 10px; }

  /* Comparativa locales */
  .comparativa-bar { flex-direction: column; align-items: stretch; }
  .comparativa-label { width: 100%; text-align: left; }
  .comparativa-value { width: 100%; text-align: left; }

  /* Chart wrapper */
  .chart-wrapper { padding: 16px; }
  .chart-wrapper canvas { max-height: 240px; }

  /* Timeline despacho */
  .timeline-item { gap: 10px; }
  .timeline-dot { width: 20px; height: 20px; }
  .timeline-title { font-size: 0.85rem; }

  /* Despacho items */
  .despacho-item { flex-wrap: wrap; padding: 10px 12px; }
  .despacho-qty { min-width: 50px; }
  .despacho-qty .qty-num { font-size: 1.1rem; }

  /* Wizard steps */
  .wizard-steps { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .wizard-step { padding: 8px 12px; font-size: 0.8rem; white-space: nowrap; }

  /* Nota venta preview */
  .nota-venta-preview { padding: 24px; }
  .nota-empresa-header { flex-direction: column; gap: 12px; }
  .nota-numero { font-size: 1.15rem; }
}

/* ── Móvil (≤600px) ─────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Tabla items cotización/venta */
  .items-table { min-width: 540px; font-size: 0.8rem; }
  .items-table th,
  .items-table td { padding: 6px 6px; }
  .items-table .qty-input { width: 60px; font-size: 0.85rem; }
  .items-table .price-input { width: 85px; font-size: 0.85rem; }
  .items-table .btn-sm { padding: 4px 8px; font-size: 0.75rem; }

  /* Totales */
  .items-totals { padding: 12px 14px; }
  .total-row { font-size: 0.8rem; flex-wrap: wrap; }
  .total-row .label { min-width: 100px; font-size: 0.8rem; }
  .total-row .value { min-width: 80px; font-size: 0.8rem; }
  .total-row.grand-total .label,
  .total-row.grand-total .value { font-size: 0.95rem; }

  /* Producto card preview */
  .producto-card-preview { flex-direction: column; padding: 12px; }
  .producto-card-img { width: 100%; height: 160px; }
  .producto-card-nombre { font-size: 0.95rem; }
  .producto-card-precio { font-size: 1rem; }

  /* Scanner QR */
  .qr-reader-wrapper { max-width: 100%; }
  .qr-result { padding: 12px; font-size: 0.85rem; }

  /* Etiquetas QR */
  .qr-label-preview { width: 100px; padding: 8px; }
  .qr-label-preview canvas { width: 75px; height: 75px; }

  /* Cuotas table */
  .cuotas-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cuotas-table { min-width: 480px; font-size: 0.8rem; }
  .cuotas-table th,
  .cuotas-table td { padding: 6px 8px; }

  /* Timeline */
  .timeline-item { gap: 8px; padding-bottom: 16px; }
  .timeline-item::before { left: 9px; }
  .timeline-dot { width: 18px; height: 18px; font-size: 0.7rem; }
  .timeline-title { font-size: 0.82rem; }
  .timeline-time { font-size: 0.72rem; }

  /* Pago row */
  .pago-row { flex-direction: column; align-items: stretch; padding: 8px; }
  .pago-row .form-control { width: 100%; }
  .pago-row .btn-icon-sm { align-self: flex-end; }

  /* Nota venta preview */
  .nota-venta-preview { padding: 16px; }
  .nota-empresa-header { gap: 10px; }
  .nota-numero { font-size: 1rem; }

  /* Comparativa */
  .comparativa-bar { margin-bottom: 10px; }
  .comparativa-label { font-size: 0.8rem; }
  .comparativa-value { font-size: 0.78rem; }
  .comparativa-track { height: 10px; }

  /* Chart wrapper */
  .chart-wrapper { padding: 12px; }
  .chart-wrapper canvas { max-height: 200px; }

  /* Cliente header */
  .cliente-header { padding: 14px; }
  .cliente-avatar-lg { width: 52px; height: 52px; font-size: 1.3rem; }
  .cliente-info h2 { font-size: 1.1rem; }
  .cliente-meta { gap: 10px; }
  .cliente-meta-item { font-size: 0.8rem; }

  /* Stock alerta */
  .stock-alerta-item { flex-direction: column; align-items: flex-start; padding: 6px 10px; font-size: 0.8rem; }

  /* Vista badge */
  .vista-badge { padding: 2px 8px; font-size: 0.7rem; }

  /* Wizard steps */
  .wizard-step { padding: 8px 10px; font-size: 0.78rem; }

  /* Despacho items */
  .despacho-item { padding: 8px 10px; gap: 8px; }
  .despacho-qty { min-width: 45px; }
  .despacho-qty .qty-num { font-size: 1rem; }
  .despacho-qty .qty-label { font-size: 0.7rem; }

  /* Foto grid */
  .foto-grid { gap: 8px; }
  .foto-thumb { width: 70px; height: 70px; }
}

/* ── Muy pequeño (≤420px) ───────────────────────────────────── */
@media (max-width: 420px) {
  /* Tabla items: más compacta */
  .items-table { min-width: 500px; font-size: 0.75rem; }
  .items-table th,
  .items-table td { padding: 5px 4px; }
  .items-table .qty-input { width: 50px; }
  .items-table .price-input { width: 75px; }

  /* Totales */
  .items-totals { padding: 10px 12px; }
  .total-row { font-size: 0.75rem; }
  .total-row.grand-total .label,
  .total-row.grand-total .value { font-size: 0.88rem; }

  /* Producto card */
  .producto-card-preview { padding: 10px; }
  .producto-card-img { height: 140px; }
  .producto-card-nombre { font-size: 0.88rem; }
  .producto-card-codigo { font-size: 0.72rem; }
  .producto-card-precio { font-size: 0.95rem; }
  .producto-card-stock { font-size: 0.78rem; }

  /* QR label */
  .qr-label-preview { width: 90px; padding: 6px; font-size: 0.7rem; }
  .qr-label-preview canvas { width: 65px; height: 65px; }

  /* Cuotas table */
  .cuotas-table { min-width: 420px; font-size: 0.75rem; }
  .cuotas-table th,
  .cuotas-table td { padding: 5px 6px; }

  /* Timeline */
  .timeline-dot { width: 16px; height: 16px; font-size: 0.65rem; }
  .timeline-title { font-size: 0.78rem; }
  .timeline-time { font-size: 0.7rem; }

  /* Cliente header */
  .cliente-header { padding: 12px; }
  .cliente-avatar-lg { width: 48px; height: 48px; font-size: 1.2rem; }
  .cliente-info h2 { font-size: 1rem; }
  .cliente-meta-item { font-size: 0.75rem; }

  /* Chart */
  .chart-wrapper { padding: 10px; }
  .chart-wrapper canvas { max-height: 180px; }

  /* Nota venta */
  .nota-venta-preview { padding: 12px; }
  .nota-numero { font-size: 0.95rem; }

  /* Comparativa */
  .comparativa-label { font-size: 0.75rem; }
  .comparativa-value { font-size: 0.72rem; }
  .comparativa-track { height: 8px; }

  /* Stock alerta */
  .stock-alerta-item { padding: 5px 8px; font-size: 0.75rem; }

  /* Despacho */
  .despacho-item { padding: 6px 8px; }
  .despacho-qty .qty-num { font-size: 0.95rem; }

  /* Foto grid */
  .foto-thumb { width: 60px; height: 60px; }

  /* Filtros horizontales — mobile */
  .filter-row { flex-direction: column; gap: 8px; }
  .filter-group,
  .filter-row .form-group { min-width: unset !important; width: 100%; flex: unset; }
}

/* ── Filtros horizontales ───────────────────────────────────── */

/* Contenedor: una fila flex con los grupos lado a lado */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}

/* Cada grupo de filtro (puede ser .filter-group o .form-group dentro de .filter-row) */
.filter-group,
.filter-row .form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
  flex: 1;
  margin-bottom: 0;
}

/* Grupo de botones: no crecer, alinearse al fondo */
.filter-group.filter-actions,
.filter-row .form-group[style*="align-self:flex-end"],
.filter-row .form-group:has(> .btn) {
  flex: 0 0 auto;
  flex-direction: row;
  align-items: flex-end;
  gap: 6px;
  min-width: unset;
}

/* Etiquetas dentro de filtros */
.filter-label,
.filter-row .form-label {
  font-size: .73rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  margin-bottom: 0;
}
