/*
  Identidade visual — financeiro-rentabilidade-centro-custo.html
  ----------------------------------------------------------------
  Tema "analítico fintech": sidebar vertical escura à esquerda (lista de
  centros de custo, funciona como navegação) + área principal clara;
  acento verde-menta para indicadores acima da média/margem positiva e
  coral para margem/variação abaixo da média. Modo escuro em slate
  profundo (sidebar e área principal convergem para o mesmo tom escuro).
  Títulos em Space Grotesk — geométrica, "produto financeiro digital".

  Estrutura própria (prefixo "fc-" = finance cockpit), independente de
  dashboard-shared.css. Continua consumindo dashboard-shared.js — 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.

  Plugin extra usado nesta página: chartjs-chart-treemap@2.3.1 (via
  jsdelivr, versão fixa) para o gráfico (a) de receita por centro de
  custo.
*/

:root {
  color-scheme: light;

  --page-plane: #eef1f0;
  --surface-1: #ffffff;
  --surface-2: #e4e9e7;
  --text-primary: #10171a;
  --text-secondary: #54626a;
  --text-muted: #8b969c;
  --gridline: #dfe6e3;
  --baseline: #c3cdc9;
  --border-ring: rgba(16, 23, 26, 0.1);
  --success-text: #0f9a75;

  /* Acentos de marca — menta (bom/acima da média) e coral (abaixo da média) */
  --accent-mint: #12b488;
  --accent-mint-soft: #12b48820;
  --accent-coral: #ef5a4c;
  --accent-coral-soft: #ef5a4c20;
  /* Valores hex literais (não var() encadeado): getComputedStyle().getPropertyValue()
     em JS (dashVar(), usado pelo Chart.js) nem sempre resolve uma custom
     property cujo valor é outro var(), então --div-pos/--div-neg duplicam o
     hex de --accent-mint/--accent-coral em vez de referenciá-los. */
  --div-pos: #12b488;
  --div-neg: #ef5a4c;

  /* Categórico — ordem fixa, nunca ciclar. Afastado do trio
     verde/amarelo/vermelho reservado a status. */
  --series-1: #12b488;
  --series-2: #2f6f9e;
  --series-3: #caa23a;
  --series-4: #7c5cbf;
  --series-5: #2f9db0;
  --series-6: #c97a3f;
  --series-7: #4f5f8a;
  --series-8: #9c6d9e;

  /* Status — reservado, nunca usar como série */
  --status-good: #1f9e6f;
  --status-warning: #c9932e;
  --status-serious: #c96a3a;
  --status-critical: #c94b3a;

  /* Sidebar — sempre escura, independente do tema (contraste fixo) */
  --sidebar-bg: #0d1416;
  --sidebar-bg-raised: #131c1f;
  --sidebar-text: #d3dbd8;
  --sidebar-text-muted: #7c8a86;
  --sidebar-border: rgba(211, 219, 216, 0.1);
  --sidebar-active-bg: rgba(18, 180, 136, 0.16);

  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius-card: 14px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgba(16, 23, 26, 0.05), 0 10px 24px rgba(16, 23, 26, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page-plane: #0b0f12;
    --surface-1: #12181c;
    --surface-2: #182024;
    --text-primary: #eef1f0;
    --text-secondary: #aab4b8;
    --text-muted: #71797d;
    --gridline: #232c30;
    --baseline: #333e42;
    --border-ring: rgba(238, 241, 240, 0.1);
    --success-text: #2bd6a4;

    --accent-mint: #2bd6a4;
    --accent-mint-soft: #2bd6a42b;
    --accent-coral: #ff7a6b;
    --accent-coral-soft: #ff7a6b2b;
    --div-pos: #2bd6a4;
    --div-neg: #ff7a6b;

    --series-1: #2bd6a4;
    --series-2: #5b93c9;
    --series-3: #dcb85a;
    --series-4: #a486d4;
    --series-5: #4bc0d6;
    --series-6: #d68f5e;
    --series-7: #7e8fc2;
    --series-8: #c184c4;

    --status-good: #2bd6a4;
    --status-warning: #e0b158;
    --status-serious: #e08a5c;
    --status-critical: #e0605c;

    --sidebar-bg: #070a0b;
    --sidebar-bg-raised: #0d1315;
    --sidebar-active-bg: rgba(43, 214, 164, 0.16);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-plane: #0b0f12;
  --surface-1: #12181c;
  --surface-2: #182024;
  --text-primary: #eef1f0;
  --text-secondary: #aab4b8;
  --text-muted: #71797d;
  --gridline: #232c30;
  --baseline: #333e42;
  --border-ring: rgba(238, 241, 240, 0.1);
  --success-text: #2bd6a4;

  --accent-mint: #2bd6a4;
  --accent-mint-soft: #2bd6a42b;
  --accent-coral: #ff7a6b;
  --accent-coral-soft: #ff7a6b2b;
  --div-pos: #2bd6a4;
  --div-neg: #ff7a6b;

  --series-1: #2bd6a4;
  --series-2: #5b93c9;
  --series-3: #dcb85a;
  --series-4: #a486d4;
  --series-5: #4bc0d6;
  --series-6: #d68f5e;
  --series-7: #7e8fc2;
  --series-8: #c184c4;

  --status-good: #2bd6a4;
  --status-warning: #e0b158;
  --status-serious: #e08a5c;
  --status-critical: #e0605c;

  --sidebar-bg: #070a0b;
  --sidebar-bg-raised: #0d1315;
  --sidebar-active-bg: rgba(43, 214, 164, 0.16);
}

* {
  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;
}

/* ---------- Shell: sidebar + conteúdo ---------- */

.fc-shell {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}
@media (min-width: 880px) {
  .fc-shell {
    flex-direction: row;
  }
}

.fc-sidebar {
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
}
@media (min-width: 880px) {
  .fc-sidebar {
    width: 240px;
    border-bottom: none;
    border-right: 1px solid var(--sidebar-border);
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
  }
}

.fc-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}
.fc-sidebar-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent-mint-soft);
  color: var(--accent-mint);
  flex-shrink: 0;
}
.fc-sidebar-brand-mark .material-symbols-outlined {
  font-size: 18px;
}
.fc-sidebar-brand-text {
  min-width: 0;
}
.fc-sidebar-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sidebar-text-muted);
  margin: 0;
}
.fc-sidebar-title {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  margin: 1px 0 0;
  color: var(--sidebar-text);
  white-space: nowrap;
}

