/* ============================================================
 * BI 2.0 — Stylesheet
 * Visual sóbrio inspirado em Linear / Stripe / Power BI moderno.
 * Dark-first não, mas com paleta clean light + acentos vivos.
 * ============================================================ */

.bi2-page {
  --bi2-bg: #f6f7fb;
  --bi2-card: #ffffff;
  --bi2-border: #e5e7eb;
  --bi2-border-strong: #d1d5db;
  --bi2-text: #0f172a;
  --bi2-muted: #64748b;
  --bi2-accent: #4f46e5;
  --bi2-accent-soft: #eef2ff;
  --bi2-success: #10b981;
  --bi2-danger:  #ef4444;
  --bi2-warning: #f59e0b;
  --bi2-radius: 12px;
  --bi2-radius-sm: 8px;
  --bi2-shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 12px rgba(15,23,42,.04);
}

/* ── Top bar (cliente, empresa, período) ───────────────────── */
.bi2-toolbar {
  background: var(--bi2-card);
  border: 1px solid var(--bi2-border);
  border-radius: var(--bi2-radius);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
  box-shadow: var(--bi2-shadow);
}
.bi2-toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bi2-toolbar-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--bi2-muted);
}
.bi2-toolbar-divider {
  width: 1px;
  height: 28px;
  background: var(--bi2-border);
}

/* ── Multi-select empresa (chips) ───────────────────────────── */
.bi2-empresas {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.bi2-empresa-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--bi2-border);
  background: #fff;
  color: var(--bi2-muted);
  cursor: pointer;
  user-select: none;
  transition: all .15s;
}
.bi2-empresa-chip:hover {
  border-color: var(--bi2-accent);
  color: var(--bi2-text);
}
.bi2-empresa-chip.is-active {
  background: var(--bi2-accent);
  color: #fff;
  border-color: var(--bi2-accent);
}
.bi2-empresa-chip.is-disabled,
.bi2-empresa-chip[disabled] {
  background: #f8fafc;
  color: #94a3b8;
  border-color: #e2e8f0;
  cursor: not-allowed;
  opacity: .7;
  pointer-events: none;
}
.bi2-empresa-chip-all {
  font-size: 11px;
  color: var(--bi2-accent);
  background: var(--bi2-accent-soft);
  border-color: var(--bi2-accent-soft);
}

/* ── Period selector (pills) ────────────────────────────────── */
.bi2-period {
  display: inline-flex;
  background: #f1f5f9;
  border-radius: var(--bi2-radius-sm);
  padding: 3px;
  gap: 2px;
}
.bi2-period-btn {
  padding: 6px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--bi2-muted);
  cursor: pointer;
  transition: all .12s;
}
.bi2-period-btn:hover { color: var(--bi2-text); }
.bi2-period-btn.is-active {
  background: #fff;
  color: var(--bi2-text);
  box-shadow: 0 1px 3px rgba(15,23,42,.08);
}
.bi2-period-custom-inputs {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin-left: 8px;
}
.bi2-date-input {
  border: 1px solid var(--bi2-border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
}

/* ── Dashboard tabs ─────────────────────────────────────────── */
.bi2-dashboard-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--bi2-border);
  padding: 0 4px;
  overflow-x: auto;
}
.bi2-tab {
  padding: 10px 14px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--bi2-muted);
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  border-radius: 6px 6px 0 0;
  transition: all .12s;
}
.bi2-tab:hover { color: var(--bi2-text); }
.bi2-tab.is-active {
  color: var(--bi2-accent);
}
.bi2-tab.is-active::after {
  content: '';
  position: absolute;
  left: 8px; right: 8px; bottom: -1px;
  height: 2px;
  background: var(--bi2-accent);
  border-radius: 2px;
}
.bi2-tab-add {
  color: var(--bi2-muted);
  font-weight: 500;
}

