/* KARDEX — Warm Technical Inventory Workbench
   Design tokens + Emil Kowalski motion discipline */

:root {
  --bg: #F5F3EE;
  --surface: #FFFFFF;
  --surface-2: #FAF9F5;
  --surface-3: #EFECE5;
  --ink: #15181C;
  --ink-2: #49525C;
  --muted: #7C8590;
  --line: rgba(21, 24, 28, 0.09);
  --line-strong: rgba(21, 24, 28, 0.16);

  --accent: #0D7A56;
  --accent-hi: #0A6647;
  --accent-bg: #E7F5EF;
  --accent-ink: #08563C;

  --warn: #B86B08;
  --warn-bg: #FEF3DF;
  --danger: #C23826;
  --danger-bg: #FDECE9;
  --blue: #1E5799;
  --blue-bg: #EAF2FC;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(21, 24, 28, 0.05);
  --shadow-md: 0 8px 24px -10px rgba(21, 24, 28, 0.16), 0 1px 2px rgba(21, 24, 28, 0.06);
  --shadow-lg: 0 24px 56px -18px rgba(21, 24, 28, 0.28), 0 0 0 1px rgba(21, 24, 28, 0.06);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  padding-bottom: 40px;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button, input, select { font: inherit; color: inherit; }

/* ── Topbar ───────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(245, 243, 238, 0.88);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 18px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: var(--ink);
  flex: none;
}

.divider-v {
  width: 1px;
  height: 22px;
  background: var(--line-strong);
  flex: none;
}

.rubro-wrap, .bcv-wrap, .tools-wrap { position: relative; }

.rubro-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background-color 140ms ease, border-color 140ms ease, transform 120ms var(--ease-out);
  max-width: 240px;
}

.rubro-btn:active { transform: scale(0.97); }
.rubro-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.rubro-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.rubro-text strong {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rubro-text small {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chev {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* Main Navigation Tabs with sliding pill */
.main-tabs {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-3);
  border: 1px solid var(--line);
}

.tab-pill {
  position: absolute;
  top: 3px;
  left: 0;
  height: calc(100% - 6px);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 220ms var(--ease-drawer), width 220ms var(--ease-drawer);
  pointer-events: none;
}

.tab-btn {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 0;
  background: transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: color 150ms ease;
}

.tab-btn.active { color: var(--ink); font-weight: 700; }

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
}
.tab-badge.warn { background: var(--danger); }

/* Header Right Cluster */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  transition: transform 120ms var(--ease-out), border-color 140ms ease;
}
.chip-btn:active { transform: scale(0.97); }
.bcv-label { color: var(--muted); font-size: 10.5px; font-weight: 600; }
.curr-tag {
  font-size: 10.5px;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--accent-bg);
  color: var(--accent-ink);
  font-weight: 700;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  min-width: 34px;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  cursor: pointer;
  transition: transform 120ms var(--ease-out), background-color 140ms ease;
}
.icon-btn:active { transform: scale(0.97); }
.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.kbd-hint {
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
}

.btn-primary, .btn-ghost, .btn-danger-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 120ms var(--ease-out), background-color 140ms ease, border-color 140ms ease;
}
.btn-primary:active, .btn-ghost:active, .btn-danger-outline:active { transform: scale(0.97); }

.btn-primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #FFFFFF;
}
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary.full { width: 100%; height: 42px; font-size: 14px; }
.btn-primary svg, .btn-ghost svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-ghost {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}

/* ── Popovers (Origin-aware) ──────────────────────────────────────────── */
.popover {
  position: absolute;
  top: calc(100% + 6px);
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  opacity: 0;
  transform: scale(0.95) translateY(-4px);
  pointer-events: none;
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}
.popover.open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

.rubro-menu { left: 0; width: 268px; transform-origin: top left; }
.bcv-pop { right: 0; width: 254px; padding: 12px; transform-origin: top right; }
.tools-menu { right: 0; width: 238px; transform-origin: top right; }

