/* Premium Business Intelligence Stylesheet — Stripe/Vercel/Linear Inspired */

/* ============================================================================
   KPI AND METRICS GRID
   ============================================================================ */
.intel-kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

@media (max-width: 1280px) {
    .intel-kpi-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .intel-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 540px) {
    .intel-kpi-grid {
        grid-template-columns: 1fr;
    }
}

.intel-kpi-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 120px;
    box-shadow: var(--shadow-xs);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s ease;
    position: relative;
    overflow: hidden;
    cursor: default;
}

.intel-kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: transparent;
    transition: background 0.2s ease;
}

.intel-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-default);
}

.intel-kpi-card.accent-indigo::before { background: linear-gradient(90deg, #6366f1, #8b5cf6); }
.intel-kpi-card.accent-green::before  { background: linear-gradient(90deg, #10b981, #059669); }
.intel-kpi-card.accent-purple::before { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }
.intel-kpi-card.accent-blue::before   { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
.intel-kpi-card.accent-red::before    { background: linear-gradient(90deg, #ef4444, #f97316); }

.intel-kpi-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
}

.intel-kpi-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    line-height: 1.4;
}

.intel-kpi-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Accent icon color variants */
.intel-kpi-icon.indigo { background-color: var(--brand-50); color: var(--brand-600); }
.intel-kpi-icon.green  { background-color: var(--color-success-bg); color: var(--color-success); }
.intel-kpi-icon.amber  { background-color: var(--color-warning-bg); color: var(--color-warning); }
.intel-kpi-icon.red    { background-color: var(--color-danger-bg); color: var(--color-danger); }
.intel-kpi-icon.purple { background-color: var(--color-purple-bg); color: var(--color-purple); }
.intel-kpi-icon.blue   { background-color: var(--color-info-bg); color: var(--color-info); }
.intel-kpi-icon.gray   { background-color: var(--bg-sunken); color: var(--text-secondary); }

:root.dark-mode .intel-kpi-icon.indigo { background-color: rgba(99,102,241,0.15); color: #a5b4fc; }
:root.dark-mode .intel-kpi-icon.green  { background-color: rgba(16,185,129,0.15); color: #6ee7b7; }
:root.dark-mode .intel-kpi-icon.amber  { background-color: rgba(245,158,11,0.15); color: #fcd34d; }
:root.dark-mode .intel-kpi-icon.red    { background-color: rgba(239,68,68,0.15);  color: #fca5a5; }
:root.dark-mode .intel-kpi-icon.purple { background-color: rgba(139,92,246,0.15); color: #c4b5fd; }
:root.dark-mode .intel-kpi-icon.blue   { background-color: rgba(59,130,246,0.15); color: #93c5fd; }
:root.dark-mode .intel-kpi-icon.gray   { background-color: rgba(148,163,184,0.12); color: var(--text-secondary); }

.intel-kpi-value {
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
    letter-spacing: -0.035em;
    margin-top: var(--space-2);
    font-variant-numeric: tabular-nums;
}

.intel-kpi-footer {
    font-size: 0.74rem;
    color: var(--text-tertiary);
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 4px;
}

.intel-kpi-delta {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: var(--radius-full);
}

.intel-kpi-delta.up   { background: var(--color-success-bg); color: var(--color-success-text); }
.intel-kpi-delta.down { background: var(--color-danger-bg);  color: var(--color-danger-text);  }
.intel-kpi-delta.flat { background: var(--bg-sunken);        color: var(--text-secondary);     }

/* ============================================================================
   KPI SKELETON LOADING STATE
   ============================================================================ */
.bi-kpi-skeleton .intel-kpi-value {
    font-size: 0;
}

.bi-kpi-skeleton .intel-kpi-value::after {
    content: '';
    display: block;
    height: 28px;
    width: 70%;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border-subtle) 50%, var(--bg-sunken) 75%);
    background-size: 200% 100%;
    animation: bi-shimmer 1.5s infinite linear;
    margin-top: 6px;
}

.bi-kpi-skeleton .intel-kpi-footer span::before {
    content: '';
    display: block;
    height: 12px;
    width: 90%;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border-subtle) 50%, var(--bg-sunken) 75%);
    background-size: 200% 100%;
    animation: bi-shimmer 1.5s infinite linear;
}

.bi-kpi-skeleton .intel-kpi-footer span {
    font-size: 0;
    display: block;
    width: 100%;
}

.bi-sync-panel {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    margin-right: 8px;
}

.bi-sync-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.bi-sync-timestamp {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bi-sync-badge {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    text-transform: capitalize;
}

.bi-sync-badge.success { background: var(--color-success-bg); color: var(--color-success-text); }
.bi-sync-badge.running { background: var(--color-info-bg); color: var(--color-info-text); }
.bi-sync-badge.failed  { background: var(--color-danger-bg); color: var(--color-danger-text); }
.bi-sync-badge.never   { background: var(--bg-sunken); color: var(--text-secondary); }

#bi-stripe-sync-btn.syncing {
    opacity: 0.7;
    pointer-events: none;
}

@keyframes bi-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================================================
   TABLE SKELETON
   ============================================================================ */
.intel-skeleton-row td {
    padding: var(--space-4) var(--space-4);
}

.intel-skeleton-block {
    height: 14px;
    background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border-subtle) 50%, var(--bg-sunken) 75%);
    background-size: 200% 100%;
    animation: bi-shimmer 1.5s infinite linear;
    border-radius: var(--radius-sm);
    width: 75%;
}

.intel-skeleton-block.w-50 { width: 50%; }
.intel-skeleton-block.w-30 { width: 30%; }
.intel-skeleton-block.w-90 { width: 90%; }

/* ============================================================================
   CHART CONTAINERS
   ============================================================================ */
.churn-chart-container {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    margin-bottom: var(--space-6);
    box-shadow: var(--shadow-xs);
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 300px;
}

.churn-chart-container h4 {
    margin: 0 0 var(--space-3) 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    flex-shrink: 0;
}

.churn-chart-wrap {
    flex: 1;
    min-height: 0;
    position: relative;
}

/* Chart Error / Empty States */
.bi-chart-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    z-index: 10;
}

.bi-chart-placeholder-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-sunken);
    color: var(--text-tertiary);
}

.bi-chart-placeholder-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
}

.bi-chart-placeholder-desc {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    text-align: center;
    max-width: 220px;
    line-height: 1.5;
}

.bi-chart-placeholder.error .bi-chart-placeholder-icon {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

/* Chart loading shimmer overlay */
.bi-chart-loading {
    position: absolute;
    inset: 0;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    overflow: hidden;
}

.bi-chart-loading-bar {
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border-subtle) 50%, var(--bg-sunken) 75%);
    background-size: 200% 100%;
    animation: bi-shimmer 1.5s infinite linear;
}

