:root {
  color-scheme: dark;
  --hz-bg: #0b1220;
  --hz-surface: #121a2b;
  --hz-heading: #f8fafc;
  --hz-body: #e2e8f0;
  --hz-muted: #94a3b8;
  --hz-border: #334155;
  --hz-primary: #4680ff;
  --hz-primary-strong: #2f62d9;
  --hz-accent: #7aa2ff;
  --hz-accent-pill: rgba(122, 162, 255, 0.16);
  --hz-raised: #1a2438;
  --hz-appbar-border: #1f2a40;
  --hz-torch-on: #facc15;
  --hz-danger-text: #fca5a5;
  --hz-success: #4ade80;
  --hz-result-valid: #1f7a5c;
  --hz-result-stop: #b91c1c;
  --hz-result-warn: #a35a00;
  --hz-result-neutral: #1d2630;
  --hz-result-neutral-border: #475569;
  --hz-result-info: #5b6b79;
  --hz-tab-h: 64px;
  --hz-rail-w: 80px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--hz-bg);
  color: var(--hz-body);
  font-family: "Segoe UI", system-ui, sans-serif;
}
body {
  padding: 0;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--hz-surface);
  border-bottom: 1px solid var(--hz-appbar-border);
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}
.appbar-in {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.appbar-copy { min-width: 0; }
.appbar-kicker {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--hz-muted);
  letter-spacing: 0.02em;
}
.appbar-house,
.appbar-login-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--hz-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--hz-heading);
  background: var(--hz-raised);
  border-radius: 999px;
  padding: 4px 10px;
  flex: 0 0 auto;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--hz-success);
}
.status.is-off { color: var(--hz-danger-text); }
.status.is-off .status-dot { background: var(--hz-danger-text); }

#install-slot { padding: 12px 16px 0; }
#install-slot:empty { padding: 0; }
.install-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--hz-raised);
  border: 1px solid var(--hz-border);
  border-radius: 14px;
  padding: 12px;
}
.install-ic {
  color: var(--hz-accent);
  flex: 0 0 auto;
}
.install-copy { flex: 1; min-width: 0; }
.install-copy strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--hz-heading);
}
.install-copy span {
  display: block;
  font-size: 13px;
  color: var(--hz-muted);
}

#scan-stage { min-width: 0; }
#scan-view {
  padding: 16px 16px calc(var(--hz-tab-h) + env(safe-area-inset-bottom) + 16px);
}
body.screen-login #scan-view {
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}

