:root {
  --ink: #0B1220;
  --ink-2: #111a2e;
  --line: rgba(255, 255, 255, 0.14);
  --text: #F6F5F1;
  --muted: rgba(246, 245, 241, 0.66);
  --blue: #0A49BA;
  --blue-shadow: #062d74;
  --teal: #00E5CC;
  --ok: #0F9D58;
  --warn: #F2A900;
  --bad: #D93A35;
  --gold: #D4A72C;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px; border: 0; border-radius: 12px; font-weight: 700; font-size: 17px;
}
.btn-primary { background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-shadow); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--blue-shadow); }
.btn-primary[disabled] { opacity: 0.6; }
.btn-light { background: #fff; color: var(--ink); }
.btn-ghost { background: transparent; color: var(--text); min-height: 44px; padding: 0 12px; }
.btn-danger { background: transparent; color: #ff8c87; border: 1px solid rgba(255, 140, 135, 0.5); }
.btn-dock { flex: 1; background: rgba(255, 255, 255, 0.12); color: #fff; border: 1px solid var(--line); }
.icon-btn {
  width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08); color: #fff; font-size: 20px; flex: none;
}
.icon-btn.on { background: var(--warn); color: var(--ink); }

/* Unlock */
.unlock { min-height: 100%; display: grid; place-items: center; padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  background: radial-gradient(120% 80% at 50% 0%, #12306f 0%, var(--ink) 60%); }
.unlock-card { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.logo { width: 170px; height: auto; margin-bottom: 4px; }
.unlock h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: -0.02em; }
.unlock label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
.unlock input, .unlock select {
  min-height: 52px; width: 100%; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--ink-2); color: var(--text); font-size: 17px; appearance: none;
}
.unlock select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 23px, calc(100% - 14px) 23px; background-size: 6px 6px; background-repeat: no-repeat; }
.unlock input:focus, .unlock select:focus { outline: 2px solid var(--teal); outline-offset: 1px; }
.pin { letter-spacing: 0.6em; font-size: 26px !important; text-align: center; }
.form-error { margin: 0; color: #ff8c87; font-weight: 600; }

/* Scanner */
.scanner { position: fixed; inset: 0; display: flex; flex-direction: column; background: #000; }
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 12px 10px; background: var(--ink); }
.who { flex: 1; min-width: 0; display: grid; line-height: 1.2; }
.who strong { font-size: 18px; }
.who span { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.counts { border: 0; background: rgba(0, 229, 204, 0.14); color: var(--teal); border-radius: 12px; padding: 6px 12px; font-weight: 800; font-size: 20px; line-height: 1.1; }
.counts small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 12px 10px; background: var(--ink); }
.mode { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-weight: 700; }
.mode.active[data-action="check_in"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.mode.active[data-action="check_out"] { background: var(--warn); border-color: var(--warn); color: var(--ink); }
.camera { position: relative; flex: 1; overflow: hidden; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.frame { position: absolute; left: 50%; top: 50%; width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%); }
.frame i { position: absolute; width: 44px; height: 44px; border: 5px solid var(--teal); }
.frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 14px 0 0 0; }
.frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 14px 0 0; }
.frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 14px; }
.frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 14px 0; }
.scanner.out .frame i { border-color: var(--warn); }
.cam-status { position: absolute; left: 0; right: 0; bottom: 18px; margin: 0; text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 3px #000; padding: 0 16px; }
.cam-retry { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.offline { position: absolute; top: 0; left: 0; right: 0; margin: 0; padding: 10px 16px; background: var(--bad); color: #fff; font-weight: 700; text-align: center; }
.dock { display: flex; gap: 10px; padding: 10px 12px calc(10px + var(--safe-bottom)); background: var(--ink); }

/* Result */
.result { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; padding: 16px 16px calc(16px + var(--safe-bottom)); background: rgba(0, 0, 0, 0.35); }
.result-inner { width: 100%; border-radius: 22px; padding: 26px 22px 20px; color: #fff; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); animation: pop 0.16s ease-out; }
@keyframes pop { from { transform: translateY(16px) scale(0.98); } to { transform: none; } }
.result.ok .result-inner { background: var(--ok); }
.result.warn .result-inner { background: var(--warn); color: var(--ink); }
.result.bad .result-inner { background: var(--bad); }
.result.info .result-inner { background: #1d2a48; }
.r-title { margin: 0; font-size: 34px; font-weight: 900; letter-spacing: -0.02em; line-height: 1.05; }
.r-title::before { display: inline-block; margin-right: 10px; }
.result.ok .r-title::before { content: "✓"; }
.result.warn .r-title::before { content: "!"; }
.result.bad .r-title::before { content: "✕"; }
.r-name { margin: 14px 0 0; font-size: 26px; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.r-detail { margin: 8px 0 0; font-size: 17px; font-weight: 600; opacity: 0.92; }
.r-ref { margin: 6px 0 0; font-size: 14px; opacity: 0.75; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.tier { display: inline-block; margin: 10px 0 0; padding: 4px 12px; border-radius: 999px; font-weight: 800; font-size: 14px; letter-spacing: 0.04em; text-transform: uppercase;
  background: rgba(255, 255, 255, 0.22); }
.tier:empty { display: none; }
.tier.vip { background: var(--gold); color: #1d1500; }
.tier.premium { background: #fff; color: var(--blue); }
.r-actions { display: grid; gap: 10px; margin-top: 20px; }
.r-actions .btn { width: 100%; min-height: 58px; font-size: 19px; }
.r-actions .btn-go { background: #fff; color: var(--ink); }
.r-actions .btn-next { background: rgba(0, 0, 0, 0.22); color: inherit; }
.result.warn .r-actions .btn-next { background: rgba(11, 18, 32, 0.12); }

/* Sheets */
.sheet { position: fixed; inset: 0; z-index: 30; overflow-y: auto; background: var(--ink); padding: calc(10px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sheet-head form { flex: 1; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 22px; }
.sheet input[type="search"] { width: 100%; min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--ink-2); padding: 0 14px; font-size: 17px; }
.sheet input[type="search"]:focus { outline: 2px solid var(--teal); }
.sheet-status { color: var(--muted); font-size: 14px; margin: 6px 0 12px; }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.results button { width: 100%; text-align: left; display: grid; gap: 2px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--ink-2); }
.results .guest { margin-left: 18px; }
.results b { font-size: 17px; }
.results span { color: var(--muted); font-size: 13px; }
.results em { font-style: normal; font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.results em.vip { color: var(--gold); }
.results em.premium { color: #8fb4ff; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; }
.stats div { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stats dt { color: var(--muted); font-size: 13px; }
.stats dd { margin: 2px 0 0; font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sheet h3 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.recent { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.recent li { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); padding: 6px 0; }
.recent span { color: var(--muted); white-space: nowrap; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: 48px; font-weight: 600; }
.toggle input { width: 22px; height: 22px; accent-color: var(--teal); }
#menu .btn { width: 100%; margin-top: 10px; }
