/* ==========================================================================
   XCRM Design System
   Modern, RTL-first, component-based CSS architecture
   ========================================================================== */

/* ==========================================================================
   1. Design Tokens
   ========================================================================== */

:root {
    /* Colors - Primary */
    --xcrm-primary: #7C3AED;
    --xcrm-primary-light: #A78BFA;
    --xcrm-primary-dark: #5B21B6;
    --xcrm-primary-bg: #F5F3FF;

    /* Colors - Semantic */
    --xcrm-success: #16A34A;
    --xcrm-success-light: #BBF7D0;
    --xcrm-success-bg: #F0FDF4;
    --xcrm-warning: #D97706;
    --xcrm-warning-light: #FDE68A;
    --xcrm-warning-bg: #FFFBEB;
    --xcrm-danger: #DC2626;
    --xcrm-danger-light: #FECACA;
    --xcrm-danger-bg: #FEF2F2;
    --xcrm-info: #2563EB;
    --xcrm-info-light: #BFDBFE;
    --xcrm-info-bg: #EFF6FF;

    /* Colors - Neutral */
    --xcrm-text: #18181B;
    --xcrm-text-secondary: #52525B;
    --xcrm-text-muted: #71717A;
    --xcrm-text-placeholder: #A1A1AA;
    --xcrm-border: #E4E4E7;
    --xcrm-border-light: #F4F4F5;
    --xcrm-bg: #FAFAFA;
    --xcrm-surface: #FFFFFF;
    --xcrm-overlay: rgba(0, 0, 0, 0.5);

    /* Typography */
    --xcrm-font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --xcrm-font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --xcrm-text-xs: 0.75rem;     /* 12px */
    --xcrm-text-sm: 0.8125rem;   /* 13px */
    --xcrm-text-base: 0.875rem;  /* 14px */
    --xcrm-text-md: 0.9375rem;   /* 15px */
    --xcrm-text-lg: 1.0625rem;   /* 17px */
    --xcrm-text-xl: 1.25rem;     /* 20px */
    --xcrm-text-2xl: 1.5rem;     /* 24px */
    --xcrm-text-3xl: 1.875rem;   /* 30px */
    --xcrm-text-4xl: 2.25rem;    /* 36px */

    --xcrm-leading-tight: 1.25;
    --xcrm-leading-normal: 1.5;
    --xcrm-leading-relaxed: 1.75;

    --xcrm-weight-normal: 400;
    --xcrm-weight-medium: 500;
    --xcrm-weight-semibold: 600;
    --xcrm-weight-bold: 700;

    /* Spacing */
    --xcrm-space-0: 0;
    --xcrm-space-1: 4px;
    --xcrm-space-2: 8px;
    --xcrm-space-3: 12px;
    --xcrm-space-4: 16px;
    --xcrm-space-5: 20px;
    --xcrm-space-6: 24px;
    --xcrm-space-7: 32px;
    --xcrm-space-8: 40px;
    --xcrm-space-9: 48px;
    --xcrm-space-10: 64px;

    /* Border Radius */
    --xcrm-radius-xs: 4px;
    --xcrm-radius-sm: 6px;
    --xcrm-radius-md: 8px;
    --xcrm-radius-lg: 12px;
    --xcrm-radius-xl: 16px;
    --xcrm-radius-2xl: 20px;
    --xcrm-radius-full: 9999px;

    /* Shadows */
    --xcrm-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --xcrm-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --xcrm-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
    --xcrm-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

    /* Transitions */
    --xcrm-transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --xcrm-transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --xcrm-transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Z-Index */
    --xcrm-z-dropdown: 100;
    --xcrm-z-sticky: 200;
    --xcrm-z-modal: 1000;
    --xcrm-z-tooltip: 1100;
}

/* ==========================================================================
   2. Base Reset & Typography
   ========================================================================== */

.xcrm-page {
    font-family: var(--xcrm-font-family);
    font-size: var(--xcrm-text-base);
    line-height: var(--xcrm-leading-normal);
    color: var(--xcrm-text);
    direction: rtl;
    text-align: right;
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--xcrm-space-7);
}

.xcrm-page *,
.xcrm-page *::before,
.xcrm-page *::after {
    box-sizing: border-box;
}

/* ==========================================================================
   3. Page Header
   ========================================================================== */

.xcrm-page-header {
    margin-bottom: var(--xcrm-space-7);
}

.xcrm-page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--xcrm-space-4);
}

.xcrm-page-title {
    font-size: var(--xcrm-text-2xl);
    font-weight: var(--xcrm-weight-bold);
    color: var(--xcrm-text);
    margin: 0 0 var(--xcrm-space-1) 0;
    line-height: var(--xcrm-leading-tight);
}

