/* Mini App. Un solo aspecto, deliberado: atardecer marciano.
   Estructura: cabecera con paisaje, tres pestañas (Almacén, Mercado, Registro) y barra inferior. */
/* Fuentes servidas desde el propio dominio (subconjunto latin, licencia OFL en fonts/). */
@font-face { font-family: "Saira Stencil One"; font-weight: 400; font-display: swap; src: url("fonts/saira-stencil-one-400.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 400; font-display: swap; src: url("fonts/atkinson-hyperlegible-400.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 700; font-display: swap; src: url("fonts/atkinson-hyperlegible-700.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-display: swap; src: url("fonts/ibm-plex-mono-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-display: swap; src: url("fonts/ibm-plex-mono-500.woff2") format("woff2"); }
:root {
  color-scheme: dark;
  --bg: #150f13;
  --panel: #211820;
  --panel-2: #2b2029;
  --line: #3e2e37;
  --fg: #f2e5d7;
  --muted: #b39e90;
  --accent: #e38a4e;
  --accent-ink: #1c120d;
  --ice: #9fd8e8;
  --ok: #9cc77a;
  --warn: #e8b65c;
  --bad: #e57462;
  --font-display: "Saira Stencil One", Impact, "Arial Narrow", sans-serif;
  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); }
body { font-family: var(--font-body); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { position: relative; display: flex; flex-direction: column; height: 100%; max-width: 520px; margin-inline: auto; background: var(--panel); overflow: hidden; }
@media (min-width: 700px) {
  body.demo { padding-block: 24px; }
  body.demo .app { height: min(860px, 100%); border: 1px solid var(--line); border-radius: 28px; box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .7); max-width: 420px; }
}

.demo-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.demo-bar b { color: var(--fg); }
.demo-btn { border: 1px solid var(--accent); background: transparent; color: var(--accent); font-family: var(--font-mono); font-size: 11px; padding: 5px 10px; border-radius: 999px; white-space: nowrap; }
.demo-btn:disabled { opacity: .5; cursor: default; }

/* cabecera */
.hero { position: relative; height: 172px; flex: none; }
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hero .over { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; padding: 12px 16px; pointer-events: none; }
.hero .top, .hero .bottom { display: flex; justify-content: space-between; gap: 8px; }
.hero .top { align-items: flex-start; }
.hero .bottom { align-items: flex-end; }
.brand { font-family: var(--font-display); font-size: 30px; line-height: 1; letter-spacing: .02em; color: #fff6ea; text-shadow: 0 2px 12px rgba(0, 0, 0, .45); }
.brand small { display: block; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; opacity: .85; margin-top: 4px; }
.clock { text-align: right; font-family: var(--font-mono); font-size: 12px; color: #fff6ea; text-shadow: 0 1px 6px rgba(0, 0, 0, .6); font-variant-numeric: tabular-nums; }
.clock strong { display: block; font-size: 20px; font-weight: 500; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days span { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; padding: 3px 6px; border-radius: 4px; background: rgba(20, 12, 16, .45); color: rgba(255, 246, 234, .65); }
.days span.past { color: rgba(255, 246, 234, .35); text-decoration: line-through; }
.days span.now { background: var(--accent); color: var(--accent-ink); font-weight: 500; }
.net { font-family: var(--font-mono); font-size: 11px; color: var(--accent-ink); background: var(--warn); padding: 3px 8px; border-radius: 999px; }

/* vistas */
.views { flex: 1; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.view { padding: 16px 16px 88px; display: flex; flex-direction: column; gap: 16px; }
.cargando { color: var(--muted); margin: 0; }
.eyebrow { font-family: var(--font-mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
h2 { font-family: var(--font-display); font-weight: 400; font-size: 22px; letter-spacing: .02em; margin: 0; text-wrap: balance; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.nota { margin: 0; font-size: 12.5px; color: var(--muted); }
.aviso { border: 1px solid var(--warn); border-radius: 14px; padding: 12px 14px; color: var(--fg); background: rgba(232, 182, 92, .08); }
.aviso.ok { border-color: var(--ok); background: rgba(156, 199, 122, .08); }
.aviso b { display: block; margin-bottom: 2px; }

/* inventario */
.inv { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.inv-row { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; }
.inv-row + .inv-row { border-top: 1px solid var(--line); }
.inv-row .name { font-weight: 700; }
.inv-row .sub { font-size: 12.5px; color: var(--muted); }
.inv-row .qty { font-family: var(--font-mono); font-size: 20px; font-variant-numeric: tabular-nums; text-align: right; }
.inv-row.zero .qty, .inv-row.zero .name { color: var(--muted); font-weight: 400; }
.ic { display: block; flex: none; }
.melt { color: var(--ice); }
.bump { animation: bump .6s ease; }
@keyframes bump { 30% { transform: scale(1.25); color: var(--accent); } }

/* encargo */
.order { background: linear-gradient(160deg, var(--panel-2), var(--panel)); border: 1px dashed var(--muted); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.order-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stamp { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; border: 1px solid var(--bad); color: var(--bad); padding: 2px 6px; border-radius: 3px; transform: rotate(-3deg); white-space: nowrap; }
.req { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--warn); border-radius: 3px; transition: width .5s ease; }
.req.done .bar i { background: var(--ok); }
.req .num { font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.req.done .num { color: var(--ok); }

/* mercado */
.offers { display: flex; flex-direction: column; gap: 10px; }
.offer { border: 1px solid var(--line); border-radius: 14px; background: var(--panel-2); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.offer.mine { border-color: var(--accent); }
.offer.forme { border-color: var(--ice); }
.offer.new { animation: slidein .5s ease; }
@keyframes slidein { from { transform: translateY(-8px); opacity: .3; } }
.offer-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.offer-meta b { color: var(--fg); }
.offer-meta .id { font-family: var(--font-mono); }
.pill { font-family: var(--font-mono); font-size: 10.5px; padding: 1px 6px; border-radius: 999px; background: var(--ice); color: var(--accent-ink); margin-left: 4px; }
.pill.mine { background: var(--accent); }
.swap { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.side > div { min-width: 0; }
.side .q { font-family: var(--font-mono); font-size: 18px; }
.side .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.side .g { font-weight: 700; overflow-wrap: anywhere; }
.arrow { color: var(--muted); font-size: 18px; }
.offer-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.btn { border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 700; background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--fg); }
.btn.danger { background: var(--bad); color: var(--accent-ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.wide { width: 100%; padding: 12px; }
.empty { padding: 24px 12px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; }

/* registro */
.chain { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.link { flex: none; min-width: 118px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--panel-2); }
.link .d { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.link code { font-family: var(--font-mono); font-size: 12px; color: var(--ice); }
.link.fresh { border-color: var(--ice); animation: slidein .6s ease; }
.chain-arrow { flex: none; align-self: center; color: var(--muted); }
.log { display: flex; flex-direction: column; }
.log-day { font-family: var(--font-mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); padding: 12px 0 6px; border-bottom: 1px solid var(--line); }
.log-row { display: grid; grid-template-columns: 44px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.log-row time { font-family: var(--font-mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.log-row.night { color: var(--ice); }
.log-row.me { background: linear-gradient(90deg, rgba(227, 138, 78, .12), transparent); }
.log-row .n { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); margin-right: 4px; }
.tag { font-family: var(--font-mono); font-size: 10.5px; border: 1px solid var(--line); padding: 0 5px; border-radius: 3px; color: var(--muted); margin-left: 4px; white-space: nowrap; }

/* barra inferior */
.nav { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); background: var(--bg); padding-bottom: env(safe-area-inset-bottom, 0px); flex: none; }
.nav button { border: 0; background: transparent; padding: 10px 4px 12px; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px; position: relative; }
.nav button[aria-selected="true"] { color: var(--fg); }
.nav button[aria-selected="true"]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 2px; background: var(--accent); }
.nav svg { width: 22px; height: 22px; }
.badge { position: absolute; top: 5px; left: calc(50% + 8px); background: var(--accent); color: var(--accent-ink); font-family: var(--font-mono); font-size: 10px; border-radius: 999px; padding: 0 5px; min-width: 16px; }

.fab { position: absolute; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); border: 0; border-radius: 999px; padding: 12px 18px; background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: 0 10px 24px -8px rgba(0, 0, 0, .6); z-index: 2; }
.fab:disabled { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); box-shadow: none; cursor: default; }
.grupo { display: flex; flex-direction: column; gap: 10px; }
.grupo-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.cupo { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); text-align: right; }
.cupo.lleno { color: var(--warn); }

/* v2: tus días y la clasificación (sin destacarla más que el mercado) */
.mis-dias { display: flex; flex-direction: column; gap: 10px; }
.dias-c { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.dia-c { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 0; font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.dia-c i { font-style: normal; font-size: 14px; min-height: 1.2em; }
.dia-c.ok { border-color: var(--ok); color: var(--ok); }
.dia-c.no { border-style: dashed; }
.clas { display: flex; flex-direction: column; gap: 6px; }
.clas-row { display: grid; grid-template-columns: 64px 1fr; gap: 10px; font-size: 14px; }
.clas-n { font-family: var(--font-mono); font-size: 12px; color: var(--muted); padding-top: 1px; }
.clas .yo { font-weight: 700; }
.clas small { color: var(--muted); }

/* hojas */
.scrim { position: absolute; inset: 0; background: rgba(10, 6, 8, .6); display: flex; align-items: flex-end; z-index: 5; }
.sheet { width: 100%; background: var(--panel-2); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 14px; animation: up .25s ease; max-height: 90%; overflow-y: auto; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet p { margin: 0; color: var(--muted); }
.field { display: grid; grid-template-columns: 46px minmax(0, 1fr) minmax(0, 1.4fr); gap: 8px; align-items: center; }
.field label { font-weight: 700; }
.field input, .field select, .to input { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; color: var(--fg); font: inherit; min-width: 0; width: 100%; }
.to { display: flex; flex-direction: column; gap: 6px; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px; }
.seg button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.cmd { font-family: var(--font-mono); font-size: 12.5px; background: var(--bg); border-radius: 8px; padding: 8px 10px; color: var(--ice); overflow-x: auto; white-space: nowrap; }
.row-btns { display: flex; gap: 8px; }
.row-btns .btn { flex: 1; }
.sheet .err { color: var(--bad); font-size: 13.5px; }
.trade-anim { display: flex; justify-content: center; align-items: center; gap: 22px; padding: 8px 0; }
.trade-anim .a { animation: toR 1s ease both; }
.trade-anim .b { animation: toL 1s ease both; }
@keyframes toR { 0% { transform: translateX(-30px); opacity: 0; } 60% { transform: translateX(8px); opacity: 1; } 100% { transform: none; } }
@keyframes toL { 0% { transform: translateX(30px); opacity: 0; } 60% { transform: translateX(-8px); opacity: 1; } 100% { transform: none; } }

.toast { position: absolute; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); background: var(--fg); color: var(--bg); border-radius: 12px; padding: 10px 14px; font-weight: 700; font-size: 14px; z-index: 6; animation: up .25s ease; }
.toast.ok { background: var(--ok); color: var(--accent-ink); }
.toast.error { background: var(--bad); color: var(--accent-ink); }

.screen { position: absolute; inset: 0; z-index: 8; background: var(--bg); display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 32px 24px; }
.screen p { color: var(--muted); margin: 0; max-width: 40ch; }
.screen code { font-family: var(--font-mono); color: var(--ice); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
