:root {
  --bg: #faf7f2; --card: #fff; --txt: #2b2420; --muted: #7a6f66; --linha: #e8e0d6;
  --pri: #7a3e1d; --pri-2: #a3532a; --ok: #2e7d32; --aviso: #e6a100; --erro: #c62828;
  --raio: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--txt); }
a { color: var(--pri); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; } h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }

.topo { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .6rem 1rem; background: var(--pri); color: #fff; }
.topo a { color: #fff; text-decoration: none; }
.marca { font-weight: 700; }
.evento { background: rgba(255,255,255,.15); padding: .15rem .6rem; border-radius: 99px; font-size: .85rem; }
.topo nav { display: flex; flex-wrap: wrap; gap: .25rem; margin-left: auto; }
.topo nav a { padding: .35rem .65rem; border-radius: 6px; font-size: .92rem; }
.topo nav a:hover { background: rgba(255,255,255,.15); }
.topo nav a.destaque { background: #fff; color: var(--pri); font-weight: 700; }

.conteudo { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.flash { padding: .7rem 1rem; border-radius: var(--raio); margin-bottom: 1rem; background: #e8f5e9; border: 1px solid #a5d6a7; }
.flash.erro { background: #ffebee; border-color: #ef9a9a; }

.cartoes { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.cartao { background: var(--card); border: 1px solid var(--linha); border-radius: var(--raio); padding: .9rem 1rem; }
.cartao .rot { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.cartao .val { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; }
.cartao .val.pos { color: var(--ok); } .cartao .val.neg { color: var(--erro); }
.grelha-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.painel { background: var(--card); border: 1px solid var(--linha); border-radius: var(--raio); padding: 1rem; }
.painel h2 { margin-top: 0; }

table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--linha); font-size: .93rem; vertical-align: middle; }
th { background: #f3ede5; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tabela-wrap { overflow-x: auto; border: 1px solid var(--linha); border-radius: var(--raio); }
tr.inativo td { color: #aaa; }
tr.baixo td { background: #fff8e1; } tr.esgotado td { background: #ffebee; }

.btn, button { display: inline-block; border: 0; border-radius: 8px; padding: .5rem .9rem; font: inherit; cursor: pointer; background: var(--pri); color: #fff; text-decoration: none; }
.btn.sec, button.sec { background: #ece4da; color: var(--txt); }
.btn.peq, button.peq { padding: .25rem .55rem; font-size: .85rem; }
.btn.perigo, button.perigo { background: var(--erro); }
.btn.ok, button.ok { background: var(--ok); }
button:disabled { opacity: .45; cursor: not-allowed; }
.acoes { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
form.inline { display: inline; }

form.form { background: var(--card); border: 1px solid var(--linha); border-radius: var(--raio); padding: 1rem; max-width: 640px; }
.campo { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .8rem; }
.campo label { font-size: .85rem; color: var(--muted); }
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #cfc4b8; border-radius: 8px; background: #fff; }
.linha-campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; }
.check { flex-direction: row; align-items: center; gap: .5rem; }

.etiqueta { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .78rem; background: #eee; }
.etiqueta.pendente { background: #fff3e0; color: #e65100; } .etiqueta.pronto { background: #e3f2fd; color: #1565c0; }
.etiqueta.entregue { background: #e8f5e9; color: var(--ok); } .etiqueta.anulado { background: #ffebee; color: var(--erro); }
.etiqueta.baixo { background: #fff3e0; color: #e65100; } .etiqueta.esgotado { background: #ffebee; color: var(--erro); }
.muted { color: var(--muted); }

/* Barras horizontais (sem bibliotecas externas — funciona sem internet) */
.barra { background: #f3ede5; border-radius: 4px; height: 14px; min-width: 60px; }
.barra > span { display: block; height: 100%; background: var(--pri-2); border-radius: 4px; }
.colunas { display: flex; align-items: flex-end; gap: 4px; height: 180px; padding-top: 1rem; overflow-x: auto; }
.colunas .col { flex: 1 0 34px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.colunas .col span.b { width: 100%; background: var(--pri-2); border-radius: 4px 4px 0 0; }
.colunas .col small { font-size: .7rem; color: var(--muted); white-space: nowrap; margin-top: 3px; }
.colunas .col em { font-size: .68rem; font-style: normal; color: var(--muted); }

/* ---------- POS / Caixa ---------- */
body.pos { height: 100vh; overflow: hidden; }
main.pos { display: grid; grid-template-columns: 1fr 360px; height: calc(100vh - 52px); }
.pos-produtos { overflow-y: auto; padding: .75rem; }
.filtros { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; position: sticky; top: 0; background: var(--bg); padding-bottom: .4rem; z-index: 1; }
.filtros button { background: #ece4da; color: var(--txt); } .filtros button.ativo { background: var(--pri); color: #fff; }
.grelha-prod { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.prod { position: relative; min-height: 96px; border-radius: 12px; padding: .7rem; color: #fff; text-align: left; display: flex; flex-direction: column; justify-content: space-between; font-weight: 600; box-shadow: 0 2px 0 rgba(0,0,0,.15); user-select: none; }
.prod:active { transform: scale(.97); }
.prod .preco { font-size: 1.1rem; }
.prod .st { position: absolute; top: 6px; right: 8px; font-size: .72rem; background: rgba(0,0,0,.25); padding: 1px 6px; border-radius: 99px; }
.prod.esgotado { filter: grayscale(1); opacity: .45; }
.pos-carrinho { background: var(--card); border-left: 1px solid var(--linha); display: flex; flex-direction: column; }
.pos-carrinho .itens { flex: 1; overflow-y: auto; padding: .5rem .75rem; }
.item { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; padding: .45rem 0; border-bottom: 1px dashed var(--linha); }
.item .qtd { display: flex; align-items: center; gap: .3rem; }
.item .qtd button { width: 32px; height: 32px; padding: 0; background: #ece4da; color: var(--txt); font-weight: 700; }
.pos-total { padding: .75rem; border-top: 2px solid var(--linha); }
.pos-total .total { display: flex; justify-content: space-between; font-size: 1.6rem; font-weight: 800; margin-bottom: .5rem; }
.pos-total .notas { display: flex; gap: .35rem; flex-wrap: wrap; margin: .4rem 0; }
.pos-total .notas button { flex: 1; background: #ece4da; color: var(--txt); padding: .45rem .3rem; }
.pos-total .troco { font-size: 1.1rem; margin: .3rem 0 .6rem; }
.pos-total .finalizar { width: 100%; padding: 1rem; font-size: 1.25rem; font-weight: 700; background: var(--ok); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; z-index: 10; }
.modal.aberto { display: flex; }
.modal .caixa { background: #fff; border-radius: 16px; padding: 2rem; text-align: center; min-width: 300px; }
.modal .senha { font-size: 5rem; font-weight: 900; color: var(--pri); line-height: 1; margin: .5rem 0; }

@media (max-width: 800px) {
  body.pos { overflow: auto; height: auto; }
  main.pos { grid-template-columns: 1fr; height: auto; }
  .pos-carrinho { border-left: 0; border-top: 2px solid var(--linha); position: sticky; bottom: 0; max-height: 55vh; }
}

/* ---------- Cozinha / Senhas ---------- */
.kds { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .75rem; }
.ticket { background: #fff; border: 2px solid var(--linha); border-radius: 12px; padding: .75rem; display: flex; flex-direction: column; gap: .4rem; }
.ticket.atraso { border-color: var(--aviso); } .ticket.muito-atraso { border-color: var(--erro); }
.ticket .cab { display: flex; justify-content: space-between; align-items: baseline; }
.ticket .num { font-size: 2rem; font-weight: 900; color: var(--pri); }
.ticket ul { margin: 0; padding-left: 1.1rem; font-size: 1.05rem; }
.ticket .nota { background: #fff8e1; padding: .3rem .5rem; border-radius: 6px; font-size: .88rem; }
body.tv { background: #1b1410; color: #fff; }
.tv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; padding: 2rem; min-height: 100vh; }
.tv-grid h2 { font-size: 2.2rem; margin: 0 0 1rem; text-align: center; }
.tv-senhas { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; }
.tv-senhas span { font-size: 4rem; font-weight: 900; background: #2e2520; border-radius: 16px; padding: .5rem 1.4rem; min-width: 150px; text-align: center; }
.tv-prontos span { background: var(--ok); animation: pulsar 2s ease-in-out 3; }
@keyframes pulsar { 50% { transform: scale(1.08); } }

/* ---------- Talão ---------- */
body.talao { background: #fff; }
.talao-papel { width: 72mm; margin: 0 auto; font-family: "Courier New", monospace; font-size: 13px; padding: 4mm 0; }
.talao-papel .c { text-align: center; }
.talao-papel .senha { font-size: 54px; font-weight: 900; text-align: center; line-height: 1.1; margin: 4px 0; }
.talao-papel table { background: none; } .talao-papel td { border: 0; padding: 1px 0; font-size: 13px; }
.talao-papel hr { border: 0; border-top: 1px dashed #000; }
.corte { page-break-after: always; }
@media print { .nao-imprimir { display: none !important; } @page { margin: 0; } }
.prod > span:not(.st):not(.preco) { padding-right: 34px; }

/* ---------- v2 ---------- */
body { display: flex; flex-direction: column; min-height: 100vh; }
main.conteudo { flex: 1; width: 100%; }
.topo nav a.atual { background: rgba(255,255,255,.22); }
.topo { position: relative; z-index: 5; }
details.menu-admin, details.menu-user { position: relative; }
details.menu-admin summary, details.menu-user summary { list-style: none; cursor: pointer; padding: .35rem .65rem; border-radius: 6px; font-size: .92rem; }
details summary::-webkit-details-marker { display: none; }
details.menu-admin summary:hover, details.menu-user summary:hover { background: rgba(255,255,255,.15); }
details.menu-admin > div, details.menu-user > div { position: absolute; right: 0; top: 110%; background: #fff; border: 1px solid var(--linha); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 190px; padding: .35rem; display: flex; flex-direction: column; z-index: 20; }
details.menu-admin > div a, details.menu-user > div a { color: var(--txt) !important; padding: .5rem .7rem; border-radius: 6px; }
details.menu-admin > div a:hover, details.menu-user > div a:hover { background: #f3ede5; }
details.menu-user > div .muted { padding: .4rem .7rem; font-size: .8rem; }
.menu-user { color: #fff; }
.rodape { text-align: center; font-size: .78rem; color: var(--muted); padding: .5rem 1rem; border-top: 1px solid var(--linha); background: #f6f1ea; }
body.pos .rodape { padding: .2rem; font-size: .7rem; }
main.pos { height: calc(100vh - 52px - 24px); }
body.tv .rodape { background: transparent; border: 0; color: #776; }
.modal .caixa.confirmar { max-width: 420px; }
.modal .caixa.confirmar h2 { margin: 0 0 .5rem; font-size: 1.3rem; }
.modal .caixa.confirmar .botoes { display: flex; gap: .75rem; margin-top: 1.25rem; }
.modal .caixa.confirmar .botoes button { flex: 1; padding: .9rem; font-size: 1.1rem; font-weight: 600; }
.ticket .acoes-t { display: flex; flex-direction: column; gap: .4rem; }
.ticket .acoes-t button { padding: .7rem; font-size: 1rem; }
.ticket button.reverter { background: #fff; color: var(--erro); border: 2px solid #f1c3c3; padding: .45rem; font-size: .9rem; }
.ticket .meta { font-size: .82rem; color: var(--muted); display: flex; gap: .5rem; flex-wrap: wrap; }
.ticket .mesa { background: #ede7f6; color: #4527a0; padding: 0 .45rem; border-radius: 99px; font-weight: 600; }
.ticket .outros { font-size: .8rem; color: var(--muted); }
.kds-posto-bebidas .ticket .num { color: #1565c0; }
.login-caixa { max-width: 380px; margin: 4rem auto; }
.etiqueta.credito { background: #ede7f6; color: #4527a0; }
.etiqueta.pago { background: #e8f5e9; color: var(--ok); }
.etiqueta.por_pagar { background: #fff3e0; color: #e65100; }
.etiqueta.reservada { background: #ede7f6; color: #4527a0; }
.cartao .val.aviso { color: #e65100; }
.pos-mesa { padding: .5rem .75rem; border-bottom: 1px solid var(--linha); display: grid; gap: .4rem; }
.pos-mesa select { width: 100%; }
.credito-toggle { display: flex; align-items: center; gap: .5rem; font-weight: 600; padding: .45rem .6rem; border-radius: 8px; background: #f3ede5; cursor: pointer; user-select: none; }
.credito-toggle.ativo { background: #ede7f6; color: #4527a0; }
.credito-toggle input { width: 20px; height: 20px; }
.pos-total .finalizar.credito { background: #5e35b1; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .3rem .8rem; }
.perm-grid label { display: flex; gap: .45rem; align-items: center; padding: .3rem 0; color: var(--txt); font-size: .93rem; }
.codigo-licenca { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; word-break: break-all; width: 100%; }
.reserva-form { display: grid; grid-template-columns: 70px 1fr 110px 115px auto; gap: .35rem; align-items: center; }
.pessoas { display: inline-flex; align-items: center; gap: .3rem; }
.pessoas form { display: inline; }
.pessoas button { width: 34px; height: 34px; padding: 0; font-weight: 700; }
.pessoas strong { min-width: 2ch; text-align: center; font-size: 1.15rem; }
@media (max-width: 800px) { .reserva-form { grid-template-columns: 1fr 1fr; } }
.topo { flex-wrap: nowrap; }
.marca { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1; }
.evento { white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.topo nav { flex-wrap: nowrap; gap: .1rem; }
.topo nav a, details.menu-admin summary, details.menu-user summary { padding: .35rem .5rem; font-size: .88rem; white-space: nowrap; }
@media (max-width: 1250px) { .topo { flex-wrap: wrap; } .topo nav { flex-wrap: wrap; } .evento { display: none; } }
body.pos main.pos { flex: 1; min-height: 0; height: auto; }

/* ---------- v3 ---------- */
:root { --menu: #7a3e1d; --menu-txt: #fff; }
.topo { background: var(--menu); color: var(--menu-txt); }
.topo a, .topo .menu-user, .topo summary { color: var(--menu-txt); }
.topo nav a:hover, details.menu-admin summary:hover, details.menu-user summary:hover,
.topo nav a.atual { background: color-mix(in srgb, currentColor 18%, transparent); }
.evento { background: color-mix(in srgb, currentColor 15%, transparent); }
.marca { display: inline-flex; align-items: center; gap: .45rem; }
.marca .logo { height: 34px; width: auto; max-width: 90px; object-fit: contain; border-radius: 4px; }
.marca span { overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; vertical-align: middle; border: 2px solid color-mix(in srgb, currentColor 40%, transparent); }
.avatar.grande { width: 72px; height: 72px; border: 0; }
.menu-toggle { display: none; background: transparent; color: var(--menu-txt); font-size: 1.5rem; padding: .1rem .5rem; margin-left: auto; }
details.menu-user { margin-left: .25rem; }

/* marca de água */
body.com-fundo::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-size: cover; background-position: center; background-repeat: no-repeat; }
body.com-fundo .rodape { background: color-mix(in srgb, #f6f1ea 85%, transparent); }

/* menu em ecrãs pequenos (telemóvel / tablet ao alto) */
@media (max-width: 900px) {
  .topo { flex-wrap: wrap; }
  .menu-toggle { display: block; }
  .topo nav { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 0; margin: .3rem 0 0;
              border-top: 1px solid color-mix(in srgb, currentColor 25%, transparent); padding-top: .3rem; }
  body.menu-aberto .topo nav { display: flex; }
  .topo nav a, details.menu-admin summary, details.menu-user summary { padding: .7rem .6rem; font-size: 1rem; }
  details.menu-admin > div, details.menu-user > div {
    position: static; box-shadow: none; border: 0; border-radius: 8px; min-width: 0;
    background: color-mix(in srgb, #fff 92%, var(--menu)); margin: 0 0 .4rem .6rem; }
  details.menu-user { margin-left: 0; }
  .marca { max-width: calc(100% - 60px); }
  body.pos main.pos { height: auto; }
}

.form-largo { max-width: 860px; }
.sec-titulo { font-size: 1rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1.2rem 0 .6rem; border-bottom: 1px solid var(--linha); padding-bottom: .3rem; }
.sec-titulo:first-child { margin-top: 0; }
.cores { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.cores input[type=color] { width: 56px; height: 40px; padding: 2px; }
.cor-amostra { display: inline-block; width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(0,0,0,.15); vertical-align: middle; padding: 0; }
.cor-amostra.grande { width: 34px; height: 34px; border-radius: 8px; cursor: pointer; }
.previa-menu { margin-top: .5rem; padding: .6rem .9rem; border-radius: 10px; display: flex; align-items: center; gap: .6rem; font-size: .92rem; }
.previa-menu img { height: 30px; }
.img-atual { display: flex; align-items: center; gap: .8rem; margin-bottom: .4rem; padding: .4rem; background: #f6f1ea; border-radius: 8px; }
.mini-logo { width: 28px; height: 28px; object-fit: contain; vertical-align: middle; }
.login-logo { display: block; margin: 0 auto .5rem; max-height: 110px; max-width: 220px; object-fit: contain; }
.grelha-logs { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; }
@media (max-width: 900px) { .grelha-logs { grid-template-columns: 1fr; } }
pre.log { background: #1b1410; color: #e8e0d6; padding: .8rem; border-radius: 8px; font-size: .78rem; line-height: 1.45; overflow: auto; max-height: 70vh; white-space: pre-wrap; word-break: break-word; margin: 0; }
pre.log .l-aviso { color: #ffcc80; } pre.log .l-erro { color: #ef9a9a; }
.edicao-banner { background: #fff3e0; border: 2px solid #ffb74d; color: #e65100; padding: .45rem .75rem; font-weight: 600; display: flex; align-items: center; gap: .5rem; }
.etiqueta.editado { background: #fff3e0; color: #e65100; }
.ticket .editado { background: #fff3e0; color: #e65100; padding: 0 .45rem; border-radius: 99px; font-weight: 700; }
.mesa-check { width: 20px; height: 20px; }
.edicao-banner[hidden] { display: none !important; }