.xcrm-page-subtitle {
    font-size: var(--xcrm-text-md);
    color: var(--xcrm-text-muted);
    margin: 0;
    line-height: var(--xcrm-leading-normal);
}

.xcrm-page-actions {
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-2);
    flex-shrink: 0;
}

/* ==========================================================================
   4. KPI Grid
   ========================================================================== */

.xcrm-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--xcrm-space-5);
    margin-bottom: var(--xcrm-space-7);
}

.xcrm-kpi {
    background: var(--xcrm-surface);
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-lg);
    padding: var(--xcrm-space-6);
    transition: border-color var(--xcrm-transition-fast), box-shadow var(--xcrm-transition-fast);
}

.xcrm-kpi:hover {
    border-color: var(--xcrm-border);
    box-shadow: var(--xcrm-shadow-sm);
}

.xcrm-kpi-label {
    font-size: var(--xcrm-text-sm);
    font-weight: var(--xcrm-weight-medium);
    color: var(--xcrm-text-muted);
    margin-bottom: var(--xcrm-space-2);
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-1);
}

.xcrm-kpi-value {
    font-size: var(--xcrm-text-3xl);
    font-weight: var(--xcrm-weight-bold);
    color: var(--xcrm-text);
    line-height: var(--xcrm-leading-tight);
    margin-bottom: var(--xcrm-space-2);
    letter-spacing: -0.025em;
}

.xcrm-kpi-unit {
    font-size: var(--xcrm-text-lg);
    font-weight: var(--xcrm-weight-medium);
    color: var(--xcrm-text-secondary);
    margin-inline-start: var(--xcrm-space-1);
}

.xcrm-kpi-trend {
    display: inline-flex;
    align-items: center;
    gap: var(--xcrm-space-1);
    font-size: var(--xcrm-text-xs);
    font-weight: var(--xcrm-weight-semibold);
    padding: 2px 8px;
    border-radius: var(--xcrm-radius-full);
}

.xcrm-kpi-trend--up {
    color: var(--xcrm-success);
    background: var(--xcrm-success-bg);
}

.xcrm-kpi-trend--down {
    color: var(--xcrm-danger);
    background: var(--xcrm-danger-bg);
}

.xcrm-kpi-trend--neutral {
    color: var(--xcrm-text-muted);
    background: var(--xcrm-border-light);
}

.xcrm-kpi-context {
    font-size: var(--xcrm-text-xs);
    color: var(--xcrm-text-placeholder);
    margin-top: var(--xcrm-space-1);
}

/* ==========================================================================
   5. Insight Component
   ========================================================================== */

.xcrm-insight {
    background: var(--xcrm-surface);
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-lg);
    padding: var(--xcrm-space-6);
    margin-bottom: var(--xcrm-space-6);
    position: relative;
    overflow: hidden;
}

.xcrm-insight::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 4px;
    background: var(--xcrm-primary);
    border-radius: 0 var(--xcrm-radius-lg) var(--xcrm-radius-lg) 0;
}

.xcrm-insight--success::before { background: var(--xcrm-success); }
.xcrm-insight--warning::before { background: var(--xcrm-warning); }
.xcrm-insight--danger::before { background: var(--xcrm-danger); }
.xcrm-insight--info::before { background: var(--xcrm-info); }

.xcrm-insight-header {
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-2);
    margin-bottom: var(--xcrm-space-3);
}

.xcrm-insight-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--xcrm-primary);
    flex-shrink: 0;
}

.xcrm-insight--success .xcrm-insight-icon { color: var(--xcrm-success); }
.xcrm-insight--warning .xcrm-insight-icon { color: var(--xcrm-warning); }
.xcrm-insight--danger .xcrm-insight-icon { color: var(--xcrm-danger); }
.xcrm-insight--info .xcrm-insight-icon { color: var(--xcrm-info); }

.xcrm-insight-title {
    font-size: var(--xcrm-text-sm);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.xcrm-insight-body {
    font-size: var(--xcrm-text-md);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text);
    line-height: var(--xcrm-leading-relaxed);
    direction: rtl;
    text-align: right;
    /* unicode-bidi: plaintext; */
}

.xcrm-insight-footer {
    margin-top: var(--xcrm-space-3);
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-3);
}

.xcrm-insight-action {
    font-size: var(--xcrm-text-sm);
    font-weight: var(--xcrm-weight-medium);
    color: var(--xcrm-primary);
    text-decoration: none;
    cursor: pointer;
    transition: color var(--xcrm-transition-fast);
}

