:root {
  --navy-950: #020b18;
  --navy-900: #06162c;
  --navy-800: #0b2542;
  --navy-700: #12385e;
  --surface: rgba(12, 34, 59, 0.92);
  --surface-soft: rgba(255, 255, 255, 0.07);
  --line: rgba(167, 211, 246, 0.2);
  --ink: #f5f9ff;
  --muted: #b5c9dd;
  --blue: #1597ff;
  --blue-light: #7fd4ff;
  --green: #10b981;
  --green-dark: #047857;
  --yellow: #f5b800;
  --yellow-dark: #a86200;
  --red: #ef3d32;
  --red-dark: #a91817;
  --focus: #9ee7ff;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.36);
  --app-viewport-height: 100dvh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--navy-950);
}

body {
  min-height: var(--app-viewport-height);
  color: var(--ink);
  background:
    radial-gradient(800px 460px at 100% -10%, rgba(21, 151, 255, 0.24), transparent 62%),
    radial-gradient(700px 420px at -10% 5%, rgba(18, 56, 94, 0.7), transparent 64%),
    linear-gradient(155deg, var(--navy-950), var(--navy-900));
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  overscroll-behavior: none;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 1000;
  transform: translateY(-150%);
  border-radius: 10px;
  padding: 10px 14px;
  color: #00101c;
  background: var(--focus);
  font-weight: 800;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(100%, 620px);
  min-height: var(--app-viewport-height);
  margin: 0 auto;
}

.screen {
  width: 100%;
  padding: 18px;
}

.auth-screen {
  height: var(--app-viewport-height);
  min-height: 0;
  display: grid;
  place-items: center;
  overflow-y: auto;
  scroll-padding-block: 18px;
}

.auth-card,
.setup-card,
.camera-card,
.devices-card,
.modal-card {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-card {
  width: min(100%, 430px);
  border-radius: 28px;
  padding: 28px 22px;
}

.setup-card {
  margin-top: 18px;
  border-radius: 24px;
  padding: 24px 20px;
}

.brand-logo {
  display: block;
  width: auto;
  object-fit: contain;
}

.brand-logo-large {
  max-width: min(100%, 300px);
  height: 86px;
  margin: 0 auto 12px;
}

.brand-logo-small {
  width: 174px;
  height: 52px;
  object-position: left center;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  letter-spacing: -0.025em;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.65rem, 6vw, 2.25rem);
  line-height: 1.08;
}

h2 {
  margin-bottom: 8px;
}

.auth-card h1 {
  text-align: center;
}

.lead {
  color: var(--muted);
  line-height: 1.5;
}

.auth-card .lead {
  margin-bottom: 22px;
  text-align: center;
}

.step-indicator {
  margin-bottom: 10px;
  color: var(--blue-light);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-card .step-indicator {
  text-align: center;
}

.simple-header,
.scan-header,
.modal-header,
.camera-actions,
.scan-actions,
.result-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.simple-header,
.scan-header,
.modal-header {
  justify-content: space-between;
}

.form-stack {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

label,
.field-label {
  color: #dbeeff;
  font-size: 0.9rem;
  font-weight: 750;
}

.event-options {
  display: grid;
  gap: 9px;
  max-height: min(42dvh, 360px);
  overflow-y: auto;
  border-radius: 14px;
  padding: 3px;
}

.event-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 11px;
  align-items: center;
  min-height: 62px;
  border: 1px solid rgba(181, 214, 241, 0.22);
  border-radius: 13px;
  padding: 11px 12px;
  color: var(--ink);
  background: rgba(0, 7, 18, 0.34);
  cursor: pointer;
}

.event-option:has(input:checked) {
  border-color: rgba(35, 224, 174, 0.72);
  background: rgba(35, 224, 174, 0.12);
}

.event-option:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.45;
}

.event-option input {
  width: 22px;
  min-height: 22px;
  margin: 0;
  accent-color: var(--green);
}

.event-option-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.event-option-copy strong,
.event-option-copy small {
  overflow-wrap: anywhere;
}

.event-option-copy small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.event-selection-summary {
  margin: 0;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 50px;
  border: 1px solid rgba(181, 214, 241, 0.28);
  border-radius: 13px;
  padding: 12px 14px;
  color: var(--ink);
  background: rgba(0, 7, 18, 0.46);
}

input::placeholder {
  color: #8098ad;
}

select option {
  color: #07182b;
  background: #fff;
}

.password-control {
  position: relative;
}

.password-control input {
  padding-right: 92px;
}

.password-toggle {
  position: absolute;
  top: 5px;
  right: 5px;
  min-width: 78px;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  color: var(--blue-light);
  background: rgba(21, 151, 255, 0.13);
  font-size: 0.82rem;
  font-weight: 800;
}

