/* ============================================================
 * BI 3.0 — Executive Dashboard (dark-first, iPad-first)
 * ============================================================
 * Superfície nova, dedicada à experiência executiva em tablet.
 * Consome o mesmo backend do BI 2.0 (/api/bi2). Design dark,
 * editorial, cinematográfico — referência Linear / Stripe / Apple.
 *
 * Tudo escopado sob .bi3 pra não vazar no resto do app (que é light).
 * Alvos de 1ª classe: iPad retrato (768px) e paisagem (1024px),
 * mantendo desktop intacto.
 * ============================================================ */

.bi3 {
  /* ── Tokens — TEMA CLARO (padrão, cores BeepHub) ─────────── */
  --b3-bg:        #F6F7FB;   /* fundo base claro */
  --b3-surface:   #FFFFFF;   /* superfície de card */
  --b3-surface-2: #F8FAFC;   /* card elevado / hover */
  --b3-surface-3: #F1F5F9;   /* controles, chips */
  --b3-border:    #E5E7EB;   /* borda sutil */
  --b3-border-2:  #CBD5E1;   /* borda em foco/hover */

  --b3-text:      #0F172A;   /* texto primário (gray-900) */
  --b3-text-2:    #334155;   /* texto secundário (gray-700) */
  --b3-muted:     #64748B;   /* texto terciário/labels (gray-500) */

  --b3-accent:      #1E4FC2; /* BeepHub blue-600 */
  --b3-accent-2:    #2563EB; /* BeepHub blue-500 */
  --b3-accent-soft: rgba(37,99,235,.10);
  --b3-accent-glow: rgba(37,99,235,.28);
  --b3-kpi-from:    #1E4FC2;
  --b3-kpi-to:      #2563EB;

  --b3-success: #16A34A;
  --b3-danger:  #DC2626;
  --b3-warning: #CA8A04;
  --b3-info:    #2563EB;

  /* overlay decorativo do fundo (sutil no claro) */
  --b3-glow-1: rgba(37,99,235,.06);
  --b3-glow-2: rgba(249,115,22,.05);

  --b3-radius:    18px;
  --b3-radius-sm: 12px;
  --b3-radius-xs: 9px;

  --b3-shadow:    0 1px 2px rgba(15,23,42,.04), 0 6px 20px rgba(15,23,42,.06);
  --b3-shadow-lg: 0 24px 70px rgba(15,23,42,.18);

  /* alvo de toque mínimo (Apple HIG = 44px) */
  --b3-touch: 44px;

  --b3-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;

  position: absolute;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--b3-glow-1), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, var(--b3-glow-2), transparent 55%),
    var(--b3-bg);
  color: var(--b3-text);
  font-family: var(--b3-font);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Tokens — TEMA ESCURO (opcional, à escolha do usuário) ──── */
.bi3[data-theme="dark"] {
  --b3-bg:        #0A0E1A;
  --b3-surface:   #111726;
  --b3-surface-2: #161D2F;
  --b3-surface-3: #1C2438;
  --b3-border:    #232C42;
  --b3-border-2:  #2E3953;

  --b3-text:      #F1F5F9;
  --b3-text-2:    #A9B4C9;
  --b3-muted:     #6B7689;

  --b3-accent:      #6366F1;
  --b3-accent-2:    #8B5CF6;
  --b3-accent-soft: rgba(99,102,241,.14);
  --b3-accent-glow: rgba(99,102,241,.35);
  --b3-kpi-from:    #FFFFFF;
  --b3-kpi-to:      #C7D2FE;

  --b3-success: #34D399;
  --b3-danger:  #F87171;
  --b3-warning: #FBBF24;
  --b3-info:    #38BDF8;

  --b3-glow-1: rgba(99,102,241,.10);
  --b3-glow-2: rgba(139,92,246,.08);

  --b3-shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.28);
  --b3-shadow-lg: 0 24px 70px rgba(0,0,0,.55);
}

/* O page-content do app tem padding — neutraliza só pra BI 3.0 (modo embutido) */
.page-content:has(> .bi3) { padding: 0 !important; background: var(--b3-bg); overflow: hidden; }

/* Modo standalone (aba exclusiva /bi3.html) */
#bi3Root { position: relative; height: 100vh; width: 100vw; overflow: hidden; }

/* ── Header executivo ──────────────────────────────────────── */
.bi3-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--b3-border);
  background: linear-gradient(180deg, rgba(17,23,38,.85), rgba(10,14,26,.4));
  backdrop-filter: blur(12px);
}
.bi3-header-logo {
  height: 30px; width: auto; flex-shrink: 0; margin-right: 2px;
  display: block; user-select: none;
}
.bi3-title-block { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bi3-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.02em;
  margin: 0;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bi3-subtitle {
  font-size: 12px;
  color: var(--b3-muted);
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.bi3-freshness {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
}
.bi3-freshness-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--b3-success);
  box-shadow: 0 0 0 0 rgba(52,211,153,.6);
  animation: b3-pulse 2.4s ease-out infinite;
}
@keyframes b3-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(52,211,153,.55); }
  70%  { box-shadow: 0 0 0 7px rgba(52,211,153,0); }
  100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); }
}

