:root {
  --brasa: #e0501c; --brasa-esc: #b93f13; --tinta: #201f1d; --texto: #2b2623; --suave: #7a716a;
  --fundo: #fafafa; --cartao: #fff; --linha: #e8e6e3; --verde: #22c55e; --ok: #2e7d32; --aviso: #b26a00; --erro: #c62828;
  --topo: env(safe-area-inset-top, 0px); --base: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--fundo); color: var(--texto);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
[hidden] { display: none !important; }
svg { width: 1.1em; height: 1.1em; fill: currentColor; flex: none; }

.ecra { min-height: 100vh; }

/* Entrar / ativar notificações */
.login { max-width: 380px; margin: 0 auto; padding: calc(var(--topo) + 40px) 24px 40px; text-align: center; }
.login-logo { border-radius: 24px; background: #fff; }
.login h1 { margin: 16px 0 4px; font-size: 26px; }
.login p { margin: 8px 0; }
.icone-grande { width: 72px; height: 72px; color: var(--brasa); margin-top: 8px; }
.pin { width: 100%; margin: 18px 0 12px; padding: 14px; font-size: 32px; letter-spacing: .5em; text-align: center; border: 2px solid var(--linha);
  border-radius: 12px; background: #fff; color: var(--texto); }
.pin:focus { outline: none; border-color: var(--brasa); }
.suave { color: var(--suave); }
.sem-conta { margin-top: 28px !important; }
.campo-texto { width: 100%; margin: 6px 0; padding: 14px; font: inherit; font-size: 17px; border: 2px solid var(--linha); border-radius: 12px; background: #fff; color: var(--texto); }
.campo-texto:focus { outline: none; border-color: var(--brasa); }
.pin-mostrado { margin: 12px 0; padding: 14px; font-size: 36px; font-weight: 700; letter-spacing: .4em; text-indent: .4em; border: 2px dashed var(--brasa); border-radius: 12px; background: #fff; user-select: all; }
#form-registo .btn-grande { margin-top: 10px; }
.erro { color: var(--erro); font-weight: 600; }
.aviso { background: #fff4e0; border: 1px solid #f2d39b; color: #6b4300; border-radius: 10px; padding: 10px 12px; text-align: left; }

/* Botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 16px; border: 0; border-radius: 12px;
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .55; }
.btn-brasa { background: var(--brasa); color: #fff; }
.btn-brasa:active { background: var(--brasa-esc); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-claro { background: #fff; color: var(--texto); border: 1.5px solid var(--linha); }
.btn-link { background: none; color: var(--suave); font-weight: 600; }
.btn-grande { width: 100%; padding: 16px; font-size: 18px; }
.btn-bloco { width: 100%; }
.btn-icone { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: rgba(255,255,255,.12); color: #fff; font-size: 20px; cursor: pointer; }
.btn-icone svg { width: 1.2em; height: 1.2em; }

/* Topo */
.topo { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: calc(var(--topo) + 14px) 18px 10px; background: var(--fundo); }
.marca { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; background: var(--tinta); color: #fff; font-size: 22px; flex: none; }
.topo-texto { flex: 1; min-width: 0; }
.topo-nome { font-weight: 700; font-size: 18px; line-height: 1.2; }
.topo-sub { font-size: 15px; color: var(--suave); }
.btn-sino { display: grid; place-items: center; width: 44px; height: 44px; border: 0; background: none; color: var(--texto); font-size: 20px; cursor: pointer; }
.btn-sino.sem-push { color: var(--erro); }
.faixa { margin: 0 18px; padding: 8px 12px; border-radius: 10px; background: var(--aviso); color: #fff; font-weight: 600; text-align: center; font-size: 14px; }

.conteudo { padding: 6px 18px calc(var(--base) + 96px); max-width: 640px; margin: 0 auto; }

/* Cartão de boas-vindas */
.boas-vindas { margin-top: 6px; padding: 16px; border-radius: 22px; background: var(--tinta); color: #fff; }
.bv-topo { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.bv-etiqueta { font-size: 13px; letter-spacing: .02em; color: #d8cdb8; }
.bv-nome { margin-top: 2px; font-size: 26px; font-weight: 700; line-height: 1.2; }
.bv-botoes { display: flex; gap: 8px; }
.bv-fundo { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 18px; }
.bv-estado { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; }
.ponto { width: 11px; height: 11px; border-radius: 50%; background: var(--verde); }
.bv-estado.pausa .ponto { background: #8b8580; }
.pilula-online { padding: 4px 11px; border-radius: 999px; background: rgba(34,197,94,.16); color: var(--verde); font-weight: 700; font-size: 14px; }
.pilula-online.off { background: rgba(255,255,255,.12); color: #cfc8c1; }
.btn-icone { width: 40px; height: 40px; font-size: 18px; }
.btn-icone:active { background: rgba(255,255,255,.26); }
.btn-icone.a-rodar svg { animation: roda .8s linear infinite; }
@keyframes roda { to { transform: rotate(360deg); } }

/* Contadores */
.contadores { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 22px 0 8px; }
.contadores strong { display: block; font-size: 28px; font-weight: 600; line-height: 1.2; }
.contadores span { color: var(--suave); font-size: 16px; }
.contadores-hist { grid-template-columns: repeat(2, 1fr); padding-top: 14px; }

.seccao { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 12px; font-size: 18px; font-weight: 600; }
.contagem { padding: 3px 10px; border-radius: 999px; background: #efefed; font-size: 14px; font-weight: 700; }
.titulo-sep { margin: 14px 0 12px; font-size: 24px; font-weight: 700; }

/* Estado vazio */
.vazio { text-align: center; padding: 44px 8px 20px; }
.vazio-icone { width: 44px; height: 44px; color: #55504b; }
.vazio h3 { margin: 18px 0 14px; font-size: 20px; font-weight: 600; }
.vazio p { margin: 8px 0; color: var(--suave); line-height: 1.5; }
.vazio-ligacao { display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: var(--suave); }
.vazio-ligacao svg { color: var(--verde); }
.vazio-ligacao.off svg { color: var(--erro); }
.vazio-simples { text-align: center; color: var(--suave); padding: 28px 8px; }

/* Cartão de entrega */
.cartao { background: var(--cartao); border: 1px solid var(--linha); border-radius: 20px; padding: 16px; margin-bottom: 14px; }
.cartao.a-caminho { box-shadow: inset 4px 0 0 var(--brasa); }
.cartao.so-ver { opacity: .85; border-style: dashed; }
.cartao.recem-pronto { box-shadow: inset 4px 0 0 var(--verde); animation: pulsa 1.2s ease-in-out 4; }
@keyframes pulsa { 50% { background: rgba(34,197,94,.14); } }
.cartao-estado { margin-top: 10px; font-size: 14px; font-weight: 700; color: var(--suave); display: flex; align-items: center; gap: 6px; }
.cartao-topo { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cartao-id { font-weight: 800; font-size: 20px; }
.cartao-hora { font-size: 13px; color: var(--suave); display: inline-flex; align-items: center; gap: 4px; }
.cartao-cliente { margin-top: 2px; font-weight: 600; }
.linha-info { display: flex; align-items: flex-start; gap: 8px; margin-top: 8px; }
.linha-info svg { margin-top: 3px; color: var(--brasa); }
.morada { font-weight: 600; }
.zona { color: var(--suave); font-size: 14px; }
.contacto { display: flex; gap: 8px; margin-top: 12px; }
.contacto + .contacto { margin-top: 8px; }
.contacto .btn { flex: 1 1 0; }
.itens { margin: 12px 0 0; padding: 10px 0 0; border-top: 1px dashed var(--linha); list-style: none; font-size: 14px; }
.itens li { padding: 1px 0; }
.itens small { color: var(--suave); display: block; margin-left: 1.4em; }
.nota { margin-top: 10px; padding: 8px 10px; background: #eaf3fb; border-radius: 10px; font-size: 14px; display: flex; gap: 8px; }
.cobrar { margin-top: 10px; padding: 10px 12px; border-radius: 12px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.cobrar.devido { background: #fff4e0; color: #8a4b00; font-size: 19px; }
.cobrar.pago { background: #e8f5e9; color: var(--ok); font-size: 15px; }
.acoes { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.acoes .btn { flex: 1 1 140px; }
.acoes .btn-pequeno, .btn-pequeno { flex: 0 0 auto; padding: 12px 14px; }

/* Histórico */
.segmentos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: #efefed; }
.segmento { padding: 10px 0; border: 0; border-radius: 11px; background: none; font: inherit; font-weight: 600; color: var(--suave); cursor: pointer; }
.segmento.ativo { background: #fff; color: var(--texto); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.hist-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 2px; border-bottom: 1px solid var(--linha); }
.hist-item strong { display: block; }
.hist-item small { color: var(--suave); }
.hist-valor { font-weight: 700; white-space: nowrap; }

/* Perfil */
.perfil-cartao { display: flex; align-items: center; gap: 14px; padding: 16px; border: 1px solid var(--linha); border-radius: 20px; background: #fff; }
.avatar { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--tinta); color: #fff; font-size: 24px; }
.perfil-nome { font-size: 20px; font-weight: 700; }
.lista-defs { margin: 14px 0; border: 1px solid var(--linha); border-radius: 20px; background: #fff; }
.def { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; }
.def + .def { border-top: 1px solid var(--linha); }
.def-texto small { display: block; color: var(--suave); }
.form-pin { display: grid; gap: 10px; padding: 4px 16px 16px; }
.campo-pin { width: 100%; padding: 12px 14px; border: 1.5px solid var(--linha); border-radius: 12px; background: #fff; font: inherit; font-size: 18px; letter-spacing: .3em; color: var(--texto); }
.campo-pin::placeholder { letter-spacing: 0; font-size: 16px; }
.campo-pin:focus { outline: none; border-color: var(--brasa); }
.interruptor { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 52px; height: 30px; margin: 0; border-radius: 999px; background: #cfcac4; cursor: pointer; transition: background .15s; }
.interruptor::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.interruptor:checked { background: var(--verde); }
.interruptor:checked::after { transform: translateX(22px); }

/* Barra inferior */
.barra { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(3, 1fr); max-width: 640px; margin: 0 auto;
  padding: 8px 18px calc(var(--base) + 8px); background: rgba(250,250,250,.96); border-top: 1px solid var(--linha); backdrop-filter: blur(8px); }
.barra-item { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; border: 0; background: none; color: var(--suave); font: inherit; font-size: 14px; cursor: pointer; }
.barra-item svg { width: 22px; height: 22px; }
.barra-item.ativo { color: var(--texto); font-weight: 700; }

/* Puxar para atualizar */
.puxar { position: fixed; top: calc(var(--topo) + 8px); left: 50%; z-index: 20; display: grid; place-items: center; width: 38px; height: 38px; margin-left: -19px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.2); opacity: 0; transform: translateY(-60px); pointer-events: none; }
.puxar.a-carregar svg { animation: roda .8s linear infinite; }

/* Manter sessão (login) */
.manter { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 0 14px; color: var(--texto); cursor: pointer; }
.manter input { width: 22px; height: 22px; accent-color: var(--brasa); flex: none; }

/* Validação obrigatória da sessão: sem fechar, sem clicar fora */
.sessao-fundo { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0,0,0,.7); }
.sessao { width: 100%; max-width: 380px; padding: 24px 22px; border-radius: 22px; background: #fff; text-align: center; }
.sessao svg { width: 44px; height: 44px; color: var(--brasa); }
.sessao h2 { margin: 10px 0 6px; font-size: 22px; }
.sessao p { margin: 6px 0 14px; color: var(--suave); line-height: 1.45; }
.sessao .campo-pin { text-align: center; }
.sessao .erro { margin: 8px 0 0; }
.sessao .btn { width: 100%; margin-top: 12px; }

/* Convite para instalar */
.instalar-fundo { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.45); }
.instalar { width: 100%; max-width: 480px; padding: 22px 22px calc(var(--base) + 22px); border-radius: 24px 24px 0 0; background: #fff; text-align: center; }
.instalar img { border-radius: 18px; }
.instalar h2 { margin: 12px 0 6px; font-size: 22px; }
.instalar p { margin: 6px 0 14px; color: var(--suave); line-height: 1.45; }
.instalar ol { margin: 0 0 14px; padding: 0; list-style: none; text-align: left; color: var(--texto); }
.instalar li { padding: 8px 0; }
.instalar .btn { width: 100%; margin-top: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--base) + 84px); transform: translateX(-50%); max-width: 90vw; padding: 12px 18px;
  background: var(--tinta); color: #fff; border-radius: 12px; font-weight: 600; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.toast.erro { background: var(--erro); }

/* Aviso de nova versão da app nativa (Android, instalada fora da loja) */
.nova-versao { position: fixed; left: 12px; right: 12px; bottom: calc(var(--base) + 76px); z-index: 60; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--tinta); color: #fff; border-radius: 12px; padding: 10px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.28); font-size: .92rem; }
.nova-versao span { flex: 1 1 100%; }
.nova-versao .btn { padding: 8px 14px; min-height: 0; }
.nova-versao .btn-link { color: #fff; }
.toast.toast-largo { display: flex; align-items: center; justify-content: space-between; width: calc(100vw - 24px); max-width: 560px; box-sizing: border-box; }
.toast.toast-medio { width: calc(100vw - 56px); max-width: 440px; box-sizing: border-box; text-align: center; }
