/* Superfícies em cinzento aço (bancada inox), letra do sistema, cor do cliente só nas ações
   principais e na seleção. A identidade está nas etiquetas de validade (.etiqueta). */
:root {
  color-scheme: light dark;
  --cor: #7a2e2e;                       /* cor do cliente (config.js) */
  --cor-texto: var(--cor);              /* cor do cliente usada como texto/ligação */
  --fundo: #f1f2f4;
  --superficie: #ffffff;
  --superficie-2: #f7f8f9;
  --texto: #1d1f23;                     /* 16,0:1 sobre branco */
  --texto-2: #565c66;                   /* 6,6:1 sobre branco */
  --linha: #dfe2e6;
  --ok: #1d7038;      --ok-f: #e3f2e7;  /* 6,1:1 sobre o fundo */
  --aviso: #8d5300;   --aviso-f: #fdf0d9; /* 5,5:1 */
  --perigo: #b0251c;  --perigo-f: #fde4e1; /* 5,6:1 */
  --neutro-f: #eceef1;
  --raio: 12px;
  --toque: 36px;
  --sombra: 0 1px 2px rgba(20, 24, 30, .06), 0 2px 8px rgba(20, 24, 30, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --cor-texto: color-mix(in srgb, var(--cor) 40%, #fff);
    --fundo: #111214;
    --superficie: #1c1d20;
    --superficie-2: #232428;
    --texto: #eceef0;                   /* 14,9:1 sobre #1c1d20 */
    --texto-2: #a3a8b1;                 /* 7,2:1 */
    --linha: #33353a;
    --ok: #6fd28f;      --ok-f: #183522;
    --aviso: #f2b552;   --aviso-f: #3a2a10;
    --perigo: #ff8f85;  --perigo-f: #401b18;
    --neutro-f: #2a2c30;
    --sombra: none;
  }
}
@media (pointer: coarse) { :root { --toque: 44px; } }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo); color: var(--texto);
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 .25rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; font-weight: 650; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
a { color: var(--cor-texto); }
.sub { color: var(--texto-2); margin: 0 0 1.25rem; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--cor) 55%, #4d90fe); outline-offset: 2px; border-radius: 6px; }