.fc-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--sidebar-text-muted);
  text-decoration: none;
  padding: 10px 18px;
  border-bottom: 1px solid var(--sidebar-border);
  white-space: nowrap;
}
.fc-back:hover {
  color: var(--accent-mint);
}
.fc-back .material-symbols-outlined {
  font-size: 16px;
}

.fc-nav-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sidebar-text-muted);
  padding: 14px 18px 8px;
  margin: 0;
}

.fc-nav {
  display: flex;
  flex-direction: column;
  padding: 0 8px 12px;
  gap: 2px;
  overflow-x: auto;
}
@media (max-width: 879px) {
  .fc-nav {
    flex-direction: row;
    padding: 8px 10px 12px;
    gap: 6px;
  }
}

.fc-nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--sidebar-text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-align: left;
  flex-shrink: 0;
}
.fc-nav-item:hover {
  background: var(--sidebar-bg-raised);
}
.fc-nav-item[aria-current="true"] {
  background: var(--sidebar-active-bg);
  border-color: var(--accent-mint);
  color: #fff;
}
.fc-nav-item .material-symbols-outlined {
  font-size: 17px;
  color: var(--sidebar-text-muted);
  flex-shrink: 0;
}
.fc-nav-item[aria-current="true"] .material-symbols-outlined {
  color: var(--accent-mint);
}
.fc-nav-item-name {
  flex: 1;
  min-width: 0;
}
.fc-nav-item-delta {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.fc-nav-item-delta.is-positive { color: var(--accent-mint); }
.fc-nav-item-delta.is-negative { color: var(--accent-coral); }

/* ---------- Conteúdo principal ---------- */

.fc-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.fc-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 22px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-ring);
}