.xcrm-insight-action:hover {
    color: var(--xcrm-primary-dark);
}

/* ==========================================================================
   6. Data Section
   ========================================================================== */

.xcrm-data-section {
    background: var(--xcrm-surface);
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-lg);
    margin-bottom: var(--xcrm-space-6);
    overflow: hidden;
}

.xcrm-data-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--xcrm-space-5) var(--xcrm-space-6);
    border-bottom: 1px solid var(--xcrm-border-light);
}

.xcrm-data-section-title {
    font-size: var(--xcrm-text-lg);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text);
    margin: 0;
}

.xcrm-data-section-description {
    font-size: var(--xcrm-text-sm);
    color: var(--xcrm-text-muted);
    margin: var(--xcrm-space-1) 0 0 0;
}

.xcrm-data-section-body {
    padding: var(--xcrm-space-6);
}

/* ==========================================================================
   7. Modern Table
   ========================================================================== */

.xcrm-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.xcrm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--xcrm-text-base);
}

.xcrm-table thead th {
    font-size: var(--xcrm-text-xs);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--xcrm-space-3) var(--xcrm-space-4);
    text-align: right;
    border-bottom: 1px solid var(--xcrm-border);
    white-space: nowrap;
    background: var(--xcrm-bg);
}

.xcrm-table tbody td {
    padding: var(--xcrm-space-4);
    text-align: right;
    border-bottom: 1px solid var(--xcrm-border-light);
    vertical-align: middle;
    color: var(--xcrm-text-secondary);
}

.xcrm-table tbody tr {
    transition: background var(--xcrm-transition-fast);
}

.xcrm-table tbody tr:hover {
    background: var(--xcrm-bg);
}

.xcrm-table tbody tr:last-child td {
    border-bottom: none;
}

/* Table Cell Variants */
.xcrm-table-cell-primary {
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text);
}

.xcrm-table-cell-number {
    font-family: var(--xcrm-font-mono);
    font-size: var(--xcrm-text-sm);
    direction: ltr;
    text-align: left;
    letter-spacing: -0.01em;
}

.xcrm-table-cell-highlight {
    font-weight: var(--xcrm-weight-bold);
    color: var(--xcrm-primary);
}

.xcrm-table-cell-muted {
    font-size: var(--xcrm-text-sm);
    color: var(--xcrm-text-muted);
}

/* ==========================================================================
   8. Badge
   ========================================================================== */

.xcrm-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--xcrm-space-1);
    font-size: var(--xcrm-text-xs);
    font-weight: var(--xcrm-weight-semibold);
    padding: 2px 10px;
    border-radius: var(--xcrm-radius-full);
    white-space: nowrap;
}

.xcrm-badge--success {
    color: var(--xcrm-success);
    background: var(--xcrm-success-bg);
}

.xcrm-badge--warning {
    color: var(--xcrm-warning);
    background: var(--xcrm-warning-bg);
}

.xcrm-badge--danger {
    color: var(--xcrm-danger);
    background: var(--xcrm-danger-bg);
}

.xcrm-badge--info {
    color: var(--xcrm-info);
    background: var(--xcrm-info-bg);
}

.xcrm-badge--neutral {
    color: var(--xcrm-text-muted);
    background: var(--xcrm-border-light);
}

.xcrm-badge--primary {
    color: var(--xcrm-primary);
    background: var(--xcrm-primary-bg);
}

/* ==========================================================================
   9. Conversion Bar
   ========================================================================== */

.xcrm-conversion-bar {
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-2);
    min-width: 120px;
}

.xcrm-conversion-bar-track {
    flex: 1;
    height: 6px;
    background: var(--xcrm-border-light);
    border-radius: var(--xcrm-radius-full);
    overflow: hidden;
}

.xcrm-conversion-bar-fill {
    height: 100%;
    border-radius: var(--xcrm-radius-full);
    background: var(--xcrm-primary);
    transition: width var(--xcrm-transition-slow);
}

.xcrm-conversion-bar-value {
    font-size: var(--xcrm-text-xs);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text-secondary);
    min-width: 36px;
    text-align: left;
    direction: ltr;
}

/* ==========================================================================
   10. Funnel Visualization
   ========================================================================== */

.xcrm-funnel {
    display: flex;
    flex-direction: column;
    gap: var(--xcrm-space-3);
    padding: var(--xcrm-space-5) 0;
}

.xcrm-funnel-stage {
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-4);
}

.xcrm-funnel-label {
    min-width: 140px;
    font-size: var(--xcrm-text-sm);
    font-weight: var(--xcrm-weight-medium);
    color: var(--xcrm-text-secondary);
    text-align: left;
}

