/* Componentes compartilhados da ferramenta (Visão geral / Meu histórico).
   Tudo fica dentro de um container .tui, então não colide com as classes
   antigas de ferramenta.html (#calc-embed ...) nem com card-system.css (site público).
   Só usa os tokens que a página já define (--paper, --paper-card, --surface-2, --ink, --ink-soft,
   --line, --emerald, --ochre, --neutral-a, --rust e as variações -soft). Dark e claro funcionam
   sozinhos, porque os tokens mudam com data-theme. Nenhum texto abaixo de 11px. */

/* Contraste WCAG AA (texto pequeno >= 4,5:1). No tema claro os tokens da página não chegam lá
   para texto de 11–14px, então dentro do .tui o cinza de apoio, o coral e o dourado de TEXTO
   ficam um tom mais escuros (as cores de barras, jarros e fundos não mudam). */
:root:not([data-theme="dark"]) .tui{ --ink-soft: #6A604F; --rust-text: #9A432B; --gold-text: #7A5314; --rust: #9A432B; }
:root[data-theme="dark"] .tui{ --rust-text: var(--rust); --gold-text: var(--ochre); }

.tui{
  --tui-radius: 16px;
  --tui-gap: 16px;
  font-family: 'Geist', sans-serif;
  color: var(--ink);
}

/* ---------- card ---------- */
.tui .card{
  background: var(--paper-card);
  border: 0.5px solid var(--line);
  border-radius: var(--tui-radius);
  padding: 20px;
  box-shadow: none;
  min-width: 0;
}
.tui .card--sm{ padding: 16px; }
.tui .card--inner{ background: var(--surface-2); }
.tui .card--ghost{ background: transparent; border: 1px dashed var(--line); }
.tui .card--clickable{
  display: block; width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit;
  transition: border-color 0.15s ease;
}
.tui .card--clickable:hover{ border-color: var(--ink-soft); }
.tui .card--clickable:focus-visible,
.tui .chip-btn:focus-visible,
.tui .tui-btn:focus-visible{ outline: 2px solid var(--emerald); outline-offset: 2px; }

.tui .card-head{ display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.tui .card-title{
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink-soft);
}
.tui .card-icon{
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 10px;
  background: var(--emerald-soft); color: var(--emerald);
  flex-shrink: 0;
}
.tui .card-icon--gold{ background: var(--ochre-soft); color: var(--gold-text); }
.tui .card-icon--coral{ background: var(--rust-soft); color: var(--rust-text); }
.tui .card-icon svg{ width: 18px; height: 18px; }

/* ---------- stat (valor + rótulo + apoio) ---------- */
.tui .stat{ display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tui .stat-label{ font-size: 12px; color: var(--ink-soft); }
.tui .stat-value{
  font-weight: 700; font-size: 24px; line-height: 1.1; letter-spacing: -0.01em; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.tui .stat-value .cents{ font-size: 0.55em; }
.tui .stat--lg .stat-value{ font-size: clamp(36px, 6vw, 48px); color: var(--emerald); }
.tui .stat--pos .stat-value{ color: var(--emerald); }
.tui .stat--neg .stat-value{ color: var(--rust-text); }
.tui .stat-sub{ font-size: 12px; color: var(--ink-soft); }
.tui .stat-row{ display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 10px; }

/* ---------- chip (positivo / negativo / neutro) ---------- */
.tui .chip{
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; line-height: 1;
  padding: 5px 10px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-soft);
}
.tui .chip svg{ width: 12px; height: 12px; flex-shrink: 0; }
.tui .chip--pos{ background: var(--emerald-soft); color: var(--emerald); }
.tui .chip--neg{ background: var(--rust-soft); color: var(--rust-text); }
.tui .chip--gold{ background: var(--ochre-soft); color: var(--gold-text); }
.tui .chip--neu{ background: var(--surface-2); color: var(--ink-soft); }
/* chip clicável (ex.: categoria sugerida) */
.tui .chip-btn{ cursor: pointer; border: 0; font-family: inherit; min-height: 32px; }
.tui .chip-btn:hover{ filter: brightness(1.1); }

/* ---------- bar (progresso em pílula) ---------- */
.tui .bar{ display: block; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.tui .card--inner .bar{ background: var(--line); }
.tui .bar-fill{
  display: block; height: 100%; width: calc(var(--p, 0) * 1%);
  max-width: 100%; border-radius: 999px; background: var(--emerald);
}
.tui .bar--gold .bar-fill{ background: var(--neutral-a); }
.tui .bar--coral .bar-fill{ background: var(--rust); }
.tui .bar-meta{ display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--ink-soft); }
.tui .bar-meta b{ color: var(--ink); font-weight: 600; }
/* barra empilhada (baldes do Mês a mês): filhos com flex-grow = % */
.tui .bar--stack{ display: flex; gap: 2px; background: transparent; }
.tui .bar--stack > span{ display: block; height: 100%; border-radius: 999px; flex: var(--w, 1) 1 0; min-width: 4px; }

/* ---------- jar (balde; mesmo desenho do mockup da capa) ---------- */
.tui .jar-wrap{ display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; min-width: 0; }
.tui .jar{
  width: 44px; height: 76px; position: relative; overflow: hidden;
  background: var(--paper); border: 2px solid var(--ink);
  border-radius: 5px 5px 12px 12px;
}
.tui .jar-fill{
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--p, 0) * 1%); background: var(--c, var(--emerald));
}
.tui .jar-fill::after{ content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: rgba(255,255,255,0.35); }
.tui .jar-name{ font-size: 12px; color: var(--ink-soft); line-height: 1.25; min-height: 30px; }
.tui .jar-amt{ font-size: 14px; font-weight: 700; color: var(--ink); }
.tui .jar-pct{ font-size: 12px; color: var(--ink-soft); }

