/*
  Identidade visual — financeiro-fluxo-caixa-dre.html
  ----------------------------------------------------
  Tema "relatório financeiro / private banking": papel off-white com
  verde-esmeralda profundo + grafite e um dourado discreto de acento;
  no escuro, verde-petróleo muito escuro com o mesmo dourado. Títulos em
  serifada (Fraunces) simulando a capa de um relatório impresso; corpo e
  números seguem em Inter para manter a leitura tabular limpa.

  Estrutura própria (prefixo "pb-" = private banking), independente de
  dashboard-shared.css: cabeçalho como capa de relatório, KPIs em formato
  de extrato (faixa horizontal com separadores, sem cards) e grid
  assimétrico (coluna larga + estreita). Continua consumindo
  dashboard-shared.js — por isso os tokens de tema, os seletores de tema
  claro/escuro e as classes/atributos usados pelo script (tema, legenda,
  toggle de tabela, chips de filtro) seguem o contrato descrito no
  cabeçalho do projeto.
*/

:root {
  color-scheme: light;

  /* Superfícies e tinta — papel off-white de relatório */
  --page-plane: #f5f2e7;
  --surface-1: #fbf9f1;
  --surface-2: #efeadb;
  --text-primary: #16231d;
  --text-secondary: #4d5c53;
  --text-muted: #85907f;
  --gridline: #ddd5bd;
  --baseline: #c2b795;
  --border-ring: rgba(22, 35, 29, 0.12);
  --success-text: #1f6f43;

  /* Marca */
  --brand-emerald: #0d3d2c;
  --brand-emerald-soft: #0d3d2c1a;
  --accent-gold: #a9812f;
  --accent-gold-soft: #a9812f22;

  /* Categórico — ordem fixa, nunca ciclar. Paleta afastada do trio
     verde/amarelo/vermelho de status (abaixo), tons de esmeralda, aço,
     dourado, ameixa, água, bronze, grafite-azulado e terracota. */
  --series-1: #1f6f54;
  --series-2: #2c5f8a;
  --series-3: #a9812f;
  --series-4: #6b4c7a;
  --series-5: #3f8f8a;
  --series-6: #8a6a4a;
  --series-7: #4a5a75;
  --series-8: #a3785a;

  /* Status — reservado, nunca usar como série */
  --status-good: #2f9163;
  --status-warning: #c08a2e;
  --status-serious: #b8642f;
  --status-critical: #a83e3e;

  --font-serif: "Fraunces", "Source Serif 4", Georgia, serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius-card: 10px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgba(22, 35, 29, 0.05), 0 8px 24px rgba(22, 35, 29, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page-plane: #071815;
    --surface-1: #0e2621;
    --surface-2: #123029;
    --text-primary: #f3efe0;
    --text-secondary: #b8c4bc;
    --text-muted: #7c8c83;
    --gridline: #1d3a33;
    --baseline: #2c4f46;
    --border-ring: rgba(243, 239, 224, 0.12);
    --success-text: #4fbf88;

    --brand-emerald: #3fae86;
    --brand-emerald-soft: #3fae8626;
    --accent-gold: #d4af5a;
    --accent-gold-soft: #d4af5a2b;

    --series-1: #3fae86;
    --series-2: #5b93c9;
    --series-3: #d4af5a;
    --series-4: #a486b6;
    --series-5: #5cbdb8;
    --series-6: #b0906a;
    --series-7: #8497bd;
    --series-8: #c9967a;

    --status-good: #4fbf88;
    --status-warning: #e0b158;
    --status-serious: #e08a5c;
    --status-critical: #e0605c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-plane: #071815;
  --surface-1: #0e2621;
  --surface-2: #123029;
  --text-primary: #f3efe0;
  --text-secondary: #b8c4bc;
  --text-muted: #7c8c83;
  --gridline: #1d3a33;
  --baseline: #2c4f46;
  --border-ring: rgba(243, 239, 224, 0.12);
  --success-text: #4fbf88;

  --brand-emerald: #3fae86;
  --brand-emerald-soft: #3fae8626;
  --accent-gold: #d4af5a;
  --accent-gold-soft: #d4af5a2b;

  --series-1: #3fae86;
  --series-2: #5b93c9;
  --series-3: #d4af5a;
  --series-4: #a486b6;
  --series-5: #5cbdb8;
  --series-6: #b0906a;
  --series-7: #8497bd;
  --series-8: #c9967a;

  --status-good: #4fbf88;
  --status-warning: #e0b158;
  --status-serious: #e08a5c;
  --status-critical: #e0605c;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--page-plane);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

.pb-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.pb-main {
  flex: 1;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px 28px;
}

/* ---------- Capa de relatório ---------- */

.pb-cover {
  background: var(--brand-emerald);
  color: #f3efe0;
  border-bottom: 3px solid var(--accent-gold);
  margin-bottom: 22px;
}

.pb-cover-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 14px 20px 20px;
}

.pb-cover-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.pb-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: #f3efe0;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(243, 239, 224, 0.35);
  white-space: nowrap;
}
.pb-back:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}
.pb-back .material-symbols-outlined {
  font-size: 16px;
}