/* ============================================================================
   FILTER BAR
   ============================================================================ */
.bi-filter-bar {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-5);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

.bi-filter-section {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.bi-filter-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.bi-filter-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

.bi-refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    height: 34px;
    padding: 0 var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.bi-refresh-btn:hover {
    background: var(--bg-sunken);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.bi-refresh-btn svg {
    transition: transform 0.6s ease;
}

.bi-refresh-btn.spinning svg {
    animation: spin-once 0.6s linear;
}

@keyframes spin-once {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.bi-filter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    color: white;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}

/* ============================================================================
   TOOLBAR, FILTERS, AND SEARCH
   ============================================================================ */
.intel-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    width: 100%;
}

.intel-search-wrapper {
    position: relative;
    flex: 1;
    min-width: 260px;
    max-width: 380px;
}

.intel-search-icon {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

.intel-search-input {
    width: 100%;
    height: 36px;
    padding-left: calc(var(--space-3) + 18px + var(--space-2));
    padding-right: var(--space-3);
    background-color: var(--bg-page);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.intel-search-input:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-brand);
    background-color: var(--bg-surface);
}

.intel-filter-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.intel-select-wrapper {
    position: relative;
    min-width: 140px;
}

.intel-select {
    width: 100%;
    height: 36px;
    padding: 0 var(--space-8) 0 var(--space-3);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    appearance: none;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    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='%2370708a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
}

.intel-select:hover  { border-color: var(--border-strong); }
.intel-select:focus  { border-color: var(--color-primary); box-shadow: var(--shadow-brand); }

.intel-reset-btn {
    height: 36px;
    padding: 0 var(--space-3);
    background-color: transparent;
    border: 1px solid transparent;
    color: var(--text-tertiary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    transition: all 0.15s ease;
    white-space: nowrap;
}

.intel-reset-btn:hover {
    background-color: var(--bg-sunken);
    color: var(--text-primary);
    border-color: var(--border-default);
}

/* Export Button */
.bi-export-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    height: 32px;
    padding: 0 var(--space-3);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-page);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
}

