/* =========================================================================
   Dashboard BI — theme isolado
   Cores semânticas:
     - azul     → faturamento / dados
     - verde    → meta / sucesso
     - laranja  → atenção / pendência
     - vermelho → alerta / queda
   ========================================================================= */
.bi {
    --bi-bg: #ffffff;
    --bi-bg-muted: #f8fafc;
    --bi-border: #e2e8f0;
    --bi-border-strong: #cbd5e1;
    --bi-text: #1e293b;
    --bi-muted: #64748b;
    --bi-helper: #94a3b8;

    --bi-blue:    #2563eb;
    --bi-blue-bg: #eff6ff;
    --bi-green:   #16a34a;
    --bi-green-bg:#f0fdf4;
    --bi-orange:  #ea580c;
    --bi-orange-bg:#fff7ed;
    --bi-red:     #dc2626;
    --bi-red-bg:  #fef2f2;
    --bi-yellow:  #ca8a04;
    --bi-yellow-bg:#fefce8;

    --bi-radius: 12px;
    --bi-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}

/* ----- header + tabs ----- */
.bi-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.bi-title {
    display: flex; align-items: center; gap: 12px;
}
.bi-title-icon {
    width: 44px; height: 44px; border-radius: 12px;
    background: var(--bi-blue-bg); color: var(--bi-blue);
    display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.bi-title h2 { margin: 0; color: var(--bi-text); font-size: 1.25rem; font-weight: 700; }
.bi-title p  { margin: 2px 0 0; font-size: .875rem; color: var(--bi-muted); }

.bi-tabs-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--bi-border);
}
.bi-tabs { display: flex; gap: 4px; overflow-x: auto; }
.bi-tab {
    background: transparent; border: 0;
    border-bottom: 2px solid transparent;
    padding: 12px 20px; font-size: .875rem; font-weight: 500;
    color: var(--bi-muted); cursor: pointer; white-space: nowrap;
    transition: color .15s, border-color .15s;
}
.bi-tab:hover { color: var(--bi-text); }
.bi-tab.is-active { color: var(--bi-blue); border-bottom-color: var(--bi-blue); }
.bi-period { color: var(--bi-muted); font-size: .875rem; }