/* ---------- ícones de linha (SVG inline, ver tool-icons.js) ---------- */
.tui .ico{ width: 1em; height: 1em; flex-shrink: 0; vertical-align: -0.125em; }

/* ---------- botões ---------- */
.tui .tui-btn{
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 0; cursor: pointer;
  font: 600 14px 'Geist', sans-serif; background: var(--emerald); color: #fff;
}
.tui .tui-btn:hover{ filter: brightness(1.08); }
.tui .tui-btn--ghost{ background: transparent; color: var(--ink); border: 0.5px solid var(--line); }
.tui .tui-btn--ghost:hover{ background: var(--surface-2); filter: none; }
.tui .tui-btn svg{ width: 16px; height: 16px; }
/* campos: 16px no mobile evita o zoom do iOS */
.tui .tui-input{
  min-height: 44px; padding: 0 12px; border-radius: 12px; width: 100%;
  border: 0.5px solid var(--line); background: var(--surface-2); color: var(--ink);
  font: 400 16px 'Geist', sans-serif;
}
.tui .tui-input:focus-visible{ outline: 2px solid var(--emerald); outline-offset: 1px; }

@media (prefers-reduced-motion: reduce){
  .tui .card--clickable{ transition: none; }
}

/* botão primário: no escuro, o branco sobre o esmeralda dá só 3,4:1 — texto escuro dá 5,8:1 */
:root[data-theme="dark"] .tui .tui-btn:not(.tui-btn--ghost){ color: var(--paper); }

/* foco visível em tudo que é interativo da ferramenta (o CSS antigo tirava o outline de vários campos) */
#calc-embed .tui :focus-visible{ outline: 2px solid var(--emerald) !important; outline-offset: 2px; }
/* tema claro: textos que o CSS antigo pinta com o dourado dos baldes (1,8:1) ficam na cor do texto */
:root:not([data-theme="dark"]) #calc-embed .tui .bucket-amount,
:root:not([data-theme="dark"]) #calc-embed .tui .hist-edit-bucket-amt{ color: var(--ink) !important; }
:root:not([data-theme="dark"]) #calc-embed .tui .tip b{ color: var(--gold-text); }
/* telas de detalhe antigas: nada abaixo de 11px */
#calc-embed .tui :is(.dia-entry-tag, .bucket-pct-suffix, .dia-total-card .lbl, .dia-entry-date, .dia-entry-cat, .cat-pct, .cat-donut-label){ font-size: 11px; }