.field-help,
.installation-info,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.installation-info {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.button,
.icon-button {
  appearance: none;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 11px 16px;
  font-weight: 850;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.button:active,
.icon-button:active {
  transform: scale(0.98);
}

.button:disabled,
.icon-button:disabled {
  cursor: wait;
  opacity: 0.56;
}

.button-primary {
  color: #001522;
  background: linear-gradient(135deg, #56c6ff, #23e0ae);
  box-shadow: 0 12px 28px rgba(19, 190, 207, 0.22);
}

.button-secondary {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.09);
}

.button-ghost {
  color: #d5e9fb;
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.055);
}

.button-light {
  color: #101827;
  background: #fff;
}

.button-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #172033;
  border-color: rgba(255, 255, 255, 0.72);
  background: #fff;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.google-mark {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}

.google-login-group {
  display: grid;
  gap: 10px;
}

.auth-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  height: 1px;
  background: var(--line);
}

.auth-method-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: center;
}

.button-block {
  width: 100%;
}

.button-compact {
  min-height: 42px;
  padding: 8px 12px;
}

.icon-button {
  min-width: 46px;
  padding: 8px;
  color: var(--ink);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.08);
  font-size: 1.3rem;
}

.form-message {
  margin: 0;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.88rem;
  line-height: 1.4;
}

.form-message-error {
  color: #ffd9d7;
  border: 1px solid rgba(255, 106, 99, 0.36);
  background: rgba(239, 61, 50, 0.13);
}

.scan-screen {
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.scan-header {
  margin-bottom: 10px;
}

.scan-header > .button {
  flex: 0 0 auto;
  font-size: 0.78rem;
}

.scan-heading {
  min-width: 0;
  flex: 1;
  text-align: center;
}

.scan-heading h1 {
  overflow: hidden;
  margin: 0;
  font-size: 1.35rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scan-heading p {
  overflow: hidden;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.network-banner {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
  border: 1px solid rgba(16, 185, 129, 0.22);
  border-radius: 11px;
  padding: 7px 10px;
  color: #bff9df;
  background: rgba(16, 185, 129, 0.08);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}

.network-banner.offline {
  color: #fff2bd;
  border-color: rgba(245, 184, 0, 0.42);
  background: rgba(245, 184, 0, 0.14);
}

.network-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.9);
}

.offline .network-dot {
  background: var(--yellow);
  box-shadow: 0 0 12px rgba(245, 184, 0, 0.85);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 10px;
}

.stat-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 4px 8px;
  background: rgba(0, 5, 14, 0.43);
  text-align: center;
}

.stat-card strong,
.stat-card span {
  display: block;
}

