/* ============================================================
   Inventario de tienda — hoja de estilos unica, mobile first
   ============================================================ */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --border: #dcdfe6;
  --text: #16191f;
  --muted: #61666f;
  --brand: #1f5fd0;
  --brand-ink: #ffffff;
  --brand-soft: #e6efff;
  --ok: #127a4a;
  --ok-soft: #e0f5ea;
  --warn: #96560a;
  --warn-soft: #fdf0da;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 20, 28, .08), 0 8px 24px rgba(16, 20, 28, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);

  /* Colores de grafica: validados contra la superficie clara (banda de luminosidad,
     croma y contraste >= 3:1). No se reutilizan para texto. */
  --chart-bar: #1f5fd0;
  --chart-bar-hover: #17408f;
  --chart-grid: #e4e7ec;
  --chart-axis: #9aa1ac;

  color-scheme: light;
}

/* El tema oscuro se aplica en dos casos: cuando el sistema lo pide y el usuario no
   forzo el claro, o cuando el usuario elige "oscuro". Los dos bloques deben tener
   los mismos valores. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="claro"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1f262f;
    --border: #2c333d;
    --text: #e8ecf2;
    --muted: #98a1ae;
    --brand: #5b9bff;
    --brand-ink: #08122a;
    --brand-soft: #16233c;
    --ok: #58d69a;
    --ok-soft: #10281d;
    --warn: #f0b95c;
    --warn-soft: #2b2313;
    --danger: #ff8a80;
    --danger-soft: #2c1614;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .35);

    --chart-bar: #4d8ef5;
    --chart-bar-hover: #8ab7fb;
    --chart-grid: #262d37;
    --chart-axis: #6b7684;

    color-scheme: dark;
  }
}

:root[data-theme="oscuro"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f262f;
  --border: #2c333d;
  --text: #e8ecf2;
  --muted: #98a1ae;
  --brand: #5b9bff;
  --brand-ink: #08122a;
  --brand-soft: #16233c;
  --ok: #58d69a;
  --ok-soft: #10281d;
  --warn: #f0b95c;
  --warn-soft: #2b2313;
  --danger: #ff8a80;
  --danger-soft: #2c1614;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .35);

  --chart-bar: #4d8ef5;
  --chart-bar-hover: #8ab7fb;
  --chart-grid: #262d37;
  --chart-axis: #6b7684;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; overflow-x: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }

/* ---------- Arranque ---------- */
.boot { display: grid; place-items: center; min-height: 100dvh; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px 8px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
}
.topbar-row { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.topbar h1 { margin: 0; font-size: 1.08rem; font-weight: 650; letter-spacing: -.01em; }
.topbar .sub { color: var(--muted); font-size: .78rem; }
.topbar-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.view {
  padding: 12px 12px calc(84px + var(--safe-b));
  max-width: 900px;
  margin: 0 auto;
  outline: none;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  border: 0; background: none; color: var(--muted);
  display: grid; justify-items: center; gap: 2px;
  padding: 8px 2px 6px; font-size: .68rem; font-weight: 600;
  min-height: var(--tap);
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button[aria-current="page"] { color: var(--brand); }

/* ---------- Bloques ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card-tight { padding: 10px 12px; }
.card h2, .card h3 { margin: 0 0 10px; font-size: .95rem; font-weight: 650; }
.section-title {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 2px 8px; font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.section-title .grow { flex: 1; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.kpi .label { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.kpi .hint { color: var(--muted); font-size: .74rem; }

.muted { color: var(--muted); }
.small { font-size: .8rem; }
.tiny { font-size: .72rem; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: .92rem; font-weight: 600;
  transition: transform .06s ease, background .12s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-soft { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: .82rem; }
.btn-icon { min-width: var(--tap); padding: 0 8px; }
.btn-block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

.fab {
  position: fixed; right: 14px; z-index: 45;
  bottom: calc(72px + var(--safe-b));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink); border: 0;
  box-shadow: 0 6px 20px rgba(31, 95, 208, .38);
  display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- Formularios ---------- */
.field { display: grid; gap: 5px; }
.field > label { font-size: .78rem; font-weight: 650; color: var(--muted); }
.input, .select, textarea.input {
  width: 100%; min-height: var(--tap);
  padding: 10px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.input:focus-visible, .select:focus-visible, .btn:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
textarea.input { min-height: 76px; resize: vertical; }
.field-error { color: var(--danger); font-size: .78rem; }
.hint { color: var(--muted); font-size: .76rem; }

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 0 6px 0 12px;
}
.search input {
  flex: 1; min-width: 0; min-height: var(--tap);
  border: 0; background: none; outline: none;
}
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: .82rem; font-weight: 600; color: var(--muted);
  white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* ---------- Etiquetas ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: .72rem; font-weight: 700;
  background: var(--surface-2); color: var(--muted);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

.stock-pill {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 5px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .8rem; font-weight: 600;
}
.stock-pill .qty { font-size: .98rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stock-pill .code { color: var(--muted); font-size: .7rem; font-weight: 700; letter-spacing: .04em; }
.stock-pill.is-low { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.stock-pill.is-zero { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

/* ---------- Listas ---------- */
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  text-align: left; padding: 11px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.item:active { background: var(--surface-2); }
.item .title { font-weight: 620; line-height: 1.25; }
.item .meta { color: var(--muted); font-size: .76rem; margin-top: 2px; }
.cell { min-width: 0; }
.item .right { margin-left: auto; display: grid; gap: 4px; justify-items: end; flex: 0 1 auto; min-width: 0; }
.chevron { color: var(--muted); flex: none; width: 18px; height: 18px; }

.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty svg { width: 42px; height: 42px; opacity: .5; margin-bottom: 8px; }

.timeline { display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.tl-item:last-child { border-bottom: 0; }
.tl-dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .7rem; font-weight: 800; }
.tl-dot svg { width: 14px; height: 14px; }
.tl-body { min-width: 0; }
.tl-who { color: var(--muted); font-size: .74rem; margin-top: 2px; }
.tl-diff {
  margin-top: 6px; padding: 7px 9px; border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: .74rem; display: grid; gap: 3px;
}
.tl-diff .k { color: var(--muted); }
.tl-diff del { color: var(--danger); text-decoration-thickness: 1px; }
.tl-diff ins { color: var(--ok); text-decoration: none; font-weight: 650; }

/* ---------- Hoja modal ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 10, 14, .5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px;
  max-height: 92dvh; overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--border);
  padding: 6px 14px calc(18px + var(--safe-b));
  animation: rise .2s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { transform: translateY(16px); } }
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 18px; max-height: 88dvh; }
}
.sheet-grip { width: 38px; height: 4px; border-radius: 4px; background: var(--border); margin: 6px auto 10px; }
.sheet h2 { margin: 0 0 2px; font-size: 1.05rem; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.sheet-actions { display: grid; gap: 8px; margin-top: 16px; }
@media (min-width: 420px) {
  .sheet-actions { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
}

/* ---------- Avisos ---------- */
.toasts {
  position: fixed; left: 12px; right: 12px; z-index: 80;
  bottom: calc(78px + var(--safe-b));
  display: grid; gap: 8px; pointer-events: none;
}
.toast {
  margin: 0 auto; max-width: 460px; width: fit-content;
  padding: 11px 15px; border-radius: 999px;
  background: #12161d; color: #f4f6fa;
  font-size: .87rem; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  animation: rise .18s ease;
}
.toast-ok { background: #0d6b41; }
.toast-error { background: #97231c; }

.alert {
  padding: 11px 13px; border-radius: var(--radius-sm);
  font-size: .86rem; margin-bottom: 12px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--brand-soft); color: var(--brand); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Acceso ---------- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-logo {
  width: 54px; height: 54px; border-radius: 15px; margin: 0 auto 14px;
  background: var(--brand); color: var(--brand-ink); display: grid; place-items: center;
}
.auth-logo svg { width: 28px; height: 28px; }

/* ---------- Pila de detalle ---------- */
.detail-head { display: grid; gap: 6px; margin-bottom: 4px; }
.detail-head .sku { color: var(--muted); font-size: .78rem; font-weight: 650; letter-spacing: .04em; }
.detail-head h2 { margin: 0; font-size: 1.18rem; line-height: 1.25; }

.inv-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 12px; background: var(--surface); }
.inv-block + .inv-block { margin-top: 8px; }
.inv-block .qty-big { font-size: 1.75rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.qty-actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; margin-top: 10px; }

.kv { display: grid; grid-template-columns: minmax(90px, 34%) minmax(0, 1fr); gap: 6px 10px; font-size: .87rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .input { text-align: center; font-size: 1.2rem; font-weight: 700; }
.stepper button {
  width: 48px; height: 48px; flex: none; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 1.3rem; font-weight: 700; display: grid; place-items: center;
}

.pager { display: flex; justify-content: center; margin-top: 12px; }
.skeleton { background: var(--surface-2); border-radius: var(--radius); height: 62px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   Escritorio: barra lateral, tablas y dos columnas.
   Nada de aqui aplica en celular; abajo de 1024px la interfaz
   sigue siendo exactamente la misma.
   ============================================================ */

/* El atributo hidden manda sobre el display del armazon. Sin esto, en escritorio
   la barra lateral seguia ocupando su alto en la pantalla de acceso y empujaba
   el formulario fuera de la vista. */
#app[hidden], #sidebar[hidden], #topbar[hidden], #tabbar[hidden] { display: none; }

.sidebar { display: none; }
.only-desk { display: none; }
.table-head { display: none; }
.cols-2 > * { min-width: 0; }

/* Tableta: se aprovecha el ancho sin cambiar la navegacion. */
@media (min-width: 700px) {
  .view { padding-left: 20px; padding-right: 20px; }
  .kv { grid-template-columns: minmax(120px, 26%) minmax(0, 1fr); }
  .inv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .inv-grid > .card { margin-bottom: 0; }
}

@media (min-width: 1024px) {
  :root { --tap: 40px; }

  .only-mobile { display: none !important; }
  .only-desk { display: revert; }
  span.only-desk { display: inline; }

  #app {
    display: grid;
    grid-template-columns: 252px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    min-height: 100dvh;
  }
  /* En la pantalla de acceso no hay armazon: el lienzo ocupa todo y centra la tarjeta. */
  #app.is-auth { display: block; }
  #app.is-auth .view { max-width: none; margin: 0; padding: 0; }

  /* ---- Barra lateral ---- */
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 2px;
    grid-column: 1;
    grid-row: 1 / -1;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    padding: 16px 12px 12px;
    background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
  .side-mark {
    width: 34px; height: 34px; flex: none; border-radius: 10px;
    background: var(--brand); color: var(--brand-ink);
    display: grid; place-items: center;
  }
  .side-mark svg { width: 19px; height: 19px; }
  .side-brand-name { display: block; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; }
  .side-brand-sub { display: block; font-size: .72rem; color: var(--muted); }

  .side-nav { display: grid; gap: 2px; }
  .side-link {
    display: flex; align-items: center; gap: 10px;
    width: 100%; text-align: left;
    padding: 9px 10px; border: 0; border-radius: 10px;
    background: none; color: var(--text);
    font-size: .9rem; font-weight: 600;
  }
  .side-link svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
  .side-link:hover { background: var(--surface-2); }
  .side-link[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
  .side-link[aria-current="page"] svg { color: var(--brand); }

  .side-sep {
    margin: 16px 10px 6px;
    font-size: .68rem; font-weight: 700; letter-spacing: .07em;
    text-transform: uppercase; color: var(--muted);
  }

  .side-scope { display: grid; gap: 2px; }
  .side-scope-item {
    display: grid; gap: 1px;
    text-align: left; padding: 7px 10px;
    border: 1px solid transparent; border-radius: 10px;
    background: none; color: var(--text);
    font-size: .84rem; font-weight: 600;
  }
  .side-scope-item:hover { background: var(--surface-2); }
  .side-scope-item[aria-pressed="true"] {
    background: var(--brand-soft); color: var(--brand); border-color: transparent;
  }
  .side-scope-item[aria-pressed="true"] .muted { color: inherit; opacity: .75; }

  .side-user {
    margin-top: auto; display: flex; align-items: center; gap: 8px;
    padding: 10px 6px 0; border-top: 1px solid var(--border);
  }

  /* ---- Cabecera y lienzo ---- */
  .topbar {
    grid-column: 2; grid-row: 1;
    padding: 16px 28px 14px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(10px);
  }
  .topbar h1 { font-size: 1.32rem; }
  .topbar .sub { font-size: .82rem; }
  .topbar-actions { gap: 8px; }

  .view {
    grid-column: 2; grid-row: 2;
    max-width: 1320px;
    margin: 0;
    padding: 22px 28px 56px;
  }
  .tabbar, .fab { display: none; }
  .toasts { bottom: 24px; left: auto; right: 24px; }

  /* ---- Dos columnas (a partir de 1200px, ver mas abajo) ---- */
  .cols-2 .section-title:first-child { margin-top: 0; }

  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .inv-grid { gap: 16px; }
  .kpi { padding: 14px 16px; }
  .kpi .value { font-size: 1.6rem; }

  /* ---- Listas con aire de tabla ---- */
  .list { gap: 6px; }
  .item {
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: none;
    transition: background .12s ease, border-color .12s ease;
  }
  .item:hover { background: var(--surface-2); border-color: var(--brand); }
  .item .meta { font-size: .78rem; }

  .table-head {
    display: grid;
    align-items: center;
    gap: 12px;
    padding: 0 14px 6px;
    font-size: .7rem; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; color: var(--muted);
  }
  .table-head .num, .row-product .num { text-align: right; }

  /* Renglon de producto: version compacta, se completa arriba de 1280px */
  .row-product, .head-product {
    grid-template-columns: minmax(0, 1fr) 190px 96px 18px;
  }
  .row-product { display: grid; align-items: center; }
  .row-product .cell-stock { margin-left: 0; justify-items: start; }
  .row-product .cell-stock .row { gap: 6px; }

  /* Renglon de usuario: idem */
  .row-user, .head-user {
    grid-template-columns: minmax(0, 1.2fr) 130px minmax(0, 1fr) 18px;
  }
  .row-user { display: grid; align-items: center; }
  .row-user .right { margin-left: 0; justify-items: start; }

  .col-sku, .col-cat, .col-price, .col-upd, .col-uname, .col-access { display: none; }

  /* ---- Linea de tiempo con fecha exacta ---- */
  .card .timeline { padding: 2px 0; }
  .tl-item { grid-template-columns: 26px minmax(0, 1fr) 160px; padding: 11px 0; }
  .tl-when { text-align: right; color: var(--muted); font-size: .74rem; line-height: 1.35; }
  .tl-item:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

  /* ---- Formularios y hojas ---- */
  .sheet { max-width: 620px; border-radius: 16px; }
  .sheet-grip { display: none; }
  .sheet-backdrop { align-items: center; }
  .search { max-width: 520px; }
  .stepper { max-width: 340px; }
  .stepper button { width: 44px; height: 44px; }
  .toolbar {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    margin-bottom: 14px;
  }
  .toolbar > .search { flex: 1 1 300px; margin: 0; }
  .toolbar > .chips { flex: 1 1 auto; margin-top: 0 !important; overflow: visible; }
  .toolbar > .row { flex: 0 0 auto; margin: 0 !important; }

  /* Los filtros extra no se esconden: hay lugar de sobra. */
  #extra-filters[hidden], #extra[hidden] { display: block; }
  #extra-filters .card, #extra .card { margin-bottom: 14px; padding: 10px 14px; }
  #extra-filters .card { display: inline-flex; align-items: flex-end; gap: 12px; }
  #extra-filters .filters-inline { justify-content: flex-start; }
  #extra-filters .field { flex: 0 1 260px; }
  #extra .card {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  }
  #extra .card > .row { flex: 0 0 auto; }
  #extra .card > .field { min-width: 190px; margin-top: 0 !important; }
  #extra .card > .btn { margin-top: 0 !important; }
  .filters-inline { display: flex; gap: 12px; align-items: flex-end; }
  .filters-inline .field { min-width: 170px; }

  .btn:active { transform: none; }
  .btn:hover { border-color: var(--brand); }
  .btn-primary:hover { filter: brightness(1.06); }
  .chip:hover { border-color: var(--brand); color: var(--brand); }
  .chip[aria-pressed="true"]:hover { color: var(--brand-ink); }
}

/* A partir de 1200px caben dos columnas de contenido. */
@media (min-width: 1200px) {
  .cols-2 {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    gap: 22px;
    align-items: start;
  }
  .detail-cols {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 22px;
    align-items: start;
  }
}

/* A partir de 1280px la tabla muestra todas sus columnas. */
@media (min-width: 1280px) {
  .col-sku, .col-cat, .col-price, .col-upd, .col-uname, .col-access { display: block; }
  .row-product, .head-product {
    grid-template-columns: 116px minmax(0, 1fr) 124px 186px 92px 100px 160px 18px;
  }
  .row-user, .head-user {
    grid-template-columns: minmax(0, 1.1fr) 150px 130px minmax(0, 1fr) 150px 18px;
  }
}

@media (min-width: 1560px) {
  .view { max-width: 1460px; }
  .row-product, .head-product {
    grid-template-columns: 130px minmax(0, 1fr) 150px 210px 110px 120px 200px 18px;
  }
}

/* ============================================================
   Caja: buscador, ticket en pantalla y comprobante impreso
   ============================================================ */

.pos { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.pos-main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; }
.pos-side { min-width: 0; }

.pos-results {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
}
.pos-result {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; text-align: left;
  background: var(--surface); color: var(--text);
  border: 0; border-bottom: 1px solid var(--border);
}
.pos-result:last-child { border-bottom: 0; }
.pos-result:hover, .pos-result:active { background: var(--surface-2); }

.pos-total {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--border);
  font-weight: 650;
}
.pos-total strong { font-size: 1.9rem; letter-spacing: -.02em; }

.pos-change {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-top: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); font-weight: 650;
}
.pos-change.is-on { background: var(--ok-soft); color: var(--ok); }
.pos-change strong { font-size: 1.35rem; }

.stepper-sm { gap: 4px; }
.stepper-sm button { width: 36px; height: 36px; border-radius: 9px; font-size: 1.1rem; }
.stepper-sm .input { min-height: 36px; padding: 4px 6px; font-size: 1rem; width: 62px; }

.row-cart { flex-wrap: wrap; }
.row-cart .cell.grow { flex: 1 1 100%; }
.row-cart .num { margin-left: auto; }
.row-cart.is-alert { border-color: var(--danger); background: var(--danger-soft); }

/* ---------- Ticket ---------- */
.ticket {
  max-width: 330px; margin: 0 auto;
  font-size: .82rem; line-height: 1.4;
}
.ticket-head { text-align: center; padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
.ticket-store { font-weight: 700; font-size: .96rem; }
.ticket-folio { font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.ticket-items { width: 100%; border-collapse: collapse; margin: 8px 0; }
.ticket-items td { padding: 4px 0; vertical-align: top; }
.ticket-items td:last-child { text-align: right; white-space: nowrap; padding-left: 8px; }
.ticket-totals { border-top: 1px dashed var(--border); padding-top: 8px; display: grid; gap: 3px; }
.ticket-total { font-size: 1.05rem; font-weight: 750; padding: 4px 0; }
.ticket-foot { text-align: center; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); font-size: .76rem; }

@media (min-width: 1024px) {
  .pos { grid-template-columns: minmax(0, 1fr) 350px; gap: 20px; align-items: start; }
  .pos-side { position: sticky; top: 96px; }
  /* En el panel de cobro los billetes se acomodan en varias lineas, no en un carrusel. */
  .pos-side .chips { flex-wrap: wrap; overflow: visible; }
  .pos-side .card { margin-bottom: 0; }

  .row-cart, .head-cart { grid-template-columns: minmax(0, 1fr) 96px 150px 110px 38px; }
  .row-cart { display: grid; align-items: center; flex-wrap: nowrap; }
  .row-cart .cell.grow { flex: initial; }
  .row-cart .num { margin-left: 0; }
  .head-cart .center { text-align: center; }

  .row-sale, .head-sale { grid-template-columns: minmax(0, 1.1fr) 74px minmax(0, 1.6fr) 110px 110px 18px; }
  .row-sale { display: grid; align-items: center; }
}

/* Comprobante impreso: solo se imprime el ticket. */
@media print {
  @page { margin: 8mm; }
  html, body { background: #fff !important; }
  body * { visibility: hidden !important; }
  .ticket, .ticket * { visibility: visible !important; }
  .sheet-backdrop {
    position: static !important; display: block !important;
    background: none !important; backdrop-filter: none !important;
  }
  .sheet {
    position: static !important; max-width: none !important; max-height: none !important;
    overflow: visible !important; box-shadow: none !important; border: 0 !important;
    padding: 0 !important; animation: none !important;
  }
  .sheet-head, .sheet-actions, .sheet-grip, .tabbar, .topbar, .sidebar, .fab, .toasts { display: none !important; }
  .ticket {
    position: absolute; left: 0; top: 0; width: 100%; max-width: none;
    color: #000; font-size: 11pt;
  }
  .ticket .muted, .ticket .tiny { color: #333 !important; }
}

/* ---------- Selector de tema (segmentado) ---------- */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  gap: 2px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px;
}
.seg-item {
  border: 0; border-radius: 8px; background: none; color: var(--muted);
  padding: 6px 4px; font-size: .76rem; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seg-item:hover { color: var(--text); }
.seg-item[aria-pressed="true"] { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }
.side-theme { margin-top: auto; }
.side-theme + .side-user { margin-top: 12px; }

/* ============================================================
   Grafica de flujo de ventas
   ============================================================ */

.chart-box { position: relative; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }

.ch-grid { stroke: var(--chart-grid); stroke-width: 1; }
.ch-base { stroke: var(--chart-grid); stroke-width: 1.5; }
.ch-axis { fill: var(--muted); font-size: 11px; font-weight: 600; }
.ch-value { fill: var(--text); font-size: 11px; font-weight: 700; }

.ch-bar { fill: var(--chart-bar); transition: fill .12s ease; }
.ch-bar-cero { fill: var(--chart-grid); }
.ch-hit { fill: transparent; }
.ch-col { cursor: pointer; outline: none; }
.ch-col:hover .ch-bar, .ch-col.is-on .ch-bar { fill: var(--chart-bar-hover); }
.ch-col:focus-visible .ch-hit { fill: color-mix(in srgb, var(--brand) 12%, transparent); }

.ch-tip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 132px; padding: 8px 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow);
}
.ch-tip-title { font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ch-tip-value { font-size: 1.05rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.ch-tip-meta { font-size: .74rem; color: var(--muted); }

.ch-table-wrap { max-height: 320px; overflow: auto; margin-top: 10px; }
.ch-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.ch-table th, .ch-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.ch-table th { position: sticky; top: 0; background: var(--surface); color: var(--muted);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.ch-table .num { text-align: right; }

.delta { display: inline-flex; align-items: center; gap: 4px; font-size: .76rem; font-weight: 700; }
.delta svg { width: 14px; height: 14px; }
.delta-up { color: var(--ok); }
.delta-down { color: var(--danger); }
.delta-flat { color: var(--muted); }

.periodo-fechas { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.periodo-fechas .field { min-width: 150px; }