.bi-export-btn:hover {
    background: var(--bg-sunken);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

/* ============================================================================
   NAVIGATION TABS
   ============================================================================ */
.expiry-tab-controls {
    display: flex;
    background-color: var(--bg-sunken);
    padding: 4px;
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-6);
    border: 1px solid var(--border-subtle);
    align-self: flex-start;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
}

.expiry-tab-controls::-webkit-scrollbar { display: none; }

.expiry-tab-btn {
    padding: var(--space-2) var(--space-4);
    background: none;
    border: none;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.15s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    position: relative;
    flex-shrink: 0;
}

.expiry-tab-btn:hover { color: var(--text-primary); background: var(--bg-surface); }

.expiry-tab-btn.active {
    background-color: var(--bg-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.bi-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 700;
    background: var(--bg-sunken);
    color: var(--text-secondary);
    line-height: 1;
    transition: background 0.15s ease, color 0.15s ease;
}

.expiry-tab-btn.active .bi-tab-badge {
    background: var(--color-primary-bg, rgba(99,102,241,0.12));
    color: var(--color-primary);
}

/* ============================================================================
   TABLE STYLES
   ============================================================================ */
.sticky-header-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

.sticky-header-table th {
    position: sticky;
    top: 0;
    background-color: var(--bg-sunken);
    z-index: 10;
    border-bottom: 1px solid var(--border-default);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sticky-header-table td {
    border-top: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.sticky-header-table tr:hover td {
    background: var(--bg-page);
}

.table-wrapper {
    box-shadow: none;
    border: none;
    border-radius: 0;
    overflow: hidden;
}

/* Sort icons */
.bi-sort-icon {
    display: inline-block;
    font-style: normal;
    opacity: 0.4;
    font-size: 0.7rem;
    margin-left: 3px;
    transition: opacity 0.15s ease;
}

th:hover .bi-sort-icon { opacity: 0.9; }
.bi-sort-icon.active   { opacity: 1; color: var(--color-primary); }

/* ============================================================================
   HEALTH SCORES AND SEGMENT PILLS
   ============================================================================ */
.health-pill {
    padding: 3px 9px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: inline-block;
    white-space: nowrap;
}

.health-excellent { background: var(--color-success-bg); color: var(--color-success-text); border: 1px solid var(--color-success-light); }
.health-healthy   { background: var(--color-info-bg);    color: var(--color-info-text);    border: 1px solid var(--color-info-light);    }
.health-risk      { background: var(--color-warning-bg); color: var(--color-warning-text); border: 1px solid var(--color-warning-light); }
.health-churn     { background: var(--color-danger-bg);  color: var(--color-danger-text);  border: 1px solid var(--color-danger-light);  }

/* ============================================================================
   PLAN PROFITABILITY MATRIX
   ============================================================================ */
.profitability-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-5);
    margin-bottom: var(--space-6);
}

.profitability-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xs);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, border-color 0.2s ease;
    gap: var(--space-3);
}

.profitability-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-default);
}

.profit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
}

.profit-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

.profit-revenue {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.profit-margin-bar-wrap {
    width: 100%;
    height: 6px;
    background: var(--bg-sunken);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-subtle);
}

.profit-margin-bar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.profit-kpi-subgrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
    margin-top: auto;
}

.profit-sub-kpi {
    background: var(--bg-page);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--border-subtle);
}

.profit-sub-kpi-label {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 3px;
    letter-spacing: 0.06em;
}

