/* Fontes da marca (OFL), servidas pelo próprio app */
@font-face { font-family: Poppins; font-weight: 400; font-display: swap; src: url(/fonts/poppins-400.woff2) format('woff2'); }
@font-face { font-family: Poppins; font-weight: 500; font-display: swap; src: url(/fonts/poppins-500.woff2) format('woff2'); }
@font-face { font-family: Poppins; font-weight: 600; font-display: swap; src: url(/fonts/poppins-600.woff2) format('woff2'); }
@font-face { font-family: Poppins; font-weight: 700 800; font-display: swap; src: url(/fonts/poppins-700.woff2) format('woff2'); }
@font-face { font-family: Allura; font-weight: 400; font-display: swap; src: url(/fonts/allura-400.woff2) format('woff2'); }

/* Paleta Casa Nuvem: ciano #0DAFDE, amarelo #FFC20A, laranja #FF810F, creme #F8F0E3, cinza #707176.
   O ciano puro é usado em destaques; botões e textos usam um tom mais fechado dele (#087DA1) para ter boa leitura. */
:root {
  --brand: #0DAFDE;
  --brand-dark: #087DA1;
  --brand-soft: #E3F6FC;
  --yellow: #FFC20A;
  --orange: #FF810F;
  --bg: #F8F0E3;
  --card: #ffffff;
  --text: #2B2B30;
  --muted: #707176;
  --line: #ECE3D3;
  --ok: #138a4f;
  --ok-soft: #e3f6ec;
  --warn: #8A5A00;
  --warn-soft: #FFF4D1;
  --err: #c62828;
  --err-soft: #fdecec;
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 15px/1.5 Poppins, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}
a { color: var(--brand-dark); }
img { max-width: 100%; display: block; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; font-weight: 600; }
/* Toque afetivo, com moderação (saudação, assinatura) */
.script { font-family: Allura, cursive; font-weight: 400; font-size: 2rem; line-height: 1.1; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Estrutura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: #fff; color: var(--text); border-bottom: 3px solid var(--brand);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 12px;
}
.topbar .brand-mark { width: 34px; height: 34px; flex: none; }
.topbar h1 { margin: 0; font-size: 1.1rem; flex: 1; }
.topbar button { background: none; border: 0; color: var(--brand-dark); font: inherit; font-size: .9rem; font-weight: 600; padding: 6px; cursor: pointer; }
.topbar .back { font-size: 1.4rem; line-height: 1; }

main {
  max-width: 980px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px);
}

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-size: .72rem; gap: 2px; position: relative;
}
.bottomnav a.active { color: var(--brand-dark); font-weight: 600; }
.bottomnav a.active svg { color: var(--brand); }
.bottomnav svg { width: 24px; height: 24px; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  background: var(--yellow); color: var(--text); border-radius: 999px; font-size: .7rem;
  min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; font-weight: 700;
}