.bi3-header-spacer { flex: 1; }

/* ── Botões do header ──────────────────────────────────────── */
.bi3-btn {
  height: var(--b3-touch);
  min-width: var(--b3-touch);
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--b3-border);
  background: var(--b3-surface-3);
  color: var(--b3-text);
  border-radius: var(--b3-radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .16s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.bi3-btn:hover { border-color: var(--b3-border-2); background: var(--b3-surface-2); }
.bi3-btn:active { transform: scale(.97); }
.bi3-btn svg { width: 17px; height: 17px; flex-shrink: 0; }
.bi3-btn-icon { padding: 0; width: var(--b3-touch); }
.bi3-btn-primary {
  background: linear-gradient(135deg, var(--b3-accent), var(--b3-accent-2));
  border-color: transparent;
  box-shadow: 0 4px 16px var(--b3-accent-glow);
}
.bi3-btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--b3-accent), var(--b3-accent-2)); }
.bi3-btn .b3-spin {
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: b3-rot .6s linear infinite;
}
@keyframes b3-rot { to { transform: rotate(360deg); } }

.bi3-filter-count {
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--b3-accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Tabs de dashboard ─────────────────────────────────────── */
.bi3-tabs {
  flex-shrink: 0;
  display: flex;
  gap: 4px;
  padding: 10px 24px 0;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--b3-border);
}
.bi3-tabs::-webkit-scrollbar { display: none; }
.bi3-tab {
  flex-shrink: 0;
  height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: transparent;
  color: var(--b3-text-2);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border-radius: 10px 10px 0 0;
  position: relative;
  white-space: nowrap;
  transition: color .14s;
  -webkit-tap-highlight-color: transparent;
}
.bi3-tab:hover { color: var(--b3-text); }
.bi3-tab.is-active { color: var(--b3-text); }
.bi3-tab.is-active::after {
  content: '';
  position: absolute;
  left: 12px; right: 12px; bottom: -1px;
  height: 2.5px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--b3-accent), var(--b3-accent-2));
}
.bi3-tab-count { font-size: 11px; color: var(--b3-muted); font-weight: 700; }

/* ── Área scrollável + grid ────────────────────────────────── */
.bi3-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 20px 24px 40px;
}
/* Grid via GridStack: o container NÃO usa display:grid (itens são
   posicionados em absoluto pelo GridStack). Só centraliza e limita largura. */
.bi3-grid.grid-stack {
  display: block;
  max-width: 1680px;
  margin: 0 auto;
  min-height: 120px;
}
/* skeleton inicial (antes do GridStack montar) — grid CSS clássico */
.bi3-grid:not(.grid-stack) {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  max-width: 1680px;
  margin: 0 auto;
}
/* O card de painel preenche 100% do tile do GridStack.
   NÃO mexer em inset — o GridStack usa inset pra aplicar o margin (gap). */
.bi3-grid .grid-stack-item-content { overflow: visible; }
.bi3-grid .grid-stack-item-content > .bi3-panel { height: 100%; min-height: 0; }
.bi3-grid .grid-stack-item-content > .bi3-panel.is-kpi { min-height: 0; }
/* Corpo/gráfico acompanham a altura do tile (sem min-height forçando overflow) */
.bi3-grid .bi3-panel-body { min-height: 0; }
.bi3-grid .bi3-chart { min-height: 0; }
/* Fallback se o GridStack não carregar: empilha os painéis */
.bi3-grid-fallback { display: flex; flex-direction: column; gap: 16px; }
.bi3-grid-fallback .grid-stack-item { position: static !important; width: 100% !important; transform: none !important; }
.bi3-grid-fallback .grid-stack-item-content { position: static !important; }
.bi3-grid-fallback .bi3-panel { min-height: 280px; }

/* ── Painel (card) ─────────────────────────────────────────── */
.bi3-panel {
  min-height: 240px;
  background: linear-gradient(180deg, var(--b3-surface), var(--b3-surface));
  border: 1px solid var(--b3-border);
  border-radius: var(--b3-radius);
  box-shadow: var(--b3-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transition: border-color .18s, transform .18s;
}
.bi3-panel::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
}
.bi3-panel:hover { border-color: var(--b3-border-2); }
/* KPI: visual compacto (largura vem do grid_w inline) */
.bi3-panel.is-kpi { min-height: 150px; }

/* Drag handle: visível só no modo "Editar layout" (evita afordância
   acidental durante a análise normal). */
