/* Philnance — gestor de finanças da família Reis.
   Paleta dos gráficos validada com o script da skill dataviz:
   séries em modo claro e escuro passam banda de luminosidade, chroma,
   separação CVD (ΔE 25,0 e 41,3 — alvo ≥12) e contraste.
   Os dois WARN de contraste (#1baf7a, #e87ba4) obrigam a rótulos visíveis:
   por isso legendas e rótulos diretos não são opcionais aqui. */

:root {
  color-scheme: light;

  /* superfícies */
  --plane:        #f4f2ee;
  --surface:      #fbfaf7;
  --surface-2:    #f7f5f1;
  --surface-sunk: #efece6;

  /* tinta */
  --ink:          #14161b;
  --ink-2:        #52514e;
  --ink-muted:    #8b8981;
  --line:         #e4e1d9;
  --line-strong:  #d3cfc5;

  /* marca — verde-dólar e o dourado dos olhos do Phil */
  --accent:       #1baf7a;
  --accent-deep:  #15855d;
  --accent-wash:  #e6f6ef;
  --gold:         #eda100;
  --gold-wash:    #fdf3dd;
  --beagle:       #8a5a2b;

  /* séries dos gráficos (validadas) */
  --s-entrada:    #1baf7a;
  --s-gasto:      #eb6834;
  --s-diego:      #2a78d6;
  --s-rosane:     #e87ba4;
  --s-conta:      #4a3aa7;
  --s-bar:        #2a78d6;   /* barras de magnitude: uma só cor + rótulo direto */

  /* estado */
  --good:         #0ca30c;
  --good-ink:     #006300;
  --warn:         #fab219;
  --warn-ink:     #8a5d10;
  --crit:         #d03b3b;

  --grid:         #e8e5dd;
  --axis:         #c9c5ba;

  --radius:       14px;
  --radius-lg:    20px;
  --shadow-sm:    0 1px 2px rgba(20,22,27,.06), 0 1px 3px rgba(20,22,27,.04);
  --shadow:       0 8px 30px rgba(20,22,27,.10), 0 2px 8px rgba(20,22,27,.05);
  --sans:         "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:        #0d0e11;
    --surface:      #14161b;
    --surface-2:    #191c22;
    --surface-sunk: #101216;
    --ink:          #f4f3ef;
    --ink-2:        #c3c2b7;
    --ink-muted:    #8b8981;
    --line:         #262a32;
    --line-strong:  #343945;
    --accent:       #199e70;
    --accent-deep:  #2ecb92;
    --accent-wash:  #10241d;
    --gold:         #c98500;
    --gold-wash:    #241d0d;
    --beagle:       #c98a52;
    --s-entrada:    #199e70;
    --s-gasto:      #d95926;
    --s-diego:      #3987e5;
    --s-rosane:     #d55181;
    --s-conta:      #9085e9;
    --s-bar:        #3987e5;
    --good:         #0ca30c;
    --good-ink:     #2ecb92;
    --warn:         #fab219;
    --warn-ink:     #f0c256;
    --crit:         #e66767;
    --grid:         #22262e;
    --axis:         #343945;
    --shadow-sm:    0 1px 2px rgba(0,0,0,.4);
    --shadow:       0 8px 30px rgba(0,0,0,.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:        #0d0e11;
  --surface:      #14161b;
  --surface-2:    #191c22;
  --surface-sunk: #101216;
  --ink:          #f4f3ef;
  --ink-2:        #c3c2b7;
  --ink-muted:    #8b8981;
  --line:         #262a32;
  --line-strong:  #343945;
  --accent:       #199e70;
  --accent-deep:  #2ecb92;
  --accent-wash:  #10241d;
  --gold:         #c98500;
  --gold-wash:    #241d0d;
  --beagle:       #c98a52;
  --s-entrada:    #199e70;
  --s-gasto:      #d95926;
  --s-diego:      #3987e5;
  --s-rosane:     #d55181;
  --s-conta:      #9085e9;
  --s-bar:        #3987e5;
  --good:         #0ca30c;
  --good-ink:     #2ecb92;
  --warn:         #fab219;
  --warn-ink:     #f0c256;
  --crit:         #e66767;
  --grid:         #22262e;
  --axis:         #343945;
  --shadow-sm:    0 1px 2px rgba(0,0,0,.4);
  --shadow:       0 8px 30px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: var(--sans);
  background: var(--plane);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* números que alinham em coluna levam tabular; os grandes ficam proporcionais */
.num { font-variant-numeric: tabular-nums; }

/* ---------- cadeado ---------- */
.gate {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 22px;
  background:
    radial-gradient(900px 480px at 50% -10%, var(--accent-wash), transparent 65%),
    var(--plane);
}
.gate-card {
  width: 100%; max-width: 370px; text-align: center; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 32px 26px 26px; box-shadow: var(--shadow);
}
.gate-card img { width: 84px; height: 84px; margin-bottom: 10px; }
.gate-t { font-size: 1.45rem; font-weight: 700; letter-spacing: -.03em; }
.gate-t b { color: var(--accent); }
.gate-p { color: var(--ink-muted); font-size: .88rem; margin: 5px 0 18px; }
.gate-card input {
  width: 100%; text-align: center; font-family: var(--sans); font-size: 1.05rem;
  letter-spacing: .3em; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface-sunk);
  color: var(--ink); outline: none; transition: border-color .15s, box-shadow .15s;
}
.gate-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-wash); }
.gate-err { color: var(--crit); font-size: .82rem; min-height: 1.2em; margin: 9px 0 2px; }
.gate-btn {
  width: 100%; margin-top: 10px; padding: 13px 16px; border: 0; border-radius: 12px;
  cursor: pointer; font-family: var(--sans); font-weight: 600; font-size: 1rem;
  color: #fff; background: linear-gradient(150deg, var(--accent), var(--accent-deep));
  transition: filter .15s, transform .1s;
}
.gate-btn:hover { filter: brightness(1.08); }
.gate-btn:active { transform: translateY(1px); }
.gate-btn:disabled { opacity: .6; cursor: default; }
.shake { animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-8px); }
  40%,80% { transform: translateX(8px); }
}

