:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f1eee7;
  --border: #e3ded3;
  --text: #1d1b16;
  --muted: #6c675c;
  --accent: #d1461f;
  --accent-ink: #ffffff;
  --good: #1f7a4d;
  --good-bg: #e3f3ea;
  --bad: #b3261e;
  --bad-bg: #fbe7e4;
  --warn: #8a5a00;
  --warn-bg: #fdf1d6;
  --bar: #d9d3c6;
  --bar-best: #1f7a4d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 25, 10, .05), 0 4px 16px rgba(30, 25, 10, .04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --surface: #1e1d17;
    --surface-2: #27251e;
    --border: #36332a;
    --text: #f0ece2;
    --muted: #a39d8f;
    --accent: #ff7a50;
    --accent-ink: #1a0f0a;
    --good: #5fd39a;
    --good-bg: #1b3326;
    --bad: #ff8a80;
    --bad-bg: #3a1e1b;
    --warn: #f3c46b;
    --warn-bg: #3a2f17;
    --bar: #3a372e;
    --bar-best: #5fd39a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); letter-spacing: -.02em; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* Topo */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.top-inner { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.logo { display: flex; align-items: center; gap: 8px; font-size: 1.2rem; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.logo b { color: var(--accent); }
.logo-mark svg { width: 26px; height: 26px; display: block; }
.logo-mark rect:first-child { fill: var(--muted); opacity: .5; }
.logo-mark rect:last-child { fill: var(--accent); }
.tabs { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: .92rem;
  padding: 8px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); }
@media (max-width: 560px) {
  .tabs { margin-left: 0; width: 100%; }
  .tabs button { flex: 1; padding: 7px 6px; font-size: .8rem; }
}

main { padding-top: 28px; padding-bottom: 40px; }
.intro { margin-bottom: 20px; max-width: 680px; }
.intro p { color: var(--muted); margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 16px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

/* Formulários */
input, select {
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  min-width: 0;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: .85rem; color: var(--muted); }
label input, label select { margin-top: 4px; }
label.inline { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
label.inline select { width: auto; margin: 0; }

.btn {
  font: inherit; font-weight: 600; font-size: .95rem;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.icon-btn {
  border: 0; background: none; color: var(--muted); font-size: 1.4rem; line-height: 1;
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--bad-bg); color: var(--bad); }

/* Linhas do comparador */
.rows-head, .row {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(0, 1fr) 84px minmax(0, 1.1fr) 36px;
  gap: 8px; align-items: center;
}
.rows-head { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 0 2px 6px; }
.row { margin-bottom: 8px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
@media (max-width: 640px) {
  .rows-head { display: none; }
  .row {
    grid-template-columns: 1fr 76px 36px;
    grid-template-areas: "name name del" "size unit unit" "price price price";
    padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
  }
  .row input, .row select { background: var(--surface); }
  .r-name { grid-area: name; } .r-size { grid-area: size; } .r-unit { grid-area: unit; }
  .r-price { grid-area: price; } .r-del { grid-area: del; }
}

/* Resultado */
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.result-head h2 { margin: 0; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; font: inherit; font-size: .82rem; color: var(--muted); padding: 5px 10px; border-radius: 999px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.verdict { margin: 10px 0 14px; }
.crown { color: var(--good); }
.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto 140px; gap: 12px; align-items: center;
  padding: 12px 8px; border-top: 1px solid var(--border);
}
.ranking li.best { background: var(--good-bg); border-radius: 10px; border-top-color: transparent; }
.ranking li.best + li { border-top-color: transparent; }
.rk-pos { font-weight: 700; color: var(--muted); text-align: center; }
.best .rk-pos { color: var(--good); }
.rk-title { font-weight: 600; overflow-wrap: anywhere; }
.rk-title .muted { font-weight: 400; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--bar); border-radius: 99px; }
.best .bar { background: color-mix(in srgb, var(--good) 15%, transparent); }
.best .bar span { background: var(--bar-best); }
.rk-unit { text-align: right; font-variant-numeric: tabular-nums; }
.rk-unit b { display: block; font-size: 1.05rem; }
.rk-unit small, .rk-diff small { color: var(--muted); font-size: .78rem; display: block; }
.rk-diff { text-align: right; }
@media (max-width: 640px) {
  .ranking li { grid-template-columns: 28px minmax(0, 1fr) auto; }
  .rk-diff { grid-column: 2 / -1; text-align: left; display: flex; gap: 8px; align-items: center; }
}

.tag {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); vertical-align: middle; white-space: nowrap;
}
.tag.good { background: var(--good); color: var(--surface); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }

.empty, .loading { color: var(--muted); padding: 14px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }
.loading::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px;
  border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.note { color: var(--muted); font-size: .82rem; margin: 10px 0 0; }

.alert { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); margin: 0 0 10px; font-size: .95rem; }
.alert.good { background: var(--good-bg); color: var(--good); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }

