:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #18202a;
  --muted: #657080;
  --line: #d9e0e8;
  --accent: #17695d;
  --accent-dark: #0f4b43;
  /* Cabeçalhos de tabela: texto mais escuro que --muted para passar WCAG AA
     com folga (8,3:1 sobre --th-bg; o --muted dava 4,55:1, no limite). */
  --th-bg: #f1f4f7;
  --th-text: #3f4957;
}

:root[data-theme="dark"] {
  --bg: #10151c;
  --surface: #1a212b;
  --text: #e7ecf2;
  --muted: #93a1b1;
  --line: #2e3947;
  --accent: #2fbfa8;
  --accent-dark: #5ddcc8;
  --th-bg: #212a35;
  --th-text: #c5cfdb; /* 9,2:1 sobre --th-bg */
}

* { box-sizing: border-box; }

.skip-link {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 100;
  transform: translateY(-140%);
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 650;
}

.skip-link:focus {
  transform: translateY(0);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  flex: 1;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

nav a:hover,
nav a.active { color: var(--text); }

nav a.active { font-weight: 650; }

/* Sublinhado subtil no item de topo ativo (além do peso da fonte), para
   orientação mais clara. Só os itens diretos da barra (não os do dropdown);
   o border-bottom transparente reserva o espaço para não haver salto. */
nav > a {
  padding-bottom: 3px;
  border-bottom: 2px solid transparent;
}

nav > a.active,
.nav-toggle.active { border-bottom-color: var(--accent); }

.nav-dropdown {
  position: relative;
}

.nav-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0 0 3px;
  font: inherit;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.nav-toggle:hover,
.nav-toggle.active { color: var(--text); }

.nav-toggle.active { font-weight: 650; }

.nav-caret {
  font-size: 10px;
  color: var(--muted);
}

.nav-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(24, 32, 42, 0.14);
}

.nav-panel[hidden] {
  display: none;
}

.nav-panel a {
  padding: 8px 10px;
  border-radius: 6px;
}

.nav-panel a:hover { background: var(--bg); }

.nav-panel a.active { color: var(--accent); }

.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 44px;
}

h1 {
  margin: 0 0 20px;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 650;
  padding: 9px 14px;
  cursor: pointer;
}

button:hover { background: var(--accent-dark); }

button:disabled { cursor: wait; opacity: 0.75; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-spinner {
  display: none;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  border-radius: 50%;
  vertical-align: -1px;
  animation: btn-spin 0.6s linear infinite;
}

button:disabled .btn-spinner { display: inline-block; }

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* Acessibilidade: respeita a preferência de movimento reduzido. Desativa
   transitions/animations globais; o spinner de loading dos botões é feedback
   funcional durante o envio e mantém-se a girar. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .btn-spinner {
    animation-duration: 0.6s !important;
    animation-iteration-count: infinite !important;
  }
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  /* Sem estas cores os campos ficavam brancos no tema escuro (valor mín./máx.,
     pesquisa) — herdam agora os tokens de superfície/texto. */
  background: var(--surface);
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

textarea {
  resize: vertical;
}

.login-panel {
  max-width: 380px;
  margin: 12vh auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}

.form-stack {
  display: grid;
  gap: 16px;
}

.form-stack label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.import-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.import-form {
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.import-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--text);
}

.check-row input {
  width: auto;
}

.import-types {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.import-types span {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--bg);
  font-size: 12px;
}

.import-summary {
  display: grid;
  gap: 16px;
}

.import-metrics {
  margin-bottom: 0;
}