.xcrm-funnel-bar-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-3);
}

.xcrm-funnel-bar {
    height: 32px;
    border-radius: var(--xcrm-radius-sm);
    background: linear-gradient(135deg, var(--xcrm-primary) 0%, var(--xcrm-primary-light) 100%);
    transition: width var(--xcrm-transition-slow);
    min-width: 4px;
}

.xcrm-funnel-count {
    font-size: var(--xcrm-text-sm);
    font-weight: var(--xcrm-weight-bold);
    color: var(--xcrm-text);
    min-width: 50px;
    direction: ltr;
    text-align: left;
}

.xcrm-funnel-percentage {
    font-size: var(--xcrm-text-xs);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text-muted);
    min-width: 40px;
    text-align: left;
    direction: ltr;
}

/* ==========================================================================
   11. Timeline / Journey
   ========================================================================== */

.xcrm-timeline {
    position: relative;
    padding: var(--xcrm-space-4) 0;
}

.xcrm-timeline-event {
    display: flex;
    align-items: flex-start;
    gap: var(--xcrm-space-4);
    padding-bottom: var(--xcrm-space-6);
    position: relative;
}

.xcrm-timeline-event:last-child {
    padding-bottom: 0;
}

.xcrm-timeline-line {
    position: absolute;
    right: 15px;
    top: 32px;
    bottom: 0;
    width: 2px;
    background: var(--xcrm-border);
}

.xcrm-timeline-event:last-child .xcrm-timeline-line {
    display: none;
}

.xcrm-timeline-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--xcrm-text-sm);
    flex-shrink: 0;
    z-index: 1;
    background: var(--xcrm-surface);
    border: 2px solid var(--xcrm-border);
}

.xcrm-timeline-dot--visit { border-color: var(--xcrm-info); color: var(--xcrm-info); }
.xcrm-timeline-dot--view { border-color: var(--xcrm-primary-light); color: var(--xcrm-primary-light); }
.xcrm-timeline-dot--cart { border-color: var(--xcrm-warning); color: var(--xcrm-warning); }
.xcrm-timeline-dot--purchase { border-color: var(--xcrm-success); color: var(--xcrm-success); }
.xcrm-timeline-dot--exit { border-color: var(--xcrm-danger); color: var(--xcrm-danger); }
.xcrm-timeline-dot--return { border-color: var(--xcrm-primary); color: var(--xcrm-primary); }

.xcrm-timeline-content {
    flex: 1;
    background: var(--xcrm-bg);
    border-radius: var(--xcrm-radius-md);
    padding: var(--xcrm-space-4);
    transition: background var(--xcrm-transition-fast);
}

.xcrm-timeline-content:hover {
    background: var(--xcrm-border-light);
}

.xcrm-timeline-time {
    font-size: var(--xcrm-text-xs);
    color: var(--xcrm-text-placeholder);
    margin-bottom: var(--xcrm-space-1);
}

.xcrm-timeline-description {
    font-size: var(--xcrm-text-base);
    color: var(--xcrm-text);
    line-height: var(--xcrm-leading-relaxed);
}

.xcrm-timeline-meta {
    font-size: var(--xcrm-text-sm);
    color: var(--xcrm-text-muted);
    margin-top: var(--xcrm-space-1);
}

/* ==========================================================================
   12. Skeleton Loading
   ========================================================================== */

.xcrm-skeleton {
    background: linear-gradient(90deg, var(--xcrm-border-light) 25%, var(--xcrm-bg) 50%, var(--xcrm-border-light) 75%);
    background-size: 200% 100%;
    animation: xcrm-skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--xcrm-radius-md);
}

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

.xcrm-skeleton-text {
    height: 14px;
    margin-bottom: var(--xcrm-space-2);
}

.xcrm-skeleton-text--sm {
    height: 12px;
    width: 60%;
}

.xcrm-skeleton-text--lg {
    height: 24px;
    width: 40%;
}

.xcrm-skeleton-text--xl {
    height: 36px;
    width: 50%;
}

.xcrm-skeleton-circle {
    border-radius: 50%;
}

.xcrm-skeleton-kpi {
    background: var(--xcrm-surface);
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-lg);
    padding: var(--xcrm-space-6);
}

.xcrm-skeleton-kpi .xcrm-skeleton-text:first-child {
    width: 50%;
    margin-bottom: var(--xcrm-space-3);
}

.xcrm-skeleton-row {
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-4);
    padding: var(--xcrm-space-4) 0;
    border-bottom: 1px solid var(--xcrm-border-light);
}

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