.profit-sub-kpi-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.profit-high   { color: var(--color-success); }
.profit-medium { color: var(--color-warning); }
.profit-low    { color: var(--color-danger);  }

/* ============================================================================
   EMPTY STATES
   ============================================================================ */
.intel-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12) var(--space-6);
    text-align: center;
}

.intel-empty-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-full);
    background: var(--bg-sunken);
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-4);
    font-size: 1.5rem;
}

.intel-empty-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
}

.intel-empty-desc {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    max-width: 300px;
    line-height: 1.6;
}

/* ============================================================================
   RESPONSIVE TWO-COLUMN LAYOUTS
   ============================================================================ */
.intel-two-col-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-5);
}

@media (max-width: 1024px) {
    .intel-two-col-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .profile-intelligence-drawer {
        grid-template-columns: 1fr !important;
        gap: var(--space-4);
    }

    .churn-chart-container {
        min-height: 280px;
    }
}

@media (max-width: 767px) {
    .intel-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .intel-search-wrapper {
        max-width: none;
        min-width: 0;
    }

    .intel-filter-group {
        width: 100%;
        flex-wrap: wrap;
    }

    .intel-select-wrapper {
        flex: 1;
        min-width: 0;
    }

    .intel-reset-btn {
        width: 100%;
        justify-content: center;
    }

    .bi-filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .bi-filter-actions {
        margin-left: 0;
        justify-content: flex-end;
    }

    .expiry-tab-controls {
        width: 100%;
    }

    .profitability-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================================
   CUSTOMER SUCCESS LEADERBOARD
   ============================================================================ */
.cs-leaderboard-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    box-shadow: var(--shadow-xs);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.cs-leaderboard-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-default);
}

.cs-card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
}

.cs-rank-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.cs-rank-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-lg);
    background: var(--bg-page);
    border: 1px solid transparent;
    transition: all 0.15s ease;
    cursor: default;
}

.cs-rank-item:hover {
    background: var(--bg-sunken);
    border-color: var(--border-subtle);
    transform: translateX(3px);
}

.cs-user-meta {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.cs-rank-number {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-full);
    background: var(--bg-sunken);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cs-rank-item:nth-child(1) .cs-rank-number { background: #fef08a; color: #854d0e; }
.cs-rank-item:nth-child(2) .cs-rank-number { background: #e2e8f0; color: #475569; }
.cs-rank-item:nth-child(3) .cs-rank-number { background: #ffedd5; color: #c2410c; }

:root.dark-mode .cs-rank-item:nth-child(1) .cs-rank-number { background: rgba(254,240,138,0.15); color: #fef08a; }
:root.dark-mode .cs-rank-item:nth-child(2) .cs-rank-number { background: rgba(226,232,240,0.15); color: #cbd5e1; }
:root.dark-mode .cs-rank-item:nth-child(3) .cs-rank-number { background: rgba(255,237,213,0.15); color: #ffedd5; }

.cs-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.cs-user-email {
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.cs-stat-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ============================================================================
   TABLE CARD HEADER WITH ACTIONS
   ============================================================================ */
.bi-table-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.bi-table-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.bi-table-card-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 3px 0 0 0;
}

/* Usage progress bars */
.usage-bar-wrap {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.usage-bar-track {
    flex: 1;
    height: 6px;
    background: var(--bg-sunken);
    border-radius: var(--radius-full);
    overflow: hidden;
    max-width: 80px;
    border: 1px solid var(--border-subtle);
}

.usage-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.usage-bar-fill.safe    { background: var(--color-primary); }
.usage-bar-fill.warning { background: var(--color-warning); }
.usage-bar-fill.danger  { background: var(--color-danger);  }

/* Action dropdown menu */
.bi-action-dropdown-wrap {
    position: relative;
    display: inline-block;
}

.bi-action-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    min-width: 175px;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    z-index: 200;
    display: none;
    animation: bi-menu-in 0.12s ease;
}

.bi-action-menu.open { display: block; }

@keyframes bi-menu-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0);    }
}

.bi-action-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 7px var(--space-3);
    font-size: 0.82rem;
    color: var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.1s ease;
    white-space: nowrap;
}

.bi-action-menu-item:hover { background: var(--bg-sunken); }
.bi-action-menu-item.danger { color: var(--color-danger); }
.bi-action-menu-item.danger:hover { background: var(--color-danger-bg); }

/* ============================================================================
   HEALTH METER (Profile Modal)
   ============================================================================ */
.health-meter-circle {
    position: relative;
    width: 96px;
    height: 96px;
    flex-shrink: 0;
}

.health-meter-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    font-weight: 700;
    font-size: 1.3rem;
    line-height: 1;
    color: var(--text-primary);
}

.health-meter-text small {
    font-size: 8px;
    font-weight: 500;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-top: 2px;
    letter-spacing: 0.06em;
}

/* ============================================================================
   TIMELINE
   ============================================================================ */
.intel-timeline-item {
    display: flex;
    gap: var(--space-3);
    font-size: 0.8rem;
    padding-left: var(--space-3);
    border-left: 2px solid var(--border-subtle);
    margin-left: 6px;
    position: relative;
    padding-bottom: var(--space-2);
}

.intel-timeline-item::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--border-default);
    border: 2px solid var(--bg-surface);
}