/* Busca */
.search-bar { display: flex; gap: 8px; padding: 10px; }
.search-bar input { font-size: 1.1rem; letter-spacing: .04em; }
.search-bar.compact { padding: 0; margin: 12px 0; border: 0; box-shadow: none; }
.search-bar.compact input { font-size: 1rem; }
@media (max-width: 520px) {
  .search-bar { flex-wrap: wrap; }
  .search-bar input { flex: 1 1 100%; }
  .search-bar .btn { flex: 1; }
}
.search-alt { display: flex; gap: 8px; align-items: center; margin: -4px 0 18px; font-size: .9rem; color: var(--muted); flex-wrap: wrap; }
.search-alt input { flex: 1; min-width: 180px; padding: 7px 10px; }

.scanner { position: relative; text-align: center; }
.scanner video { width: 100%; max-height: 360px; object-fit: cover; border-radius: 10px; background: #000; display: block; margin-bottom: 10px; }
.scanner-frame {
  position: absolute; left: 50%; top: calc(18px + 180px); transform: translate(-50%, -50%);
  width: min(70%, 320px); height: 120px; border: 2px solid var(--accent); border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.25); pointer-events: none;
}

.product { display: flex; gap: 16px; align-items: center; }
.product img, .noimg { width: 96px; height: 96px; object-fit: contain; border-radius: 10px; background: #fff; flex: none; border: 1px solid var(--border); }
.noimg { display: grid; place-items: center; color: var(--muted); background: var(--surface-2); font-size: 1.6rem; }
.noimg.sm { width: 48px; height: 48px; }
.product h2 { margin-bottom: 2px; }
.product p { margin: 0 0 4px; }
.product .qty { font-size: 1.3rem; font-weight: 700; }

.sizes { list-style: none; margin: 8px 0 0; padding: 0; }
.sizes li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.sizes li:first-child { border-top: 0; }
.sizes li.current .sz-qty { color: var(--accent); }
.sizes img { width: 48px; height: 48px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--border); flex: none; }
.sz-main { flex: 1; min-width: 0; }
.sz-qty { font-weight: 700; }
.sz-name { font-size: .9rem; overflow-wrap: anywhere; }
.sz-price { position: relative; width: 120px; flex: none; }
.sz-price .prefix { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .85rem; }
.sz-price input { padding-left: 34px; margin: 0; }

.timeline { list-style: none; padding: 0 0 0 14px; margin: 14px 0 0; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 4px 0 10px 10px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 10px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.tl-qty { font-weight: 700; margin-right: 8px; }

/* Antes × depois */
.ba-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 8px; }
.ba-col label { margin-bottom: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stats div { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.stats small { display: block; color: var(--muted); font-size: .75rem; }
.stats b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stats .neg { color: var(--bad); }
.stats .pos { color: var(--good); }
.hist-name { margin: 0 0 10px; }

.explainer ul { margin: 0; padding-left: 20px; }
.explainer li { margin-bottom: 6px; }

.foot { color: var(--muted); font-size: .85rem; padding-bottom: 32px; }
.tabs .short { display: none; }
@media (max-width: 560px) {
  .tabs .long { display: none; }
  .tabs .short { display: inline; }
}
