/* ---------- Tokens ---------- */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --line: #dde3e0;
  --text: #14201b;
  --text-2: #56635d;
  --text-3: #85918b;
  --brand: #0f8a5f;
  --brand-strong: #0b6b49;
  --brand-soft: #e2f4ec;
  --ok: #16834f;
  --ok-soft: #e3f5ea;
  --warn: #b26a00;
  --warn-soft: #fff1d9;
  --bad: #c62f2f;
  --bad-soft: #fde7e7;
  --info: #2b62c4;
  --info-soft: #e6eefc;
  --shadow: 0 1px 2px rgba(10, 30, 20, .06), 0 4px 14px rgba(10, 30, 20, .06);
  --radius: 16px;
  --radius-sm: 10px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1512; --surface: #15201b; --surface-2: #1c2924; --line: #2a3832;
    --text: #e8efeb; --text-2: #a8b6af; --text-3: #7a8a82;
    --brand: #2fbf86; --brand-strong: #5ad6a3; --brand-soft: #173a2c;
    --ok: #4cc98a; --ok-soft: #173826; --warn: #f0a43a; --warn-soft: #3a2a10;
    --bad: #ff6b6b; --bad-soft: #3d1a1a; --info: #7aa7ff; --info-soft: #1b2a47;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1512; --surface: #15201b; --surface-2: #1c2924; --line: #2a3832;
  --text: #e8efeb; --text-2: #a8b6af; --text-3: #7a8a82;
  --brand: #2fbf86; --brand-strong: #5ad6a3; --brand-soft: #173a2c;
  --ok: #4cc98a; --ok-soft: #173826; --warn: #f0a43a; --warn-soft: #3a2a10;
  --bad: #ff6b6b; --bad-soft: #3d1a1a; --info: #7aa7ff; --info-soft: #1b2a47;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
