:root {
  --bg: #0f1714;
  --surface: #18231f;
  --surface-2: #213029;
  --line: #2c3d35;
  --text: #eef5f1;
  --muted: #93a89e;
  --accent: #4fd1a1;
  --accent-ink: #06261a;
  --warn: #f5b84a;
  --bad: #ff7a6b;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html { height: 100%; }
body { min-height: 100%; min-height: 100dvh; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; letter-spacing: .2px; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 12px; color: var(--text); }
.icon-btn:active { background: var(--surface-2); }

.view { flex: 1; display: flex; flex-direction: column; padding: 0 14px calc(18px + var(--safe-b)); gap: 12px; }

/* Scan view */
#scanView { padding-bottom: calc(12px + var(--safe-b)); }
.name-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 0 12px;
}
.name-search:focus-within { border-color: var(--accent); }
.name-search svg { color: var(--muted); flex: none; }
.name-search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; padding: 13px 0; font-size: 16px; }
.cat-chips { display: flex; gap: 6px; overflow-x: auto; margin: -2px -14px 0; padding: 0 14px 2px; scrollbar-width: none; }
.cat-chips::-webkit-scrollbar { display: none; }
.cat-chips button {
  flex: none; background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  padding: 6px 12px; border-radius: 99px; font-size: 13px;
}
.cat-chips button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.alt-queries button.ai { border-style: solid; border-color: var(--accent); color: var(--accent); }
.camera {
  position: relative; flex: 1; min-height: 300px;
  border-radius: 22px; overflow: hidden; background: #000;
}
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.frame { position: absolute; inset: 14%; pointer-events: none; }
.frame span { position: absolute; width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.85); }
.frame span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 10px 0 0 0; }
.frame span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 10px 0 0; }
.frame span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 10px; }
.frame span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 10px 0; }
.cam-msg {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; padding: 24px; background: #0b100e; color: var(--muted);
}
.chip-float {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(0,0,0,.6); color: #fff; padding: 7px 14px; border-radius: 99px; font-size: 13px; white-space: nowrap;
  transition: background .2s;
}
.chip-float.found { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.hint-row input, .search-row input, .form input[type=password], .form select {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
.hint-row input:focus, .search-row input:focus { border-color: var(--accent); }
.controls { display: flex; align-items: center; justify-content: space-around; padding: 4px 0; }
.ctl {
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 76px;
  background: none; border: 0; color: var(--muted); font-size: 12px; cursor: pointer;
}
.ctl svg { width: 28px; height: 28px; color: var(--text); }
.shutter {
  width: 78px; height: 78px; border-radius: 50%; border: 4px solid var(--text); background: none; padding: 5px;
}
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--accent); transition: transform .1s; }
.shutter:active span { transform: scale(.88); }

/* Generic */
.btn {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px;
  padding: 12px 18px; font-weight: 650; cursor: pointer; white-space: nowrap;
}
.btn:active { filter: brightness(.9); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.wide { width: 100%; margin-top: 6px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 8px 2px 0; font-weight: 600; }
.nomargin { margin: 0 0 8px; }
.tag { font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.tag:empty { display: none; }
.tag.high { background: #164a37; color: #8ff0c6; }
.tag.medium { background: #4a3a14; color: #f5d08a; }
.tag.low { background: #4d1f1a; color: #ffb1a7; }

/* Result */
.item-card { display: flex; gap: 14px; align-items: flex-start; }
.item-photo { width: 92px; height: 92px; object-fit: cover; border-radius: 12px; flex: none; background: #000; }
.item-info { min-width: 0; flex: 1; }
.item-top { display: flex; gap: 6px; flex-wrap: wrap; }
.item-info h2 { margin: 6px 0 6px; font-size: 20px; line-height: 1.2; }
.details { display: flex; flex-wrap: wrap; gap: 6px; }
.details span { font-size: 13px; color: var(--text); background: var(--bg); border: 1px solid var(--line); padding: 2px 8px; border-radius: 8px; }
.status { padding: 12px 14px; border-radius: 12px; background: #3a2e14; color: #ffdca0; font-size: 14px; }
.status.error { background: #45201b; color: #ffc2b9; }
.search-row { display: flex; gap: 8px; }
.alt-queries { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -4px; }
.alt-queries button {
  background: none; border: 1px dashed var(--line); color: var(--muted); padding: 5px 10px; border-radius: 99px; font-size: 13px;
}
.price-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--text); }
.price-main { font-size: 46px; font-weight: 750; letter-spacing: -1px; margin: 4px 0 8px; }
.range-bar { position: relative; height: 10px; border-radius: 99px; background: var(--bg); }
#rangeFill { position: absolute; top: 0; bottom: 0; border-radius: 99px; background: color-mix(in srgb, var(--accent) 45%, transparent); }
#rangeMid { position: absolute; top: -4px; width: 4px; height: 18px; border-radius: 2px; background: var(--accent); transform: translateX(-2px); }
.range-labels { display: flex; justify-content: space-between; margin-top: 6px; font-size: 14px; }
.links { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.links a {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  color: var(--text); text-decoration: none; font-weight: 600; font-size: 15px;
}
.links a.primary { grid-column: 1 / -1; background: var(--accent); color: var(--accent-ink); border-color: transparent; font-size: 16px; }
.links a svg { width: 18px; height: 18px; opacity: .7; }
.notes { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 15px; }
.listings { display: grid; gap: 8px; }
.listing {
  display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px;
}
.listing img, .listing .noimg { width: 58px; height: 58px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-2); }
.listing .lt { flex: 1; min-width: 0; font-size: 14px; }
.listing .lt div { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.listing .lp { font-weight: 700; text-align: right; white-space: nowrap; }
.listing .lp small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

/* History */
.history { display: grid; gap: 8px; }
.history button {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px;
}
.history img, .history .noimg { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-2); }
.history .ht { flex: 1; min-width: 0; }
.history .ht b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .hp { font-weight: 700; }

/* Settings */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-weight: 600; font-size: 15px; }
.form label.check { grid-template-columns: auto 1fr; align-items: center; font-weight: 500; }
.form input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.health { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 15px; }
.health li::before { content: "● "; }
.health li.ok::before { color: var(--accent); }
.health li.off::before { color: var(--bad); }
.health li.info::before { color: var(--warn); }

/* Overlays */
.loading {
  position: fixed; inset: 0; z-index: 20; background: rgba(5,10,8,.75); backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
}
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw;
}