.bi3-drag-handle {
  display: none; align-items: center; justify-content: center;
  width: 22px; height: 28px; margin: -2px 2px -2px -6px; flex-shrink: 0;
  color: var(--b3-muted); cursor: grab; transition: opacity .14s;
}
.bi3-editing .bi3-drag-handle { display: inline-flex; opacity: .65; }
.bi3-editing .bi3-drag-handle:hover { opacity: 1; }
.bi3-drag-handle:active { cursor: grabbing; }
.bi3-drag-handle svg { width: 16px; height: 16px; }

/* ── Modo edição de layout (GridStack) ─────────────────────── */
.bi3-editing .bi3-panel {
  outline: 1px dashed var(--b3-border-2);
  outline-offset: -1px;
}
.bi3-editing .grid-stack-item-content > .bi3-panel:hover {
  border-color: var(--b3-accent);
}
/* No modo edição o gráfico não dispara drill — não parecer clicável */
.bi3-editing .bi3-chart { cursor: default; }
/* Esconde os handles de resize fora do modo edição (staticGrid já remove,
   mas reforça visualmente) e revela suavemente no hover do tile editável. */
.bi3 .grid-stack-item > .ui-resizable-handle { opacity: 0; transition: opacity .15s; }
.bi3-editing .grid-stack-item:hover > .ui-resizable-handle { opacity: .9; }
.bi3-editing .grid-stack-item > .ui-resizable-se {
  width: 16px; height: 16px; right: 4px; bottom: 4px;
}
/* Placeholder (prévia do destino ao arrastar/redimensionar) */
.bi3 .grid-stack-placeholder > .placeholder-content {
  background: var(--b3-accent-soft, rgba(99,102,241,.12));
  border: 1px dashed var(--b3-accent);
  border-radius: var(--b3-radius);
  margin: 0;
}

/* Pílula "Salvo / Falha" do autosave de layout */
.bi3-saved-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 5px 10px;
  border-radius: 999px; white-space: nowrap; transition: opacity .3s;
}
/* Sólida (texto branco) — legível sobre o header escuro e em ambos os temas */
.bi3-saved-pill.ok  { color: #FFFFFF; background: #16A34A; }
.bi3-saved-pill.err { color: #FFFFFF; background: #DC2626; }
.bi3-saved-pill svg { width: 13px; height: 13px; }

.bi3-panel-head {
  flex-shrink: 0;
  padding: 16px 18px 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.bi3-panel-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--b3-text);
  margin: 0;
  line-height: 1.3;
  letter-spacing: -.01em;
}
.bi3-panel-desc {
  font-size: 11.5px;
  color: var(--b3-muted);
  margin: 3px 0 0;
  line-height: 1.4;
}
.bi3-panel-actions { display: flex; gap: 4px; flex-shrink: 0; }
.bi3-panel-icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--b3-muted); border-radius: 8px;
  cursor: pointer; transition: all .14s;
  -webkit-tap-highlight-color: transparent;
}
.bi3-panel-icon-btn:hover { background: var(--b3-surface-3); color: var(--b3-text); }
.bi3-panel-icon-btn svg { width: 16px; height: 16px; }

.bi3-panel-body {
  flex: 1;
  position: relative;
  padding: 4px 14px 14px;
  min-height: 140px;
}
.bi3-chart { width: 100%; height: 100%; min-height: 200px; }

.bi3-panel-foot {
  flex-shrink: 0;
  padding: 8px 16px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10.5px;
  color: var(--b3-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
}
.bi3-tag {
  background: var(--b3-surface-3);
  border: 1px solid var(--b3-border);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
  letter-spacing: .04em;
}
.bi3-tag.cache { background: rgba(52,211,153,.1); border-color: rgba(52,211,153,.25); color: var(--b3-success); }

/* ── KPI ───────────────────────────────────────────────────── */
.bi3-kpi {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6px 4px;
}
.bi3-kpi-value {
  font-size: clamp(26px, 4.6vw, 40px);
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1;
  background: linear-gradient(135deg, var(--b3-kpi-from), var(--b3-kpi-to));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-variant-numeric: tabular-nums;
}
.bi3-kpi-label {
  font-size: 11.5px;
  color: var(--b3-muted);
  margin-top: 8px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
}

/* ── Tabela ────────────────────────────────────────────────── */
.bi3-table-wrap { width: 100%; height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; }
.bi3-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.bi3-table th, .bi3-table td {
  padding: 9px 12px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--b3-border);
}
.bi3-table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--b3-surface-2);
  color: var(--b3-muted);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.bi3-table tbody tr:hover { background: var(--b3-surface-2); }
