:root {
  color-scheme: light;
  --ink: #171717;
  --ink-2: #3a3a3a;
  --muted: #6b6b6b;
  --line: #e6e6e6;
  --line-strong: #cfcfcf;
  --paper: #ffffff;
  --ground: #f5f5f3;
  --wash: #f4f4f2;
  --black: #151515;
  --on-black: #fafafa;
  --on-black-muted: #a3a3a3;
  --accent: #ffd43b;
  --accent-hover: #f6c523;
  --accent-ink: #765500;
  --accent-soft: #fff5cc;
  --income: var(--ink);
  --expense: var(--ink-2);
  --income-on-black: var(--accent);
  --expense-on-black: var(--on-black);
  --radius-panel: 20px;
  --radius-control: 10px;
  --radius-shell: 24px;
  --shell-gap: 12px;
  --sidebar-width: 248px;
  --chrome-shadow: 0 12px 30px -20px #0005;
  --display: "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --body: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --gutter: clamp(16px, 2.7vw, 36px);
  --topbar-h: 66px;
  font-family: var(--body);
  color: var(--ink);
  background: var(--ground);
  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: calc(var(--topbar-h) + 52px); scrollbar-color: #b5b5b5 transparent; }
body { margin: 0; accent-color: var(--accent); background: var(--ground); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, dl { margin: 0; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -.02em; }
button, input, select { font: inherit; }
button, summary { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
::selection { color: var(--ink); background: var(--accent); }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 3px; }
.icon { flex: none; display: block; }
* { scrollbar-color: #b5b5b5 transparent; }

.container { width: min(1280px, calc(100% - var(--gutter) * 2)); margin-inline: auto; }

/* Barra superior e menu lateral */
body.sidebar-collapsed { --sidebar-width: 76px; }
.topbar {
  position: sticky;
  top: var(--shell-gap);
  z-index: 20;
  margin: var(--shell-gap) var(--shell-gap) 0;
  background: #fffffff0;
  backdrop-filter: blur(20px);
  border: 1px solid var(--line);
  border-radius: var(--radius-shell);
  box-shadow: var(--chrome-shadow);
}
.topbar-inner { width: auto; margin-inline: 0; padding-inline: clamp(12px, 2vw, 24px); display: flex; align-items: center; gap: 14px; min-height: var(--topbar-h); }
.menu-toggle { flex: none; }
.brand { font-size: 1rem; font-weight: 700; line-height: 1.2; }
.brand small, .sidebar-brand small { display: block; font-size: .78rem; font-weight: 400; }
.brand small { margin-top: 3px; color: var(--muted); }
.session-user-box { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 0; }
#session-user { max-width: 24ch; overflow: hidden; font-size: .88rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.user-avatar { display: grid; flex: none; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); }
.sidebar {
  position: fixed;
  z-index: 19;
  inset: var(--shell-gap) auto var(--shell-gap) var(--shell-gap);
  width: var(--sidebar-width);
  overflow: auto;
  padding: 12px;
  color: var(--on-black);
  background: radial-gradient(ellipse at top left, #2e2919 0, transparent 240px), var(--black);
  border: 1px solid #292929;
  border-radius: var(--radius-shell);
  box-shadow: var(--chrome-shadow);
}
.sidebar :focus-visible { outline-color: var(--accent); outline-offset: -3px; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; min-height: 66px; padding: 3px 4px 15px; border-bottom: 1px solid #ffffff26; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border: 1px solid #ffd43b66;
  border-radius: var(--radius-control);
  color: var(--accent);
  font-size: .75rem;
  font-weight: 700;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand strong { display: block; font-size: .96rem; line-height: 1.2; }
.sidebar-brand small { margin-top: 4px; color: var(--on-black-muted); }
.dashboard-menu { display: grid; gap: 5px; margin-top: 16px; }
.dashboard-menu a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  padding: 0 13px;
  color: #c6c6c6;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-size: .9rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.dashboard-menu a:hover { color: #fff; background: #ffffff10; }
.dashboard-menu a[href="#atendimentos"] { white-space: normal; }
.dashboard-menu a[aria-current="page"] { color: #fff; background: #ffd43b1c; border-color: #ffd43b30; }
.dashboard-menu a[aria-current="page"] .icon { color: var(--accent); }
.dashboard-menu a[aria-current="page"]::after {
  content: "";
  position: absolute;
  inset: 10px auto 10px 0;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.sidebar-collapsed .sidebar-brand { padding-inline: 0; justify-content: center; }
.sidebar-collapsed .sidebar-brand-text { display: none; }
.sidebar-collapsed .dashboard-menu a { justify-content: center; gap: 0; padding-inline: 0; font-size: 0; }

@media (min-width: 861px) {
  body:has(#session:not([hidden])) .topbar { margin-left: calc(var(--sidebar-width) + var(--shell-gap) * 2); }
  body:has(#session:not([hidden])) .dashboard-layout {
    width: auto;
    margin-left: calc(var(--sidebar-width) + var(--shell-gap) * 2 + var(--gutter));
    margin-right: calc(var(--shell-gap) + var(--gutter));
  }
}

/* Login */
.auth {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  width: min(1000px, calc(100% - var(--gutter) * 2));
  margin-block: clamp(18px, 4vh, 40px) 36px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  overflow: hidden;
}
.auth-intro { display: grid; place-items: center; min-height: 500px; padding: clamp(24px, 5vw, 56px); background: var(--black); }
.book-cover {
  position: relative;
  display: grid;
  align-content: center;
  gap: 12px;
  isolation: isolate;
  width: min(100%, 340px);
  min-height: 330px;
  padding: 40px 28px;
  color: var(--on-black);
  text-align: center;
  background: #202020;
  border-radius: 6px 12px 12px 6px;
}
.book-cover::before,
.book-cover::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 20px;
  border: 1px solid #ffd43b80;
  border-radius: 3px;
}
.book-cover::after { inset: 25px; border-color: #2e2e2e; }
.book-cover h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); font-weight: 600; line-height: 1.04; letter-spacing: -.03em; }
.book-cover p { color: var(--accent); font-size: .9rem; }
.auth-body { align-self: center; padding: clamp(22px, 4vh, 40px) clamp(22px, 4.5vw, 60px); }
.auth-body h2 { font-size: clamp(1.7rem, 3vw, 2.4rem); line-height: 1.1; }
.auth-body form { display: grid; gap: 6px; }
.auth-body label { margin-top: 9px; font-size: .88rem; font-weight: 600; }
.auth-body form > p { color: var(--muted); margin-block: 2px 7px; line-height: 1.45; }
.auth-body form > button { margin-top: 12px; }
.auth-body input { width: 100%; }
.auth-help { font-size: .83rem; }
.login-challenge { min-width: 0; margin-top: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.challenge-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.auth-body .challenge-heading label { margin: 0; }
.challenge-heading button { flex: none; padding: 7px 10px; font-size: .8rem; }
.challenge-picture { position: relative; overflow: hidden; width: 100%; border-radius: 8px; background: var(--wash); user-select: none; }
#challenge-background { display: block; width: 100%; height: 100%; }
#challenge-piece { position: absolute; object-fit: fill; pointer-events: none; filter: drop-shadow(0 1px 2px #0008); }
.auth-body #challenge-position { display: block; margin: 12px 0 6px; padding: 0; min-height: 32px; border: 0; background: transparent; cursor: ew-resize; accent-color: var(--accent-ink); }
#challenge-position:disabled { cursor: default; }
.login-challenge .auth-help { margin-top: 5px; color: var(--muted); line-height: 1.45; }
.login-challenge .auth-help.error { color: #a62525; }


/* Dashboard */
#dashboard { padding-block: clamp(24px, 3vw, 40px) 64px; }
.dashboard-layout { display: block; width: min(1280px, calc(100% - var(--gutter) * 2)); }
.dashboard-main { min-width: 0; }
.page-heading, .period-bar, .ledger-heading, .dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.page-heading { margin-bottom: 24px; }
.page-heading h1 { font-size: clamp(2rem, 3.3vw, 3.1rem); font-weight: 700; line-height: 1.04; letter-spacing: -.045em; }
.page-heading p { margin-top: 8px; color: var(--muted); }
.page-heading p:empty { margin: 0; }
#period-title::first-letter { text-transform: uppercase; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.primary, .secondary, input, select {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  padding: 9px 14px;
  color: var(--ink);
  background: var(--paper);
}
input:hover, select:hover { border-color: #8a8a8a; }
.primary, .secondary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; text-decoration: none; transition: background .15s ease-out, border-color .15s ease-out; }
.primary { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.primary:hover:enabled { background: var(--accent-hover); border-color: var(--accent-hover); }
.secondary { background: var(--paper); border-color: var(--line-strong); }
.secondary:hover:enabled, a.secondary:hover { background: var(--wash); }
.arrow { width: 44px; padding: 0; }

.period-bar { padding: 11px clamp(12px, 2vw, 18px); border: 1px solid var(--line); border-radius: var(--radius-panel); background: #ffffffb8; margin-bottom: 12px; }
.period-control, .period-nav { display: flex; align-items: center; gap: 8px; }
.period-control > label { margin-right: 8px; font-weight: 600; font-size: .88rem; }
#month { width: 196px; }
.status-badge {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid #ead995;
  color: var(--accent-ink);
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-badge.closed { background: var(--black); border-color: var(--black); color: #fff; }
.status-badge::before { content: ""; display: inline-block; width: .45em; height: .45em; margin-right: .5em; vertical-align: .12em; background: currentColor; border-radius: 50%; }

/* Visão geral */
.overview-heading { padding: 16px 0 20px; }
.overview-heading h2 { font-size: clamp(1.4rem, 2.6vw, 1.8rem); line-height: 1.15; }
.overview-heading p { margin-top: 6px; color: var(--muted); line-height: 1.5; }
.overview-types { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.type-card { min-width: 0; padding: clamp(16px, 2.5vw, 24px); border: 1px solid var(--line); border-radius: var(--radius-panel); background: var(--paper); }
.type-card h3 { font-size: clamp(1.1rem, 1.8vw, 1.3rem); line-height: 1.2; }
.type-card p { margin-top: 4px; color: var(--muted); font-size: .86rem; }
.type-card dl { margin-top: 16px; }
.type-card dl > div { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; border-top: 1px solid var(--line); padding-block: 11px; }
.type-card dt { align-self: center; color: var(--muted); font-size: .85rem; }
.type-card dd { margin: 0; overflow-wrap: anywhere; font-size: clamp(1rem, 1.8vw, 1.35rem); font-weight: 600; line-height: 1.15; letter-spacing: -.02em; }

/* Gráficos */
.overview-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.overview-charts:empty { display: none; }
.overview-charts > * { min-width: 0; }
.overview-charts > .kpi-row,
.overview-charts > .chart-wide,
.overview-charts > .chart-panel:first-child,
.overview-charts > .chart-panel:last-child:nth-child(even) { grid-column: 1 / -1; }
.chart-panel { min-width: 0; padding: clamp(16px, 2.6vw, 28px); background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-panel); margin-bottom: 0; }
#account-chart { margin-bottom: clamp(20px, 3vw, 32px); }
.chart-panel svg { display: block; width: 100%; height: auto; max-width: 100%; overflow: visible; }
.chart-title { font-size: 1.05rem; line-height: 1.25; }
.chart-sub { margin-top: 4px; margin-bottom: 18px; color: var(--muted); font-size: .86rem; line-height: 1.45; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 16px 0 0; padding: 0; list-style: none; font-size: .86rem; color: var(--ink-2); }
.chart-legend > * { display: inline-flex; align-items: center; gap: 8px; }
.chart-legend .swatch, .swatch { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 3px; }
.chart-empty { padding: 28px 0; color: var(--muted); text-align: center; }
.kpi-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-panel); }
.kpi { min-width: 0; padding: clamp(16px, 2.6vw, 28px); }
.kpi + .kpi { border-left: 1px solid var(--line); }
.kpi-label { color: var(--muted); font-size: .86rem; }
.kpi-value { display: block; margin-top: 8px; font-size: clamp(1.4rem, 3vw, 2.4rem); font-weight: 600; line-height: 1.1; letter-spacing: -.03em; overflow-wrap: anywhere; }
.kpi.is-dark { color: var(--on-black); background: var(--black); border-radius: var(--radius-panel) 0 0 var(--radius-panel); }
.kpi.is-dark .kpi-label { color: var(--on-black-muted); }
.kpi.is-dark .kpi-value, .total strong { color: var(--accent); }
.chart-tooltip { position: absolute; z-index: 5; pointer-events: none; padding: 8px 10px; color: #fff; background: var(--black); border-radius: 8px; font-size: .8rem; line-height: 1.4; white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) {
  .chart-panel svg .chart-anim { animation: chart-in .35s ease-out both; }
}
@keyframes chart-in { from { opacity: 0; } to { opacity: 1; } }

/* Saldos */
.balances {
  display: grid;
  grid-template-columns: minmax(260px, .85fr) minmax(0, 1.35fr);
  margin-bottom: clamp(20px, 3vw, 32px);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  overflow: hidden;
  background: var(--paper);
}
.balance { min-width: 0; padding: clamp(18px, 2.6vw, 32px); }
.balance:not(.total) { display: grid; grid-template-columns: minmax(0, 1.06fr) minmax(0, 1fr); column-gap: clamp(12px, 2.5vw, 36px); align-content: center; }
.balance + .balance + .balance { border-top: 1px solid var(--line); }
.balance:not(.total) h2 { grid-column: 1; align-self: end; }
.balance:not(.total) strong { grid-column: 1; align-self: start; }
.balance:not(.total) dl { grid-column: 2; grid-row: 1 / 3; align-self: center; }
.balance h2 { font-size: .92rem; font-weight: 600; letter-spacing: 0; }
.balance strong { display: block; margin-top: 8px; font-size: clamp(1.2rem, 2.1vw, 1.9rem); font-weight: 600; line-height: 1.1; letter-spacing: -.03em; overflow-wrap: anywhere; }
.balance dl div { display: flex; justify-content: space-between; gap: 4px 8px; padding-block: 8px; font-size: .85rem; }
.balance dl div + div { border-top: 1px solid var(--line); }
.balance dt { color: var(--muted); }
.balance dd { margin: 0; font-weight: 600; text-align: end; overflow-wrap: anywhere; }
.total { grid-row: span 2; color: var(--on-black); background: var(--black); }
.total h2 { color: var(--on-black-muted); }
.total strong { font-size: clamp(1.9rem, 3.6vw, 3.2rem); letter-spacing: -.035em; }
.total dl { margin-top: clamp(16px, 2.75vw, 30px); padding-top: 8px; border-top: 1px solid #333; }
.total dl div + div { border-color: #2a2a2a; }
.total dt { color: var(--on-black-muted); }

/* Tabelas */
.ledger { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-panel); overflow: hidden; }
.ledger-heading { padding: 20px clamp(14px, 2.6vw, 28px); }
.ledger-heading h2, .dialog-heading h2 { font-size: clamp(1.25rem, 2.4vw, 1.6rem); line-height: 1.15; }
.ledger-heading p { margin-top: 5px; color: var(--muted); font-size: .86rem; }
.filter { display: flex; align-items: center; gap: 8px; font-size: .84rem; font-weight: 600; }
.ledger-filters { display: flex; flex-wrap: wrap; gap: 8px 16px; min-width: 0; }
.ledger-filters select { min-width: 0; max-width: 185px; }
.description-filter input { width: min(13rem, 100%); min-width: 0; }
.table-scroll { overflow: auto; }
.table-scroll:focus-visible { outline-offset: -3px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 14px clamp(10px, 1.75vw, 22px); text-align: start; border-top: 1px solid var(--line); }
th { color: var(--ink-2); background: var(--wash); font-size: .8rem; font-weight: 600; white-space: nowrap; }
td { font-size: .92rem; }
tbody tr:hover { background: var(--ground); }
#ledger-table td:first-child, #ledger-table td.amount { white-space: nowrap; }
#ledger-table th:last-child, #ledger-table td:last-child, th.amount, td.amount { text-align: end; }
td.amount { font-weight: 600; }
#ledger-table td:nth-child(2) { width: 100%; min-width: 150px; overflow-wrap: anywhere; }
#ledger-table td:nth-child(5) { min-width: 100px; max-width: 250px; overflow-wrap: normal; word-break: normal; }
.ledger-ficha { display: block; width: max-content; margin: 5px 0 0; }
.attendance-deacon-action { display: flex; margin-top: 7px; white-space: nowrap; }
.edit-entry { min-height: 44px; }
.emergency-summary, .emergency-queue { margin-top: 20px; }
.emergency-summary tbody th { color: var(--ink); font-size: .92rem; font-weight: 600; letter-spacing: 0; text-transform: none; background: transparent; }
.emergency-summary td.amount { white-space: nowrap; }
.deacon-share { min-width: 150px; white-space: nowrap; }
.confidential-text { color: var(--muted); font-style: italic; }
.transfer-tag { display: inline-block; margin-left: 8px; color: var(--muted); font-size: .76rem; }
.emergency-queue a { text-decoration: none; }
#entry-deacon-help, #entry-attendance-help { margin-top: 0; color: var(--muted); font-size: .86rem; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.message.error { padding: 10px 12px; border-left: 3px solid var(--accent-ink); border-radius: var(--radius-control); color: var(--accent-ink); background: var(--accent-soft); }
.total .income, .on-black .income { color: var(--income-on-black); }
.total .expense, .on-black .expense { color: var(--expense-on-black); }
.empty { border-top: 1px solid var(--line); padding: 28px clamp(14px, 2.6vw, 28px); color: var(--muted); }
.message { margin-block: 12px; line-height: 1.45; }
.control-message { margin: 0 clamp(14px, 2.6vw, 28px) 14px; }
.control-ledger td { vertical-align: middle; }
.control-ledger td.amount { white-space: nowrap; }
.control-ledger td:has(.status-badge) { white-space: nowrap; }
.control-ledger .status-badge { margin: 0; }
.attendance-type { display: inline-block; padding: 3px 8px; border: 1px solid transparent; border-radius: var(--radius-control); font-size: .84rem; font-weight: 600; }
.attendance-type.confidential { border-color: var(--line-strong); background: var(--wash); color: var(--ink-2); }
.attendance-type.emergency { background: var(--accent-soft); color: var(--accent-ink); }
#atendimentos td:nth-child(3), #envelope-rows td:nth-child(3), #unregistered-envelope-rows td:nth-child(2), #unlinked-return-rows td:nth-child(2) { min-width: 9rem; overflow-wrap: anywhere; }
.workflow-row-actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 8rem; }
.envelope-heading { flex-direction: column; align-items: stretch; gap: 14px; }
.envelope-heading-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
#unregistered-envelopes, #unlinked-returns { margin-top: 20px; }
.dashboard-main:has(#usuarios:not([hidden])) > #message { display: none; }
.users-heading { flex-wrap: wrap; }
#users-rows td:first-child { width: 35%; overflow-wrap: anywhere; }
#users-rows .user-inactive { color: var(--ink-2); background: var(--wash); border-color: var(--line-strong); }
#user-dialog-description { overflow-wrap: anywhere; }
dialog .user-field-help { margin-top: 5px; color: var(--muted); font-size: .86rem; }

/* Planilha */
.archive { margin-top: 20px; }
.archive summary { padding: 16px clamp(14px, 2.6vw, 28px); min-height: 52px; font: 600 1.05rem var(--display); letter-spacing: -.01em; outline-offset: -4px; }
.archive summary::marker { color: var(--ink); }
.archive summary:hover { background: var(--ground); }
.archive-controls { padding: 0 clamp(14px, 2.6vw, 28px) 16px; }
.archive-controls > p:first-child { margin-bottom: 12px; color: var(--muted); line-height: 1.45; }
.archive-controls .message { margin-bottom: 0; }
.archive select { max-width: calc(100% - 3rem); }
.archive-scroll { max-height: 30rem; }
.archive table { width: max-content; min-width: 100%; }
.archive caption { padding: 12px 20px; text-align: start; font-weight: 600; background: var(--wash); }
.archive td { padding: 8px 12px; white-space: pre-wrap; vertical-align: top; }
.archive td + td { border-left: 1px solid var(--line); }
.archive tr:nth-child(even) { background: var(--ground); }

/* Dialogs */
dialog {
  color: var(--ink);
  background: var(--paper);
  width: min(500px, calc(100% - 2rem));
  max-height: calc(100% - 2rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 24px;
  box-shadow: 0 24px 64px #0a0a0a40;
}
dialog::backdrop { background: #0a0a0acc; }
dialog p { margin-top: 12px; line-height: 1.45; }
dialog footer { margin-top: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.form-grid label { display: grid; gap: 5px; min-width: 0; font-size: .86rem; font-weight: 600; }
.form-grid input, .form-grid select { width: 100%; min-width: 0; }
.wide { grid-column: 1 / -1; }

/* Relatórios */
.reports { margin-top: 4px; }
.report-filters { padding: 20px clamp(14px, 2.6vw, 28px); overflow: visible; }
.report-filters-title { margin-bottom: 14px; font-size: 1.05rem; line-height: 1.25; }
.report-fields { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.report-shortcuts { display: flex; flex-wrap: wrap; gap: 8px; }
.report-fields select { max-width: 200px; }
.report-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.report-filters .message { margin-bottom: 0; }
.report-output { display: grid; gap: 20px; margin-top: 20px; }
.report-header { padding: 4px 0; }
.report-header h2 { font-size: clamp(1.4rem, 2.6vw, 1.8rem); line-height: 1.15; }
.report-header p { margin-top: 6px; color: var(--muted); line-height: 1.45; }
.report-header .report-org { margin: 0 0 6px; color: var(--ink); font-size: .78rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.report-block h3 { font-size: 1.05rem; line-height: 1.25; }
.report-block td.amount { white-space: nowrap; }
.report-block td:first-child { white-space: nowrap; }
.report-block tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); }
.report-block .table-scroll + .table-scroll { margin-top: 0; }
.report-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

@media (max-width: 1050px) {
  .overview-charts { grid-template-columns: minmax(0, 1fr); }
  .report-charts { grid-template-columns: minmax(0, 1fr); }
  .ledger-heading:has(.ledger-filters) { flex-direction: column; align-items: stretch; }
  .balance:not(.total) { column-gap: 10px; }
  .balance dl div { flex-wrap: wrap; }
}

@media (max-width: 860px) {
  .sidebar { top: calc(var(--topbar-h) + var(--shell-gap) * 2 + 2px); bottom: auto; max-height: calc(100dvh - var(--topbar-h) - var(--shell-gap) * 3 - 2px); }
}

@media (max-width: 740px) {
  .auth { grid-template-columns: 1fr; }
  .auth-intro { min-height: auto; padding: 14px; }
  .book-cover { min-height: 114px; width: min(100%, 340px); padding-block: 20px; gap: 6px; }
  .book-cover::before { inset: 12px; }
  .book-cover::after { inset: 17px; }
  .balances { grid-template-columns: minmax(0, 1fr); }
  .total { grid-row: auto; }
  .balance dl div { flex-wrap: nowrap; }
  .kpi-row { grid-template-columns: minmax(0, 1fr); }
  .kpi + .kpi { border-left: 0; border-top: 1px solid var(--line); }
  .kpi.is-dark { border-radius: var(--radius-panel) var(--radius-panel) 0 0; }
}

@media (max-width: 520px) {
  .page-heading { flex-direction: column; align-items: flex-start; }
  .page-heading .actions { justify-content: flex-start; }
  .topbar-inner { gap: 10px; }
  #session-user { display: none; }
  .period-bar { flex-wrap: wrap; gap: 8px; }
  .period-control { flex-direction: column; align-items: flex-start; gap: 6px; }
  .status-badge { align-self: end; margin-bottom: 8px; }
  #month { width: clamp(150px, 46vw, 190px); }
  .balance:not(.total) { grid-template-columns: minmax(0, .8fr) minmax(0, 1fr); }
  .balance dl div { flex-wrap: wrap; }
  .ledger-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ledger-filters .filter { display: grid; gap: 4px; min-width: 0; }
  .ledger-filters select { width: 100%; max-width: none; }
  .description-filter { grid-column: 1 / -1; }
  .description-filter input { width: 100%; }
  .report-actions { margin-left: 0; }
  .emergency-summary .ledger-heading, .emergency-queue .ledger-heading { flex-wrap: wrap; }
  .overview-types { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 385px) {
  .user-avatar { display: none; }
  .period-bar { flex-direction: column; align-items: flex-start; }
  .status-badge { align-self: flex-start; margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .primary, .secondary { transition: none; }
}

/* Impressão / PDF */
@media print {
  @page { size: A4; margin: 15mm; }
  :root { --ground: #fff; --paper: #fff; --ink: #000; }
  html, body { color: #000; background: #fff !important; }
  .topbar, .sidebar, .period-bar, #message, .report-filters, .chart-tooltip, button, .edit-entry { display: none !important; }
  .dashboard-main:has(#relatorios:not([hidden])) .page-heading { display: none; }
  .page-heading .actions { display: none !important; }
  .container { width: 100%; margin: 0; }
  body:has(#session:not([hidden])) .dashboard-layout { width: 100%; margin: 0; }
  #dashboard { padding: 0; }
  .report-output { margin-top: 0; gap: 14px; }
  .ledger, .chart-panel, .kpi-row, .balances { border-color: #bdbdbd; }
  .table-scroll { overflow: visible !important; max-height: none !important; }
  table { font-size: 9.5pt; }
  thead { display: table-header-group; }
  tfoot { display: table-row-group; }
  th, td { padding: 6px 8px; }
  tr, .chart-panel, .report-header, .kpi-row { break-inside: avoid; page-break-inside: avoid; }
  h2, h3, .ledger-heading { break-after: avoid; page-break-after: avoid; }
  tbody tr:hover { background: none; }
  svg, .swatch, .chart-panel, .deacon-share span, .kpi.is-dark, .total, .income, .expense {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .chart-panel svg .chart-anim { animation: none !important; }
  .report-charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  a { color: inherit; text-decoration: none; }
}
