/* ============================================================================
   BI IMPLANTAÇÕES — Cockpit de gestão (redesign)
   Escopo 100% em .bi-*  · usa os tokens do design-system.css
   Objetivo: densidade, pouca rolagem vertical, grid com scroll interno.
   ========================================================================== */

/* Container ocupa o viewport: só o data grid rola por dentro (sensação de app) */
.bi-cockpit { display: flex; flex-direction: column; gap: 10px; height: calc(100vh - 92px); min-height: 480px; }
.bi-cockpit.bi-foco .bi-analytics { display: none; }
/* #biConteudo é o miolo que flexiona: só o data grid rola por dentro */
#biConteudo { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 860px) { #biConteudo { min-height: 0; } }

/* ---- Faixa 1: cabeçalho compacto ---- */
.bi-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.bi-top-esq { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.bi-top h1 { font-size: 1.15rem; font-weight: 800; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.35); letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.bi-top .bi-meta { font-size: 0.76rem; color: rgba(255,255,255,.82); text-shadow: 0 1px 2px rgba(0,0,0,.3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bi-acoes { display: flex; gap: 6px; flex-wrap: wrap; }
.bi-acoes .btn { padding: 7px 12px; }

/* ---- Abas de visão ---- */
.bi-barra2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.bi-views { display: inline-flex; background: var(--panel); border: 1px solid var(--borda); border-radius: var(--r-md); padding: 3px; gap: 2px; }
.bi-view { padding: 6px 14px; border-radius: var(--r-sm); font-size: 0.8rem; font-weight: 600; color: var(--texto-fraco); cursor: pointer; border: none; background: none; white-space: nowrap; transition: color var(--t-fast), background var(--t-fast); }
.bi-view:hover { color: var(--texto); }
.bi-view.ativa { background: var(--accent); color: #fff; box-shadow: var(--sh-sm); }
.bi-ferramentas { display: inline-flex; gap: 6px; align-items: center; }
.bi-mini-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border: 1px solid var(--borda); background: var(--panel); border-radius: var(--r-md); font-size: 0.78rem; font-weight: 600; color: var(--texto-fraco); cursor: pointer; transition: all var(--t-fast); }
.bi-mini-btn:hover { color: var(--texto); border-color: var(--texto-apagado); }
.bi-mini-btn.ativo { color: var(--accent); border-color: var(--accent); background: var(--accent-suave); }

/* ---- Faixa 2: barra de filtros ---- */
.bi-filtros { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--borda); border-radius: var(--r-lg); padding: 9px 12px; box-shadow: var(--sh-sm); }
.bi-busca { position: relative; flex: 1 1 240px; min-width: 200px; display: flex; align-items: center; }
.bi-busca .icone { position: absolute; left: 10px; color: var(--texto-apagado); pointer-events: none; }
.bi-busca input { width: 100%; padding: 8px 10px 8px 32px; border: 1px solid var(--borda); border-radius: var(--r-md); font-size: 0.84rem; background: var(--panel-alto); color: var(--texto); }
.bi-busca input:focus { outline: none; box-shadow: var(--foco); border-color: var(--accent); background: var(--panel); }
.bi-filtros { gap: 7px; }
.bi-filtros select.input-filtro { padding: 8px 10px; border-radius: var(--r-md); min-width: 96px; max-width: 160px; }
/* botão ↗ de abrir em nova aba (coluna opcional da tabela) */
.bi-abrir-aba { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: 1px solid var(--borda); background: var(--panel); border-radius: var(--r-sm); color: var(--texto-fraco); cursor: pointer; font-size: 0.95rem; line-height: 1; transition: all var(--t-fast); }
.bi-abrir-aba:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-suave); }
.bi-filtros .bi-sep { width: 1px; align-self: stretch; background: var(--borda-suave); margin: 2px 2px; }
.bi-chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; width: 100%; margin-top: 2px; }
.bi-chips-vazio { display: none; }
.bi-chips .bi-chips-label { font-size: 0.72rem; color: var(--texto-apagado); font-weight: 600; }
.bi-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-suave); color: var(--accent); border-radius: var(--r-md); padding: 4px 6px 4px 10px; font-size: 0.74rem; font-weight: 600; }
.bi-chip .x { cursor: pointer; opacity: .65; font-size: 0.95rem; line-height: 1; padding: 0 2px; }
.bi-chip .x:hover { opacity: 1; }
.bi-limpar { background: none; border: none; color: var(--texto-fraco); font-size: 0.75rem; font-weight: 600; cursor: pointer; text-decoration: underline; }
.bi-limpar:hover { color: var(--st-danger-fg); }

