:root {
  --fundo: #f5f1e8;
  --cartao: #fffdf8;
  --texto: #1d241f;
  --suave: #5f6b63;
  --linha: #e3dccd;
  --marca: #1f3a2e;
  --marca-texto: #fdf8ec;
  --acento: #d9822b;
  --acento-texto: #ffffff;
  --ok: #2f7d4f;
  --alerta: #c27a0a;
  --perigo: #b3402f;
  --novo: #fff1dc;
  --preparo: #e8f0fb;
  --caminho: #e6f4ea;
  --receita: #2a78d6;
  --despesa: #eb6834;
  --grelha: #ece6d8;
  --sombra: 0 1px 2px rgba(30, 35, 30, .06), 0 4px 14px rgba(30, 35, 30, .05);
  --raio: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fundo: #141a16; --cartao: #1c241f; --texto: #ecebe4; --suave: #a3ada6; --linha: #2e3a32;
    --marca: #0f1f17; --marca-texto: #f3ecd9; --acento: #e8923a; --novo: #3a2c16; --preparo: #1d2a3b; --caminho: #1b3324;
    --receita: #3987e5; --despesa: #d95926; --grelha: #2a352e; --sombra: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fundo: #141a16; --cartao: #1c241f; --texto: #ecebe4; --suave: #a3ada6; --linha: #2e3a32;
  --marca: #0f1f17; --marca-texto: #f3ecd9; --acento: #e8923a; --novo: #3a2c16; --preparo: #1d2a3b; --caminho: #1b3324;
  --receita: #3987e5; --despesa: #d95926; --grelha: #2a352e; --sombra: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--fundo); color: var(--texto); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }
[hidden] { display: none !important; }
a { color: inherit; }
code { background: var(--fundo); padding: 1px 5px; border-radius: 4px; }

input, textarea, select {
  font: inherit; color: inherit; background: var(--cartao); border: 1px solid var(--linha);
  border-radius: 8px; padding: .55rem .65rem; width: 100%; min-width: 0;
}
input:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--acento); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--suave); }
label.inline { flex-direction: row; align-items: center; gap: 6px; }
label.inline input { width: auto; }
label.check { flex-direction: row; align-items: center; color: var(--texto); font-size: .95rem; }
label.check input { width: auto; }

.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--linha); background: var(--cartao); color: var(--texto);
  border-radius: 8px; padding: .55rem .9rem; cursor: pointer; white-space: nowrap;
  transition: transform .1s ease, background-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primario { background: var(--acento); border-color: var(--acento); color: var(--acento-texto); }
.btn.fantasma { background: transparent; }
.btn.perigo { color: var(--perigo); background: transparent; }
.btn.pequeno { padding: .35rem .65rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }

.cartao { background: var(--cartao); border: 1px solid var(--linha); border-radius: var(--raio); padding: 1rem; box-shadow: var(--sombra); margin-bottom: 1rem; }

