:root {
  --fundo: #F6F7F5;
  --superficie: #FFFFFF;
  --texto: #1F2A2E;
  --texto-2: #5C676B;
  --texto-3: #3D484C;
  --texto-apagado: #6E797D;
  --borda: #DCE1DE;
  --borda-2: #E1E5E3;
  --borda-forte: #C9D0CC;
  --tracejado: #CFD5D2;
  --apoio: #ECEFED;
  --aviso: #F1F4F2;
  --gasto: #C62F2A;
  --ok: #2E6A4E;
  --overlay: rgba(31, 42, 46, 0.5);
  --fonte: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --seguro-topo: env(safe-area-inset-top, 0px);
  --seguro-base: env(safe-area-inset-bottom, 0px);
  --seguro-esq: env(safe-area-inset-left, 0px);
  --seguro-dir: env(safe-area-inset-right, 0px);
  --margem: clamp(16px, 4vw, 40px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  background: var(--fundo);
  color: var(--texto);
  font-family: var(--fonte);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid #1F2A2E; outline-offset: 2px; }

/* ---------- Telas ---------- */
.tela {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding-left: var(--seguro-esq);
  padding-right: var(--seguro-dir);
}
.conteudo { flex: 1 1 auto; overflow-y: auto; padding: 0 var(--margem); -webkit-overflow-scrolling: touch; }

/* ---------- Cabeçalho ---------- */
.topo {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 12px;
  padding: calc(20px + var(--seguro-topo)) var(--margem) 12px;
}
.topo h1 { margin: 0; font-size: 30px; font-weight: 800; font-stretch: 85%; letter-spacing: -0.01em; line-height: 1.1; }
.topo-sub { display: flex; align-items: center; gap: 2px; font-size: 14px; color: var(--texto-2); }
.topo-acoes { display: flex; gap: 8px; }
.btn-config { width: 44px; height: 44px; margin: -12px 0 -12px -6px; color: var(--texto-2); }

@media (max-width: 389px) {
  .topo h1 { font-size: 26px; }
  .topo-acoes { gap: 6px; }
  .topo-acoes .btn-pilula { padding: 0 12px; font-size: 15px; }
}

.topo-voltar { justify-content: flex-start; gap: 8px; padding-left: 12px; padding-right: 12px; }
.topo-voltar h1 { font-size: 26px; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  font-weight: 700;
  text-decoration: none;
  color: var(--texto);
}
.btn-pilula { height: 44px; padding: 0 14px; border-radius: 22px; }
.btn-grande { height: 52px; border-radius: 14px; font-size: 16px; padding: 0 12px; }
.btn-bloco { width: 100%; margin-top: 12px; }
.btn-contorno { border: 1px solid var(--borda); background: transparent; font-weight: 600; }
.btn-grande.btn-contorno { border-color: var(--borda-forte); background: var(--superficie); font-weight: 700; }
.btn-grafite { background: var(--texto); color: #FFFFFF; }
.btn-grafite:disabled { background: var(--borda); color: var(--texto-apagado); }
.btn-gasto { background: var(--gasto); color: #FFFFFF; }
.btn-gasto:disabled { background: var(--borda); color: var(--texto-apagado); }

.btn-icone {
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 22px; background: transparent; color: var(--texto); padding: 0;
}

/* ---------- Lista do carrinho ---------- */
.lista { list-style: none; margin: 0; padding: 0 0 8px; }
.item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 14px 0;
  border-bottom: 1px solid var(--borda-2);
}
.miniatura {
  width: 56px; height: 56px; padding: 0; border: 0; border-radius: 10px;
  background: #E7EBE8; color: #8A9599; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.miniatura img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-meio { min-width: 0; }
.item-nome { font-weight: 600; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.item-calc { font-size: 14px; color: var(--texto-2); margin-top: 2px; font-variant-numeric: tabular-nums; }
.item-qtd { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.item-qtd .btn-qtd { width: 44px; height: 44px; border-radius: 10px; font-size: 18px; }
.item-qtd output { min-width: 28px; text-align: center; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.item-dir { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.item-sub { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.link-remover {
  border: 0; background: transparent; color: var(--texto-2);
  font-size: 13px; text-decoration: underline; padding: 12px 0 12px 12px; min-height: 44px;
}

.btn-qtd {
  flex-shrink: 0; font-weight: 700; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.btn-menos { border: 1px solid var(--borda); background: var(--superficie); color: var(--texto); }
.btn-menos:disabled { color: #A9B2B0; }
.btn-mais { border: 0; background: var(--gasto); color: #FFFFFF; }

/* ---------- Carrinho vazio ---------- */
.vazio {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 0 20px; gap: 10px;
}
.vazio-icone {
  width: 88px; height: 88px; border-radius: 50%; background: var(--apoio); color: var(--texto-apagado);
  display: flex; align-items: center; justify-content: center;
}
.vazio h2 { margin: 6px 0 0; font-size: 22px; font-weight: 700; font-stretch: 85%; }
.vazio p { margin: 0; font-size: 16px; line-height: 1.5; color: var(--texto-2); }

/* ---------- Barra inferior (cupom) ---------- */
.rodape { padding: 0 12px calc(16px + var(--seguro-base)); filter: drop-shadow(0 -2px 10px rgba(31, 42, 46, 0.08)); }
.recibo {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 16px 16px 20px;
  background: var(--superficie);
  border-radius: 0 0 18px 18px;
  margin-top: 8px;
}
.recibo::before {
  content: "";
  position: absolute; left: 0; right: 0; top: -8px; height: 8px;
  background: radial-gradient(circle at 6px 0, transparent 5px, var(--superficie) 5.5px) 0 0 / 12px 8px repeat-x;
}
.recibo-info { flex: 1 1 auto; min-width: 0; }
.recibo-rotulo { font-size: 13px; color: var(--texto-2); font-weight: 600; }
.valor-grande {
  font-size: 42px; font-weight: 800; font-stretch: 70%; line-height: 1.05;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.valor-grande.zerado { color: #8A9599; }
.recibo-ultimo {
  margin-top: 6px; border-top: 1px dashed var(--tracejado); padding-top: 6px;
  font-size: 13px; color: var(--texto-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-adicionar {
  flex-shrink: 0;
  width: 76px; height: 76px; border: 0; border-radius: 20px;
  background: var(--gasto); color: #FFFFFF;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 13px; font-weight: 700;
}
.btn-adicionar:active { transform: scale(0.97); }

@keyframes pulso {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.valor-grande.mudou { animation: pulso 280ms ease-out; transform-origin: left center; }
@media (prefers-reduced-motion: reduce) {
  .valor-grande.mudou { animation: none; }
  .painel[open] { animation: none !important; }
}

/* ---------- Painéis (bottom sheet) ---------- */
dialog { color: var(--texto); }
dialog::backdrop { background: var(--overlay); }
.painel {
  width: 100%; max-width: 600px;
  max-height: calc(100dvh - 24px - var(--seguro-topo));
  margin: auto auto 0;
  padding: 10px 20px calc(20px + var(--seguro-base));
  border: 0; border-radius: 22px 22px 0 0;
  background: var(--superficie);
  overflow-y: auto;
}
.painel[open] { animation: subir 220ms ease-out; }
@keyframes subir { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.painel form { display: flex; flex-direction: column; }
.painel-alca { width: 40px; height: 4px; border-radius: 2px; background: var(--borda); margin: 0 auto 14px; }
.painel h2 { margin: 0 0 12px; font-size: 21px; font-weight: 700; font-stretch: 85%; }
.painel-sub { margin: -6px 0 0; font-size: 15px; color: var(--texto-2); }

.conf-foto {
  height: 160px; width: 100%; padding: 0; border: 0; border-radius: 14px;
  background: var(--apoio); overflow: hidden; display: block;
}
.conf-foto img { width: 100%; height: 100%; object-fit: contain; display: block; }

.aviso {
  display: flex; gap: 8px; align-items: flex-start;
  margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--aviso); font-size: 14px; line-height: 1.4; color: var(--texto-3);
}
.aviso svg { flex-shrink: 0; margin-top: 1px; }

.rotulo { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
.linha-2 .rotulo { margin-top: 12px; }
.campo {
  width: 100%; height: 48px; padding: 0 14px;
  border: 1px solid var(--borda); border-radius: 12px;
  background: var(--fundo); font-size: 17px; color: var(--texto);
}
.campo:focus { border: 2px solid var(--texto); background: var(--superficie); outline: none; padding: 0 13px; }
.linha-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 4px; }
.col { display: flex; flex-direction: column; min-width: 0; }

.qtd-campo { display: flex; align-items: center; gap: 6px; height: 48px; }
.qtd-campo .btn-qtd { width: 48px; height: 48px; border-radius: 12px; font-size: 20px; }
.campo-qtd { min-width: 0; padding: 0; text-align: center; font-weight: 600; }
.campo-qtd:focus { padding: 0; }
.campo-sufixo { position: relative; }
.campo-sufixo .campo { padding-right: 40px; font-weight: 600; }
.campo-sufixo span {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-size: 15px; color: var(--texto-2); pointer-events: none;
}
.dica { font-size: 13px; color: var(--texto-2); margin-top: 6px; text-align: right; }

.escolhas { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.escolhas button {
  min-height: 44px; padding: 0 14px; border-radius: 22px;
  border: 1px solid var(--borda); background: var(--superficie);
  font-size: 14px; font-weight: 600;
}
.escolhas button[aria-pressed="true"] { border-color: var(--texto); background: var(--texto); color: #FFFFFF; }

.segmentado {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px;
  margin-top: 12px; padding: 4px; border-radius: 12px; background: var(--apoio);
}
.segmentado button {
  height: 44px; border: 0; border-radius: 9px; background: transparent;
  font-size: 14px; font-weight: 600; color: var(--texto-2);
}
.segmentado button[aria-pressed="true"] {
  background: var(--superficie); color: var(--texto); font-weight: 700;
  box-shadow: 0 1px 2px rgba(31, 42, 46, 0.12);
}

.soma {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--tracejado);
}
.soma > span:first-child { font-size: 15px; color: var(--texto-2); }
.valor-medio { font-size: 28px; font-weight: 800; font-stretch: 75%; font-variant-numeric: tabular-nums; }
.confere {
  display: flex; align-items: center; gap: 6px; justify-content: flex-end;
  font-size: 13px; color: var(--ok); margin-top: 2px;
}

.acoes { display: grid; grid-template-columns: 1fr 1.5fr; gap: 12px; margin-top: 16px; }

/* ---------- Finalizar ---------- */
.cupom {
  list-style: none; margin: 16px 0 0; padding: 4px 0;
  border-top: 1px dashed var(--tracejado); border-bottom: 1px dashed var(--tracejado);
}
.cupom li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 15px; }
.cupom li span:first-child { min-width: 0; overflow-wrap: anywhere; }
.cupom li span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.fin-total { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 12px; }
.fin-total > span:first-child { font-size: 15px; font-weight: 600; }
.valor-total-fin { font-size: 36px; font-weight: 800; font-stretch: 70%; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Histórico ---------- */
.cartoes { list-style: none; margin: 0; padding: 0 0 calc(20px + var(--seguro-base)); display: flex; flex-direction: column; gap: 12px; }
.cartao {
  border: 1px solid var(--borda-2); background: var(--superficie); border-radius: 14px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
}
.cartao-topo { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.cartao-data { font-size: 15px; font-weight: 600; }
.cartao-total { font-size: 22px; font-weight: 800; font-stretch: 75%; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cartao-qtd { font-size: 13px; color: var(--texto-2); }
.cartao-itens {
  font-size: 14px; color: var(--texto-3); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cartao .btn { margin-top: 8px; height: 44px; border: 1px solid var(--borda); background: var(--fundo); border-radius: 12px; font-size: 15px; font-weight: 600; }
.cartao .btn:disabled { color: var(--texto-apagado); }
.historico-vazio { text-align: center; color: var(--texto-2); margin-top: 30vh; }

/* ---------- Foto ampliada ---------- */
.dlg-foto {
  width: 100vw; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: #111;
}
.dlg-foto img { width: 100%; height: 100%; object-fit: contain; display: block; }
.btn-fechar-foto {
  position: absolute; top: calc(12px + var(--seguro-topo)); right: 12px;
  width: 44px; height: 44px; border: 0; border-radius: 22px;
  background: rgba(255, 255, 255, 0.9); color: var(--texto); font-size: 18px; font-weight: 700;
}

/* ---------- Confirmação ---------- */
.dlg-centro {
  width: calc(100% - 32px); max-width: 420px;
  border: 0; border-radius: 18px; padding: 20px; background: var(--superficie);
}
.dlg-centro h2 { margin: 0 0 6px; font-size: 20px; font-weight: 700; font-stretch: 85%; }
.dlg-centro p { margin: 0; color: var(--texto-2); }
.dlg-centro .acoes { grid-template-columns: 1fr 1fr; }

/* ---------- Aviso rápido ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(120px + var(--seguro-base));
  max-width: 480px; margin: 0 auto;
  padding: 12px 16px; border-radius: 12px;
  background: var(--texto); color: #FFFFFF; font-size: 15px; z-index: 10;
}

/* ---------- Responsividade: ocupa a tela inteira em qualquer tamanho ---------- */
.rodape { padding-left: calc(var(--margem) - 8px); padding-right: calc(var(--margem) - 8px); }

/* Telas muito estreitas: preço e quantidade empilhados */
@media (max-width: 340px) {
  .linha-2 { grid-template-columns: 1fr; gap: 0; }
  .item { grid-template-columns: 48px minmax(0, 1fr) auto; gap: 10px; }
  .miniatura { width: 48px; height: 48px; }
  .valor-grande { font-size: 36px; }
  .btn-adicionar { width: 68px; height: 68px; }
}

/* Telas largas (tablet, desktop): itens e compras em colunas */
@media (min-width: 720px) {
  .lista { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); column-gap: 32px; }
  .cartoes { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
  .topo h1 { font-size: 36px; }
  .valor-grande { font-size: 52px; }
  .btn-adicionar { width: 88px; height: 88px; font-size: 14px; }
  .recibo { padding: 20px 20px 20px 28px; }
  .painel { max-width: 640px; }
}

/* Celular deitado ou janela baixa: painel com foto menor */
@media (max-height: 560px) {
  .topo { padding-top: calc(10px + var(--seguro-topo)); padding-bottom: 6px; }
  .conf-foto { height: 96px; }
  .valor-grande { font-size: 32px; }
  .btn-adicionar { width: 64px; height: 64px; }
  .recibo { padding-top: 10px; padding-bottom: 10px; }
  .rodape { padding-bottom: calc(8px + var(--seguro-base)); }
  .painel { max-height: calc(100dvh - 8px); }
}

/* ---------- Histórico: forma de pagamento ---------- */
.cartao-pag { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.cartao-pag label { font-size: 13px; color: var(--texto-2); }
.seletor {
  appearance: none; -webkit-appearance: none;
  min-height: 44px; max-width: 70%; padding: 0 36px 0 12px;
  border: 1px solid var(--borda); border-radius: 12px; background-color: var(--superficie);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235C676B' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  font-size: 15px; font-weight: 600; color: var(--texto); text-overflow: ellipsis;
}
.seletor.vazio-sel { color: var(--texto-2); font-weight: 500; }
.seletor:disabled { background-color: var(--fundo); color: var(--texto-apagado); }