.xcrm-skeleton-row .xcrm-skeleton-text {
    margin-bottom: 0;
}

/* ==========================================================================
   13. Empty State
   ========================================================================== */

.xcrm-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--xcrm-space-10) var(--xcrm-space-6);
    text-align: center;
}

.xcrm-empty-state-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--xcrm-radius-xl);
    background: var(--xcrm-border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--xcrm-space-5);
    color: var(--xcrm-text-placeholder);
}

.xcrm-empty-state-title {
    font-size: var(--xcrm-text-lg);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text);
    margin: 0 0 var(--xcrm-space-2) 0;
}

.xcrm-empty-state-description {
    font-size: var(--xcrm-text-base);
    color: var(--xcrm-text-muted);
    max-width: 400px;
    margin: 0 0 var(--xcrm-space-6) 0;
    line-height: var(--xcrm-leading-relaxed);
}

/* ==========================================================================
   14. Error State
   ========================================================================== */

.xcrm-error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--xcrm-space-10) var(--xcrm-space-6);
    text-align: center;
}

.xcrm-error-state-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--xcrm-radius-xl);
    background: var(--xcrm-danger-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--xcrm-space-5);
    color: var(--xcrm-danger);
}

.xcrm-error-state-title {
    font-size: var(--xcrm-text-lg);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text);
    margin: 0 0 var(--xcrm-space-2) 0;
}

.xcrm-error-state-description {
    font-size: var(--xcrm-text-base);
    color: var(--xcrm-text-muted);
    max-width: 400px;
    margin: 0 0 var(--xcrm-space-6) 0;
    line-height: var(--xcrm-leading-relaxed);
}

/* ==========================================================================
   15. Buttons
   ========================================================================== */

.xcrm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--xcrm-space-2);
    font-family: var(--xcrm-font-family);
    font-size: var(--xcrm-text-sm);
    font-weight: var(--xcrm-weight-medium);
    line-height: 1;
    padding: 8px 16px;
    border-radius: var(--xcrm-radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--xcrm-transition-fast);
    white-space: nowrap;
    text-decoration: none;
}

.xcrm-btn:focus-visible {
    outline: 2px solid var(--xcrm-primary);
    outline-offset: 2px;
}

.xcrm-btn--primary {
    background: var(--xcrm-primary);
    color: white;
    border-color: var(--xcrm-primary);
}

.xcrm-btn--primary:hover {
    background: var(--xcrm-primary-dark);
    border-color: var(--xcrm-primary-dark);
}

.xcrm-btn--secondary {
    background: var(--xcrm-surface);
    color: var(--xcrm-text);
    border-color: var(--xcrm-border);
}

.xcrm-btn--secondary:hover {
    background: var(--xcrm-bg);
    border-color: var(--xcrm-border);
}

.xcrm-btn--ghost {
    background: transparent;
    color: var(--xcrm-text-secondary);
    border-color: transparent;
}

.xcrm-btn--ghost:hover {
    background: var(--xcrm-bg);
    color: var(--xcrm-text);
}

.xcrm-btn--sm {
    font-size: var(--xcrm-text-xs);
    padding: 6px 12px;
}

.xcrm-btn--icon {
    padding: 8px;
}

.xcrm-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.xcrm-btn:disabled:hover {
    background: var(--xcrm-surface);
    border-color: var(--xcrm-border);
}

.xcrm-btn--primary:disabled:hover {
    background: var(--xcrm-primary);
    border-color: var(--xcrm-primary);
}

/* ==========================================================================
   16. Search Input
   ========================================================================== */

.xcrm-search-input-wrapper {
    position: relative;
    max-width: 400px;
    z-index: var(--xcrm-z-sticky);
}

.xcrm-search-input {
    width: 100%;
    font-family: var(--xcrm-font-family);
    font-size: var(--xcrm-text-base);
    padding: 10px 16px;
    padding-inline-start: 40px;
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-md);
    background: var(--xcrm-surface);
    color: var(--xcrm-text);
    transition: border-color var(--xcrm-transition-fast), box-shadow var(--xcrm-transition-fast);
}

.xcrm-search-input:focus {
    outline: none;
    border-color: var(--xcrm-primary);
    box-shadow: 0 0 0 3px var(--xcrm-primary-bg);
}

.xcrm-search-input::placeholder {
    color: var(--xcrm-text-placeholder);
}

.xcrm-search-input-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--xcrm-text-placeholder);
    pointer-events: none;
}

.xcrm-search-input-loading {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--xcrm-border);
    border-top-color: var(--xcrm-primary);
    border-radius: 50%;
    animation: xcrm-spin 0.6s linear infinite;
    display: none;
}

