:root {
  --bg: #f6f3ef;
  --card: #ffffff;
  --ink: #1c1917;
  --ink2: #57534e;
  --muted: #78716c;
  --line: #e7e2dc;
  --brand: #c2410c;
  --brand-escuro: #9a3412;
  --brand-soft: #fff1e6;
  --barra-clara: #f2b892;
  --ok: #15803d;
  --ok-soft: #e7f5ec;
  --ok-ink: #14532d;
  --warn: #b45309;
  --warn-soft: #fef1dc;
  --warn-ink: #7c2d12;
  --danger: #b91c1c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
body.com-modal { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #2563eb; outline-offset: 2px; }

.view {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px calc(110px + env(safe-area-inset-bottom));
}
body.sem-abas .abas { display: none; }
body.sem-abas .view { padding-bottom: calc(130px + env(safe-area-inset-bottom)); }
.carregando { text-align: center; color: var(--muted); padding: 60px 0; }

/* ---------- Cabeçalho ---------- */
.cab {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  display: flex; align-items: center; gap: 12px;
  min-height: 68px; padding: 12px 0 10px;
}
h1 { font-size: 28px; margin: 0; font-weight: 800; letter-spacing: -.01em; }
.sub { margin: -4px 0 14px; color: var(--ink2); }
h2.secao {
  font-size: 15px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 26px 0 10px; font-weight: 800;
}
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
h1.marca { display: flex; align-items: center; gap: 10px; font-size: 25px; letter-spacing: .01em; }
.marca-icone { width: 38px; height: 38px; border-radius: 10px; flex: none; }
.vazio {
  padding: 26px 16px; text-align: center; color: var(--muted);
  background: var(--card); border: 2px dashed var(--line); border-radius: var(--radius);
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 18px;
  border-radius: 14px; border: 2px solid transparent;
  font-size: 18px; font-weight: 700; text-align: center; line-height: 1.15;
  background: var(--card);
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn-bloco { display: flex; width: 100%; }
.btn-grande { min-height: 66px; font-size: 21px; }
.btn-prim { background: var(--brand); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-claro { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn-perigo { background: var(--danger); color: #fff; }
.btn-icone {
  width: 56px; min-height: 56px; flex: none;
  border-radius: 14px; border: 2px solid var(--line); background: var(--card);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icone svg { width: 24px; height: 24px; }
.btn-icone.perigo { color: var(--danger); }
.link {
  background: none; border: 0; color: var(--brand); font-weight: 700;
  padding: 12px 4px; text-decoration: underline; text-underline-offset: 3px;
}
.link.perigo { color: var(--danger); }
.link.centro { display: block; margin: 4px auto 0; }
.voltar {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--card); border: 2px solid var(--line); border-radius: 12px;
  min-height: 50px; padding: 0 16px 0 10px; font-weight: 700; font-size: 18px; flex: none;
}
.voltar svg { width: 22px; height: 22px; }

/* ---------- Campos ---------- */
.campo {
  width: 100%; min-height: 58px;
  border: 2px solid var(--line); border-radius: 14px;
  background: var(--card); padding: 0 16px; font-size: 20px;
}
.campo:focus { border-color: var(--brand); outline: none; }
.campo-select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  border-color: var(--brand); background-color: var(--brand-soft); font-weight: 700;
  padding-right: 56px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23c2410c' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center; background-size: 26px;
}
.caixa-busca { position: relative; margin-bottom: 12px; }
.caixa-busca svg {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; color: var(--muted); pointer-events: none;
}
.caixa-busca .campo { padding-left: 52px; }
.rotulo { display: block; font-weight: 700; margin: 16px 0 6px; }
.rotulo small { color: var(--muted); font-weight: 500; }
.erro { color: var(--danger); font-weight: 700; margin: 10px 0 0; min-height: 0; }
.erro:empty { display: none; }

/* ---------- Fiado: lista de clientes ---------- */
.em-aberto {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--warn-soft); color: var(--warn-ink);
  border-radius: 14px; padding: 12px 16px; margin-bottom: 12px; font-weight: 600;
}
.em-aberto strong { font-size: 21px; white-space: nowrap; }
.chips { display: flex; gap: 8px; margin-bottom: 12px; }
.chip {
  flex: 1; min-height: 48px; padding: 0 14px;
  border-radius: 999px; border: 2px solid var(--line); background: var(--card); font-weight: 700;
}
.chip.ativo { background: var(--ink); border-color: var(--ink); color: #fff; }
.cli {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 72px; padding: 12px 16px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  text-align: left; box-shadow: var(--shadow);
}
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 20px;
}
.cli-nome { flex: 1; font-size: 20px; font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.cli-valor { font-weight: 800; font-size: 20px; white-space: nowrap; }
.cli-valor.deve { color: var(--warn); }
.cli-valor.em-dia { color: var(--muted); font-weight: 600; font-size: 16px; }

/* ---------- Página do cliente ---------- */
.nome-cliente { font-size: 30px; margin: 2px 0 12px; overflow-wrap: anywhere; }
.saldo {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; font-weight: 700;
}
.saldo strong { font-size: 30px; white-space: nowrap; }
.saldo.deve { background: var(--warn-soft); color: var(--warn-ink); }
.saldo.ok { background: var(--ok-soft); color: var(--ok-ink); }
.fiado {
  background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--warn);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.fiado.pago { border-left-color: var(--ok); }
.fiado-topo {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; flex-wrap: wrap; margin-bottom: 6px;
}
.fiado-data { font-weight: 800; }
.selo { font-size: 15px; font-weight: 700; padding: 4px 12px; border-radius: 999px; white-space: nowrap; }
.selo-esp { background: var(--warn-soft); color: var(--warn-ink); }
.selo-ok { background: var(--ok-soft); color: var(--ok-ink); }
.itens { list-style: none; margin: 0; padding: 0; }
.itens li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 7px 0; border-bottom: 1px dashed var(--line); color: var(--ink2);
}
.itens li span:last-child { white-space: nowrap; }
.fiado-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: 10px; font-weight: 700; }
.fiado-total strong { font-size: 23px; }
.fiado-acoes { display: flex; gap: 8px; margin-top: 12px; }
.fiado-acoes .btn { flex: 1; padding: 0 10px; font-size: 17px; }
.rodape-acoes {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  margin-top: 28px; padding-top: 8px; border-top: 1px solid var(--line);
}

/* ---------- Anotar fiado ---------- */
.cab-titulo { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.cab-titulo small { color: var(--muted); font-size: 15px; font-weight: 600; }
.cab-titulo strong { font-size: 22px; overflow-wrap: anywhere; }
.linha-data { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; color: var(--ink2); }
.linha-data strong { color: var(--ink); }
.input-data {
  min-height: 46px; border: 2px solid var(--line); border-radius: 10px;
  padding: 0 10px; background: var(--card); font-size: 17px;
}
.prod {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 8px 8px 8px 0; margin-bottom: 8px;
}
.prod.tem { border-color: var(--brand); background: var(--brand-soft); }
.prod-info {
  flex: 1; background: none; border: 0; text-align: left;
  padding: 8px 0 8px 16px; display: flex; flex-direction: column; min-width: 0;
}
.prod-nome { font-size: 19px; font-weight: 700; overflow-wrap: anywhere; }
.prod-preco { color: var(--ink2); font-size: 16px; }
.qtd { display: flex; align-items: center; gap: 6px; flex: none; }
.q-btn {
  width: 52px; height: 52px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); background: var(--card);
  font-size: 28px; font-weight: 700; line-height: 1;
  display: grid; place-items: center; padding: 0;
}
.q-btn:disabled { opacity: .35; cursor: default; }
.q-mais { background: var(--brand); border-color: var(--brand); color: #fff; }
.q-num { min-width: 34px; text-align: center; font-size: 24px; font-weight: 800; }
.barra-total {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .08);
  padding: 12px max(16px, calc((100% - 760px) / 2 + 16px)) calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 14px;
}
.bt-info { flex: 1; display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.bt-info small { color: var(--muted); font-size: 15px; font-weight: 600; }
.bt-info strong { font-size: 28px; white-space: nowrap; }
.btn-salvar { min-width: 150px; min-height: 62px; font-size: 21px; }

/* ---------- Menu de abas ---------- */
.abas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, .05);
}
.aba {
  flex: 1; max-width: 190px; position: relative;
  background: none; border: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 2px; min-height: 72px;
  color: var(--muted); font-size: 14px; font-weight: 700;
}
.aba svg { width: 28px; height: 28px; }
.aba.ativa { color: var(--brand); }
.aba.ativa::before {
  content: ""; position: absolute; top: 0; left: 22%; right: 22%;
  height: 4px; border-radius: 0 0 4px 4px; background: var(--brand);
}

/* ---------- Resumo ---------- */
.nav-dia {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; margin-bottom: 4px;
}
.nav-dia-txt { flex: 1; text-align: center; display: flex; flex-direction: column; line-height: 1.2; }
.nav-dia-txt strong { font-size: 21px; }
.nav-dia-txt small { color: var(--muted); font-size: 15px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 6px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.kpi span { display: block; color: var(--ink2); font-size: 15px; font-weight: 700; }
.kpi strong { display: block; font-size: 27px; font-weight: 800; margin-top: 2px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.kpi small { display: block; color: var(--muted); font-size: 14px; }
.kpi.destaque { background: var(--brand-escuro); border-color: var(--brand-escuro); color: #fff; }
.kpi.destaque span, .kpi.destaque small { color: #fde4d3; }
.nota { color: var(--muted); font-size: 15px; margin: 6px 2px 0; }
.cartao {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-top: 14px;
}
.cartao h3 { margin: 0 0 2px; font-size: 19px; }
.cartao .dica { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
.grafico { display: flex; align-items: stretch; gap: 6px; height: 200px; }
.g-col {
  flex: 1; min-width: 0; background: none; border: 0; padding: 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.g-valor { font-size: 14px; font-weight: 800; height: 20px; white-space: nowrap; color: var(--ink); }
.g-area {
  flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center;
  border-bottom: 2px solid var(--line);
}
.g-barra { width: 100%; max-width: 46px; background: var(--barra-clara); border-radius: 4px 4px 0 0; }
.g-col:hover .g-barra { filter: brightness(.95); }
.g-col.sel .g-barra { background: var(--brand); }
.g-rot { display: flex; flex-direction: column; align-items: center; line-height: 1.1; font-size: 13px; color: var(--muted); font-weight: 700; }
.g-col.sel .g-rot { color: var(--ink); }
.linhas { margin: 0; padding: 0; list-style: none; }
.linhas li, .linhas button {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  width: 100%; padding: 12px 2px; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left; font-size: 18px;
}
.linhas li:last-child, .linhas button:last-child { border-bottom: 0; }
.linhas strong { white-space: nowrap; }
.linhas .qtd-tag {
  display: inline-block; min-width: 44px; text-align: center; margin-right: 10px;
  background: var(--brand-soft); color: var(--brand); border-radius: 8px; padding: 2px 6px; font-weight: 800;
}
.linhas .deve { color: var(--warn); }

/* ---------- Mercadorias ---------- */
.merc {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 12px 12px 12px; margin-bottom: 8px; box-shadow: var(--shadow);
  width: 100%; text-align: left;
}
.merc-q {
  min-width: 72px; text-align: center; display: flex; flex-direction: column; line-height: 1.1;
  background: var(--brand-soft); color: var(--brand); border-radius: 12px; padding: 8px 6px; flex: none;
}
.merc-q strong { font-size: 24px; }
.merc-q small { font-size: 13px; font-weight: 800; }
.merc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.merc-nome { font-weight: 700; font-size: 19px; overflow-wrap: anywhere; }
.merc-info small { color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }
.merc-editar { color: var(--muted); font-size: 15px; font-weight: 700; flex: none; }

/* ---------- Preços ---------- */
.prod-linha {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  width: 100%; min-height: 64px; padding: 12px 16px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  text-align: left; font-size: 19px; font-weight: 600; box-shadow: var(--shadow);
}
.prod-linha span { min-width: 0; overflow-wrap: anywhere; }
.prod-linha strong { font-size: 20px; white-space: nowrap; }
.aviso { background: #fff8e6; border: 1px solid #f3d48a; color: #6b4a00; border-radius: 14px; padding: 12px 16px; margin-bottom: 12px; }
.aviso small { display: block; margin-top: 6px; }
.versao { text-align: center; color: var(--muted); font-size: 14px; margin-top: 28px; }

/* ---------- Janela (modal) ---------- */
.modal-fundo {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(28, 25, 23, .5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: aparecer .15s ease-out;
}
.modal {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 22px 22px 0 0;
  padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow: auto;
  animation: subir .2s ease-out;
}
@media (min-width: 700px) {
  .modal-fundo { align-items: center; }
  .modal { border-radius: 22px; }
}
.modal h2 { margin: 0 0 6px; font-size: 24px; }
.modal p { margin: 0 0 8px; color: var(--ink2); }
.modal-botoes { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.modal-botoes .btn { flex: 1 1 140px; }
.unidades { display: flex; flex-wrap: wrap; gap: 8px; }
.unidades .chip { flex: 0 0 auto; }
.qtd-grande { display: flex; align-items: center; gap: 10px; }
.linha-outro-dia { display: flex; gap: 10px; }
.linha-outro-dia .campo { flex: 1; min-width: 0; font-size: 18px; }
.linha-outro-dia .btn { flex: none; }
.qtd-grande .campo { text-align: center; font-size: 26px; font-weight: 800; flex: 1; min-width: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 14px 22px; border-radius: 999px;
  font-weight: 700; opacity: 0; pointer-events: none; transition: .2s; white-space: nowrap;
}
.toast.mostrar { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Entrada (login) — versão 7 ---------- */
.login { max-width: 440px; margin: 0 auto; padding-top: 24px; }
.login-icone { display: block; width: 84px; height: 84px; border-radius: 20px; margin: 0 auto 12px; }
.login-titulo { text-align: center; font-size: 26px; margin-bottom: 10px; overflow-wrap: anywhere; }
.login-texto { text-align: center; font-size: 19px; color: var(--ink2); line-height: 1.45; overflow-wrap: anywhere; }
.mostrar-senha { display: flex; align-items: center; gap: 12px; margin-top: 16px; font-size: 18px; min-height: 44px; }
.mostrar-senha input { width: 26px; height: 26px; accent-color: var(--brand); }
.nota.centro { text-align: center; margin-top: 18px; }

/* Conta que só pode ver: some com os botões de mudar */
body.so-ver .fiado-acoes,
body.so-ver .rodape-acoes,
body.so-ver [data-action="novo-cliente"],
body.so-ver [data-action="anotar"],
body.so-ver [data-action="anotar-entrega"],
body.so-ver [data-action="nova-entrega"],
body.so-ver [data-action="novo-produto"],
body.so-ver [data-action="importar"] { display: none !important; }

@keyframes aparecer { from { opacity: 0; } }
@keyframes subir { from { transform: translateY(30px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