.import-reconcile {
  max-width: 420px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.metric > span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric strong {
  font-size: 26px;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.metric-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.metric-link:hover {
  border-color: var(--accent);
  box-shadow: 0 1px 4px rgba(15, 75, 67, 0.08);
}

.metric-alert {
  border-color: #f0c0ba;
  background: #fdf4f2;
}

.metric-alert strong {
  color: #b42318;
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.grid-two > div { min-width: 0; }

.workday-overview {
  margin-bottom: 26px;
}

.workday-intro {
  max-width: 760px;
  margin: -12px 0 18px;
  line-height: 1.5;
}

.workday-status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 18px;
}

.workday-status-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-decoration: none;
}

.workday-status-item:hover {
  border-color: var(--accent);
  color: var(--text);
}

.workday-status-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workday-status-item strong {
  flex: none;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.workday-status-item.has-alert strong { color: #b42318; }

.workday-next-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.workday-next-section h3 { margin-top: 0; }

.section-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-toolbar h2 { margin-bottom: 0; }

.dashboard-filters {
  margin-bottom: 0;
  align-items: end;
}

.dashboard-filters .ff-year { width: 110px; }

.mode-switch {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.mode-switch a {
  min-width: 82px;
  padding: 9px 12px;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  font-weight: 650;
}

.mode-switch a + a { border-left: 1px solid var(--line); }

.mode-switch a.active {
  color: white;
  background: var(--accent);
}

.finance-evolution {
  margin: 28px 0;
}

.finance-evolution > .dashboard-filters { justify-content: flex-start; }
.annual-table-scroll { max-width: 100%; overflow-x: auto; }
.annual-table-scroll .annual-values { min-width: 680px; margin-bottom: 0; }

/* Indicadores de topo do resumo ---------------------------------------------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 24px;
}

.kpi {
  display: block;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}

a.kpi:hover {
  border-color: var(--accent);
}

.kpi-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.kpi-value {
  display: block;
  margin: 6px 0 4px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* Vermelho reservado a trabalho atrasado — um número alto não é, por si só,
   um problema. */
.kpi-value.is-late { color: #b42318; }

.kpi-hint {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
}

/* Pendentes: cartões comuns ao resumo, entidades e documentos por entidade. */
.outstanding-row .kpi[aria-current="page"] {
  border-color: var(--accent);
  box-shadow: inset 0 3px var(--accent);
}
.outstanding-parties { margin-top: 28px; }
.outstanding-party {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}
.outstanding-party > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  cursor: pointer;
  list-style: none;
}
.outstanding-party > summary::-webkit-details-marker { display: none; }
.outstanding-party > summary::before { content: '▸'; color: var(--muted); }
.outstanding-party[open] > summary::before { content: '▾'; }
.outstanding-party-identity { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.outstanding-party-identity > span { display: block; margin-top: 4px; font-size: 12px; }
.outstanding-party-amount { white-space: nowrap; font-size: 18px; }
.outstanding-party-documents { padding: 0 16px 16px; border-top: 1px solid var(--line); }
.outstanding-table-scroll { overflow-x: auto; }
.outstanding-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px; }
.outstanding-actions form { margin: 0; }
.outstanding-table-scroll table { margin-bottom: 0; }
.outstanding-table-scroll caption { text-align: left; padding: 12px 0; color: var(--muted); }
@media (max-width: 600px) {
  .outstanding-party > summary { flex-wrap: wrap; }
  .outstanding-party-identity { flex-basis: calc(100% - 32px); }
  .outstanding-party-amount { margin-left: 24px; }
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}

.chart-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.chart-panel-wide {
  grid-column: 1 / -1;
}

.chart-panel h3 {
  margin: 0 0 14px;
  font-size: 15px;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(28px, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 230px;
}

.bar-slot {
  display: grid;
  grid-template-rows: 160px 18px 32px;
  gap: 6px;
  min-width: 0;
}

/* Sem fundo cheio: a pista preenchida à altura toda lia-se como uma barra vazia
   ("sem dados") em vez de um mês a zero. Fica só a linha de base de onde as
   barras crescem. */
.bar-track {
  position: relative;
  width: 100%;
  height: 160px;
  background: transparent;
  box-shadow: inset 0 -1px 0 var(--line);
  overflow: hidden;
}

.bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: max(2px, var(--bar-value));
  border-radius: 4px 4px 0 0;
}

.bar-purchases { background: #ba4a3c; }
.bar-sales { background: #177245; }

.bar-label,
.bar-value,
.cash-net {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar-value {
  overflow: hidden;
  text-overflow: ellipsis;
}

.cash-chart {
  display: grid;
  gap: 7px;
}

.cash-head,
.cash-row {
  display: grid;
  grid-template-columns: 34px minmax(160px, 1fr) 116px;
  align-items: center;
  gap: 10px;
}

.cash-head {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
}

.cash-head span:last-child { text-align: right; }

.cash-bars {
  display: grid;
  gap: 4px;
}

.cash-bar {
  display: block;
  width: var(--bar-value);
  min-width: 2px;
  height: 9px;
  border-radius: 999px;
}

.cash-in { background: #177245; }
.cash-out { background: #ba4a3c; }

/* Mês sem movimento: ocupa a linha para as barras não saltarem, mas não pinta
   nada — um traço colorido leria-se como um valor pequeno. */
.cash-empty {
  min-width: 0;
  background: transparent;
}

/* Coluna própria à direita: dentro de .cash-bars o valor sobrepunha-se às
   barras e desaparecia nos meses de valor pequeno. */
.cash-net {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cash-net-positive { color: #177245; }
.cash-net-negative { color: #ba4a3c; }
.cash-net-neutral { color: var(--muted); }

.chart-legend {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.chart-legend i {
  display: inline-block;
  width: 18px;
  height: 8px;
  margin-right: 6px;
  border-radius: 999px;
  vertical-align: 1px;
}

.legend-in { background: #177245; }
.legend-out { background: #ba4a3c; }

.annual-values {
  margin-bottom: 22px;
}

/* Mês sem atividade: esbatido nos gráficos e na tabela (o valor continua lá,
   mas deixa de competir com os meses que têm números). */
.bar-slot.is-zero .bar-label { opacity: .55; }
.cash-row.is-zero { opacity: .45; }
.annual-values tbody tr.row-zero > td { color: var(--muted); }
.annual-values tbody tr.row-zero > td > * { opacity: .6; }

/* Tabela mensal: fundo cheio só na coluna "Fluxo líquido"; Compras/Vendas/
   Entrou/Saiu mantêm só o texto na cor semântica, sobre fundo neutro. */
.annual-values td.num:not(.col-net):has(.amount-pos),
.annual-values td.num:not(.col-net):has(.amount-neg),
.annual-values tbody tr:hover > td.num:not(.col-net):has(.amount-pos),
.annual-values tbody tr:hover > td.num:not(.col-net):has(.amount-neg) {
  background: transparent;
}
.annual-values tbody tr:hover > td.num:not(.col-net) { background: #f6f8fa; }
.annual-values td.col-net { font-weight: 650; }
.annual-values tfoot td.num:not(.col-net):has(.amount-pos),
.annual-values tfoot td.num:not(.col-net):has(.amount-neg) { background: #f8fafc; }

.annual-values tfoot th,
.annual-values tfoot td {
  border-top: 2px solid var(--line);
  background: #f8fafc;
  font-weight: 750;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--th-text);
  font-size: 12px;
  font-weight: 700;
  background: var(--th-bg);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.filters {
  display: grid;
  grid-template-columns: 140px minmax(240px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
  max-width: 720px;
}

.filters label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.filters-wide {
  grid-template-columns: 100px 160px 190px 145px 115px minmax(180px, 1fr) auto;
  max-width: none;
}

.filters-toconline {
  grid-template-columns: 230px 150px 150px minmax(220px, 1fr) auto;
  max-width: none;
}

.sync-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: -8px 0 18px;
  color: var(--muted);
}

.sync-summary span {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 7px 10px;
  font-size: 12px;
}

.sync-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -6px 0 18px;
}

.validation-panel {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 420px);
  gap: 24px;
  align-items: start;
  max-width: 960px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.validation-panel h2 {
  margin-top: 0;
}

/* Separadores de vista (página de alertas) */
/* Linha única: quando não cabem (desktop estreito), deslizam na horizontal com
   uma barra fina em vez de quebrarem para uma segunda linha desalinhada. A
   linha de base é uma sombra interior (e não border + margin negativa) porque
   overflow-x: auto cortaria o separador ativo que a sobrepõe. */
.tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  box-shadow: inset 0 -1px 0 var(--line);
  margin-bottom: 18px;
}
.tabs::-webkit-scrollbar { height: 6px; }
.tabs::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.tabs::-webkit-scrollbar-track { background: transparent; }

.tabs .tab {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  white-space: nowrap;
  color: var(--muted);
  text-decoration: none;
  font-weight: 650;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}

.tabs .tab:hover { color: var(--text); }

.tabs .tab-active {
  color: var(--text);
  background: var(--surface);
  border-color: var(--line);
}

@media (max-width: 1240px) {
  .tabs { gap: 2px; }
  .tabs .tab { padding: 9px 9px; gap: 6px; font-size: 13.5px; }
}

.tabs button.tab {
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.tabs button.tab:hover {
  background: transparent;
  color: var(--text);
}

.tabs button.tab-active {
  color: var(--text);
  background: var(--surface);
}

.tab-count {
  min-width: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--bg);
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}

/* Vermelho só quando há trabalho atrasado (ver REVIEW_OVERDUE_DAYS). */
.tab-count.is-late {
  color: #b42318;
  background: #fdedeb;
}

.workday-tab-panels {
  min-width: 0;
}

.workday-tab-panel.alert-section {
  margin-bottom: 0;
}

/* Barra de filtros em linha (alterna conforme o separador) */
.filters-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-bottom: 16px;
}

.filters-inline .filter-field { gap: 5px; }

.filters-inline .ms-toggle { min-width: 140px; }
.filters-inline .ff-bank .ms-toggle { min-width: 118px; }

.filters-inline .filter-field-amount { flex: 0 0 92px; }
.filters-inline .filter-field-amount input { width: 92px; }

.filters-inline .filter-field-grow {
  flex: 1 1 200px;
  min-width: 160px;
}
.filters-inline .filter-field-grow input { width: 100%; }

.filters-inline .filter-actions { align-self: end; }

/* Popover "Filtros" -----------------------------------------------------------
   Os filtros secundários (banco, estado, revisão, mês, valores) vivem aqui
   dentro para a barra caber numa linha: antes ocupavam o primeiro ecrã inteiro
   e a primeira linha de dados só aparecia a ~420px do topo. O painel fica no
   mesmo <form>, por isso os campos submetem na mesma. */
.filters-more {
  position: relative;
  align-self: end;
}

.filters-more-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.filters-more-toggle:hover,
.filters-more-toggle[aria-expanded="true"] {
  background: var(--surface);
  border-color: var(--accent);
}

/* Com filtros ativos o botão passa a ser o sítio onde se percebe que a lista
   está limitada — os chips por baixo dizem quais. */
.filters-more-toggle.has-filters {
  border-color: var(--accent);
  color: var(--accent);
}

.filters-more-count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
}

.filters-more-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  width: max-content;
  max-width: min(560px, calc(100vw - 48px));
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(24, 32, 42, 0.16);
}

.filters-more-panel[hidden] { display: none; }

.filters-more-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 12px;
}

/* Dentro da grelha os campos ocupam a coluna toda: as larguras fixas da barra
   (92px nos valores, 118/140px nos dropdowns) deixariam buracos. */
.filters-inline .filters-more-fields .filter-field { min-width: 0; }
.filters-inline .filters-more-fields .ms-toggle { min-width: 0; }
.filters-inline .filters-more-fields .filter-field-amount input { width: 100%; }

.filters-more-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.ignored-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  margin: -2px 0 14px;
}

/* Interruptor "Mostrar tratados": é um link (muda a vista por URL), mas com
   aspeto de controlo — trilho + botão + rótulo — para não passar por texto. */
.switch-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.switch-toggle:hover { background: #eef1f4; }
.switch-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 30px;
  height: 18px;
  border-radius: 999px;
  background: #7d8998; /* 3,4:1 sobre --bg (contorno de controlo, WCAG 1.4.11) */
  transition: background .15s ease;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .15s ease;
}
.switch-toggle[aria-checked="true"] .switch-track { background: var(--accent); }
.switch-toggle[aria-checked="true"] .switch-thumb { transform: translateX(12px); }
.switch-hint { font-size: 12px; }
[data-theme="dark"] .switch-toggle:hover { background: #263040; }
[data-theme="dark"] .switch-track { background: #4a5768; }

.filters-active {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -6px 0 18px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 650;
  text-decoration: none;
}

.filter-chip span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}

.filter-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.filter-actions,
.quick-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-small {
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1.1;
}

.btn-muted {
  background: #eef1f4;
  color: var(--text);
}

.btn-muted:hover {
  background: #dfe5eb;
}

.flash {
  margin-bottom: 16px;
  padding: 12px;
  border-radius: 6px;
  background: #fff2cc;
  border: 1px solid #ead38a;
}

.error-panel {
  max-width: 620px;
  margin: 8vh auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 32px 34px;
}

.error-code {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: #e7f1ef;
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 16px;
}

.error-message {
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  margin: 0 0 16px;
}

.error-hint {
  background: #f1f4f7;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  padding: 12px 14px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 24px;
}

.error-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-block;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 650;
  padding: 9px 16px;
  text-decoration: none;
}

.btn:hover { background: var(--accent-dark); }

.btn-ghost {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

.btn-ghost:hover { color: var(--text); }

.error-detail {
  margin-top: 28px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.error-detail summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.error-detail-type {
  font-weight: 700;
  color: var(--text);
  margin: 12px 0 4px;
}

.error-detail pre {
  background: #f1f4f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12.5px;
  line-height: 1.45;
  margin: 0 0 12px;
}

.error-detail-trace {
  color: #7a2532;
  white-space: pre !important;
}

/* Linhas das tabelas: hover subtil */
tbody tr:hover > td {
  background: #f6f8fa;
}

/* thead fixo nas tabelas longas */
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.movement-correspondences {
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
  white-space: normal;
  overflow-wrap: anywhere;
}
.movement-correspondences ul {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
}
.movement-correspondences li + li { margin-top: 0.5rem; }
.correspondence-label { font-weight: 600; }
.correspondence-refs { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.movement-correspondences summary { cursor: pointer; margin-top: 0.4rem; }

.workday-queue-table {
  min-width: 1180px;
}

.alerts-table {
  min-width: 1120px;
}

.workday-queue-table .col-actions-sticky,
.alerts-table .col-actions-sticky {
  position: sticky;
  right: 0;
  z-index: 3;
  width: 252px;
  min-width: 252px;
  background: var(--surface);
  box-shadow: -1px 0 0 var(--line);
}

.workday-queue-table thead .col-actions-sticky,
.alerts-table thead .col-actions-sticky {
  z-index: 4;
  background: var(--th-bg);
}

.workday-queue-table tbody tr:hover > .col-actions-sticky,
.alerts-table tbody tr:hover > .col-actions-sticky {
  background: #f6f8fa;
}

/* Valores por sinal (subtil e profissional) */
.amount-pos { color: #1b7f4e; }
.amount-neg { color: #b42318; }

/* Nas tabelas de movimentos, leve fundo na célula de valor */
td.num:has(.amount-pos) {
  background: #e9f5ee;
}
td.num:has(.amount-neg) {
  background: #fdedeb;
}
/* manter o hover legível por cima da tinta */
tbody tr:hover > td.num:has(.amount-pos) { background: #def0e6; }
tbody tr:hover > td.num:has(.amount-neg) { background: #fbe2de; }

/* Badges de estado */
.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 650;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-ok { color: #1b7f4e; background: #e9f5ee; }
.badge-warn { color: #9a6700; background: #fdf3da; }
.badge-bad { color: #b42318; background: #fdedeb; }
.badge-neutral { color: #5a6571; background: #eef1f4; }

/* Sugestão de associação que bate certo em valor E data */
tr.candidate-match > td { background: #e9f5ee; }
tr.candidate-match > td:first-child { box-shadow: inset 4px 0 0 var(--accent); }

.count-badge {
  vertical-align: middle;
  margin-left: 6px;
  font-size: 12px;
}

/* Página de alertas */
.alert-section { margin-bottom: 36px; }
.alert-section:last-child { margin-bottom: 0; }

/* Tabela de possíveis compras duplicadas: separa visualmente cada grupo
   (mesmo NIF/tipo/total/data) com uma linha mais marcada no topo. */
.duplicates-table tbody tr.group-start td {
  border-top: 2px solid var(--line);
}

.section-note {
  color: var(--muted);
  font-size: 12.5px;
  margin: -6px 0 12px;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 22px 18px;
  color: var(--muted);
  text-align: center;
}

/* Botão de expansão de linha */
.col-toggle {
  width: 1%;
  white-space: nowrap;
  padding-right: 4px;
}

.row-toggle {
  background: none;
  border: 0;
  border-radius: 4px;
  padding: 2px 4px;
  margin: 0;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-weight: 600;
}

.row-toggle:hover { background: #eef1f4; color: var(--text); }

.row-toggle .chevron {
  display: inline-block;
  transition: transform 0.15s ease;
  font-size: 11px;
}

.row-toggle[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}

/* O contador de ligações vinha colado ao triângulo e lia-se como o ID da
   linha ("▸ 1"); agora é uma pastilha separada. */
.row-toggle .toggle-count {
  margin-left: 4px;
  min-width: 18px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #eef1f4;
  color: var(--th-text);
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
}
[data-theme="dark"] .row-toggle .toggle-count { background: #2a3442; }

/* Coluna Ações: ação primária + secundária lado a lado, sem quebrar. */
td.col-actions, th.col-actions { width: 1%; white-space: nowrap; }
td.col-actions .quick-actions { flex-wrap: nowrap; }

/* Campo extra mostrado na linha expandida (ex.: Detalhe do extrato). */
.detail-row-field { margin: 0 0 10px; }
.detail-row-label {
  margin-right: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.row-toggle-empty {
  color: var(--line);
  padding: 0 6px;
}

/* Subtabelas */
.detail-row > td {
  background: #fafbfc;
  padding: 0;
}

/* Observações do movimento (caixa de texto na linha expandida) */
.obs-form {
  padding: 10px 12px 14px 40px;
}
.obs-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}
.obs-form textarea {
  display: block;
  width: 100%;
  max-width: 620px;
  resize: vertical;
}
.obs-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.obs-hint {
  font-size: 12px;
  color: var(--muted);
}

.subtable-wrap {
  padding: 8px 12px 12px 40px;
}

.subtable-title {
  margin: 8px 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.subtable {
  width: auto;
  min-width: 60%;
  border: 1px solid var(--line);
  background: var(--surface);
}

.subtable th {
  font-size: 11px;
  padding: 6px 9px;
  background: var(--th-bg);
}

.subtable td {
  padding: 6px 9px;
}

.subtable thead th { position: static; }

/* Linha derivada do e-Fatura (AT) — só leitura, recuada sob a compra */
.subtable tr.efatura-derived td,
.movement-links tr.efatura-derived td {
  background: #fbfaf6;
  color: #6b5b3a;
  border-top: 1px dashed #e6ddc7;
}
.subtable tr.efatura-derived td:first-child,
.movement-links tr.efatura-derived td:first-child { padding-left: 22px; }

/* Documento ligado a mais do que um movimento */
.subtable tr.link-conflict > td,
tr.link-conflict > td { background: #fdedeb; }

.conflict-chip { margin-left: 6px; }

/* NIF — alinhado e sem quebra */
td.nif { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Coluna do método: estreita, só o ícone de info */
.col-method { width: 1%; white-space: nowrap; text-align: center; }

/* Form de associação rápida dentro de uma célula de subtabela (sem margem) */
.inline-form { margin: 0; }

/* Linha "sem sugestões" dentro da linha expandida do separador e-Fatura */
.subtable-empty { margin: 4px 0 2px; }

/* Ícone de info (ⓘ) com o método de correspondência em tooltip */
.info-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font: italic 700 10px/1 Georgia, "Times New Roman", serif;
  cursor: help;
  position: relative;
  user-select: none;
}
.info-tip:hover,
.info-tip:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}
.obs-tip {
  margin-right: 6px;
  vertical-align: middle;
}
.info-tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  z-index: 50;
  width: max-content;
  max-width: 280px;
  padding: 6px 9px;
  border-radius: 6px;
  background: #1f2733;
  color: #fff;
  font: 400 11.5px/1.45 system-ui, -apple-system, sans-serif;
  text-align: left;
  white-space: normal;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(3px);
  transition: opacity .12s ease, transform .12s ease;
  pointer-events: none;
}
.info-tip::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 3px);
  right: 5px;
  z-index: 51;
  border: 5px solid transparent;
  border-top-color: #1f2733;
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease;
  pointer-events: none;
}
.info-tip:hover::after,
.info-tip:focus-visible::after,
.info-tip:hover::before,
.info-tip:focus-visible::before {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Cabeçalhos ordenáveis */
th.sortable { padding: 0; }

th.sortable a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  text-decoration: none;
  padding: 9px 10px;
  width: 100%;
}

th.sortable a:hover { color: var(--text); }

th.sortable .sort-ind {
  font-size: 10px;
  color: var(--muted);
  opacity: 0.35;
}

th.sorted a { color: var(--text); }
th.sorted .sort-ind { opacity: 1; }

/* Cabeçalhos ordenáveis client-side (tabelas planas com .js-sortable) */
.js-sortable th.is-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.js-sortable th.is-sortable:hover { color: var(--text); }

.js-sortable th.is-sortable::after {
  content: "↕";
  font-size: 10px;
  color: var(--muted);
  opacity: 0.35;
  margin-left: 5px;
}

.js-sortable th.is-sortable[aria-sort="ascending"]::after { content: "▲"; opacity: 1; }
.js-sortable th.is-sortable[aria-sort="descending"]::after { content: "▼"; opacity: 1; }
.js-sortable th.is-sortable[aria-sort] { color: var(--text); }

/* Barra de filtros consistente */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.filters-bar .filters-bar-q {
  width: auto;
  flex: 1 1 240px;
  min-width: 200px;
  max-width: 420px;
}

.filters-bar select {
  width: auto;
  min-width: 150px;
}

.filters-bar .filters-amount {
  width: auto;
  flex: 0 0 110px;
  max-width: 120px;
}

.filters-bar .filters-clear { margin-left: 2px; }

.filters-bar .filters-count {
  font-size: 12.5px;
  margin-left: auto;
}

/* Filtro multi-seleção (dropdown de checkboxes) */
.ms-dropdown {
  position: relative;
  display: inline-block;
}

.filter-field .ms-dropdown {
  display: block;
}

.ms-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 150px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.ms-toggle:hover,
.ms-toggle[aria-expanded="true"] {
  background: var(--surface);
  border-color: var(--accent);
}

.ms-toggle-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ms-caret {
  flex: none;
  color: var(--muted);
  font-size: 11px;
}

.filter-field .ms-toggle {
  min-width: 0;
}

.ms-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-width: 320px;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(24, 32, 42, 0.14);
}

.ms-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 8px 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.ms-panel-title {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.ms-link {
  width: auto;
  padding: 2px 4px;
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ms-link:hover {
  background: none;
  color: var(--accent-dark);
  text-decoration: underline;
}

.ms-options {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ms-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
}

.ms-option:hover {
  background: #eef1f4;
}

.ms-option input {
  width: auto;
  flex: none;
  margin: 0;
  accent-color: var(--accent);
}

/* Campo de filtro com etiqueta (formulários .filters) */
.filter-field {
  display: grid;
  gap: 5px;
}

.filter-field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

/* Barra de paginação */
.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.pagination-nav {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.pagination-pages { color: var(--muted); }

.page-btn {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}

a.page-btn:hover { border-color: var(--accent); color: var(--accent); }

.page-btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

/* Link de drill-down */
.ref-link {
  color: var(--accent);
  text-decoration: none;
}

.ref-link:hover { text-decoration: underline; }

/* Observação citada num evento de auditoria */
.audit-note {
  color: var(--text);
  font-style: italic;
}

/* Link de ação discreto (tabela de movimentos) */
.action-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
}

.action-link:hover { text-decoration: underline; }

/* Botão compacto e variante de perigo */
.btn-small {
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.2;
  background: var(--accent);
  color: #fff;
}

a.btn-small {
  display: inline-block;
  text-decoration: none;
  font-weight: 650;
}

.btn-small:hover { background: var(--accent-dark); }

.btn-small.btn-muted {
  background: #eef1f4;
  color: var(--text);
}

.btn-small.btn-muted:hover { background: #dfe5eb; }

.btn-danger { background: #b42318; color: #fff; }
.btn-danger:hover { background: #8f1b12; }

/* Cartão resumo do movimento (página associar) */
.back-link { margin: 0 0 8px; }

/* Cartão compacto: os campos seguem-se numa linha que aproveita a largura e
   só quebra quando não cabem. Descrição/Detalhe já não ocupam uma linha
   inteira para texto curto — crescem até ~48ch e aí quebram o texto. */
.movement-card {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 16px;
}

.movement-field { display: flex; flex-direction: column; gap: 3px; flex: 0 0 auto; min-width: 0; }
.movement-field-wide { flex: 0 1 auto; max-width: 48ch; overflow-wrap: anywhere; }

.movement-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.movement-value { font-size: 15px; }

.raw-text-details { margin-bottom: 24px; }

.raw-text-details summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.raw-text {
  background: #f1f4f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 10px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12.5px;
  line-height: 1.45;
}

.best-suggestion {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px 18px;
  align-items: start;
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid #b7dcc6;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #f3faf6;
}

.best-suggestion-main {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.best-suggestion-ref {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.best-suggestion-ref strong {
  font-size: 17px;
}

.best-suggestion-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px 18px;
  margin: 0;
}

.best-suggestion-info > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.best-suggestion-info dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.best-suggestion-info dd {
  margin: 0;
  font-size: 14px;
  word-break: break-word;
}

.best-suggestion-comparison {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.best-suggestion-side {
  padding: 10px;
  border: 1px solid #d7e7df;
  border-radius: 7px;
  background: rgba(255, 255, 255, .62);
}

.best-suggestion-side:only-child {
  grid-column: 1 / -1;
}

.best-suggestion-side dd + dd { margin-top: 4px; }

.best-suggestion-date,
.best-suggestion-movement {
  color: var(--muted);
  font-size: 12px;
}

.best-suggestion-side .field-blocker {
  margin-top: 8px;
}

.candidate-field-blocked {
  color: #9a6700;
  background: #fff7e6;
  border-radius: 6px;
  padding: 3px 6px;
}

.field-blocker {
  display: block;
  margin-top: 2px;
  color: #9a6700;
  font-size: 11px;
  font-weight: 650;
}

.best-suggestion-obs {
  grid-column: 1 / -1;
}

.best-suggestion-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.review-action-panel {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.review-action-panel h2 {
  margin-top: 0;
}

.review-ignore-form {
  display: grid;
  gap: 8px;
}

.review-ignore-form textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
}

.review-ignore-actions {
  display: flex;
  justify-content: flex-end;
}

.workday-action-primary {
  background: var(--accent);
  color: white;
  font-weight: 650;
}

a.workday-action-primary {
  display: inline-block;
  text-decoration: none;
  font-weight: 650;
}

.workday-action-primary:hover {
  background: var(--accent-dark);
  color: white;
}

/* Secções da página associar */
.associate-section { margin-bottom: 32px; }
.associate-section:last-child { margin-bottom: 0; }

.suggestion-more-toggle { margin-top: 8px; }

.reason-cell { font-size: 12.5px; max-width: 280px; }

.classify-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: flex-start;
}

.classify-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  width: 100%;
}

.classify-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
}

.classify-option:hover {
  border-color: var(--accent);
}

.classify-option:has(input:checked) {
  border-color: var(--accent);
  background: #f3faf6;
  font-weight: 600;
}

/* Rádio à esquerda e rótulo a ocupar o resto do cartão (a regra global
   input { width: 100% } esticava o rádio e empurrava o texto para a direita). */
.classify-option input {
  flex: 0 0 auto;
  width: auto;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.classify-option > span {
  flex: 1 1 auto;
  text-align: left;
}

.classify-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.classify-other-description {
  display: grid;
  gap: 6px;
  width: min(100%, 440px);
  font-size: 14px;
  font-weight: 600;
}

/* O display: grid acima anulava o atributo hidden: o campo "Descrição" de
   "Outros" aparecia sempre. */
.classify-other-description[hidden] { display: none; }

.classify-other-description input {
  width: 100%;
}

[data-theme="dark"] .classify-option:has(input:checked) {
  background: #132820;
}

.drawer-open { overflow: hidden; }

.associate-drawer[hidden] { display: none; }

.associate-drawer {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.associate-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .38);
}

.associate-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(760px, 92vw);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 42px rgba(15, 23, 42, .18);
}

.associate-drawer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-weight: 700;
}

.associate-drawer-content {
  min-height: 0;
  overflow: hidden;
  padding: 0;
}

.associate-drawer-content > .empty-state {
  margin: 18px;
}

.associate-drawer-feedback {
  flex-shrink: 0;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.associate-drawer-feedback .flash { margin: 0; }
.associate-drawer-feedback button { margin-top: 8px; }

.associate-panel-layout {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.associate-panel-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  scroll-padding-top: 18px;
}

.associate-panel-scroll > .associate-section { margin-bottom: 24px; }

.associate-search-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.associate-search-section h2 { margin-top: 0; }
.associate-search-section .filters-bar { margin-bottom: 0; }
.associate-search-section .filters-bar + table,
.associate-search-section .filters-bar + .empty-state { margin-top: 14px; }

.associate-decision-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 -8px 22px rgba(15, 23, 42, .08);
}

.associate-decision-primary,
.associate-decision-secondary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-decision-primary {
  display: inline-block;
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  text-decoration: none;
}

.btn-decision-primary:hover {
  background: var(--accent-dark);
  color: #fff;
}

.associate-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.associate-panel-head h2 { margin: 0; }
.associate-panel-head p { margin: 4px 0 0; }

/* Flash por categoria (sucesso/erro) — além do amarelo genérico */
.flash.success {
  background: #e9f5ee;
  border-color: #b7dcc6;
  color: #1b5e3a;
}

.flash.error {
  background: #fdedeb;
  border-color: #f1b8b0;
  color: #8f1b12;
}

@media (max-width: 980px) {
  .topbar { align-items: flex-start; height: auto; flex-wrap: wrap; padding: 14px; }
  nav { order: 3; width: 100%; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workday-status-strip { grid-template-columns: 1fr; }
  .grid-two { grid-template-columns: 1fr; }
  .section-toolbar { align-items: stretch; flex-direction: column; }
  .dashboard-filters .ff-year { width: 100%; }
  .mode-switch { width: 100%; }
  .mode-switch a { flex: 1; }
  .chart-grid { grid-template-columns: 1fr; }
  .bar-chart {
    grid-template-columns: repeat(6, minmax(34px, 1fr));
    row-gap: 14px;
  }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cash-head,
  .cash-row { grid-template-columns: 34px minmax(120px, 1fr) 92px; }
  table { display: block; overflow-x: auto; }
  thead th { position: static; }
  .workday-queue-table .col-actions-sticky,
  .alerts-table .col-actions-sticky {
    position: static;
    width: auto;
    min-width: 0;
    box-shadow: none;
  }
  .subtable-wrap { padding-left: 12px; }
  .obs-form { padding-left: 12px; }
  .filters,
  .filters-wide { grid-template-columns: 1fr; }
  .filters-inline { flex-direction: column; align-items: stretch; }
  /* Sem espaço lateral para um popover flutuante: o painel passa a expandir-se
     na própria coluna, como um acordeão. */
  .filters-more { align-self: stretch; }
  .filters-more-toggle { width: 100%; justify-content: space-between; }
  .filters-more-panel {
    position: static;
    width: auto;
    max-width: none;
    margin-top: 8px;
    box-shadow: none;
  }
  .filters-more-fields { grid-template-columns: 1fr; }
  .filters-inline .filter-field-amount,
  .filters-inline .filter-field-grow { flex-basis: auto; min-width: 0; }
  .filters-inline .filter-field-amount input { width: 100%; }
  .filters-bar { flex-direction: column; align-items: stretch; }
  .filters-bar .filters-bar-q,
  .filters-bar select,
  .filters-bar .filters-amount { width: 100%; max-width: none; flex-basis: auto; }
  .filters-bar .filters-count { margin-left: 0; }
  .movement-card { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .associate-drawer-panel { width: 100vw; }
  .associate-drawer-content { padding: 0; }
  .associate-panel-scroll { padding: 14px; }
  .associate-search-section { padding: 12px; }
  .associate-search-section .filters-bar button { width: 100%; }
  .associate-decision-bar { align-items: stretch; padding: 10px 14px; }
  .associate-decision-primary,
  .associate-decision-secondary { width: 100%; }
  .associate-decision-primary > *,
  .associate-decision-secondary > * { flex: 1; text-align: center; }
  .associate-panel-head { flex-direction: column; }
  .best-suggestion { grid-template-columns: 1fr; }
  .best-suggestion-actions { justify-content: flex-start; }
}

/* Botão de alternância de tema (claro/escuro) na barra superior */
.theme-toggle {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.theme-toggle:hover {
  background: none;
  color: var(--text);
  border-color: var(--accent);
}

/* Lua/sol coexistem no botão; mostra-se um por tema (a troca é só por CSS,
   o app.js já não substitui o ícone — ver base.html). */
.theme-toggle .theme-icon { display: block; }
.theme-toggle .theme-icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .theme-icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .theme-icon-sun { display: block; }

/* Botão "Sair" discreto (ghost): despromovido face à nav — borda + texto dos
   tokens, sem o preenchimento verde sólido, mantendo área de clique confortável. */
.topbar-logout {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
  padding: 8px 14px;
}

.topbar-logout:hover {
  background: none;
  color: var(--text);
  border-color: var(--accent);
}

/* ============================================================
   Tema escuro ([data-theme="dark"] em <html>)
   As variáveis em :root[data-theme="dark"] já cobrem a maior
   parte da interface. Os blocos abaixo ajustam apenas as cores
   fixas (badges, montantes, flashes, tooltips, etc.) que não
   usam variáveis — sem alterar nenhuma regra do tema claro.
   ============================================================ */

/* Fundos neutros (cabeçalhos de tabela, blocos de código, hover) */
[data-theme="dark"] th,
[data-theme="dark"] .subtable th,
[data-theme="dark"] .error-hint,
[data-theme="dark"] .error-detail pre,
[data-theme="dark"] .raw-text {
  background: #212a35;
}

[data-theme="dark"] tbody tr:hover > td,
[data-theme="dark"] .detail-row > td {
  background: #1f2731;
}

[data-theme="dark"] .btn-muted,
[data-theme="dark"] .btn-small.btn-muted,
[data-theme="dark"] .row-toggle:hover,
[data-theme="dark"] .ms-option:hover,
[data-theme="dark"] .badge-neutral {
  background: #2a333f;
}

[data-theme="dark"] .btn-muted:hover,
[data-theme="dark"] .btn-small.btn-muted:hover {
  background: #36414f;
}

[data-theme="dark"] .badge-neutral {
  color: #aab8c6;
}

[data-theme="dark"] .workday-queue-table .col-actions-sticky,
[data-theme="dark"] .alerts-table .col-actions-sticky {
  background: var(--surface);
}

[data-theme="dark"] .workday-queue-table thead .col-actions-sticky,
[data-theme="dark"] .alerts-table thead .col-actions-sticky {
  background: #212a35;
}

[data-theme="dark"] .workday-queue-table tbody tr:hover > .col-actions-sticky,
[data-theme="dark"] .alerts-table tbody tr:hover > .col-actions-sticky {
  background: #1f2731;
}

/* Montantes e estados positivos (verde) */
[data-theme="dark"] .amount-pos,
[data-theme="dark"] .badge-ok {
  color: #5fd9a8;
}

[data-theme="dark"] td.num:has(.amount-pos),
[data-theme="dark"] .badge-ok,
[data-theme="dark"] tr.candidate-match > td {
  background: #163328;
}

[data-theme="dark"] tbody tr:hover > td.num:has(.amount-pos) {
  background: #1d4536;
}

[data-theme="dark"] .flash.success {
  background: #163328;
  border-color: #2f5e4a;
  color: #9be8c6;
}

[data-theme="dark"] .best-suggestion {
  background: #132820;
  border-color: #2f5e4a;
}

[data-theme="dark"] .best-suggestion-side {
  background: rgba(15, 35, 28, .72);
  border-color: #2f5e4a;
}

[data-theme="dark"] .review-action-panel {
  background: #1f2731;
  border-color: #344054;
}

/* Montantes e estados negativos (vermelho) */
[data-theme="dark"] .amount-neg,
[data-theme="dark"] .badge-bad,
[data-theme="dark"] .metric-alert strong,
[data-theme="dark"] .kpi-value.is-late,
[data-theme="dark"] .tab-count.is-late,
[data-theme="dark"] .error-detail-trace {
  color: #ff968a;
}

[data-theme="dark"] .tab-count.is-late {
  background: #3a2228;
}

[data-theme="dark"] td.num:has(.amount-neg),
[data-theme="dark"] .badge-bad,
[data-theme="dark"] .subtable tr.link-conflict > td,
[data-theme="dark"] tr.link-conflict > td {
  background: #3a2228;
}

[data-theme="dark"] tbody tr:hover > td.num:has(.amount-neg) {
  background: #48282e;
}

[data-theme="dark"] .flash.error {
  background: #3a2228;
  border-color: #6b3a40;
  color: #ffb3a8;
}

[data-theme="dark"] .metric-alert {
  /* Antes ficava acastanhado; alinhado agora ao tint vermelho limpo já usado
     nos negativos/flash.error desta secção de tema escuro. */
  background: #3a2228;
  border-color: #6b3a40;
}

[data-theme="dark"] .btn-danger { background: #b3261e; }
[data-theme="dark"] .btn-danger:hover { background: #8f1d17; }

/* Aviso (amarelo) */
[data-theme="dark"] .badge-warn {
  color: #f3cf73;
  background: #3a3115;
}

[data-theme="dark"] .candidate-field-blocked {
  color: #f3cf73;
  background: #3a3115;
}

[data-theme="dark"] .field-blocker {
  color: #f3cf73;
}

[data-theme="dark"] .flash {
  background: #3a3115;
  border-color: #5c4d22;
  color: #f3cf73;
}

/* Distintivo de código de erro (tom do acento) */
[data-theme="dark"] .error-code {
  background: #163530;
}

/* Tooltip do método de correspondência */
[data-theme="dark"] .info-tip::after {
  background: #2a333f;
  border: 1px solid #475467;
}

[data-theme="dark"] .info-tip::before {
  border-top-color: #475467;
}

/* Linha derivada do e-Fatura (AT) */
[data-theme="dark"] .subtable tr.efatura-derived td,
[data-theme="dark"] .movement-links tr.efatura-derived td {
  background: #2c2a1f;
  color: #d4c397;
  border-top-color: #4a4530;
}

/* ============================================================
   Página de verificação — chips de filtro, toggle de opção
   ============================================================ */

/* Checkboxes maiores nas tabelas de verificação (não afecta os
   dropdowns multi-seleção que vivem fora de <table>) */
table input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
  vertical-align: middle;
}

/* Fila de chips de filtro por tipo de alteração */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.filter-chips a {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.1s ease, color 0.1s ease;
}

.filter-chips a:hover {
  border-color: var(--accent);
  color: var(--text);
}

.filter-chips a.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

[data-theme="dark"] .filter-chips a.chip-active {
  color: var(--bg);
}

/* Toggle "Associar apenas a pagamentos" */
.po-toggle {
  margin-bottom: 14px;
}

.po-toggle label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.po-toggle input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--accent);
  flex: none;
}

/* Barra de seleção em lote + modal de justificação (fila de revisão / Alertas). */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem .75rem;
  margin: .5rem 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.bulk-bar[hidden] {
  display: none;
}
.ignore-dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.4rem 1.6rem;
  width: 80vw;
  max-width: 80vw;
  box-sizing: border-box;
  background: var(--surface);
  color: inherit;
}
.ignore-dialog h3 { margin: 0 0 .6rem; }
.ignore-dialog textarea { width: 100%; box-sizing: border-box; }
.ignore-dialog .obs-actions { margin-top: .75rem; display: flex; gap: .5rem; justify-content: flex-end; }
.ignore-dialog::backdrop { background: rgba(0, 0, 0, .35); }
.ignore-movement-context { max-height: 35vh; overflow-y: auto; margin-bottom: 16px; }
.ignore-movement-context .movement-card { margin-bottom: 8px; }
.ignore-movement-context .movement-field-wide { max-width: 100%; }

/* Estado vazio acionável (macro empty_state). */
.empty-state-rich { text-align: center; padding: 1.75rem 1.25rem; }
.empty-state-rich .es-ico {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px; font-size: 22px; background: var(--line);
}
.empty-state-rich .es-ico.es-success { color: #1b7f4e; }
.empty-state-rich .es-ico.es-info { color: var(--accent); }
.empty-state-rich .es-ico.es-neutral { color: var(--muted); }
.empty-state-rich .es-title { font-size: 16px; font-weight: 500; margin: 0 0 4px; }
.empty-state-rich .es-sub { font-size: 14px; color: var(--muted); margin: 0 0 14px; line-height: 1.6; }
.empty-state-rich .es-act { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }
[data-theme="dark"] .empty-state-rich .es-ico.es-success { color: #5dcca8; }

.ignore-dialog .verify-assoc { margin: 0 0 12px; }
.ignore-dialog .verify-assoc .assoc-subtable { width: 100%; }

/* Navegação por teclado (app.js): linha ativa e legenda de atalhos (?) */
tbody tr.kbd-active {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.kbd-legend {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  display: grid;
  gap: 6px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-size: 13px;
  color: var(--muted);
}

.kbd-legend strong { color: var(--text); }

.kbd-legend kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: 600 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
}


/* Resumo no escuro: fundo neutro fora do "Fluxo líquido" (as regras escuras de
   td.num:has(...) têm mais especificidade de atributo) e verdes/vermelhos do
   saldo do fluxo de caixa legíveis sobre --surface. */
[data-theme="dark"] .annual-values td.num:not(.col-net):has(.amount-pos),
[data-theme="dark"] .annual-values td.num:not(.col-net):has(.amount-neg) {
  background: transparent;
}
[data-theme="dark"] .annual-values tbody tr:hover > td.num:not(.col-net) { background: #1f2731; }
[data-theme="dark"] .annual-values tfoot th,
[data-theme="dark"] .annual-values tfoot td,
[data-theme="dark"] .annual-values tfoot td.num:not(.col-net):has(.amount-pos),
[data-theme="dark"] .annual-values tfoot td.num:not(.col-net):has(.amount-neg) { background: #212a35; }
[data-theme="dark"] .cash-net-positive { color: #5fd9a8; }
[data-theme="dark"] .cash-net-negative { color: #ff968a; }

/* --- Alertas: separadores agrupados (Movimentos / Documentos) -------------- */
/* Uma linha só, como antes; cada grupo tem um rótulo pequeno e os grupos são
   separados por um traço vertical. Separadores a zero ficam esbatidos (mas
   clicáveis e com o contador verde) e já vêm ordenados para o fim do grupo. */
.alert-tabs { align-items: flex-end; gap: 12px; }
.alert-tabs .tab-group {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-end;
  gap: 4px;
}
.alert-tabs .tab-group + .tab-group {
  padding-left: 12px;
  box-shadow: inset 1px 0 0 var(--line);
}
.alert-tabs .tab-group-label {
  align-self: center;
  padding: 0 2px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}
/* Com os rótulos dos grupos, os seis separadores só cabem numa linha a 1360px
   com menos folga lateral que os separadores genéricos. */
.alert-tabs .tab { padding: 10px 11px; gap: 6px; }
.alert-tabs .tab-empty { opacity: .55; font-weight: 550; }
.alert-tabs .tab-empty:hover,
.alert-tabs .tab-empty:focus-visible,
.alert-tabs .tab-empty.tab-active { opacity: 1; }
@media (max-width: 1240px) {
  .alert-tabs { gap: 8px; }
  .alert-tabs .tab-group + .tab-group { padding-left: 8px; }
  .alert-tabs .tab { padding: 9px 8px; }
}

/* --- Painel lateral: linhas vazias compactas e navegação ------------------- */
.associate-empty-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 0 0 18px;
  padding: 8px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 13px;
}
.associate-empty-line strong { font-weight: 650; }
.associate-panel-scroll > .associate-empty-line { margin-bottom: 18px; }

.associate-decision-bar[hidden],
.drawer-nav[hidden] { display: none; }
.drawer-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.drawer-nav-pos { font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.drawer-nav button:disabled { opacity: .45; cursor: default; }

/* Linha que está aberta no painel. */
tbody tr.drawer-active > td,
.alerts-table tbody tr.drawer-active > .col-actions-sticky { background: #e8f3f1; }
tbody tr.drawer-active { outline: 2px solid var(--accent); outline-offset: -2px; }
[data-theme="dark"] tbody tr.drawer-active > td,
[data-theme="dark"] .alerts-table tbody tr.drawer-active > .col-actions-sticky { background: #16302b; }

.association-amount-shortcut { margin: 8px 0 12px; }
.association-search-pills { margin: 0 0 14px; }
.association-search-pills form { margin: 0; }
.association-search-pills .filter-chip { background: var(--surface); color: var(--text); }
.association-search-pills .filter-chip:hover { background: var(--surface); color: var(--accent); }
.association-search-form { align-items: end; }
.association-search-form .filters-bar-q { min-width: 150px; flex-basis: 180px; }
.association-search-margin { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.association-search-margin[hidden] { display: none; }
.association-search-margin input { width: 95px; }
.association-search-form select[name="search_margin_unit"] { width: 60px; min-width: 60px; flex: 0 0 60px; }
.association-search-buttons, .association-search-shortcuts { display: flex; gap: 8px; flex-wrap: wrap; }
.association-search-help { font-size: 12px; margin: 10px 0; }
.association-search-shortcuts { margin: 10px 0 14px; align-items: center; }
.association-search-shortcuts form { margin: 0; }

/* --- Painel encostado (Alertas e Trabalho, ≥1100px) ------------------------ */
/* Em vez de cobrir a tabela, o painel ocupa uma coluna fixa à direita e o corpo
   da página encolhe (padding-right), por isso a tabela continua visível e
   rolável. Escondem-se as colunas secundárias para caberem Data/Texto banco/
   Valor/Estado + Ações. Abaixo de 1100px mantém-se a sobreposição normal. */
:root { --dock-w: clamp(420px, var(--dock-preferred, 42vw), min(1200px, calc(100vw - 540px))); }
.associate-drawer-resize { display: none; }
.bank-link-destination { margin-top: 8px; overflow-wrap: anywhere; }
@media (min-width: 1100px) {
  .associate-drawer-resize {
    display: block; position: absolute; left: -5px; top: 0; bottom: 0;
    width: 10px; cursor: col-resize; touch-action: none; z-index: 2;
  }
  .associate-drawer-resize:hover, .associate-drawer-resize:focus-visible {
    background: var(--accent); opacity: .5; outline: 2px solid var(--accent);
  }
  body.drawer-resizing { cursor: col-resize; user-select: none; }
  .associate-drawer[data-drawer-dock] { left: auto; width: var(--dock-w); }
  .associate-drawer[data-drawer-dock] .associate-drawer-backdrop { display: none; }
  .associate-drawer[data-drawer-dock] .associate-drawer-panel {
    width: 100%;
    box-shadow: -8px 0 24px rgba(15, 23, 42, .10);
  }
  body.drawer-open.drawer-dockable { overflow: auto; padding-right: var(--dock-w); }
  body.drawer-open.drawer-dockable .alert-section { overflow-x: auto; }
  body.drawer-open.drawer-dockable .alerts-table { min-width: 0; }
  body.drawer-open.drawer-dockable .alerts-table .col-secondary { display: none; }
  body.drawer-open.drawer-dockable .alerts-table .col-actions-sticky { width: auto; min-width: 0; white-space: nowrap; }
  body.drawer-open.drawer-dockable .workday-queue-table { min-width: 0; width: 100%; }
  body.drawer-open.drawer-dockable .workday-queue-table .col-secondary { display: none; }
  body.drawer-open.drawer-dockable .workday-queue-table .col-actions-sticky { width: auto; min-width: 0; }
  body.drawer-open.drawer-dockable .workday-queue-table .col-text { max-width: 280px; overflow-wrap: anywhere; }
  /* O painel encostado é mais estreito que a gaveta: as tabelas lá dentro
     (ligações, sugestões, resultados) rolam na horizontal em vez de saírem. */
  .associate-drawer[data-drawer-dock] .associate-panel-scroll table { display: block; max-width: 100%; overflow-x: auto; }
  body.drawer-open.drawer-dockable .alerts-table td.col-text {
    max-width: 0;
    width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  body.drawer-open.drawer-dockable .topbar { gap: 14px; padding: 0 16px; }
}

/* --- Fila de revisão: lote, agrupamento e densidade ------------------------ */
/* Texto do banco limitado a 2 linhas (o completo fica no title / hover), para
   as linhas terem altura regular em vez de crescerem com descritivos longos. */
.text-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.review-queue-table td { padding-top: 7px; padding-bottom: 7px; vertical-align: middle; }
.review-queue-table td.col-text { max-width: 420px; }
.review-queue-table .detail-row td { vertical-align: top; }

.queue-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 6px;
}

.bulk-bar { position: sticky; top: 64px; z-index: 5; box-shadow: 0 2px 8px rgba(15, 23, 42, .06); }
.bulk-bar .bulk-count { font-weight: 650; min-width: 9ch; }

/* Grupo de descritivos repetidos: linha de cabeçalho destacada, membros com
   recuo à esquerda. */
.review-queue-table tr.group-row > td { background: #f3f7f6; }
.review-queue-table tr.group-row > td.col-actions-sticky { background: #f3f7f6; }
.review-queue-table tr.group-row .group-label { font-weight: 600; }
.review-queue-table tr.group-member > td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.group-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.group-suggestion {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
  font-size: 12.5px;
}
.group-suggestion .btn-small { padding: 2px 8px; }
.group-dates { white-space: nowrap; }
.group-actions { white-space: normal; }
.group-actions .btn-small { margin: 0 4px 4px 0; }

/* Diálogos de lote (Ignorar / Classificar): passos confirmar e resultado. */
.classify-dialog { max-width: 720px; width: 92vw; }
.classify-dialog .classify-options { margin: 4px 0 12px; }
.classify-dialog input[type="text"] { width: 100%; box-sizing: border-box; }
.bulk-error { color: #b42318; margin: 8px 0 0; }
.bulk-confirm-message { font-size: 15px; font-weight: 600; margin: 4px 0 8px; }
.bulk-notes { margin: 0 0 4px; padding-left: 1.2rem; color: var(--muted); }
.bulk-notes[hidden] { display: none; }
.bulk-result-message { font-size: 15px; font-weight: 600; }
.bulk-warning {
  border: 1px solid #f0c36d;
  background: #fdf6e3;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
}
.bulk-warning[hidden] { display: none; }
.bulk-warning p { margin: 0 0 6px; }
.sql-block {
  margin: 6px 0 8px;
  padding: 8px 10px;
  background: var(--th-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: all;
}
.classify-rule-note { margin: 0 0 8px; }

[data-theme="dark"] .review-queue-table tr.group-row > td,
[data-theme="dark"] .review-queue-table tr.group-row > td.col-actions-sticky { background: #18302b; }
[data-theme="dark"] .bulk-warning { background: #2e2614; border-color: #6b5520; }
[data-theme="dark"] .bulk-error { color: #ff8a80; }
[data-theme="dark"] .bulk-bar { box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }

/* --- Regras: separadores e regras sugeridas -------------------------------- */
.rules-tabs { margin-bottom: 14px; }
.rules-intro { margin: 0 0 10px; max-width: 900px; line-height: 1.55; }
.rules-setup-warning { margin: 0 0 14px; }
.rule-suggestions .suggest-desc strong { display: block; overflow-wrap: anywhere; }
.rule-suggestions .suggest-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }
.rule-suggestions .suggest-meta .small { font-size: 12px; }
.rule-suggestions .suggest-type { min-width: 190px; }
.rule-suggestions .suggest-type select,
.rule-suggestions .suggest-type input { width: 100%; box-sizing: border-box; }
.rule-suggestions .suggest-type input { margin-top: 4px; }
.rule-suggestions .suggest-type input[hidden] { display: none; }
.rule-suggestions .suggest-actions { white-space: nowrap; }
.rule-suggestions .suggest-actions .btn-small + .btn-small { margin-left: 4px; }
.rule-suggestions td.nowrap { white-space: nowrap; }
.rules-dismissed { margin-top: 16px; }
.rules-dismissed > summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.rule-suggestions .suggest-actions .btn-small.btn-ghost { background: transparent; color: var(--muted); }
.rule-suggestions .suggest-actions .btn-small.btn-ghost:hover { color: var(--text); text-decoration: underline; }
.rules-setup-warning details { margin: 0 0 8px; }
.rules-setup-warning summary { cursor: pointer; font-weight: 600; margin-bottom: 6px; }

.match-hint { font-size: 12px; margin-top: 2px; font-weight: 600; }
.match-ok { color: #1b7f4e; }
.match-diff { color: #a15c00; }
[data-theme="dark"] .match-ok { color: #5fd39a; }
[data-theme="dark"] .match-diff { color: #f0b45a; }

/* Montantes pendentes e dimensão financeira dos alertas. */
.outstanding-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.alert-amounts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 16px 0;
}
.alert-amount-scope {
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
}
.alert-amount-scope > .kpi-label { display: block; margin-bottom: 8px; }
.alert-amount-values { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.alert-amount-values strong { white-space: nowrap; }
.alert-amount-scope .section-note { margin: 8px 0 0; }
@media (max-width: 640px) {
  .outstanding-row, .alert-amounts { grid-template-columns: 1fr; }
}

/* === Revisão de layout: margens, respiração e alvos clicáveis ==============
   Só espaçamento/alinhamento/tamanho; sem alterar estrutura ou textos.
   Tokens de espaço: --space-1..5 (4/8/12/16/24 px) + --section-gap. */
:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --section-gap: 32px;
  --tap-min: 40px;
}

/* Menu superior: o botão do dropdown herdava o fundo verde de `button:hover`
   (e padding 0), pelo que o item focado/ativo se sobrepunha aos vizinhos. */

.topbar nav { gap: 6px 8px; }
.topbar nav > a,
.nav-toggle {
  min-height: var(--tap-min);
  padding: 0 12px;
  border-radius: 6px;
  border-bottom: 0;
  display: inline-flex;
  align-items: center;
  box-shadow: inset 0 -2px 0 transparent;
}
.topbar nav > a.active,
.nav-toggle.active { border-bottom: 0; box-shadow: inset 0 -2px 0 var(--accent); }
button.nav-toggle:hover,
.topbar nav > a:hover,
.nav-toggle:hover,
.nav-toggle:focus,
.nav-toggle[aria-expanded="true"] {
  background: var(--bg);
  color: var(--text);
}
.nav-toggle:focus:not(:focus-visible) { outline: none; }
.nav-panel { top: calc(100% + 6px); min-width: 180px; padding: var(--space-2); gap: 2px; }
.nav-panel a { display: flex; align-items: center; min-height: 36px; padding: 6px 12px; }
.topbar { gap: var(--space-5); padding: 0 var(--space-5); }
.theme-toggle,
.topbar-logout { min-height: var(--tap-min); min-width: var(--tap-min); }

/* Margens da página e ritmo vertical dos blocos */
.page { padding: var(--space-5) var(--space-5) 56px; }
h1 { margin-bottom: var(--space-5); }
h2 { margin: 0 0 var(--space-3); line-height: 1.3; }
.back-link { margin: 0 0 var(--space-3); }
.back-link .btn-ghost,
.btn-ghost { display: inline-flex; align-items: center; min-height: 32px; }

/* Blocos consecutivos nunca ficam colados (ex.: movimento → Ligações → Notas) */
.page > section + section,
.page > section + h2,
.page > .grid-two + .alert-section,
.page > .alert-section + .alert-section { margin-top: var(--section-gap); }
.page > table + h2,
.page > .tabs + h2,
.page > div + h2 { margin-top: var(--section-gap); }
.page > h2 + table,
.page > h2 + .empty-state { margin-top: 0; }
.alert-section { margin-bottom: 0; }
.alert-section > table,
.alert-section > .empty-state { margin-top: var(--space-3); }

/* Título de secção com botão (Ligações + Associar documentos) */
h2 > .btn-small,
h2 > a.btn-small,
h2 > button {
  margin-left: var(--space-3);
  vertical-align: middle;
}

/* Botões: alvo mínimo ~40px e separação entre botões vizinhos */
button,
.btn { min-height: var(--tap-min); }
.btn { display: inline-flex; align-items: center; justify-content: center; }
.btn-small,
a.btn-small {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 14px;
  font-size: 13px;
}
td .btn-small,
td a.btn-small { min-height: 34px; }
.btn-small + .btn-small,
.btn-small + button,
button + .btn-small,
.btn + .btn,
button + button { margin-left: var(--space-2); }
.quick-actions .btn-small + .btn-small,
.filter-actions .btn-small + .btn-small,
.filter-actions button + button { margin-left: 0; }
form + form { margin-top: var(--space-2); }
td form { margin: 0; }
td .quick-actions { gap: var(--space-2); }
td .btn-small,
td a.btn-small,
td button { margin-top: 2px; margin-bottom: 2px; }
.row-toggle { min-height: 32px; min-width: 32px; justify-content: center; }
.page-btn { min-height: 36px; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin: var(--space-4) 0 var(--space-5); }
.associate-decision-bar button,
.associate-decision-bar .btn-small { margin-top: 0; margin-bottom: 0; }

/* Tabelas: células com mais folga (linhas deixam de se encostar) */
th, td { padding: 11px 12px; }
td { line-height: 1.45; }
.review-queue-table td { padding-top: 9px; padding-bottom: 9px; }
.subtable th, .subtable td { padding: 7px 10px; }
.alert-section + .alert-section,
table + table { margin-top: var(--section-gap); }
.subtable-wrap { padding: var(--space-3) var(--space-4) var(--space-4) 40px; }

/* Formulários e barras de filtros */
.form-stack { gap: var(--space-4); }
.form-stack button { margin-top: var(--space-1); }
.filters-bar,
.filters-inline,
.filters { margin-bottom: var(--space-4); gap: var(--space-3); }
.filters-bar input,
.filters-bar select,
.filters-inline input,
.filters-inline select,
.filters input,
.filters select { min-height: var(--tap-min); }
.filter-chips,
.po-toggle { margin: 0 0 var(--space-4); }
.filter-chips { gap: var(--space-2); }
.filter-chips a { min-height: 34px; display: inline-flex; align-items: center; }
.po-toggle label { min-height: var(--tap-min); }
.tabs { margin-bottom: var(--space-4); }
.tabs .tab { min-height: var(--tap-min); }
.tabs + .filter-chips,
.tabs + p,
.tabs + form { margin-top: var(--space-4); }
.section-toolbar { margin-bottom: var(--space-4); }
.pagination-bar { margin-top: var(--space-4); gap: var(--space-3); }
.bulk-bar { gap: var(--space-3); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3); }
.metrics, .kpi-row { gap: var(--space-4); }
.metric, .kpi { padding: var(--space-4) var(--space-4); }
.flash { margin-bottom: var(--space-4); padding: var(--space-3) var(--space-4); }

/* Automatizar (/verificacao): classes opcionais a aplicar em verificacao.html
   - .auto-table      → <table> de sugestões (linhas mais espaçadas)
   - .auto-actions    → barra com "Aplicar selecionados"
   - .auto-section    → blocos seguintes (Associações automáticas aplicadas)
   Sem a classe, os seletores genéricos acima já cobrem os casos comuns. */
.auto-table td,
.auto-table th { padding: 12px 14px; }
.movement-proposal-select {
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.auto-table td .small,
.auto-table td .muted.small { display: block; margin-top: 3px; }
.auto-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin: var(--space-4) 0 var(--section-gap); }
.auto-section { margin-top: var(--section-gap); padding-top: var(--space-5); border-top: 1px solid var(--line); }
.page > .form-actions { margin-bottom: var(--section-gap); }
.page > .form-actions + h2 { margin-top: var(--section-gap); padding-top: var(--space-5); border-top: 1px solid var(--line); }
.page > table + .form-actions,
.page > form > table + .form-actions { margin-top: var(--space-4); }
.match-hint { margin-top: 4px; }
.link-match-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-top: 3px; }
.auto-table .link-match-line > .small,
.auto-table .link-match-line > .match-hint { display: inline; margin-top: 0; }
.proposal-rules { color: var(--text); }

@media (max-width: 980px) {
  .topbar { padding: var(--space-3) var(--space-4); gap: var(--space-2) var(--space-4); }
  .topbar nav { gap: 4px; }
  .page { padding: var(--space-4) var(--space-4) 48px; }
  h1 { font-size: 24px; margin-bottom: var(--space-4); }
  .grid-two { gap: var(--section-gap); }
  th, td { padding: 10px; }
}
@media (max-width: 520px) {
  .page { padding: var(--space-3) var(--space-3) 40px; }
  .btn-small + .btn-small { margin-left: 0; margin-top: var(--space-2); }
  .form-actions > *, .auto-actions > * { flex: 1 1 100%; }
}

/* Aviso global: sessão TOConline expirada */
.toconline-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin: 12px 24px 0;
  padding: 10px 16px;
  border: 1px solid #e3c477;
  border-radius: 8px;
  background: #fdf6e3;
  color: #5c4308;
  font-size: 0.95rem;
}
.toconline-banner-text { flex: 1 1 280px; }
.toconline-banner-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 6px;
  background: #8a6410;
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.toconline-banner-link:hover { background: #6d500c; }
:root[data-theme="dark"] .toconline-banner {
  border-color: #6b5521;
  background: #2b2412;
  color: #f0dca8;
}
:root[data-theme="dark"] .toconline-banner-link { background: #e0b84f; color: #1d1604; }
:root[data-theme="dark"] .toconline-banner-link:hover { background: #f0cc6e; }


/* A referência mantém o mesmo texto para pesquisa e ordenação das tabelas. */
.document-ref { display: inline-flex; align-items: center; gap: 3px; vertical-align: baseline; max-width: 100%; }
.apptjs-file-chip { text-decoration: none; font-size: 12px; margin-left: 4px; white-space: nowrap; }
.apptjs-ok { color: #1b7f4e; font-weight: 600; }
.apptjs-mismatch { color: #b42318; font-weight: 600; }
.doc-sync-action {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 26px; height: 26px; padding: 4px; margin: 0;
  border: 1px solid transparent; border-radius: 5px;
  background: transparent; color: var(--muted); box-shadow: none; cursor: pointer;
  vertical-align: middle;
}
.doc-sync-action:hover { background: var(--surface); border-color: var(--line); color: var(--accent); }
.doc-sync-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.doc-sync-action:disabled { opacity: .45; cursor: wait; }
.doc-sync-action[aria-busy="true"] { color: var(--accent); opacity: 1; }
.doc-sync-action[aria-busy="true"] svg { animation: document-sync-spin 1s linear infinite; }
@keyframes document-sync-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .doc-sync-action[aria-busy="true"] svg { animation: none; } }
.document-sync-status {
  position: fixed; bottom: 20px; right: 20px; z-index: 250;
  max-width: min(520px, calc(100vw - 40px)); padding: 12px 16px;
  border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px;
  background: var(--surface); color: var(--text); box-shadow: 0 4px 20px rgba(0, 0, 0, .15);
  font-size: 13px; overflow-wrap: anywhere;
}
.document-sync-status.is-error { border-left-color: var(--danger, #b42318); }
.document-sync-status a { text-decoration: underline; }
/* Shared PN surfaces follow the existing cards, forms and status palette. */
.party-card { margin: var(--space-4, 16px) 0; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.party-card h2 { font-size: 16px; }
.party-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.party-heading h1 { margin-bottom: 4px; }
.party-heading p { margin: 0; }
.party-binding { border-left: 3px solid #d9a400; }
.party-binding p { margin: 0 0 12px; }
.party-binding-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.party-binding-actions .btn-small { padding: 9px 12px; font-size: 13px; text-decoration: none; }
.party-check { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.party-check input { width: auto; margin: 0; accent-color: var(--accent); }
.party-binding-actions button { margin-left: 0; }
.party-table .party-name { font-weight: 600; }
.party-table .party-taxid { white-space: nowrap; font-variant-numeric: tabular-nums; }
.party-table td .badge-warn { white-space: normal; line-height: 1.3; }
.party-table tbody tr:hover > td { background: var(--th-bg); }
.party-table .empty-state { border: 0; padding: 12px; }
.party-sync > summary { margin: -2px 0; }
.party-sync[open] > summary { margin-bottom: 12px; }
.party-sync .party-runs { margin-top: 12px; }
@media (max-width: 720px) { .party-check { margin-left: 0; } }
.party-suggestions { padding-left: 1.3rem; }
.party-suggestions li { margin: .6rem 0; }
.party-card details > summary, details.party-card > summary { cursor: pointer; font-weight: 600; }
.party-card .form-stack { max-width: 48rem; margin-top: 1rem; }
.party-card input:not([type=checkbox]), .party-card select { max-width: 100%; }
.party-back { margin-bottom: 8px; }
.party-detail-head { margin-bottom: var(--space-4, 16px); }
.party-detail-head h1 { margin-bottom: 6px; }
.party-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.party-period input, .party-period select, .party-period button { box-sizing: border-box; height: 38px; }
.party-period .party-period-year input { width: 96px; }
.party-period .party-period-date input { width: 150px; }
.party-period select { width: 130px; }
.party-period-or { align-self: end; padding-bottom: 10px; font-size: 12.5px; }
.party-period .btn-ghost { align-self: end; padding-bottom: 6px; }
.party-period-label { margin-left: auto; align-self: end; padding-bottom: 10px; font-size: 12.5px; }
.party-metrics { margin-bottom: 8px; }
.party-metrics-note { margin: 0 0 var(--space-4, 16px); }
.party-movements .badge { white-space: nowrap; }
.party-movements td > .small { margin-top: 3px; }
details.party-card[open] > summary { margin-bottom: 12px; }
details.party-card > summary .badge { margin-left: 4px; }
.party-source { padding: 12px 0; border-top: 1px solid var(--line); }
.party-source p { margin: 0 0 8px; }
.party-check-inline { display: flex !important; align-items: center; gap: 8px; }
.party-check-inline input { width: auto; margin: 0; accent-color: var(--accent); }
.party-aliases { margin: 14px 0 0; padding-left: 1.2rem; }
@media (max-width: 720px) {
  .party-period .party-period-year input,
  .party-period .party-period-date input,
  .party-period select { width: 100%; }
  .party-period-or { display: none; }
  .party-period-label { margin-left: 0; padding-bottom: 0; }
}

/* --- Fiscal (estimativa de IVA e IRC) -------------------------------------- */
.fiscal-exports { display: flex; gap: 8px; }
.fiscal-disclaimer { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.fiscal-section { margin-top: var(--section-gap, 32px); }
.fiscal-section > h2 { margin-bottom: 4px; }
.fiscal-lead { margin: 0 0 16px; max-width: 760px; }
.fiscal-source { margin-right: 4px; }

.fiscal-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.fiscal-irc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .fiscal-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .fiscal-cards, .fiscal-irc-grid { grid-template-columns: 1fr; } }

.fiscal-card { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.fiscal-card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.fiscal-card.is-empty { opacity: .6; }
.fiscal-card > header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.fiscal-card h3 { margin: 0; font-size: 15px; }
.fiscal-card-total { margin: 0 0 12px; }
.fiscal-card-label { display: block; color: var(--muted); font-size: 12px; }
.fiscal-card-total strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.fiscal-card-meta { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }

.fiscal-lines { margin: 0; }
.fiscal-lines > div { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.fiscal-lines > div:first-child { border-top: 0; }
.fiscal-lines dt { color: var(--muted); }
.fiscal-lines dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fiscal-lines > div.is-total { font-weight: 700; border-top: 2px solid var(--line); }
.fiscal-lines > div.is-total dt { color: inherit; }
.fiscal-lines > div.is-late, .fiscal-lines > div.is-late dt { color: #b42318; }

.fiscal-projection { width: 100%; }
.fiscal-projection tr.is-total td { font-weight: 700; }
.fiscal-missing { margin-top: 12px; padding: 12px 16px; border: 1px dashed var(--line); border-radius: 8px; font-size: 13.5px; }

.fiscal-reliability { font-weight: 650; white-space: nowrap; }
.fiscal-reliability.is-high { color: #1b7f4e; }
.fiscal-reliability.is-mid { color: #9a6700; }
.fiscal-reliability.is-low { color: #b42318; }

.fiscal-alert { margin: 8px 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 6px; }
.fiscal-alert > summary { cursor: pointer; }
.fiscal-alert-warn { border-left: 4px solid #9a6700; }
.fiscal-alert-bad { border-left: 4px solid #b42318; }
.fiscal-alert-neutral { border-left: 4px solid #5a6571; }
.fiscal-alert table { margin-top: 8px; }
.fiscal-section details > summary { cursor: pointer; }
.fiscal-section details > summary > h2 { display: inline; }
.fiscal-detail h3 { margin-top: 20px; }
.fiscal-irc tr.fiscal-total > td { font-weight: 700; border-top: 1px solid var(--line); }
.fiscal-config { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.fiscal-config .filter-field { display: flex; flex-direction: column; gap: 4px; }
.fiscal-form { margin-top: 12px; }
.fiscal-hints { padding-left: 18px; }
.fiscal-hints li { margin: 4px 0; }

@media print {
  .topbar, .toconline-banner, .skip-link, .flash-region, .fiscal-filters, .fiscal-exports,
  .fiscal-edit, .document-sync-status, .fiscal-card a, #documentos .btn-ghost { display: none !important; }
  .fiscal-cards { grid-template-columns: repeat(2, 1fr); }
  .fiscal-card, .fiscal-alert { break-inside: avoid; }
  .annual-table-scroll { overflow: visible !important; }
  body { background: #fff; color: #000; }
}

/* Pré-visualização de ficheiros (popup partilhado: file_preview_dialog) */
.file-preview-dialog { height: 88vh; display: none; flex-direction: column; padding: 1rem 1.2rem; }
.file-preview-dialog[open] { display: flex; }
.file-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.file-preview-head h3 { margin: 0; overflow-wrap: anywhere; }
.file-preview-head .obs-actions { margin-top: 0; }
.file-preview-dialog a.btn-small { text-decoration: none; display: inline-flex; align-items: center; }
.file-preview-body { flex: 1; min-height: 0; margin-top: .75rem; display: flex; justify-content: center; align-items: flex-start; overflow: auto; }
.file-preview-body iframe.file-preview-view { width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.file-preview-body img.file-preview-view { max-width: 100%; max-height: 100%; object-fit: contain; }
@media (max-width: 640px) { .file-preview-dialog { width: 96vw; max-width: 96vw; height: 92vh; } }
.apptjs-file-chip { cursor: pointer; }
.apptjs-file-chip.is-disabled { opacity: .3; filter: grayscale(1); cursor: default; pointer-events: none; }
.apptjs-file-count { font-size: 10px; vertical-align: super; margin-left: 1px; }
.file-preview-files { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.file-preview-files button[aria-pressed="true"] { outline: 2px solid var(--line); font-weight: 600; }

/* Detalhe do movimento: layout compacto */
.movement-detail .md-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-3); }
.movement-detail .md-head h1 { margin: 0; font-size: 24px; }
.movement-detail .party-card { margin: 0 0 var(--space-4); padding: 10px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
.movement-detail .party-card h2 { margin: 0; font-size: 15px; }
.movement-detail .party-card > p { margin: 0; }
.movement-detail .party-card > details, .movement-detail .party-card > ul { flex-basis: 100%; margin: 0; }
.movement-detail .party-card details > summary { cursor: pointer; font-weight: 600; }
.movement-detail .md-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: var(--space-5); align-items: start; }
.movement-detail .md-main h2 { margin-bottom: var(--space-2); }
.movement-detail .md-facts { margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; }
.movement-detail .md-facts > div { padding: 8px 12px; border-bottom: 1px solid var(--line); min-width: 0; }
.movement-detail .md-facts .md-wide { grid-column: 1 / -1; }
.movement-detail .md-facts > div:nth-last-child(1) { border-bottom: 0; }
.movement-detail .md-facts dt { font-size: 12px; color: var(--muted, #8a94a6); margin: 0 0 2px; text-transform: uppercase; letter-spacing: .03em; }
.movement-detail .md-facts dd { margin: 0; overflow-wrap: anywhere; }
.movement-detail .md-facts dd.num { text-align: left; font-variant-numeric: tabular-nums; }
.movement-detail .md-review { gap: var(--space-3); }
.movement-detail .md-head-actions { margin-left: auto; display: flex; gap: var(--space-2); }
/* Resumo do movimento: o valor em destaque e a descrição logo a seguir. */
.movement-detail .md-summary { display: grid; grid-template-columns: auto repeat(3, minmax(90px, max-content)) minmax(0, 1fr); gap: var(--space-2) var(--space-5); align-items: start; margin: 0 0 var(--space-4); padding: 12px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.movement-detail .md-summary > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.movement-detail .md-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.movement-detail .md-amount strong { font-size: 22px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.movement-detail .md-desc strong { overflow-wrap: anywhere; }
.movement-detail .md-desc .muted { font-size: 13px; overflow-wrap: anywhere; }
.movement-detail .md-section { margin: 0 0 var(--space-5); }
.movement-detail .md-section > table { margin-top: var(--space-2); }
.movement-detail .md-count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px; background: var(--line); font-size: 12px; text-align: center; vertical-align: middle; }
.movement-detail .md-main { margin-bottom: var(--space-4); }
.movement-detail .md-source { margin: 0 0 var(--space-4); }
.movement-detail .md-source > summary { cursor: pointer; color: var(--muted); font-weight: 600; margin-bottom: var(--space-2); }
.movement-links td.col-actions { text-align: right; }
@media (max-width: 900px) {
  .movement-detail .md-main { grid-template-columns: 1fr; }
  .movement-detail .md-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .movement-detail .md-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .movement-detail .md-desc { grid-column: 1 / -1; }
  .movement-detail .md-section { overflow-x: auto; }
}

/* Fila de revisão: colunas compactas, texto do banco com mais espaço */
.review-queue-table th, .review-queue-table td { padding-left: 8px; padding-right: 8px; }
.review-queue-table td.col-text { max-width: 560px; }
.review-queue-table th.col-toggle, .review-queue-table td.col-toggle { width: 1%; white-space: nowrap; padding-left: 4px; padding-right: 2px; }
.review-queue-table td.col-secondary { width: 1%; white-space: nowrap; }
.review-queue-table td.num, .review-queue-table td:has(> .badge) { width: 1%; white-space: nowrap; }

/* Análise de compras (purchase_analysis.html) -------------------------------
   Cores por tipo: FC azul, DSP âmbar, outros cinza. Tokens próprios para o
   tema escuro manter o contraste. */
:root {
  --pa-fc: #3d6fd6;
  --pa-dsp: #e0962b;
  --pa-other: #9aa5b4;
  --pa-track: #eef1f5;
  --pa-hover: #f6f8fb;
}
:root[data-theme="dark"] {
  --pa-fc: #6f9bff;
  --pa-dsp: #f2b04f;
  --pa-other: #6b7787;
  --pa-track: #242d39;
  --pa-hover: #1f2731;
}
.pa { display: grid; gap: 20px; max-width: 1180px; }
.pa .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.pa-t-fc { background: var(--pa-fc); }
.pa-t-dsp { background: var(--pa-dsp); }
.pa-t-ncf, .pa-t-other { background: var(--pa-other); }
.pa-t-solid { background: var(--accent); }
.pa-muted { color: var(--muted); }
.pa-eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.pa-label { margin: 0 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.pa-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.pa-note { margin: 0 0 14px; padding: 10px 12px; border-radius: 8px; background: var(--pa-track); color: var(--text); font-size: 13px; }

.pa-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.pa-head h1 { margin: 0; font-size: 28px; letter-spacing: -.01em; }
.pa-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pa-select select { height: 36px; padding: 0 30px 0 12px; border: 1px solid var(--line); border-radius: 999px; background-color: var(--surface); color: var(--text); font-weight: 600; }
.pa-seg { display: inline-flex; flex-wrap: nowrap; max-width: 100%; overflow-x: auto; scrollbar-width: none; padding: 3px; border-radius: 999px; background: var(--pa-track); }
.pa-seg a { padding: 6px 14px; border-radius: 999px; color: var(--muted); font-size: 13px; font-weight: 650; text-decoration: none; white-space: nowrap; }
.pa-seg a:hover { color: var(--text); }
.pa-seg a.is-on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }
.pa-seg-sm a { padding: 4px 11px; font-size: 12.5px; }

.pa-card { padding: 22px 24px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.pa-card h2 { margin: 0; font-size: 17px; }
.pa-card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }

.pa-hero { display: grid; grid-template-columns: minmax(220px, 1fr) 2.2fr; gap: 28px; align-items: center; }
.pa-hero h2.pa-label { font-size: 13px; }
.pa-big { margin: 0; font-size: 36px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pa-stack { display: flex; height: 12px; overflow: hidden; border-radius: 999px; background: var(--pa-track); gap: 2px; }
.pa-stack > span { display: block; height: 100%; }
.pa-types { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.pa-type { display: grid; gap: 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; color: inherit; text-decoration: none; transition: border-color .15s, background .15s; }
.pa-type:hover { background: var(--pa-hover); }
.pa-type.is-on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pa-type-head { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; }
.pa-type-head .pa-muted { overflow: hidden; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.pa-type strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.pa-type > .pa-muted { font-size: 12.5px; }
.pa-chip { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--pa-track); color: var(--text); font-weight: 650; }
.pa-dot { display: inline-block; width: 9px; height: 9px; flex: none; border-radius: 50%; }
.pa-legend { display: flex; gap: 14px; color: var(--muted); font-size: 12.5px; }
.pa-legend span { display: inline-flex; align-items: center; gap: 6px; }

.pa-columns { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; align-items: end; height: 220px; }
.pa-col { display: grid; grid-template-rows: auto 1fr auto; gap: 6px; height: 100%; color: inherit; text-align: center; text-decoration: none; }
.pa-col-value { min-height: 16px; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.pa-col-track { grid-row: 2; display: flex; align-items: flex-end; justify-content: center; }
.pa-col-bar { display: flex; flex-direction: column; width: min(100%, 38px); min-height: 2px; overflow: hidden; border-radius: 6px 6px 2px 2px; background: var(--pa-track); transition: filter .15s; }
.pa-col-bar > span { display: block; width: 100%; }
.pa-col:hover .pa-col-bar { filter: brightness(1.08) saturate(1.1); }
.pa-col:hover .pa-col-label { color: var(--text); }
.pa-col-label { grid-row: 3; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: capitalize; }
.pa-details { margin-top: 14px; }
.pa-details summary { color: var(--muted); font-size: 13px; cursor: pointer; }
.pa-details[open] summary { margin-bottom: 10px; }

.pa-rank, .pa-suppliers { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.pa-rank-row, .pa-suppliers li { display: grid; grid-template-columns: minmax(0, 1fr) auto 56px; grid-template-areas: "name value share" "bar bar bar" "meta meta meta"; column-gap: 14px; row-gap: 6px; padding: 10px 12px; border-radius: 10px; color: inherit; text-decoration: none; }
.pa-suppliers li { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name value" "bar bar" "meta meta"; padding: 8px 0; }
.pa-rank-row:hover { background: var(--pa-hover); }
.pa-rank li.is-on .pa-rank-row { background: var(--pa-hover); box-shadow: inset 3px 0 0 var(--accent); }
.pa-rank li.is-muted .pa-rank-name { color: var(--muted); font-style: italic; }
.pa-rank-name { grid-area: name; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.pa-rank-value { grid-area: value; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.pa-rank-share { grid-area: share; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; }
.pa-rank-bar { grid-area: bar; display: block; height: 8px; overflow: hidden; border-radius: 999px; background: var(--pa-track); }
.pa-rank-bar > span { display: flex; height: 100%; min-width: 2px; overflow: hidden; border-radius: 999px; }
.pa-rank-bar > span > span { display: block; height: 100%; }
.pa-rank-meta { grid-area: meta; font-size: 12.5px; }
.pa-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin: 12px 0 0; padding: 12px 12px 0; border-top: 1px solid var(--line); }

.pa-close { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: var(--muted); text-decoration: none; }
.pa-close:hover { background: var(--pa-track); color: var(--text); }
.pa-detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: 28px; margin-top: 18px; }
.pa-doc-scroll { max-height: 520px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.pa-table { width: 100%; margin: 0; border-collapse: collapse; font-size: 13px; }
.pa-table th { position: sticky; top: 0; z-index: 1; }
.pa-table td.nowrap { white-space: nowrap; }
.pa-doc-party { width: 100%; max-width: 0; }
.pa-doc-lines { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 900px) {
  .pa-hero, .pa-detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .pa-card { padding: 16px; border-radius: 12px; }
  .pa-types { grid-template-columns: 1fr; }
  .pa-big { font-size: 30px; }
  .pa-columns { gap: 4px; height: 180px; }
  .pa-col-value { display: none; }
  .pa-rank-row { padding: 10px 4px; }
  .pa-head h1 { font-size: 24px; }
  .pa-controls { width: 100%; }
  .pa-controls .pa-seg { order: 3; flex: 1 0 100%; justify-content: space-between; }
  .pa-card-head .pa-seg { flex: 1 0 100%; justify-content: space-between; }
  .pa-seg a { padding: 6px 10px; }
  .pa-rank-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name name" "value share" "bar bar" "meta meta"; }
  .pa-rank-name { white-space: normal; }
  .pa-rank-value { text-align: left; }
}
.pa-more summary { padding: 8px 12px; color: var(--accent); font-size: 13px; font-weight: 650; cursor: pointer; }
.pa-rank-special { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.pa-rank-row { padding: 8px 12px; }

/* Resumo: linha compacta de valores (a receber, a pagar, vencimentos, impostos). */
.kpi-row-compact { gap: 10px; }
.kpi-row-compact .kpi { padding: 10px 14px; }
.kpi-row-compact .kpi-value { margin: 4px 0 2px; font-size: 20px; }
.kpi-row-compact .kpi-hint { font-size: 12px; }
.outstanding-row.kpi-row-compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .outstanding-row.kpi-row-compact { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .kpi-row .kpi-value { font-size: 20px; white-space: nowrap; }
}

/* Revogar uma marca na lista e na ficha do parceiro, ao lado do nome. */
.party-table .inline-form, .party-aliases .inline-form { display: inline; }
.party-aliases .inline-form { margin-left: 6px; }
.btn-link {
  background: none; border: 0; padding: 0 2px; min-height: 0;
  color: var(--muted, #6b7280); font: inherit; cursor: pointer; line-height: 1;
}
.btn-link:hover, .btn-link:focus-visible { color: var(--danger, #b42318); }