.intel-timeline-time {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    white-space: nowrap;
    min-width: 110px;
}

.intel-timeline-msg {
    color: var(--text-primary);
    line-height: 1.4;
}

.intel-timeline-detail {
    color: var(--text-secondary);
    font-size: 0.72rem;
}

/* Increase spacing between remaining columns in User Intelligence tables */
#users-intelligence-table th,
#users-intelligence-table td,
#bi-panel-users table.table th,
#bi-panel-users table.table td {
    padding-left: var(--space-6) !important;
    padding-right: var(--space-6) !important;
}

/* ── BI Action Preview / Email Modal ─────────────────────────────────────── */
.bi-action-modal-content {
    max-width: 920px;
    width: 96%;
    max-height: min(92vh, 860px);
}

.bi-action-modal-subtitle {
    margin: 4px 0 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.bi-action-modal-body {
    padding: var(--space-5) var(--space-6);
}

.bi-action-modal-grid {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: var(--space-5);
    align-items: start;
}

.bi-action-context-panel {
    background: var(--bg-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bi-action-context-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.bi-action-context-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-3);
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.8rem;
}

.bi-action-context-row span {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.bi-action-context-row strong {
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
    word-break: break-word;
}

.bi-action-context-row--stack {
    flex-direction: column;
    align-items: stretch;
    border-bottom: none;
    gap: 6px;
}

.bi-action-context-row--stack strong {
    text-align: left;
    font-weight: 500;
    line-height: 1.45;
}

.bi-action-compose-panel .form-label {
    margin-bottom: 6px;
}

.bi-email-char-count {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
}

.bi-email-char-count.is-over {
    color: var(--color-danger);
    font-weight: 600;
}

.bi-email-preview-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin: var(--space-2) 0 8px;
}

.bi-email-preview-host {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    background: var(--bg-sunken);
    max-height: 220px;
    overflow: auto;
}

.bi-email-preview-frame {
    padding: var(--space-3);
}

.bi-email-preview-subject {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.bi-email-preview-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    color: #111827;
}

:root.dark-mode .bi-email-preview-card {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

.bi-email-preview-brand {
    background: #111827;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 10px 14px;
    letter-spacing: -0.02em;
}

.bi-email-preview-body {
    padding: 14px;
    font-size: 0.82rem;
    line-height: 1.55;
}

.bi-email-preview-body p {
    margin: 0 0 10px;
}

.bi-email-preview-meta {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 10px 14px 14px;
    border-top: 1px solid #e5e7eb;
    font-size: 0.72rem;
}

:root.dark-mode .bi-email-preview-meta {
    border-top-color: #334155;
}

.bi-email-preview-meta span {
    display: block;
    color: #6b7280;
    margin-bottom: 2px;
}

.bi-email-preview-meta strong {
    color: inherit;
    font-weight: 600;
    display: block;
    line-height: 1.35;
}

#bi-email-send-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .bi-action-modal-grid {
        grid-template-columns: 1fr;
    }

    .bi-email-preview-meta {
        grid-template-columns: 1fr;
    }
}