.rubro-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background-color 120ms ease;
}
.rubro-option strong { display: block; font-size: 13px; }
.rubro-option small { display: block; font-size: 11.5px; color: var(--muted); }
.rubro-option.active { background: var(--accent-bg); }
.rubro-option.active strong { color: var(--accent-ink); }
.rubro-tag {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--ink-2);
}

.pop-head strong { display: block; font-size: 13px; }
.pop-head small { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 10px; }
.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-2);
  margin-bottom: 10px;
}
.field-inline span { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.field-inline input {
  width: 96px;
  border: 0;
  background: transparent;
  text-align: right;
  font-weight: 700;
  font-size: 14px;
  outline: none;
}

.seg-mini {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-3);
}
.seg-mini button {
  border: 0;
  background: transparent;
  padding: 5px 4px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-2);
  cursor: pointer;
}
.seg-mini button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.tools-menu button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tools-menu .danger-item { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 5px 0; }

/* ── Main Shell & Views ───────────────────────────────────────────────── */
.shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px 18px 28px;
}

.view { display: none; }
.view.active { display: block; }

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.view-head h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.view-head p { margin: 2px 0 0; font-size: 13px; }
.head-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ── KPI Strip ────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, transform 120ms var(--ease-out), box-shadow 140ms ease;
}
.kpi-card:active { transform: scale(0.985); }
.kpi-card.active-filter {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.kpi-val {
  font-family: "JetBrains Mono", monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1.15;
}
.kpi-val.danger { color: var(--danger); }
.kpi-val.warn { color: var(--warn); }
.kpi-sub {
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Toolbar ──────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 42px;
  padding: 0 6px 0 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.search-box.compact { height: 38px; margin-bottom: 12px; }
.search-box svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 13.5px;
}

.scan-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex: none;
  transition: transform 120ms var(--ease-out), background-color 140ms ease;
}
.scan-trigger:active { transform: scale(0.97); }
.scan-trigger svg { width: 15px; height: 15px; stroke: var(--ink); }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.status-pills {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: var(--surface-3);
  border-radius: 9px;
  border: 1px solid var(--line);
}
.pill {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 140ms ease, color 140ms ease, transform 120ms var(--ease-out);
}
.pill:active { transform: scale(0.97); }
.pill.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.select-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

select {
  height: 34px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

/* ── Main Sheet & Table ───────────────────────────────────────────────── */
.sheet-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-wrap { overflow-x: auto; }

.inv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.inv-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.inv-table th.num { text-align: right; }
.inv-table th.act-col { text-align: right; }

.inv-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.inv-table tbody tr:last-child td { border-bottom: 0; }
.inv-table tbody tr {
  cursor: pointer;
  transition: background-color 110ms ease;
}

.prod-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.cat-dot {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--ink-2);
  flex: none;
}
.prod-title {
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}
.prod-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--muted);
}

.loc-chip {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.ok { background: var(--accent-bg); color: var(--accent-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.neutral { background: var(--surface-3); color: var(--ink-2); }

/* Calibrated Stock Gauge */
.stock-cell { min-width: 142px; }
.stock-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}
.stock-qty { font-size: 13.5px; font-weight: 700; }
.stock-unit { font-size: 11px; color: var(--muted); font-weight: 500; }
.gauge {
  height: 5px;
  width: 100%;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}
.gauge-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: transform 220ms var(--ease-out);
  transform-origin: left center;
}
.gauge-fill.warn { background: var(--warn); }
.gauge-fill.danger { background: var(--danger); }

.money-stack { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.money-bs { font-size: 11px; color: var(--muted); }

/* Quick Inline Stepper */
.quick-step {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
}
.step-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 110ms var(--ease-out), background-color 120ms ease, border-color 120ms ease;
}
.step-btn:active { transform: scale(0.93); }
.step-btn.plus { color: var(--accent-ink); border-color: rgba(13, 122, 86, 0.3); }
.step-btn.minus { color: var(--danger); border-color: rgba(194, 56, 38, 0.25); }
.step-btn.cart-add {
  width: auto;
  padding: 0 8px;
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 11.5px;
  color: var(--ink-2);
}

.flash-qty { animation: qtyPulse 320ms var(--ease-out); }
@keyframes qtyPulse {
  0% { background: rgba(13, 122, 86, 0.2); border-radius: 4px; }
  100% { background: transparent; }
}

/* Mobile Inventory Cards (hidden on desktop) */
.inv-cards { display: none; }

.empty-state {
  padding: 44px 20px;
  text-align: center;
}
.empty-state p { margin: 0 0 6px; }
.empty-actions { display: flex; justify-content: center; gap: 8px; margin-top: 14px; }

/* ── View 2: Despacho / Movimiento ────────────────────────────────────── */
.mov-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
  gap: 16px;
  align-items: start;
}