.pb-cover-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.pb-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 11px 5px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(243, 239, 224, 0.3);
  color: #f3efe0;
}
.pb-badge .material-symbols-outlined {
  font-size: 14px;
}
.pb-badge--gold {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.pb-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(243, 239, 224, 0.35);
  background: transparent;
  color: #f3efe0;
  cursor: pointer;
  font-family: inherit;
}
.pb-theme-toggle:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.pb-cover-eyebrow {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-gold);
  margin: 0 0 6px;
}

.pb-cover-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(24px, 4.4vw, 36px);
  line-height: 1.15;
  margin: 0 0 16px;
  max-width: 720px;
}

.pb-cover-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 22px 36px;
  border-top: 1px solid rgba(243, 239, 224, 0.22);
  padding-top: 14px;
}

.pb-cover-meta-item {
  min-width: 0;
}
.pb-cover-meta-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(243, 239, 224, 0.6);
  margin: 0 0 3px;
}
.pb-cover-meta-value {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  color: #f3efe0;
}

/* ---------- Filtros ---------- */

.pb-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.dash-filter-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius-pill);
  padding: 4px;
}

.dash-filter-chip {
  appearance: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
}
.dash-filter-chip[aria-pressed="true"] {
  background: var(--brand-emerald);
  color: #f3efe0;
}
.dash-filter-chip:not([aria-pressed="true"]):hover {
  color: var(--text-primary);
}

.pb-select {
  appearance: none;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius-pill);
  padding: 8px 30px 8px 14px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2385907f' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ---------- Extrato de KPIs (sem cards, separadores verticais) ---------- */

.pb-statement {
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
  overflow: hidden;
}
@media (min-width: 760px) {
  .pb-statement {
    flex-direction: row;
  }
}

.pb-statement-item {
  flex: 1;
  min-width: 0;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gridline);
}
.pb-statement-item:last-child {
  border-bottom: none;
}
@media (min-width: 760px) {
  .pb-statement-item {
    border-bottom: none;
    border-right: 1px solid var(--gridline);
  }
  .pb-statement-item:last-child {
    border-right: none;
  }
}

.pb-statement-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.pb-statement-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.pb-statement-value {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: proportional-nums;
}

.pb-statement-delta {
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.pb-statement-delta .material-symbols-outlined {
  font-size: 14px;
}
.pb-statement-delta.is-good { color: var(--success-text); }
.pb-statement-delta.is-bad { color: var(--status-critical); }
.pb-statement-delta.is-neutral { color: var(--text-muted); }

.pb-statement-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 6px 0 0;
}

.pb-statement-spark {
  position: relative;
  margin-top: 10px;
  width: 100%;
  height: 26px;
}
.pb-statement-spark canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ---------- Grid assimétrico ---------- */