/* ---------- cabeçalho ---------- */
.top {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}
.top-in {
  max-width: 1240px; margin: 0 auto; padding: 11px 20px;
  display: flex; align-items: center; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
/* o wordmark é monocromático e usa currentColor: herda a tinta do tema */
.brand .wm { height: 30px; width: auto; color: var(--ink); display: block; }
@media (max-width: 720px) { .brand .wm { height: 26px; } }
.top-sp { flex: 1; }
.sync {
  font-size: .72rem; color: var(--ink-muted); display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-2); white-space: nowrap;
}
.sync::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-muted);
}
.sync[data-s="synced"]::before { background: var(--good); }
.sync[data-s="syncing"]::before { background: var(--warn); animation: pulse 1s infinite; }
.sync[data-s="offline"]::before { background: var(--crit); }
@keyframes pulse { 50% { opacity: .3; } }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer; font-size: 15px;
  display: grid; place-items: center; transition: .14s;
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--ink); }

/* ---------- navegação ---------- */
.nav { border-bottom: 1px solid var(--line); background: var(--surface); }
.nav-in {
  max-width: 1240px; margin: 0 auto; padding: 0 20px; display: flex; gap: 2px;
  overflow-x: auto; scrollbar-width: none;
}
.nav-in::-webkit-scrollbar { display: none; }
.nav a {
  padding: 11px 13px; font-size: .86rem; font-weight: 600; color: var(--ink-muted);
  text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap;
  transition: color .14s, border-color .14s; display: flex; align-items: center; gap: 6px;
}
.nav a:hover { color: var(--ink); }
.nav a.on { color: var(--accent-deep); border-bottom-color: var(--accent); }

/* ---------- layout ---------- */
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 20px 72px; }
.view-h { margin-bottom: 18px; display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.view-h h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.03em; }
.view-h .sub { color: var(--ink-muted); font-size: .86rem; }
.sec-t {
  font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-muted); margin: 30px 0 12px;
}
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.full { grid-column: 1 / -1; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.card h3 { font-size: .92rem; font-weight: 650; letter-spacing: -.01em; }
.card .hint { font-size: .76rem; color: var(--ink-muted); margin-top: 2px; }

/* ---------- KPIs ---------- */
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
       padding: 15px 17px; box-shadow: var(--shadow-sm); }