/* ---------- Componentes ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 1px 3px rgba(80, 60, 30, .06); border: 1px solid var(--line);
}
.card + .card { margin-top: 12px; }
.card.tight { padding: 12px; }

.btn {
  appearance: none; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--brand-dark); color: #fff; font: inherit; font-weight: 600;
  padding: 12px 16px; min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.lg { min-height: 56px; font-size: 1.05rem; }
.btn.secondary { background: var(--brand-soft); color: var(--brand-dark); }
.btn.ghost { background: transparent; color: var(--brand-dark); border: 1px solid var(--line); }
.btn.ok { background: var(--ok); }
.btn.danger { background: var(--err); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
.field + .field { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.grid2 .field + .field, .grid3 .field + .field { margin-top: 0; }

.check { display: flex; align-items: center; gap: 10px; font-size: 1rem; color: var(--text); margin: 0; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; background: var(--bg); border-radius: 12px; padding: 4px; }
.segmented label {
  margin: 0; text-align: center; padding: 10px 6px; border-radius: 9px; cursor: pointer;
  color: var(--text); font-size: .95rem; font-weight: 500;
}
.segmented input { display: none; }
.segmented label:has(input:checked) { background: #fff; color: var(--brand-dark); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 4px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px;
  font-size: .85rem; white-space: nowrap; cursor: pointer; color: var(--text);
}
.chip.active { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }

.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.promo { background: var(--orange); color: var(--text); }
.tag.err { background: var(--err-soft); color: var(--err); }
.tag.info { background: var(--brand-soft); color: var(--brand-dark); }

.alert { border-radius: 12px; padding: 12px 14px; font-size: .92rem; }
.alert.err { background: var(--err-soft); color: var(--err); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--brand-soft); color: var(--brand-dark); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list a.item, .list .item { display: flex; gap: 12px; align-items: center; padding: 12px 0; text-decoration: none; color: inherit; }

.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--bg); flex: none; }
.thumb.ph { display: grid; place-items: center; color: var(--muted); font-size: 1.4rem; }

.price { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.price.xl { font-size: 2rem; color: var(--brand-dark); }

.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.qty button { width: 40px; height: 40px; border: 0; background: var(--bg); font-size: 1.2rem; cursor: pointer; }
.qty input { width: 52px; text-align: center; border: 0; border-radius: 0; min-height: 40px; padding: 0; }

/* ---------- Telas ---------- */
.scan-hero {
  background: linear-gradient(135deg, var(--brand-dark), #0A8FB8); color: #fff;
  border-radius: 18px; padding: 22px; text-align: center;
}
.scan-hero .script { margin-bottom: 6px; }
.scan-hero .btn { background: #fff; color: var(--brand-dark); }
.scan-hero p { margin: 6px 0 16px; opacity: .9; }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: var(--radius); }
.gallery img { width: 100%; flex: none; aspect-ratio: 1; object-fit: contain; background: #fff; scroll-snap-align: start; border-radius: var(--radius); }
.gallery.ph { aspect-ratio: 2; display: grid; place-items: center; background: #fff; border: 1px solid var(--line); color: var(--muted); }

.stock { font-weight: 600; }
.stock.ok { color: var(--ok); }
.stock.low { color: var(--warn); }
.stock.none { color: var(--err); }

.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.totals .grand { font-size: 1.2rem; font-weight: 800; }

.sticky-actions {
  position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 8px);
  margin-top: 16px; z-index: 5;
}

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 380px; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 18px; }
.logo img { width: min(220px, 70%); height: auto; }
.logo span { color: var(--brand-dark); }

/* Scanner */
.scanner {
  position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column;
}
.scanner #reader { flex: 1; min-height: 0; overflow: hidden; }
.scanner #reader video { object-fit: cover; width: 100% !important; height: 100% !important; }
.scanner .bar { flex-shrink: 0; }
.scanner-close {
  position: absolute; z-index: 2; top: calc(env(safe-area-inset-top, 0px) + 8px); right: 10px;
  width: 44px; height: 44px; border-radius: 50%; border: 0; font-size: 1.3rem; line-height: 1;
  background: rgba(255, 255, 255, .18); color: #fff; cursor: pointer;
}
.scanner .bar { padding: 16px 16px calc(16px + var(--safe-b)); display: flex; gap: 10px; background: #000; }
.scanner .hint { color: #fff; text-align: center; padding: calc(env(safe-area-inset-top, 0px) + 14px) 60px 10px; }

/* Modal simples */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(43, 43, 48, .45); display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: #fff; width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 90dvh; overflow: auto; }
@media (min-width: 700px) { .modal { align-items: center; } .modal .sheet { border-radius: 18px; } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 12px 16px; border-radius: 12px; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--err); }

/* Tabelas (painel admin) */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td input { min-height: 38px; padding: 6px 8px; }

code { word-break: break-all; }

.price-row { display: flex; gap: 12px; align-items: center; padding: 12px 0; flex-wrap: wrap; }
.price-row .grow { min-width: 180px; }
.ean-list { gap: 6px; margin-top: 6px; }
.tag-x { border: 0; background: none; color: inherit; font-size: 1rem; line-height: 1; padding: 0 0 0 4px; cursor: pointer; }
.price-ctrl { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.price-ctrl input[type=number] { width: 120px; min-height: 40px; }
@media (max-width: 520px) { .price-ctrl { width: 100%; padding-left: 68px; } .price-ctrl input[type=number] { width: auto; flex: 1 1 100px; } }

.admin-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.admin-tabs a { padding: 8px 14px; border-radius: 10px; text-decoration: none; color: var(--text); background: #fff; border: 1px solid var(--line); white-space: nowrap; font-size: .92rem; }
/* No celular, as abas viram uma grade de 3 colunas (sem rolagem para o lado) */
@media (max-width: 640px) {
  .admin-tabs { display: grid; grid-template-columns: repeat(3, 1fr); }
  .admin-tabs a { padding: 8px 4px; text-align: center; white-space: normal; font-size: .8rem; line-height: 1.25; display: grid; place-items: center; }
}
.admin-tabs a.active { background: var(--brand-dark); color: #fff; border-color: var(--brand-dark); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi .v { font-size: 1.4rem; font-weight: 800; }

.spinner { width: 22px; height: 22px; border: 3px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 420px) {
  .grid2 { grid-template-columns: 1fr; }
}
.card-prices { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.card-prices .totals { margin-top: 4px; }
.fee-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px 12px; }
.range-row { display: grid; grid-template-columns: 1fr 1fr 92px 40px; gap: 6px; }
.range-row input, .range-row select { min-width: 0; padding-left: 8px; padding-right: 4px; }
.range-row .btn { padding: 0; }
.pix-price { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--brand-soft); }
.pix-price .price.xl { line-height: 1.15; }

/* Tabelas viram cartões no celular (sem rolagem para o lado) */
@media (max-width: 640px) {
  .stack-table thead { display: none; }
  .stack-table, .stack-table tbody, .stack-table tfoot, .stack-table tr { display: block; width: 100%; }
  .stack-table tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .stack-table td, .stack-table th { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 3px 0; border: 0; text-align: right; }
  .stack-table [data-label]::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 500; text-align: left; text-transform: none; letter-spacing: 0; }
  .stack-table .cell-title { display: block; text-align: left; padding-bottom: 4px; font-size: 1rem; }
  .stack-table .cell-actions { justify-content: flex-end; padding-top: 6px; }
  .stack-table .cell-empty { display: none; }
  .stack-table tfoot th { color: var(--text); font-size: .92rem; }
}

/* Textos longos sem espaço (e-mails, códigos) quebram em vez de alargar a tela */
body { overflow-wrap: break-word; }
.price, .totals > span { white-space: nowrap; }
.card-prices .totals > span { white-space: normal; }
@media (max-width: 380px) { .price-ctrl { padding-left: 0; } }
.fee-grid .field + .field { margin-top: 0; }
@media (max-width: 400px) {
  .range-row { grid-template-columns: 1fr 1fr; }
  .range-row .btn { width: 40px; justify-self: end; }
}
