:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #efece3;
  --ink: #1f2a24;
  --ink-2: #55615a;
  --line: #e2ddd0;
  --tag: #ffd23f;
  --tag-ink: #1f2a24;
  --accent: #1f7a4d;
  --accent-ink: #ffffff;
  --sale: #c2410c;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 42, 36, .06), 0 6px 20px rgba(31, 42, 36, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714;
    --surface: #1b221e;
    --surface-2: #232b26;
    --ink: #eef1ec;
    --ink-2: #a3ada6;
    --line: #2e3832;
    --accent: #3fb47a;
    --accent-ink: #0d1410;
    --sale: #fb923c;
    --danger: #f97066;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
main { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 8px 16px 32px; }
[hidden] { display: none !important; }
a { color: var(--accent); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  background: none; border: 0; padding: 0; color: var(--ink); cursor: pointer;
  font: 700 19px/1 "Space Grotesk", Inter, sans-serif; letter-spacing: -.01em;
}
.brand img { border-radius: 7px; }

.banner {
  max-width: 560px; margin: 10px auto 0; padding: 10px 14px;
  border-radius: 10px; background: var(--surface-2); color: var(--ink-2); font-size: 14px;
  width: calc(100% - 32px);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 12px; padding: 11px 16px;
  font: 600 15px/1 Inter, sans-serif; cursor: pointer; color: var(--ink);
  background: var(--surface); transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.big { width: 100%; padding: 16px; font-size: 17px; border-radius: 14px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 7px 14px; font: 600 14px/1 Inter, sans-serif; cursor: pointer;
}
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.back { margin: 8px 0 4px; display: inline-block; }

/* Home */
.hero { padding: 18px 0 8px; }
.hero h1 {
  font: 700 32px/1.08 "Space Grotesk", Inter, sans-serif; letter-spacing: -.02em; margin: 6px 0 10px;
}
.hero p { color: var(--ink-2); margin: 0 0 18px; }
.manual { display: flex; gap: 8px; margin-top: 12px; }
.manual input { flex: 1; }

input:not([type=checkbox]) {
  width: 100%; min-width: 0;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 16px Inter, sans-serif;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.shopping {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 14px 0 0; padding: 10px 14px; border-radius: 12px;
  background: var(--surface-2); font-size: 14px; color: var(--ink-2);
}
.shopping strong { color: var(--ink); }
.shopping .link { margin-left: auto; font-size: 14px; }

.section-title {
  font: 700 18px/1.2 "Space Grotesk", Inter, sans-serif; margin: 26px 0 10px;
}
.section-title.small { font-size: 15px; margin-top: 22px; }
.muted { color: var(--ink-2); font-weight: 400; }
.page-title { font: 700 26px/1.1 "Space Grotesk", Inter, sans-serif; margin: 10px 0 6px; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); width: 100%; text-align: left; color: var(--ink);
  font: inherit;
}
button.item { cursor: pointer; }
.item .thumb {
  width: 44px; height: 44px; border-radius: 10px; flex: none; object-fit: contain;
  background: var(--surface-2);
}
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.best { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 6px; margin-left: 6px; vertical-align: 1px;
}
.badge.best { background: var(--accent); color: var(--accent-ink); }
.badge.sale { background: color-mix(in srgb, var(--sale) 16%, transparent); color: var(--sale); }
.badge.old  { background: var(--surface-2); color: var(--ink-2); }

/* The price-tag look */
.tag {
  position: relative; flex: none;
  background: var(--tag); color: var(--tag-ink);
  font: 700 18px/1 "Space Grotesk", Inter, sans-serif; letter-spacing: -.01em;
  padding: 8px 12px 8px 18px;
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 10px 100%, 0 50%);
  border-radius: 4px;
}
.tag::before {
  content: ""; position: absolute; left: 7px; top: 50%; width: 5px; height: 5px; margin-top: -2.5px;
  border-radius: 50%; background: color-mix(in srgb, var(--tag-ink) 55%, transparent);
}
.tag sup { font-size: 11px; vertical-align: 6px; }

.empty {
  padding: 18px; border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--ink-2); font-size: 14px; text-align: center;
}
.skeleton {
  height: 68px; border-radius: var(--radius); background: var(--surface-2);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .5; } }

/* Product */
.product {
  display: flex; gap: 14px; align-items: center; margin: 10px 0 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px;
  box-shadow: var(--shadow);
}
.product img, .product .noimg {
  width: 84px; height: 84px; border-radius: 12px; object-fit: contain; background: #fff; flex: none;
}
.product .noimg { background: var(--surface-2); display: grid; place-items: center; color: var(--ink-2); font-size: 12px; }
.product h1 { font: 700 20px/1.15 "Space Grotesk", Inter, sans-serif; margin: 0 0 4px; }
.product .meta { font-size: 14px; color: var(--ink-2); }
.product .code { font: 12px ui-monospace, Menlo, monospace; color: var(--ink-2); margin-top: 6px; }
.summary {
  display: flex; gap: 8px; margin: -4px 0 4px; font-size: 13px; color: var(--ink-2);
}
.summary b { color: var(--ink); }

/* Scanner */
.scan-wrap { display: flex; flex-direction: column; gap: 14px; padding-top: 10px; }
#reader { width: 100%; border-radius: 18px; overflow: hidden; background: #000; min-height: 260px; }
#reader video { border-radius: 18px; }
.scan-hint { color: var(--ink-2); text-align: center; margin: 0; font-size: 14px; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 12, .45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto;
  max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { font: 700 22px/1.1 "Space Grotesk", Inter, sans-serif; margin: 0; }
.sheet #sheetProduct { margin: 4px 0 0; font-size: 14px; }

.price-input {
  display: flex; align-items: center; gap: 4px;
  background: var(--tag); color: var(--tag-ink); border-radius: 14px; padding: 6px 14px;
}
.price-input span { font: 700 34px/1 "Space Grotesk", Inter, sans-serif; }
.price-input input {
  border: 0; background: transparent; color: var(--tag-ink); padding: 8px 0;
  font: 700 38px/1 "Space Grotesk", Inter, sans-serif; letter-spacing: -.02em;
}
.price-input input::placeholder { color: color-mix(in srgb, var(--tag-ink) 40%, transparent); }
.price-input input:focus { outline: none; }

.store-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; font-weight: 600; margin-top: 2px; }
.store-list { display: flex; flex-direction: column; gap: 6px; max-height: 38dvh; overflow-y: auto; }
.store {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
}
.store .body { flex: 1; min-width: 0; }
.store .title { font-weight: 600; }
.store .sub { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.store .dist { font-size: 12px; color: var(--ink-2); flex: none; }
.store[aria-pressed=true] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.store[aria-pressed=true] .title::after { content: "  ✓"; color: var(--accent); }
.manual-store summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; }
.manual-store .row { margin-top: 8px; }
.manual-store .row > .btn { flex: none; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; max-width: calc(100% - 32px); transition: all .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

.foot {
  max-width: 560px; margin: 0 auto; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  font-size: 12px; color: var(--ink-2); text-align: center;
}
