:root {
  --bg: #fbf8f4;
  --surface: #ffffff;
  --text: #2b2420;
  --muted: #6f655d;
  --line: #e6ddd3;
  --accent: #9a3412;
  --accent-soft: #fdeee4;
  --ok-bg: #e9f6ec;
  --ok: #1f6b33;
  --err-bg: #fdecec;
  --err: #a32020;
  --warn-bg: #fff6dc;
  --warn: #7a5a00;
  --on-accent: #fff;  /* texto sobre --accent */
  --on-err: #fff;     /* texto sobre --err (botões de eliminar) */
  --radius: 8px;
  color-scheme: light;
}

/* Esquemas de cores (atributo data-theme no <html>, escolhido pelo utilizador).
   Sem atributo, o esquema original segue o modo claro/escuro do sistema. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1d1916;
    --surface: #26211d;
    --text: #efe8e1;
    --muted: #b0a59b;
    --line: #3d3530;
    --accent: #f0915e;
    --accent-soft: #3a2a20;
    --ok-bg: #1d3323;
    --ok: #9fdcae;
    --err-bg: #3e1f1f;
    --err: #ffb0b0;
    --warn-bg: #3a3218;
    --warn: #f1d98a;
    color-scheme: dark;
  }
}

/* Escuro: as cores escuras do original, independentemente do sistema */
:root[data-theme="escuro"] {
  --bg: #1d1916;
  --surface: #26211d;
  --text: #efe8e1;
  --muted: #b0a59b;
  --line: #3d3530;
  --accent: #f0915e;
  --accent-soft: #3a2a20;
  --ok-bg: #1d3323;
  --ok: #9fdcae;
  --err-bg: #3e1f1f;
  --err: #ffb0b0;
  --warn-bg: #3a3218;
  --warn: #f1d98a;
  --on-accent: #1d1916;
  --on-err: #1d1916;
  color-scheme: dark;
}

:root[data-theme="azul-claro"] {
  --bg: #f2f6fb;
  --surface: #ffffff;
  --text: #1c2733;
  --muted: #5a6b7d;
  --line: #d5e0ec;
  --accent: #1d5fa8;
  --accent-soft: #e2edfa;
  --ok-bg: #e7f5ee;
  --ok: #1a6640;
  --err-bg: #fbeaea;
  --err: #a32020;
  --warn-bg: #fdf5dc;
  --warn: #6f5300;
  --on-accent: #fff;
  --on-err: #fff;
  color-scheme: light;
}

:root[data-theme="azul-escuro"] {
  --bg: #0e1724;
  --surface: #162233;
  --text: #e2eaf4;
  --muted: #9aaec4;
  --line: #29394e;
  --accent: #6cb0f5;
  --accent-soft: #1b3150;
  --ok-bg: #173327;
  --ok: #94dcb4;
  --err-bg: #3c1f26;
  --err: #ffaeb8;
  --warn-bg: #352f18;
  --warn: #f0d78a;
  --on-accent: #0b1522;
  --on-err: #0b1522;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.7rem; margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }
code { font-size: .9em; }

/* barra superior */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem;
  padding: .6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--accent); }
.modules { display: flex; gap: .25rem; }
.modules a { padding: .35rem .65rem; border-radius: var(--radius); text-decoration: none; color: var(--text); }
.modules a.active, .modules a:hover { background: var(--accent-soft); color: var(--accent); }
.search { display: flex; flex: 1 1 260px; gap: .4rem; max-width: 520px; margin-left: auto; }
.search input { flex: 1; min-width: 0; }
.account { display: flex; align-items: center; gap: .75rem; font-size: .95rem; }
.theme-form { display: flex; align-items: center; gap: .3rem; }
.theme-form select { padding: .3rem .45rem; font-size: .88rem; }
.theme-form button { padding: .25rem .6rem; font-size: .85rem; }
.theme-form [hidden] { display: none; }
.who small { color: var(--muted); }

