/* Cestea · diseño D «ticket con pegatinas» */
:root {
  --ground: #E8E4DC;
  --paper: #FFFDF7;
  --ink: #1A1A1A;
  --muted: #5E5A52;
  --line: #C4BEB2;
  --coral: #FF6B4A;
  --coral-soft: #FF9B7A;
  --yellow: #FFD95A;
  --green: #8FE3A8;
  --blue: #9AD8FF;
  --pink: #F6B3D0;
  --danger: #B3261E;
  --radius: 20px;
  --font: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Fredoka', 'Outfit', system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.35; font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- estructura ---------- */
.app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 108px); display: flex; flex-direction: column; gap: 14px; }
#main { display: flex; flex-direction: column; gap: 14px; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 44px; }
.brand { font-family: var(--display); font-weight: 700; font-size: 28px; letter-spacing: -0.3px; }
.brand i { font-style: normal; color: var(--coral); }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; }
h2 { font-size: 20px; }
.sechead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.note { font-size: 13px; color: var(--muted); margin: 8px 2px; }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; }

/* ---------- botones ---------- */
.btn { min-height: 44px; padding: 0 16px; border-radius: 22px; border: 2px solid var(--ink); background: var(--ink); color: #fff; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.sec { background: transparent; color: var(--ink); }
.btn.yellow { background: var(--yellow); color: var(--ink); }
.btn.coral { background: var(--coral); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 18px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btns > .btn { flex: 1 1 140px; }
.link { background: none; border: 0; padding: 6px 2px; min-height: 36px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; color: var(--ink); }
.iconbtn { width: 44px; height: 44px; border-radius: 22px; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.iconbtn svg { width: 22px; height: 22px; }

/* ---------- el ticket de papel ---------- */
.ticket { position: relative; }
.paper { background: var(--paper); padding: 14px 16px 10px; display: flex; flex-direction: column; gap: 10px; }
.zig { height: 10px; background: linear-gradient(-45deg, transparent 8px, var(--paper) 0), linear-gradient(45deg, transparent 8px, var(--paper) 0); background-size: 16px 16px; background-repeat: repeat-x; background-position: left bottom; }
.paper-head { text-align: center; }
.paper-head h1 { font-size: 19px; }
.dash { border: 0; border-top: 1.5px dashed var(--line); margin: 0; }
.corner { position: absolute; right: -6px; top: -10px; transform: rotate(9deg); background: var(--blue); border: 2px solid var(--ink); border-radius: 12px; padding: 3px 10px; font-family: var(--display); font-weight: 600; font-size: 13px; z-index: 1; }

/* ---------- pegatinas ---------- */
.stk { display: inline-block; border: 1.5px solid var(--ink); border-radius: 9px; padding: 0 7px; font-family: var(--display); font-weight: 600; font-size: 11.5px; line-height: 18px; color: var(--ink); white-space: nowrap; transform: rotate(-3deg); }
.stk:nth-of-type(even) { transform: rotate(3deg); }
.stk.real { background: var(--green); }
.stk.buen { background: var(--yellow); }
.stk.ultra { background: var(--coral-soft); }
.stk.nocomida { background: #E4E0D8; }
.stk.black { background: var(--ink); color: #fff; border-color: var(--ink); }
.stk.fav { background: var(--pink); }
.stk.try { background: var(--blue); }
.stk.big { font-size: 14px; line-height: 24px; padding: 0 10px; border-width: 2px; border-radius: 12px; }
.total-stk { background: var(--coral); border: 2px solid var(--ink); border-radius: 14px; padding: 2px 12px; font-size: 22px; font-weight: 700; transform: rotate(-2deg); white-space: nowrap; }

/* ---------- filas ---------- */
.rows { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.row.tap { background: none; border: 0; padding: 0; text-align: left; width: 100%; }
.row .grow { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
.row .sub { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.row .price { font-weight: 600; font-size: 15px; white-space: nowrap; }
.row.off .name { color: #6E695F; text-decoration: line-through; }
.check { width: 28px; height: 28px; border-radius: 9px; border: 2.5px solid var(--ink); background: #fff; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.check.on { background: var(--green); }
.check svg { width: 16px; height: 16px; }
.checkhit { width: 44px; height: 44px; margin: -8px -8px -8px -8px; display: inline-flex; align-items: center; justify-content: center; background: none; border: 0; padding: 0; flex-shrink: 0; }

/* miniatura del producto */
.thumb { width: 44px; height: 44px; border-radius: 10px; border: 1.5px solid var(--ink); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden; background: #fff; }
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumb svg { width: 24px; height: 24px; }
.thumb.lg { width: 112px; height: 112px; border-radius: 18px; border-width: 2px; }
.thumb.lg svg { width: 56px; height: 56px; }
.row.off .thumb { border-color: #8C877C; opacity: .7; }

/* ---------- formularios ---------- */
.addrow { display: flex; gap: 8px; }
.input { width: 100%; min-height: 44px; border: 2px solid var(--ink); border-radius: 14px; background: #fff; padding: 8px 12px; font-size: 16px; }
textarea.input { min-height: 140px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label, .lbl { font-weight: 600; font-size: 14px; }
.err { color: var(--danger); font-weight: 600; margin: 6px 2px; }
.ok-msg { color: #1E6B3A; font-weight: 600; margin: 6px 2px; }
.warn { background: #FFF2C2; border: 2px solid var(--ink); border-radius: 14px; padding: 10px 12px; font-size: 14px; }

/* ---------- tarjetas de tickets ---------- */
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tcard { border: 0; border-radius: 20px; padding: 11px 14px; text-align: left; display: flex; flex-direction: column; gap: 0; min-height: 84px; color: var(--ink); }
.tcard b { font-size: 21px; font-weight: 700; }
.tcard span { font-size: 12.5px; font-weight: 600; }
.tcard small { font-size: 12px; font-weight: 500; }
.tlist { display: flex; flex-direction: column; gap: 10px; }
.tline { display: flex; align-items: center; gap: 12px; background: var(--paper); border-radius: 18px; padding: 12px 14px; border: 0; text-align: left; width: 100%; min-height: 64px; }
.tline .dot { width: 14px; height: 40px; border-radius: 7px; border: 1.5px solid var(--ink); flex-shrink: 0; }
.tline .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tline b { font-size: 18px; white-space: nowrap; }
.linked { font-size: 12px; font-weight: 600; color: #1E6B3A; }

/* ---------- productos ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 18px; border: 2px solid var(--ink); background: var(--paper); font-weight: 600; font-size: 14px; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; }
.card { background: var(--paper); border-radius: var(--radius); padding: 14px 16px; }
.plist .row { border-bottom: 1.5px dashed var(--line); padding-bottom: 10px; }
.plist .row:last-child { border-bottom: 0; padding-bottom: 0; }
.score { display: inline-flex; align-items: center; justify-content: center; width: 58px; height: 58px; border-radius: 29px; border: 2.5px solid var(--ink); font-family: var(--display); font-weight: 700; font-size: 22px; flex-shrink: 0; }
.score.s0 { background: #FF9B7A; } .score.s1 { background: #FFC48A; } .score.s2 { background: var(--yellow); } .score.s3 { background: var(--green); } .score.sn { background: #E4E0D8; font-size: 15px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.fact { background: #fff; border: 1.5px solid var(--ink); border-radius: 14px; padding: 8px 10px; font-size: 13px; }
.fact b { display: block; font-size: 16px; }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.seg button { min-height: 44px; border-radius: 14px; border: 2px solid var(--ink); background: #fff; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg button.no[aria-pressed="true"] { background: var(--ink); }
.hist { width: 100%; border-collapse: collapse; font-size: 14px; }
.hist td { padding: 7px 0; border-bottom: 1px dashed var(--line); }
.hist td.r { text-align: right; font-weight: 600; }
.adds { display: flex; flex-wrap: wrap; gap: 6px; }
.adds span { border: 1.5px solid var(--ink); border-radius: 8px; padding: 1px 7px; font-size: 12.5px; background: #fff; }
.adds span.risk { background: var(--coral-soft); font-weight: 600; }

/* ---------- barra de abajo ---------- */
.navwrap { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(env(safe-area-inset-bottom) + 12px); pointer-events: none; z-index: 20; }
.nav { pointer-events: auto; max-width: 420px; margin: 0 auto; height: 62px; border-radius: 31px; background: var(--ink); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; padding: 0 6px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.nav button { justify-self: center; width: 48px; height: 48px; border-radius: 24px; border: 0; background: transparent; color: #fff; display: flex; align-items: center; justify-content: center; position: relative; }
.nav button svg { width: 22px; height: 22px; }
.nav button[aria-current="page"] { background: var(--paper); color: var(--ink); }
.nav button.plus { background: var(--coral); color: var(--ink); width: 50px; height: 50px; border-radius: 25px; }
.nav button.plus svg { width: 26px; height: 26px; }
.nav .badge { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--yellow); color: var(--ink); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 4px; }

/* ---------- hoja (ventana desde abajo) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(26,26,26,.38); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--ground); border-radius: 26px 26px 0 0; padding: 14px 16px calc(env(safe-area-inset-bottom) + 20px); outline: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; position: sticky; top: -14px; background: var(--ground); padding: 10px 0 6px; z-index: 2; }
.sheet-head h2 { font-size: 21px; }
@media (min-width: 700px) { .scrim { align-items: center; } .sheet { border-radius: 26px; max-height: 86vh; } }

/* ---------- avisos ---------- */
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); transform: translateX(-50%); z-index: 60; background: var(--ink); color: #fff; border-radius: 18px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25); font-weight: 500; }
.toast.up { bottom: auto; top: calc(env(safe-area-inset-top) + 12px); }
.toast button { background: var(--yellow); color: var(--ink); border: 0; border-radius: 12px; min-height: 34px; padding: 0 10px; font-weight: 700; }
.syncline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin: 0; }
.led { width: 9px; height: 9px; border-radius: 5px; background: #9A958C; display: inline-block; }
.led.ok { background: #2E9E5B; } .led.busy { background: #E0A100; } .led.err { background: var(--danger); }
.progress { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.spin { width: 14px; height: 14px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } .stk, .total-stk, .corner { transform: none; } }

/* ---------- bienvenida ---------- */
.welcome { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.welcome-box { width: 100%; max-width: 400px; }
.welcome-box .paper { padding: 22px 20px 14px; }
.welcome-box h1 { font-size: 40px; font-weight: 700; text-align: center; }
.welcome-box .lead { text-align: center; margin: 0 0 8px; color: var(--muted); }
.or { text-align: center; color: var(--muted); margin: 10px 0; }

/* ---------- vista previa de un ticket ---------- */
.prev .row { min-height: 40px; }
.code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; background: #fff; border: 1.5px solid var(--ink); border-radius: 10px; padding: 8px 10px; word-break: break-all; user-select: all; }
ol.steps { padding-left: 20px; margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.scan video { width: 100%; border-radius: 16px; border: 2px solid var(--ink); background: #000; }