.bi3-table td { color: var(--b3-text-2); }
.bi3-table td.num, .bi3-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Skeleton loading ──────────────────────────────────────── */
.bi3-skeleton {
  position: absolute; inset: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.bi3-skel-bar {
  border-radius: 8px;
  background: linear-gradient(90deg, var(--b3-surface-2) 25%, var(--b3-surface-3) 37%, var(--b3-surface-2) 63%);
  background-size: 400% 100%;
  animation: b3-shimmer 1.4s ease infinite;
}
@keyframes b3-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ── Estados vazio / erro ──────────────────────────────────── */
.bi3-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; padding: 24px; text-align: center;
}
.bi3-state-icon {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: var(--b3-surface-3);
  color: var(--b3-muted);
}
.bi3-state-icon svg { width: 22px; height: 22px; }
.bi3-state.error .bi3-state-icon { background: rgba(248,113,113,.12); color: var(--b3-danger); }
.bi3-state-title { font-size: 13px; font-weight: 700; color: var(--b3-text-2); }
.bi3-state-msg { font-size: 11.5px; color: var(--b3-muted); line-height: 1.5; max-width: 280px; }
.bi3-state-retry {
  margin-top: 4px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--b3-border-2);
  background: var(--b3-surface-3);
  color: var(--b3-text);
  border-radius: 9px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.bi3-state-retry:hover { background: var(--b3-surface-2); }

/* ── Dashboard vazio (página) ──────────────────────────────── */
.bi3-empty-page {
  margin: 60px auto; max-width: 460px;
  text-align: center;
  padding: 48px 32px;
  border: 1px dashed var(--b3-border-2);
  border-radius: var(--b3-radius);
  background: var(--b3-surface);
}
.bi3-empty-page h3 { font-size: 17px; font-weight: 800; margin: 0 0 8px; }
.bi3-empty-page p { font-size: 13px; color: var(--b3-muted); margin: 0 0 20px; line-height: 1.6; }

/* ── Filter drawer ─────────────────────────────────────────── */
.bi3-drawer-backdrop {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(5,8,15,.6);
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.bi3-drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.bi3-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 1101;
  width: 380px; max-width: 90vw;
  background: var(--b3-surface);
  border-left: 1px solid var(--b3-border);
  box-shadow: var(--b3-shadow-lg);
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.32,.72,0,1);
  display: flex; flex-direction: column;
  color: var(--b3-text);
  font-family: var(--b3-font);
}
.bi3-drawer.open { transform: none; }
.bi3-drawer-head {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--b3-border);
}
.bi3-drawer-head h3 { font-size: 16px; font-weight: 800; margin: 0; }
.bi3-drawer-close {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: var(--b3-surface-3); color: var(--b3-text-2);
  border-radius: 9px; font-size: 20px; cursor: pointer; font-family: inherit;
}
.bi3-drawer-close:hover { background: var(--b3-surface-2); color: var(--b3-text); }
.bi3-drawer-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 24px; }
.bi3-drawer-foot {
  flex-shrink: 0;
  padding: 16px 20px;
  border-top: 1px solid var(--b3-border);
  display: flex; gap: 10px;
}
.bi3-drawer-foot .bi3-btn { flex: 1; }

.bi3-field { display: flex; flex-direction: column; gap: 9px; }
.bi3-field-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--b3-muted);
}
.bi3-select {
  height: var(--b3-touch);
  padding: 0 12px;
  border: 1px solid var(--b3-border);
  background: var(--b3-surface-3);
  color: var(--b3-text);
  border-radius: var(--b3-radius-sm);
  font-size: 14px; font-family: inherit;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236B7689' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.bi3-select:focus { outline: none; border-color: var(--b3-accent); }

/* chips de período / empresa */
.bi3-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.bi3-chip {
  min-height: 38px;
  padding: 0 14px;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--b3-border);
  background: var(--b3-surface-3);
  color: var(--b3-text-2);
  border-radius: 999px;
  font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: all .14s;
  -webkit-tap-highlight-color: transparent;
}
.bi3-chip:hover { border-color: var(--b3-border-2); color: var(--b3-text); }
.bi3-chip.is-active {
  background: var(--b3-accent-soft);
  border-color: var(--b3-accent);
  color: #C7D2FE;
}
.bi3-chip.is-disabled { opacity: .4; pointer-events: none; }

.bi3-date-row { display: flex; align-items: center; gap: 8px; }
.bi3-date-input {
  flex: 1;
  height: var(--b3-touch);
  padding: 0 12px;
  border: 1px solid var(--b3-border);
  background: var(--b3-surface-3);
  color: var(--b3-text);
  border-radius: var(--b3-radius-sm);
  font-size: 13px; font-family: inherit;
  color-scheme: light;
}
.bi3[data-theme="dark"] .bi3-date-input,
.bi3[data-theme="dark"] .bi3-select { color-scheme: dark; }