.pb-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.pb-col-12 { grid-column: span 12; }
.pb-col-8 { grid-column: span 12; }
.pb-col-4 { grid-column: span 12; }
@media (min-width: 900px) {
  .pb-col-8 { grid-column: span 8; }
  .pb-col-4 { grid-column: span 4; }
}

.pb-card {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 18px 20px 16px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.pb-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.pb-card-title {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}
.pb-card-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin: 3px 0 0;
}

.pb-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pb-btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-ring);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.pb-btn-ghost:hover {
  color: var(--brand-emerald);
  border-color: var(--brand-emerald);
}
.pb-btn-ghost[aria-pressed="true"] {
  color: var(--brand-emerald);
  border-color: var(--brand-emerald);
}

/* Grupo canvas + legenda — classe exigida pelo shared.js (toggle "ver tabela") */
.dash-chart-body {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.dash-chart-body.is-hidden {
  display: none;
}

.pb-canvas-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 240px;
}
.pb-canvas-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.dash-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 16px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.dash-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.dash-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ---------- Meter (meta de margem) ---------- */

.pb-meter-row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 7px;
}

.pb-meter {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.pb-meter-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--brand-emerald);
}
.pb-meter-fill.is-warning { background: var(--status-warning); }
.pb-meter-fill.is-critical { background: var(--status-critical); }

.pb-facts {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pb-facts li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  gap: 10px;
}
.pb-facts span:first-child {
  color: var(--text-secondary);
}
.pb-facts strong {
  font-weight: 700;
  color: var(--text-primary);
}

/* ---------- Ranking textual (top despesas) ---------- */

.pb-rank-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.pb-rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 12.5px;
}
.pb-rank-item:last-child {
  border-bottom: none;
}
.pb-rank-index {
  font-family: var(--font-serif);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-gold);
  width: 18px;
  flex-shrink: 0;
}
.pb-rank-name {
  flex: 1;
  min-width: 0;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pb-rank-value {
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ---------- Tabelas ---------- */

.pb-table-wrap {
  display: none;
  overflow-x: auto;
  margin-top: 10px;
}
.pb-table-wrap.is-visible {
  display: block;
}

.pb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.pb-table caption {
  text-align: left;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.pb-table th,
.pb-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
.pb-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Demonstrativo contábil: subtotais em negrito, resultado final destacado
   em dourado, negativos entre parênteses (classe aplicada no <td>). */
.pb-table--dre .pb-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.pb-table--dre tr.is-subtotal td {
  font-weight: 700;
  border-top: 1px solid var(--baseline);
  border-bottom: 1px solid var(--baseline);
}
.pb-table--dre tr.is-final td {
  font-weight: 700;
  font-size: 14px;
  color: var(--brand-emerald);
  border-top: 2px solid var(--accent-gold);
  border-bottom: 2px solid var(--accent-gold);
}
:root[data-theme="dark"] .pb-table--dre tr.is-final td {
  color: var(--accent-gold);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .pb-table--dre tr.is-final td {
    color: var(--accent-gold);
  }
}
.pb-table--dre .is-negative {
  color: var(--text-secondary);
}

/* ---------- Badge de status (aging) ---------- */

.pb-badge-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px 3px 7px;
  border-radius: var(--radius-pill);
}
.pb-badge-status .material-symbols-outlined {
  font-size: 14px;
}
.pb-badge-status--good { color: var(--status-good); background: color-mix(in srgb, var(--status-good) 14%, transparent); }
.pb-badge-status--warning { color: var(--status-warning); background: color-mix(in srgb, var(--status-warning) 20%, transparent); }
.pb-badge-status--serious { color: var(--status-serious); background: color-mix(in srgb, var(--status-serious) 20%, transparent); }
.pb-badge-status--critical { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 14%, transparent); }

/* ---------- Rodapé ---------- */

.pb-footer {
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border-ring);
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- Utilitários ---------- */

.pb-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .pb-cover-title { font-size: 22px; }
  .pb-statement-value { font-size: 20px; }
  .pb-main { padding: 0 14px 20px; }
  .pb-cover-inner { padding: 12px 14px 16px; }
}
