/* Layout: programa de gestión — barra de aplicación oscura fija, banda de indicadores, libro de existencias con barras de nivel y diario de movimientos agrupado por día */
:root {
  --bg: #eef1f0;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --fg: #141c19;
  --muted: #5a6964;
  --line: #dbe2df;
  --line-strong: #c4cec9;
  --bar: #12201b;
  --bar-fg: #eaf2ee;
  --bar-muted: #93a8a0;
  --accent: #0b6e4f;
  --accent-hover: #095c42;
  --accent-fg: #ffffff;
  --accent-soft: #e0f0e9;
  --in: #0b7a55;
  --in-soft: #e0f0e9;
  --out: #b4441f;
  --out-soft: #fbe6de;
  --warn: #a86400;
  --warn-soft: #fcefd4;
  --warn-fg: #6e4300;
  --bad-fg: #962c0c;
  --ok-fg: #0b5a41;
  --track: #e6ebe9;
  --shadow: 0 1px 2px rgb(16 32 26 / 0.06), 0 2px 8px rgb(16 32 26 / 0.04);
  --font-display: "Familjen Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412; --surface: #161e1b; --surface-2: #1a2420; --fg: #e5ece9; --muted: #95a49e; --line: #26312d; --line-strong: #34413c;
    --bar: #0a0f0d; --bar-fg: #e5ece9; --bar-muted: #7f938b;
    --accent: #3fbf8f; --accent-hover: #5ccfa2; --accent-fg: #05130e; --accent-soft: #153026;
    --in: #4fd09f; --in-soft: #153026; --out: #f08a62; --out-soft: #3a1c12;
    --warn: #f0b44c; --warn-soft: #36290c; --warn-fg: #f3c86b; --bad-fg: #ff9f7c; --ok-fg: #6fdcb1;
    --track: #24302b; --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bar); }
[hidden] { display: none !important; }
.gutter { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.inner { max-width: 1220px; margin: 0 auto; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* App bar */
.appbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 9; background: var(--bar); color: var(--bar-fg); }
.appbar .inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; flex-wrap: wrap; padding-block: 8px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; flex: none; }
.mark svg.i { width: 20px; height: 20px; }
.mark.logo { background: #ffffff; padding: 2px; overflow: hidden; width: 42px; height: 42px; }
.mark.logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card .mark.logo { width: 56px; height: 56px; }
.brand h1 { font-size: 1.15rem; font-weight: 600; letter-spacing: -0.005em; }
.live { display: flex; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--bar-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--bar-muted); }
.live.on i { background: #4fd09f; box-shadow: 0 0 0 3px rgb(79 208 159 / 0.2); }
.bar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.who { font-size: 0.8rem; color: var(--bar-muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--fg); padding: 8px 14px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; }
button:hover { border-color: var(--muted); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ghost-bar { background: transparent; color: var(--bar-fg); border-color: rgb(255 255 255 / 0.18); }
button.ghost-bar:hover { border-color: rgb(255 255 255 / 0.4); }
button.danger { color: var(--out); }
button.link { border: 0; background: none; min-height: 32px; padding: 4px 6px; color: var(--accent); font-size: 0.88rem; }
button.link:hover { text-decoration: underline; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

main.gutter { padding-block: 22px 56px; }
main .inner { display: grid; gap: 18px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: grid; gap: 6px; box-shadow: var(--shadow); min-width: 0; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); }
.kpi .label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }
.kpi .value { font-family: var(--font-mono); font-size: 1.6rem; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi .sub { font-size: 0.8rem; color: var(--muted); }
.kpi.alert .value, .kpi.alert .kpi-top { color: var(--out); }

.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--warn-soft); color: var(--warn-fg); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: 10px; padding: 10px 14px; }
.banner p { margin: 0; flex: 1; min-width: 200px; }
.banner button { background: transparent; color: var(--warn-fg); border-color: color-mix(in srgb, var(--warn) 50%, transparent); min-height: 34px; padding: 6px 12px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 18px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; min-width: 0; box-shadow: var(--shadow); }
.panel-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 1.05rem; font-weight: 600; }
.panel-head .count { font-family: var(--font-mono); font-size: 0.8rem; color: var(--muted); margin-left: 6px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.search { position: relative; flex: 1 1 220px; min-width: 0; }
.search svg.i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
input, select { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; min-height: 38px; }
.search input { width: 100%; padding-left: 34px; }
.chips { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.chips button { border: 0; border-radius: 0; min-height: 36px; padding: 6px 12px; font-size: 0.88rem; color: var(--muted); background: transparent; }
.chips button + button { border-left: 1px solid var(--line); }
.chips button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chips .n { font-family: var(--font-mono); font-size: 0.78rem; opacity: 0.85; }
#sort { font-size: 0.88rem; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover td { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
th.r, td.r { text-align: right; }
.pname { font-weight: 600; overflow-wrap: anywhere; }
#rows td:first-child { min-width: 200px; }
.psub { font-size: 0.78rem; color: var(--muted); font-family: var(--font-mono); }
.tag { display: inline-block; font-size: 0.78rem; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.stockcell { display: grid; gap: 5px; justify-items: end; min-width: 96px; }
.stock { font-family: var(--font-mono); font-size: 1.1rem; font-weight: 500; font-variant-numeric: tabular-nums; border-radius: 4px; padding: 0 4px; }
.level { width: 88px; height: 5px; border-radius: 99px; background: var(--track); overflow: hidden; }
.level span { display: block; height: 100%; border-radius: 99px; }
.level.ok span { background: var(--in); }
.level.low span { background: var(--warn); }
.level.zero span { background: var(--out); }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 0.74rem; font-weight: 600; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--in-soft); color: var(--ok-fg); }
.pill.low { background: var(--warn-soft); color: var(--warn-fg); }
.pill.zero { background: var(--out-soft); color: var(--bad-fg); }
.minline { font-size: 0.76rem; color: var(--muted); margin-top: 3px; }
.rowbtns { display: flex; gap: 6px; justify-content: flex-end; }
.ib { width: 38px; height: 38px; padding: 0; min-height: 0; }
.ib.in { color: var(--in); }
.ib.in:hover { background: var(--in-soft); border-color: var(--in); }
.ib.out { color: var(--out); }
.ib.out:hover { background: var(--out-soft); border-color: var(--out); }
.ib.edit { color: var(--muted); border-color: transparent; background: transparent; }
.ib.edit:hover { color: var(--fg); border-color: var(--line-strong); }
.show-sm { display: none; }

.empty { padding: 48px 20px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.empty .mark { width: 44px; height: 44px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.empty h3 { font-size: 1.1rem; }
.empty p { margin: 0; max-width: 46ch; }

.log { list-style: none; margin: 0; padding: 0 0 6px; max-height: 680px; overflow-y: auto; }
.day { position: sticky; top: 0; background: var(--surface-2); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; color: var(--muted); padding: 7px 16px; border-bottom: 1px solid var(--line); }
.mov { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.mov:last-child { border-bottom: 0; }
.dir { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; }
.dir svg.i { width: 15px; height: 15px; stroke-width: 2.2; }
.dir.in { background: var(--in-soft); color: var(--in); }
.dir.out { background: var(--out-soft); color: var(--out); }
.mov .what { min-width: 0; }
.mov .pn { font-weight: 500; overflow-wrap: anywhere; font-size: 0.92rem; }
.mov .meta { font-size: 0.78rem; color: var(--muted); overflow-wrap: anywhere; }
.mov .qty { text-align: right; display: grid; gap: 1px; }
.mov .q { font-family: var(--font-mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.mov .q.in { color: var(--in); }
.mov .q.out { color: var(--out); }
.mov .after { font-family: var(--font-mono); font-size: 0.74rem; color: var(--muted); }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--fg); padding: 0; width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgb(0 0 0 / 0.25); }
dialog::backdrop { background: rgb(8 16 13 / 0.5); }
dialog form, .card form { display: grid; gap: 16px; padding: 20px; }
.dlg-head { display: grid; gap: 2px; }
.dlg-head h2 { font-size: 1.2rem; font-weight: 600; overflow-wrap: anywhere; }
.dlg-head .sub { font-size: 0.85rem; color: var(--muted); }
.field { display: grid; gap: 5px; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.field input { width: 100%; }
.hint { font-size: 0.76rem; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg { position: relative; }
.seg input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.seg label { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg label + input + label { border-left: 1px solid var(--line); }
.seg input:checked + label.in { background: var(--in-soft); color: var(--in); }
.seg input:checked + label.out { background: var(--out-soft); color: var(--out); }
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }
.qtyrow input { width: 100%; font-family: var(--font-mono); font-size: 1.1rem; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { min-height: 32px; padding: 4px 10px; font-family: var(--font-mono); font-size: 0.85rem; color: var(--muted); }
.preview { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.preview div { display: grid; gap: 1px; }
.preview .lbl { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 600; }
.preview .v { font-family: var(--font-mono); font-size: 1.25rem; font-weight: 500; }
.preview .arrow { color: var(--muted); }
.preview div:last-child { text-align: right; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-top: 4px; }
.dlg-foot .spacer { flex: 1; }
.err { color: var(--out); font-size: 0.85rem; margin: 0; }
.confirm-del { background: var(--out-soft); color: var(--bad-fg); padding: 12px; border-radius: 8px; font-size: 0.9rem; display: grid; gap: 8px; }

/* Ventas */
.ventas-body { display: grid; grid-template-columns: 230px minmax(0, 1fr) 280px; }
.ventas-body > * { min-width: 0; padding: 14px 16px; }
.ventas-body > * + * { border-left: 1px solid var(--line); }
.vstats { display: grid; gap: 14px; align-content: start; }
.vstat { display: grid; gap: 2px; }
.vstat .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; color: var(--muted); }
.vstat .value { font-family: var(--font-mono); font-size: 1.35rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.vstat .sub { font-size: 0.8rem; color: var(--muted); }
.trend.up { color: var(--in); font-weight: 600; }
.trend.down { color: var(--out); font-weight: 600; }
.vtitle { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.vchart-svg svg { display: block; width: 100%; height: auto; }
.vchart-svg text { font-family: var(--font-mono); font-size: 11px; fill: var(--muted); }
.vchart-svg .val { fill: var(--fg); font-size: 10.5px; }
.vchart-svg .bar { fill: var(--accent); opacity: 0.45; }
.vchart-svg .bar.now { opacity: 1; }
.vchart-svg .base { stroke: var(--line-strong); }
.vchart-svg .grid { stroke: var(--line); stroke-dasharray: 3 4; }
.vtop ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.vtop li { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 8px; align-items: baseline; font-size: 0.9rem; }
.vtop .rk { font-family: var(--font-mono); color: var(--muted); font-size: 0.8rem; }
.vtop .nm { overflow-wrap: anywhere; }
.vtop .am { font-family: var(--font-mono); text-align: right; white-space: nowrap; }
.vtop .am small { display: block; color: var(--muted); font-size: 0.75rem; }
.seg-sm label { padding: 8px; font-size: 0.85rem; }
.mov .meta .sale { color: var(--in); font-weight: 600; }
.mov .undo { min-height: 0; padding: 0; font-size: 0.74rem; color: var(--muted); justify-self: end; }
.mov .undo:hover { color: var(--out); }
.mov.void .pn { text-decoration: line-through; color: var(--muted); }
.mov.void .q { color: var(--muted); }
.mov.void .meta .sale { color: var(--muted); }
.mov.void .dir { opacity: 0.45; }
.mov .voided { color: var(--out); font-weight: 600; }
@media (max-width: 1180px) {
  .ventas-body { grid-template-columns: 220px minmax(0, 1fr); }
  .vtop { grid-column: 1 / -1; border-left: 0 !important; border-top: 1px solid var(--line); }
}
@media (max-width: 700px) {
  .ventas-body { grid-template-columns: minmax(0, 1fr); }
  .ventas-body > * + * { border-left: 0; border-top: 1px solid var(--line); }
  .vstats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .vstat .value { font-size: 1.05rem; }
}
@media (max-width: 460px) {
  .vstats { grid-template-columns: minmax(0, 1fr); }
  .vstat .value { font-size: 1.25rem; }
}

/* Escáner */
.seg3 { grid-template-columns: repeat(3, 1fr); }
.seg3 label + input + label { border-left: 1px solid var(--line); }
.seg3 input:checked + label[for="scVer"] { background: var(--accent-soft); color: var(--accent); }
.qtyrow { display: flex; gap: 8px; align-items: stretch; }
.qtyrow input { flex: 1; min-width: 0; }
.video-box { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 48vh; border-radius: 10px; overflow: hidden; background: #000; }
.video-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-line { position: absolute; left: 10%; right: 10%; top: 50%; height: 2px; background: #ff4d4d; box-shadow: 0 0 10px #ff4d4d; }
.video-box.off .scan-line { display: none; }
.video-box.off::after { content: "Cámara apagada"; position: absolute; inset: 0; display: grid; place-items: center; color: #9aa; font-size: 0.9rem; }
@media (prefers-reduced-motion: no-preference) {
  .scan-line { animation: scan 1.6s ease-in-out infinite alternate; }
  @keyframes scan { from { top: 25%; } to { top: 75%; } }
}

/* Copias de seguridad */
.backup { display: grid; gap: 10px; padding-top: 16px; margin-top: 4px; border-top: 1px solid var(--line); }
.backup .dlg-head h2 { font-size: 1.05rem; }

/* Excel */
.xstatus { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: 0.9rem; overflow-wrap: anywhere; }
.xstatus b { font-family: var(--font-mono); font-weight: 500; }
.xstatus.warn { background: var(--warn-soft); color: var(--warn-fg); border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.xdot { width: 7px; height: 7px; border-radius: 50%; background: #f0b44c; }

/* Login / setup */
.screen { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding-block: 32px; }
.card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.card .brand { padding: 20px 20px 0; }
.card .brand h1 { font-size: 1.25rem; }
.card button.primary { width: 100%; min-height: 44px; }
.card code { font-family: var(--font-mono); font-size: 0.85em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; overflow-wrap: anywhere; }
.card ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--bar); color: var(--bar-fg); padding: 10px 16px; border-radius: 8px; font-size: 0.9rem; z-index: 20; max-width: calc(100vw - 32px); display: flex; gap: 8px; align-items: center; box-shadow: 0 8px 24px rgb(0 0 0 / 0.25); }
.toast svg.i { color: #4fd09f; }
.toast.bad svg.i { color: var(--out); }

@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .hide-sm { display: none; }
  .show-sm { display: block; }
  td, th { padding: 10px 8px; }
  td:first-child, th:first-child { padding-left: 14px; }
  #rows td:first-child { min-width: 0; }
  .grid2 { grid-template-columns: 1fr; }
  .chips { width: 100%; }
  .chips button { flex: 1; }
  #sort { width: 100%; }
  .lbl-long, .who { display: none; }
  .level { width: 64px; }
  .stockcell { min-width: 64px; }
  .kpi .value { font-size: 1.3rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .stock.flash { animation: flash 1s ease-out; }
  @keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
  .level span { transition: width 0.4s ease; }
}
