/* ══════════════════════════════════════════════════════════════
   Biomed Dashboard — Design System (Dash Plotly)
   Migrado de dashboard/static/style.css
   Complementa o tema dbc.themes.FLATLY
   ══════════════════════════════════════════════════════════════ */

:root {
    /* Primary */
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --primary-200: #c7d2fe;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;
    --primary-800: #3730a3;
    --primary-900: #312e81;

    /* Success */
    --success-50: #ecfdf5;
    --success-100: #d1fae5;
    --success-500: #10b981;
    --success-600: #059669;
    --success-700: #047857;

    /* Warning */
    --warning-50: #fffbeb;
    --warning-100: #fef3c7;
    --warning-500: #f59e0b;
    --warning-600: #d97706;

    /* Danger */
    --danger-50: #fef2f2;
    --danger-100: #fee2e2;
    --danger-500: #ef4444;
    --danger-600: #dc2626;
    --danger-700: #b91c1c;

    /* Neutrals */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* ── Global ───────────────────────────────────────────────────── */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50) !important;
    color: var(--gray-800);
    -webkit-font-smoothing: antialiased;
}

/* ── Navbar Overrides ─────────────────────────────────────────── */

.navbar-biomed {
    background: var(--gray-900) !important;
    box-shadow: var(--shadow-md);
    min-height: 56px;
    padding: 0 var(--space-8);
}

.navbar-biomed .navbar-brand-custom {
    font-size: 1.15rem;
    font-weight: 700;
    color: white !important;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
}

.brand-dot {
    width: 8px;
    height: 8px;
    background: var(--primary-500);
    border-radius: var(--radius-full);
    display: inline-block;
}

.navbar-biomed .nav-link {
    color: var(--gray-400) !important;
    font-size: 0.875rem;
    font-weight: 500;
    padding: var(--space-2) var(--space-4) !important;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}

.navbar-biomed .nav-link:hover {
    color: white !important;
    background: rgba(255, 255, 255, 0.08);
}

.navbar-biomed .nav-link.active {
    color: white !important;
    background: rgba(255, 255, 255, 0.12);
}

.sync-badge {
    font-size: 0.75rem;
    color: var(--gray-400);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.sync-dot {
    width: 6px;
    height: 6px;
    background: var(--success-500);
    border-radius: var(--radius-full);
    display: inline-block;
}

/* ── Page Header ──────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
    gap: var(--space-3);
}

.rfm-filters-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

@media (max-width: 576px) {
    .rfm-filters-row {
        width: 100%;
    }
    .rfm-filters-row .rfm-dropdown {
        flex: 1 1 100% !important;
        min-width: 0 !important;
    }
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.025em;
    margin-bottom: 0;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--gray-500);
    font-weight: 400;
}

.page-period {
    font-size: 0.8rem;
    color: var(--gray-500);
    background: var(--gray-100);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-weight: 500;
}

/* ── KPI Card ─────────────────────────────────────────────────── */

.kpi-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-5) var(--space-6);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-100);
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--gray-200);
}

.kpi-card.accent-primary::before { background: var(--primary-500); }
.kpi-card.accent-success::before { background: var(--success-500); }
.kpi-card.accent-warning::before { background: var(--warning-500); }
.kpi-card.accent-danger::before  { background: var(--danger-500); }

.kpi-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--space-2);
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--gray-900);
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.kpi-valuesm { font-size: 1.35rem; }

.kpi-change {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 0.78rem;
    font-weight: 600;
    margin-top: var(--space-2);
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
}

.kpi-change.positive {
    color: var(--success-700);
    background: var(--success-50);
}

.kpi-change.negative {
    color: var(--danger-700);
    background: var(--danger-50);
}

.kpi-detail {
    font-size: 0.78rem;
    color: var(--gray-500);
    margin-top: var(--space-1);
}

/* ── Run Rate Card ────────────────────────────────────────────── */

.run-rate-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-5) var(--space-6);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-100);
}

