/*
 * Compra sob Controle — estilos.
 * Ideia visual: a etiqueta amarela de gôndola é o saldo (o elemento que se vê de relance no corredor);
 * o resto é papel de cupom fiscal: neutro, tinta escura, números alinhados.
 * Situação do preço nunca depende só de cor: conferido tem ✓, estimado tem tracejado.
 */
:root {
  --paper: #f1f3f2;
  --card: #ffffff;
  --ink: #161a1d;
  --muted: #566267;
  --line: #cfd6d8;
  --tag: #ffd60a;
  --tag-ink: #1a1600;
  --ok: #0f6b4f;
  --ok-bg: #dcf1e8;
  --warn: #8a4b00;
  --warn-bg: #ffe9c2;
  --over: #a82015;
  --over-bg: #ffd9d3;
  --focus: #0b57d0;
  --radius: 14px;
  --bar-h: 168px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1214;
    --card: #181c1f;
    --ink: #eceff0;
    --muted: #9aa6ab;
    --line: #2c3338;
    --ok: #62d6a6;
    --ok-bg: #12382c;
    --warn: #ffc56b;
    --warn-bg: #3d2b0a;
    --over: #ff9f94;
    --over-bg: #4a1712;
    --focus: #8ab4f8;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.screen { padding-bottom: 32px; }
.screen.has-bar { padding-bottom: calc(var(--bar-h) + 24px); }

/* ---------- topo ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 0 10px; }
.brand { font-weight: 800; letter-spacing: -0.01em; font-size: 1.15rem; }
.top .title { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { color: var(--muted); font-size: 0.85rem; }
.nav { display: flex; gap: 4px; }
.link-btn {
  background: none; border: 0; padding: 10px 10px; border-radius: 10px; font-weight: 600; color: var(--ink);
  min-height: 44px;
}
.link-btn:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }

/* ---------- botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 2px solid var(--ink);
  background: var(--card); font-weight: 700;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.tag { background: var(--tag); color: var(--tag-ink); border-color: var(--tag-ink); }
.btn.danger { border-color: var(--over); color: var(--over); }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 0.9rem; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ---------- etiqueta de saldo ---------- */
.tag-card {
  position: relative;
  background: var(--tag); color: var(--tag-ink);
  border: 2px solid var(--tag-ink);
  border-radius: 6px 22px 22px 6px;
  padding: 18px 20px 16px 52px;
  margin-top: 4px;
}
.tag-card::before { /* furo da etiqueta */
  content: ""; position: absolute; left: 16px; top: 50%; width: 18px; height: 18px; margin-top: -9px;
  border-radius: 50%; background: var(--paper); border: 2px solid var(--tag-ink);
}
.tag-card .label { font-size: 0.9rem; font-weight: 700; }
.tag-card .big { font-size: clamp(2.2rem, 11vw, 3rem); font-weight: 900; line-height: 1.05; letter-spacing: -0.02em; }
.tag-card .detail { font-size: 0.9rem; margin-top: 4px; }
.meter { height: 10px; border-radius: 6px; background: rgba(26, 22, 0, 0.18); margin-top: 10px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--tag-ink); border-radius: 6px; transition: width 0.25s ease; }
.tag-card.over { background: var(--over-bg); color: var(--over); border-color: var(--over); }
.tag-card.over .meter { background: rgba(168, 32, 21, 0.2); }
.tag-card.over .meter > span { background: var(--over); }
.tag-card.warn .meter > span { background: var(--warn); }
@media (prefers-color-scheme: dark) {
  .tag-card.over { color: #ffd9d3; border-color: #ff9f94; }
  .tag-card.over .meter > span { background: #ff9f94; }
}
.tag-card .set-budget { margin-top: 8px; }
.tag-card .btn { background: transparent; color: inherit; border-color: currentColor; }

.alert { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; font-weight: 600; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.over { background: var(--over-bg); color: var(--over); }

/* ---------- confiança do total ---------- */
.trust { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.trust > div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.trust .k { font-size: 0.78rem; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.trust .v { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.trust-note { color: var(--muted); font-size: 0.85rem; margin: 6px 0 0; }

/* ---------- chips de situação do preço ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; border: 1.5px solid transparent; white-space: nowrap; }
.chip.confirmed { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.chip.informed { background: transparent; color: var(--ink); border-color: var(--ink); }
.chip.estimated {
  color: var(--warn); border: 1.5px dashed var(--warn);
  background: repeating-linear-gradient(135deg, var(--warn-bg) 0 5px, transparent 5px 10px);
}
button.chip { cursor: pointer; min-height: 28px; }

/* ---------- lista (cupom) ---------- */
.section-title { font-weight: 800; font-size: 1rem; margin: 18px 0 6px; display: flex; justify-content: space-between; align-items: baseline; }
.section-title .n { color: var(--muted); font-weight: 600; font-size: 0.88rem; }
.receipt { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.receipt > li { padding: 12px 14px; border-bottom: 1px dashed var(--line); }
.receipt > li:last-child { border-bottom: 0; }
.line-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.line-name { font-weight: 600; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.line-total { font-weight: 800; white-space: nowrap; }
.line-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.line-sub { color: var(--muted); font-size: 0.88rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.diverge { margin-top: 6px; font-size: 0.85rem; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 6px 8px; }
.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--paper); }
.stepper button { width: 44px; height: 40px; border: 0; background: transparent; font-size: 1.25rem; font-weight: 700; }
.stepper button:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.stepper output { min-width: 34px; text-align: center; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }

/* ---------- barra de ações fixa ---------- */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: color-mix(in srgb, var(--paper) 94%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
}
.bar .wrap { display: grid; gap: 8px; }
.bar .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bar .scan { min-height: 60px; font-size: 1.15rem; }

/* ---------- formulários ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.card h2 { margin: 0 0 10px; font-size: 1.05rem; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > label, .field > .lab { font-weight: 700; font-size: 0.92rem; }
.hint { color: var(--muted); font-size: 0.85rem; }
.input {
  width: 100%; min-height: 48px; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--line);
  background: var(--paper);
}
.input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }
.input.price { font-size: 1.6rem; font-weight: 800; }
.error { color: var(--over); font-weight: 600; font-size: 0.9rem; min-height: 1.2em; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.install { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px 14px; margin-top: 14px; font-size: 0.92rem; }

/* ---------- histórico ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list button.item {
  width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: grid; gap: 2px;
}
.item .a { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; }
.item .b { color: var(--muted); font-size: 0.88rem; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; text-align: right; }

/* ---------- folha (diálogo) ---------- */
dialog.sheet {
  width: min(560px, 100vw); max-width: 100vw; max-height: 92dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--paper); color: var(--ink); overflow: auto;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
.sheet-in { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.viewfinder { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 4 / 3; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewfinder .guide {
  position: absolute; left: 8%; right: 8%; top: 34%; bottom: 34%;
  border: 3px solid var(--tag); border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
}
.viewfinder .guide::after { content: ""; position: absolute; left: 6px; right: 6px; top: 50%; height: 2px; background: #ff4d3d; }
.scan-status { margin: 10px 0; font-weight: 600; min-height: 1.4em; }
.suggest { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.suggest .big { font-size: 1.3rem; font-weight: 800; }
.suggest.none { color: var(--muted); }
.live-diff { font-weight: 600; font-size: 0.9rem; border-radius: 8px; padding: 6px 8px; background: var(--warn-bg); color: var(--warn); }
.product-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ean { color: var(--muted); font-size: 0.85rem; }

/* ---------- aviso rápido ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bar-h) + 8px); z-index: 50;
  max-width: min(520px, calc(100vw - 24px)); display: flex; gap: 12px; align-items: center;
  background: var(--ink); color: var(--paper); border-radius: 12px; padding: 12px 14px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}
#toast.no-bar { bottom: 20px; }
#toast button { background: none; border: 0; color: var(--tag); font-weight: 800; padding: 4px 8px; min-height: 36px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- conta e base compartilhada ---------- */
.top { flex-wrap: wrap; }
.nav { flex-wrap: wrap; }
@media (max-width: 380px) { .link-btn { padding: 10px 6px; } .brand { font-size: 1.05rem; } }
.notice { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--focus); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; font-weight: 600; overflow-wrap: anywhere; }
.notice.warn { border-left-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.notice.over { border-left-color: var(--over); background: var(--over-bg); color: var(--over); }
.account-strip { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px 6px 14px; margin-top: 4px; }
.account-strip .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-card h2 { margin-bottom: 6px; }
select.input { appearance: auto; }
textarea.input { resize: vertical; min-height: 96px; }
.product-head { margin-bottom: 10px; }
.product-head .pname { font-weight: 800; font-size: 1.15rem; overflow-wrap: anywhere; }
.info-box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.info-box .avg { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-size: 1.05rem; }
.info-box .avg .v { font-weight: 900; font-size: 1.4rem; }
.info-box .avg.none { color: var(--muted); font-weight: 600; font-size: 0.95rem; }
.info-box .k { font-weight: 700; }
.info-box .v { font-weight: 800; }
.here { margin-top: 10px; padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--ok); background: var(--ok-bg); }
.here.stale { border: 1.5px dashed var(--warn); background: var(--warn-bg); }
.here .row-between, .row-between { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }
.stale-note { margin-top: 4px; font-weight: 700; color: var(--warn); font-size: 0.9rem; }
.cls { font-weight: 700; font-size: 0.85rem; border-radius: 999px; padding: 2px 8px; display: inline-block; margin-top: 4px; border: 1.5px solid currentColor; }
.cls.cheaper { color: var(--ok); } .cls.average { color: var(--ink); } .cls.expensive { color: var(--over); }
.section-title.small { font-size: 0.9rem; margin: 12px 0 4px; }
.others { list-style: none; margin: 0; padding: 0; }
.others li { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.others li:last-child { border-bottom: 0; }
.others .cls { margin-top: 0; }
.top .nav { margin-left: auto; }
.nav .link-btn { padding-left: 8px; padding-right: 8px; }
