/* =========================================================
   DASHBOARD CORPORATIVO — SISTEMA DE DESIGN ÚNICO
   ---------------------------------------------------------
   Todas as abas (Demanda Final, Meta Interna, Compras,
   Vendas e Dashboard Analítico) usam EXATAMENTE os mesmos
   tokens, componentes e paleta definidos neste arquivo.
   Nenhuma aba tem estilo próprio.

   1. Tokens (cores, tipografia, espaço, sombra)
   2. Base
   3. Topbar
   4. Estado vazio
   5. Abas + cabeçalho de view
   6. Barra de filtros
   7. Cards de KPI
   8. Cards de gráfico
   9. Cards de tabela
   10. Avisos / badges
   11. Loading
   12. Responsivo
   ========================================================= */

/* ============ 1. TOKENS ============ */
:root{
  /* --- Marca: petróleo/teal (identidade única do dashboard) --- */
  --brand-900: #1b2834;
  --brand-800: #263846;
  --brand-700: #344e5e;
  --brand-600: #496675;
  --brand-500: #607d89;
  --brand-400: #879da5;
  --brand-300: #afbec3;
  --brand-200: #d2dcdf;
  --brand-100: #e9eef0;
  --brand-050: #f5f7f8;

  /* --- Semânticas (mesmo significado em TODAS as abas) --- */
  --success-600: #49677d;
  --success-500: #5a7890;
  --success-100: #edf1f4;

  --danger-600:  #665873;
  --danger-500:  #786887;
  --danger-100:  #f0edf3;

  --accent-600:  #896126;
  --accent-500:  #a77c39;
  --accent-100:  #f5efe5;

  /* Aliases de leitura executiva usados em cards, tabelas e gráficos */
  --m-demanda:      #426989;
  --m-demanda-soft: #e9eff4;
  --m-meta:         #a77c39;
  --m-meta-soft:    var(--accent-100);
  --m-entradas:     #50778c;
  --m-entradas-soft:var(--success-100);
  --m-saidas:       #786887;
  --m-saidas-soft:  var(--danger-100);
  --m-saldo:        #263846;
  --m-saldo-soft:   #e9edef;

  /* --- Paleta categórica dos gráficos (lida pelo charts.js) --- */
  --cat-1: #354f62;
  --cat-2: #48677c;
  --cat-3: #5d778b;
  --cat-4: #718797;
  --cat-5: #8295a2;
  --cat-6: #666f7c;
  --cat-7: #7d8792;
  --cat-8: #98a3ab;

  /* --- Neutros --- */
  --color-bg:            #f2f4f6;
  --color-surface:       #ffffff;
  --color-surface-alt:   #f7f8f9;
  --color-border:        #dce2e6;
  --color-border-strong: #c4ced4;
  --color-text:          #263744;
  --color-text-muted:    #667580;
  --color-text-soft:     #8d99a2;

  /* Compatibilidade com nomes antigos (não usar em código novo) */
  --color-ink-900: var(--brand-900);
  --color-ink-700: var(--brand-700);
  --color-ink-600: var(--brand-600);
  --color-ink-500: var(--brand-500);
  --color-ink-100: var(--brand-100);
  --color-gray-100: var(--color-surface-alt);
  --color-gray-200: #e8eef1;
  --color-success: var(--success-500);
  --color-warning: var(--accent-500);
  --color-danger:  var(--danger-500);

  /* --- Tipografia --- */
  --font-main: 'Segoe UI Variable', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --fs-eyebrow: .70rem;
  --fs-label:   .74rem;
  --fs-sm:      .82rem;
  --fs-base:    .88rem;
  --fs-title:   .95rem;
  --fs-kpi:     1.55rem;

  /* --- Raio / sombra / espaço --- */
  --radius-lg: 10px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --gap:       18px;

  --shadow-sm: 0 1px 2px rgba(16, 42, 67, .04), 0 2px 8px rgba(16, 42, 67, .035);
  --shadow-md: 0 8px 24px rgba(16, 42, 67, .09);
}

/* ============ 2. BASE ============ */
*{ box-sizing: border-box; }

body{
  margin:0;
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--fs-base);
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3{ margin:0; }

code{
  background: var(--brand-100);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--brand-700);
  font-size: .92em;
}

/* Todo número do dashboard usa numeral tabular */
.kpi-value,
.ranking-table td,
.gap-table td,
.table-card-footer{ font-variant-numeric: tabular-nums; }

::selection{ background: var(--brand-200); }

:focus-visible{
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
}

/* ============ 3. TOPBAR ============ */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 16px;
  padding: 13px 32px;
  background: var(--brand-900);
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
  box-shadow: 0 5px 18px rgba(16,42,67,.16);
}

.topbar-brand{ display:flex; align-items:center; gap: 12px; }

.brand-icon{
  width: 62px;
  height: 40px;
  padding: 4px 6px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,.95);
  border: 1px solid rgba(255,255,255,.14);
  color:#fff;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 1.15rem;
  flex-shrink: 0;
}
.brand-icon img{ width:100%; height:100%; object-fit:contain; }