/* ── Tela de login (standalone) ────────────────────────────── */
.bi3-login {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.bi3-login-card {
  width: 100%; max-width: 380px;
  background: var(--b3-surface);
  border: 1px solid var(--b3-border);
  border-radius: var(--b3-radius);
  box-shadow: var(--b3-shadow-lg);
  padding: 36px 32px 28px;
  text-align: center;
  animation: bi3-slidein .25s cubic-bezier(.16,1,.3,1);
}
@keyframes bi3-slidein { from { opacity:0; transform: translateY(10px); } to { opacity:1; transform:none; } }
.bi3-login-logo {
  display: inline-flex; align-items: center; justify-content: center;
  margin: 0 auto 18px; padding: 4px;
}
.bi3-login-logo img { height: 46px; width: auto; display: block; }
/* No tema escuro a logo tem texto escuro — plaquinha branca pra não sumir */
.bi3[data-theme="dark"] .bi3-login-logo {
  background: #fff; border-radius: 12px; padding: 12px 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.bi3-login-tag {
  display: inline-block; margin: 0 0 4px;
  font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
  color: var(--b3-accent);
}
.bi3-login-card h1 { font-size: 20px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 4px; }
.bi3-login-card p.sub { font-size: 13px; color: var(--b3-muted); margin: 0 0 24px; }
.bi3-login-field { text-align: left; margin-bottom: 14px; }
.bi3-login-field label {
  display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--b3-muted); margin-bottom: 6px;
}
.bi3-login-field input {
  width: 100%; height: var(--b3-touch); box-sizing: border-box;
  padding: 0 14px; border: 1px solid var(--b3-border); background: var(--b3-surface-3);
  color: var(--b3-text); border-radius: var(--b3-radius-sm);
  font-size: 15px; font-family: inherit; color-scheme: light;
}
.bi3[data-theme="dark"] .bi3-login-field input { color-scheme: dark; }
.bi3-login-field input:focus { outline: none; border-color: var(--b3-accent); box-shadow: 0 0 0 3px var(--b3-accent-soft); }
.bi3-login-btn {
  width: 100%; height: 46px; margin-top: 6px;
  background: linear-gradient(135deg, var(--b3-accent), var(--b3-accent-2)); color: #fff;
  border: none; border-radius: var(--b3-radius-sm); font-size: 14px; font-weight: 700;
  font-family: inherit; cursor: pointer; transition: filter .14s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.bi3-login-btn:hover:not(:disabled) { filter: brightness(1.08); }
.bi3-login-btn:disabled { opacity: .65; cursor: default; }
.bi3-login-btn .b3-spin { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: b3-rot .6s linear infinite; }
.bi3-login-error {
  background: rgba(220,38,38,.1); border: 1px solid rgba(220,38,38,.25);
  color: var(--b3-danger); font-size: 12.5px; font-weight: 600;
  border-radius: 9px; padding: 9px 12px; margin-bottom: 14px; text-align: left;
}
.bi3-login-foot { margin-top: 18px; font-size: 11px; color: var(--b3-muted); }

/* ── Modal de drill-down ───────────────────────────────────── */
.bi3-modal-backdrop {
  position: fixed; inset: 0; z-index: 1200;
  background: rgba(5,8,15,.5);
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease;
}
.bi3-modal-backdrop.open { opacity: 1; pointer-events: auto; }
.bi3-modal {
  position: fixed; z-index: 1201;
  top: 50%; left: 50%;
  transform: translate(-50%, -48%) scale(.98);
  width: min(920px, 92vw);
  max-height: 86vh;
  background: var(--b3-surface);
  border: 1px solid var(--b3-border);
  border-radius: var(--b3-radius);
  box-shadow: var(--b3-shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease, transform .22s cubic-bezier(.32,.72,0,1);
  color: var(--b3-text); font-family: var(--b3-font);
}
.bi3-modal.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.bi3-modal-head {
  flex-shrink: 0;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--b3-border);
}
.bi3-modal-title { font-size: 16px; font-weight: 800; margin: 0; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.bi3-modal-title svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--b3-accent); }
.bi3-modal-sub { font-size: 12px; color: var(--b3-muted); margin: 3px 0 0; }
.bi3-modal-sub strong { color: var(--b3-text-2); }
.bi3-modal-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 14px 20px 20px; }
.bi3-modal-meta {
  font-size: 11px; color: var(--b3-muted);
  text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  margin-bottom: 10px;
}

/* ── Tabs: nova aba + excluir ──────────────────────────────── */
.bi3-tab-wrap { display: inline-flex; align-items: center; flex-shrink: 0; }
.bi3-tab-del {
  width: 26px; height: 26px; margin-left: -4px; margin-right: 2px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--b3-muted);
  border-radius: 7px; cursor: pointer; transition: all .12s;
}
.bi3-tab-del:hover { background: rgba(220,38,38,.12); color: var(--b3-danger); }
.bi3-tab-del svg { width: 14px; height: 14px; }
.bi3-tab-new { color: var(--b3-accent); font-weight: 700; opacity: .9; }
.bi3-tab-new:hover { opacity: 1; }
.bi3-tab-new svg { width: 15px; height: 15px; }

/* ── Empty state com ações ─────────────────────────────────── */
.bi3-empty-spark {
  width: 56px; height: 56px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 16px;
  background: var(--b3-accent-soft); color: var(--b3-accent);
}
.bi3-empty-spark svg { width: 28px; height: 28px; }
.bi3-empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.bi3-empty-actions .bi3-btn { height: 42px; padding: 0 18px; }
.bi3-empty-actions svg { width: 16px; height: 16px; }