/* ===== Estrutura: barra lateral em ecrã largo, separadores em baixo no telemóvel ===== */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.lateral {
  background: var(--superficie-2); border-right: 1px solid var(--linha);
  padding: 1.25rem .75rem; position: sticky; top: 0; height: 100vh;
}
.marca { padding: 0 .75rem 1.25rem; }
.marca strong { display: block; font-size: 1rem; }
.marca small { color: var(--texto-2); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: var(--texto); text-decoration: none; padding: 0 .75rem; min-height: 40px; border-radius: 8px;
  display: flex; gap: .65rem; align-items: center; position: relative;
}
.nav a svg { width: 20px; height: 20px; flex: none; color: var(--texto-2); }
.nav a:hover { background: var(--neutro-f); }
.nav a.ativo { background: color-mix(in srgb, var(--cor) 12%, transparent); color: var(--cor-texto); font-weight: 600; }
.nav a.ativo svg { color: var(--cor-texto); }
.badge {
  margin-left: auto; background: var(--perigo); color: #fff; border-radius: 99px;
  font-size: .75rem; font-weight: 700; min-width: 1.3rem; height: 1.3rem; padding: 0 .35rem;
  display: inline-grid; place-items: center;
}
.badge[hidden] { display: none; }
@media (prefers-color-scheme: dark) { .badge { color: #2a0d0a; } }
.conteudo { padding: 2rem 2.25rem 4rem; max-width: 1120px; width: 100%; }

@media (max-width: 760px) {
  body { font-size: 17px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .lateral {
    position: fixed; inset: auto 0 0 0; height: auto; z-index: 10; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--linha);
    background: color-mix(in srgb, var(--superficie) 86%, transparent);
    -webkit-backdrop-filter: saturate(1.8) blur(18px); backdrop-filter: saturate(1.8) blur(18px);
  }
  .marca { display: none; }
  .nav { flex-direction: row; justify-content: space-around; }
  .nav a { flex: 1; flex-direction: column; gap: 2px; padding: 6px 2px; min-height: 52px; justify-content: center; font-size: .7rem; background: none !important; }
  .nav a svg { width: 24px; height: 24px; }
  .nav a .badge { position: absolute; top: 3px; left: calc(50% + 6px); margin: 0; }
  .conteudo { padding: 1.25rem 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.85rem; }
}
@media (prefers-reduced-transparency: reduce) { .lateral { background: var(--superficie); backdrop-filter: none; } }

/* ===== Controlos ===== */
.barra { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.barra .esp { flex: 1; }
.btn {
  font: inherit; font-size: .95rem; border: 1px solid var(--linha); background: var(--superficie); color: var(--texto);
  padding: 0 1rem; min-height: var(--toque); border-radius: 10px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.btn:hover { background: var(--superficie-2); }
.btn.primario { background: var(--cor); border-color: var(--cor); color: #fff; font-weight: 600; }
.btn.primario:hover { filter: brightness(1.12); }
.btn.perigo { color: var(--perigo); }
.btn.peq { font-size: .875rem; padding: 0 .75rem; min-height: max(32px, calc(var(--toque) - 4px)); }
.btn.ligacao { border-color: transparent; background: none; color: var(--cor-texto); padding: 0 .5rem; }
.btn-x {
  border: 0; background: none; cursor: pointer; color: var(--texto-2); border-radius: 8px;
  min-width: var(--toque); min-height: var(--toque); display: inline-grid; place-items: center; font-size: 1.3rem;
}
.btn-x:hover { background: var(--neutro-f); color: var(--perigo); }
input, select, textarea {
  font: inherit; color: inherit; background: var(--superficie); border: 1px solid var(--linha);
  border-radius: 10px; padding: .55rem .7rem; width: 100%; min-height: var(--toque);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--cor-texto); outline-offset: -1px; }
.pesquisa { max-width: 300px; flex: 1 1 200px; }
@media (max-width: 760px) {
  .pesquisa { max-width: none; flex-basis: 100%; }
  .barra .esp { display: none; }
  .barra > .btn { flex: 1 1 auto; }
}

.segmentos { display: inline-flex; background: var(--neutro-f); border-radius: 10px; padding: 3px; margin-bottom: 1rem; }
.segmentos a { text-decoration: none; color: var(--texto); padding: .35rem 1rem; border-radius: 8px; font-size: .92rem; min-height: 32px; display: grid; place-items: center; }
.segmentos a.ativo { background: var(--superficie); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.filtros { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 1rem; padding: 0 16px; scrollbar-width: none; }
.filtros button {
  font: inherit; font-size: .9rem; border: 1px solid var(--linha); background: var(--superficie); color: var(--texto);
  min-height: max(32px, calc(var(--toque) - 8px)); padding: 0 .85rem; border-radius: 99px; cursor: pointer; white-space: nowrap;
}
.filtros button.ativo { background: var(--texto); color: var(--superficie); border-color: var(--texto); }
.filtros small { opacity: .65; margin-left: .2rem; }

/* ===== Blocos ===== */
.bloco { background: var(--superficie); border: 1px solid var(--linha); border-radius: var(--raio); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; box-shadow: var(--sombra); }
.vazio { color: var(--texto-2); padding: 1.75rem 1rem; text-align: center; }
.nota { background: var(--neutro-f); border-radius: 10px; padding: .75rem .9rem; color: var(--texto-2); font-size: .92rem; margin: 0 0 1rem; }
.faixa { border-radius: 10px; padding: .7rem .9rem; margin-bottom: 1rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; background: var(--aviso-f); color: var(--aviso); }
.faixa .btn { color: var(--texto); }

.resumo { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.5rem; }
.resumo a { background: var(--superficie); border: 1px solid var(--linha); border-radius: var(--raio); padding: .8rem 1rem; text-decoration: none; color: var(--texto); box-shadow: var(--sombra); }
.resumo b { display: block; font-size: 1.5rem; }
.resumo span { color: var(--texto-2); font-size: .9rem; }

/* ===== Etiqueta de validade (elemento de assinatura) =====
   Lembra as etiquetas de rotação da cozinha: faixa de cor + data grande + estado escrito. */
.etiqueta {
  display: inline-grid; grid-template-columns: 6px auto; min-width: 116px; border-radius: 6px; overflow: hidden;
  background: var(--superficie); border: 1px solid var(--linha); font-variant-numeric: tabular-nums; vertical-align: top;
}
.etiqueta::before { content: ""; background: var(--estado, var(--texto-2)); }
.etiqueta > span { padding: .3rem .6rem .35rem; display: flex; flex-direction: column; line-height: 1.15; }
.etiqueta small { font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--estado, var(--texto-2)); }
.etiqueta b { font-size: 1.05rem; }
.etiqueta i { font-style: normal; font-size: .8rem; color: var(--texto-2); }
.etiqueta.ok { --estado: var(--ok); }
.etiqueta.aviso { --estado: var(--aviso); }
.etiqueta.perigo { --estado: var(--perigo); background: var(--perigo-f); }
.etiqueta.semdata { --estado: var(--texto-2); border-style: dashed; }

/* ===== Listas / tabelas ===== */
.tabela-wrap { background: var(--superficie); border: 1px solid var(--linha); border-radius: var(--raio); box-shadow: var(--sombra); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .65rem .85rem; border-bottom: 1px solid var(--linha); vertical-align: middle; }
th { font-size: .78rem; font-weight: 600; color: var(--texto-2); background: var(--superficie-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--superficie-2); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.acoes { white-space: nowrap; text-align: right; }
.tit { font-weight: 600; }
.mini { color: var(--texto-2); font-size: .85rem; }
a.tit { text-decoration: none; color: var(--texto); }
a.tit:hover { color: var(--cor-texto); text-decoration: underline; }

@media (max-width: 760px) {
  .tabela-wrap thead { display: none; }
  .tabela-wrap table, .tabela-wrap tbody, .tabela-wrap tr, .tabela-wrap td { display: block; width: 100%; }
  .tabela-wrap tr { padding: .75rem 1rem; border-bottom: 1px solid var(--linha); position: relative; }
  .tabela-wrap tr:last-child { border-bottom: 0; }
  .tabela-wrap td { border: 0; padding: .1rem 0; text-align: left; }
  .tabela-wrap td.num { text-align: left; }
  .tabela-wrap td[data-l]:not(:empty)::before { content: attr(data-l) ": "; color: var(--texto-2); font-size: .85rem; }
  .tabela-wrap td:first-child { padding-right: 3rem; font-size: 1.05rem; }
  .tabela-wrap td.acoes { text-align: left; padding-top: .5rem; }
  .tabela-wrap td.acoes .btn-x { position: absolute; top: .4rem; right: .4rem; }
  .tabela-wrap td.etq { padding: .35rem 0; }
}

.chip { display: inline-block; font-size: .78rem; padding: .1rem .5rem; border-radius: 99px; background: var(--neutro-f); color: var(--texto); margin: 1px 2px 1px 0; white-space: nowrap; text-decoration: none; }
.chip.aviso, .chip.alerg { background: var(--aviso-f); color: var(--aviso); }
.chip.perigo { background: var(--perigo-f); color: var(--perigo); }
.chip.ok { background: var(--ok-f); color: var(--ok); }

/* ===== Ficha técnica ===== */
.ficha-cab { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; margin-bottom: .75rem; }
.voltar { display: inline-flex; align-items: center; min-height: var(--toque); text-decoration: none; font-weight: 500; }
.metricas { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; margin-bottom: 1.25rem; }
.metrica { background: var(--superficie); border: 1px solid var(--linha); border-radius: 10px; padding: .6rem .85rem; }
.metrica .t { font-size: .8rem; color: var(--texto-2); }
.metrica .v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.alerg-tabela { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px; }
.alerg-tabela div { padding: .4rem .65rem; border-radius: 8px; background: var(--neutro-f); color: var(--texto-2); font-size: .92rem; }
.alerg-tabela div.sim { background: var(--aviso-f); color: var(--aviso); font-weight: 700; }
.texto-livre { white-space: pre-wrap; margin: 0; }

/* ===== Folha (modal): cartão centrado em ecrã largo, folha a subir no telemóvel ===== */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; }
.modal[hidden] { display: none; }
.modal-fundo { position: absolute; inset: 0; background: rgba(10, 12, 16, .45); }
.modal-caixa { position: relative; background: var(--superficie); border-radius: 14px; width: min(580px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; box-shadow: 0 12px 48px rgba(0,0,0,.28); }
.modal-caixa.largo { width: min(860px, 100%); }
.modal-caixa header { padding: .75rem 1.25rem; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .5rem; border-bottom: 1px solid var(--linha); }
.modal-caixa header h2 { margin: 0; font-size: 1.05rem; text-align: center; }
.modal-caixa header .esq { justify-self: start; }
.modal-caixa header .dir { justify-self: end; }
.modal-corpo { padding: 1rem 1.25rem 1.5rem; overflow-y: auto; }
.grelha { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.campo { display: flex; flex-direction: column; gap: .3rem; }
.campo > span { font-size: .85rem; font-weight: 600; color: var(--texto-2); }
.campo.largo { grid-column: 1 / -1; }
.campo-chk { flex-direction: row; align-items: center; gap: .6rem; min-height: var(--toque); }
.campo-chk input { width: 22px; height: 22px; min-height: 0; accent-color: var(--cor); }
.alerg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0 .75rem; }
.chk { display: flex; gap: .5rem; align-items: center; min-height: var(--toque); font-size: .95rem; }
.chk input { width: 20px; height: 20px; min-height: 0; accent-color: var(--cor); flex: none; }
.ing-lista { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .5rem; }
.ing-linha { display: grid; grid-template-columns: 1fr 92px 78px var(--toque); gap: .4rem; align-items: center; }
@media (max-width: 760px) {
  .modal { padding: 0; place-items: end stretch; }
  .modal-caixa, .modal-caixa.largo { width: 100%; max-height: calc(100vh - 12px); border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .modal-caixa::before { content: ""; width: 36px; height: 5px; border-radius: 3px; background: var(--linha); position: absolute; top: 6px; left: 50%; transform: translateX(-50%); }
  .modal-caixa header { padding: 1rem 8px .6rem; }
  .grelha { grid-template-columns: 1fr; }
  .ing-linha { grid-template-columns: 1fr 1fr var(--toque); padding-bottom: .5rem; border-bottom: 1px solid var(--linha); }
  .ing-linha select[name=ing_ref] { grid-column: 1 / -1; }
}

.toast {
  position: fixed; bottom: 24px; left: 16px; right: 16px; margin: 0 auto; width: fit-content; max-width: 560px; z-index: 30;
  background: var(--texto); color: var(--superficie); padding: .4rem .5rem .4rem 1.1rem; border-radius: 14px; min-height: 48px;
  display: flex; align-items: center; gap: .5rem; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast[hidden] { display: none; }
.toast:not(:has(button)) { padding-right: 1.1rem; }
.toast button { font: inherit; font-weight: 700; border: 0; background: none; color: inherit; text-decoration: underline; cursor: pointer; min-height: var(--toque); padding: 0 .6rem; }
@media (max-width: 760px) { .toast { bottom: calc(80px + env(safe-area-inset-bottom)); } }

/* ===== Impressão (pasta para a ASAE): sempre claro ===== */
@media print {
  :root { --fundo: #fff; --superficie: #fff; --superficie-2: #fff; --texto: #000; --texto-2: #444; --linha: #ccc; }
  body { font-size: 12px; background: #fff; }
  .app { display: block; }
  .lateral, .barra, .acoes, .btn, .nao-imprimir { display: none !important; }
  .conteudo { padding: 0; max-width: none; }
  .bloco, .tabela-wrap, .metrica { box-shadow: none; break-inside: avoid; }
}
