:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --ink: #1c211e;
  --muted: #69716c;
  --line: #e3e0d8;
  --brand: #1f6f50;
  --brand-2: #e7f1ec;
  --warn: #a8530f;
  --warn-bg: #fbeedf;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --radius: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131614; --card: #1b1f1c; --ink: #e8ece9; --muted: #98a19b; --line: #2c322e;
    --brand: #4fb98c; --brand-2: #1c2f26; --warn: #eba25f; --warn-bg: #362817; --bad: #f08a83; --bad-bg: #3a1f1d;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.2em; margin: 0; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }

.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }

/* topo e navegação */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px; background: var(--bg); }
.topbar h1 { font-size: 22px; font-weight: 700; }
.top-right { display: flex; align-items: center; gap: 6px; }
#topActions { display: flex; gap: 6px; }
main { padding: 0 14px calc(90px + var(--safe-b)); max-width: 760px; margin: 0 auto; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabbar button { flex: 1; border: 0; background: none; padding: 9px 0 7px; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px; position: relative; cursor: pointer; }
.tabbar button .ic { width: 22px; height: 22px; }
.tabbar button.on { color: var(--brand); font-weight: 600; }
.tabbar button.on .ic { stroke-width: 2.1; }
.badge { position: absolute; top: 4px; left: 54%; background: var(--bad); color: #fff; font-size: 10px;
  min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }
.badge.warn { background: var(--warn); }

/* controles */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line);
  background: var(--card); padding: 10px 14px; border-radius: 9px; font-weight: 600; cursor: pointer; min-height: 42px; }
.btn .ic { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: transparent; background: var(--bad-bg); }
.btn.small { padding: 6px 10px; font-size: 13px; min-height: 32px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.file { position: relative; overflow: hidden; }
.btn.file input { position: absolute; inset: 0; opacity: 0; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: none; padding: 7px; border-radius: 8px; cursor: pointer; color: var(--muted);
  display: inline-grid; place-items: center; }
.icon-btn:active { background: var(--line); }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; margin: 8px 0; }
.row.gap > .btn { flex: 1; }
.spread { justify-content: space-between; }
input:not([type]), input[type=search], input[type=text], input[type=tel], input[type=url], input[type=number], input[type=password],
input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--card);
  outline: none; min-height: 42px; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