h3 { font-size: .95rem; margin: 0; }
p { margin: 0; }
a { color: var(--brand); }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }
.hidden, [hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar-title { font-size: 1.35rem; margin: 0; flex: 1; letter-spacing: -.01em; }
.topbar-actions { display: flex; gap: 4px; }
main { padding: 4px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); max-width: 720px; margin: 0 auto; outline: none; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-3); text-decoration: none; font-size: .7rem; font-weight: 600;
}
.tabbar a[aria-current="page"] { color: var(--brand); }
.tabbar a.tab-main svg { background: var(--brand); color: #fff; border-radius: 14px; padding: 7px; width: 40px; height: 40px; margin-top: -10px; box-shadow: var(--shadow); }
.tabbar a.tab-main[aria-current="page"] svg { background: var(--brand-strong); }
.tab-badge {
  position: absolute; top: 4px; left: calc(50% + 10px);
  background: var(--bad); color: #fff; font-size: .65rem; min-width: 18px; height: 18px; border-radius: 9px;
  display: grid; place-items: center; padding: 0 5px;
}

/* ---------- Components ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-label { font-size: .75rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; margin: 22px 2px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 0;
  background: var(--surface-2); color: var(--text); font-weight: 600;
  transition: transform .12s ease, background-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .5; pointer-events: none; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: transparent; color: var(--text-2);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.on { color: var(--brand); }

.actions-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.action-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px 12px;
  border: 0; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  text-align: left; font-weight: 600; font-size: .85rem; color: var(--text);
}
.action-tile svg { color: var(--brand); width: 26px; height: 26px; }
.action-tile:active { transform: scale(.97); }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: .8rem; color: var(--text-2); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
textarea.input { min-height: 110px; resize: vertical; }
.input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.input.big { font-size: 1.6rem; font-weight: 700; text-align: center; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: .85rem; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.neutral { background: var(--surface-2); color: var(--text-2); }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 36px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: .85rem; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 14px; background: var(--line); transition: background-color .2s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list > li.tap { cursor: pointer; }
.list > li.tap:active { background: var(--surface-2); }
.thumb { width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); flex: none; display: grid; place-items: center; overflow: hidden; font-size: 1.4rem; }
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-sub { font-size: .8rem; color: var(--text-2); }
.price { font-weight: 700; white-space: nowrap; }
.empty { text-align: center; padding: 32px 16px; color: var(--text-2); }
.empty svg { width: 48px; height: 48px; color: var(--text-3); margin-bottom: 8px; }

.check { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); flex: none; display: grid; place-items: center; background: transparent; padding: 0; }
.check svg { width: 16px; height: 16px; stroke-width: 3; opacity: 0; color: #fff; }
.check[aria-checked="true"] { background: var(--brand); border-color: var(--brand); }
.check[aria-checked="true"] svg { opacity: 1; }
li.done .item-name { text-decoration: line-through; color: var(--text-3); }

.qty { display: flex; align-items: center; gap: 2px; background: var(--surface-2); border-radius: 10px; }
.qty button { width: 32px; height: 32px; border: 0; background: transparent; font-size: 1.1rem; font-weight: 700; }
.qty span { min-width: 34px; text-align: center; font-weight: 700; font-size: .9rem; }

/* ---------- Cart total ---------- */
.total-card { background: var(--brand); color: #fff; border-radius: 20px; padding: 16px 18px; box-shadow: var(--shadow); }
.total-card .label { font-size: .8rem; opacity: .85; font-weight: 600; }
.total-card .value { font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.total-card .meta { font-size: .8rem; opacity: .9; }
.limit-bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.25); margin-top: 10px; overflow: hidden; }
.limit-bar i { display: block; height: 100%; border-radius: 4px; background: #fff; transition: width .3s ease, background-color .3s; }
.total-card.over { background: var(--bad); }
.total-card.near { background: var(--warn); }

/* ---------- Stats ---------- */
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .k { font-size: .75rem; color: var(--text-2); font-weight: 600; }
.stat .v { font-size: 1.35rem; font-weight: 800; letter-spacing: -.01em; }
.stat .d { font-size: .75rem; }
.up { color: var(--bad); }
.down { color: var(--ok); }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .b i { display: block; width: 100%; border-radius: 6px 6px 2px 2px; background: var(--brand); min-height: 2px; }
.bars .b.cur i { background: var(--brand-strong); }
.bars .b small { font-size: .65rem; color: var(--text-3); }

.hbar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.hbar i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }

/* ---------- Health ---------- */
.nutri { display: inline-flex; border-radius: 8px; overflow: hidden; font-weight: 800; font-size: .8rem; }
.nutri b { width: 22px; height: 26px; display: grid; place-items: center; color: #fff; opacity: .35; }
.nutri b.on { opacity: 1; transform: scale(1.1); }
.nutri .a { background: #038141; } .nutri .b { background: #85bb2f; } .nutri .c { background: #e5a000; }
.nutri .d { background: #ee8100; } .nutri .e { background: #e63e11; }
.alert-box { display: flex; gap: 10px; padding: 12px; border-radius: 12px; background: var(--bad-soft); color: var(--bad); font-weight: 600; font-size: .9rem; }
.alert-box.warn { background: var(--warn-soft); color: var(--warn); }
.alert-box.ok { background: var(--ok-soft); color: var(--ok); }
.alert-box.info { background: var(--info-soft); color: var(--info); }
.alert-box svg { flex: none; width: 20px; height: 20px; }

/* ---------- Sheets / modal ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.4); animation: fade .2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 71; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 8px 16px calc(20px + var(--safe-b));
  animation: up .25s cubic-bezier(.2,.8,.2,1); max-width: 720px; margin: 0 auto;
}
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 1.15rem; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Scanner ---------- */
.scanner { position: fixed; inset: 0; z-index: 60; background: #000; color: #fff; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); width: min(78vw, 340px); aspect-ratio: 1.6; border-radius: 18px; box-shadow: 0 0 0 9999px rgba(0,0,0,.5); border: 3px solid rgba(255,255,255,.9); }
.scanner .frame.qr { aspect-ratio: 1; }
.scanner .frame::after { content: ""; position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: #2fbf86; box-shadow: 0 0 12px #2fbf86; animation: scan 1.8s ease-in-out infinite; }
@keyframes scan { 0%,100% { transform: translateY(-40px); } 50% { transform: translateY(40px); } }
.scanner .top, .scanner .bottom { position: relative; z-index: 2; padding: calc(14px + var(--safe-t)) 16px 14px; display: flex; align-items: center; gap: 10px; }
.scanner .bottom { margin-top: auto; flex-direction: column; align-items: stretch; padding-bottom: calc(18px + var(--safe-b)); background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.scanner .icon-btn { color: #fff; background: rgba(0,0,0,.35); }
.scanner .hint { text-align: center; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.scanner .last { background: rgba(255,255,255,.95); color: #14201b; border-radius: 14px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.scanner .last .grow { min-width: 0; }
.scanner .total-mini { font-weight: 800; font-size: 1.1rem; }
.scanner .seg { background: rgba(255,255,255,.15); }
.scanner .seg button { color: #fff; }
.scanner .seg button[aria-pressed="true"] { background: #fff; color: #14201b; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); transform: translate(-50%, 20px);
  z-index: 90; background: #14201b; color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { background: none; border: 0; color: #5ad6a3; font-weight: 700; padding: 0; }

/* ---------- Map ---------- */
#map { height: 320px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); z-index: 1; background: var(--surface-2); }
.leaflet-popup-content { font: 14px/1.4 system-ui, sans-serif; }

/* ---------- Check (conferência) ---------- */
.check-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.diff { color: var(--bad); font-weight: 700; }
.photo-proof { width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px; background: var(--surface-2); }

/* ---------- Badges (conquistas) ---------- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.badge { background: var(--surface); border-radius: var(--radius); padding: 12px 8px; text-align: center; box-shadow: var(--shadow); font-size: .75rem; font-weight: 600; }
.badge .e { font-size: 1.8rem; display: block; margin-bottom: 4px; }
.badge.locked { opacity: .4; filter: grayscale(1); box-shadow: none; border: 1px dashed var(--line); }

/* ---------- Print (PDF da conferência) ---------- */
#printArea { display: none; }
@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block; color: #000; font: 12px/1.4 system-ui, sans-serif; }
  #printArea table { width: 100%; border-collapse: collapse; }
  #printArea th, #printArea td { border-bottom: 1px solid #ccc; padding: 4px; text-align: left; }
  #printArea .r { text-align: right; }
  #printArea .bad { color: #c62f2f; font-weight: 700; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 760px) {
  .actions-grid { grid-template-columns: repeat(6, 1fr); }
}