/* ── Modal Criar com IA ────────────────────────────────────── */
.bi3-modal-create { width: min(1080px, 94vw); }
.bi3-create-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.bi3-create-drop {
  position: relative;
  border: 2px dashed var(--b3-border-2);
  border-radius: var(--b3-radius-sm);
  padding: 16px; text-align: center;
  color: var(--b3-muted); font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: all .14s; background: var(--b3-surface-2);
}
.bi3-create-drop:hover, .bi3-create-drop.drag { border-color: var(--b3-accent); color: var(--b3-accent); background: var(--b3-accent-soft); }
.bi3-create-drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.bi3-create-file { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; color: var(--b3-text); }
.bi3-create-file button { border: none; background: none; color: var(--b3-muted); font-size: 18px; cursor: pointer; }
.bi3-create-file button:hover { color: var(--b3-danger); }
.bi3-create-prompt {
  width: 100%; border: 1px solid var(--b3-border); background: var(--b3-surface-3);
  color: var(--b3-text); border-radius: var(--b3-radius-sm); padding: 11px 13px;
  font-family: inherit; font-size: 14px; line-height: 1.5; resize: vertical; box-sizing: border-box;
}
.bi3-create-prompt:focus { outline: none; border-color: var(--b3-accent); }
.bi3-create-prompt::placeholder { color: var(--b3-muted); }

.bi3-create-preview { margin-top: 18px; border-top: 1px solid var(--b3-border); padding-top: 16px; }
.bi3-create-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.bi3-create-preview-head strong { font-size: 14px; }
.bi3-create-save-row { display: flex; gap: 8px; align-items: center; }
.bi3-create-save-row .bi3-select { min-width: 200px; }
.bi3-create-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.bi3-create-card { background: var(--b3-surface-2); border: 1px solid var(--b3-border); border-radius: var(--b3-radius-sm); overflow: hidden; display: flex; flex-direction: column; }
.bi3-create-card.has-error { border-color: rgba(220,38,38,.4); }
.bi3-create-card-head { padding: 12px 14px 8px; }
.bi3-create-card-head h4 { font-size: 13px; font-weight: 700; margin: 0 0 3px; }
.bi3-create-card-head p { font-size: 11px; color: var(--b3-muted); margin: 0 0 6px; line-height: 1.4; }
.bi3-create-tags { display: flex; gap: 5px; flex-wrap: wrap; }
.bi3-create-card-body { flex: 1; min-height: 160px; position: relative; padding: 4px 10px 12px; }

