:root {
  --bg: #f6f4ef; --card: #fff; --ink: #1d1b16; --muted: #6b665c; --line: #e6e1d6;
  --accent: #5b3cc4; --accent-2: #7b5ce6; --accent-ink: #fff; --soft: #efeafc;
  --ok: #1f7a4d; --ok-bg: #dcf3e6; --warn: #9a5b00; --warn-bg: #fff1d6; --bad: #b3261e; --bad-bg: #fbe1df; --info: #1f4f9c; --info-bg: #e5efff;
  --radius: 16px; --nav-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #131218; --card: #1e1d25; --ink: #ecebf2; --muted: #a29fb0; --line: #2e2c39; --soft: #2a2540; --accent: #8d73f0; --accent-2: #a48ff5;
    --ok-bg: #173b2a; --ok: #7fd8a8; --warn-bg: #3d2d10; --warn: #f2c06b; --bad-bg: #42201e; --bad: #f2a29c; --info-bg: #1b2b47; --info: #9cc0ff; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { overscroll-behavior-y: none; }
a { color: var(--accent); }

/* ---- estructura de app ---- */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 8px; display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: -.3px; }
.topbar .back { border: 0; background: var(--card); width: 38px; height: 38px; border-radius: 12px; font-size: 18px; padding: 0; }
.view { max-width: 560px; margin: 0 auto; padding: 4px 14px calc(var(--nav-h) + 110px + var(--safe-b)); }
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--line); display: flex; }
.bottomnav button { flex: 1; border: 0; background: none; border-radius: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 6px 0; }
.bottomnav button .ic { font-size: 21px; line-height: 1; }
.bottomnav button.on { color: var(--accent); font-weight: 600; }
.actionbar { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 15; padding: 10px 14px; background: linear-gradient(to top, var(--bg) 75%, transparent); }
.actionbar .inner { max-width: 560px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.actionbar .mine { min-width: 0; }
.actionbar .mine .lbl { font-size: 12px; color: var(--muted); }
.actionbar .mine .amt { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.actionbar .grow { flex: 1; }

/* ---- piezas ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 16px; margin: 0 0 8px; }
.card h3 { font-size: 14px; margin: 12px 0 6px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.nowrap { flex-wrap: nowrap; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.center { text-align: center; }
.money { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.big { font-size: 28px; font-weight: 750; font-variant-numeric: tabular-nums; }
button { font: inherit; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 10px 14px; cursor: pointer; min-height: 42px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.block { width: 100%; }
button.lg { min-height: 52px; font-size: 16px; border-radius: 14px; }
button.ghost { background: transparent; border-color: transparent; color: var(--accent); }
button.on { background: var(--soft); border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.chip { min-height: 32px; padding: 4px 11px; border-radius: 999px; font-size: 13px; }
input, select, textarea { font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); width: 100%; }
textarea { min-height: 80px; }
label.field { display: block; margin: 10px 0; }
label.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
ul.list { list-style: none; margin: 0; padding: 0; }
ul.list > li { padding: 11px 0; border-bottom: 1px solid var(--line); }
ul.list > li:last-child { border-bottom: 0; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; background: var(--soft); white-space: nowrap; }
.b-abierto { background: var(--line); color: var(--muted); }
.b-confirmado, .b-parcialmente_pagado, .b-info { background: var(--info-bg); color: var(--info); }
.b-cobrando, .b-pendiente, .b-propuesto, .b-entrega_registrada, .b-demo { background: var(--warn-bg); color: var(--warn); }
.b-cerrado, .b-pagado, .b-aceptado, .b-entregado, .b-liquidado, .b-atendido, .b-real { background: var(--ok-bg); color: var(--ok); }
.b-vencido, .b-revision, .b-fallido, .b-rechazado { background: var(--bad-bg); color: var(--bad); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--soft); border-radius: 14px; padding: 12px; }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.wide { grid-column: 1 / -1; }
.pill-ok { color: var(--ok); } .pill-warn { color: var(--warn); } .pill-bad { color: var(--bad); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
td.r, th.r { text-align: right; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
blockquote { margin: 8px 0; padding: 10px 12px; background: var(--soft); border-radius: 12px; }

/* tarjetas de lugar */
.place { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 12px; }
.place .emoji { font-size: 26px; width: 44px; height: 44px; border-radius: 12px; background: var(--soft); display: flex; align-items: center; justify-content: center; }
.place .t { flex: 1; min-width: 0; }
.place.on { border-color: var(--accent); background: var(--soft); }

/* personas */
.people { display: flex; gap: 10px; overflow-x: auto; padding: 4px 0; }
.person { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 56px; font-size: 12px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; position: relative; }
.avatar .ok { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 11px; display: flex; align-items: center; justify-content: center; border: 2px solid var(--card); }

/* pasos */
.steps { display: flex; gap: 4px; margin: 4px 0 12px; }
.steps div { flex: 1; text-align: center; font-size: 11px; color: var(--muted); }
.steps div::before { content: ""; display: block; height: 5px; border-radius: 3px; background: var(--line); margin-bottom: 4px; }
.steps div.done::before { background: var(--accent-2); }
.steps div.now { color: var(--accent); font-weight: 650; }
.steps div.now::before { background: var(--accent); }

/* hoja inferior */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 86vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 8px 16px calc(18px + var(--safe-b)); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }

.qr { background: #fff; color: #000; border-radius: 16px; padding: 14px; text-align: center; }
.qr img { width: 240px; max-width: 100%; height: auto; image-rendering: pixelated; }
.qr pre { white-space: pre-wrap; word-break: break-all; font-size: 11px; text-align: left; background: #f3f3f3; padding: 8px; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 90px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 11px 15px; border-radius: 12px; width: max-content; max-width: 90vw; z-index: 60; font-size: 14px; }
.net { font-size: 12px; padding: 4px 9px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); }
.hero { text-align: center; padding: 30px 6px 10px; }
.hero img { width: 84px; height: 84px; border-radius: 22px; }
.hero h1 { margin: 12px 0 4px; font-size: 30px; }
.hl { animation: hl 1.6s ease-out; }
@keyframes hl { from { background: #fff3a8; } to { background: transparent; } }
.empty { text-align: center; padding: 18px 8px; color: var(--muted); }

/* caja (escritorio) */
header.cajabar { position: sticky; top: 0; z-index: 5; background: #1d1b16; color: #fff; padding: 10px 14px; display: flex; gap: 10px; align-items: center; }
header.cajabar h1 { font-size: 18px; margin: 0; }
header.cajabar .sp { flex: 1; }
header.cajabar select { width: auto; background: rgba(255,255,255,.12); color: inherit; border-color: rgba(255,255,255,.3); padding: 6px 8px; font-size: 14px; }
header.cajabar select option { color: #000; }
main.caja { max-width: 1100px; margin: 0 auto; padding: 12px; }
main.caja .toast { bottom: 18px; }
