:root {
  --bg-base: #0B0F14;
  --bg-elevated: #131A22;
  --accent: #38BDF8;
  --valid: #2FBF71;
  --invalid: #E3432B;
  --text: #E8ECF0;
  --muted: #7C8A99;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-base);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  transition: background-color .25s ease;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--bg-elevated);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.brand-text {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--text);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.kassa-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid rgba(255,255,255,.12);
  padding: 3px 8px;
  border-radius: 6px;
}
.conn-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--muted);
  border: none;
  padding: 0;
}
.conn-dot.ok { background: var(--valid); box-shadow: 0 0 6px var(--valid); }
.conn-dot.bad { background: var(--invalid); box-shadow: 0 0 6px var(--invalid); }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  padding: 4px;
}

/* ---------- camera / scan area ---------- */
.scan-area {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
}
#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.viewfinder {
  position: absolute;
  top: 50%; left: 50%;
  width: min(78vw, 78vh);
  height: min(78vw, 78vh);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.corner {
  position: absolute;
  width: 34px; height: 34px;
  border-color: var(--accent);
  border-style: solid;
  border-width: 0;
  filter: drop-shadow(0 0 4px rgba(56,189,248,.6));
}
.corner.tl { top: 0; left: 0; border-top-width: 4px; border-left-width: 4px; border-top-left-radius: 10px; }
.corner.tr { top: 0; right: 0; border-top-width: 4px; border-right-width: 4px; border-top-right-radius: 10px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 4px; border-left-width: 4px; border-bottom-left-radius: 10px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 4px; border-right-width: 4px; border-bottom-right-radius: 10px; }

.scanline {
  position: absolute;
  left: 6%; right: 6%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  top: 8%;
  animation: scanmove 2.2s ease-in-out infinite;
  opacity: .9;
}
@keyframes scanmove {
  0% { top: 8%; }
  50% { top: 92%; }
  100% { top: 8%; }
}

.scan-hint {
  position: absolute;
  left: 0; right: 0;
  bottom: 18px;
  text-align: center;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  z-index: 2;
}

.no-camera {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  gap: 6px;
  background: var(--bg-base);
}

/* ---------- manual input ---------- */
.manual-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--bg-elevated);
}
.manual-form input {
  flex: 1;
  background: var(--bg-base);
  border: 1px solid rgba(255,255,255,.14);
  color: var(--text);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.manual-form button {
  background: var(--accent);
  border: none;
  color: #051018;
  font-weight: 700;
  padding: 0 18px;
  border-radius: 8px;
  font-size: 14px;
}

/* ---------- result overlay ---------- */
.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px;
  text-align: center;
}
.result-overlay.hidden { display: none; }

.result-overlay.valid { background: var(--valid); color: #052015; }
.result-overlay.invalid { background: var(--invalid); color: #2b0a06; }

.result-icon {
  font-size: 84px;
  line-height: 1;
  font-weight: 800;
}
.result-title {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: .03em;
}
.result-detail {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  line-height: 1.6;
  opacity: .92;
  max-width: 320px;
}
.ok-btn {
  margin-top: 18px;
  min-width: 180px;
  padding: 16px 28px;
  border-radius: 12px;
  border: none;
  background: rgba(0,0,0,.22);
  color: inherit;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .05em;
}
.ok-btn:active { background: rgba(0,0,0,.35); }

/* ---------- settings ---------- */
.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
}
.settings-panel.hidden { display: none; }
.settings-card {
  width: 100%;
  background: var(--bg-elevated);
  border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.settings-card h2 { margin: 0; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.field input {
  background: var(--bg-base);
  border: 1px solid rgba(255,255,255,.14);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}
.settings-actions { display: flex; gap: 10px; margin-top: 4px; }
.primary-btn {
  flex: 1;
  background: var(--accent);
  color: #051018;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
}
.ghost-btn {
  flex: 1;
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(255,255,255,.2);
  padding: 12px;
  border-radius: 10px;
}
.muted { color: var(--muted); }
.small { font-size: 11px; }
.hidden { display: none !important; }