.brand-text{ display:flex; flex-direction:column; line-height:1.2; }
.brand-title{ font-weight:750; font-size: 1.08rem; color: #fff; letter-spacing:-.01em; }
.brand-subtitle{ font-size: .70rem; color: rgba(255,255,255,.62); letter-spacing:.02em; }

.topbar-actions{ display:flex; align-items:center; gap: 10px; flex-wrap: wrap; }

.data-health{
  display:flex;
  flex-direction:column;
  gap:3px;
  padding-right:14px;
  margin-right:2px;
  border-right:1px solid rgba(255,255,255,.13);
}
.data-health-label{
  color:rgba(255,255,255,.46);
  font-size:.61rem;
  font-weight:800;
  letter-spacing:.1em;
  line-height:1;
  text-transform:uppercase;
}
.data-health-row{ display:flex; align-items:center; gap:9px; min-height:25px; }

.status-badge{
  font-size: .74rem;
  padding: 0;
  display:inline-flex;
  align-items:center;
  gap: 6px;
  font-weight: 700;
  border: 0;
  background:transparent !important;
}
.status-badge i{ font-size:.62rem; }
.status-disconnected{ color: rgba(255,255,255,.7); }
.status-disconnected i{ color:#d7a54a; }
.status-connected{ color: #dce8f0; }
.status-connected i{ color:#8eabc0; }
.status-loading{ color: #dcebed; }
.status-loading i{ color:var(--brand-300); animation:sync-spin 1s linear infinite; font-size:.78rem; }
.status-error{ color:#e6dfea; }
.status-error i{ color:#aa96b5; }
@keyframes sync-spin{ to{ transform:rotate(360deg); } }

/* Selo com a data/hora da última leitura da pasta */
.update-stamp{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .70rem;
  font-weight: 500;
  color: rgba(255,255,255,.57);
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  white-space: nowrap;
}
.update-stamp i{ color: var(--brand-300); }
.update-stamp.is-stale{
  background: transparent;
  color: #f0c36d;
}
.update-stamp.is-stale i{ color: var(--accent-500); }

.topbar-actions .btn{
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: var(--fs-sm);
  display:inline-flex;
  align-items:center;
  gap: 6px;
}
.btn-source{
  color:rgba(255,255,255,.82);
  background:transparent;
  border:1px solid rgba(255,255,255,.22);
}
.btn-source:hover,
.btn-source:focus{
  color:#fff;
  background:rgba(255,255,255,.08);
  border-color:rgba(255,255,255,.4);
}
.btn-logout{
  color:rgba(255,255,255,.72);
  background:transparent;
  border:1px solid rgba(255,255,255,.18);
}
.btn-logout:hover,
.btn-logout:focus{
  color:#fff;
  background:rgba(255,255,255,.08);
  border-color:rgba(255,255,255,.35);
}
.sync-group{ box-shadow:0 4px 14px rgba(0,0,0,.13); border-radius:var(--radius-sm); }
.btn-sync{
  color:#fff;
  background:var(--brand-500);
  border-color:var(--brand-500);
  font-weight:700 !important;
}
.btn-sync:hover,
.btn-sync:focus{
  color:#fff;
  background:var(--brand-700);
  border-color:var(--brand-700);
}
.btn-sync:disabled{
  color:rgba(255,255,255,.55);
  background:rgba(255,255,255,.1);
  border-color:rgba(255,255,255,.12);
}
.btn-primary{
  background: var(--brand-500);
  border-color: var(--brand-500);
}
.btn-primary:hover,
.btn-primary:focus{
  background: var(--brand-900);
  border-color: var(--brand-900);
}
.btn-outline-secondary{
  color: rgba(255,255,255,.88);
  border-color: rgba(255,255,255,.25);
}
.btn-outline-secondary:hover{
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.42);
  color: #fff;
}

.refresh-dropdown{
  padding: 8px;
  min-width: 310px;
  border-radius: var(--radius-md);
  border-color: var(--color-border);
  box-shadow: var(--shadow-md);
}
.refresh-dropdown-header{
  display:flex;
  align-items:center;
  gap:11px;
  padding:8px 8px 12px;
  margin-bottom:3px;
  border-bottom:1px solid var(--color-border);
}
.refresh-dropdown-icon{
  width:34px;
  height:34px;
  border-radius:8px;
  display:flex;
  align-items:center;
  justify-content:center;
  color:var(--brand-700);
  background:var(--brand-100);
  flex-shrink:0;
}
.refresh-dropdown-header strong{
  display:block;
  color:var(--brand-900);
  font-size:.82rem;
  line-height:1.2;
}
.refresh-dropdown-header small{
  display:block;
  margin-top:2px;
  color:var(--color-text-muted);
  font-size:.69rem;
}
.refresh-dropdown-title{
  display:block;
  font-size: var(--fs-eyebrow);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-muted);
  padding: 4px 6px 8px;
}
.refresh-dropdown-item{
  display:flex;
  align-items:center;
  gap: 8px;
  padding: 8px 9px;
  font-size: var(--fs-base);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 0;
}
.refresh-dropdown-item:hover{ background: var(--brand-100); }
.refresh-dropdown-item input{ cursor: pointer; accent-color: var(--brand-600); }
.refresh-dropdown-actions{
  display:flex;
  align-items:center;
  gap: 6px;
  margin-top: 6px;
  padding: 9px 4px 2px;
  border-top: 1px solid var(--color-border);
}
.refresh-dropdown-actions .btn-link{
  font-size: var(--fs-sm);
  padding: 4px 6px;
  color: var(--brand-600);
  text-decoration: none;
}
.refresh-dropdown-actions .btn-primary{ margin-left: auto; font-size: .74rem; white-space:nowrap; }

/* ============ 4. ESTADO VAZIO ============ */
.empty-state{
  max-width: 980px;
  margin: clamp(34px, 8vh, 78px) auto;
  padding: 0 24px;
  color: var(--color-text-muted);
}
.empty-onboarding{
  display:grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, .75fr);
  overflow:hidden;
  background:var(--color-surface);
  border:1px solid var(--color-border);
  border-radius:14px;
  box-shadow:0 20px 50px rgba(16,42,67,.10);
}
.empty-onboarding-main{
  padding:48px 52px 44px;
  border-top:4px solid var(--brand-500);
}
.empty-kicker{
  display:block;
  margin-bottom:18px;
  color:var(--brand-600);
  font-size:.67rem;
  font-weight:800;
  letter-spacing:.11em;
  text-transform:uppercase;
}
.empty-icon{
  width:52px;
  height:52px;
  display:flex;
  align-items:center;
  justify-content:center;
  margin-bottom:20px;
  border-radius:12px;
  color:var(--brand-700);
  background:var(--brand-100);
  font-size:1.35rem;
}
.empty-state .empty-icon i{ color:inherit; font-size:inherit; margin:0; display:inline; }
.empty-state h2{
  margin:0 0 11px;
  color:var(--brand-900);
  font-size:1.7rem;
  font-weight:760;
  letter-spacing:-.03em;
}
.empty-lead{
  max-width:560px;
  margin:0 0 25px;
  color:var(--color-text-muted);
  font-size:.94rem;
  line-height:1.6;
}
.empty-cta{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:11px 18px;
  color:#fff;
  background:var(--brand-700);
  border:1px solid var(--brand-700);
  border-radius:7px;
  font-size:.85rem;
  font-weight:700;
  box-shadow:0 5px 14px rgba(31,79,111,.18);
}
.empty-cta:hover,
.empty-cta:focus{ color:#fff; background:var(--brand-900); border-color:var(--brand-900); }
.empty-privacy{
  display:flex;
  align-items:center;
  gap:7px;
  margin:18px 0 0;
  color:var(--color-text-soft);
  font-size:.72rem;
}
.empty-privacy i{ color:var(--success-500); }
.empty-onboarding-aside{
  padding:46px 32px 34px;
  background:#f7fafb;
  border-left:1px solid var(--color-border);
}
.empty-aside-label{
  display:block;
  margin-bottom:17px;
  color:var(--color-text-muted);
  font-size:.67rem;
  font-weight:800;
  letter-spacing:.09em;
  text-transform:uppercase;
}
.empty-onboarding-aside ul{ list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:17px; }
.empty-onboarding-aside li{ display:flex; align-items:flex-start; gap:10px; }
.empty-onboarding-aside li > i{
  width:20px;
  height:20px;
  display:flex;
  align-items:center;
  justify-content:center;
  flex-shrink:0;
  border-radius:50%;
  color:var(--success-600);
  background:var(--success-100);
  font-size:.72rem;
}
.empty-onboarding-aside li span{ display:flex; flex-direction:column; gap:1px; }
.empty-onboarding-aside li strong{ color:var(--brand-900); font-size:.8rem; }
.empty-onboarding-aside li small{ color:var(--color-text-muted); font-size:.72rem; }
.empty-details{ margin-top:27px; padding-top:16px; border-top:1px solid var(--color-border); }
.empty-details summary{ color:var(--brand-700); font-size:.74rem; font-weight:700; cursor:pointer; }
.empty-details p{ margin:10px 0 0; color:var(--color-text-muted); font-size:.7rem; line-height:1.6; }

/* ============ 5. ABAS + CABEÇALHO DE VIEW ============ */
.app-content{
  padding: 22px 32px 72px;
  max-width: 1800px;
  margin: 0 auto;
}

.view-tabs{
  display:flex;
  gap: 4px;
  margin-bottom: 24px;
  padding: 5px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 9px;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.view-tab{
  display:flex;
  align-items:center;
  gap: 8px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  font-weight: 650;
  font-size: var(--fs-base);
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.view-tab i{ font-size: 1rem; opacity: .85; }
.view-tab:hover{ background: var(--brand-050); color: var(--brand-700); }
.view-tab.is-active{
  background: var(--brand-800);
  color: #fff;
  box-shadow: 0 2px 7px rgba(16,42,67,.16);
}
.view-tab.is-active i{ opacity: 1; }

.view-intro{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap: 28px;
  margin: 2px 2px 18px;
  padding: 0 2px 16px;
  border-bottom: 1px solid var(--color-border);
}
.view-intro h1{
  margin: 3px 0 0;
  color: var(--brand-900);
  font-size: 1.48rem;
  font-weight: 760;
  letter-spacing: -.025em;
}
.view-intro p{
  max-width: 620px;
  margin: 0;
  color: var(--color-text-muted);
  font-size: .82rem;
  line-height: 1.5;
  text-align: right;
}
.view-eyebrow{
  color: var(--brand-600);
  font-size: .67rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

/* O nome da aba aparece só no botão da barra de abas — sem título
   repetido dentro da view, para não gastar altura de tela. */

/* ============ 6. BARRA DE FILTROS ============ */
/* Faixa única e baixa: rótulo pequeno em caixa alta, e abaixo dele um
   grupo de chips (filtros curtos) ou um dropdown compacto com caixas de
   seleção (filtros longos). Os <select multiple> nativos continuam no
   HTML como fonte de verdade, apenas escondidos — ver js/filtros-ui.js. */

.filter-bar{
  display:flex;
  flex-wrap: wrap;
  gap: 13px 16px;
  align-items: flex-end;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 9px;
  padding: 15px 18px 16px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  border-top: 2px solid var(--brand-700);
}

.filter-item{
  display:flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  flex: 0 1 auto;
}

.filter-item label{
  font-size: var(--fs-label);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--color-text-muted);
  display:flex;
  align-items:center;
  gap: 5px;
}
.filter-item label i{ color: var(--brand-500); font-size: .85rem; }

/* O select nativo vira fonte de dados invisível assim que a camada de
   UI assume. Sem JS, ele continua visível e utilizável. */
select.filtro-nativo{ display: none !important; }

/* --- Chips (Operação, Ano, Tipo de Operação) --- */
.chip-group{
  display:inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 3px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: 10px;
}

.chip{
  appearance: none;
  border: none;
  background: transparent;
  border-radius: 7px;
  padding: 6px 11px;
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: inherit;
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background .13s ease, color .13s ease;
}
.chip:hover{ background: var(--brand-100); color: var(--brand-700); }
.chip.is-active{ background: var(--brand-700); color: #fff; }
.chip.is-active:hover{ background: var(--brand-900); color: #fff; }
.chip.is-empty{ color: var(--color-text-soft); cursor: default; font-weight: 500; }
.chip.is-empty:hover{ background: transparent; color: var(--color-text-soft); }

/* --- Dropdown com caixas de seleção (Mês, Tipo, Categoria, ...) --- */
/* Os itens com dropdown esticam para ocupar a faixa e encolhem em telas
   estreitas, mantendo a barra em uma única linha. Os chips ficam sempre
   do tamanho do conteúdo. */
.filter-item-dropdown{
  flex: 0 1 140px;   /* não cresce; encolhe quando a barra aperta */
  min-width: 0;      /* sem isso o conteúdo trava o encolhimento */
}
.filter-item-chips{ flex: 0 0 auto; }
/* Rótulo longo ("Tipo de Operação") não pode ditar a largura mínima */
.filter-item-dropdown label{ overflow: hidden; }
.filter-item-dropdown label span,
.filter-item-dropdown label{ white-space: nowrap; text-overflow: ellipsis; }

.filtro-drop{ position: relative; width: 100%; }

.filtro-drop-btn{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: 8px;
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition: border-color .13s ease, box-shadow .13s ease;
}
.filtro-drop-btn i{ font-size: .7rem; color: var(--color-text-soft); flex-shrink: 0; }
.filtro-drop-btn:hover{ border-color: var(--brand-400); }
.filtro-drop.is-aberto .filtro-drop-btn,
.filtro-drop-btn:focus-visible{
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
  outline: none;
}
.filtro-drop-btn.is-filtrado{
  border-color: var(--brand-400);
  background: var(--brand-050);
  color: var(--brand-800);
}
.filtro-drop-texto{
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filtro-drop-texto.is-vazio{ color: var(--color-text-muted); font-weight: 500; }

.filtro-drop-menu{
  display: none;
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  z-index: 60;
  min-width: 100%;
  width: max-content;
  max-width: 300px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.filtro-drop.is-aberto .filtro-drop-menu{ display: block; }

.filtro-drop-busca{
  position: relative;
  padding: 8px 8px 4px;
}
.filtro-drop-busca i{
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-25%);
  font-size: .8rem;
  color: var(--color-text-soft);
}
.filtro-drop-busca input{
  width: 100%;
  height: 30px;
  padding: 0 8px 0 27px;
  border: 1px solid var(--color-border-strong);
  border-radius: 6px;
  font-size: var(--fs-sm);
  font-family: inherit;
  color: var(--color-text);
}
.filtro-drop-busca input:focus{
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}

.filtro-drop-lista{
  max-height: 244px;
  overflow-y: auto;
  padding: 4px;
}

.filtro-drop-item{
  display:flex;
  align-items:center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 6px;
  font-size: var(--fs-sm);
  color: var(--color-text);
  cursor: pointer;
  margin: 0;
  white-space: nowrap;
}
.filtro-drop-item:hover{ background: var(--brand-050); }
.filtro-drop-item.is-active{ color: var(--brand-800); font-weight: 600; }
.filtro-drop-item input{
  accent-color: var(--brand-600);
  width: 15px;
  height: 15px;
  cursor: pointer;
  flex-shrink: 0;
}

.filtro-drop-vazio{
  margin: 0;
  padding: 12px 10px;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  text-align: center;
}

.filtro-drop-acoes{
  display:flex;
  gap: 4px;
  padding: 6px 8px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-alt);
}
.filtro-drop-acao{
  flex: 1;
  border: none;
  background: transparent;
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--brand-600);
  cursor: pointer;
}
.filtro-drop-acao:hover{ background: var(--brand-100); color: var(--brand-900); }

/* --- Selects simples (Ano/Mês da Visão Consolidada) --- */
.filter-item select:not([multiple]){
  height: 36px;
  min-width: 158px;
  padding: 0 11px;
  border: 1px solid var(--color-border-strong);
  border-radius: 8px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--color-text);
  background-color: var(--color-surface);
}
.filter-item select:not([multiple]):focus{
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}

/* Sem JS: o select múltiplo nativo mantém um tamanho utilizável */
.filter-item select[multiple]{
  min-height: 74px;
  min-width: 158px;
  border-radius: 8px;
  border: 1px solid var(--color-border-strong);
  font-size: var(--fs-sm);
}

.filter-clear{ flex: 0 0 auto; margin-left: auto; }
.filter-clear .btn{
  font-size: var(--fs-sm);
  color: var(--brand-600);
  font-weight: 600;
  text-decoration: none;
  padding: 8px 4px;
}
.filter-clear .btn:hover{ color: var(--brand-900); }

/* Dica informativa dentro da barra de filtros */
.filter-hint,
.da-filter-hint{
  margin-left: auto;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-050);
  border: 1px solid var(--brand-100);
  border-radius: 999px;
  padding: 7px 14px;
}
.filter-hint i,
.da-filter-hint i{ color: var(--brand-500); }
.da-date-input{
  width: 154px;
  height: 36px;
  border: 1px solid var(--color-border-strong);
  border-radius: 8px;
  color: var(--color-text);
  background: var(--color-surface);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.da-date-input:focus{
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}

/* ============ 7. CARDS DE KPI ============ */
.kpi-row{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: var(--gap);
  margin-bottom: 26px;
}
.kpi-row-home{ grid-template-columns: repeat(4, 1fr); }
.da-kpi-row{ grid-template-columns: repeat(4, 1fr); }

/* Componente único de card. A cor vem sempre de --kpi-accent,
   nunca de regras específicas de aba. */
.kpi-card,
.kpi-card-da{
  --kpi-accent: var(--brand-500);
  --kpi-accent-soft: var(--brand-100);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--kpi-accent);
  border-radius: var(--radius-lg);
  padding: 17px 18px 18px;
  display:flex;
  align-items:center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
  min-width: 0;
}
.kpi-card:hover,
.kpi-card-da:hover{ box-shadow: 0 5px 18px rgba(16,42,67,.075); }

.kpi-icon{
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--kpi-accent-soft);
  color: var(--kpi-accent);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.kpi-body{ display:flex; flex-direction:column; gap: 2px; min-width: 0; }
.kpi-label{
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .065em;
  line-height: 1.25;
}
.kpi-value{
  font-size: var(--fs-kpi);
  font-weight: 800;
  color: var(--brand-900);
  line-height: 1.2;
  letter-spacing: -.02em;
}

/* --- Modificadores semânticos (valem igual em todas as abas) --- */
.kpi-brand   { --kpi-accent: var(--brand-500);   --kpi-accent-soft: var(--brand-100); }
.kpi-accent  { --kpi-accent: var(--m-meta);      --kpi-accent-soft: var(--m-meta-soft); }
.kpi-success { --kpi-accent: var(--m-entradas);  --kpi-accent-soft: var(--m-entradas-soft); }
.kpi-danger  { --kpi-accent: var(--m-saidas);    --kpi-accent-soft: var(--m-saidas-soft); }
.kpi-neutral { --kpi-accent: var(--color-border-strong); --kpi-accent-soft: var(--color-surface-alt); }
.kpi-neutral .kpi-icon{ color: var(--brand-600); }

/* Card de destaque: o primeiro card de CADA aba (métrica-título) */
.kpi-total{
  background: linear-gradient(135deg, var(--brand-900), var(--brand-700));
  border-color: transparent;
  border-top-color: var(--brand-400);
}
.kpi-total .kpi-label{ color: rgba(255,255,255,.78); }
.kpi-total .kpi-value{ color: #fff; }
.kpi-total .kpi-icon{ background: rgba(255,255,255,.16); color: #fff; }

/* Compatibilidade com nomes antigos usados no HTML/JS */
.kpi-primary{ background: linear-gradient(135deg, var(--brand-900), var(--brand-700)); border-color: transparent; border-top-color: var(--brand-400); }
.kpi-primary .kpi-label{ color: rgba(255,255,255,.78); }
.kpi-primary .kpi-value{ color: #fff; }
.kpi-primary .kpi-icon{ background: rgba(255,255,255,.16); color: #fff; }
.kpi-meta{ --kpi-accent: var(--m-meta); --kpi-accent-soft: var(--m-meta-soft); }
.kpi-entradas{ --kpi-accent: var(--m-entradas); --kpi-accent-soft: var(--m-entradas-soft); }
.kpi-vendas{ --kpi-accent: var(--m-saidas); --kpi-accent-soft: var(--m-saidas-soft); }

/* Estados dinâmicos do Dashboard Analítico (aplicados via JS) */
.da-saldo.da-negativo{ --kpi-accent: var(--m-saidas); --kpi-accent-soft: var(--m-saidas-soft); }
.da-saldo.da-negativo .kpi-value{ color: var(--danger-600); }
.da-percentual.da-meta-ok{ --kpi-accent: var(--m-entradas); --kpi-accent-soft: var(--m-entradas-soft); }
.da-percentual.da-meta-ok .kpi-value{ color: var(--success-600); }
.da-percentual.da-meta-atencao{ --kpi-accent: var(--m-meta); --kpi-accent-soft: var(--m-meta-soft); }
.da-percentual.da-meta-atencao .kpi-value{ color: var(--accent-600); }
.da-percentual.da-meta-critico{ --kpi-accent: var(--m-saidas); --kpi-accent-soft: var(--m-saidas-soft); }
.da-percentual.da-meta-critico .kpi-value{ color: var(--danger-600); }

.kpi-lg{ padding: 20px 20px; }
.kpi-lg .kpi-value{ font-size: 1.8rem; }
.kpi-lg .kpi-icon{ width: 50px; height: 50px; font-size: 1.35rem; }
.kpi-gap-negativo{ --kpi-accent: var(--m-saidas); --kpi-accent-soft: var(--m-saidas-soft); }
.kpi-gap-negativo .kpi-value{ color: var(--danger-600); }

/* ============ 8. CARDS DE GRÁFICO ============ */
.chart-grid{
  display:grid;
  gap: var(--gap);
  margin-bottom: 26px;
}
.chart-grid-3{ grid-template-columns: repeat(3, 1fr); }
.chart-grid-2{ grid-template-columns: repeat(2, 1fr); }
.chart-grid-1{ grid-template-columns: 1fr; }
.da-chart-grid-main{ grid-template-columns: 2fr 1fr; }
.da-chart-grid-performance{ grid-template-columns: 2fr 1fr 1fr; }

.da-section-heading{
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin: 28px 2px 12px;
}
.da-section-heading h2{
  margin: 2px 0 0;
  color: var(--color-text);
  font-size: 1.08rem;
  font-weight: 750;
  letter-spacing: -.01em;
}
.da-section-heading p{
  max-width: 560px;
  margin: 0;
  color: var(--color-text-muted);
  font-size: .79rem;
  text-align: right;
}
.da-section-kicker{
  color: var(--brand-600);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.chart-card{
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  display:flex;
  flex-direction:column;
  overflow:hidden;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.chart-card:hover{ border-color: var(--color-border-strong); box-shadow: 0 4px 18px rgba(16,42,67,.065); }

.chart-card-header{
  padding: 15px 18px 13px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.chart-card-header h3{
  font-size: var(--fs-title);
  font-weight: 720;
  color: var(--brand-900);
  display:flex;
  align-items:center;
  gap: 8px;
  letter-spacing: -.01em;
}
.chart-card-header h3 i{
  color: var(--brand-500);
  font-size: 1rem;
}

.chart-card-body{
  padding: 16px 18px;
  height: 300px;
  position: relative;
  flex: 1 1 auto;
}
/* Os gráficos de barras horizontais recebem a altura por JS (charts.js),
   proporcional ao número de categorias, em estilo inline. */
.chart-card-body-tall{ height: 560px; }
.chart-card-note{
  margin: -6px 20px 16px;
  color: var(--color-text-muted);
  font-size: .74rem;
  line-height: 1.45;
}
.chart-card-note i{ color: var(--brand-500); margin-right: 4px; }
.da-chart-wide .chart-card-body{ height: 340px; }

/* ============ 9. CARDS DE TABELA ============ */
.table-card{
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  overflow:hidden;
  margin-bottom: 26px;
}

.table-card-header{
  padding: 14px 20px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  display:flex;
  align-items:center;
  justify-content:space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.table-card-header h3{
  font-size: var(--fs-title);
  font-weight: 720;
  color: var(--brand-900);
  display:flex;
  align-items:center;
  gap: 8px;
  letter-spacing: -.01em;
}
.table-card-header h3 i{ color: var(--brand-500); font-size: 1rem; }

.table-card-actions{ display:flex; align-items:center; gap: 10px; flex-wrap: wrap; }

.table-search{ position: relative; display:flex; align-items:center; }
.table-search i{
  position:absolute;
  left: 10px;
  color: var(--color-text-soft);
  font-size: .85rem;
}
.table-search input{
  padding: 7px 12px 7px 30px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  min-width: 240px;
  color: var(--color-text);
}
.table-search input:focus{
  outline:none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}

.btn-success{
  background: var(--success-500);
  border-color: var(--success-500);
  font-size: var(--fs-sm);
  font-weight: 600;
  display:inline-flex;
  align-items:center;
  gap: 6px;
  border-radius: var(--radius-sm);
}
.btn-success:hover,
.btn-success:focus{ background: var(--success-600); border-color: var(--success-600); }

.ranking-table,
.gap-table{ margin-bottom: 0; font-size: var(--fs-sm); }

/* Todas as colunas (cabeçalho e conteúdo) ficam centralizadas.
   O !important vence os utilitários .text-end do Bootstrap usados no
   HTML e nas linhas geradas por JS. */
.ranking-table th, .ranking-table td,
.gap-table th, .gap-table td{
  text-align: center !important;
  vertical-align: middle;
}
.ranking-table th.text-end, .ranking-table td.text-end,
.gap-table th.text-end, .gap-table td.text-end{
  text-align: center !important;
}

.ranking-table thead th,
.gap-table thead th{
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  font-size: var(--fs-label);
  text-transform: uppercase;
  letter-spacing: .065em;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--color-border-strong);
  padding: 10px 14px;
}
.ranking-table thead th i{ font-size: .7rem; opacity: .45; margin-left: 3px; }
.ranking-table thead th:hover{ color: var(--brand-700); }
.ranking-table thead th.sorted{ color: var(--brand-700); background: var(--brand-050); }
.ranking-table thead th.sorted i{ opacity: 1; color: var(--brand-600); }

.ranking-table tbody td,
.gap-table tbody td{
  padding: 9px 14px;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}
.ranking-table tbody tr:hover,
.gap-table tbody tr:hover{ background: #f5f9fa; }


.rank-badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--brand-100);
  color: var(--brand-700);
  font-size: .7rem;
  font-weight: 700;
  margin-right: 6px;
}

.nivel-badge{
  display:inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 700;
  border: 1px solid transparent;
}
.nivel-ok{ background: var(--success-100); color: var(--success-600); border-color:#d4dfe7; }
.nivel-atencao{ background: var(--accent-100); color: var(--accent-600); border-color:#f0dcb4; }
.nivel-critico{ background: var(--danger-100); color: var(--danger-600); border-color:#ded7e3; }
.table-card-footer{
  padding: 10px 20px;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-alt);
}

.table-card-hint{
  margin: 0;
  padding: 12px 20px 0;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
}

/* Cabeçalho fixo nas tabelas roláveis */
.table-scroll{ max-height: 460px; overflow-y: auto; }
.table-scroll thead th{ position: sticky; top: 0; z-index: 5; }

/* Colunas com significado fixo (mesmas cores dos gráficos) */
.da-col-entradas{ color: var(--m-entradas); font-weight: 600; }
.da-col-saidas{ color: var(--m-saidas); font-weight: 600; }
.da-saldo-positivo{ color: var(--success-600); font-weight: 700; }
.da-saldo-negativo{ color: var(--danger-600); font-weight: 700; }
.da-saldo-neutro{ color: var(--color-text-muted); }

/* ============ 10. AVISOS / BADGES ============ */
.table-card-alert{ border-color: #f0dcb4; }
.table-card-alert .table-card-header{
  background: linear-gradient(180deg, var(--accent-100), var(--color-surface));
  border-bottom-color: #f0dcb4;
}
.table-card-alert .table-card-header h3,
.table-card-alert .table-card-header h3 i{ color: var(--accent-600); }
.table-card-alert.is-empty{ display: none; }

.badge-count{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-500);
  color: #fff;
  font-size: .7rem;
  font-weight: 800;
  margin-left: 4px;
}

.da-aviso{
  display: flex; align-items: center; gap: 8px;
  background: var(--accent-100);
  color: var(--accent-600);
  border: 1px solid #f0dcb4;
  border-left: 3px solid var(--accent-500);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: var(--fs-sm);
  margin-bottom: 14px;
}
.da-aviso i{ color: var(--accent-500); font-size: 1rem; }
.da-aviso strong{ color: var(--accent-600); }

/* Variante informativa (dado real, apenas um resíduo a declarar) */
.da-aviso.da-aviso-info{
  background: var(--brand-050);
  color: var(--brand-700);
  border-color: var(--brand-200);
  border-left-color: var(--brand-500);
}
.da-aviso.da-aviso-info i{ color: var(--brand-500); }
.da-aviso.da-aviso-info strong{ color: var(--brand-800); }

/* Painel de alertas */
.alert-panel{
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}
.alert-panel-header{
  display:flex; align-items:center; justify-content:space-between;
  padding: 13px 20px;
  border-bottom: 1px solid var(--color-border);
  background: linear-gradient(180deg, var(--color-surface-alt), var(--color-surface));
}
.alert-panel-header h3{
  font-size: var(--fs-title); font-weight: 700; color: var(--brand-900);
  display:flex; align-items:center; gap: 8px;
}
.alert-panel-header h3 i{ color: var(--accent-500); }
.alert-panel-hint{ font-size: var(--fs-sm); color: var(--color-text-muted); }
.alert-panel-body{
  padding: 18px 20px;
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.alert-card{
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-border-strong);
  background: var(--color-surface-alt);
}
.alert-card.alert-critico{ border-left-color: var(--danger-500); background: var(--danger-100); border-color:#ded7e3; }
.alert-card.alert-atencao{ border-left-color: var(--accent-500); background: var(--accent-100); border-color:#f0dcb4; }
.alert-card-header{
  font-size: var(--fs-sm); font-weight: 700; color: var(--brand-900);
  display:flex; align-items:center; gap: 6px; margin-bottom: 8px;
}
.alert-card.alert-critico .alert-card-header i{ color: var(--danger-500); }
.alert-card.alert-atencao .alert-card-header i{ color: var(--accent-500); }
.alert-card-list{
  list-style: none; margin: 0; padding: 0;
  font-size: var(--fs-sm); color: var(--color-text);
  display:flex; flex-direction: column; gap: 4px;
}

.home-intro{ color: var(--color-text-muted); font-size: var(--fs-base); margin: 0 0 16px 4px; }
.filter-item-narrow{ flex: 0 0 160px; min-width: 140px; }

/* ============ RELATÓRIOS / COMPLETUDE ============ */
.relatorios-kpis{ grid-template-columns: repeat(4, 1fr); }
.relatorios-toolbar{ align-items: flex-end; }
.relatorios-search{ flex: 1 1 320px; max-width: 520px; }
.relatorios-search input{ width: 100%; }
.relatorios-legend{ color: var(--color-text-muted); font-size: var(--fs-sm); }
.relatorios-legend i{ color: var(--brand-500); margin-right: 4px; }
#relatoriosTable code{
  color: var(--brand-800);
  background: var(--brand-050);
  border-radius: 5px;
  padding: 2px 6px;
  white-space: normal;
  overflow-wrap: anywhere;
}
#relatoriosTable .rel-row-missing{ background: var(--danger-100); }
#relatoriosTable .rel-row-missing:hover{ background: #f5e8ec; }
.rel-status{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
}
.rel-status-ok{ color: var(--success-600); background: var(--success-100); }
.rel-status-missing{ color: var(--danger-600); background: #fff; border: 1px solid #e5ccd4; }
.rel-status-warning{ color: var(--accent-600); background: var(--accent-100); }

/* ============ 11. LOADING ============ */
.loading-overlay{
  position: fixed;
  inset: 0;
  background: rgba(10, 37, 48, .5);
  backdrop-filter: blur(3px);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index: 1000;
}
.loading-box{
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 26px 34px;
  display:flex;
  align-items:center;
  gap: 16px;
  box-shadow: var(--shadow-md);
  font-weight: 600;
  color: var(--brand-900);
}
.loading-box .spinner-border{ color: var(--brand-500); }

/* ============ 12. RESPONSIVO ============ */
@media (max-width: 1400px){
  .kpi-row{ grid-template-columns: repeat(3, 1fr); }
  .kpi-row-home{ grid-template-columns: repeat(3, 1fr); }
  .da-kpi-row{ grid-template-columns: repeat(3, 1fr); }
  .da-chart-grid-performance{ grid-template-columns: 1.6fr 1fr; }
  .da-chart-grid-performance .da-chart-wide{ grid-column: 1 / -1; }
  .chart-grid-3{ grid-template-columns: repeat(2, 1fr); }
  .relatorios-kpis{ grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px){
  .app-content{ padding: 16px; }
  .view-intro{ align-items:flex-start; flex-direction:column; gap:6px; }
  .view-intro p{ text-align:left; }
  .kpi-row,
  .kpi-row-home,
  .da-kpi-row{ grid-template-columns: repeat(2, 1fr); }
  .chart-grid-3,
  .chart-grid-2,
  .da-chart-grid-main,
  .da-chart-grid-performance{ grid-template-columns: 1fr; }
  .da-chart-grid-performance .da-chart-wide{ grid-column: auto; }
  .da-section-heading{ align-items: flex-start; flex-direction: column; gap: 5px; }
  .da-section-heading p{ text-align: left; }
  .topbar{ padding: 12px 16px; }
  .filter-item{ min-width: 130px; }
  .filter-hint, .da-filter-hint{ margin-left: 0; }
  .chart-card-body-tall{ height: 480px; }
}

@media (max-width: 760px){
  .empty-state{ margin:28px auto; padding:0 16px; }
  .empty-onboarding{ grid-template-columns:1fr; }
  .empty-onboarding-main{ padding:36px 30px 32px; }
  .empty-onboarding-aside{ padding:28px 30px; border-left:0; border-top:1px solid var(--color-border); }
}

@media (max-width: 560px){
  .kpi-row,
  .kpi-row-home,
  .da-kpi-row{ grid-template-columns: 1fr; }
  .topbar-actions{ width: 100%; justify-content: flex-start; }
  .view-intro h1{ font-size: 1.3rem; }
  .table-search input{ min-width: 160px; }
  .empty-onboarding-main,
  .empty-onboarding-aside{ padding-left:22px; padding-right:22px; }
  .empty-state h2{ font-size:1.4rem; }
  .empty-cta{ width:100%; justify-content:center; }
  .relatorios-kpis{ grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce){
  *{ animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