.xcrm-search-input.is-loading .xcrm-search-input-loading {
    display: block;
}

.xcrm-search-input-enter {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: var(--xcrm-text-xs);
    color: var(--xcrm-text-placeholder);
    background: var(--xcrm-bg);
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-xs);
    padding: 2px 6px;
    pointer-events: none;
    display: none;
}

.xcrm-search-input:focus ~ .xcrm-search-input-enter {
    display: block;
}

.xcrm-search-input.is-loading ~ .xcrm-search-input-enter {
    display: none;
}

.xcrm-search-input-no-results {
    padding: var(--xcrm-space-4);
    text-align: center;
    font-size: var(--xcrm-text-sm);
    color: var(--xcrm-text-muted);
}

/* ==========================================================================
   17. Dropdown / Search Results
   ========================================================================== */

.xcrm-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    margin-top: var(--xcrm-space-1);
    background: var(--xcrm-surface);
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-md);
    box-shadow: var(--xcrm-shadow-lg);
    z-index: var(--xcrm-z-dropdown);
    max-height: 240px;
    overflow-y: auto;
}

.xcrm-dropdown-item {
    padding: var(--xcrm-space-3) var(--xcrm-space-4);
    cursor: pointer;
    transition: background var(--xcrm-transition-fast);
    border-bottom: 1px solid var(--xcrm-border-light);
}

.xcrm-dropdown-item:last-child {
    border-bottom: none;
}

.xcrm-dropdown-item:hover {
    background: var(--xcrm-bg);
}

.xcrm-dropdown-item-name {
    font-size: var(--xcrm-text-base);
    font-weight: var(--xcrm-weight-medium);
    color: var(--xcrm-text);
}

.xcrm-dropdown-item-meta {
    font-size: var(--xcrm-text-xs);
    color: var(--xcrm-text-muted);
    margin-top: 2px;
}

/* ==========================================================================
   18. Attribution Table
   ========================================================================== */

.xcrm-attribution-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--xcrm-space-4);
    padding: var(--xcrm-space-5);
}

.xcrm-attribution-item {
    display: flex;
    flex-direction: column;
    gap: var(--xcrm-space-1);
}

.xcrm-attribution-label {
    font-size: var(--xcrm-text-xs);
    font-weight: var(--xcrm-weight-medium);
    color: var(--xcrm-text-muted);
}

.xcrm-attribution-value {
    font-size: var(--xcrm-text-base);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text);
}

/* ==========================================================================
   19. Stats Card Grid (Overview Page)
   ========================================================================== */

.xcrm-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--xcrm-space-5);
    margin-top: var(--xcrm-space-6);
}

.xcrm-stats-card {
    display: flex;
    align-items: flex-start;
    gap: var(--xcrm-space-4);
    background: var(--xcrm-surface);
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-lg);
    padding: var(--xcrm-space-6);
    text-decoration: none;
    color: inherit;
    transition: border-color var(--xcrm-transition-fast), box-shadow var(--xcrm-transition-fast), transform var(--xcrm-transition-fast);
}

.xcrm-stats-card:hover {
    border-color: var(--xcrm-primary-light);
    box-shadow: var(--xcrm-shadow-md);
    transform: translateY(-2px);
}

.xcrm-stats-card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--xcrm-radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    background: var(--xcrm-primary-bg);
    color: var(--xcrm-primary);
}

.xcrm-stats-card-content {
    flex: 1;
    min-width: 0;
}

.xcrm-stats-card-title {
    font-size: var(--xcrm-text-md);
    font-weight: var(--xcrm-weight-semibold);
    color: var(--xcrm-text);
    margin: 0 0 var(--xcrm-space-1) 0;
}

.xcrm-stats-card-description {
    font-size: var(--xcrm-text-sm);
    color: var(--xcrm-text-muted);
    margin: 0;
    line-height: var(--xcrm-leading-relaxed);
}

/* ==========================================================================
   20. WordPress Admin Notice Override
   ========================================================================== */

.xcrm-page .notice {
    border-radius: var(--xcrm-radius-md);
    border-color: var(--xcrm-border);
    box-shadow: var(--xcrm-shadow-xs);
}

.xcrm-page .notice-info {
    border-right: 4px solid var(--xcrm-info);
}

.xcrm-page .notice-success {
    border-right: 4px solid var(--xcrm-success);
}

.xcrm-page .notice-error {
    border-right: 4px solid var(--xcrm-danger);
}

.xcrm-page .button-primary {
    background: var(--xcrm-primary);
    border-color: var(--xcrm-primary);
}

