:root {
  --red: #c8102e;
  --red-strong: #a00c24;
  --red-soft: #fcecee;
  --red-line: #f1bcc4;
  --ink: #141414;
  --ink-2: #3b3b3b;
  --muted: #646464;
  --line: #e4e2e0;
  --line-strong: #c9c6c3;
  --bg: #f3f2f0;
  --card: #fff;
  --ok: #146c36;
  --ok-soft: #e8f5ec;
  --ok-line: #b6dcc2;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(20 20 20 / .05), 0 4px 14px rgb(20 20 20 / .04);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --tap: 44px;
  --zero: #8a8784;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
::selection { background: var(--red); color: #fff; }
input, textarea { caret-color: var(--red); }
main { max-width: 560px; margin: 0 auto; padding: 12px 16px calc(32px + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0 0 14px; line-height: 1.2; letter-spacing: -.01em; text-wrap: balance; }
h1 { font-size: 1.375rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; margin-top: 24px; }
a { color: var(--red-strong); text-underline-offset: 3px; }
strong, b { font-weight: 700; }
.accent { color: var(--red); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* barra superior */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--ink); color: #fff;
}
.brand { color: #fff; text-decoration: none; font-weight: 750; white-space: nowrap; display: flex; align-items: baseline; gap: 6px; }
.brand span { color: #ff6b7d; font-weight: 600; font-size: .9rem; }
.links { display: flex; align-items: center; gap: 2px; }
.links a, .linklike {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 8px;
  color: #d8d8d8; text-decoration: none; font: inherit; font-size: .95rem; background: none; border: 0; cursor: pointer;
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.links a:hover, .linklike:hover { color: #fff; background: #2a2a2a; }
.links a[aria-current] { color: #fff; background: #333; }
.links form { margin: 0; }

.card { background: var(--card); border-radius: var(--radius); padding: 20px 16px; margin: 12px 0; box-shadow: var(--shadow); }
.login { margin-top: 12vh; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.section-head h1, .section-head h2 { margin: 0; }
.hint { color: var(--muted); font-size: .875rem; font-weight: 400; margin: 6px 0 0; }

/* formularios */
label { display: block; font-weight: 600; margin: 0 0 16px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 12px; font: inherit; font-size: 16px; font-weight: 400;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; color: var(--ink);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
textarea { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 14px; }
input::placeholder, textarea::placeholder { color: #8a8784; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgb(20 20 20 / .12); }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
fieldset { border: 0; padding: 0; margin: 0 0 20px; min-width: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 8px; }
.pass { display: flex; gap: 8px; align-items: stretch; }
.pass input { margin: 0; }
.pass .mini { min-height: 48px; min-width: 64px; justify-content: center; }

/* botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
  min-height: 48px; padding: 10px 18px; border: 0; border-radius: var(--radius-sm);
  background: var(--red); color: #fff; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  transition: background-color .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--red-strong); }
.btn:active { transform: scale(.985); }
.btn:disabled { background: #d4d1ce; color: #6b6865; cursor: default; transform: none; }
.btn-big { width: 100%; min-height: 56px; font-size: 1.0625rem; }
.btn-copy { min-height: 44px; padding: 8px 16px; }
.btn-ghost { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.btn-ghost:hover { background: #f2f1ef; }
.btn-danger { background: #fff; color: var(--red-strong); box-shadow: inset 0 0 0 1.5px var(--red-strong); }
.btn-danger:hover { background: var(--red-soft); }
.btn.is-copied, .btn.is-copied:hover { background: var(--ok); }
.btn.is-busy { cursor: progress; }
.mini {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 6px 12px;
  border: 1.5px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink);
  font: inherit; font-size: .875rem; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: border-color .15s var(--ease), background-color .15s var(--ease);
}
.mini:hover { border-color: var(--ink); }
.mini .ic { width: 16px; height: 16px; }
.mini.is-copied { border-color: var(--ok); color: var(--ok); }

/* tribunas */
.tribs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.trib {
  position: relative; margin: 0; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: 84px; padding: 12px 4px;
  border: 2px solid var(--line-strong); border-radius: 12px; background: #fff;
  transition: border-color .15s var(--ease), background-color .15s var(--ease);
}
.trib:hover { border-color: var(--ink-2); }
.trib input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.trib-name { font-weight: 800; font-size: clamp(.82rem, 3.5vw, .98rem); letter-spacing: .02em; }
.trib-stock { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.trib-stock b { color: var(--ink); font-size: 1rem; }
.trib-sub { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.trib:has(input:checked) .trib-stock b { color: var(--red-strong); }
.trib:has(input:checked) { border-color: var(--red); background: var(--red-soft); }
.trib:has(input:checked) .trib-name { color: var(--red-strong); }
.trib:has(input:focus-visible) { outline: 3px solid var(--red); outline-offset: 2px; }
.trib.is-off { cursor: not-allowed; background: #f6f5f4; border-style: dashed; }
.trib.is-off .trib-name { color: var(--muted); }
.trib.is-off .trib-stock { color: var(--red-strong); font-weight: 700; }
.trib.is-off input { cursor: not-allowed; }

/* cantidad */
.qty { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; }
.qty input { margin: 0; text-align: center; font-size: 1.5rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.step {
  border: 1.5px solid var(--line-strong); background: #fff; border-radius: var(--radius-sm);
  font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--ink); touch-action: manipulation;
}
.step:hover { border-color: var(--ink); }
.step:active { background: #eceae8; }
.step:disabled { color: #b8b4b0; border-color: var(--line); cursor: default; }
.chips { display: flex; gap: 8px; margin-top: 10px; }
.chip {
  flex: 1; min-height: 44px; border: 1.5px solid var(--line-strong); border-radius: 999px; background: #fff;
  font: inherit; font-weight: 600; cursor: pointer; color: var(--ink); touch-action: manipulation;
  font-variant-numeric: tabular-nums; transition: background-color .15s var(--ease), color .15s var(--ease);
}
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }
.chip:disabled { color: #b8b4b0; border-color: var(--line); background: #fff; cursor: default; }

/* mensajes */
.alert, .flash { padding: 12px 14px; border-radius: var(--radius-sm); font-weight: 600; margin: 0 0 16px; }
.alert { background: var(--red-soft); color: var(--red-strong); border: 1px solid var(--red-line); }
.flash { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok-line); margin-top: 12px; }

/* resultado */
.result h1 { display: flex; align-items: center; gap: 8px; font-size: 1.5rem; margin-bottom: 4px; }
.result h1 .ic { width: 28px; height: 28px; color: var(--ok); stroke-width: 2.5; }
.result-meta { margin: 0 0 18px; color: var(--ink-2); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 20px; }

/* copiar */
.copy-block { margin: 8px 0 0; }
.copy-msg { margin: 6px 0 0; font-size: .875rem; font-weight: 600; color: var(--ok); }
.copy-msg:empty { display: none; }
.copy-msg.is-error { color: var(--red-strong); }
.fallback { margin-top: 8px; }
.codes { margin: 12px 0 0; padding-left: 1.7em; }
.codes li { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.codes li::marker { color: var(--muted); font-variant-numeric: tabular-nums; }
.codes code { font-size: .8rem; overflow-wrap: anywhere; color: var(--ink-2); min-width: 0; }
.codes .mini { min-height: var(--tap); }
details summary { cursor: pointer; color: var(--ink-2); font-size: .875rem; padding: 12px 0; min-height: var(--tap); }
details summary:hover { color: var(--ink); }

/* totales por tribuna */
.tally { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 12px 0 4px; }
.tally-cell { background: #fff; padding: 10px 6px; text-align: center; display: flex; flex-direction: column; gap: 1px; }
.tally-label { font-size: .7rem; font-weight: 700; letter-spacing: .04em; color: var(--muted); }
.tally-cell strong { font-size: 1.375rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tally-sub { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tally-cell.is-zero strong { color: var(--zero); font-weight: 500; }
.tally-total { background: var(--ink); }
.tally-total .tally-label, .tally-total .tally-sub { color: #c7c4c1; }
.tally-total strong { color: #fff; }

/* navegación por días */
.day-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.day-form { margin: 0; }
.day-form input { margin: 0; padding: 8px 10px; width: auto; min-height: var(--tap); font-variant-numeric: tabular-nums; }
.day-label { font-weight: 600; margin-right: 4px; }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); border-radius: 8px;
  border: 1.5px solid var(--line-strong); color: var(--ink); background: #fff;
}
.icon-btn:hover { border-color: var(--ink); }
.icon-btn.is-off { color: #c3bfbb; border-color: var(--line); }

/* entregas */
.entregas { list-style: none; padding: 0; margin: 8px 0 0; }
.entrega { border-top: 1px solid var(--line); padding: 14px 0 10px; }
.entrega:first-child { border-top: 0; }
.entrega-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.entrega-head a { color: var(--ink); text-decoration: none; }
.entrega-head a:hover { text-decoration: underline; }
time { color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); padding: 14px 0 4px; }

/* panel: sub-navegación */
.subnav { display: flex; gap: 6px; overflow-x: auto; padding: 4px 16px; margin: 4px -16px 0; scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
  flex: none; padding: 8px 14px; min-height: var(--tap); display: inline-flex; align-items: center;
  border-radius: 999px; background: #fff; color: var(--ink); text-decoration: none; font-size: .875rem; font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.subnav a:hover { box-shadow: inset 0 0 0 1.5px var(--ink); }

/* tablas */
.table-wrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .9375rem; }
th, td { padding: 10px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.nums td { text-align: right; font-variant-numeric: tabular-nums; }
table.nums thead th:not(:first-child) { text-align: right; }
thead th { font-size: .8rem; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
tbody th { font-weight: 600; }
td.is-zero { color: var(--zero); }
td.col-total { font-weight: 750; }
.cell-sub { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; }
abbr { text-decoration: none; }
.short { display: none; }
@media (max-width: 420px) { .long { display: none; } .short { display: inline; } }
.detalle { margin-top: 10px; }

/* stock */
.stock { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.stock-head { display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; }
.stock-head span { color: var(--ink-2); }
.bar { display: block; height: 8px; margin: 6px 0 4px; border-radius: 4px; overflow: hidden; }
.bar svg { display: block; width: 100%; height: 8px; }
.bar-bg { fill: #ebe9e7; }
.bar-fill { fill: var(--ink); }
.stock-row.is-low .bar-fill { fill: var(--red); }
.stock-row.is-low .stock-head span, .stock-row.is-out .stock-head span, .stock-row.is-low .stock-sub b, .stock-row.is-out .stock-sub b { color: var(--red-strong); }
.stock-sub { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* topes */
.topes-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; margin-top: 14px; }
.topes-form label { margin-bottom: 14px; }
.topes-form input { font-variant-numeric: tabular-nums; }
.topes-form .btn { grid-column: 1 / -1; }
@media (max-width: 520px) { .topes-form { grid-template-columns: 1fr; } }

/* usuarios */
.users { list-style: none; margin: 0; padding: 0; }
.user-row { padding: 10px 0 2px; border-bottom: 1px solid var(--line); }
.user-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.user-head form { margin: 0; }
.user-pass summary { padding: 8px 0; }
.text-danger { min-height: var(--tap); padding: 0 4px; border: 0; background: none; color: var(--red-strong); font: inherit; font-size: .875rem; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.user-row.is-inactive .user-id strong { color: var(--muted); text-decoration: line-through; }
.user-pass .inline { display: flex; gap: 6px; margin-bottom: 4px; }
.user-pass .inline input { margin: 0; flex: 1; min-width: 0; padding: 8px 10px; min-height: var(--tap); }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-form .btn { grid-column: 1 / -1; }
.danger-zone { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 4px; }

@media (min-width: 760px) {
  main { max-width: 720px; }
  .card { padding: 24px; }
}
@media (max-width: 380px) {
  .grid-form { grid-template-columns: 1fr; }
  .brand span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* leyenda con label dentro: sin margen extra */
.qty-field legend label { margin: 0; }

/* aviso cuando no se puede pedir */
.notice { margin: 0; padding: 14px; border-radius: var(--radius-sm); background: #f6f5f4; border: 1px dashed var(--line-strong); color: var(--ink-2); font-weight: 600; }

/* historial compacto: una fila por pedido */
.entrega { padding: 6px 0; }
.entrega-row { display: flex; align-items: center; gap: 10px; }
.entrega-info { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 6px 0; color: var(--ink); text-decoration: none; }
.entrega-info:hover .entrega-what { text-decoration: underline; }
.entrega-what { font-size: 1rem; font-variant-numeric: tabular-nums; }
.entrega-what strong { font-size: 1.125rem; }
.entrega-when { display: flex; gap: 8px; flex-wrap: wrap; }
.copied-at { color: var(--ok); font-size: .8rem; font-weight: 600; }
.copied-at:empty { display: none; }
.result-meta .copied-at { margin-left: 8px; }
.btn-row {
  display: inline-flex; align-items: center; gap: 6px; flex: none; min-height: var(--tap); padding: 0 14px;
  border: 1.5px solid var(--ink); border-radius: var(--radius-sm); background: #fff; color: var(--ink);
  font: inherit; font-weight: 700; font-size: .9375rem; cursor: pointer; touch-action: manipulation;
  transition: background-color .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.btn-row:hover { background: #f2f1ef; }
.btn-row.is-copied { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.btn-row .ic { width: 18px; height: 18px; }
.btn-share { width: 100%; margin-top: 8px; }
.stack-form .btn { width: auto; }

table.nums td.empty { text-align: left; }