.stat-card strong {
  font-size: clamp(1.35rem, 7vw, 2rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-card span {
  overflow: hidden;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.59rem;
  font-weight: 750;
  line-height: 1.15;
  text-overflow: ellipsis;
}

.stat-ok strong { color: #45e7ae; }
.stat-warn strong { color: #ffd34f; }
.stat-bad strong { color: #ff716b; }
.stat-total strong { color: #72cfff; }

.devices-card {
  margin-bottom: 10px;
  border-radius: 13px;
  padding: 10px 12px;
  box-shadow: none;
}

.devices-card summary {
  color: #d9ecfa;
  font-size: 0.78rem;
  font-weight: 800;
}

.device-stats-list {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.device-stat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border-radius: 10px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.06);
}

.device-stat-row.current {
  border: 1px solid rgba(114, 207, 255, 0.42);
  background: rgba(21, 151, 255, 0.12);
}

.device-stat-name {
  overflow: hidden;
  font-size: 0.78rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-stat-counts {
  color: var(--muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.device-stats-actions {
  margin-top: 10px;
}

.camera-card {
  overflow: hidden;
  border-radius: 20px;
  padding: 10px;
}

.video-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 15px;
  background: #000;
  aspect-ratio: 4 / 5;
}

#video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-reticle {
  position: absolute;
  inset: 15%;
  pointer-events: none;
}

.scan-reticle span {
  position: absolute;
  width: 32px;
  height: 32px;
  border-color: #46efa9;
  filter: drop-shadow(0 0 5px rgba(70, 239, 169, 0.72));
}

.scan-reticle span:nth-child(1) { top: 0; left: 0; border-top: 4px solid; border-left: 4px solid; border-radius: 10px 0 0; }
.scan-reticle span:nth-child(2) { top: 0; right: 0; border-top: 4px solid; border-right: 4px solid; border-radius: 0 10px 0 0; }
.scan-reticle span:nth-child(3) { bottom: 0; left: 0; border-bottom: 4px solid; border-left: 4px solid; border-radius: 0 0 0 10px; }
.scan-reticle span:nth-child(4) { right: 0; bottom: 0; border-right: 4px solid; border-bottom: 4px solid; border-radius: 0 0 10px; }

.scan-reticle i {
  position: absolute;
  top: 50%;
  right: 3%;
  left: 3%;
  height: 2px;
  background: #40f09f;
  box-shadow: 0 0 14px rgba(64, 240, 159, 0.95);
  animation: scan-line 2s ease-in-out infinite alternate;
}

@keyframes scan-line {
  from { transform: translateY(-82px); }
  to { transform: translateY(82px); }
}

.camera-actions {
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 10px;
}

.camera-status {
  margin: 9px 4px 1px;
  color: #c7dced;
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: center;
}

.camera-status.error {
  color: #ffaaa5;
}

.scan-actions {
  justify-content: center;
  margin-top: 12px;
}

.result-backdrop,
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 6, 16, 0.6);
  backdrop-filter: blur(6px);
}

.result-panel {
  width: min(100%, 620px);
  min-height: min(70dvh, 620px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 30px 30px 0 0;
  padding: 30px 24px calc(24px + env(safe-area-inset-bottom));
  color: #fff;
  background: linear-gradient(165deg, var(--green), var(--green-dark));
  box-shadow: 0 -24px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.result-panel.result-warn {
  color: #1d1600;
  background: linear-gradient(165deg, #ffd229, var(--yellow));
}

.result-panel.result-offline {
  background: linear-gradient(165deg, #1d9fc5, #0b5685);
}

.result-panel.result-bad,
.result-panel.result-network {
  background: linear-gradient(165deg, #ff493d, var(--red-dark));
}

.result-icon {
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
  margin-bottom: 20px;
  border: 7px solid currentColor;
  border-radius: 999px;
  font-size: 4.2rem;
  font-weight: 900;
  line-height: 1;
}

.result-eyebrow {
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.result-panel h2 {
  max-width: 520px;
  margin-bottom: 12px;
  font-size: clamp(2.3rem, 11vw, 4.5rem);
  line-height: 0.98;
}

.result-detail {
  max-width: 480px;
  margin-bottom: 12px;
  font-size: clamp(1rem, 4.5vw, 1.25rem);
  font-weight: 750;
  line-height: 1.4;
}

.result-meta,
.result-seller,
.result-footer {
  max-width: 480px;
  margin-bottom: 10px;
  font-size: 0.82rem;
  line-height: 1.4;
}

.result-meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.result-seller {
  border: 1px solid currentColor;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 850;
}

.result-actions {
  width: min(100%, 430px);
  flex-direction: column;
  margin-top: 14px;
}

.result-footer {
  margin-top: 14px;
  margin-bottom: 0;
  opacity: 0.82;
}

.modal {
  align-items: center;
  padding: 18px;
}

.modal-card {
  width: min(100%, 500px);
  max-height: min(88dvh, 720px);
  overflow: auto;
  border-radius: 24px;
  padding: 20px;
}

.modal-header h2 {
  margin: 0;
}

.modal-header .step-indicator {
  margin-bottom: 4px;
}

.history-modal-card {
  width: min(100%, 720px);
  max-height: min(92dvh, 820px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-modal-card > .lead {
  margin-bottom: 12px;
  font-size: 0.86rem;
}

.history-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 8px;
}

.history-status {
  margin: 12px 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.history-status.error {
  color: #ffaaa5;
}

.history-list {
  min-height: 0;
  display: grid;
  gap: 8px;
  overflow: auto;
  margin: 0 0 12px;
  padding: 0 2px 2px 0;
  list-style: none;
  overscroll-behavior: contain;
}

.history-entry {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.055);
}

.history-entry-head,
.history-entry-main {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.history-entry time {
  color: #d8eafa;
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.history-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.history-badge.ok {
  color: #8af3c8;
  background: rgba(16, 185, 129, 0.17);
}

.history-badge.warn {
  color: #ffda63;
  background: rgba(245, 184, 0, 0.17);
}

.history-badge.bad {
  color: #ff9b96;
  background: rgba(239, 61, 50, 0.18);
}

.history-entry-code {
  overflow: hidden;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-entry-ticket {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.72rem;
}

.history-entry-device,
.history-entry-message {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.history-entry-device {
  color: #c7e8ff;
  font-weight: 750;
}

.manual-results {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.manual-result-button {
  width: 100%;
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  text-align: left;
}

.manual-result-button strong {
  font-size: 1rem;
}

.manual-result-button span {
  color: var(--muted);
  font-size: 0.76rem;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 18px;
  z-index: 200;
  width: min(calc(100% - 36px), 500px);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 14px;
  color: var(--ink);
  background: #0d2b48;
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
}

.toast.error {
  border-color: rgba(255, 113, 107, 0.52);
  background: #5f1718;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
}

noscript {
  display: block;
  margin: 20px;
  border-radius: 12px;
  padding: 14px;
  color: #fff;
  background: var(--red-dark);
  text-align: center;
}

@media (min-width: 540px) {
  .screen {
    padding: 24px;
  }

  .video-wrap {
    aspect-ratio: 1 / 1;
  }
}

@media (max-height: 720px) {
  .brand-logo-large {
    height: 62px;
  }

  .auth-card {
    padding-top: 18px;
    padding-bottom: 18px;
  }

  .result-panel {
    min-height: 82dvh;
    padding-top: 20px;
  }

  .result-icon {
    width: 78px;
    height: 78px;
    margin-bottom: 12px;
    font-size: 3rem;
  }
}

@media (max-width: 640px) {
  .auth-screen:focus-within {
    place-items: start center;
  }
}

@media (max-width: 380px) {
  .scan-header {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .scan-heading {
    order: -1;
    flex-basis: 100%;
  }

  .scan-header > .button {
    flex: 1;
  }

  .history-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