.run-rate-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: var(--space-3);
}

.run-rate-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.run-rate-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-800);
}

.progress-track {
    width: 100%;
    height: 8px;
    background: var(--gray-100);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: var(--space-3) 0;
}

.progress-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.6s ease;
}

.progress-fill.good    { background: var(--success-500); }
.progress-fill.warning { background: var(--warning-500); }
.progress-fill.danger  { background: var(--danger-500); }

.run-rate-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* ── Stat Row (Pipeline) ──────────────────────────────────────── */

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--gray-100);
}

.stat-row:last-child { border-bottom: none; }

.stat-label {
    font-size: 0.82rem;
    color: var(--gray-600);
}

.stat-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--gray-800);
}

/* ── Bar Inline (Vendedores) ──────────────────────────────────── */

.bar-inline {
    height: 6px;
    background: var(--primary-200);
    border-radius: var(--radius-full);
    min-width: 4px;
    transition: width 0.4s ease;
}

/* ── Badges ───────────────────────────────────────────────────── */

.badge-custom {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.badge-success { background: var(--success-50); color: var(--success-700); }
.badge-warning { background: var(--warning-50); color: var(--warning-600); }
.badge-danger  { background: var(--danger-50);  color: var(--danger-700); }
.badge-info    { background: var(--primary-50); color: var(--primary-700); }
.badge-neutral { background: var(--gray-100);   color: var(--gray-600); }

/* ABC badges */
.abc-a { background: var(--success-50); color: var(--success-700); font-weight: 800; }
.abc-b { background: var(--warning-50); color: var(--warning-600); font-weight: 800; }
.abc-c { background: var(--gray-100);   color: var(--gray-600);    font-weight: 800; }

/* Priority badges */
.priority-urgente { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.priority-alto    { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
.priority-medio   { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.priority-baixo   { background: var(--gray-100); color: var(--gray-600); border: 1px solid var(--gray-200); }

/* Level badges */
.nivel-critico { background: var(--danger-50);  color: var(--danger-700); }
.nivel-baixo   { background: var(--warning-50); color: var(--warning-600); }
.nivel-ok      { background: var(--success-50); color: var(--success-700); }
.nivel-zerado  { background: var(--danger-100); color: var(--danger-700); font-weight: 800; }

/* ── Card Title ───────────────────────────────────────────────── */

.card-title-text {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ── Text Truncate in Tables ──────────────────────────────────── */

.text-truncate-cell {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-xs {
    font-size: 0.75rem;
}

/* ── Footer ───────────────────────────────────────────────────── */

.footer-biomed {
    border-top: 1px solid var(--gray-200);
    margin-top: var(--space-4);
    font-size: 0.75rem;
}

/* ── Main Container ───────────────────────────────────────────── */

.main-container {
    max-width: 1440px;
}

/* ── Date Picker Overrides ────────────────────────────────────── */

.date-picker-biomed .DateInput_input {
    font-size: 0.82rem !important;
    font-weight: 500 !important;
    padding: 4px 10px !important;
    border-radius: var(--radius-sm) !important;
    border: 1px solid var(--gray-200) !important;
    background: white !important;
    color: var(--gray-700) !important;
    width: 110px !important;
}

.date-picker-biomed .DateInput_input__focused {
    border-color: var(--primary-500) !important;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15) !important;
}

.date-picker-biomed .DateRangePickerInput {
    border: none !important;
    background: transparent !important;
}

.date-picker-biomed .DateRangePickerInput_arrow {
    color: var(--gray-400) !important;
    padding: 0 6px !important;
}

/* ── Plotly Overrides ─────────────────────────────────────────── */

.js-plotly-plot .plotly .modebar {
    display: none !important;
}

/* ── DBC Card Overrides ───────────────────────────────────────── */

.card {
    border-radius: var(--radius-lg) !important;
    border: 1px solid var(--gray-100) !important;
    box-shadow: var(--shadow) !important;
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md) !important;
}

.card-header {
    background: white !important;
    border-bottom: 1px solid var(--gray-100) !important;
    padding: var(--space-4) var(--space-5) !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
}

.card-body {
    padding: var(--space-5) !important;
}

/* ── Table Overrides ──────────────────────────────────────────── */

.table {
    font-size: 0.85rem;
    color: var(--gray-700);
}

.table thead th {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--gray-200) !important;
    padding: var(--space-3) !important;
    white-space: nowrap;
}

.table tbody td {
    padding: var(--space-3) !important;
    border-bottom: 1px solid var(--gray-100) !important;
    vertical-align: middle;
}

.table-hover tbody tr:hover {
    background-color: var(--gray-50) !important;
}

/* ── Rank Badges (Top Clientes) ───────────────────────────────── */

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--gray-500);
    background: var(--gray-100);
}

.rank-badge.gold   { background: #fef3c7; color: #92400e; }
.rank-badge.silver { background: var(--gray-200); color: var(--gray-700); }
.rank-badge.bronze { background: #fed7aa; color: #9a3412; }

/* ── Concentration Bar (Pareto) ───────────────────────────────── */

.concentration-bar {
    position: relative;
    width: 100%;
    height: 24px;
    background: var(--gray-100);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: var(--space-3) 0;
}

.concentration-fill {
    height: 100%;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: white;
    transition: width 0.6s ease;
}

.concentration-fill.safe     { background: var(--success-500); }
.concentration-fill.moderate { background: var(--warning-500); }
.concentration-fill.risky    { background: var(--danger-500); }

/* ── Coverage Bar (Previsao Cobertura) ───────────────────────── */

.coverage-bar {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 100px;
}

.coverage-track {
    width: 60px;
    height: 6px;
    background: var(--gray-100);
    border-radius: var(--radius-full);
    overflow: hidden;
    flex-shrink: 0;
}

.coverage-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.4s ease;
}

.coverage-fill.critical { background: var(--danger-500); }
.coverage-fill.low      { background: var(--warning-500); }
.coverage-fill.ok       { background: var(--success-500); }

.coverage-text {
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

/* ── ABC Summary Row ─────────────────────────────────────────── */

.abc-summary-row {
    display: flex;
    gap: var(--space-6);
    justify-content: center;
    padding: var(--space-4) 0;
}

.badge-lg-abc {
    font-size: 0.85rem;
    padding: 4px 14px;
}

/* ── Total Reposicao Footer ──────────────────────────────────── */

.total-reposicao-footer {
    display: flex;
    justify-content: flex-end;
    padding: var(--space-4) var(--space-5);
    border-top: 2px solid var(--gray-200);
}

.total-reposicao-value {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--gray-900);
    margin-top: 2px;
}

/* ── Alert Boxes ─────────────────────────────────────────────── */

.alert-box-warning {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    background: var(--warning-50);
    border: 1px solid var(--warning-100);
    color: #92400e;
}

.alert-box-danger {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    background: var(--danger-50);
    border: 1px solid var(--danger-100);
    color: #991b1b;
}

.alert-box-info {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    background: var(--primary-50);
    border: 1px solid var(--primary-100);
    color: var(--primary-800);
}

/* ── Produtos: Matrix Table ──────────────────────────────────── */

.matrix-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.matrix-table {
    font-size: 0.78rem;
    white-space: nowrap;
}

.matrix-table thead th {
    font-size: 0.65rem;
    position: sticky;
    top: 0;
    z-index: 2;
    background: white;
}

.month-col {
    min-width: 70px;
}

.month-cell {
    font-size: 0.75rem;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.summary-row {
    background: var(--gray-50) !important;
    border-top: 2px solid var(--gray-200) !important;
}

.summary-row td {
    font-weight: 700 !important;
    font-size: 0.78rem;
}

/* Search input */
.search-input-produtos {
    max-width: 350px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-4);
    font-size: 0.85rem;
}

.search-input-produtos:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-counter {
    font-size: 0.78rem;
    color: var(--gray-500);
    white-space: nowrap;
}

/* ── Produtos: Sparklines ────────────────────────────────────── */

.sparkline {
    display: flex;
    align-items: flex-end;
    gap: 1px;
    height: 24px;
    min-width: 50px;
}

.spark-bar {
    flex: 1;
    background: var(--primary-200);
    border-radius: 1px 1px 0 0;
    min-width: 3px;
    transition: background-color 0.2s;
}

.spark-bar:last-child {
    background: var(--primary-500);
}

/* ── Produtos: Trend Indicators ──────────────────────────────── */

.trend-indicator {
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.trend-up     { color: var(--success-600); }
.trend-down   { color: var(--danger-600); }
.trend-stable { color: var(--gray-500); }

/* ── Produtos: CV Badges ─────────────────────────────────────── */

.cv-stable   { background: var(--success-50); color: var(--success-700); }
.cv-moderate { background: var(--warning-50); color: var(--warning-600); }
.cv-erratic  { background: var(--danger-50);  color: var(--danger-700); }

/* ── Produtos: Forecast ──────────────────────────────────────── */

.forecast-value {
    color: var(--primary-600);
    font-weight: 600;
    font-style: italic;
}

/* ── Sticky Columns (Produtos matrix) ────────────────────────── */

.sticky-col-rank,
.sticky-col-abc,
.sticky-col-sku,
.sticky-col-nome,
.sticky-col-spark {
    position: sticky;
    background: white;
    z-index: 1;
}

.sticky-col-rank  { left: 0; min-width: 36px; }
.sticky-col-abc   { left: 36px; min-width: 40px; }
.sticky-col-sku   { left: 76px; min-width: 90px; }
.sticky-col-nome  { left: 166px; min-width: 150px; max-width: 180px; }
.sticky-col-spark { left: 316px; min-width: 55px; }

.summary-row .sticky-col-rank,
.summary-row .sticky-col-abc,
.summary-row .sticky-col-sku,
.summary-row .sticky-col-nome,
.summary-row .sticky-col-spark {
    background: var(--gray-50);
}

.product-row:hover .sticky-col-rank,
.product-row:hover .sticky-col-abc,
.product-row:hover .sticky-col-sku,
.product-row:hover .sticky-col-nome,
.product-row:hover .sticky-col-spark {
    background: var(--gray-50);
}

/* ── Animations ───────────────────────────────────────────────── */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.kpi-card, .run-rate-card {
    animation: fadeIn 0.3s ease forwards;
}

/* Stagger for KPI row */
.page-home .row > div:nth-child(1) .kpi-card { animation-delay: 0ms; }
.page-home .row > div:nth-child(2) .kpi-card { animation-delay: 40ms; }
.page-home .row > div:nth-child(3) .kpi-card { animation-delay: 80ms; }
.page-home .row > div:nth-child(4) .kpi-card { animation-delay: 120ms; }
.page-home .row > div:nth-child(5) .kpi-card { animation-delay: 160ms; }

/* ── Loading Spinner ──────────────────────────────────────────── */

._dash-loading {
    min-height: 60px;
}

.dash-spinner.dash-dot-spinner {
    margin: 2rem auto;
}

/* ── RFM / Clientes ──────────────────────────────────────────── */

.rfm-dropdown .Select-control {
    border-radius: var(--radius-md);
    border-color: var(--gray-200);
}

/* Segment badges */
.rfm-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.rfm-campeoes { background: rgba(16, 185, 129, 0.12); color: var(--success-600); }
.rfm-leais { background: rgba(99, 102, 241, 0.12); color: var(--primary-600); }
.rfm-novos { background: rgba(6, 182, 212, 0.12); color: #0891b2; }
.rfm-crescimento { background: rgba(139, 92, 246, 0.12); color: #7c3aed; }
.rfm-requer-atencao { background: rgba(245, 158, 11, 0.12); color: var(--warning-600); }
.rfm-risco { background: rgba(239, 68, 68, 0.12); color: var(--danger-600); }
.rfm-inativos { background: var(--gray-100); color: var(--gray-500); }

/* Status de atividade */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}
.status-ativo { background: rgba(16, 185, 129, 0.12); color: var(--success-600); }
.status-em-risco { background: rgba(245, 158, 11, 0.12); color: var(--warning-600); }
.status-inativo { background: rgba(239, 68, 68, 0.12); color: var(--danger-600); }

/* RFM Score pills (R-F-M mini badges) */
.rfm-score-pills {
    display: inline-flex;
    gap: 3px;
}

.rfm-score-pip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
}

.rfm-score-1 { background: var(--danger-500); }
.rfm-score-2 { background: var(--warning-500); }
.rfm-score-3 { background: var(--success-500); }

/* Action cards */
.rfm-action-item {
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rfm-action-item:last-child {
    border-bottom: none;
}

.rfm-card-campeoes { border-left: 3px solid var(--success-500); }
.rfm-card-risco { border-left: 3px solid var(--danger-500); }
.rfm-card-promissores { border-left: 3px solid #8b5cf6; }

/* ── Drill-down Interactive ──────────────────────────────────── */

.drill-clickable .js-plotly-plot {
    cursor: pointer;
}

.drill-clickable .card-header::after {
    content: "🔍";
    float: right;
    opacity: 0.4;
    font-size: 0.85rem;
}

.modal-content {
    border-radius: var(--radius-lg) !important;
    border: none !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;
}

.modal-header {
    border-bottom: 1px solid var(--gray-100) !important;
    padding: var(--space-4) var(--space-5) !important;
}

.modal-body {
    padding: var(--space-5) !important;
}

.modal-xl {
    max-width: 1200px !important;
}

/* Segment sub-page back button */
.page-clientes .btn-outline-secondary {
    border-color: var(--gray-300);
    color: var(--gray-600);
    font-weight: 500;
    transition: all 0.15s ease;
}

.page-clientes .btn-outline-secondary:hover {
    background: var(--gray-100);
    border-color: var(--gray-400);
    color: var(--gray-800);
}

/* ── Dual-value cells (valor + quantidade) ───────────────────── */

.cell-dual {
    display: flex;
    flex-direction: column;
    gap: 1px;
    line-height: 1.2;
}

.cell-valor {
    font-size: 0.75rem;
    color: var(--gray-800);
    white-space: nowrap;
}

.cell-qtd {
    font-size: 0.65rem;
    color: var(--secondary-400, #94a3b8);
    font-weight: 500;
    white-space: nowrap;
}

.summary-row .cell-valor {
    font-weight: 700;
}

.summary-row .cell-qtd {
    font-weight: 600;
    color: var(--secondary-400, #94a3b8);
}

.matrix-legend {
    flex-shrink: 0;
    opacity: 0.85;
}

/* ── Toggle Valor/Qtd/Ambos ─────────────────────────────────── */

.toggle-view-radios {
    display: flex;
    gap: 0;
    background: var(--gray-100, #f1f5f9);
    border-radius: var(--radius-md, 8px);
    padding: 3px;
}

.toggle-view-radios .form-check {
    padding: 0;
    margin: 0;
}

.toggle-view-radios .form-check-input {
    display: none;
}

.toggle-view-radios .form-check-label {
    display: block;
    padding: 5px 14px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gray-500, #64748b);
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    user-select: none;
}

.toggle-view-radios .form-check-input:checked + .form-check-label {
    background: white;
    color: var(--primary-600, #4f46e5);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-weight: 600;
}

.toggle-view-radios .form-check-label:hover {
    color: var(--gray-700, #334155);
}

/* View modes: hide/show valor or qtd lines */
.page-produtos.view-valor .cell-qtd { display: none; }
.page-produtos.view-valor .cell-dual { gap: 0; }

.page-produtos.view-qtd .cell-valor { display: none; }
.page-produtos.view-qtd .cell-dual { gap: 0; }
.page-produtos.view-qtd .cell-qtd {
    font-size: 0.75rem;
    color: var(--gray-800);
}
.page-produtos.view-qtd .summary-row .cell-qtd {
    font-weight: 700;
    color: var(--gray-800);
}

/* Ambos = default, no hiding */

/* ── Detail pages (drillthrough) ─────────────────────────────── */

.detail-header {
    margin-bottom: var(--space-4, 1rem);
}

.back-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--primary-500, #6366f1);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: var(--radius-md, 8px);
    background: var(--gray-50, #f8fafc);
    border: 1px solid var(--gray-200, #e2e8f0);
    transition: all 0.15s ease;
}

.back-button:hover {
    background: var(--primary-50, #eef2ff);
    border-color: var(--primary-200, #c7d2fe);
    color: var(--primary-700, #4338ca);
    text-decoration: none;
}

.text-truncate-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Drillthrough links in tables */
.drillthrough-link {
    color: var(--primary-600, #4f46e5);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px dashed var(--primary-300, #a5b4fc);
    transition: all 0.15s ease;
}

.drillthrough-link:hover {
    color: var(--primary-700, #4338ca);
    border-bottom-style: solid;
    text-decoration: none;
}

/* Clickable badges in Resumo por Segmento table */
a .rfm-badge {
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.15s ease;
}
a:hover .rfm-badge {
    filter: brightness(0.9);
    transform: scale(1.05);
}

/* Score bars in RFM */
.page-detalhe-cliente .progress-track {
    background: var(--gray-100, #f1f5f9);
    border-radius: 4px;
    overflow: hidden;
}

.page-detalhe-cliente .progress-fill {
    height: 100%;
    background: var(--primary-500, #6366f1);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Transacoes table scroll */
.page-detalhe-cliente .table-sm td,
.page-detalhe-cliente .table-sm th {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    vertical-align: middle;
}

/* ── Print ────────────────────────────────────────────────────── */

@media print {
    .navbar-biomed { display: none; }
    .main-container { padding: 0; max-width: 100%; }
    .card, .kpi-card { box-shadow: none !important; border: 1px solid #ddd !important; page-break-inside: avoid; }
}

/* ══════════════════════════════════════════════════════════════
   Chat Widget Flutuante — Global
   ══════════════════════════════════════════════════════════════ */

/* ── FAB (Floating Action Button) ────────────────────────────── */

.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-500), #8b5cf6);
    color: white;
    border: none;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10001;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.chat-fab:active {
    transform: scale(0.96);
}

.chat-fab-hidden {
    transform: scale(0) !important;
    opacity: 0;
    pointer-events: none;
}

/* ── Painel flutuante ────────────────────────────────────────── */

.chat-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 420px;
    height: 560px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10001;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-panel-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Panel header ────────────────────────────────────────────── */

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--gray-900);
    color: white;
    flex-shrink: 0;
}

.chat-panel-title {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.chat-status-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 2px;
}

.chat-status-online {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

.chat-status-cloud {
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
}

.chat-status-offline {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.chat-minimize-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-minimize-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ── Sugestoes ───────────────────────────────────────────────── */

.chat-sugestoes-area {
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-100);
    flex-shrink: 0;
}

.chat-sugestao-dropdown {
    font-size: 0.78rem !important;
}

/* ── Messages area ───────────────────────────────────────────── */

.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-msg {
    display: flex;
    max-width: 100%;
}

.chat-msg-user {
    justify-content: flex-end;
}

.chat-msg-assistant {
    justify-content: flex-start;
}

/* ── Bubbles ─────────────────────────────────────────────────── */

.chat-bubble {
    padding: 8px 14px;
    font-size: 0.82rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-bubble-user {
    background: var(--primary-500);
    color: #fff;
    border-radius: 14px 14px 4px 14px;
    max-width: 80%;
}

.chat-bubble-assistant {
    background: var(--gray-50);
    color: var(--gray-800);
    border: 1px solid var(--gray-200);
    border-radius: 14px 14px 14px 4px;
    max-width: 90%;
}

/* ── Markdown inside bubbles ─────────────────────────────────── */

.chat-md p {
    margin-bottom: 0.35rem;
}

.chat-md p:last-child {
    margin-bottom: 0;
}

.chat-md ul, .chat-md ol {
    margin-bottom: 0.35rem;
    padding-left: 1.1rem;
    font-size: 0.8rem;
}

.chat-md code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.75rem;
}

.chat-bubble-user .chat-md code {
    background: rgba(255, 255, 255, 0.2);
}

.chat-md pre {
    background: var(--gray-800);
    color: #e2e8f0;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.72rem;
    margin: 0.4rem 0;
}

.chat-md strong {
    font-weight: 600;
}

.chat-bubble-user .chat-md strong {
    color: #fff;
}

.chat-md table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.4rem 0;
    font-size: 0.72rem;
}

.chat-md th, .chat-md td {
    padding: 3px 6px;
    border: 1px solid var(--gray-200);
    text-align: left;
}

.chat-md th {
    background: var(--gray-100);
    font-weight: 600;
}

/* ── Input area ──────────────────────────────────────────────── */

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    flex-shrink: 0;
}

.chat-input-field {
    flex: 1;
    border-radius: 20px !important;
    border: 1px solid var(--gray-300) !important;
    padding: 7px 14px !important;
    font-size: 0.82rem !important;
}

.chat-input-field:focus {
    border-color: var(--primary-500) !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
}

.chat-send-btn {
    border-radius: 50% !important;
    width: 36px;
    height: 36px;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--primary-500) !important;
    border-color: var(--primary-500) !important;
    font-size: 0.85rem;
}

.chat-send-btn:hover {
    background: var(--primary-600) !important;
    border-color: var(--primary-600) !important;
}

/* ── Thinking dots ───────────────────────────────────────────── */

.thinking-dots {
    display: flex;
    gap: 4px;
    padding: 4px 2px;
    align-items: center;
    height: 24px;
}

.thinking-dots .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--gray-400);
    animation: thinking-bounce 1.4s infinite ease-in-out both;
}

.thinking-dots .dot:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots .dot:nth-child(2) { animation-delay: -0.16s; }
.thinking-dots .dot:nth-child(3) { animation-delay: 0s; }

@keyframes thinking-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ── Graficos area ───────────────────────────────────────────── */

.chat-graficos-area {
    padding: 0 12px;
    max-height: 350px;
    overflow-y: auto;
}

.chart-card-ai {
    border-radius: 10px;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.chart-card-ai .card-body {
    padding: 0.4rem;
}

/* ── Responsive: mobile fullscreen ───────────────────────────── */

@media (max-width: 576px) {
    .chat-panel {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }

    .chat-fab {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
}

/* ══ Login Page ══════════════════════════════════════════════ */

.login-bg {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, var(--primary-900) 0%, var(--primary-700) 50%, var(--primary-500) 100%);
    z-index: -1;
}

.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    border: none;
    border-radius: 12px;
}

.login-card .card-body {
    padding: 2.5rem;
}

.brand-dot-login {
    width: 14px;
    height: 14px;
    display: inline-block;
    background: var(--primary-500);
    border-radius: 50%;
    margin-right: 4px;
}

.login-brand-text {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-800);
}

.login-btn {
    background: var(--primary-600) !important;
    border: none !important;
    padding: 0.6rem;
    font-weight: 600;
    border-radius: 8px;
    transition: background 0.2s;
}

.login-btn:hover {
    background: var(--primary-700) !important;
}

/* Footer/chat hidden via serve_layout() when not authenticated */