label.field { display: block; margin: 10px 0 0; font-size: 12px; color: var(--muted); font-weight: 600; }
label.field > input, label.field > select, label.field > textarea { margin-top: 4px; color: var(--ink); font-weight: 400; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.searchbar { position: relative; margin: 2px 0 8px; }
.searchbar .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.searchbar input { padding-left: 36px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 11px;
  font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.warn { color: var(--warn); }
.chip.warn.on { background: var(--warn); border-color: var(--warn); color: #fff; }
.summary { font-size: 13px; color: var(--muted); margin: 4px 2px 10px; }
.hint { color: var(--muted); font-size: 14px; margin: 6px 2px 10px; }
.hint.small { font-size: 13px; margin: 14px 2px 0; }

.segmented { display: flex; background: var(--line); border-radius: 9px; padding: 3px; margin: 4px 0 8px; }
.segmented button { flex: 1; border: 0; background: none; padding: 8px 6px; border-radius: 7px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button.on { background: var(--card); color: var(--ink); }
.segmented.small button { padding: 7px 4px; font-size: 13px; }

/* listas e cartões */
.list { display: flex; flex-direction: column; gap: 6px; }
.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 10px; }
.pcard { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.thumb { flex: none; width: 54px; height: 54px; border-radius: 8px; overflow: hidden; display: grid; place-items: center;
  background: var(--brand-2); color: var(--brand); font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumb.big { width: 112px; height: 112px; font-size: 34px; border-radius: 12px; }
.thumb.sm { width: 40px; height: 40px; font-size: 14px; }
.thumb .ic { width: 22px; height: 22px; }
.thumb.mono { background: hsl(var(--h, 150) 32% 91%); color: hsl(var(--h, 150) 38% 30%); }
@media (prefers-color-scheme: dark) {
  .thumb.mono { background: hsl(var(--h, 150) 18% 22%); color: hsl(var(--h, 150) 45% 75%); }
}
.pinfo { flex: 1; min-width: 0; }
.pname { font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.psub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { font-size: 11.5px; padding: 2px 7px; border-radius: 5px; background: var(--brand-2); color: var(--brand); font-weight: 600; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.gray { background: transparent; color: var(--muted); padding-left: 0; font-weight: 500; }
.qty { display: flex; align-items: center; gap: 2px; flex: none; }
.qty button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  cursor: pointer; display: grid; place-items: center; color: var(--ink); }
.qty button .ic { width: 18px; height: 18px; }
.qty .n { min-width: 44px; text-align: center; font-weight: 700; font-size: 17px; }
.qty .n small { display: block; font-size: 10.5px; font-weight: 500; color: var(--muted); }
.zero .n { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty b { color: var(--ink); }
.empty .btn { margin-top: 12px; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 2px 2px; font-weight: 700; }

.fab { position: fixed; right: 18px; bottom: calc(76px + var(--safe-b)); width: 54px; height: 54px; border-radius: 14px;
  background: var(--brand); color: #fff; border: 0; box-shadow: 0 4px 14px rgba(0,0,0,.18); cursor: pointer; z-index: 6;
  display: grid; place-items: center; }
.fab .ic { width: 26px; height: 26px; stroke-width: 2.2; }

/* leitor de câmera */
.reader:empty { display: none; }
.reader { margin-bottom: 4px; }
.cam { position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 62vh; background: #000; border-radius: var(--radius); overflow: hidden; }
.cam video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-frame { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); border: 2px solid rgba(255,255,255,.9);
  border-radius: 10px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.cam-frame.qr { width: 72%; aspect-ratio: 1; }
.cam-frame.ean { width: 82%; height: 26%; }
.cam-status { position: absolute; left: 12px; right: 12px; top: 10px; color: #fff; font-size: 13.5px; text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.cam-tools { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; align-items: center; gap: 8px; }
.cam-btn { border: 0; border-radius: 8px; padding: 8px 12px; background: rgba(0,0,0,.55); color: #fff; font-weight: 600; font-size: 13px; cursor: pointer; }
.cam-btn.on { background: #fff; color: #111; }
.cam-zoom { flex: 1; accent-color: #fff; }
.cam-tools [data-cam=stop] { margin-left: auto; }

/* folha (painel de baixo) */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; background: var(--bg);
  border-radius: 16px 16px 0 0; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto;
  animation: up .16s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: .7; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 12px 6px 16px; }
.sheet-head h2 { font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(20px + var(--safe-b)); }
.hero { display: flex; gap: 14px; align-items: center; margin: 4px 0 10px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.stat b { display: block; font-size: 16px; }
.stat span { font-size: 11.5px; color: var(--muted); }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.t td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
table.t td.r, table.t th.r { text-align: right; }
.section-title { margin: 18px 0 6px; font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
details { margin-top: 10px; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.store-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }

/* gastos */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.kpi b { display: block; font-size: 21px; letter-spacing: -.02em; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi.wide { grid-column: span 2; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 10px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bars .bar { width: 42%; max-width: 20px; border-radius: 3px 3px 0 0; background: var(--brand); min-height: 2px; }
.bars .bar.b2 { background: var(--warn); opacity: .75; }
.bars .lbl { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.hbar { margin: 8px 0; }
.hbar .top { display: flex; justify-content: space-between; font-size: 13px; gap: 8px; }
.hbar .top span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 6px; border-radius: 3px; background: var(--line); margin-top: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--brand); border-radius: 3px; }
.panel { margin-top: 8px; }
.panel > .section-title:first-child { margin-top: 2px; }

/* cupom */
.ritem { display: flex; gap: 10px; align-items: flex-start; }
.ritem .raw { font-size: 12px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.ritem.review { border-color: var(--warn); box-shadow: inset 3px 0 0 var(--warn); }
.ritem .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.fixbox { margin-top: 4px; }
.fixbox summary { font-size: 13px; color: var(--muted); font-weight: 600; padding: 4px 0; list-style: none; }
.fixbox summary::-webkit-details-marker { display: none; }
.fixbox summary::after { content: " ›"; }
.fixbox[open] summary::after { content: " ‹"; }
.note { font-size: 13px; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 8px 10px; margin: 0 0 10px; }

/* validades */
.lot { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; cursor: pointer; padding: 10px 12px; }
.lot.warn, .lotrow.warn { box-shadow: inset 3px 0 0 var(--warn); }
.lot.bad, .lotrow.bad { box-shadow: inset 3px 0 0 var(--bad); }
.lotrow { margin-bottom: 6px; }
.preview { white-space: pre-wrap; font: 13px/1.45 ui-monospace, Menlo, monospace; background: var(--bg); border-radius: 8px;
  padding: 10px; margin: 10px 0 0; border: 1px solid var(--line); }

/* ajustes */
.set-group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 12px 12px; margin-bottom: 12px; }
.set-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 0 2px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row select { width: auto; min-width: 110px; }
.set-row .lbl b { display: block; font-weight: 600; }
.set-row .lbl span { font-size: 12.5px; color: var(--muted); }
.person { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.person .pinfo .pname { -webkit-line-clamp: 1; }
.add-person { display: grid; grid-template-columns: 1fr 1.3fr auto; gap: 6px; margin-top: 10px; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 13px; transition: background .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff;
  border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(18px); }
.status-line { font-size: 13px; padding: 8px 10px; border-radius: 8px; margin-top: 8px; }
.status-line.ok { background: var(--brand-2); color: var(--brand); }
.status-line.off { background: var(--line); color: var(--muted); }

/* diálogo central */
.dialog { position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 20px; }
.dialog-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.dialog-panel { position: relative; width: 100%; max-width: 360px; background: var(--card); border-radius: 14px; padding: 18px; }
.dialog-panel h3 { font-size: 17px; }
.dialog-panel p { margin: 6px 0 0; font-size: 14px; }
.dialog-panel p:empty { display: none; }
#dialogField:not(:empty) { margin-top: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog-actions .btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }

/* login, carregando e avisos */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 320px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.login-card .logo { width: 64px; height: 64px; margin: 0 auto 4px; }
.busy { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45); display: grid; place-content: center;
  justify-items: center; color: #fff; gap: 10px; text-align: center; padding: 20px; }
.spinner { width: 38px; height: 38px; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%;
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); z-index: 70;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25); text-align: center; }
.toast.bad { background: var(--bad); color: #fff; }
.pick { display: flex; gap: 10px; align-items: center; padding: 8px 6px; border-radius: 8px; cursor: pointer; }
.pick:active { background: var(--brand-2); }
.check { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.done .pname { text-decoration: line-through; color: var(--muted); }
.captcha { display: block; width: 100%; max-height: 110px; object-fit: contain; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; margin-top: 4px; }
a.btn { text-decoration: none; color: inherit; }

/* tela larga (computador): mesma largura do conteúdo */
@media (min-width: 800px) {
  .topbar { padding-left: calc((100vw - 760px) / 2 + 14px); padding-right: calc((100vw - 760px) / 2 + 14px); }
  .tabbar { justify-content: center; }
  .tabbar button { max-width: 150px; }
  .fab { right: calc((100vw - 760px) / 2 + 14px); }
}