/* ── Grid de painéis ────────────────────────────────────────── */
.bi2-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}
.bi2-panel {
  background: var(--bi2-card);
  border: 1px solid var(--bi2-border);
  border-radius: var(--bi2-radius);
  box-shadow: var(--bi2-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 200px;
}
.bi2-panel-head {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--bi2-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.bi2-panel-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--bi2-text);
  line-height: 1.25;
  margin: 0 0 2px;
}
.bi2-panel-desc {
  font-size: 11px;
  color: var(--bi2-muted);
  line-height: 1.4;
  margin: 0;
}
.bi2-panel-actions {
  display: flex;
  gap: 4px;
}
.bi2-icon-btn {
  width: 26px; height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: var(--bi2-muted);
  cursor: pointer;
  transition: all .12s;
}
.bi2-icon-btn:hover { background: #f1f5f9; color: var(--bi2-text); }

.bi2-panel-body {
  flex: 1;
  padding: 12px 14px;
  position: relative;
  min-height: 160px;
}
.bi2-panel-foot {
  padding: 6px 14px 8px;
  font-size: 10px;
  color: var(--bi2-muted);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-top: 1px solid var(--bi2-border);
}
.bi2-tag {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.bi2-tag-cache-hit { background: #ecfdf5; color: #047857; }

/* ── States ─────────────────────────────────────────────────── */
.bi2-loading, .bi2-empty, .bi2-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--bi2-muted);
  text-align: center;
  padding: 16px;
}
.bi2-error {
  color: var(--bi2-danger);
  flex-direction: column;
  gap: 8px;
}
.bi2-spinner {
  width: 24px; height: 24px;
  border: 2.5px solid #e5e7eb;
  border-top-color: var(--bi2-accent);
  border-radius: 50%;
  animation: bi2-spin .6s linear infinite;
}
@keyframes bi2-spin { to { transform: rotate(360deg); } }

/* ── ECharts containers ─────────────────────────────────────── */
.bi2-chart {
  width: 100%;
  height: 100%;
  min-height: 200px;
}

/* ── Tabela ─────────────────────────────────────────────────── */
.bi2-table-wrap {
  width: 100%;
  height: 100%;
  overflow: auto;
}
.bi2-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.bi2-table th, .bi2-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--bi2-border);
  text-align: left;
  white-space: nowrap;
}
.bi2-table th {
  background: #f8fafc;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--bi2-muted);
  position: sticky;
  top: 0;
  z-index: 1;
}
.bi2-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── KPI ────────────────────────────────────────────────────── */
.bi2-kpi {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  height: 100%;
  padding: 8px 4px;
}
.bi2-kpi-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--bi2-text);
  letter-spacing: -.02em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.bi2-kpi-label {
  font-size: 11px;
  color: var(--bi2-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* ── Empty state do dashboard ───────────────────────────────── */
.bi2-empty-dashboard {
  background: var(--bi2-card);
  border: 1px dashed var(--bi2-border-strong);
  border-radius: var(--bi2-radius);
  padding: 60px 20px;
  text-align: center;
  color: var(--bi2-muted);
}
.bi2-empty-dashboard h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--bi2-text);
  margin: 0 0 6px;
}
.bi2-empty-dashboard p { font-size: 13px; margin: 0 0 16px; }