.mode-switch {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 3px;
  border-radius: 9px;
  background: var(--surface-3);
  border: 1px solid var(--line);
}
.mode-btn {
  border: 0;
  background: transparent;
  padding: 6px 11px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-2);
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, transform 110ms var(--ease-out);
}
.mode-btn:active { transform: scale(0.97); }
.mode-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.mov-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 9px;
}

.pick-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  transition: transform 120ms var(--ease-out), border-color 140ms ease;
}
.pick-card:active { transform: scale(0.975); }
.pick-card.in-cart {
  border-color: var(--accent);
  background: #F6FBF8;
}
.pick-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.pick-name { font-weight: 700; font-size: 13px; line-height: 1.25; }
.pick-foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
}

.mov-cart {
  position: sticky;
  top: 74px;
  display: flex;
  flex-direction: column;
}
.cart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.cart-head h2 { margin: 2px 0 0; font-size: 16px; font-weight: 800; }
.kicker-tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent-ink);
  background: var(--accent-bg);
  padding: 2px 7px;
  border-radius: 5px;
}
.kicker-tag.warn { background: var(--warn-bg); color: var(--warn); }
.kicker-tag.danger { background: var(--danger-bg); color: var(--danger); }
.kicker-tag.blue { background: var(--blue-bg); color: var(--blue); }

.cart-warehouses {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.cart-items {
  max-height: 320px;
  overflow-y: auto;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cart-empty {
  padding: 28px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.cart-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.cart-row:last-child { border-bottom: 0; padding-bottom: 0; }
.cart-row-info { min-width: 0; flex: 1; }
.cart-row-info strong {
  display: block;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cart-row-info small { font-size: 11px; color: var(--muted); }
.cart-qty-ctrl { display: flex; align-items: center; gap: 4px; }
.cart-qty-ctrl input {
  width: 50px;
  height: 28px;
  text-align: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 12.5px;
}

.cart-meta {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}

.cart-footer {
  padding: 12px 16px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tot-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  color: var(--ink-2);
}
.tot-row.big { margin-top: 4px; color: var(--ink); font-weight: 700; }
.tot-money { text-align: right; }
.tot-money strong { display: block; font-size: 20px; }

/* ── View 4: Conteo Físico ────────────────────────────────────────────── */
.conteo-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.conteo-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 11px 14px;
}
.conteo-stat span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; }
.conteo-stat strong { font-size: 18px; }

.conteo-input {
  width: 82px;
  height: 32px;
  padding: 0 8px;
  text-align: right;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
}
.conteo-input.changed {
  border-color: var(--accent);
  background: #F4FBF8;
}

/* ── View 5: Reposición ───────────────────────────────────────────────── */
.reponer-total-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  font-size: 12px;
}

.reponer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
}

