:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --ink: #1c1917;
  --ink-2: #57534e;
  --ink-3: #a8a29e;
  --line: #d6d3d1;
  --wine: #7a1f3d;
  --wine-ink: #ffffff;
  --ok: #15803d;
  --ok-bg: #16a34a;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --r: 12px;
  --tap: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; }
button, input, select { font: inherit; color: inherit; }
.mono { font-family: ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace; letter-spacing: 0.02em; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* 100dvh = the area actually visible between Safari's/Chrome's bars (vh/inset:0 would include space behind them). */
.view { display: none; position: fixed; top: 0; left: 0; right: 0; height: 100vh; height: 100dvh; flex-direction: column; padding: calc(var(--safe-t) + 0px) 12px calc(var(--safe-b) + 12px); gap: 10px; background: var(--bg); overflow: hidden; }
.view > * { flex-shrink: 0; }
.view.on { display: flex; }

.bar { display: flex; align-items: center; gap: 8px; min-height: 56px; }
.bar .title { font-size: 19px; font-weight: 600; flex: 1; }
.icon-btn { width: 48px; height: 48px; border: 0; background: none; border-radius: 50%; display: grid; place-items: center; }
.icon-btn:active { background: #0001; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 10px 14px; font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.sync { flex: 1; text-align: right; font-size: 13px; color: var(--ink-2); }
.sync.pending { color: var(--warn); font-weight: 600; }
.tag { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 15px; }
.tag.strong { font-weight: 700; }
.step { margin: 0; font-size: 22px; font-weight: 700; }
.lead { font-size: 18px; font-weight: 600; margin: 4px 0; text-align: center; }
.hint { color: var(--ink-2); font-size: 14px; text-align: center; }
.err { color: var(--bad); font-weight: 600; min-height: 1.3em; margin: 0; text-align: center; }
.warn { background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: 8px; margin: 0; }
.scroll { overflow-y: auto; flex: 1 1 auto; min-height: 0; -webkit-overflow-scrolling: touch; }

.btn { min-height: 52px; padding: 0 18px; border-radius: var(--r); border: 1.5px solid var(--line); background: var(--surface); font-size: 17px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; color: var(--ink); touch-action: manipulation; }
.btn:active { transform: scale(0.98); background: #eee; }
.btn.big { min-height: var(--tap); font-size: 19px; }
.btn.primary { background: var(--wine); color: var(--wine-ink); border-color: var(--wine); }
.btn.primary:active { background: #5e1730; }
.btn.danger { color: var(--bad); border-color: #fca5a5; }
.btn.ghost { border: 0; background: none; }
.btn.square { width: var(--tap); padding: 0; flex: none; }
.btn.grow { flex: 1; }
.row-btns { display: flex; gap: 10px; }

/* PIN and numpads */
.pad-wrap { display: flex; flex-direction: column; gap: 12px; flex: 1; justify-content: flex-end; }
.pin-dots { display: flex; justify-content: center; gap: 14px; min-height: 22px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; background: var(--ink); }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.numpad button, .keypad button { min-height: 64px; border-radius: var(--r); border: 1.5px solid var(--line); background: var(--surface); font-size: 26px; font-weight: 600; touch-action: manipulation; }
.numpad button:active, .keypad button:active { background: #e7e5e4; }
.field { min-height: 64px; border-radius: var(--r); background: var(--surface); border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 700; width: 100%; }

.qty-field { font-size: 44px; min-height: 84px; font-variant-numeric: tabular-nums; }
.qty-field.ok { border-color: var(--ok); }

/* Who */
.who-list { display: grid; gap: 8px; }
.who-list button { min-height: 64px; font-size: 21px; }
.who-add { display: flex; gap: 8px; margin-top: 16px; }
.who-add input, .search input, .form input, .form select { min-height: 56px; border-radius: var(--r); border: 1.5px solid var(--line); padding: 0 14px; font-size: 18px; background: var(--surface); width: 100%; user-select: text; -webkit-user-select: text; }
.who-add input { flex: 1; }

/* Scan */
.camera { position: relative; flex: 1 1 auto; border-radius: var(--r); overflow: hidden; background: #000; min-height: 200px; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.reticle { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.reticle span { width: 82%; height: 34%; border: 3px solid #fffc; border-radius: 10px; box-shadow: 0 0 0 9999px #0005; }
.camera.hit .reticle span { border-color: #4ade80; }
.cam-msg { position: absolute; left: 0; right: 0; bottom: 12px; text-align: center; color: #fff; font-size: 16px; margin: 0; padding: 0 16px; text-shadow: 0 1px 3px #000; }

/* Vintage */
.vintage-grid { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: 8px; }
.vintage-grid button { border-radius: var(--r); border: 1.5px solid var(--line); background: var(--surface); font-size: 26px; font-weight: 700; min-height: 56px; touch-action: manipulation; }
.vintage-grid button:active { background: var(--wine); color: #fff; }
.vintage-grid button.nv { color: var(--ink-2); font-size: 20px; }

/* Location */
/* The middle part shrinks/scrolls; keypad and the save button always stay on screen. */
.loc-main { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 0; overflow-y: auto; }
.loc-main > * { flex-shrink: 0; }
.mic { width: 112px; height: 112px; border-radius: 50%; border: 3px solid var(--wine); background: var(--surface); color: var(--wine); display: grid; place-items: center; flex: none; touch-action: manipulation; }
.mic svg { width: 44px; height: 44px; }
.mic.live { background: var(--wine); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #7a1f3d66; } 70% { box-shadow: 0 0 0 22px #7a1f3d00; } 100% { box-shadow: 0 0 0 0 #7a1f3d00; } }
.heard { margin: 0; text-align: center; color: var(--ink-2); font-size: 15px; min-height: 2.6em; max-width: 30em; }
.loc-field { font-size: 34px; }
.loc-field.ok { border-color: var(--ok); }
.loc-field.bad { border-color: var(--bad); }
.valid { margin: 0; font-size: 15px; font-weight: 600; min-height: 1.3em; text-align: center; }
.valid.ok { color: var(--ok); }
.valid.bad { color: var(--bad); }
.alts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.alts button { min-height: 48px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-size: 18px; font-weight: 600; }
.keypad { display: flex; flex-direction: column; gap: 6px; }
.keypad .krow { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 6px; }
.keypad button { min-height: 50px; font-size: 22px; padding: 0; }
.keypad button.pre { font-size: 16px; background: #f0ebe5; }
.loc-actions { display: flex; gap: 10px; }
/* Keypad open: compact header area so everything fits between Safari's bars. */
#v-loc.kbd .step { display: none; }
#v-loc.kbd .loc-main { justify-content: flex-start; gap: 6px; }
#v-loc.kbd .mic-row { width: 100%; display: flex; gap: 8px; align-items: center; }
#v-loc.kbd .mic { width: 60px; height: 60px; }
#v-loc.kbd .mic svg { width: 28px; height: 28px; }
#v-loc.kbd .loc-field { min-height: 60px; flex: 1; font-size: 30px; }
#v-loc.kbd .heard { min-height: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#v-loc.kbd .valid { min-height: 0; font-size: 13px; }
#v-loc.kbd .alts button { min-height: 44px; }
.mic-row { display: contents; }

/* Saved flash */
.flash { background: var(--ok-bg); color: #fff; align-items: center; justify-content: center; text-align: center; }
.flash.error { background: var(--bad); }
.flash .check { width: 120px; height: 120px; stroke-width: 1.6; }
.flash-title { font-size: 34px; font-weight: 800; margin: 8px 0 0; }
.flash-sub { font-size: 20px; margin: 0; }
.flash-note { font-size: 15px; margin: 0; opacity: 0.9; min-height: 1.2em; }
.btn.on-flash { background: transparent; color: #fff; border-color: #fff; margin-top: 32px; }

/* List */
.search input { width: 100%; }
.entry { display: flex; align-items: center; gap: 10px; padding: 12px 6px; border-bottom: 1px solid var(--line); min-height: 64px; width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; }
.entry:active { background: #0000000a; }
.entry .loc { font-size: 21px; font-weight: 700; }
.entry .sub { font-size: 14px; color: var(--ink-2); }
.entry .main { flex: 1; min-width: 0; }
.entry .badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); font-weight: 600; white-space: nowrap; }
.entry .badge.ok { background: #dcfce7; color: var(--ok); }
.day { font-size: 13px; font-weight: 700; color: var(--ink-2); padding: 14px 6px 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.empty { text-align: center; color: var(--ink-2); padding: 40px 12px; }

/* Edit form */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 15px; }
.form .inline { display: flex; gap: 8px; }
.meta { color: var(--ink-2); font-size: 14px; margin: 0; }
.log { font-size: 14px; color: var(--ink-2); }
.log summary { font-weight: 600; padding: 8px 0; }
.log div div { padding: 4px 0; border-bottom: 1px solid var(--line); }

/* Menu / owner */
.menu { display: flex; flex-direction: column; gap: 10px; }
.owner { display: flex; flex-direction: column; gap: 12px; }
.owner h3 { margin: 18px 0 0; font-size: 16px; }
.metric { background: var(--surface); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; border: 1px solid var(--line); }
.metric span { color: var(--ink-2); font-size: 14px; }
.metric strong { font-size: 40px; }
.metric small { color: var(--ink-2); }
.o-current { background: var(--surface); border: 2px solid var(--wine); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.hist { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 8px; }
.hist a { color: var(--wine); font-weight: 600; text-decoration: none; padding: 8px; }
.staff-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 90px); background: var(--ink); color: #fff; padding: 14px 16px; border-radius: var(--r); font-size: 16px; text-align: center; opacity: 0; transform: translateY(10px); transition: 0.2s; pointer-events: none; z-index: 10; }
.toast.on { opacity: 1; transform: none; }
.toast.bad { background: var(--bad); }

@media (min-width: 640px) {
  .view { max-width: 520px; margin: 0 auto; }
}
@media (max-height: 700px) {
  .mic { width: 88px; height: 88px; }
  .numpad button { min-height: 52px; }
  .keypad button { min-height: 44px; }
  .bar { min-height: 48px; }
  .btn.big { min-height: 54px; }
}