.kpi .lbl {
  font-size: .7rem; color: var(--ink-muted); text-transform: uppercase;
  letter-spacing: .07em; font-weight: 700;
}
.kpi .val { font-size: 1.65rem; font-weight: 700; margin-top: 6px; letter-spacing: -.035em; }
.kpi .hint { font-size: .75rem; color: var(--ink-muted); margin-top: 3px; }
.pos { color: var(--good-ink); }
.neg { color: var(--crit); }
.delta { font-size: .75rem; font-weight: 650; margin-top: 3px; display: inline-flex; gap: 3px; }
.delta.up { color: var(--crit); }
.delta.down { color: var(--good-ink); }
.delta.flat { color: var(--ink-muted); }

/* ---------- avisos ---------- */
.note {
  border-radius: var(--radius); padding: 13px 16px; font-size: .85rem;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
  display: flex; gap: 10px; align-items: flex-start;
}
.note b { color: var(--ink); }
.note.warn { background: var(--gold-wash); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.note.warn b { color: var(--warn-ink); }
.note .ic { flex: none; font-size: 1rem; line-height: 1.3; }

/* ---------- barras de magnitude (uma cor + rótulo direto) ---------- */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: center; }
.bar-nm { font-size: .8rem; color: var(--ink-2); display: flex; align-items: center; gap: 6px;
          overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.bar-tr { background: var(--surface-sunk); border-radius: 5px; height: 9px; overflow: hidden; }
.bar-fl { height: 100%; border-radius: 5px; background: var(--s-bar); transition: width .5s cubic-bezier(.2,.8,.2,1); }
/* 94px cabe "15 223,07 €" numa linha — com menos, os valores grandes quebravam */
.bar-vl { font-size: .8rem; font-weight: 650; text-align: right; min-width: 94px; white-space: nowrap; }
.bar-row.clickable { cursor: pointer; }
.bar-row.clickable:hover .bar-nm { color: var(--ink); }

/* ---------- progresso de metas ---------- */
.goal { padding: 13px 0; border-bottom: 1px solid var(--line); }
.goal:last-child { border-bottom: 0; }
.goal-h { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.goal-nm { font-size: .88rem; font-weight: 600; }
.goal-vl { font-size: .8rem; color: var(--ink-muted); }
.goal-tr { background: var(--surface-sunk); border-radius: 6px; height: 10px; margin-top: 7px; overflow: hidden; }
.goal-fl { height: 100%; border-radius: 6px; background: var(--good); transition: width .5s; }
.goal-fl.warn { background: var(--warn); }
.goal-fl.over { background: var(--crit); }

/* ---------- tabela ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th {
  text-align: left; color: var(--ink-muted); font-size: .68rem; text-transform: uppercase;
  letter-spacing: .07em; padding: 9px 10px; border-bottom: 1px solid var(--line-strong);
  font-weight: 700; white-space: nowrap; position: sticky; top: 0; background: var(--surface);
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.desc-c { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: .7rem; font-weight: 650;
  padding: 3px 8px; border-radius: 6px; background: var(--surface-sunk); color: var(--ink-2);
  border: 1px solid var(--line); white-space: nowrap;
}
.chip.tag { background: var(--accent-wash); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent-deep); }
.chip.c9111 { color: var(--s-diego); }
.chip.c1455 { color: var(--s-rosane); }
.chip.cconta { color: var(--s-conta); }

/* ---------- filtros ---------- */
.filters { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.fbtn {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 13px; font-size: .78rem; font-weight: 600; cursor: pointer; color: var(--ink-2);
  font-family: var(--sans); transition: .14s;
}
.fbtn:hover { border-color: var(--line-strong); color: var(--ink); }
.fbtn.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.inp, select.inp {
  padding: 7px 11px; border: 1px solid var(--line); border-radius: 9px; font-size: .82rem;
  font-family: var(--sans); background: var(--surface); color: var(--ink); outline: none;
}
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.search { flex: 1; min-width: 160px; }

/* ---------- legenda ---------- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .76rem; color: var(--ink-2); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.chart-box { position: relative; height: 260px; margin-top: 10px; }
.chart-box.tall { height: 320px; }

/* ---------- donut + legenda com números ----------
   O círculo sozinho não deixa ler valores: a legenda numérica não é decoração,
   é o que torna o donut honesto. */
.donut-wrap { display: grid; grid-template-columns: 1fr 1.1fr; gap: 14px; align-items: center; }
.dleg { display: flex; flex-direction: column; gap: 7px; }
.dleg-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px;
            align-items: center; font-size: .8rem; }
.dleg-nm { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dleg-vl { font-weight: 650; white-space: nowrap; }
.dleg-pc { color: var(--ink-muted); min-width: 32px; text-align: right; }
@media (max-width: 560px) { .donut-wrap { grid-template-columns: 1fr; } }

/* ---------- calendário (heatmap) ----------
   Rampa sequencial de uma só cor: mais escuro = mais gasto. É a forma certa
   para magnitude numa grelha — cores categóricas aqui não significariam nada. */
.hm-scroll { overflow-x: auto; padding-bottom: 4px; }
.hm { display: inline-block; min-width: min-content; }
/* os meses partilham o mesmo template de colunas da grelha, senão os rótulos
   flutuam por cima das semanas erradas */
.hm-meses { display: grid; gap: 2px; font-size: .65rem; color: var(--ink-muted);
            margin-bottom: 4px; }
.hm-meses span { grid-row: 1; white-space: nowrap; }
/* fluxo por LINHAS: emitimos rótulo + 53 células, sete vezes */
.hm-grid { display: grid; gap: 2px; align-items: center; }
.hm-dia { font-size: .58rem; color: var(--ink-muted); padding-right: 6px;
          text-align: right; line-height: 10px; }
.hm-c { width: 10px; height: 10px; border-radius: 2px; display: block; }
.hm-off { background: transparent !important; }
.hm-leg { display: flex; align-items: center; gap: 3px; justify-content: flex-end;
          margin-top: 10px; font-size: .68rem; color: var(--ink-muted); }
.hm-leg span { margin: 0 4px; }

/* ---------- lista de comerciantes ---------- */
.mlist { display: flex; flex-direction: column; }
.mrow {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.mrow:last-child { border-bottom: 0; }
.mrow .mn { flex: 1; min-width: 0; }
.mrow .mt { font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow .ms { font-size: .73rem; color: var(--ink-muted); margin-top: 1px; }
.mrow .mv { font-size: .88rem; font-weight: 700; text-align: right; white-space: nowrap; }
.mrow .mv small { display: block; font-size: .7rem; font-weight: 500; color: var(--ink-muted); }

/* ---------- oportunidade ---------- */
.opp {
  display: flex; gap: 13px; align-items: flex-start; padding: 14px 16px;
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); background: var(--surface); margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.opp.warn { border-left-color: var(--warn); }
.opp.crit { border-left-color: var(--crit); }
.opp .oi { flex: none; font-size: 1.1rem; }
.opp .ot { font-size: .9rem; font-weight: 650; }
.opp .od { font-size: .8rem; color: var(--ink-2); margin-top: 4px; line-height: 1.5; }
.opp .ov { flex: none; text-align: right; font-weight: 700; font-size: .95rem; white-space: nowrap; }
.opp .ov small { display: block; font-size: .68rem; font-weight: 500; color: var(--ink-muted); }

/* ---------- importador ---------- */
.drop {
  border: 2px dashed var(--line-strong); border-radius: var(--radius-lg); padding: 40px 24px;
  text-align: center; background: var(--surface-2); transition: .16s; cursor: pointer;
}
.drop.over { border-color: var(--accent); background: var(--accent-wash); }
.drop .di { font-size: 2.2rem; }
.drop .dt { font-weight: 650; margin-top: 8px; }
.drop .ds { font-size: .8rem; color: var(--ink-muted); margin-top: 4px; }

.btn {
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer;
  font-family: var(--sans); font-size: .85rem; font-weight: 600;
  background: var(--surface); color: var(--ink); transition: .14s;
}
.btn:hover { border-color: var(--line-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }

.empty { text-align: center; padding: 44px 20px; color: var(--ink-muted); font-size: .88rem; }
.empty .ei { font-size: 2rem; margin-bottom: 8px; opacity: .5; }

/* ---------- responsivo ---------- */
/* as barras precisam de ~370px para o rótulo, a barra e o valor caberem numa
   linha; abaixo disso passam a coluna única em vez de espremer */
@media (max-width: 1000px) {
  .g4 { grid-template-columns: 1fr 1fr; }
  .g3 { grid-template-columns: 1fr; }
  .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 96px 1fr auto; }
  .wrap { padding: 18px 14px 60px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