/* ----- KPI cards (row 1) ----- */
.bi-kpis {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 12px;
}
.bi-kpi {
    background: var(--bi-bg);
    border: 1px solid var(--bi-border);
    border-radius: var(--bi-radius);
    padding: 16px;
    display: flex; flex-direction: column;
    min-height: 120px;
    box-shadow: var(--bi-shadow);
    transition: transform .15s, border-color .15s;
}
.bi-kpi:hover { border-color: var(--bi-border-strong); transform: translateY(-1px); }
.bi-kpi-head { display: flex; align-items: center; gap: 8px; }
.bi-kpi-icon {
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.bi-kpi-icon.is-blue   { background: var(--bi-blue-bg);   color: var(--bi-blue); }
.bi-kpi-icon.is-green  { background: var(--bi-green-bg);  color: var(--bi-green); }
.bi-kpi-icon.is-orange { background: var(--bi-orange-bg); color: var(--bi-orange); }
.bi-kpi-icon.is-red    { background: var(--bi-red-bg);    color: var(--bi-red); }
.bi-kpi-icon.is-yellow { background: var(--bi-yellow-bg); color: var(--bi-yellow); }
.bi-kpi-label {
    font-size: .6875rem; font-weight: 600;
    color: var(--bi-muted); text-transform: uppercase; letter-spacing: .04em;
}
.bi-kpi-value {
    margin-top: 6px;
    font-size: 1.25rem; font-weight: 700; color: var(--bi-text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bi-kpi-foot {
    display: flex; justify-content: space-between; align-items: flex-end;
    gap: 8px; margin-top: auto;
}
.bi-delta {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: .75rem; font-weight: 600;
}
.bi-delta.is-up    { color: var(--bi-green); }
.bi-delta.is-down  { color: var(--bi-red); }
.bi-delta.is-flat  { color: var(--bi-muted); }
.bi-spark { width: 80px; height: 32px; }

/* KPI Meta×Realizado: gauge donut */
.bi-kpi.is-gauge .bi-gauge-wrap {
    display: flex; align-items: center; gap: 12px; margin-top: 6px;
}
.bi-kpi.is-gauge canvas { width: 70px !important; height: 70px !important; }
.bi-gauge-text { display: flex; flex-direction: column; }
.bi-gauge-pct  { font-size: 1.25rem; font-weight: 700; color: var(--bi-text); line-height: 1; }
.bi-gauge-sub  { font-size: .6875rem; color: var(--bi-muted); margin-top: 4px; }

/* ----- Chart cards (rows 2/3) ----- */
.bi-chart-card {
    background: var(--bi-bg);
    border: 1px solid var(--bi-border);
    border-radius: var(--bi-radius);
    padding: 20px;
    box-shadow: var(--bi-shadow);
}
.bi-chart-card h3 {
    margin: 0 0 12px;
    font-size: 1rem; font-weight: 600; color: var(--bi-text);
    display: flex; align-items: center; gap: 8px;
}
.bi-chart-card h3 i { color: var(--bi-blue); }
.bi-chart-card p.bi-chart-sub {
    margin: 0 0 16px; font-size: .8125rem; color: var(--bi-muted);
}
.bi-chart-host {
    position: relative;
    height: 320px;
}

/* ----- Insights (row 4) ----- */
.bi-insights {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}
.bi-insight {
    background: var(--bi-bg);
    border: 1px solid var(--bi-border);
    border-radius: var(--bi-radius);
    padding: 16px;
    box-shadow: var(--bi-shadow);
    display: flex; gap: 12px; align-items: flex-start;
}
.bi-insight-icon {
    width: 36px; height: 36px; border-radius: 999px;
    display: flex; align-items: center; justify-content: center; font-size: 18px;
    flex-shrink: 0;
}
.bi-insight-title {
    margin: 0; font-size: .875rem; font-weight: 600; color: var(--bi-text);
}
.bi-insight-text {
    margin: 4px 0 0; font-size: .8125rem; color: var(--bi-muted); line-height: 1.4;
}
.bi-insight.is-positive .bi-insight-icon { background: var(--bi-green-bg);  color: var(--bi-green); }
.bi-insight.is-warning  .bi-insight-icon { background: var(--bi-orange-bg); color: var(--bi-orange); }
.bi-insight.is-record   .bi-insight-icon { background: var(--bi-yellow-bg); color: var(--bi-yellow); }
.bi-insight.is-info     .bi-insight-icon { background: var(--bi-blue-bg);   color: var(--bi-blue); }

/* ----- Ranking (row 5) ----- */
.bi-ranking { overflow-x: auto; }
.bi-ranking table { width: 100%; border-collapse: collapse; min-width: 720px; }
.bi-ranking thead { background: var(--bi-bg-muted); }
.bi-ranking th {
    text-align: left; padding: 12px 16px; font-size: .75rem; font-weight: 600;
    color: var(--bi-muted); text-transform: uppercase; letter-spacing: .04em;
    border-bottom: 1px solid var(--bi-border);
}
.bi-ranking td {
    padding: 14px 16px; font-size: .875rem; color: var(--bi-text);
    border-bottom: 1px solid var(--bi-border);
}
.bi-ranking tr:last-child td { border-bottom: 0; }
.bi-ranking tr.is-current td { background: var(--bi-blue-bg); }
.bi-rank-pos {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; border-radius: 999px;
    background: var(--bi-bg-muted); color: var(--bi-text);
    font-size: .75rem; font-weight: 700;
}
.bi-rank-pos.is-top { background: #fef3c7; color: #92400e; }
.bi-progress {
    position: relative;
    width: 140px; height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden;
}
.bi-progress-bar {
    position: absolute; left: 0; top: 0; bottom: 0;
    background: var(--bi-green); border-radius: 999px;
    transition: width .4s;
}
.bi-progress-bar.is-low  { background: var(--bi-orange); }
.bi-progress-bar.is-mid  { background: var(--bi-yellow); }
.bi-progress-text { font-size: .75rem; color: var(--bi-muted); margin-top: 2px; }

/* ----- Empty/error states ----- */
.bi-empty {
    background: var(--bi-bg-muted);
    border: 1px dashed var(--bi-border-strong);
    border-radius: var(--bi-radius);
    padding: 32px; text-align: center; color: var(--bi-muted);
}

/* ----- Responsividade ----- */
@media (max-width: 1536px) {
    .bi-kpis      { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .bi-insights  { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
    .bi-kpis      { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .bi-insights  { grid-template-columns: 1fr; }
    .bi-chart-host{ height: 280px; }
    .bi-header    { flex-direction: column; align-items: stretch; }
}