.fc-titles {
  min-width: 0;
}
.fc-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-mint);
  margin: 0 0 2px;
}
.fc-title {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fc-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.fc-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);
  background: var(--accent-mint-soft);
  color: var(--success-text);
}
.fc-badge .material-symbols-outlined {
  font-size: 14px;
}

.fc-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-ring);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
}
.fc-theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.fc-main {
  flex: 1;
  padding: 20px 22px 28px;
  max-width: 1360px;
  width: 100%;
}

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

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

.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(--text-primary);
  color: var(--surface-1);
}
.dash-filter-chip:not([aria-pressed="true"]):hover {
  color: var(--text-primary);
}

.fc-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='%238b969c' 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;
}

/* ---------- KPI: cards compactos com sparkline ---------- */

.fc-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.fc-kpi-card {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 14px 16px;
  min-width: 0;
}

.fc-kpi-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 7px;
}

.fc-kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
}

.fc-kpi-value {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: proportional-nums;
}

.fc-kpi-delta {
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.fc-kpi-delta .material-symbols-outlined {
  font-size: 13px;
}
.fc-kpi-delta.is-good { color: var(--success-text); }
.fc-kpi-delta.is-bad { color: var(--accent-coral); }
.fc-kpi-delta.is-neutral { color: var(--text-muted); }

.fc-kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin: 5px 0 0;
}

.fc-kpi-spark {
  position: relative;
  margin-top: 8px;
  width: 100%;
  height: 34px;
}
.fc-kpi-spark canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ---------- Grid de cards ---------- */

.fc-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.fc-col-12 { grid-column: span 12; }
.fc-col-6 { grid-column: span 12; }
.fc-col-7 { grid-column: span 12; }
.fc-col-5 { grid-column: span 12; }
@media (min-width: 860px) {
  .fc-col-6 { grid-column: span 6; }
  .fc-col-7 { grid-column: span 7; }
  .fc-col-5 { grid-column: span 5; }
}

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

.fc-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.fc-card-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}
.fc-card-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin: 3px 0 0;
}
.fc-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.fc-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;
}
.fc-btn-ghost:hover {
  color: var(--accent-mint);
  border-color: var(--accent-mint);
}
.fc-btn-ghost[aria-pressed="true"] {
  color: var(--accent-mint);
  border-color: var(--accent-mint);
}

/* 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;
}

.fc-canvas-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 240px;
}
.fc-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;
}

/* ---------- Tabela (ranking) ---------- */

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

.fc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.fc-table caption {
  text-align: left;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.fc-table th,
.fc-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
.fc-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.fc-table tr.fc-row-highlight {
  background: var(--accent-mint-soft);
}
.fc-table td.fc-rank-name {
  font-family: var(--font-display);
  font-weight: 600;
}
.fc-table td.is-positive { color: var(--accent-mint); font-weight: 700; }
.fc-table td.is-negative { color: var(--accent-coral); font-weight: 700; }

/* ---------- Badge de status ---------- */

.fc-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);
}
.fc-badge-status .material-symbols-outlined {
  font-size: 14px;
}
.fc-badge-status--good { color: var(--status-good); background: color-mix(in srgb, var(--status-good) 14%, transparent); }
.fc-badge-status--warning { color: var(--status-warning); background: color-mix(in srgb, var(--status-warning) 20%, transparent); }
.fc-badge-status--serious { color: var(--status-serious); background: color-mix(in srgb, var(--status-serious) 20%, transparent); }
.fc-badge-status--critical { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 14%, transparent); }

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

.fc-footer {
  margin-top: 6px;
  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 ---------- */

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

@media (max-width: 480px) {
  .fc-title { font-size: 16px; }
  .fc-kpi-value { font-size: 19px; }
  .fc-main { padding: 14px 14px 20px; }
  .fc-topbar { padding: 12px 14px; }
}
