:root {
  --bg: #F3F0E9;
  --surface: #FFFFFF;
  --ink: #151515;
  --muted: #6B675F;
  --line: #E2DDD2;
  --ok: #2F7D4F;
  --ok-bg: #E3F1E8;
  --warn: #9A5B00;
  --warn-bg: #FBEFD9;
  --bad: #B3261E;
  --bad-bg: #FBE4E1;
  --radius: 18px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --display: 'Inter Tight', 'Inter', system-ui, sans-serif;
  --wordmark: 'Archivo', 'Inter Tight', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { min-height: 100dvh; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
button, input, select { font: inherit; color: inherit; }
img { display: block; }

.wrap { max-width: 520px; margin: 0 auto; padding: 16px 16px 48px; }
.center-screen { min-height: 100dvh; display: grid; place-items: center; }
.splash-mark { width: 56px; opacity: .9; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 18px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 30px; height: 30px; }
.brand span { font-family: var(--wordmark); font-stretch: 125%; font-weight: 800; font-size: 19px; letter-spacing: -.03em; }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 14px; padding: 8px; cursor: pointer; }

/* login */
.login { min-height: 90dvh; display: flex; flex-direction: column; justify-content: center; gap: 22px; }
.login .logo-big { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 8px; }
.login .logo-big img { width: 72px; height: 72px; }
.login .logo-big span { font-family: var(--wordmark); font-stretch: 125%; font-weight: 800; font-size: 36px; letter-spacing: -.035em; }
.login .logo-big small { color: var(--ink); letter-spacing: .3em; font-size: 11px; text-transform: uppercase; }

h1 { font-family: var(--display); font-size: 28px; letter-spacing: -.02em; margin: 0 0 4px; }
h2 { font-family: var(--display); font-size: 18px; margin: 0 0 12px; letter-spacing: -.01em; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.field { margin-bottom: 14px; }
input, select {
  width: 100%; padding: 14px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 16px; outline: none;
}
input:focus, select:focus { border-color: var(--ink); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 15px 18px; border-radius: 14px; border: 1px solid var(--ink);
  background: var(--ink); color: #fff; font-weight: 600; font-size: 16px; cursor: pointer;
  transition: transform .08s ease, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.secondary { background: transparent; color: var(--ink); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.sm { width: auto; padding: 9px 14px; font-size: 14px; border-radius: 10px; }
.stack > * + * { margin-top: 10px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 12px; }
.hero { text-align: center; padding: 28px 18px 24px; }
.hero .big { font-family: var(--display); font-weight: 800; font-size: 84px; line-height: 1; letter-spacing: -.04em; }
.hero .big.neg { color: var(--bad); }
.hero .lbl { font-weight: 600; margin-top: 6px; }
.hero .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.kv:first-of-type { border-top: 0; padding-top: 0; }
.kv .k { color: var(--muted); font-size: 14px; }
.kv .v { font-weight: 600; text-align: right; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.stats .card { margin: 0; }
.stat-num { font-family: var(--display); font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.stat-lbl { color: var(--muted); font-size: 13px; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.soon, .badge.zero { background: var(--warn-bg); color: var(--warn); }
.badge.minus, .badge.expired { background: var(--bad-bg); color: var(--bad); }
.badge.none { background: #ECE8DF; color: var(--muted); }

.alert { border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; font-size: 14px; line-height: 1.45; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; }
.list li:first-child { border-top: 0; }
.x-btn { background: none; border: 0; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; padding: 4px 8px; }

/* admin */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.summary .card { margin: 0; padding: 12px; text-align: center; }
.summary .stat-num { font-size: 24px; }
.search { margin-bottom: 12px; }
.client-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 8px; cursor: pointer; }
.client-row .name { font-weight: 600; }
.client-row .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.client-row .right { text-align: right; flex-shrink: 0; }
.client-row .rem { font-family: var(--display); font-weight: 800; font-size: 22px; }
.client-row .rem.neg { color: var(--bad); }
.packs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.pack { padding: 14px 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: center; cursor: pointer; font-weight: 700; font-size: 18px; }
.pack small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.pack.on { border-color: var(--ink); background: var(--ink); color: #fff; }
.pack.on small { color: #cfcac0; }
.seg { display: flex; background: #E9E5DC; border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.back { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 8px 0; margin-bottom: 8px; font-weight: 600; cursor: pointer; }

.fab { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom)); width: min(488px, calc(100% - 32px)); box-shadow: 0 10px 30px rgba(0,0,0,.18); z-index: 5; }
.fab-space { height: 84px; }

/* modal */
.modal { position: fixed; inset: 0; background: var(--bg); z-index: 20; overflow-y: auto; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; } }
.modal .wrap { padding-top: 20px; }
.qr-box { background: #fff; border-radius: 22px; padding: 22px; margin: 10px auto 18px; max-width: 340px; border: 1px solid var(--line); }
.qr-box img { width: 100%; height: auto; image-rendering: pixelated; }
#reader { width: 100%; border-radius: 18px; overflow: hidden; background: #000; min-height: 280px; }
#reader video { border-radius: 18px; }

.toast { position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); width: max-content; transform: translateX(-50%) translateY(-20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 50; max-width: min(420px, calc(100% - 32px)); text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.success-tick { width: 72px; height: 72px; border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center; font-size: 38px; margin: 10px auto 14px; }
.success-tick.warn { background: var(--bad); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.quick button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 12px; font-size: 13px; cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.summary button.card { font: inherit; color: inherit; width: 100%; }
