/* Central da Casa — estilos.
 * Tokens em :root; o tema escuro só redefine tokens. Nenhuma cor fixa fora
 * daqui. As cores dos potes (--s1…--s8) são a paleta de referência validada
 * (ordem fixa, passos próprios para o escuro) — ver README, "Cores". */

:root {
  --bg: #f6f1e9;
  --surface: #fffdf9;
  --surface-2: #efe8dd;
  --line: #e4dbcd;
  --ink: #2a2521;
  --ink-2: #645a50;
  --ink-3: #8a7f73;
  --accent: #3f6b55;
  --accent-ink: #ffffff;
  --accent-soft: #e2ece5;
  --danger: #a8352b;
  --danger-soft: #f7e3df;
  --warn: #8a5a00;
  --warn-soft: #f8ecd2;
  --ok: #2f6b45;
  --shadow: 0 1px 2px rgb(42 37 33 / 0.05), 0 6px 20px rgb(42 37 33 / 0.06);
  --shadow-lg: 0 20px 60px rgb(42 37 33 / 0.2);
  --veil: rgb(42 37 33 / 0.4);

  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --grid: #ece5da;

  --font-display: 'Fraunces', Georgia, serif;
  --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r-sm: 10px;
  --r: 16px;
  --r-lg: 22px;
  --pill: 999px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='claro']) {
    --bg: #171513; --surface: #211e1a; --surface-2: #2a2621; --line: #37322b;
    --ink: #f2ede6; --ink-2: #b9afa3; --ink-3: #8f857a;
    --accent: #8dbfa3; --accent-ink: #13201a; --accent-soft: #23302a;
    --danger: #e98a7f; --danger-soft: #3a221f; --warn: #e3b55a; --warn-soft: #33291a; --ok: #8cc49e;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.25);
    --shadow-lg: 0 20px 60px rgb(0 0 0 / 0.5); --veil: rgb(0 0 0 / 0.55);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --grid: #302b25;
    color-scheme: dark;
  }
}
:root[data-theme='escuro'] {
  --bg: #171513; --surface: #211e1a; --surface-2: #2a2621; --line: #37322b;
  --ink: #f2ede6; --ink-2: #b9afa3; --ink-3: #8f857a;
  --accent: #8dbfa3; --accent-ink: #13201a; --accent-soft: #23302a;
  --danger: #e98a7f; --danger-soft: #3a221f; --warn: #e3b55a; --warn-soft: #33291a; --ok: #8cc49e;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.25);
  --shadow-lg: 0 20px 60px rgb(0 0 0 / 0.5); --veil: rgb(0 0 0 / 0.55);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --grid: #302b25;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; margin: 0; line-height: 1.2; }
h1 { font-size: 30px; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; flex: none; }
.num { font-variant-numeric: tabular-nums; }
.sub { color: var(--ink-2); font-size: 14px; }
.mini { color: var(--ink-3); font-size: 12.5px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---- estrutura ------------------------------------------------------------ */

#app { padding: calc(var(--safe-t) + 20px) 16px calc(var(--nav-h) + var(--safe-b) + 28px); max-width: 760px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 18px; animation: entrar 0.25s var(--ease); }
@keyframes entrar { from { opacity: 0; transform: translateY(4px); } }

.topo { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.topo .sub { margin-top: 4px; }
.voltar { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); text-decoration: none; font-size: 14px; margin-bottom: -8px; }
.voltar svg { width: 18px; height: 18px; }

.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.nav ul { list-style: none; margin: 0 auto; padding: 0; display: flex; max-width: 520px; height: var(--nav-h); }
.nav li { flex: 1; }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 100%; color: var(--ink-3); text-decoration: none; font-size: 11.5px; font-weight: 600; }
.nav a[aria-current='page'] { color: var(--accent); }

/* No computador: navegação à esquerda, conteúdo mais largo. */
@media (min-width: 960px) {
  .nav { inset: 0 auto 0 0; width: 220px; border-top: 0; border-right: 1px solid var(--line); padding: 28px 12px; }
  .nav::before { content: 'Central da Casa'; display: block; font: 600 20px var(--font-display); padding: 0 12px 22px; color: var(--ink); }
  .nav ul { flex-direction: column; height: auto; gap: 2px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: var(--r-sm); font-size: 15px; }
  .nav a[aria-current='page'] { background: var(--accent-soft); }
  #app { margin-left: 220px; max-width: 980px; padding: 40px 40px 60px; }
  body:has(.nav[hidden]) #app { margin-left: auto; }
}

/* ---- cartões ---------------------------------------------------------------- */

.cartao { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.cartao > h2, .cartao > h3, .cartao .cab-cartao { margin-bottom: 12px; }
.cab-cartao { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cab-cartao h2, .cab-cartao h3 { margin: 0; }
.grelha { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grelha-2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .grelha-2.empilha { grid-template-columns: 1fr; } }

.numero { display: flex; flex-direction: column; gap: 2px; }
.numero .rotulo { font-size: 13px; color: var(--ink-2); }
.numero .valor { font: 600 24px var(--font-display); font-variant-numeric: tabular-nums; }
.numero .valor.grande { font-size: 32px; }
.numero .nota { font-size: 12.5px; color: var(--ink-3); }
.positivo { color: var(--ok); }
.negativo { color: var(--danger); }

.lista { list-style: none; margin: 0; padding: 0; }
.lista > li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.lista > li:first-child { border-top: 0; }
.lista .corpo { flex: 1; min-width: 0; }
.lista .titulo { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lista .direita { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lista button.linha { all: unset; display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; cursor: pointer; }
.grupo-titulo { font-size: 12.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); margin: 18px 0 2px; display: flex; justify-content: space-between; }

.etiqueta { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: var(--pill); background: var(--surface-2); color: var(--ink-2); }
.etiqueta.ok { background: var(--accent-soft); color: var(--accent); }
.etiqueta.aviso { background: var(--warn-soft); color: var(--warn); }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; background: var(--accent-soft); color: var(--accent); flex: none; }

.alerta { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-sm); background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.alerta.perigo { background: var(--danger-soft); color: var(--danger); }
.alerta.info { background: var(--accent-soft); color: var(--accent); }
.alerta svg { width: 20px; height: 20px; margin-top: 1px; }

/* ---- potes ------------------------------------------------------------------ */

.pote { display: flex; flex-direction: column; gap: 8px; }
.pote .linha-pote { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pote .nome { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.marca { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--c, var(--s1)); }
.barra { height: 8px; border-radius: var(--pill); background: var(--surface-2); overflow: hidden; }
.barra > span { display: block; height: 100%; border-radius: var(--pill); background: var(--c, var(--accent)); width: 0; transition: width 0.6s var(--ease); }
.c0 { --c: var(--s1); } .c1 { --c: var(--s2); } .c2 { --c: var(--s3); } .c3 { --c: var(--s4); }
.c4 { --c: var(--s5); } .c5 { --c: var(--s6); } .c6 { --c: var(--s7); } .c7 { --c: var(--s8); }

/* ---- botões e campos -------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--pill); border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px;
  cursor: pointer; text-decoration: none; transition: transform 0.1s, opacity 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.sec { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.perigo { background: var(--danger); color: #fff; }
.btn.bloco { width: 100%; }
.btn.peq { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn svg { width: 18px; height: 18px; }
.ico { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--ink-2); }
.ico.limpo { border-color: transparent; background: transparent; }
.ico svg { width: 20px; height: 20px; }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; }
.girar { animation: girar 0.9s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

.campo { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.campo input, .campo select, .campo textarea {
  font-weight: 400; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 11px 12px; min-height: 46px; width: 100%;
}
.campo textarea { min-height: 80px; resize: vertical; }
.campo input:focus, .campo select:focus, .campo textarea:focus, .btn:focus-visible, .ico:focus-visible, a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.campo .dica { font-weight: 400; font-size: 12.5px; color: var(--ink-3); }
.campo.euro { position: relative; }
.campo.euro input { padding-right: 32px; text-align: right; font-variant-numeric: tabular-nums; }
.campo.euro::after { content: '€'; position: absolute; right: 12px; bottom: 12px; color: var(--ink-3); font-weight: 400; }
.campo.pct input { padding-right: 32px; text-align: right; }
.campo.pct { position: relative; }
.campo.pct::after { content: '%'; position: absolute; right: 12px; bottom: 12px; color: var(--ink-3); font-weight: 400; }
.form { display: flex; flex-direction: column; gap: 14px; }
.erro-box { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: var(--r-sm); font-size: 14px; }

.segmentos { display: flex; background: var(--surface-2); border-radius: var(--pill); padding: 4px; gap: 4px; }
.segmentos button { flex: 1; border: 0; background: transparent; border-radius: var(--pill); padding: 8px 10px; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; min-height: 38px; }
.segmentos button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.interruptor { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px; }
.interruptor input { width: 44px; height: 26px; appearance: none; background: var(--line); border-radius: var(--pill); position: relative; cursor: pointer; transition: background 0.2s; flex: none; }
.interruptor input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.2s var(--ease); box-shadow: 0 1px 3px rgb(0 0 0 / 0.2); }
.interruptor input:checked { background: var(--accent); }
.interruptor input:checked::after { transform: translateX(18px); }

/* ---- folha (bottom sheet), avisos, vazio ------------------------------------- */

.veu { position: fixed; inset: 0; z-index: 50; background: var(--veil); display: flex; align-items: flex-end; justify-content: center; animation: aparecer 0.2s; }
.veu.saindo { opacity: 0; transition: opacity 0.2s; }
@keyframes aparecer { from { opacity: 0; } }
.folha {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: var(--r-lg) var(--r-lg) 0 0; padding: 8px 16px calc(var(--safe-b) + 20px);
  box-shadow: var(--shadow-lg); animation: subir 0.3s var(--ease);
}
@keyframes subir { from { transform: translateY(40px); opacity: 0.6; } }
@media (min-width: 700px) { .veu { align-items: center; } .folha { border-radius: var(--r-lg); padding-bottom: 20px; } }
.folha .pega { width: 40px; height: 5px; border-radius: var(--pill); background: var(--line); margin: 4px auto 10px; }
.folha .cab { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.folha .conteudo { display: flex; flex-direction: column; gap: 14px; }
.rodape { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.rodape .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 76px); transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: var(--pill); font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); animation: aparecer 0.2s; max-width: calc(100% - 32px); }
.toast.erro { background: var(--danger); color: #fff; }

.vazio { text-align: center; padding: 32px 16px; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.vazio h3 { color: var(--ink); }
.vazio .simbolo { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }

/* ---- entrada ------------------------------------------------------------------ */

.entrada-tela { max-width: 400px; margin: 6vh auto 0; }
.entrada-tela .marca-casa { width: 64px; height: 64px; border-radius: 18px; margin-bottom: 8px; }
.entrada-tela h1 { font-size: 34px; }

/* ---- gráfico ------------------------------------------------------------------ */

.grafico { position: relative; }
.grafico svg { width: 100%; height: auto; display: block; overflow: visible; }
.grafico .eixo text { fill: var(--ink-3); font-size: 11px; font-family: var(--font); }
.grafico .grade line { stroke: var(--grid); stroke-width: 1; }
.grafico .zero { stroke: var(--ink-3); stroke-width: 1; }
.grafico .serie { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.grafico .serie.tracejada { stroke-dasharray: 5 4; }
.grafico .rotulo-fim { font-size: 11.5px; font-weight: 600; fill: var(--ink-2); font-family: var(--font); }
.grafico .cruz { stroke: var(--ink-3); stroke-width: 1; }
.grafico .ponto { stroke: var(--surface); stroke-width: 2; }
.grafico .meta-linha { stroke-width: 1; stroke-dasharray: 2 4; }
.dica-grafico {
  position: absolute; top: 0; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg); padding: 8px 10px; font-size: 12.5px; min-width: 170px;
}
.dica-grafico strong { display: block; margin-bottom: 4px; }
.dica-grafico .l { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.dica-grafico .l span:first-child { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.legenda { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.legenda span { display: inline-flex; align-items: center; gap: 6px; }
.legenda .traco { width: 14px; height: 0; border-top: 2px solid var(--c); }
.legenda .traco.tracejado { border-top-style: dashed; }

/* ---- tabela ------------------------------------------------------------------ */

.tabela-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.tabela { border-collapse: collapse; font-size: 13px; width: 100%; font-variant-numeric: tabular-nums; }
.tabela th, .tabela td { padding: 7px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
.tabela th:first-child, .tabela td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.tabela th { color: var(--ink-3); font-weight: 600; font-size: 12px; }
.tabela tr.defice td { color: var(--danger); }

details.dobra > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
details.dobra > summary::-webkit-details-marker { display: none; }
details.dobra > summary::after { content: '+'; font-size: 20px; color: var(--ink-3); }
details.dobra[open] > summary::after { content: '−'; }
details.dobra[open] > summary { margin-bottom: 12px; }

/* ---- editor de cenário -------------------------------------------------------- */

.pote-editor { display: grid; grid-template-columns: 1fr 92px; gap: 10px; align-items: end; padding: 14px 0; border-top: 1px solid var(--line); }
.pote-editor:first-of-type { border-top: 0; padding-top: 0; }
.pote-editor .extra { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.soma-pct { display: flex; justify-content: space-between; align-items: center; font-weight: 600; padding: 10px 12px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent); }
.soma-pct.errada { background: var(--danger-soft); color: var(--danger); }
.evento { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.evento:first-child { border-top: 0; }
.evento .icone-ev { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); flex: none; }
.evento .icone-ev svg { width: 18px; height: 18px; }
.barra-guardar { position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 10px); z-index: 10; display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 10px 10px 16px; border-radius: var(--pill); background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); }
.barra-guardar .btn { min-height: 38px; }
@media (min-width: 960px) { .barra-guardar { bottom: 20px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