.xcrm-page .button-primary:hover {
    background: var(--xcrm-primary-dark);
    border-color: var(--xcrm-primary-dark);
}

.xcrm-page .button {
    font-family: var(--xcrm-font-family);
    border-radius: var(--xcrm-radius-md);
}

/* ==========================================================================
   22. Responsive
   ========================================================================== */

@media (max-width: 1024px) {
    .xcrm-page {
        padding: var(--xcrm-space-5);
    }

    .xcrm-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .xcrm-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .xcrm-page {
        padding: var(--xcrm-space-4);
    }

    .xcrm-page-header-row {
        flex-direction: column;
        gap: var(--xcrm-space-3);
    }

    .xcrm-page-actions {
        width: 100%;
    }

    .xcrm-kpi-grid {
        grid-template-columns: 1fr;
    }

    .xcrm-kpi-value {
        font-size: var(--xcrm-text-2xl);
    }

    .xcrm-stats-grid {
        grid-template-columns: 1fr;
    }

    .xcrm-table-wrapper {
        margin-inline: calc(-1 * var(--xcrm-space-4));
        padding-inline: var(--xcrm-space-4);
    }

    .xcrm-funnel-stage {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--xcrm-space-2);
    }

    .xcrm-funnel-label {
        min-width: auto;
    }

    .xcrm-attribution-grid {
        grid-template-columns: 1fr 1fr;
    }

    .xcrm-data-section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--xcrm-space-2);
    }
}

@media (max-width: 480px) {
    .xcrm-page {
        padding: var(--xcrm-space-3);
    }

    .xcrm-page-title {
        font-size: var(--xcrm-text-xl);
    }

    .xcrm-attribution-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   23. Utilities
   ========================================================================== */

.xcrm-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.xcrm-hidden {
    display: none !important;
}

.xcrm-text-center {
    text-align: center;
}

.xcrm-text-left {
    text-align: left;
}

.xcrm-mt-0 { margin-top: 0; }
.xcrm-mt-4 { margin-top: var(--xcrm-space-4); }
.xcrm-mt-6 { margin-top: var(--xcrm-space-6); }
.xcrm-mb-0 { margin-bottom: 0; }
.xcrm-mb-4 { margin-bottom: var(--xcrm-space-4); }
.xcrm-mb-6 { margin-bottom: var(--xcrm-space-6); }

/* ==========================================================================
   24. Data Mode Toggle
   ========================================================================== */

.xcrm-data-mode-toggle {
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-3);
    background: var(--xcrm-surface);
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-lg);
    padding: var(--xcrm-space-3) var(--xcrm-space-5);
    margin-bottom: var(--xcrm-space-6);
}

.xcrm-toggle-label-off,
.xcrm-toggle-label-on {
    font-size: var(--xcrm-text-sm);
    font-weight: var(--xcrm-weight-medium);
    color: var(--xcrm-text-muted);
    transition: color var(--xcrm-transition-fast);
}

.xcrm-toggle-label-on {
    color: var(--xcrm-primary);
    font-weight: var(--xcrm-weight-semibold);
}

.xcrm-toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.xcrm-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.xcrm-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: var(--xcrm-border);
    transition: var(--xcrm-transition-base);
    border-radius: var(--xcrm-radius-full);
}

.xcrm-toggle-slider::before {
    position: absolute;
    content: '';
    height: 18px;
    width: 18px;
    right: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--xcrm-transition-base);
    border-radius: 50%;
    box-shadow: var(--xcrm-shadow-xs);
}

.xcrm-toggle-switch input:checked + .xcrm-toggle-slider {
    background-color: var(--xcrm-primary);
}

.xcrm-toggle-switch input:checked + .xcrm-toggle-slider::before {
    transform: translateX(-20px);
}

.xcrm-toggle-switch input:focus-visible + .xcrm-toggle-slider {
    outline: 2px solid var(--xcrm-primary);
    outline-offset: 2px;
}

.xcrm-toggle-hint {
    font-size: var(--xcrm-text-xs);
    color: var(--xcrm-text-placeholder);
}

/* ==========================================================================
   25. Onboarding Progress
   ========================================================================== */
#xcrm-acq-search-results {
    position: inherit;
}

#xcrm-search-results {
    position: inherit;

}
.xcrm-onboarding-card {
    background: var(--xcrm-surface);
    border: 1px solid var(--xcrm-border);
    border-radius: var(--xcrm-radius-xl);
    padding: var(--xcrm-space-7);
    margin-bottom: var(--xcrm-space-7);
    position: relative;
    overflow: hidden;
}

