/* ============================================================
   Quantum — patrones NUEVOS sobre .qc-* (prefijo .qm-*)
   Mismo lenguaje/tokens. KPIs con tendencia · sparkline · tablas
   ordenables · paginador · wizard · gráficos · export · análisis.
   ============================================================ */

/* ---------- KPI grande con tendencia + sparkline ---------- */
.qm-kpi { position: relative; }
.qm-kpi .qc-kpi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.qm-kpi-ic { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: color-mix(in srgb, var(--k, var(--accent)) 14%, transparent); color: var(--k, var(--accent)); flex-shrink: 0; }
.qm-trend { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.qm-trend.up { color: var(--accent-green); background: color-mix(in srgb, var(--accent-green) 14%, transparent); }
.qm-trend.down { color: var(--accent-red); background: color-mix(in srgb, var(--accent-red) 14%, transparent); }
.qm-trend.flat { color: var(--text-muted); background: var(--bg-card-hover); }
.qm-kpi.alert { border-color: color-mix(in srgb, var(--accent-yellow) 45%, var(--border)); background: color-mix(in srgb, var(--accent-yellow) 7%, var(--bg-card)); }
.qm-spark { width: 100%; height: 30px; margin-top: auto; display: block; }
.qm-spark path.line { fill: none; stroke: var(--k, var(--accent)); stroke-width: 2; }
.qm-spark path.area { fill: color-mix(in srgb, var(--k, var(--accent)) 13%, transparent); stroke: none; }

/* ---------- Tabla: header ordenable + thumb + acciones ---------- */
.qc-table thead th.qm-sort { cursor: pointer; user-select: none; }
.qc-table thead th.qm-sort:hover { color: var(--text); }
.qm-sort-i { display: inline-flex; vertical-align: middle; margin-left: 4px; opacity: .55; transition: opacity .12s, transform .12s; }
.qc-table thead th.qm-sort.active .qm-sort-i { opacity: 1; color: var(--accent); }
.qc-table thead th.qm-sort.desc .qm-sort-i { transform: rotate(180deg); }
.qm-thumb { width: 38px; height: 38px; border-radius: 8px; flex-shrink: 0; display: grid; place-items: center; color: var(--text-muted); background: repeating-linear-gradient(135deg, var(--bg-card-hover) 0 6px, var(--bg) 6px 12px); border: 1px solid var(--border-light); }
.qm-rowacts { display: flex; gap: 4px; justify-content: flex-end; opacity: 0; transition: opacity .12s; }
.qc-table tbody tr:hover .qm-rowacts { opacity: 1; }
@media (hover: none) { .qm-rowacts { opacity: 1; } }

/* ---------- Paginador táctil ---------- */
.qm-pager { display: flex; align-items: center; gap: 8px; padding: 12px 2px 2px; flex-shrink: 0; flex-wrap: wrap; }
.qm-pager-info { font-size: 12.5px; color: var(--text-muted); }
.qm-pager-sp { flex: 1; }
.qm-pg { display: grid; place-items: center; min-width: 34px; height: 34px; padding: 0 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-secondary); font-size: 13px; font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; transition: all .12s; }
.qm-pg:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text); }
.qm-pg.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.qm-pg:disabled { opacity: .4; cursor: default; }

