/* Gestão Jardim — receitas = azul, despesas = laranja (paleta validada para daltonismo).
   O verde é só cromo da interface (botões); nunca representa dados. */
:root {
  color-scheme: light;
  --bg: #f3f3ef;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --line: #e1e0da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #6b6a66;
  --accent: #2e6b3e;
  --accent-ink: #ffffff;
  --income: #2a78d6;
  --expense: #eb6834;
  --danger: #b42f2f;
  --warn-bg: #fff3d6;
  --warn-ink: #6b4a00;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #262624;
    --line: #333331;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #9d9c93;
    --accent: #6cbf80;
    --accent-ink: #0b0b0b;
    --income: #3987e5;
    --expense: #d95926;
    --danger: #ee8a8a;
    --warn-bg: #3a2f12;
    --warn-ink: #f5d27a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--text-3); }
.small { font-size: 0.85rem; }

/* ---------- Estrutura ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 960px; margin: 0 auto; padding: 16px;
}
.top h1 { font-size: 1.25rem; font-weight: 700; white-space: nowrap; }
.top-actions { display: flex; gap: 8px; }
.top-actions .btn { min-height: 40px; padding: 0 12px; font-size: 0.9rem; white-space: nowrap; }
.page { max-width: 960px; margin: 0 auto; padding: 0 16px 48px; display: grid; gap: 16px; transition: opacity .15s; }
.page[aria-busy="true"] { opacity: .55; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card h2 { font-size: 1.05rem; font-weight: 650; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }

/* ---------- Botões e campos ---------- */
.btn {
  appearance: none; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.icon { width: 44px; padding: 0; font-size: 1.5rem; line-height: 1; border-color: var(--line); background: var(--surface); color: var(--text); }
.btn.icon:disabled { opacity: .35; cursor: default; }
.btn.block { width: 100%; }
.btn.small-btn { min-height: 36px; padding: 0 12px; font-size: 0.9rem; font-weight: 500; }
.btn:disabled { opacity: .6; cursor: default; }
:focus-visible { outline: 3px solid var(--income); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: 0.92rem; margin: 14px 0 6px; }
input, select {
  font: inherit; width: 100%; min-height: 46px; padding: 8px 12px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
input[type="radio"] { width: auto; min-height: 0; }
.form-error { color: var(--danger); font-weight: 600; margin-top: 12px; }

/* ---------- Mês e KPIs ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.month-nav h2 { font-size: 1.25rem; font-weight: 700; text-align: center; flex: 1; }

.kpis { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.kpi.hero, .kpi.net { grid-column: 1 / -1; }
.kpi .figure { font-size: 1.4rem; }
@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .kpi.net { grid-column: auto; }
  .kpi .figure { font-size: 1.6rem; }
}
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.kpi h3 { font-size: 0.9rem; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.kpi .figure { font-weight: 700; margin-top: auto; padding-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hero-figure { font-size: 3rem; line-height: 1.15; font-weight: 750; margin: 4px 0 2px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.key { width: 14px; height: 4px; border-radius: 2px; display: inline-block; flex: none; }
.key.income { background: var(--income); }
.key.expense { background: var(--expense); }

/* ---------- Gráfico de 6 meses ---------- */
.legend { list-style: none; display: flex; gap: 16px; margin: 0 0 8px; padding: 0; color: var(--text-2); font-size: 0.9rem; }
.legend li { display: flex; align-items: center; gap: 8px; }
.chart { position: relative; display: grid; grid-template-columns: 52px 1fr; gap: 8px; height: 240px; }
.chart-axis { position: relative; height: 200px; }
.chart-axis span { position: absolute; right: 0; transform: translateY(50%); font-size: 0.72rem; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-plot { position: relative; height: 240px; }
.chart-grid { position: absolute; inset: 0 0 40px 0; }
.chart-grid i { position: absolute; left: 0; right: 0; height: 1px; background: var(--line); }
.chart-cols { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(6, 1fr); }
.col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; cursor: default; border-radius: 8px; outline-offset: -2px; }
.col:hover, .col:focus-visible { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.col .bars { height: 200px; display: flex; align-items: flex-end; gap: 2px; }
.bar { width: clamp(10px, 3.2vw, 24px); min-height: 0; border-radius: 4px 4px 0 0; }
.bar.income { background: var(--income); }
.bar.expense { background: var(--expense); }
.col .label { height: 40px; padding-top: 8px; font-size: 0.8rem; color: var(--text-2); }
.col.current .label { color: var(--text); font-weight: 700; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; min-width: 170px; padding: 10px 12px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 18%); font-size: 0.88rem;
}
.tooltip .t-title { color: var(--text-2); margin-bottom: 6px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.tooltip .t-row strong { font-variant-numeric: tabular-nums; }
.tooltip .t-row span:last-child { color: var(--text-2); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 0.85rem; color: var(--text-2); font-weight: 600; }

/* ---------- Categorias ---------- */
.cats { display: grid; gap: 14px; margin-top: 12px; }
.cat-row .cat-head { display: flex; justify-content: space-between; gap: 12px; font-size: 0.95rem; }
.cat-row .cat-value { font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }
.cat-row .track { height: 10px; margin-top: 6px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.cat-row .fill { height: 100%; border-radius: 0 4px 4px 0; }
.cat-row .fill.income { background: var(--income); }
.cat-row .fill.expense { background: var(--expense); }
.empty { color: var(--text-3); padding: 8px 0; }

/* ---------- Lançamentos ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.tab {
  font: inherit; font-weight: 600; cursor: pointer; min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--text-2);
}
.tab[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line); }
.tx:first-child { border-top: 0; }
.tx .key { width: 6px; height: 36px; border-radius: 3px; }
.tx .main { min-width: 0; }
.tx .title { font-weight: 600; overflow-wrap: anywhere; }
.tx .meta { color: var(--text-3); font-size: 0.85rem; overflow-wrap: anywhere; }
.tx .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.tx .actions { grid-column: 2 / -1; display: flex; gap: 8px; }
.tx .link { font: inherit; font-size: 0.85rem; background: none; border: 0; padding: 6px 0; margin-right: 8px; color: var(--text-2); text-decoration: underline; cursor: pointer; min-height: 32px; }
.tx .link.danger { color: var(--danger); }
.badge { display: inline-block; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 0.75rem; color: var(--text-2); }

/* ---------- Diálogo ---------- */
dialog { width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; border: 1px solid var(--line); border-radius: 16px; padding: 20px; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog h2 { font-size: 1.2rem; }
.segmented { border: 0; padding: 0; margin: 14px 0 0; display: flex; gap: 8px; }
.segmented legend { font-weight: 600; font-size: 0.92rem; padding: 0; margin-bottom: 6px; }
.segmented label { flex: 1; margin: 0; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span { display: flex; align-items: center; justify-content: center; min-height: 46px; border: 1px solid var(--line); border-radius: 10px; font-weight: 600; cursor: pointer; }
.segmented input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.segmented input:focus-visible + span { outline: 3px solid var(--income); outline-offset: 2px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 30; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 6px 20px rgb(0 0 0 / 25%); }

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 1.5rem; }
.login-card form { margin-top: 16px; }
.login-card .btn { margin-top: 20px; }

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

/* ---------- Conferência, comprovantes, conta ---------- */
.pending-banner {
  font: inherit; font-weight: 700; text-align: left; cursor: pointer; width: 100%;
  min-height: 52px; padding: 12px 16px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn-ink); border: 1px solid color-mix(in srgb, var(--warn-ink) 30%, transparent);
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tag-warn { display: inline-block; padding: 0 8px; border-radius: 6px; font-size: 0.75rem; font-weight: 700; background: var(--warn-bg); color: var(--warn-ink); }
.tx .heard { color: var(--text-2); font-size: 0.85rem; font-style: italic; overflow-wrap: anywhere; }
.tx .link.ok { color: var(--accent); font-weight: 700; }
.files { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 12px; margin: 16px 0 0; }
.files legend { font-weight: 600; font-size: 0.92rem; padding: 0 4px; }
.file-list, .user-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.file-list li, .user-list li { display: flex; align-items: center; gap: 8px; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 6px 0; }
.file-list a { color: var(--text); overflow-wrap: anywhere; }
.file-list .link, .user-list .link { font: inherit; font-size: 0.85rem; background: none; border: 0; color: var(--text-2); text-decoration: underline; cursor: pointer; min-height: 32px; }
.file-list .link.danger, .user-list .link.danger { color: var(--danger); }
.file-pick { margin: 0; width: fit-content; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#account-dialog h3 { font-size: 1rem; margin-top: 20px; }
.user-list .who { min-width: 0; overflow-wrap: anywhere; }
.user-list .who small { display: block; color: var(--text-3); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 22px; height: 22px; min-height: 0; flex: none; margin: 0; }