/* ── Botões ─────────────────────────────────────────────────── */
.bi2-btn {
  padding: 7px 14px;
  border: 1px solid var(--bi2-border);
  background: #fff;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--bi2-text);
  cursor: pointer;
  transition: all .12s;
}
.bi2-btn:hover { border-color: var(--bi2-accent); color: var(--bi2-accent); }
.bi2-btn-primary {
  background: var(--bi2-accent);
  color: #fff;
  border-color: var(--bi2-accent);
}
.bi2-btn-primary:hover { background: #4338ca; border-color: #4338ca; color: #fff; }

/* ── Cliente picker (platform_admin) ────────────────────────── */
.bi2-client-picker select {
  border: 1px solid var(--bi2-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  background: #fff;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .bi2-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .bi2-panel { grid-column: span 6 !important; }
}
@media (max-width: 600px) {
  .bi2-grid { grid-template-columns: 1fr; }
  .bi2-panel { grid-column: span 1 !important; }
}

/* ── Analista IA ─────────────────────────────────────────────── */
.bi2-analyst-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(3px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: bi2-fadein .18s ease;
}
@keyframes bi2-fadein { from { opacity: 0; } to { opacity: 1; } }

.bi2-analyst-dialog {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .22), 0 4px 16px rgba(15, 23, 42, .08);
  width: 100%;
  max-width: 1080px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: bi2-slidein .2s cubic-bezier(.16,1,.3,1);
}
@keyframes bi2-slidein {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.bi2-analyst-dialog-header {
  padding: 18px 24px 16px;
  border-bottom: 1px solid var(--bi2-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.bi2-analyst-dialog-header h2 {
  font-size: 17px;
  font-weight: 800;
  color: var(--bi2-text);
  margin: 0 0 2px;
  letter-spacing: -.02em;
}
.bi2-analyst-dialog-header p {
  font-size: 12px;
  color: var(--bi2-muted);
  margin: 0;
  line-height: 1.4;
}
.bi2-analyst-close {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border: none;
  background: #f1f5f9;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  color: var(--bi2-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .12s;
}
.bi2-analyst-close:hover { background: #e2e8f0; color: var(--bi2-text); }

.bi2-analyst-dialog-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* Input column */
.bi2-analyst-input-col {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--bi2-border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

/* Full-width input state (before first generation) */
.bi2-analyst-dialog-body.no-panels .bi2-analyst-input-col {
  width: 100%;
  max-width: 560px;
  border-right: none;
  margin: 0 auto;
  padding: 32px 40px;
}

/* Dropzone */
.bi2-analyst-dropzone {
  border: 2px dashed var(--bi2-border-strong);
  border-radius: 10px;
  padding: 22px 16px;
  text-align: center;
  color: var(--bi2-muted);
  cursor: pointer;
  transition: all .15s;
  position: relative;
  background: #fafbfd;
  font-size: 13px;
}
.bi2-analyst-dropzone:hover,
.bi2-analyst-dropzone.drag-over {
  border-color: var(--bi2-accent);
  background: var(--bi2-accent-soft);
  color: var(--bi2-accent);
}
.bi2-analyst-dropzone input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.bi2-analyst-dropzone-icon {
  font-size: 28px;
  margin-bottom: 6px;
  display: block;
}
.bi2-analyst-dropzone-hint {
  font-size: 11px;
  color: var(--bi2-muted);
  margin-top: 4px;
}
.bi2-analyst-file-selected {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bi2-accent-soft);
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--bi2-text);
}
.bi2-analyst-file-icon { font-size: 18px; flex-shrink: 0; }
.bi2-analyst-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.bi2-analyst-file-remove {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--bi2-muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
}
.bi2-analyst-file-remove:hover { color: var(--bi2-danger); }

/* Prompt */
.bi2-analyst-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--bi2-muted);
  margin-bottom: 4px;
  display: block;
}
.bi2-analyst-prompt {
  width: 100%;
  min-height: 110px;
  border: 1px solid var(--bi2-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  color: var(--bi2-text);
  resize: vertical;
  transition: border-color .12s;
  box-sizing: border-box;
  background: #fff;
}
.bi2-analyst-prompt:focus {
  outline: none;
  border-color: var(--bi2-accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .1);
}

.bi2-analyst-generate-btn {
  width: 100%;
  padding: 11px 16px;
  background: var(--bi2-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.bi2-analyst-generate-btn:hover:not(:disabled) { background: #4338ca; }
.bi2-analyst-generate-btn:disabled {
  opacity: .6;
  cursor: not-allowed;
}
.bi2-analyst-generate-btn .spin {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: bi2-spin .6s linear infinite;
  flex-shrink: 0;
}
.bi2-analyst-stats {
  font-size: 11px;
  color: var(--bi2-muted);
  text-align: center;
  padding: 4px 0;
}

/* Preview column */
.bi2-analyst-preview-col {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  min-width: 0;
}
.bi2-analyst-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.bi2-analyst-preview-header h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--bi2-text);
  margin: 0;
}
.bi2-analyst-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

/* Preview card */
.bi2-analyst-card {
  background: #fff;
  border: 1px solid var(--bi2-border);
  border-radius: var(--bi2-radius);
  box-shadow: var(--bi2-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow .15s;
}
.bi2-analyst-card:hover { box-shadow: 0 4px 20px rgba(15,23,42,.1); }
.bi2-analyst-card.has-error { border-color: #fecaca; background: #fff8f8; }

.bi2-analyst-card-head {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--bi2-border);
}
.bi2-analyst-card-head h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--bi2-text);
  margin: 0 0 3px;
  line-height: 1.25;
}
.bi2-analyst-card-head p {
  font-size: 11px;
  color: var(--bi2-muted);
  margin: 0 0 6px;
  line-height: 1.4;
}
.bi2-analyst-card-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.bi2-analyst-card-body {
  flex: 1;
  position: relative;
  min-height: 160px;
}

.bi2-analyst-card-foot {
  padding: 10px 14px;
  border-top: 1px solid var(--bi2-border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.bi2-analyst-card-foot select {
  flex: 1;
  font-size: 12px;
  border: 1px solid var(--bi2-border);
  border-radius: 6px;
  padding: 5px 8px;
  font-family: inherit;
  background: #fff;
  color: var(--bi2-text);
  min-width: 0;
}
.bi2-analyst-card-save-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  background: var(--bi2-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s;
  white-space: nowrap;
}
.bi2-analyst-card-save-btn:hover:not(:disabled) { background: #4338ca; }
.bi2-analyst-card-save-btn:disabled { opacity: .6; cursor: default; }
.bi2-analyst-card-saved {
  font-size: 12px;
  color: var(--bi2-success);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Analyst button in toolbar */
.bi2-btn-analyst {
  background: linear-gradient(135deg, var(--bi2-accent), #7c3aed);
  color: #fff;
  border-color: transparent;
  letter-spacing: .01em;
}
.bi2-btn-analyst:hover {
  background: linear-gradient(135deg, #4338ca, #6d28d9);
  color: #fff;
  border-color: transparent;
}
.bi2-btn-analyst:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* Empty preview state */
.bi2-analyst-preview-empty {
  grid-column: 1 / -1;
  padding: 48px 20px;
  text-align: center;
  color: var(--bi2-muted);
  font-size: 13px;
}

@media (max-width: 740px) {
  .bi2-analyst-dialog-body { flex-direction: column; }
  .bi2-analyst-input-col {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--bi2-border);
    max-height: 300px;
  }
}
