:root {
  --bg: #000000;
  --bg-2: #0e0e10;
  --card: #141416;
  --card-2: #1d1d20;
  --line: #2a2a2e;
  --txt: #ffffff;
  --txt-2: #9a9aa2;
  --gold: #e9e9ee;
  --gold-2: #cfcfd6;
  --green: #2fd08f;
  --red: #ff5a5a;
  --blue: #4f8cff;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 16px;
  background: var(--bg-2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 14px; width: 100%;
  outline: none;
}
input:focus, select:focus { border-color: var(--gold); }

.brand-gold { color: var(--gold); }
.muted { color: var(--txt-2); }
.center { text-align: center; }

/* ====== LOGIN ====== */
.login-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 28px;
}
.logo {
  width: 92px; height: 92px; border-radius: 24px;
  background: linear-gradient(145deg, #1c1c22, #0d0d0f);
  border: 1px solid var(--gold);
  display: grid; place-items: center; margin-bottom: 22px;
  box-shadow: 0 10px 40px rgba(212,175,55,.18);
}
.logo span { font-size: 38px; font-weight: 800; color: var(--gold); letter-spacing: 1px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 22px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p.sub { margin: 0 0 22px; color: var(--txt-2); font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--txt-2); margin-bottom: 6px; }

.btn {
  width: 100%; border: none; border-radius: 12px; padding: 15px;
  font-size: 16px; font-weight: 700; color: #000;
  background: #ffffff;
}
.btn:active { transform: scale(.98); background: #e6e6e6; }
.btn-ghost {
  background: transparent; color: #fff;
  border: 1px solid #4a4a52; font-weight: 600;
}
.btn-sm { padding: 9px 14px; font-size: 14px; width: auto; border-radius: 10px; }
.btn-danger { background: transparent; border: 1px solid var(--red); color: var(--red); }

.alert {
  display: none; margin-top: 14px; padding: 11px 14px; border-radius: 10px;
  font-size: 14px; background: rgba(255,90,90,.12); color: #ff9a9a; border: 1px solid rgba(255,90,90,.3);
}
.alert.show { display: block; }

/* ====== APP SHELL ====== */
.app { padding-bottom: calc(74px + var(--safe-b)); min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: rgba(13,13,15,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .t-logo { font-weight: 800; color: var(--gold); font-size: 18px; letter-spacing: .5px; }
.topbar .t-user { font-size: 12px; color: var(--txt-2); text-align: right; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.dot.on { background: var(--green); } .dot.off { background: var(--red); }

.view { padding: 16px 16px 8px; }
.view h2 { margin: 4px 0 14px; font-size: 20px; }

.searchbar { display: flex; gap: 8px; margin-bottom: 14px; }
.searchbar input { flex: 1; }

/* cards de lista */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px; display: flex; gap: 12px; align-items: center;
}
.item:active { background: var(--card-2); }
.thumb {
  width: 56px; height: 56px; border-radius: 10px; flex-shrink: 0;
  background: var(--bg-2); object-fit: cover; display: grid; place-items: center;
  color: var(--txt-2); font-size: 11px; border: 1px solid var(--line);
}
.item .info { flex: 1; min-width: 0; }
.item .info .title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .info .meta { color: var(--txt-2); font-size: 13px; margin-top: 3px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.green { background: rgba(39,192,138,.15); color: var(--green); }
.badge.gold { background: rgba(212,175,55,.15); color: var(--gold); }
.badge.gray { background: var(--card-2); color: var(--txt-2); }
.badge.red { background: rgba(255,90,90,.15); color: var(--red); }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.kpi .k-label { color: var(--txt-2); font-size: 12px; }
.kpi .k-value { font-size: 22px; font-weight: 800; margin-top: 6px; }

.empty, .loading { text-align: center; color: var(--txt-2); padding: 40px 10px; font-size: 14px; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

.pager { display: flex; justify-content: center; gap: 12px; margin: 16px 0; align-items: center; }

/* bottom nav */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; background: rgba(22,22,26,.97); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  flex: 1; background: none; border: none; color: var(--txt-2);
  padding: 9px 2px 8px; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabbar button.active { color: var(--gold); }
.tabbar button svg { width: 22px; height: 22px; }

/* modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60;
  display: none; align-items: flex-end; justify-content: center;
}
.modal-bg.show { display: flex; }
.modal {
  background: var(--card); width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0; border: 1px solid var(--line);
  padding: 20px 18px calc(22px + var(--safe-b)); max-height: 90dvh; overflow-y: auto;
  animation: up .25s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.modal h3 { margin: 0 0 4px; }
.modal .close { float: right; color: var(--txt-2); font-size: 26px; line-height: 1; background: none; border: none; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.detail-img { width: 100%; max-height: 240px; object-fit: contain; border-radius: 12px; background: var(--bg-2); margin-bottom: 14px; }
.dl { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.dl span:first-child { color: var(--txt-2); }
.dl span:last-child { font-weight: 600; text-align: right; }

.install-banner {
  display: none; margin: 0 16px 12px; padding: 12px 14px; border-radius: 12px;
  background: rgba(212,175,55,.1); border: 1px solid rgba(212,175,55,.35);
  align-items: center; justify-content: space-between; gap: 10px; font-size: 13px;
}
.install-banner.show { display: flex; }

@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .modal { border-radius: 20px; margin-bottom: 5vh; }
  .modal-bg { align-items: center; }
}

/* ====== PDV / VENDA ====== */
.cart-line { display:flex; align-items:center; gap:10px; background:var(--card); border:1px solid var(--line); border-radius:12px; padding:10px; margin-bottom:8px; }
.cart-line .ci { flex:1; min-width:0; }
.cart-line .ci .t { font-size:14px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.cart-line .ci .s { font-size:12px; color:var(--txt-2); }
.stepper { display:flex; align-items:center; gap:6px; }
.stepper button { width:30px; height:30px; border-radius:8px; border:1px solid #4a4a52; background:#fff; color:#000; font-size:18px; font-weight:700; line-height:1; }
.stepper span { min-width:26px; text-align:center; font-weight:700; }
.x-rm { background:none; border:none; color:var(--red); font-size:20px; padding:0 4px; }
.cart-total { background:var(--card); border:1px solid var(--line); border-radius:14px; padding:14px; margin:12px 0; }
.cart-total .l { display:flex; justify-content:space-between; padding:5px 0; font-size:15px; }
.cart-total .l.big { font-size:20px; font-weight:800; border-top:1px solid var(--line); margin-top:6px; padding-top:10px; }
.chip { display:inline-block; background:var(--card-2); border:1px solid var(--line); border-radius:999px; padding:8px 14px; margin:4px 6px 4px 0; font-size:14px; }
.chip.sel { background:#fff; color:#000; border-color:#fff; font-weight:700; }

/* botão flutuante vender */
.fab { position:fixed; right:18px; bottom:calc(86px + var(--safe-b)); z-index:45; background:#fff; color:#000; border:none; border-radius:999px; padding:14px 20px; font-weight:800; font-size:15px; box-shadow:0 6px 24px rgba(0,0,0,.5); }

/* dashboard */
.big-num { font-size:30px; font-weight:800; margin:2px 0; }
.stat { background:var(--card); border:1px solid var(--line); border-radius:14px; padding:16px; margin-bottom:10px; }
.stat .lbl { color:var(--txt-2); font-size:13px; }
.stat.pos .big-num { color:var(--green); }
.stat.neg .big-num { color:var(--red); }
.seg { display:flex; gap:6px; margin-bottom:14px; }
.seg button { flex:1; padding:9px; border-radius:10px; border:1px solid var(--line); background:var(--card); color:var(--txt-2); font-size:13px; font-weight:600; }
.seg button.on { background:#fff; color:#000; border-color:#fff; }
.bar-row { display:flex; align-items:center; gap:8px; margin:5px 0; font-size:12px; }
.bar-row .bn { width:62px; color:var(--txt-2); white-space:nowrap; }
.bar-row .bt { flex:1; height:10px; background:var(--card-2); border-radius:6px; overflow:hidden; }
.bar-row .bt i { display:block; height:100%; background:#fff; }
.bar-row .bv { width:74px; text-align:right; }

/* --- Leitor de código de barras / QR (v4) --- */
.btn-scan { display:inline-flex; align-items:center; justify-content:center; padding:9px 11px; }
#reader { background:#000; }
#reader video { border-radius:12px; }
.searchbar .btn-scan svg { display:block; }