.xcrm-onboarding-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--xcrm-primary), var(--xcrm-primary-light));
}

.xcrm-onboarding-content {
    display: flex;
    align-items: flex-start;
    gap: var(--xcrm-space-4);
    margin-bottom: var(--xcrm-space-6);
}

.xcrm-onboarding-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--xcrm-radius-lg);
    background: var(--xcrm-primary-bg);
    color: var(--xcrm-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.xcrm-onboarding-title {
    font-size: var(--xcrm-text-lg);
    font-weight: var(--xcrm-weight-bold);
    color: var(--xcrm-text);
    margin: 0 0 var(--xcrm-space-1) 0;
}

.xcrm-onboarding-desc {
    font-size: var(--xcrm-text-sm);
    color: var(--xcrm-text-muted);
    margin: 0;
    line-height: var(--xcrm-leading-relaxed);
}

.xcrm-onboarding-progress-wrapper {
    margin-bottom: var(--xcrm-space-5);
}

.xcrm-onboarding-progress-bar {
    width: 100%;
    height: 10px;
    background: var(--xcrm-border-light);
    border-radius: var(--xcrm-radius-full);
    overflow: hidden;
    margin-bottom: var(--xcrm-space-2);
}

.xcrm-onboarding-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--xcrm-primary), var(--xcrm-primary-light));
    border-radius: var(--xcrm-radius-full);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.xcrm-onboarding-progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: xcrm-progress-shine 2s ease-in-out infinite;
}

@keyframes xcrm-progress-shine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.xcrm-onboarding-progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--xcrm-text-sm);
    color: var(--xcrm-text-muted);
}

.xcrm-onboarding-progress-info span:last-child {
    font-weight: var(--xcrm-weight-bold);
    color: var(--xcrm-primary);
}

.xcrm-onboarding-tips {
    display: flex;
    flex-direction: column;
    gap: var(--xcrm-space-2);
    padding-top: var(--xcrm-space-4);
    border-top: 1px solid var(--xcrm-border-light);
}

.xcrm-onboarding-tip {
    display: flex;
    align-items: center;
    gap: var(--xcrm-space-2);
    font-size: var(--xcrm-text-sm);
    color: var(--xcrm-text-muted);
}

.xcrm-onboarding-tip svg {
    color: var(--xcrm-primary-light);
    flex-shrink: 0;
}

.xcrm-onboarding-tip--action {
    background: var(--xcrm-primary-bg);
    padding: var(--xcrm-space-3) var(--xcrm-space-4);
    border-radius: var(--xcrm-radius-md);
    border: 1px solid var(--xcrm-primary-light);
}

/* ==========================================================================
   26. Celebration
   ========================================================================== */

.xcrm-celebration-card {
    background: var(--xcrm-surface);
    border: 2px solid var(--xcrm-success-light);
    border-radius: var(--xcrm-radius-xl);
    padding: var(--xcrm-space-10) var(--xcrm-space-7);
    margin-bottom: var(--xcrm-space-7);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.xcrm-celebration-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--xcrm-success), #34D399);
}

#xcrm-confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.xcrm-celebration-content {
    position: relative;
    z-index: 1;
}

.xcrm-celebration-check {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--xcrm-success-bg);
    color: var(--xcrm-success);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--xcrm-space-6);
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.xcrm-celebration-check--animated {
    opacity: 1;
    transform: scale(1);
}

.xcrm-celebration-check svg {
    width: 40px;
    height: 40px;
}

.xcrm-celebration-title {
    font-size: var(--xcrm-text-2xl);
    font-weight: var(--xcrm-weight-bold);
    color: var(--xcrm-text);
    margin: 0 0 var(--xcrm-space-3) 0;
}

.xcrm-celebration-desc {
    font-size: var(--xcrm-text-md);
    color: var(--xcrm-text-muted);
    max-width: 500px;
    margin: 0 auto var(--xcrm-space-6);
    line-height: var(--xcrm-leading-relaxed);
}

.xcrm-celebration-btn {
    font-size: var(--xcrm-text-base) !important;
    padding: 12px 28px !important;
}



/* ==========================================================================
   27. Responsive - Toggle & Onboarding
   ========================================================================== */

@media (max-width: 768px) {
    .xcrm-data-mode-toggle {
        flex-wrap: wrap;
        gap: var(--xcrm-space-2);
    }

    .xcrm-onboarding-content {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .xcrm-celebration-card {
        padding: var(--xcrm-space-7) var(--xcrm-space-4);
    }

    .xcrm-celebration-title {
        font-size: var(--xcrm-text-xl);
    }
}
