:root {
  --bg: #000;
  --fg: #fff;
  --muted: #aaa;
  --accent: #0a66c2;
  --danger: #c2300a;
  --card: #1c1c1e;
  --border: #2c2c2e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font-family: inherit;
  font-size: 16px;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button.primary { background: var(--accent); font-weight: 600; }
button.secondary { background: #333; }
button.danger { background: var(--danger); }
button.link { background: transparent; color: var(--accent); padding: 8px; }
button.big { font-size: 18px; padding: 16px 28px; }
button.pill { background: rgba(0,0,0,0.55); color: white; border-radius: 999px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.18); }
button.navBtn {
  font-size: 17px;
  font-weight: 600;
  padding: 12px 18px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  color: var(--accent);
  border-radius: 12px;
}
button.navBtn.pill { background: rgba(0,0,0,0.55); color: white; padding: 12px 18px; }
.navIcon { font-size: 20px; line-height: 1; }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 8px;
  margin-left: 4px;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.view { position: fixed; inset: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

#cameraView { background: black; }

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#cameraOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}
#cameraOverlay > * { pointer-events: auto; }

.topBar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 0;
}

#reticle {
  align-self: center;
  margin: auto;
  width: 70vmin;
  height: 70vmin;
  max-width: 320px;
  max-height: 320px;
  border: 3px solid rgba(255,255,255,0.85);
  border-radius: 28px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
  pointer-events: none;
  transition: border-color 0.15s, transform 0.15s;
}
#reticle.hit { border-color: #4ade80; transform: scale(1.04); }

.hint {
  text-align: center;
  padding: 0 24px 12px;
  color: rgba(255,255,255,0.85);
  font-size: 14px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

.bottomBar {
  display: flex;
  justify-content: center;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 28px);
}

.shutter {
  width: 76px;
  height: 76px;
  border-radius: 999px;
  background: white;
  border: 5px solid rgba(255,255,255,0.4);
  background-clip: padding-box;
  padding: 0;
}
.shutter:active { background: #ddd; }

#startOverlay {
  position: absolute;
  inset: 0;
  background: black;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
#startOverlay h1 { font-size: 32px; margin: 0 0 8px; }
#startOverlay p { color: var(--muted); margin: 0 0 24px; }
#startOverlay[hidden] { display: none; }

#formView { background: var(--bg); overflow-y: auto; }
.formHeader, .listHeader {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.formHeader h2, .listHeader h2 { margin: 0; font-size: 17px; text-align: center; }
#listTitle {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}
#listTitle:active { background: var(--card); }
.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 220px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.7);
  z-index: 60;
}
.dropdown[hidden] { display: none; }
.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
}
.dropdown-item:active { background: rgba(255,255,255,0.06); }
.dropdown-item.danger { color: #ff6b4a; }
.formHeader > :first-child, .listHeader > :first-child { justify-self: start; }
.formHeader > :last-child, .listHeader > :last-child { justify-self: end; }

.formBody { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.formBody label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.formBody input, .formBody textarea {
  font-family: inherit;
  font-size: 17px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.formBody input:focus, .formBody textarea:focus {
  outline: none;
  border-color: var(--accent);
}

#badgePreview {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 12px;
  background: #111;
}

.formActions { display: flex; gap: 10px; margin-top: 8px; }
.formActions button { flex: 1; }

#listView { background: var(--bg); overflow-y: auto; }
#leadsList { list-style: none; padding: 0; margin: 0; flex: 1; overflow-y: auto; }
#leadsList li {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.li-thumb {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  color: var(--muted);
}
.li-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.li-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.li-row1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.li-name {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  word-break: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
}
.li-name:active { opacity: 0.7; }
.li-meta { color: var(--muted); font-size: 12px; }
.li-url { font-size: 12px; color: var(--muted); word-break: break-all; }
.li-notes { font-size: 14px; color: #ddd; margin-top: 2px; }
.li-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }
.li-actions .li-edit {
  padding: 6px 12px;
  font-size: 13px;
  min-height: 32px;
  background: var(--card);
  color: var(--accent);
  border-radius: 8px;
  font-weight: 600;
}
.iconBtn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.iconBtn svg { display: block; }
.iconBtn.danger { color: #ff6b4a; background: transparent; }
.iconBtn.danger:active { background: rgba(255,107,74,0.15); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 120px);
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 100;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast[hidden] { opacity: 0; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
}
.lightbox-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 14px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
  color: white;
  font-size: 20px;
  font-weight: 600;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#leadsList .li-thumb { cursor: pointer; }
#badgePreview { cursor: pointer; }

#myQrView { background: var(--bg); }
.myQrBody {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
  overflow-y: auto;
}
.myQrCode {
  width: min(78vw, 380px);
  aspect-ratio: 1;
  background: white;
  padding: 16px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.myQrCode svg { width: 100%; height: 100%; display: block; }
.myQrCode .emptyHint { color: #555; text-align: center; padding: 24px; font-size: 15px; }
.myQrUrl {
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
  text-align: center;
  max-width: 88vw;
}
.myQrFooter {
  display: flex;
  justify-content: center;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.iconBtn.settings {
  width: 48px;
  height: 48px;
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--border);
}

.dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 150;
}
.dialog[hidden] { display: none; }
.dialog-card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  max-width: 380px;
  width: 100%;
}
.dialog-card h3 { margin: 0 0 8px; font-size: 18px; }
.dialog-card p { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.dialog-card input {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 16px;
  padding: 12px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
}
.dialog-card input:focus { outline: none; border-color: var(--accent); }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }
.dialog-actions button { padding: 10px 18px; }