/* ---------- Wizard (armador de PC) ---------- */
.qm-builder { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 360px; gap: 16px; }
.qm-build-main { min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.qm-steps { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 12px; flex-shrink: 0; scrollbar-width: none; }
.qm-steps::-webkit-scrollbar { display: none; }
.qm-step { display: flex; align-items: center; gap: 9px; padding: 8px 13px 8px 9px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-card); cursor: pointer; white-space: nowrap; transition: all .12s; flex-shrink: 0; }
.qm-step:hover { border-color: var(--border-strong); }
.qm-step.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
.qm-step.done { border-color: color-mix(in srgb, var(--accent-green) 45%, var(--border)); }
.qm-step-n { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--bg); border: 1px solid var(--border); color: var(--text-muted); font-size: 12px; font-weight: 800; flex-shrink: 0; }
.qm-step.active .qm-step-n { background: var(--accent); border-color: var(--accent); color: #fff; }
.qm-step.done .qm-step-n { background: var(--accent-green); border-color: var(--accent-green); color: #fff; }
.qm-step-tx { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.qm-step-tx b { font-size: 12.5px; font-weight: 700; color: var(--text); }
.qm-step-tx span { font-size: 10.5px; color: var(--text-muted); }
.qm-pick { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 2px; }
.qm-pickrow { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-card); cursor: pointer; transition: all .12s; }
.qm-pickrow:hover { border-color: var(--border-strong); }
.qm-pickrow.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.qm-pickrow-tx { flex: 1; min-width: 0; }
.qm-pickrow-tx b { font-size: 13.5px; font-weight: 600; display: block; }
.qm-pickrow-tx span { font-size: 11.5px; color: var(--text-muted); }
.qm-pickrow-price { text-align: right; flex-shrink: 0; }
.qm-pickrow-price b { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.qm-pickrow-price span { font-size: 11px; color: var(--text-muted); display: block; }

/* ---------- Gráficos temados (barras + línea, SVG) ---------- */
.qm-chart { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; min-width: 0; }
.qm-chart-h { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.qm-chart-h h3 { margin: 0; font-size: 14px; font-weight: 700; }
.qm-chart-h .qm-chart-sp { flex: 1; }
.qm-legend { display: flex; gap: 12px; flex-wrap: wrap; }
.qm-legend span { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-secondary); font-weight: 600; }
.qm-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.qm-svg { width: 100%; height: auto; overflow: visible; }
.qm-svg .grid { stroke: var(--border-light); stroke-width: 1; }
.qm-svg .axis { fill: var(--text-muted); font-size: 10px; font-weight: 600; font-family: var(--font-mono); }
.qm-svg .lbar { transition: opacity .12s; }
.qm-svg .lline { fill: none; stroke-width: 2.2; }
.qm-svg .ldot { stroke: var(--bg-card); stroke-width: 1.5; }

/* distribución (mini barras horizontales) */
.qm-dist { display: flex; flex-direction: column; gap: 9px; }
.qm-dist-row { display: grid; grid-template-columns: 110px 1fr 56px; align-items: center; gap: 10px; }
.qm-dist-row b { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qm-dist-track { height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.qm-dist-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.qm-dist-val { font-size: 12px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); }

/* medidor (hit rate / salud) */
.qm-meter { width: 72px; height: 6px; border-radius: 999px; background: var(--bg); overflow: hidden; display: inline-block; vertical-align: middle; }
.qm-meter span { display: block; height: 100%; border-radius: 999px; background: var(--m, var(--accent-green)); }

/* pill resumen (competidores) */
.qm-pillrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.qm-pill { display: flex; align-items: center; gap: 11px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 13px 15px; box-shadow: var(--shadow-sm); }
.qm-pill-ic { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: color-mix(in srgb, var(--k, var(--accent)) 14%, transparent); color: var(--k, var(--accent)); flex-shrink: 0; }
.qm-pill-tx b { font-size: 20px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; display: block; }
.qm-pill-tx span { font-size: 11.5px; color: var(--text-muted); }

/* ---------- Buscar (log de progreso colapsable) ---------- */
.qm-progress { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.qm-progress-bar { height: 4px; background: var(--bg); overflow: hidden; }
.qm-progress-bar span { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.qm-progress-h { display: flex; align-items: center; gap: 10px; padding: 11px 14px; cursor: pointer; }
.qm-progress-h b { font-size: 13px; font-weight: 700; }
.qm-progress-log { font-family: var(--font-mono); font-size: 11.5px; line-height: 1.7; color: var(--text-secondary); background: var(--bg-terminal); color: #c7c4ba; padding: 12px 14px; max-height: 160px; overflow-y: auto; }
.qm-progress-log .ok { color: var(--accent-green); }
.qm-progress-log .dim { color: var(--text-muted); }

/* ---------- Export a Odoo (panel guiado) ---------- */
.qm-export { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.qm-export-preview { position: sticky; top: 0; }
.qm-colchips { display: flex; flex-wrap: wrap; gap: 6px; }
.qm-colchip { font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; color: var(--text-secondary); background: var(--bg); border: 1px solid var(--border); padding: 3px 9px; border-radius: 6px; }

/* ---------- Análisis (plantilla de categoría) ---------- */
.qm-anav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.qm-anav::-webkit-scrollbar { display: none; }

/* ---------- utilidades de grid responsive ---------- */
.qm-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.qm-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.qm-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-right: 2px; }
.qm-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.qm-flag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; color: var(--accent-green); }
.qm-flag.best { color: var(--accent-green); }

/* segmented dentro de tabla (filtros de catálogo en vivo) */
.qm-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-bottom: 12px; flex-shrink: 0; }
.qm-mini { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text-secondary); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.qm-mini select { border: none; background: none; outline: none; color: var(--text); font-size: 12.5px; font-weight: 600; font-family: inherit; cursor: pointer; }
.qm-mini:hover { border-color: var(--border-strong); }

/* responsive */
@media (max-width: 980px) {
  .qm-builder { grid-template-columns: 1fr; }
  .qm-build-main { padding-bottom: 96px; }
  .qm-build-side { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-lg); max-height: 72vh; }
  .qm-build-side .qb-build-h { cursor: pointer; }
  .qm-build-side .qb-build-items { display: none !important; }
  .qm-build-side.open .qb-build-items { display: block !important; }
  .qm-build-side .qb-sheet-chev { display: inline-flex; transition: transform .15s; }
  .qm-build-side.open .qb-sheet-chev { transform: rotate(180deg); }
  .qm-export { grid-template-columns: 1fr; }
  .qm-export-preview { position: static; }
}
@media (min-width: 981px) { .qm-build-side .qb-sheet-chev { display: none; } }
@media (max-width: 760px) {
  .qm-grid-2, .qm-grid-3 { grid-template-columns: 1fr; }
  .qm-dist-row { grid-template-columns: 92px 1fr 48px; }
}

/* ============================================================
   Pulido responsive (móvil): evitar recorte de texto en filtros
   y que la lupa del buscador no se monte sobre el placeholder.
   ============================================================ */
@media (max-width: 680px) {
  .gar-search input, .gar-filters select, .compras-filters select, .prod-toolbar select {
    min-height: 42px; line-height: 1.3;
  }
  .gar-search input { padding-left: 38px; }
  .gar-search svg { left: 12px; z-index: 1; }
}
