:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #17201b;
  --muted: #5d6862;
  --border: #dfe3df;
  --brand: #0f3d2e;
  --brand-ink: #ffffff;
  --focus: #2563eb;

  /* Verdict colours: impact levels as agreed (low=yellow, medium=orange, high=red) */
  --low: #eab308;      --low-bg: #fef9c3;      --low-ink: #713f12;
  --medium: #f97316;   --medium-bg: #ffedd5;   --medium-ink: #7c2d12;
  --high: #dc2626;     --high-bg: #fee2e2;     --high-ink: #7f1d1d;
  --vhigh: #7f1d1d;    --vhigh-bg: #fecaca;    --vhigh-ink: #450a0a;
  --clear: #16a34a;    --clear-bg: #dcfce7;    --clear-ink: #14532d;
  --unknown: #6b7280;  --unknown-bg: #eceef0;  --unknown-ink: #1f2937;

  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1210;
    --surface: #161d1a;
    --text: #e8ece9;
    --muted: #9aa59f;
    --border: #2a3430;
    --brand: #1f6b50;
    --low-bg: #3a2f06;      --low-ink: #fde68a;
    --medium-bg: #3d1d07;   --medium-ink: #fed7aa;
    --high-bg: #3f1010;     --high-ink: #fecaca;
    --vhigh: #b91c1c;       --vhigh-bg: #2a0606; --vhigh-ink: #fecaca;
    --clear-bg: #0b2e18;    --clear-ink: #bbf7d0;
    --unknown-bg: #252b29;  --unknown-ink: #e5e7eb;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; margin-top: 1.4em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { font-size: 1.1rem; margin: 0; letter-spacing: .01em; }
.lang { display: flex; border: 1px solid rgb(255 255 255 / .35); border-radius: 999px; overflow: hidden; }
.lang button { background: none; border: 0; color: inherit; padding: 4px 12px; font-size: .8rem; cursor: pointer; }
.lang button[aria-pressed="true"] { background: rgb(255 255 255 / .2); font-weight: 600; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.big { width: 100%; min-height: 64px; font-size: 1.1rem; }
.btn.big svg { width: 28px; height: 28px; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; font-size: .875rem; padding: 0 12px; }
input[type="search"], input:not([type]), input[inputmode] {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}

/* Scan */
.scan-start { display: grid; gap: 16px; }
.manual label { display: block; color: var(--muted); font-size: .875rem; margin-bottom: 4px; text-align: center; }
.notice { margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--unknown-bg); color: var(--unknown-ink); font-size: .9rem; }
.camera {
  position: relative; overflow: hidden; border-radius: var(--radius);
  background: #000; aspect-ratio: 3 / 4; max-height: 62dvh; margin-bottom: 16px;
}
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.guide { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.guide span {
  width: 78%; height: 26%; border-radius: 12px;
  box-shadow: 0 0 0 9999px rgb(0 0 0 / .35); border: 2px solid rgb(255 255 255 / .9);
}
.aim { position: absolute; top: 12px; left: 0; right: 0; margin: 0; text-align: center; color: #fff; font-size: .9rem; text-shadow: 0 1px 2px #000; }
.camera-actions { position: absolute; bottom: 12px; left: 12px; right: 12px; display: flex; gap: 8px; justify-content: center; }
.camera-actions .btn { color: #fff; border-color: rgb(255 255 255 / .6); background: rgb(0 0 0 / .35); }

/* Verdict */
.verdict {
  border-radius: var(--radius); padding: 16px; margin: 16px 0 12px;
  border-left: 8px solid var(--c); background: var(--c-bg); color: var(--c-ink);
}
.verdict h2 { margin: 0 0 4px; font-size: 1.3rem; display: flex; gap: 10px; align-items: center; }
.verdict p { margin: 0; }
.verdict .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); flex: none; }
.v-low       { --c: var(--low);     --c-bg: var(--low-bg);     --c-ink: var(--low-ink); }
.v-medium    { --c: var(--medium);  --c-bg: var(--medium-bg);  --c-ink: var(--medium-ink); }
.v-high      { --c: var(--high);    --c-bg: var(--high-bg);    --c-ink: var(--high-ink); }
.v-very-high { --c: var(--vhigh);   --c-bg: var(--vhigh-bg);   --c-ink: var(--vhigh-ink); }
.v-clear     { --c: var(--clear);   --c-bg: var(--clear-bg);   --c-ink: var(--clear-ink); }
.v-unknown   { --c: var(--unknown); --c-bg: var(--unknown-bg); --c-ink: var(--unknown-ink); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700;
  background: var(--c); color: #fff; white-space: nowrap;
}
.v-low .badge, .badge.v-low { color: #422006; }
.pill { display: inline-block; margin-top: 10px; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--high); color: #fff; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.product { display: flex; gap: 12px; align-items: flex-start; }
.product img { width: 64px; height: 64px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
.product dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: .9rem; }
.product dt { color: var(--muted); }
.product dd { margin: 0; overflow-wrap: anywhere; }
.product .name { font-weight: 600; margin: 0 0 4px; }

.company { border-left: 6px solid var(--c); }
.company header { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.company h3 { margin: 0; font-size: 1.05rem; }
.company .meta { font-size: .85rem; color: var(--muted); margin: 2px 0 8px; }
.company p { margin: 6px 0; font-size: .92rem; }
.company .matched { font-size: .85rem; }
.company .matched em { font-style: normal; font-weight: 600; }
.muted-card { --c: var(--unknown); opacity: .85; }
.muted-card .badge { background: var(--unknown); color: #fff; }
.caveat { font-size: .85rem; padding: 8px 10px; border-radius: 10px; background: var(--unknown-bg); color: var(--unknown-ink); margin: 8px 0; }
.company ul { margin: 4px 0; padding-left: 18px; font-size: .88rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font-size: .78rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); }
details summary { cursor: pointer; font-size: .88rem; color: var(--muted); margin-top: 6px; }

form.add { display: grid; gap: 8px; }
form.add label { font-size: .875rem; color: var(--muted); }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions .btn { flex: 1; }

/* Why? */
.why { margin-top: 8px; }
.why h2 { font-size: 1.1rem; margin-bottom: .4em; }
.why p { margin: 0 0 .7em; font-size: .93rem; }
.why ul { margin: 6px 0 0; padding-left: 18px; font-size: .88rem; }
.why li { margin-bottom: 4px; }

/* Search */
#view-search input { margin-bottom: 4px; }
#search-results { margin-top: 12px; }

/* History */
.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: flex; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
}
.history .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.history .info { flex: 1; min-width: 0; }
.history .info b, .history .info span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .info span { font-size: .8rem; color: var(--muted); }
.history time { font-size: .75rem; color: var(--muted); white-space: nowrap; }

/* Legend */
.legend { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.legend .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); }

/* Tabs */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabs button { background: none; border: 0; display: grid; place-items: center; gap: 2px; font-size: .72rem; color: var(--muted); cursor: pointer; padding: 6px 0; }
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--brand); font-weight: 700; }
@media (prefers-color-scheme: dark) { .tabs button[aria-current="page"] { color: #6ee7b7; } }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
.loading { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 24px; color: var(--muted); }
