:root {
  color-scheme: light dark;
  --bg: #f6f6fb;
  --card: #ffffff;
  --ink: #16162a;
  --muted: #6a6a85;
  --line: #e2e2ee;
  --accent: #4338ca;
  --accent-ink: #ffffff;
  --ok: #0f7a4d;
  --ok-bg: #dcf5e9;
  --err: #b42318;
  --err-bg: #fde4e1;
  --warn: #8a5a00;
  --warn-bg: #fdf0cf;
  --test: #1d4ed8;
  --test-bg: #dfe9ff;
  --radius: 14px;
  --nav-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e18;
    --card: #181826;
    --ink: #f0f0fa;
    --muted: #9a9ab8;
    --line: #2a2a40;
    --accent: #8b83ff;
    --accent-ink: #0e0e18;
    --ok: #5fdca0;
    --ok-bg: #123524;
    --err: #ff8f84;
    --err-bg: #3d1713;
    --warn: #f2c261;
    --warn-bg: #3a2c0d;
    --test: #8fb1ff;
    --test-bg: #15244d;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); min-height: 100dvh; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* topo e navegação */
#top { 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(--bg); border-bottom: 1px solid var(--line); }
#top h1 { font-size: 18px; letter-spacing: -0.01em; }
.badge { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; }
.badge.test { background: var(--test-bg); color: var(--test); }
.badge.live { background: var(--err-bg); color: var(--err); }
#nav { position: fixed; inset: auto 0 0 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); }
#nav a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 500; }
#nav a.on { color: var(--accent); }
#nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#queueDot { position: absolute; top: 9px; left: calc(50% + 8px); width: 10px; height: 10px; border-radius: 50%; background: #f59e0b; }
#view { max-width: 720px; margin: 0 auto; padding: 14px 16px 24px; }

/* controles */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--err); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: 0.5; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 0; }
input[type='text'], input[type='password'], input[type='number'], input:not([type]), input[inputmode], select, textarea { width: 100%; min-height: 46px; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font-weight: 400; }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 10px; margin: 12px 0 0; font-size: 15px; color: var(--ink); font-weight: 500; }
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 16px; margin-bottom: 4px; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--line); color: var(--muted); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.err { background: var(--err-bg); color: var(--err); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.test { background: var(--test-bg); color: var(--test); }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.alert { padding: 10px 12px; border-radius: 12px; font-size: 14px; margin: 10px 0; background: var(--warn-bg); color: var(--warn); }
.alert.err { background: var(--err-bg); color: var(--err); }

/* scanner */
.viewport { position: relative; aspect-ratio: 3 / 4; max-height: 62dvh; width: 100%; background: #000; border-radius: var(--radius); overflow: hidden; }
.viewport video { width: 100%; height: 100%; object-fit: cover; }
.reticle { position: absolute; inset: 30% 10%; border: 3px solid rgba(255, 255, 255, 0.9); border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35); pointer-events: none; }
.reticle::after { content: ''; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff4d4d; animation: scan 1.6s ease-in-out infinite alternate; }
@keyframes scan { from { transform: translateY(-34px); } to { transform: translateY(34px); } }
.cam-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; color: #fff; font-size: 15px; }
.scan-tools { display: flex; gap: 10px; margin-top: 12px; align-items: center; }
.scan-tools form { display: flex; gap: 8px; flex: 1; }
.scan-tools input { margin: 0; }
.count { text-align: center; margin: 12px 0 0; color: var(--muted); font-size: 14px; }

/* folha (modal inferior) */
.sheet { position: fixed; inset: 0; z-index: 20; display: none; align-items: flex-end; justify-content: center; background: rgba(8, 8, 20, 0.55); }
.sheet.open { display: flex; }
.sheet-card { width: 100%; max-width: 720px; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain; background: var(--bg); border-radius: 22px 22px 0 0; padding: 16px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-head h2 { font-size: 19px; }
.x { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--line); font-size: 22px; line-height: 1; cursor: pointer; }
.actions { display: flex; gap: 10px; margin-top: 16px; position: sticky; bottom: -18px; padding: 10px 0 2px; background: linear-gradient(transparent, var(--bg) 30%); }
.actions .btn { flex: 1; }
.actions .btn.primary { flex: 2; }

/* fotos */
.photos { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; }
.ph { position: relative; flex: none; width: 76px; height: 76px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--card); }
.ph img { width: 100%; height: 100%; object-fit: cover; }
.ph button { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 15px; line-height: 1; }
.ph.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-style: dashed; color: var(--accent); font-size: 12px; font-weight: 600; cursor: pointer; }
.ph.add b { font-size: 26px; line-height: 1; font-weight: 400; }

/* prévia de preço */
.preview { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.pv-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 6px 0; }
.pv-row + .pv-row { border-top: 1px solid var(--line); }
.pv-row .price { font-weight: 700; font-size: 18px; text-align: right; }
.pv-row .muted { grid-column: 1 / -1; font-size: 12.5px; }
details { margin-top: 12px; }
summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); padding: 6px 0; }

/* lista de produtos */
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.toolbar input { margin: 0; flex: 1; }
.filters { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.filters button { flex: none; min-height: 34px; padding: 0 13px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.filters button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.item { display: grid; grid-template-columns: 26px 62px 1fr; gap: 10px; align-items: start; padding: 10px; margin-bottom: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.item .chk { display: flex; align-items: center; justify-content: center; height: 62px; }
.item .chk input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.item img, .item .noimg { width: 62px; height: 62px; border-radius: 10px; object-fit: cover; background: var(--line); }
.item .noimg { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); }
.item h3 { font-size: 15px; font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item .prices { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }
.item .prices span { font-size: 13px; font-weight: 700; }
.item .chips { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.bulk { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 7; display: none; padding: 10px 14px; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.12); }
.bulk.on { display: block; }
.bulk-in { max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.bulk .check { margin: 0; font-size: 14px; }
.bulk .btn { margin-left: auto; }
.progress { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 14px 0 6px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 0.2s; }
.res { padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.res b { display: block; }

/* regras */
.tier { display: grid; grid-template-columns: 1fr 1fr 1fr 34px; gap: 6px; align-items: end; margin-top: 6px; }
.tier input { margin-top: 2px; }
.tier .x { width: 34px; height: 46px; border-radius: 10px; }
.tier-h { display: grid; grid-template-columns: 1fr 1fr 1fr 34px; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 10px; }
.ov { display: grid; grid-template-columns: 2fr 1fr 1fr 34px; gap: 6px; align-items: end; margin-top: 6px; }
.ov input { margin-top: 2px; }
.ov .x { width: 34px; height: 46px; border-radius: 10px; }
.stickysave { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); display: flex; gap: 8px; margin-top: 8px; }
.stickysave .btn { flex: 1; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2); }
.attr-chip { display: inline-flex; align-items: center; gap: 6px; margin: 4px 6px 0 0; padding: 3px 4px 3px 10px; border-radius: 99px; background: var(--line); font-size: 13px; }
.attr-chip button { width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--card); line-height: 1; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 14px; }
.kv + .kv { border-top: 1px solid var(--line); }
code { font-size: 12.5px; word-break: break-all; background: var(--line); padding: 2px 6px; border-radius: 6px; }

/* avisos */
#toast { position: fixed; left: 0; right: 0; top: calc(60px + env(safe-area-inset-top)); z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: 14.5px; font-weight: 500; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); }
.toast.err { background: var(--err); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.login { max-width: 360px; margin: 14vh auto 0; text-align: center; }
.login h2 { font-size: 24px; margin-bottom: 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.7s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .reticle::after, .spin { animation: none; } }