/* estrutura: conteúdo à esquerda, lista de receitas à direita */
.wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1.5rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem;
}
.wrap.single { grid-template-columns: minmax(0, 1fr); max-width: 900px; }
main { min-width: 0; }
.sidebar {
  position: sticky; top: 4.5rem;
  align-self: start;
  max-height: calc(100vh - 6rem);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.sidebar h2 { margin: 0; font-size: 1rem; }
.sidebar h2 small { color: var(--muted); font-weight: 400; }
#filtro { margin: .6rem 0; width: 100%; }
#lista { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#lista a { display: block; padding: .22rem .45rem; border-radius: 5px; text-decoration: none; color: var(--text); font-size: .94rem; }
#lista a:hover { background: var(--accent-soft); }
#lista a.current { background: var(--accent); color: var(--on-accent); }
footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem; }

@media (max-width: 860px) {
  .wrap { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; max-height: 22rem; }
  .search { margin-left: 0; max-width: none; }
}

/* formulários */
input[type=text], input[type=search], input[type=password], input[type=file], select, textarea {
  font: inherit; color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .45rem .6rem;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; margin: .8rem 0; font-weight: 600; }
label > input[type=text], label > input[type=password], label > select, label > textarea, label > input[type=file] {
  display: block; width: 100%; margin-top: .3rem; font-weight: 400;
}
label.check, label.radio { font-weight: 400; display: flex; gap: .5rem; align-items: baseline; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 1rem 0; padding: .4rem 1rem 1rem; }
legend { font-weight: 600; padding: 0 .3rem; }
.hint { color: var(--muted); font-size: .9rem; font-weight: 400; }

button, .button {
  display: inline-block;
  font: inherit; font-weight: 600;
  background: var(--accent); color: var(--on-accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: .45rem .95rem;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .button:hover { filter: brightness(1.08); }
.button.small { padding: .2rem .6rem; font-size: .88rem; }
.button.secondary { background: transparent; color: var(--accent); }
.button.disabled { opacity: .5; cursor: not-allowed; }
button.danger { background: var(--err); border-color: var(--err); color: var(--on-err); }
button.link {
  background: none; border: 0; padding: 0; color: var(--accent);
  font-weight: 400; text-decoration: underline; cursor: pointer;
}
.danger-text { color: var(--err) !important; }
form.inline { display: inline; }
.actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-top: 1rem; }

.box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}
.box h2 { margin-top: 0; }
.narrow { max-width: 520px; }
.danger-zone { border-color: var(--err); }