.sup-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sup-head {
  padding: 13px 15px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.sup-head strong { display: block; font-size: 14.5px; }
.sup-head small { color: var(--muted); font-size: 12px; }
.sup-list { padding: 10px 15px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.sup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}
.sup-item:last-child { border-bottom: 0; padding-bottom: 0; }
.sup-item input {
  width: 60px;
  height: 28px;
  text-align: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
}
.sup-foot {
  padding: 12px 15px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.sup-foot .btn-primary, .sup-foot .btn-ghost { flex: 1; }

/* ── Forms ────────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field span {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-2);
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13.5px;
}
.field textarea { resize: vertical; min-height: 90px; font-family: "JetBrains Mono", monospace; font-size: 12px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* ── Product Drawer ───────────────────────────────────────────────────── */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(21, 24, 28, 0.34);
  opacity: 0;
  transition: opacity 220ms ease;
}
.backdrop.open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 85;
  width: min(460px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 260ms var(--ease-drawer);
}
.drawer.open { transform: translateX(0); }
.drawer-handle { display: none; }

.drawer-head {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.drawer-head h2 { margin: 4px 0 0; font-size: 17px; font-weight: 800; line-height: 1.25; }
.sku-chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--ink-2);
}

.drawer-body {
  padding: 16px 18px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dr-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.dr-metric {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.dr-metric span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; }
.dr-metric strong { display: block; font-size: 16px; margin-top: 2px; }

.dr-section h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.wh-list { display: flex; flex-direction: column; gap: 7px; }
.wh-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.barcode-card {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 12px;
  background: #FFFFFF;
  text-align: center;
}
.barcode-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.barcode-card-actions button { flex: 1; }

.mini-hist { display: flex; flex-direction: column; gap: 6px; }
.mini-hist-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.mini-hist-row:last-child { border-bottom: 0; }

/* Hold-to-delete (Emil clip-path pattern: slow press 1.2s, snappy 180ms release) */
.hold-del {
  position: relative;
  width: 100%;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(194, 56, 38, 0.35);
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 140ms var(--ease-out);
}
.hold-del:active { transform: scale(0.985); }
.hold-del-fill {
  position: absolute;
  inset: 0;
  background: var(--danger);
  color: #FFFFFF;
  display: grid;
  place-items: center;
  clip-path: inset(0 100% 0 0);
  transition: clip-path 180ms var(--ease-out);
  pointer-events: none;
}
.hold-del.holding .hold-del-fill {
  clip-path: inset(0 0 0 0);
  transition: clip-path 1.15s linear;
}

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 95;
  background: rgba(21, 24, 28, 0.42);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal {
  width: min(540px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modalIn 180ms var(--ease-out);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 800; }
.modal-body { padding: 16px 18px 18px; }

.margin-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--accent-bg);
  color: var(--accent-ink);
  font-size: 12.5px;
  font-weight: 700;
}

.scanner-stage {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #11151A;
  aspect-ratio: 16 / 10;
  display: grid;
  place-items: center;
  color: #E5E7EB;
  margin-bottom: 12px;
}
.scanner-stage video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute;
  width: 68%;
  height: 44%;
  border: 2px solid #10B981;
  border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.38);
  pointer-events: none;
}

/* ── Instant Command Palette (0ms animation, Raycast rule) ────────────── */
.cmd-backdrop {
  position: fixed;
  inset: 0;
  z-index: 105;
  background: rgba(21, 24, 28, 0.36);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12vh 16px 16px;
}
.cmd-box {
  width: min(560px, 100%);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.cmd-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.cmd-input-row svg { width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; }
.cmd-input-row input {
  flex: 1;
  border: 0;
  outline: none;
  font-size: 14.5px;
  background: transparent;
}
.cmd-input-row kbd {
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--muted);
}
.cmd-list { max-height: 360px; overflow-y: auto; padding: 6px; }
.cmd-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
}
.cmd-item.selected { background: var(--accent-bg); color: var(--accent-ink); }
.cmd-item strong { font-weight: 700; }
.cmd-item small { color: var(--muted); font-size: 11.5px; }

