/* Identidade derivada do app de velas (tokens de cor, navegação lateral, cards, avisos amarelos,
   erro/sucesso), adaptada a tons de massa e casca de pão. Tema claro/escuro por tokens. */
:root {
  --fundo: #FFFCF8;
  --fundo-2: #F4ECE2;
  --superficie: #FFFFFF;
  --texto: #1F1A16;
  --texto-2: #594E44;
  --acento: #8A3F0F;
  --acento-suave: #F6E3D3;
  --sobre-acento: #FFFFFF;
  --navegacao: #F6EEE4;
  --borda: #CDBFB1;
  --borda-forte: #8C7F73;
  --erro: #A4000F;
  --sucesso: #0F5F2E;
  --aviso-fundo: #FFF4CE;
  --aviso-texto: #5C3B00;
  --sombra: 0 1px 2px rgba(60, 35, 15, .08), 0 4px 14px rgba(60, 35, 15, .06);
  --raio: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) {
    --fundo: #15110E; --fundo-2: #1F1915; --superficie: #241D18; --texto: #F3ECE4; --texto-2: #C4B6A8;
    --acento: #E59A5B; --acento-suave: #3A2718; --sobre-acento: #1B120B; --navegacao: #1C1713;
    --borda: #43382F; --borda-forte: #7A6C60; --erro: #FF8A8A; --sucesso: #7FD49A;
    --aviso-fundo: #3A2E10; --aviso-texto: #F5D88A; --sombra: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-tema="escuro"] {
  --fundo: #15110E; --fundo-2: #1F1915; --superficie: #241D18; --texto: #F3ECE4; --texto-2: #C4B6A8;
  --acento: #E59A5B; --acento-suave: #3A2718; --sobre-acento: #1B120B; --navegacao: #1C1713;
  --borda: #43382F; --borda-forte: #7A6C60; --erro: #FF8A8A; --sucesso: #7FD49A;
  --aviso-fundo: #3A2E10; --aviso-texto: #F5D88A; --sombra: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fundo); color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--acento); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.oculto { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Estrutura ---------- */
.topo {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .5rem;
  padding: .55rem 1rem; padding-top: max(.55rem, env(safe-area-inset-top));
  background: var(--fundo); border-bottom: 1px solid var(--borda);
}
.marca { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--texto); text-decoration: none; margin-right: auto; }
.marca img { width: 30px; height: 30px; border-radius: 8px; }
.status-sync { font-size: .78rem; color: var(--texto-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; background: none; border: 0; font: inherit; font-size: .78rem; cursor: pointer; padding: .3rem .2rem; }
body { overflow-x: hidden; }
.btn-icone {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--texto); cursor: pointer; font-size: 1.15rem;
}
.btn-icone:hover { background: var(--fundo-2); }
.layout { display: flex; min-height: calc(100vh - 57px); }
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--navegacao); border-top: 1px solid var(--borda);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--texto-2); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.nav a .ico { font-size: 1.25rem; line-height: 1; }
.nav a[aria-current="page"] { color: var(--acento); }
.nav a[aria-current="page"] .ico { background: var(--acento-suave); border-radius: 999px; padding: 2px 14px; }
main { flex: 1; min-width: 0; padding: 1rem 1rem calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; width: 100%; }
@media (min-width: 900px) {
  .nav {
    position: sticky; top: 57px; height: calc(100vh - 57px); width: 210px; grid-template-columns: none;
    grid-auto-rows: 52px; align-content: start; padding: .75rem .5rem; border-top: 0; border-right: 1px solid var(--borda);
  }
  .nav a { flex-direction: row; justify-content: flex-start; gap: .7rem; padding: 0 .8rem; font-size: .95rem; border-radius: 10px; }
  .nav a[aria-current="page"] { background: var(--acento-suave); }
  .nav a[aria-current="page"] .ico { background: none; padding: 0; }
  main { padding: 1.5rem 2rem 2rem; }
}

/* ---------- Componentes ---------- */
.cabecalho { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.cabecalho h1 { margin: 0 auto 0 0; }
.card { background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); padding: 1rem; box-shadow: var(--sombra); }
.card + .card, .secao + .secao { margin-top: 1rem; }
.grade { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.grade-2 { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.numeros { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.numero { background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); padding: .8rem 1rem; }
.numero b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.numero span { color: var(--texto-2); font-size: .85rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .5rem 1rem;
  border-radius: 10px; border: 1px solid var(--borda-forte); background: var(--superficie); color: var(--texto);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--fundo-2); }
.btn.primario { background: var(--acento); border-color: var(--acento); color: var(--sobre-acento); }
.btn.primario:hover { filter: brightness(1.08); }
.btn.perigo { color: var(--erro); border-color: var(--erro); }
.btn.pequeno { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.acoes { display: flex; flex-wrap: wrap; gap: .5rem; }
:focus-visible { outline: 3px solid var(--acento); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.campo { margin-bottom: .8rem; }
.campo small { display: block; color: var(--texto-2); font-weight: 400; margin-top: .2rem; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: .5rem .7rem; border: 1px solid var(--borda-forte); border-radius: 10px;
  background: var(--superficie); color: var(--texto); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--acento); }
.check { display: flex; align-items: center; gap: .6rem; font-weight: 500; }
.busca { position: relative; }
.busca input { padding-left: 2.3rem; }
.busca::before { content: "⌕"; position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--texto-2); font-size: 1.2rem; }

.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: none; }
.chip {
  flex: none; padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--borda); background: var(--superficie);
  color: var(--texto); font: inherit; font-size: .88rem; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.chip[aria-pressed="true"] { background: var(--acento); border-color: var(--acento); color: var(--sobre-acento); }