#scanner-host { display: none; padding: 16px 16px 0; }
body.screen-scan.cam-live #scanner-host { display: block; }
.viewfinder {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  height: min(62vh, 520px);
}
#voucher-scan-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.vf-frame { position: absolute; inset: 16% 12% 22% 12%; }
.vf-frame i {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.7);
}
.vf-frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 6px 0 0 0; }
.vf-frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 6px 0 0; }
.vf-frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 6px; }
.vf-frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 6px 0; }
.vf-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.scan-idle {
  background: var(--hz-surface);
  border-radius: 16px;
  min-height: min(42vh, 320px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px 16px;
  color: var(--hz-heading);
}
.scan-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}
.scan-actions.single { grid-template-columns: 1fr; }
.scan-actions .btn { min-height: 52px; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--hz-surface);
  border-top: 1px solid var(--hz-appbar-border);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  height: calc(var(--hz-tab-h) + env(safe-area-inset-bottom));
}
.tab {
  flex: 1;
  min-height: 56px;
  border: 0;
  background: none;
  color: var(--hz-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font: 500 12px/1.2 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
}
.tab:focus-visible {
  outline: 2px solid var(--hz-accent);
  outline-offset: -4px;
}
.tab-pill {
  width: 56px;
  height: 32px;
  border-radius: 16px;
  display: grid;
  place-items: center;
}
.tab[aria-current="page"] {
  color: var(--hz-accent);
  font-weight: 600;
}
.tab[aria-current="page"] .tab-pill { background: var(--hz-accent-pill); }
body.kb-open .tabbar { display: none; }

h1 { color: var(--hz-heading); font-size: 1.5rem; margin: 0 0 12px; }
.lead, .hint { color: var(--hz-muted); }
.hint { font-size: 13px; }
label { display: block; margin: 12px 0 6px; font-weight: 600; color: var(--hz-heading); }
input, select {
  width: 100%;
  font-size: max(16px, 1rem);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--hz-border);
  background: #0f172a;
  color: var(--hz-heading);
}
a {
  color: var(--hz-heading);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
a:hover, a:active { text-decoration-thickness: 2px; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--hz-accent);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: 600 16px/1.2 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
  color: var(--hz-heading);
  background: var(--hz-raised);
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--hz-primary-strong); color: #fff; }
.btn-primary:active { background: #2852b8; }
.btn-secondary { background: var(--hz-raised); border-color: var(--hz-border); color: var(--hz-heading); }
.btn-ghost { background: transparent; color: var(--hz-heading); }
.btn-ghost:active { background: rgba(255, 255, 255, 0.06); }
.btn-block { width: 100%; }
.btn-submit { margin-top: 16px; }
.btn-login-submit { min-height: 52px; margin-top: 16px; }
.btn-sm { min-height: 40px; height: 40px; padding: 0 12px; font-size: 15px; }
.btn-danger { background: #b91c1c; color: #fff; }
.btn-oncolor { background: #fff; color: inherit; }
.btn-ghost-oncolor { background: transparent; color: #fff; border: 2px solid rgba(255, 255, 255, 0.7); }
.icon-btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--hz-heading);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.btn-torch[aria-pressed="true"] {
  background: var(--hz-torch-on);
  color: #0b1220;
  border-color: var(--hz-torch-on);
}

.banner, .alert {
  background: #7f1d1d;
  color: #fff;
  padding: 10px 12px;
  border-radius: 10px;
}
.field-error {
  color: var(--hz-danger-text);
  margin: 8px 0 0;
}
.ios-note { color: var(--hz-muted); font-size: 13px; margin: 0 0 10px; }

.result {
  border-radius: 20px;
  padding: 24px;
  color: #fff;
}
.result-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}
.emo {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: 28px;
  line-height: 1;
}
.result-body { margin: 0 0 14px; font-size: 16px; }
.result-details { margin: 0 0 16px; font-size: 15px; }
.result-details p { margin: 4px 0; }
.result-actions { display: grid; gap: 10px; }
.result-cam-note { margin: 14px 0 0; font-size: 13px; color: rgba(255, 255, 255, 0.85); }
.result--valid { background: var(--hz-result-valid); color: var(--hz-result-valid); }
.result--stop { background: var(--hz-result-stop); color: var(--hz-result-stop); }
.result--warn { background: var(--hz-result-warn); color: var(--hz-result-warn); }
.result--info { background: var(--hz-result-info); color: var(--hz-result-info); }
.result--neutral {
  background: var(--hz-result-neutral);
  color: var(--hz-result-neutral);
  border: 2px solid var(--hz-result-neutral-border);
}
.result--valid .result-title,
.result--stop .result-title,
.result--warn .result-title,
.result--info .result-title,
.result--neutral .result-title,
.result-body,
.result-details,
.result-cam-note { color: #fff; }

.today-head { margin-bottom: 12px; }
.today-summary { margin: 0; font-weight: 600; color: var(--hz-heading); }
.today-updated { margin: 4px 0 12px; color: var(--hz-muted); font-size: 13px; }
.today-list { list-style: none; margin: 0; padding: 0; }
.today-list.is-busy { opacity: 0.6; }
.today-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--hz-border);
}
.today-row strong { color: var(--hz-heading); }
.refresh-ic.is-spin { animation: spin 0.8s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  .refresh-ic.is-spin { animation: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }

.menu-group {
  background: var(--hz-surface);
  border: 1px solid var(--hz-appbar-border);
  border-radius: 16px;
  margin: 0 0 16px;
  overflow: hidden;
}
.menu-group h2 {
  margin: 0;
  padding: 12px 16px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--hz-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.menu-row {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border: 0;
  border-top: 1px solid var(--hz-appbar-border);
  background: transparent;
  color: var(--hz-heading);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-row[data-static] { cursor: default; }
.menu-row .danger { color: var(--hz-danger-text); }
.menu-val { color: var(--hz-muted); }
.switch {
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: #334155;
  position: relative;
  flex: 0 0 auto;
}
.switch.on { background: var(--hz-primary-strong); }
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
}
.switch.on::after { left: 22px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--hz-tab-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 40;
  background: var(--hz-raised);
  border: 1px solid var(--hz-border);
  color: var(--hz-heading);
  border-radius: 12px;
  padding: 12px 14px;
}
.toast.is-error { color: var(--hz-danger-text); }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 30;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  background: var(--hz-raised);
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
}
.sheet-grab {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: #475569;
  margin: 0 auto 14px;
}
.sheet h2 { margin: 0 0 12px; color: var(--hz-heading); font-size: 20px; }
.sheet-close { position: absolute; top: 8px; right: 8px; }
.sheet-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--hz-appbar-border);
}
.sheet-step:last-of-type { border-bottom: 0; }
.sheet-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--hz-accent-pill);
  color: var(--hz-accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: 0 0 auto;
}
.sheet-actions { display: grid; gap: 10px; margin-top: 16px; }
.kbdic {
  display: inline-flex;
  vertical-align: middle;
  background: var(--hz-surface);
  border: 1px solid var(--hz-border);
  border-radius: 8px;
  padding: 3px;
  color: var(--hz-accent);
  margin: 0 2px;
}

.pw-row { position: relative; }
.pw-row input { padding-right: 48px; }
.pw-row .icon-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
}

@media (orientation: landscape) and (max-height: 500px) {
  body:not(.screen-login) .appbar,
  body:not(.screen-login) #install-slot,
  body:not(.screen-login) #scan-stage {
    margin-inline-start: calc(var(--hz-rail-w) + env(safe-area-inset-left));
    min-width: 0;
  }
  .appbar {
    padding-top: 0;
    padding-left: 16px;
  }
  .appbar-in { height: 48px; }
  .tabbar {
    top: 0;
    right: auto;
    width: calc(var(--hz-rail-w) + env(safe-area-inset-left));
    height: auto;
    flex-direction: column;
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
    border-top: 0;
    border-right: 1px solid var(--hz-appbar-border);
  }
  .tab {
    height: 64px;
    min-height: 0;
    max-height: 64px;
    flex: 0 0 64px;
  }
  #scan-view {
    padding-left: 16px;
    padding-bottom: 16px;
    min-width: 0;
  }
  body.screen-login #scan-view { padding-left: 16px; }
  #scanner-host {
    padding-left: 16px;
    min-width: 0;
  }
  body.screen-scan.cam-live #scan-stage,
  body.screen-scan #scan-stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, min(240px, 42%));
    align-items: start;
    min-width: 0;
  }
  body.screen-scan #scanner-host { grid-column: 1; min-width: 0; }
  body.screen-scan #scan-view { grid-column: 2; padding-left: 16px; min-width: 0; }
  body.screen-scan #scan-view .scan-actions { grid-template-columns: 1fr; }
  body.screen-scan #scan-view .btn { min-width: 0; }
  .viewfinder { height: calc(100vh - 72px); min-width: 0; }
}