/* ---- Faixa 3: KPI strip ---- */
.bi-kpis { display: flex; gap: 8px; }
.bi-kpi { flex: 1 1 0; min-width: 116px; background: var(--panel); border: 1px solid var(--borda); border-radius: var(--r-lg); padding: 10px 12px; cursor: pointer; transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast); position: relative; overflow: hidden; }
.bi-kpi:hover { box-shadow: var(--sh-md); transform: translateY(-1px); }
.bi-kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--kpi-cor, var(--st-neutral)); opacity: .0; transition: opacity var(--t-fast); }
.bi-kpi:hover::before, .bi-kpi.ativo::before { opacity: 1; }
.bi-kpi.ativo { border-color: var(--kpi-cor, var(--accent)); box-shadow: var(--foco); }
.bi-kpi-rot { font-size: 0.64rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 700; color: var(--texto-fraco); display: flex; align-items: center; gap: 5px; }
.bi-kpi-rot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--kpi-cor, var(--st-neutral)); flex-shrink: 0; }
.bi-kpi-val { font-size: 1.5rem; font-weight: 800; line-height: 1.1; margin-top: 3px; color: var(--texto); }
.bi-kpi.compacto { padding: 7px 11px; }
.bi-kpi.compacto .bi-kpi-val { font-size: 1.15rem; }

/* ---- Faixa 4: analytics ---- */
.bi-analytics { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.bi-analytics.full { grid-template-columns: repeat(3, minmax(0,1fr)); grid-auto-rows: 1fr; }
.bi-card { background: var(--panel); border: 1px solid var(--borda); border-radius: var(--r-lg); padding: 12px 14px; box-shadow: var(--sh-sm); display: flex; flex-direction: column; min-width: 0; }
.bi-card-cab { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.bi-card-tit { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 700; color: var(--texto-fraco); }
.bi-dim-tabs { display: inline-flex; gap: 2px; background: var(--panel-alto); border-radius: var(--r-sm); padding: 2px; }
.bi-dim-tab { padding: 3px 8px; font-size: 0.68rem; font-weight: 600; color: var(--texto-fraco); border: none; background: none; border-radius: 4px; cursor: pointer; }
.bi-dim-tab.ativa { background: var(--panel); color: var(--texto); box-shadow: var(--sh-sm); }
.bi-card-link { font-size: 0.72rem; font-weight: 600; color: var(--accent); cursor: pointer; background: none; border: none; }

/* barras horizontais (ranking) */
.bi-bar { margin-bottom: 7px; cursor: pointer; }
.bi-bar:last-child { margin-bottom: 0; }
.bi-bar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 0.76rem; margin-bottom: 3px; }
.bi-bar-nome { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--texto); }
.bi-bar-qtd { font-weight: 700; color: var(--texto); flex-shrink: 0; }
.bi-bar-trilha { background: var(--panel-alto); height: 8px; border-radius: 4px; overflow: hidden; }
.bi-bar-fill { height: 100%; border-radius: 4px; background: var(--bar-cor, var(--accent)); transition: width var(--t-slow) var(--ease); }
.bi-bar:hover .bi-bar-fill { filter: brightness(1.08); }
.bi-bar.sel .bi-bar-nome, .bi-bar.sel .bi-bar-qtd { color: var(--accent); }
.bi-nota { font-size: 0.7rem; color: var(--texto-apagado); margin-top: 6px; }
.bi-ver-todos { font-size: 0.72rem; font-weight: 600; color: var(--accent); cursor: pointer; background: none; border: none; margin-top: 6px; align-self: flex-start; }