/* ── Toasts (Interruptible CSS transition) ────────────────────────────── */
.toast-region {
  position: fixed;
  left: 18px;
  bottom: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 28px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 200ms var(--ease-out), transform 220ms var(--ease-out);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-undo {
  border: 0;
  background: rgba(255, 255, 255, 0.16);
  color: #FFFFFF;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex: none;
}

/* ── Mobile Bottom Nav ────────────────────────────────────────────────── */
.mobile-nav { display: none; }

/* ── Desktop Fine-Pointer Hover Gating ────────────────────────────────── */
@media (hover: hover) and (pointer: fine) {
  .rubro-btn:hover { background: var(--surface); border-color: var(--line-strong); }
  .rubro-option:hover:not(.active), .tools-menu button:hover { background: var(--surface-2); }
  .btn-primary:hover:not(:disabled) { background: var(--accent-hi); }
  .btn-ghost:hover, .icon-btn:hover, .chip-btn:hover, .scan-trigger:hover { background: var(--surface-2); border-color: rgba(21, 24, 28, 0.24); }
  .kpi-card:hover { border-color: var(--line-strong); }
  .inv-table tbody tr:hover { background: #FAF9F6; }
  .step-btn:hover { background: var(--surface-2); }
  .pick-card:hover { border-color: var(--line-strong); }
}

/* ── Responsive Breakpoints ───────────────────────────────────────────── */
@media (max-width: 1080px) {
  .main-tabs { display: none; }
  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: calc(58px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line-strong);
  }
  .mnav-btn {
    position: relative;
    border: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
  }
  .mnav-btn svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .mnav-btn.active { color: var(--accent); }
  .mnav-dot {
    position: absolute;
    top: 5px;
    right: calc(50% - 19px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 99px;
    font-style: normal;
    font-size: 10px;
    font-family: "JetBrains Mono", monospace;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
  }
  .mnav-dot.warn { background: var(--danger); }
  body { padding-bottom: 84px; }
  .toast-region { bottom: 72px; right: 12px; left: 12px; max-width: none; }
  .mov-layout { grid-template-columns: 1fr; }
  .mov-cart { position: static; }
}

@media (max-width: 780px) {
  .topbar-inner { padding: 0 12px; gap: 8px; }
  .brand span { display: none; }
  .kbd-hint, .btn-primary span, .scan-trigger span { display: none; }
  .bcv-label, .curr-tag { display: none; }
  .rubro-btn { max-width: 170px; padding: 4px 6px; }
  .shell { padding: 12px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi-val { font-size: 18px; }
  .toolbar, .filter-bar { min-width: 0; max-width: 100%; }
  .filter-bar { flex-direction: column; align-items: stretch; gap: 7px; }
  .select-cluster {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .select-cluster::-webkit-scrollbar { display: none; }
  .select-cluster > * { flex: none; }
  .conteo-summary { grid-template-columns: 1fr; }
  .reponer-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }

  /* Switch inventory & kardex tables to touch-friendly cards on phones */
  #view-inventario .table-wrap, #view-kardex .table-wrap { display: none; }
  .inv-cards { display: flex; flex-direction: column; }

  .mcard {
    padding: 12px 13px;
    border-bottom: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .mcard:last-child { border-bottom: 0; }
  .mcard-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
  .mcard-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

  /* Drawer becomes bottom sheet on mobile */
  .drawer {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 88vh;
    border-left: 0;
    border-top: 1px solid var(--line-strong);
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
  }
  .drawer.open { transform: translateY(0); }
  .drawer-handle {
    display: flex;
    justify-content: center;
    padding: 8px 0 2px;
  }
  .drawer-handle span {
    width: 36px;
    height: 4px;
    border-radius: 99px;
    background: var(--line-strong);
  }
}

/* ── Reduced Motion ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
  }
}

/* ── Print Styles (Labels & Receipts Only) ────────────────────────────── */
.print-surface { display: none; }

@media print {
  body > *:not(.print-surface) { display: none !important; }
  body { background: #FFFFFF; padding: 0; }
  .print-surface {
    display: block !important;
    padding: 12px;
    font-family: "Plus Jakarta Sans", sans-serif;
    color: #000000;
  }
  .print-label-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
  .print-label {
    border: 1px dashed #999;
    padding: 10px;
    text-align: center;
    break-inside: avoid;
  }
  .print-label strong { display: block; font-size: 12px; margin-bottom: 2px; }
  .print-label .pl-price { font-family: "JetBrains Mono", monospace; font-size: 14px; font-weight: 700; margin: 4px 0; }
}
