/* Livro-caixa: papel quente, tinta escura, verde de escritório como único acento. */
:root {
  color-scheme: light;
  --page: #f3f1ea;
  --surface: #fcfcfb;
  --ink: #17170f;
  --ink-2: #52514e;
  --muted: #6f6d67;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #14594c;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe5;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --in: #006300;
  --warn-bg: #fff4d6;
  --warn-ink: #5c4300;
  --err-bg: #fbe5e3;
  --err-ink: #8c1f1f;
  --ok-bg: #e0f1e4;
  --ok-ink: #0d4d1c;
  --shadow: 0 1px 2px rgb(40 35 15 / 6%), 0 8px 24px -16px rgb(40 35 15 / 20%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f100e;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a9890;
    --line: #2c2c2a;
    --axis: #383835;
    --accent: #5fc4ad;
    --accent-ink: #06231d;
    --accent-soft: #17332c;
    --series-1: #3987e5;
    --series-2: #d95926;
    --in: #4cc765;
    --warn-bg: #3a2f10;
    --warn-ink: #f6dd9c;
    --err-bg: #3c1a1a;
    --err-ink: #f5b8b5;
    --ok-bg: #16321d;
    --ok-ink: #aee3ba;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f100e;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #9a9890;
  --line: #2c2c2a;
  --axis: #383835;
  --accent: #5fc4ad;
  --accent-ink: #06231d;
  --accent-soft: #17332c;
  --series-1: #3987e5;
  --series-2: #d95926;
  --in: #4cc765;
  --warn-bg: #3a2f10;
  --warn-ink: #f6dd9c;
  --err-bg: #3c1a1a;
  --err-ink: #f5b8b5;
  --ok-bg: #16321d;
  --ok-ink: #aee3ba;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 15px/1.45 "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, p { margin: 0; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.lead { margin-bottom: 16px; max-width: 70ch; }
.nowrap { white-space: nowrap; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 24px;
  padding: 12px max(16px, calc((100vw - 1180px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; color: var(--ink); text-decoration: none; font-size: 16px;
}
.brand-mark {
  display: inline-block; width: 14px; height: 18px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) 0 3px, transparent 3px),
    repeating-linear-gradient(0deg, var(--accent-soft) 0 3px, var(--surface) 3px 6px);
  border: 1px solid var(--accent);
}
.top nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; }
.top nav a {
  padding: 6px 10px; border-radius: 6px; color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.top nav a:hover { background: var(--page); }
.top nav a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 600; text-align: center;
}
.logout { margin-left: auto; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.card > .muted { margin-bottom: 12px; }
.empty { text-align: center; padding: 40px 18px; }
.empty h2 { font-size: 18px; margin-bottom: 6px; }
.empty .button { margin-top: 14px; }

.columns { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
.columns.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack-cards > .card:last-child { margin-bottom: 0; }

/* Botões e campos */
button, .button {
  display: inline-block; font: inherit; font-weight: 500; cursor: pointer;
  padding: 7px 12px; border-radius: 6px; line-height: 1.3; text-decoration: none;
  border: 1px solid var(--axis); background: var(--surface); color: var(--ink);
}
button:hover, .button:hover { background: var(--page); }
.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.primary:hover, button.primary:hover { background: var(--accent); filter: brightness(1.12); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-weight: 400; }
input, select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 6px; padding: 7px 9px; min-height: 36px; width: 100%;
}
input[type="file"] { padding: 6px; }
input[type="checkbox"] { width: auto; min-height: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); }
label > input, label > select { margin-top: 3px; font-size: 15px; font-weight: 400; }
.stack { display: grid; gap: 12px; margin-top: 12px; }
.stack > button { justify-self: start; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.filter-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.filter-row label { flex: 0 1 170px; }
.filter-row label.grow { flex: 1 1 220px; }
.filter-row .meta { flex-basis: 100%; font-size: 13px; }
.add-entry summary, .table-view summary { cursor: pointer; color: var(--ink-2); font-weight: 500; }
.add-entry form { margin-top: 12px; }
.table-view { margin-top: 8px; }
.table-view table { margin-top: 8px; }

/* Avisos */
.notice {
  display: flex; gap: 8px; padding: 9px 12px; border-radius: 8px; margin-bottom: 12px;
  background: var(--page); color: var(--ink-2); text-decoration: none;
}
.notice > span:first-child { font-weight: 700; }
.notice.ok { background: var(--ok-bg); color: var(--ok-ink); }
.notice.error { background: var(--err-bg); color: var(--err-ink); }
.notice.warn { background: var(--warn-bg); color: var(--warn-ink); }
.review-link:hover strong { text-decoration: underline; }
.tag {
  display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 12px; font-weight: 500;
  background: var(--page); color: var(--ink-2); border: 1px solid var(--line);
}
.tag.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.tag.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.balance-line { font-size: 14px; }
.facts dt { font-size: 13px; font-weight: 500; color: var(--ink-2); }

/* Painel */
.filters { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 6px;
  border: 1px solid var(--axis); background: var(--surface); color: var(--ink);
  text-decoration: none; font-size: 20px; line-height: 1;
}
.icon-btn:hover { background: var(--page); }
.segmented { display: inline-flex; border: 1px solid var(--axis); border-radius: 7px; overflow: hidden; background: var(--surface); }
.segmented a { padding: 6px 14px; color: var(--ink-2); text-decoration: none; font-weight: 500; border-left: 1px solid var(--line); }
.segmented a:first-child { border-left: 0; }
.segmented a[aria-current] { background: var(--accent); color: var(--accent-ink); }

.hero {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 24px;
  padding: 24px; margin-bottom: 16px; border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line); border-top: 3px solid var(--accent); box-shadow: var(--shadow);
}
.label, dt { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.hero-value { font-size: clamp(36px, 7vw, 56px); font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; margin: 2px 0 6px; }
.delta { display: block; font-size: 13px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 0; align-self: end; }
.tiles dd { margin: 2px 0 4px; font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }

.chart { width: 100%; height: 260px; }
.chart svg { display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .tick.strong { fill: var(--ink); font-weight: 600; }
.chart .s1, .swatch.s1 { fill: var(--series-1); background: var(--series-1); }
.chart .s2, .swatch.s2 { fill: var(--series-2); background: var(--series-2); }
.chart .month { opacity: 0.5; transition: opacity 0.15s; }
.chart .month.current { opacity: 1; }
.chart .hit { fill: transparent; cursor: pointer; outline-offset: -2px; }
.chart .month:has(+ text + .hit:hover), .chart .month:has(+ text + .hit:focus) { opacity: 1; }
.legend { display: flex; gap: 14px; list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }

.tooltip {
  position: fixed; top: 0; left: 0; z-index: 10; pointer-events: none; min-width: 160px; max-width: 280px;
  padding: 8px 10px; border-radius: 8px; font-size: 13px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--axis);
  box-shadow: 0 6px 20px rgb(0 0 0 / 18%);
}
.tip-title { font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.tip-row strong { margin-left: auto; padding-left: 12px; font-weight: 600; }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bar-link {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px;
  color: inherit; text-decoration: none; border-radius: 4px;
}
.bar-label { font-weight: 500; }
.bar-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 8px; display: block; }
.bar-fill { display: block; height: 100%; min-width: 2px; background: var(--series-2); border-radius: 0 4px 4px 0; }
.bar-delta { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }

/* Tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child > td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.plain td { padding: 7px 0; }
table.plain td.num { padding-left: 12px; }
table.plain + form { margin-top: 16px; }
.ledger .desc { min-width: 240px; overflow-wrap: anywhere; }
.ledger select { min-width: 170px; }
.ledger tr.dimmed td { opacity: 0.6; }
.amount.in { color: var(--in); font-weight: 500; }
.amount.out { color: var(--ink); }
.cat-form { display: flex; align-items: center; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-weight: 400; }
.inline { display: inline; margin-left: 6px; font-size: 13px; }
.count { margin-bottom: 6px; font-size: 13px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 16px; }

.dup-list { list-style: none; margin: 0; padding: 0; }
.dup-list li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.row-actions { display: flex; gap: 8px; }
.connection { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.connection .notice { margin: 6px 0 0; }
.grow-text { flex: 1 1 240px; }

/* Futuro */
.forecast-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 12px; }
.forecast-tiles dd { font-size: 20px; }
.premises { margin: 8px 0; }
.premises summary { cursor: pointer; color: var(--ink-2); font-weight: 500; }
.premises ul { margin: 8px 0; padding-left: 18px; color: var(--ink-2); font-size: 14px; display: grid; gap: 4px; }
.premises p { font-size: 14px; }
.small { font-size: 13px; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .zero { stroke: var(--ink-2); stroke-width: 1; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .direct { fill: var(--ink); font-size: 12px; font-weight: 600; }
@media (max-width: 520px) { .forecast-tiles { grid-template-columns: minmax(0, 1fr); } }

/* DRE: a primeira coluna fica fixa ao rolar os meses */
.dre { font-size: 14px; }
.dre th, .dre td { white-space: nowrap; }
.dre tbody th { font-weight: 400; text-align: left; font-size: 14px; color: var(--ink); border-bottom: 1px solid var(--line); }
.dre th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--line); }
.dre tbody th a { color: inherit; text-decoration: none; }
.dre tbody th a:hover { text-decoration: underline; }
.dre .section-row th { font-weight: 600; font-size: 12px; color: var(--muted); padding-top: 14px; }
.dre .subtotal th, .dre .subtotal td { font-weight: 600; }
.dre .total-col { font-weight: 600; box-shadow: inset 1px 0 0 var(--line); }
.dre .result-row th, .dre .result-row td { font-weight: 700; border-top: 2px solid var(--axis); border-bottom: 0; }

/* Modificação em massa e iguais */
.pick { width: 36px; padding-right: 0; }
.row-link { display: inline-block; margin-left: 6px; font-size: 13px; }
.bulk-bar {
  position: sticky; bottom: 12px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin: 12px 0; padding: 10px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--accent); box-shadow: 0 6px 20px rgb(0 0 0 / 18%);
}
.bulk-bar[hidden] { display: none; }
.bulk-bar select { flex: 1 1 200px; width: auto; }
.bulk-count { white-space: nowrap; }
.group-list { list-style: none; margin: 0; padding: 0; }
.group-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(230px, 300px); align-items: center;
  gap: 8px 16px; padding: 10px 0; border-top: 1px solid var(--line);
}
.group-info p { overflow-wrap: anywhere; }
.group-info .muted { font-size: 13px; }
.group-total { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.group-form { display: flex; gap: 8px; }
.group-form select { flex: 1; min-width: 0; }
.facts { margin: 0 0 12px; display: grid; gap: 8px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.stack .check { font-size: 14px; }

.login { max-width: 360px; margin: 12vh auto 0; }
.login h1 { display: flex; align-items: center; gap: 8px; }

/* Entrada escalonada do painel */
@media (prefers-reduced-motion: no-preference) {
  .rise { animation: rise 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .columns .rise, .card.rise { animation-delay: 0.08s; }
  .columns .rise { animation-delay: 0.16s; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}

@media (max-width: 820px) {
  .columns, .columns.even, .hero { grid-template-columns: minmax(0, 1fr); }
  .columns > .card, .stack-cards > .card:last-child { margin-bottom: 16px; }
  .columns { gap: 0; }
  .hero { padding: 18px; gap: 18px; }
  .filter-row label { flex: 1 1 140px; }
  .top nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .top nav a { white-space: nowrap; }

  /* Tabela de lançamentos vira cartões empilhados */
  .ledger thead { display: none; }
  .ledger, .ledger tbody, .ledger tr, .ledger td { display: block; width: 100%; }
  .ledger tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .ledger tr:last-child { border-bottom: 0; }
  .ledger td { padding: 2px 0; border: 0; text-align: left; }
  .ledger .desc { min-width: 0; font-weight: 500; }
  .ledger td.pick { width: auto; padding-bottom: 4px; }
  .group-list li { grid-template-columns: minmax(0, 1fr) auto; }
  .group-form { grid-column: 1 / -1; }
  .card:not(.flush) .ledger tr { padding-inline: 0; }
  .ledger select { flex: 1; min-width: 0; }
}