/* ── Menu de exportação (popover) ──────────────────────────── */
.bi3-exmenu {
  position: fixed; z-index: 1300;
  min-width: 220px; padding: 6px;
  background: var(--b3-surface, #fff);
  border: 1px solid var(--b3-border, #E5E7EB);
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(15,23,42,.22);
  display: flex; flex-direction: column; gap: 2px;
  font-family: var(--b3-font, -apple-system, sans-serif);
  animation: bi3-fadein .14s ease;
}
.bi3[data-theme="dark"] .bi3-exmenu,
.bi3-exmenu { color: var(--b3-text, #0F172A); }
.bi3-exmenu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; min-height: 40px;
  border: none; background: transparent; cursor: pointer;
  border-radius: 8px; font-size: 13px; font-weight: 600; font-family: inherit;
  color: var(--b3-text, #0F172A); text-align: left; transition: background .12s;
}
.bi3-exmenu-item:hover:not([disabled]) { background: var(--b3-accent-soft, #eef2ff); color: var(--b3-accent, #1E4FC2); }
.bi3-exmenu-item[disabled] { opacity: .5; cursor: default; }
.bi3-exmenu-item svg { flex-shrink: 0; color: var(--b3-accent, #1E4FC2); }

/* ── Tabela analítica do drill-down ────────────────────────── */
/* Modal mais largo (muitas colunas) e corpo em coluna flex */
#bi3DrillModal { width: min(1240px, 96vw); }
#bi3DrillModal .bi3-modal-body { padding: 0; display: flex; flex-direction: column; overflow: hidden; }

.bi3-dt { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* Toolbar: busca global + contagem + page size */
.bi3-dt-toolbar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--b3-border);
  background: var(--b3-surface);
}
.bi3-dt-search {
  position: relative; flex: 1; max-width: 360px; display: flex; align-items: center;
}
.bi3-dt-search svg { position: absolute; left: 11px; width: 15px; height: 15px; color: var(--b3-muted); pointer-events: none; }
.bi3-dt-search input {
  width: 100%; height: 38px; padding: 0 12px 0 34px;
  border: 1px solid var(--b3-border); background: var(--b3-surface-3); color: var(--b3-text);
  border-radius: var(--b3-radius-sm); font-size: 13.5px; font-family: inherit;
}
.bi3-dt-search input:focus { outline: none; border-color: var(--b3-accent); }
.bi3-dt-toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.bi3-dt-count { font-size: 12px; color: var(--b3-muted); font-weight: 600; white-space: nowrap; }
.bi3-dt-pagesize { font-size: 12px; color: var(--b3-muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.bi3-dt-pagesize select {
  height: 32px; border: 1px solid var(--b3-border); background: var(--b3-surface-3); color: var(--b3-text);
  border-radius: 8px; font-size: 12.5px; font-family: inherit; padding: 0 6px; color-scheme: light;
}
.bi3[data-theme="dark"] .bi3-dt-pagesize select { color-scheme: dark; }

/* Área rolável (x e y) */
.bi3-dt-scroll { flex: 1; overflow: auto; min-height: 0; -webkit-overflow-scrolling: touch; position: relative; }

.bi3-dt-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; min-width: max-content; }

/* Cabeçalho ordenável (sticky) */
.bi3-dt-table thead th { background: var(--b3-surface-2); position: sticky; z-index: 2; }
.bi3-dt-head th {
  top: 0; cursor: pointer; user-select: none;
  padding: 10px 12px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--b3-border);
  color: var(--b3-muted); font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  transition: color .12s, background .12s;
}
.bi3-dt-head th:hover { color: var(--b3-accent); background: var(--b3-surface-3); }
.bi3-dt-head th.num .bi3-dt-th { justify-content: flex-end; }
.bi3-dt-th { display: inline-flex; align-items: center; gap: 2px; }
.bi3-dt-arrow { color: var(--b3-accent); font-weight: 900; }

/* Linha de filtros por coluna (sticky logo abaixo do cabeçalho) */
.bi3-dt-filters th { top: 36px; padding: 6px 8px; border-bottom: 1px solid var(--b3-border); }
.bi3-dt-filter {
  width: 100%; min-width: 90px; height: 30px; box-sizing: border-box;
  padding: 0 8px; border: 1px solid var(--b3-border); background: var(--b3-surface);
  color: var(--b3-text); border-radius: 7px; font-size: 12px; font-family: inherit;
}
.bi3-dt-filter:focus { outline: none; border-color: var(--b3-accent); background: var(--b3-surface-3); }
.bi3-dt-filter::placeholder { color: var(--b3-muted); opacity: .7; }

/* Corpo */
.bi3-dt-table tbody td {
  padding: 9px 12px; white-space: nowrap; border-bottom: 1px solid var(--b3-border);
  color: var(--b3-text-2);
}
.bi3-dt-table tbody td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--b3-text); }
.bi3-dt-table tbody td.date { font-variant-numeric: tabular-nums; }
.bi3-dt-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--b3-surface-2) 50%, transparent); }
.bi3-dt-table tbody tr:hover td { background: var(--b3-accent-soft); }

/* Empty */
.bi3-dt-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 48px 20px; text-align: center;
}

/* Rodapé / paginação */
.bi3-dt-foot {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; border-top: 1px solid var(--b3-border); background: var(--b3-surface);
  font-size: 12px; color: var(--b3-muted);
}
.bi3-dt-pager { display: flex; align-items: center; gap: 10px; }
.bi3-dt-pginfo { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--b3-text-2); }
.bi3-dt-pgbtn {
  width: 34px; height: 34px; border: 1px solid var(--b3-border); background: var(--b3-surface-3);
  color: var(--b3-text); border-radius: 9px; font-size: 18px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; transition: all .12s;
}
.bi3-dt-pgbtn:hover:not(:disabled) { border-color: var(--b3-accent); color: var(--b3-accent); }
.bi3-dt-pgbtn:disabled { opacity: .4; cursor: default; }

@media (max-width: 640px) {
  .bi3-dt-toolbar { flex-wrap: wrap; }
  .bi3-dt-search { max-width: 100%; }
  .bi3-dt-toolbar-right { width: 100%; justify-content: space-between; }
}

/* ── Editor de painel ──────────────────────────────────────── */
.bi3-modal-edit { width: min(560px, 94vw); }
.bi3-modal-foot {
  flex-shrink: 0; padding: 14px 20px; border-top: 1px solid var(--b3-border);
  display: flex; gap: 10px; justify-content: flex-end;
}
.bi3-modal-foot .bi3-btn { min-width: 110px; height: 40px; }
.bi3-edit-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }

.bi3-charttype-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bi3-charttype {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 6px; border: 1px solid var(--b3-border); background: var(--b3-surface-2);
  border-radius: var(--b3-radius-sm); color: var(--b3-text-2);
  font-size: 11px; font-weight: 600; font-family: inherit; cursor: pointer; transition: all .12s;
  -webkit-tap-highlight-color: transparent;
}
.bi3-charttype svg { width: 22px; height: 22px; }
.bi3-charttype:hover { border-color: var(--b3-border-2); color: var(--b3-text); }
.bi3-charttype.is-active {
  border-color: var(--b3-accent); background: var(--b3-accent-soft); color: var(--b3-accent);
}
.bi3-edit-preview {
  border: 1px solid var(--b3-border); border-radius: var(--b3-radius-sm);
  background: var(--b3-surface-2); overflow: hidden;
}