/* donut de status */
.bi-donut-wrap { display: flex; align-items: center; gap: 14px; }
.bi-donut { position: relative; flex-shrink: 0; }
.bi-donut svg { display: block; }
.bi-donut-centro { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.bi-donut-centro b { font-size: 1.15rem; font-weight: 800; line-height: 1; }
.bi-donut-centro span { font-size: 0.6rem; text-transform: uppercase; color: var(--texto-apagado); font-weight: 700; }
.bi-donut-seg { cursor: pointer; transition: opacity var(--t-fast); }
.bi-donut-seg:hover { opacity: .82; }
.bi-legenda { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.bi-legenda-item { display: flex; align-items: center; gap: 7px; font-size: 0.76rem; cursor: pointer; padding: 2px 4px; border-radius: 5px; }
.bi-legenda-item:hover { background: var(--panel-alto); }
.bi-legenda-item .pt { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.bi-legenda-item .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--texto-fraco); }
.bi-legenda-item .qt { font-weight: 700; }

/* ---- Faixa 5: data grid ---- */
.bi-grid-wrap { flex: 1 1 auto; min-height: 140px; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--borda); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--sh-sm); }
.bi-grid-cab { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--borda-suave); flex-shrink: 0; }
.bi-grid-cab .tit { font-size: 0.82rem; font-weight: 700; }
.bi-grid-cab .tit b { color: var(--accent); }
.bi-grid-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; }
.bi-grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.8rem; }
.bi-grid thead th { position: sticky; top: 0; z-index: 3; background: var(--panel-alto); color: var(--texto-fraco); font-size: 0.66rem; text-transform: uppercase; letter-spacing: .02em; font-weight: 700; text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--borda); white-space: nowrap; cursor: pointer; user-select: none; }
.bi-grid thead th:hover { color: var(--texto); }
.bi-grid thead th .ord { opacity: .35; margin-left: 3px; font-size: 0.7rem; }
.bi-grid thead th.ord-ativa { color: var(--accent); }
.bi-grid thead th.ord-ativa .ord { opacity: 1; }
.bi-grid tbody td { padding: 9px 12px; border-bottom: 1px solid var(--borda-suave); white-space: nowrap; color: var(--texto); vertical-align: middle; }
.bi-grid tbody tr { cursor: pointer; transition: background var(--t-fast); }
.bi-grid tbody tr:hover { background: var(--accent-suave); }
.bi-grid tbody tr.sel { background: var(--accent-suave); }
/* coluna Loja congelada */
.bi-grid th.fix, .bi-grid td.fix { position: sticky; left: 0; z-index: 2; background: var(--panel); box-shadow: 1px 0 0 var(--borda-suave); }
.bi-grid thead th.fix { z-index: 4; background: var(--panel-alto); }
.bi-grid tbody tr:hover td.fix { background: var(--accent-suave); }
.bi-grid tbody tr.sel td.fix { background: var(--accent-suave); }
.bi-grid td.fix strong { font-weight: 600; }
/* densidade */
.bi-grid-wrap.densa .bi-grid tbody td { padding: 5px 12px; }
.bi-grid-wrap.densa .bi-grid thead th { padding: 6px 12px; }
/* alertas discretos na célula de virada/pendência */
.bi-alerta-venc { color: var(--st-danger-fg); font-weight: 700; }
.bi-alerta-prox { color: var(--st-warn-fg); font-weight: 700; }
.bi-flag { display: inline-flex; align-items: center; gap: 3px; }
.bi-flag .icone { width: 13px; height: 13px; }
.bi-pend { color: var(--st-warn-fg); }
.bi-grid-vazio { padding: 40px 20px; text-align: center; color: var(--texto-apagado); font-size: 0.86rem; }