/* Entrar */
.entrar { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.entrar-caixa { width: min(340px, 100%); display: grid; gap: .8rem; text-align: center; }
.logo { font-size: 2.6rem; }
.erro { color: var(--perigo); min-height: 1.2em; margin: 0; }
.ok { color: var(--ok); }

/* Topo */
.topo { position: sticky; top: 0; z-index: 10; background: var(--marca); color: var(--marca-texto); display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .5rem 16px; }
.marca { display: flex; align-items: center; gap: .4rem; font-size: 1.05rem; }
.abas { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.abas button { font: inherit; background: none; border: 0; color: var(--marca-texto); opacity: .75; padding: .5rem .75rem; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.abas button.ativa { opacity: 1; background: rgba(255, 255, 255, .12); font-weight: 600; }
.topo-acoes { display: flex; gap: .4rem; }
.topo .btn { background: rgba(255, 255, 255, .1); color: var(--marca-texto); border-color: rgba(255, 255, 255, .2); }
.bolha { background: var(--acento); color: #fff; border-radius: 99px; padding: 0 .45rem; font-size: .75rem; font-weight: 700; margin-left: 2px; }
.faixa { background: #fff3cd; color: #4a3700; padding: .5rem 16px; font-size: .9rem; }

main { padding: 1rem 16px 3rem; max-width: 1500px; margin: 0 auto; }
.barra { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; margin-bottom: 1rem; }
.barra h2 { margin: 0; }
.barra input[type="date"] { width: auto; }
.resumo { display: flex; flex-wrap: wrap; gap: .4rem; color: var(--suave); font-size: .9rem; }
.resumo b { color: var(--texto); }
.titulo-sec { margin-top: 1.5rem; }
.nota { color: var(--suave); font-size: .85rem; }

/* Quadro de pedidos */
.quadro { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; align-items: start; }
.coluna h2 { display: flex; justify-content: space-between; padding: 0 .2rem; color: var(--suave); font-size: .9rem; text-transform: uppercase; letter-spacing: .03em; }
.lista { display: grid; gap: .6rem; }
.pedido { background: var(--cartao); border: 1px solid var(--linha); border-left: 5px solid var(--linha); border-radius: var(--raio); padding: .75rem; box-shadow: var(--sombra); display: grid; gap: .35rem; }
.pedido.e-novo { border-left-color: var(--acento); background: var(--novo); }
.pedido.e-preparo { border-left-color: #3d6fb6; }
.pedido.e-pronto, .pedido.e-saiu { border-left-color: var(--ok); }
.pedido.e-cancelado { opacity: .55; }
.pedido.chegou { animation: chegou 1.2s ease-out 2; }
@keyframes chegou { 50% { box-shadow: 0 0 0 4px var(--acento); } }
.ped-cab { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.ped-num { font-size: 1.25rem; font-weight: 800; }
.ped-hora { color: var(--suave); font-size: .85rem; text-align: right; }
.espera { font-weight: 700; }
.espera.media { color: var(--alerta); }
.espera.alta { color: var(--perigo); }
.ped-quando { font-size: .92rem; background: var(--fundo); border-radius: 6px; padding: .2rem .5rem; justify-self: start; }
.ped-itens { margin: 0; padding: 0; list-style: none; font-weight: 600; }
.ped-info { font-size: .88rem; color: var(--suave); }
.ped-info a { color: var(--texto); }
.ped-obs { background: rgba(217, 130, 43, .12); border-radius: 6px; padding: .25rem .5rem; font-size: .88rem; }
.ped-total { display: flex; justify-content: space-between; align-items: center; gap: .4rem; flex-wrap: wrap; }
.etiqueta { font-size: .75rem; font-weight: 700; padding: .1rem .45rem; border-radius: 99px; border: 1px solid var(--linha); background: var(--cartao); cursor: pointer; }
.etiqueta.pago { background: var(--ok); color: #fff; border-color: var(--ok); }
.ped-acoes { display: flex; gap: .4rem; flex-wrap: wrap; }
.ped-acoes .btn.primario { flex: 1; }
.vazio { color: var(--suave); font-size: .9rem; text-align: center; padding: 1rem .5rem; border: 1px dashed var(--linha); border-radius: var(--raio); }

/* Entregas */
.grelha { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .8rem; }
.zona-titulo { grid-column: 1 / -1; margin: .5rem 0 0; color: var(--suave); font-size: .9rem; text-transform: uppercase; }

/* Conversas */
.conversas { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; }
.lista-conv { padding: .4rem; max-height: 70vh; overflow-y: auto; }
.conv { display: block; width: 100%; text-align: left; font: inherit; color: inherit; background: none; border: 0; border-radius: 8px; padding: .55rem .6rem; cursor: pointer; }
.conv:hover, .conv.ativa { background: var(--fundo); }
.conv small { display: block; color: var(--suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .bolha { float: right; }
.chat-equipa { display: flex; flex-direction: column; min-height: 60vh; padding: 0; }
.chat-cab { padding: .8rem 1rem; border-bottom: 1px solid var(--linha); font-weight: 600; }
.chat-msgs, .tel-msgs { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .4rem; max-height: 60vh; }
.msg { max-width: 80%; padding: .45rem .7rem; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; font-size: .92rem; }
.msg.entrada { align-self: flex-start; background: var(--fundo); border: 1px solid var(--linha); }
.msg.saida { align-self: flex-end; background: #dcf3d6; color: #12301b; }
.msg small { display: block; opacity: .6; font-size: .72rem; margin-top: 2px; }
.chat-form, .tel-form { display: flex; gap: .4rem; padding: .7rem; border-top: 1px solid var(--linha); }

/* Finanças */
.segmentos { display: inline-flex; border: 1px solid var(--linha); border-radius: 8px; overflow: hidden; }
.segmentos button { font: inherit; border: 0; background: var(--cartao); color: var(--texto); padding: .45rem .75rem; cursor: pointer; }
.segmentos button + button { border-left: 1px solid var(--linha); }
.segmentos button.ativa { background: var(--marca); color: var(--marca-texto); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.kpi { background: var(--cartao); border: 1px solid var(--linha); border-radius: var(--raio); padding: .8rem 1rem; }
.kpi span { color: var(--suave); font-size: .82rem; }
.kpi b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--suave); }
.kpi.lucro b.neg { color: var(--perigo); }
.graf-cab { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .4rem 1rem; margin-bottom: .6rem; }
.graf-cab h3 { margin: 0; }
.grafico { position: relative; }
.grafico svg { display: block; width: 100%; height: 240px; overflow: visible; }
.grafico .eixo { fill: var(--suave); font-size: 11px; font-variant-numeric: tabular-nums; }
.grafico .coluna-hit { fill: transparent; cursor: default; }
.grafico .coluna-hit:hover, .grafico .coluna-hit.ativa { fill: var(--texto); fill-opacity: .05; }
.legenda { display: flex; gap: 1rem; font-size: .85rem; color: var(--suave); }
.legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.dica { position: absolute; pointer-events: none; background: var(--cartao); border: 1px solid var(--linha); border-radius: 10px; padding: .55rem .7rem; font-size: .85rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .12); min-width: 170px; z-index: 5; }
.dica b { display: block; margin-bottom: .25rem; }
.dica div { display: flex; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }
.dica i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.dica .sep { border-top: 1px solid var(--linha); margin-top: .25rem; padding-top: .25rem; font-weight: 700; }
.vazio-graf { color: var(--suave); text-align: center; padding: 3rem 1rem; }
.hbarras { display: grid; gap: .7rem; }
.hbarra-cab { display: flex; justify-content: space-between; gap: .6rem; font-size: .9rem; margin-bottom: .25rem; }
.hbarra-cab span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.hbarra-trilho { height: 10px; border-radius: 5px; background: var(--grelha); overflow: hidden; }
.hbarra-trilho div { height: 100%; border-radius: 5px; }
.duas { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.form-grelha { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.form-grelha .largo, .form-grelha h3 { grid-column: 1 / -1; }
.form-linha { display: flex; gap: .4rem; margin-bottom: .8rem; }
.acoes { display: flex; gap: .5rem; align-items: center; }
.dias { border: 1px solid var(--linha); border-radius: 8px; display: flex; flex-wrap: wrap; gap: .3rem .8rem; }
.dias legend { color: var(--suave); font-size: .85rem; }
.tabela-sc { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--linha); vertical-align: middle; }
th { color: var(--suave); font-weight: 600; font-size: .8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.inativo td { opacity: .5; }
.barra-h { height: 8px; border-radius: 4px; background: var(--despesa); }
.linha-barra { display: grid; grid-template-columns: 1fr auto; gap: .2rem .6rem; margin-bottom: .5rem; font-size: .9rem; }
.linha-barra .barra-h { grid-column: 1 / -1; }
.ligacoes { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }

/* Simulador */
.simulador { display: grid; grid-template-columns: 380px 1fr; gap: 1rem; align-items: start; }
.telemovel { background: #efe7dc; border-radius: 22px; border: 8px solid #1d241f; overflow: hidden; display: flex; flex-direction: column; height: 72vh; min-height: 480px; }
.tel-cab { background: #1f5c44; color: #fff; padding: .7rem 1rem; font-weight: 600; }
.tel-cab small { display: block; font-weight: 400; opacity: .7; }
.tel-msgs { max-height: none; }
.tel-form { background: #f6f2ea; }
.telemovel .msg.entrada { background: #fff; color: #1d241f; border: 0; }
.telemovel .msg.saida { background: #d9fdd3; color: #12301b; }
.telemovel .msg { max-width: 88%; color: #1d241f; }
.telemovel .nota { color: #5f6b63; }
.telemovel .tel-form input { background: #fff; color: #1d241f; }
.sim-ajuda p { color: var(--suave); }
/* No simulador, a mensagem do cliente fica à direita (como no telemóvel do cliente). */
.telemovel .msg.cli { align-self: flex-end; background: #d9fdd3; }
.telemovel .msg.rob { align-self: flex-start; background: #fff; }

.aviso { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--texto); color: var(--fundo); padding: .6rem 1rem; border-radius: 8px; z-index: 50; max-width: calc(100% - 32px); }

@media (max-width: 1100px) { .quadro { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 800px) {
  .duas, .conversas, .simulador { grid-template-columns: minmax(0, 1fr); }
  .quadro { grid-template-columns: minmax(0, 1fr); }
  .form-grelha { grid-template-columns: minmax(0, 1fr); }
  .topo { padding: .5rem 16px; }
  .topo-acoes { margin-left: auto; }
  .abas { order: 3; flex-basis: 100%; }
  .telemovel { height: 70vh; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Cardápio: visíveis (verde) em cima, escondidos (cinzento) no fim */
.tabela-pratos tr.visivel td:first-child { box-shadow: inset 4px 0 0 var(--ok); }
.tabela-pratos tr.inativo td { opacity: 1; color: var(--suave); background: repeating-linear-gradient(135deg, transparent 0 8px, rgba(127, 127, 127, .06) 8px 16px); }
.tabela-pratos tr.inativo td:first-child { box-shadow: inset 4px 0 0 var(--linha); }
.tabela-pratos tr.inativo b { text-decoration: line-through; text-decoration-color: rgba(127, 127, 127, .5); }
.tabela-pratos tr.divisor td { background: none; color: var(--suave); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding-top: 1rem; border-bottom: 1px dashed var(--linha); }
.estado-prato { font: inherit; font-size: .82rem; font-weight: 700; border-radius: 99px; padding: .25rem .7rem; cursor: pointer; border: 1px solid; white-space: nowrap; }
.estado-prato.on { background: rgba(47, 125, 79, .14); color: var(--ok); border-color: rgba(47, 125, 79, .35); }
.estado-prato.off { background: transparent; color: var(--suave); border-color: var(--linha); }
.kpi.lucro { border-color: var(--ok); }
.kpi.lucro b { color: var(--ok); }
.previa-wa { background: #efe7dc; border-radius: 12px; padding: .8rem; margin: .6rem 0; }
.msg-previa { background: #d9fdd3; color: #12301b; border-radius: 10px; padding: .55rem .75rem; white-space: pre-wrap; max-width: 90%; font-size: .92rem; }
.previa-wa .nota { color: #5f6b63; display: block; margin-top: .3rem; }
.btn.gravando { background: var(--perigo); border-color: var(--perigo); color: #fff; animation: pulsar 1s ease-in-out infinite; }
@keyframes pulsar { 50% { opacity: .6; } }

/* ---------- Telemóvel: barra de navegação em baixo ---------- */
.nav-baixo, .folha-mais, .fundo-mais { display: none; }
@media (max-width: 800px) {
  .abas { display: none !important; }
  main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .aviso { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .nav-baixo {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--cartao); border-top: 1px solid var(--linha); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .08);
  }
  .nav-baixo button, .folha-mais button {
    font: inherit; font-size: .72rem; color: var(--suave); background: none; border: 0; border-radius: 10px;
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; min-height: 54px; position: relative; cursor: pointer;
  }
  .nav-baixo .ico, .folha-mais .ico { font-size: 1.35rem; line-height: 1; }
  .nav-baixo button.ativa { color: var(--texto); font-weight: 700; background: var(--fundo); }
  .nav-baixo .bolha { position: absolute; top: 2px; right: 18%; margin: 0; }
  .fundo-mais[hidden], .folha-mais[hidden] { display: none !important; }
  .fundo-mais { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 28; }
  .folha-mais {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; position: fixed; left: 8px; right: 8px; z-index: 29;
    bottom: calc(76px + env(safe-area-inset-bottom)); background: var(--cartao); border: 1px solid var(--linha);
    border-radius: 16px; padding: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  }
  .folha-mais button { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: .95rem; color: var(--texto); padding: 14px 12px; background: var(--fundo); }
  .folha-mais button.ativa { outline: 2px solid var(--acento); }
  .topo { gap: .4rem; }
  .topo .btn.pequeno { padding: .35rem .55rem; font-size: .8rem; }
}

/* ---------- Sem deslize lateral ---------- */
.abas { flex-wrap: wrap; overflow: visible; }
.telemovel .tel-form .btn:not(.primario) { background: #fff; color: #1d241f; border-color: #d8d2c4; }
html, body { overflow-x: hidden; }
@media (max-width: 800px) {
  /* Tabelas viram cartões, com o nome de cada campo à vista */
  .tabela-cartoes thead { display: none; }
  .tabela-cartoes, .tabela-cartoes tbody { display: block; }
  .tabela-cartoes tr { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .9rem; padding: .75rem .5rem; border-bottom: 1px solid var(--linha); }
  .tabela-cartoes td { border: 0; padding: 0; text-align: left; }
  .tabela-cartoes td[data-l]::before { content: attr(data-l) ': '; color: var(--suave); font-size: .82rem; font-weight: 400; }
  .tabela-pratos td:first-child { flex-basis: 100%; padding-left: .6rem; }
  .tabela-pratos td:last-child { margin-left: auto; }
  .tabela-pratos tr.divisor td { flex-basis: 100%; }
  .tabela-clientes td:nth-child(2) { flex-basis: calc(100% - 40px); }
  .tabela-clientes td:last-child { flex-basis: 100%; }
  .barra { gap: .5rem; }
  .barra input[type="date"] { flex: 1; min-width: 0; }
  .segmentos { display: grid; grid-template-columns: repeat(2, 1fr); width: 100%; }
  .segmentos button + button { border-left: 0; }
  .segmentos button:nth-child(even) { border-left: 1px solid var(--linha); }
  .segmentos button:nth-child(n+3) { border-top: 1px solid var(--linha); }
  label.inline { flex: 1; }
  label.inline input { width: 100%; }
}