/* Segmented control (presets de tamanho) */
.bi3-segmented { display: inline-flex; background: var(--b3-surface-3); border: 1px solid var(--b3-border); border-radius: var(--b3-radius-sm); padding: 3px; gap: 2px; width: 100%; }
.bi3-segmented button {
  flex: 1; height: 36px; border: none; background: transparent; cursor: pointer;
  border-radius: 8px; font-size: 12.5px; font-weight: 600; font-family: inherit; color: var(--b3-muted); transition: all .12s;
}
.bi3-segmented button:hover { color: var(--b3-text); }
.bi3-segmented button.is-active { background: var(--b3-surface); color: var(--b3-accent); box-shadow: 0 1px 3px rgba(15,23,42,.12); }
.bi3[data-theme="dark"] .bi3-segmented button.is-active { background: var(--b3-accent-soft); box-shadow: none; }

/* Botão de exclusão */
.bi3-btn-danger { color: var(--b3-danger); border-color: transparent; background: transparent; }
.bi3-btn-danger:hover { background: rgba(220,38,38,.1); border-color: transparent; color: var(--b3-danger); }
.bi3-btn-danger svg { width: 15px; height: 15px; }

@media (max-width: 520px) {
  .bi3-charttype-grid { grid-template-columns: repeat(3, 1fr); }
  .bi3-edit-row { grid-template-columns: 1fr; }
}

/* ── Responsivo ────────────────────────────────────────────────
   O nº de colunas do grid (e o colapso em tablet/telefone) é
   controlado pelo GridStack via columnOpts.breakpoints em bi3.js
   (700→1col, 1100→6col). Aqui só ajustes de chrome (header, tabs,
   espaçamentos). As antigas regras grid-column foram removidas:
   no grid real os itens são posicionados em absoluto, não por grid. */
@media (max-width: 834px) {
  .bi3-header { padding: 14px 18px; gap: 12px; }
  .bi3-title { font-size: 17px; }
  .bi3-tabs { padding: 8px 18px 0; }
  .bi3-body { padding: 16px 18px 36px; }
  .bi3-grid { gap: 14px; }
  /* esconde o label do botão atualizar em telas estreitas, mantém ícone */
  .bi3-btn-label-hide { display: none; }
}

/* ── iPhone / telas pequenas (≤520) ────────────────────────── */
@media (max-width: 520px) {
  .bi3-header { flex-wrap: wrap; }
  .bi3-drawer { width: 100%; max-width: 100%; }
}

/* ── Acessibilidade: reduz movimento ───────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .bi3-freshness-dot, .bi3-skel-bar, .bi3 *, .bi3-drawer { animation: none !important; transition: none !important; }
}

/* ── Inspetor SQL & Fonte (modal de edição — admin) ─────────── */
.bi3-sql-section {
  margin: 18px 0 8px;
  padding: 14px;
  border: 1px solid var(--b3-border);
  border-radius: var(--b3-radius-sm);
  background: var(--b3-surface-2);
}
.bi3-sql-section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.bi3-source-badge {
  font-size: 11.5px; font-weight: 600;
  color: var(--b3-accent); background: var(--b3-accent-soft);
  border: 1px solid var(--b3-accent-soft);
  padding: 4px 10px; border-radius: 999px;
}
.bi3-sql-editor {
  width: 100%; box-sizing: border-box;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5;
  color: var(--b3-text); background: var(--b3-bg);
  border: 1px solid var(--b3-border-2); border-radius: var(--b3-radius-xs);
  padding: 10px 12px; resize: vertical; min-height: 150px;
  tab-size: 2;
}
.bi3-sql-editor:focus { outline: none; border-color: var(--b3-accent); box-shadow: 0 0 0 3px var(--b3-accent-soft); }
.bi3-sql-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.bi3-sql-status { font-size: 12px; font-weight: 600; }
.bi3-sql-status.ok  { color: var(--b3-success); }
.bi3-sql-status.err { color: var(--b3-danger); }
.bi3-sql-executed { margin-top: 8px; }
.bi3-sql-executed > summary {
  cursor: pointer; font-size: 12px; font-weight: 600;
  color: var(--b3-text-2); padding: 4px 0; user-select: none;
}
.bi3-sql-pre {
  margin: 8px 0 0; padding: 10px 12px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11.5px; line-height: 1.5;
  color: var(--b3-text-2); background: var(--b3-bg);
  border: 1px solid var(--b3-border); border-radius: var(--b3-radius-xs);
  max-height: 220px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.bi3-sql-section code {
  font-family: ui-monospace, monospace; font-size: 11px;
  background: var(--b3-surface-3); padding: 1px 5px; border-radius: 4px;
}