/* chip de status/contrato premium (usado na tabela e no drawer) */
.bi-status, .bi-contrato { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--r-md); font-size: 0.7rem; font-weight: 700; }
.bi-status::before, .bi-contrato::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.bi-st-ok { background: var(--st-ok-bg); color: var(--st-ok-fg); }
.bi-st-info { background: var(--st-info-bg); color: var(--st-info-fg); }
.bi-st-warn { background: var(--st-warn-bg); color: var(--st-warn-fg); }
.bi-st-danger { background: var(--st-danger-bg); color: var(--st-danger-fg); }
.bi-st-neutral { background: var(--st-neutral-bg); color: var(--st-neutral-fg); }
.bi-st-aceite { background: var(--st-danger-bg); color: var(--st-danger-fg); box-shadow: 0 0 0 1px var(--st-danger-fg) inset; }
.bi-cat { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: var(--r-sm); font-size: 0.62rem; font-weight: 800; letter-spacing: .02em; }
.bi-cat-impl { background: var(--st-info-bg); color: var(--st-info-fg); }
.bi-cat-prod { background: #e4f7fb; color: #0e7490; }
.bi-cat-troca { background: #fce7f3; color: #be1e64; }

/* ---- Drawer de detalhe da loja ---- */
.bi-drawer-bg { position: fixed; inset: 0; background: rgba(15,23,42,.32); z-index: var(--z-drawer); opacity: 0; pointer-events: none; transition: opacity var(--t); }
.bi-drawer-bg.aberto { opacity: 1; pointer-events: auto; }
.bi-drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(430px, 94vw); background: var(--panel); z-index: calc(var(--z-drawer) + 1); box-shadow: var(--sh-xl); transform: translateX(100%); transition: transform var(--t) var(--ease); display: flex; flex-direction: column; }
.bi-drawer.aberto { transform: none; }
.bi-drawer-cab { padding: 18px 20px 14px; border-bottom: 1px solid var(--borda-suave); }
.bi-drawer-cab .cat { margin-bottom: 8px; }
.bi-drawer-cab h2 { font-size: 1.1rem; font-weight: 800; line-height: 1.25; }
.bi-drawer-cab .sub { font-size: 0.76rem; color: var(--texto-fraco); margin-top: 3px; }
.bi-drawer-fechar { position: absolute; top: 14px; right: 14px; border: none; background: none; font-size: 1.5rem; line-height: 1; color: var(--texto-apagado); cursor: pointer; border-radius: var(--r-sm); padding: 2px 8px; }
.bi-drawer-fechar:hover { background: var(--panel-alto); color: var(--texto); }
.bi-drawer-corpo { flex: 1; overflow-y: auto; padding: 16px 20px; }
.bi-dl { display: grid; grid-template-columns: 118px 1fr; gap: 9px 12px; align-items: start; }
.bi-dl dt { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .02em; font-weight: 700; color: var(--texto-apagado); padding-top: 2px; }
.bi-dl dd { font-size: 0.86rem; color: var(--texto); }
.bi-drawer-acoes { padding: 14px 20px; border-top: 1px solid var(--borda-suave); display: flex; gap: 8px; }
.bi-drawer-acoes .btn { flex: 1; }

/* ---- Modal "Personalizar colunas" (mostrar/esconder + reordenar) ---- */
.bi-col-lista { display: flex; flex-direction: column; gap: 4px; max-height: 54vh; overflow-y: auto; padding: 2px; }
.bi-col-item { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border: 1px solid var(--borda-suave); border-radius: var(--r-md); background: var(--panel); transition: border-color var(--t-fast), background var(--t-fast); }
.bi-col-item:hover { border-color: var(--borda); background: var(--panel-alto); }
.bi-col-grip { color: var(--texto-apagado); cursor: grab; display: flex; }
.bi-col-grip:active { cursor: grabbing; }
.bi-col-lab { flex: 1; display: flex; align-items: center; gap: 9px; font-size: 0.86rem; cursor: pointer; min-width: 0; }
.bi-col-lab .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bi-col-lab input { width: 15px; height: 15px; accent-color: var(--accent); flex-shrink: 0; }
.bi-col-sec { font-size: 0.6rem; text-transform: uppercase; letter-spacing: .02em; color: var(--texto-apagado); font-weight: 700; background: var(--panel-alto); padding: 2px 7px; border-radius: var(--r-full); flex-shrink: 0; }
.bi-col-arrows { display: flex; flex-direction: column; flex-shrink: 0; }
.bi-col-arrows button { border: none; background: none; color: var(--texto-apagado); cursor: pointer; font-size: 0.58rem; line-height: 1; padding: 1px 5px; }
.bi-col-arrows button:hover:not(:disabled) { color: var(--accent); }
.bi-col-arrows button:disabled { opacity: .22; cursor: default; }

/* ---- Modal "Explorar análises" (staging multi-seleção) ---- */
.bi-explorar-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.bi-exp-footer { position: sticky; bottom: 0; margin: 16px -24px -24px; padding: 13px 24px; background: var(--panel); border-top: 1px solid var(--borda-suave); box-shadow: 0 -6px 16px rgba(16,24,40,.06); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; z-index: 2; }
.bi-exp-sel { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; flex: 1; min-width: 0; }
.bi-exp-dica { font-size: 0.8rem; color: var(--texto-apagado); }
.bi-exp-botoes { display: flex; gap: 8px; flex-shrink: 0; }
/* barra selecionada (staging E drill-down): tint + acento à esquerda, sem pular layout */
.bi-bar.sel { background: var(--accent-suave); border-radius: var(--r-sm); box-shadow: inset 3px 0 0 var(--accent); padding-left: 8px; margin-left: -8px; }
.bi-bar.sel .bi-bar-nome, .bi-bar.sel .bi-bar-qtd { color: var(--accent); font-weight: 700; }
/* pílula "Limpar tudo" com UX de destaque */
.bi-limpar-pill { display: inline-flex; align-items: center; gap: 5px; background: var(--st-danger-bg); color: var(--st-danger-fg); border: 1px solid transparent; border-radius: var(--r-md); padding: 4px 11px; font-size: 0.74rem; font-weight: 700; cursor: pointer; transition: all var(--t-fast); }
.bi-limpar-pill .icone { width: 13px; height: 13px; }
.bi-limpar-pill:hover { background: var(--st-danger-fg); color: #fff; box-shadow: var(--sh-sm); }

/* ============================ RESPONSIVO ============================ */
@media (max-width: 1366px) {
  .bi-kpi { min-width: 104px; }
  .bi-kpi-val { font-size: 1.3rem; }
}
@media (max-width: 1100px) {
  .bi-analytics, .bi-analytics.full { grid-template-columns: 1fr 1fr; }
  .bi-explorar-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .bi-cockpit { height: auto; }
  .bi-grid-wrap { min-height: 60vh; }
}
@media (max-width: 768px) {
  .bi-kpis { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .bi-kpi { flex: 0 0 44%; min-width: 44%; }
  .bi-analytics, .bi-analytics.full { grid-template-columns: 1fr; }
  .bi-top h1 { font-size: 1.05rem; }
  .bi-drawer { width: 100vw; }
}