.flash { padding: .7rem 1rem; border-radius: var(--radius); margin: 0 0 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

.lead { color: var(--muted); font-size: 1.05rem; }
.empty { color: var(--muted); font-style: italic; }
.meta { color: var(--muted); font-size: .88rem; margin: .1rem 0 .4rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.nowrap { white-space: nowrap; }

/* início e pesquisa */
.cards { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.cards li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; }
.cards a { font-weight: 600; text-decoration: none; display: block; }
.cards .meta { display: block; }
.results { list-style: none; padding: 0; }
.results li { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.results a { font-weight: 600; font-size: 1.05rem; }
.snippet { color: var(--muted); margin: .25rem 0 0; font-size: .92rem; }

/* receita */
.recipe-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: .75rem; }
.recipe-head .actions { margin: 0; }
.recipe section { margin-top: 1.25rem; }
.origin .pre { color: var(--muted); }
.ingredients ul { padding-left: 1.3rem; }
.ingredients li { margin: .15rem 0; }
.ingredients li.group { list-style: none; margin-left: -1.3rem; margin-top: .6rem; font-weight: 600; }
.instructions .pre { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; }
.gallery figure { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem; }
.gallery img { display: block; width: 100%; height: 200px; object-fit: cover; object-position: top; border-radius: 5px; }
/* tipo e palavras-chave */
.field-row { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 0 1rem; }
@media (max-width: 640px) { .field-row { grid-template-columns: 1fr; } }
.field-row .hint { display: block; margin-top: .25rem; }
.recipe-title { min-width: 0; flex: 1 1 auto; }
.recipe-title h1 { margin-bottom: .35rem; }
.taxonomy { display: grid; grid-template-columns: auto 1fr; gap: .3rem .6rem; align-items: center; margin: 0 0 .3rem; font-size: .9rem; }
.taxonomy dt { color: var(--muted); font-weight: 600; }
.taxonomy dd { margin: 0; display: flex; flex-wrap: wrap; gap: .3rem; }
.taxonomy .none { color: var(--muted); font-style: italic; }
.type-badge { display: inline-block; padding: .1rem .6rem; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: .85rem; font-weight: 600; }
.tag { display: inline-block; padding: .08rem .55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--line); font-size: .85rem; text-decoration: none; }
.tag::before { content: "#"; opacity: .55; margin-right: .1rem; }
a.tag:hover { border-color: var(--accent); }
.tag.big { font-size: 1.2rem; vertical-align: middle; }
.sidebar .filters { display: flex; flex-direction: column; gap: .4rem; margin: .6rem 0; }
.sidebar .filters #filtro { margin: 0; }
#filtro-tipo { width: 100%; }
#filtro-tipo.active { border-color: var(--accent); background: var(--accent-soft); }
#filtro-vazio { font-size: .9rem; margin: .2rem 0 .4rem; }
table.types td { vertical-align: middle; }
form.rename { display: flex; gap: .6rem; align-items: center; }
form.rename input { flex: 1; min-width: 0; max-width: 22rem; }
form.add-type { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
form.add-type input { flex: 1 1 14rem; max-width: 26rem; }
.tag-admin { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem .9rem; }
.tag-admin li { display: inline-flex; align-items: center; gap: .25rem; }
button.tag-remove { background: none; border: 0; padding: 0 .25rem; color: var(--err); font-size: 1.1rem; line-height: 1; font-weight: 600; }

.gallery a.photo-link { display: block; cursor: zoom-in; }

/* visualizador de fotos */
html.lb-open { overflow: hidden; }
.lightbox { position: fixed; inset: 0; z-index: 1000; background: rgba(15, 12, 10, .92); }
.lightbox[hidden] { display: none; }
.lb-stage { position: absolute; inset: 0; overflow: auto; display: flex; padding: 3.5rem 1rem; overscroll-behavior: contain; }
.lb-stage img { margin: auto; display: block; max-width: 100%; max-height: 100%; object-fit: contain;
  cursor: zoom-in; box-shadow: 0 6px 30px rgba(0, 0, 0, .5); background: #fff; user-select: none; }
.lightbox.zoomed .lb-stage { padding: 0; }
.lightbox.zoomed .lb-stage img { max-width: none; max-height: none; cursor: zoom-out; box-shadow: none; }
.lb-caption { position: absolute; left: 50%; bottom: .6rem; transform: translateX(-50%); margin: 0;
  max-width: calc(100% - 2rem); padding: .3rem .8rem; border-radius: var(--radius);
  background: rgba(0, 0, 0, .6); color: #f5efe9; font-size: .9rem; text-align: center; }
.lightbox.zoomed .lb-caption, .lb-caption[hidden] { display: none; }
.lb-btn { position: absolute; border: 0; border-radius: 50%; width: 2.6rem; height: 2.6rem; padding: 0;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 1.7rem; line-height: 1; cursor: pointer; }
.lb-btn:hover, .lb-btn:focus-visible { background: rgba(0, 0, 0, .8); }
.lb-btn[hidden] { display: none; }
.lb-close { top: .6rem; right: .6rem; }
.lb-prev, .lb-next { top: 50%; transform: translateY(-50%); }
.lb-prev { left: .6rem; }
.lb-next { right: .6rem; }
.lightbox.zoomed .lb-prev, .lightbox.zoomed .lb-next { display: none; }
.gallery figcaption { font-size: .82rem; color: var(--muted); margin-top: .3rem; }
.comment { border-left: 3px solid var(--accent-soft); padding: .3rem .9rem; margin: .7rem 0; }
.comment-form { margin-top: 1rem; }
.history table, table.users, table.kv { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; vertical-align: top; padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
table.kv th { width: 16rem; }
details summary { cursor: pointer; font-weight: 600; }
details.prev summary { font-weight: 400; color: var(--accent); }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.roles { font-size: .9rem; color: var(--muted); }
.roles dt { font-weight: 600; color: var(--text); margin-top: .4rem; }
.roles dd { margin: 0; }
pre.code { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; overflow-x: auto; font-size: .85rem; }

/* login */
.login-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.login-options .box { margin: 0; }