.aviso { background: var(--aviso-fundo); color: var(--aviso-texto); border-radius: 10px; padding: .6rem .8rem; font-size: .92rem; }
.aviso + .aviso { margin-top: .5rem; }
.erro-txt { color: var(--erro); }
.ok-txt { color: var(--sucesso); }
.pendente { display: inline-block; font-size: .75rem; font-weight: 700; color: var(--aviso-texto); background: var(--aviso-fundo); border-radius: 6px; padding: 0 .4rem; }
.muted { color: var(--texto-2); }
.vazio { text-align: center; color: var(--texto-2); padding: 2rem 1rem; }

/* Cartão de receita */
.receita-card { display: flex; flex-direction: column; overflow: hidden; padding: 0; text-decoration: none; color: inherit; }
.receita-card .foto { aspect-ratio: 16 / 10; background: var(--fundo-2) center/cover no-repeat; display: grid; place-items: center; font-size: 2.4rem; }
.receita-card .corpo { padding: .7rem .9rem .9rem; }
.receita-card h3 { margin: 0 0 .2rem; }
.linha-meta { display: flex; flex-wrap: wrap; gap: .3rem .8rem; font-size: .85rem; color: var(--texto-2); }
.fav { color: #D9822B; }

/* Tabelas (viram listas no celular) */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--borda); vertical-align: top; }
th { font-size: .8rem; color: var(--texto-2); font-weight: 700; }
td.num, th.num { text-align: right; white-space: nowrap; }
tfoot td { font-weight: 700; border-bottom: 0; }
.lista { list-style: none; margin: 0; padding: 0; }
.lista > li { display: flex; align-items: center; gap: .6rem; padding: .65rem 0; border-bottom: 1px solid var(--borda); }
.lista > li:last-child { border-bottom: 0; }
.lista.simples > li { display: block; }
.lista .principal { flex: 1; min-width: 0; }
.lista .principal b { display: block; overflow-wrap: anywhere; }

/* Editor de receita */
.item-ing { display: grid; grid-template-columns: 1fr 90px 130px auto; gap: .4rem; align-items: start; padding: .5rem 0; border-bottom: 1px dashed var(--borda); }
.item-ing .controles { display: flex; gap: .15rem; }
.etapa { display: grid; grid-template-columns: 28px 1fr auto; gap: .4rem; align-items: start; padding: .4rem 0; }
.etapa .n { font-weight: 700; color: var(--acento); padding-top: .6rem; text-align: center; }
@media (max-width: 560px) {
  .item-ing { grid-template-columns: 1fr 1fr; }
  .item-ing .nome-ing { grid-column: 1 / -1; }
  .item-ing .controles { grid-column: 1 / -1; justify-content: flex-end; }
}
.foto-previa { width: 100%; max-width: 360px; aspect-ratio: 4/3; object-fit: cover; border-radius: 12px; border: 1px solid var(--borda); display: block; }

/* Modo de preparo */
.preparo .item { display: flex; gap: .8rem; align-items: center; padding: .8rem .2rem; border-bottom: 1px solid var(--borda); cursor: pointer; }
.preparo .item input { width: 28px; height: 28px; flex: none; }
.preparo .qtd { font-size: 1.25rem; font-weight: 800; min-width: 5.5rem; font-variant-numeric: tabular-nums; }
.preparo .item.feito { opacity: .5; }
.preparo .item.feito .texto { text-decoration: line-through; }
.preparo .etapa-txt { font-size: 1.08rem; }
.progresso { height: 8px; background: var(--fundo-2); border-radius: 99px; overflow: hidden; }
.progresso > div { height: 100%; background: var(--acento); transition: width .2s; }
.capa { width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--raio); }

/* Diálogo e aviso flutuante */
dialog { border: 1px solid var(--borda); border-radius: var(--raio); background: var(--superficie); color: var(--texto); padding: 1.2rem; max-width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20, 12, 5, .45); }
dialog img.ampliada { max-width: 100%; max-height: 80vh; display: block; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: var(--texto); color: var(--fundo); padding: .6rem 1rem; border-radius: 10px; box-shadow: var(--sombra); max-width: calc(100vw - 32px);
}
@media (min-width: 900px) { .toast { bottom: 24px; } }

@media print {
  .topo, .nav, .acoes, .nao-imprimir, .toast { display: none !important; }
  main { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; color: #000; }
}
