/* ============================================
   RSL Stats Component
   Version: 1.0.0
   Description: Lightweight, accessible statistics
   display for landing pages, dashboards, and
   marketing sections. Simpler than KPI Cards,
   perfect for trust indicators and key metrics.

   Accessibility: WCAG 2.1 AA compliant
   - High contrast focus states
   - Reduced motion support
   - Screen reader optimized
   ============================================ */

/* ============================================
   CSS Custom Properties
   ============================================ */
:root {
    /* Base colors */
    --rsl-stat-bg: transparent;
    --rsl-stat-text: #1e293b;
    --rsl-stat-text-muted: #64748b;
    --rsl-stat-border: #e2e8f0;

    /* Color schemes */
    --rsl-stat-primary: #6E7BFF;
    --rsl-stat-primary-light: rgba(110, 123, 255, 0.1);
    --rsl-stat-success: #10b981;
    --rsl-stat-success-light: rgba(16, 185, 129, 0.1);
    --rsl-stat-warning: #f59e0b;
    --rsl-stat-warning-light: rgba(245, 158, 11, 0.1);
    --rsl-stat-danger: #ef4444;
    --rsl-stat-danger-light: rgba(239, 68, 68, 0.1);
    --rsl-stat-info: #06b6d4;
    --rsl-stat-info-light: rgba(6, 182, 212, 0.1);

    /* Animation */
    --rsl-stat-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --rsl-stat-animation-duration: 1500ms;

    /* Focus ring */
    --rsl-stat-focus-ring: 3px solid var(--rsl-stat-primary);
    --rsl-stat-focus-offset: 4px;
}

/* ============================================
   Stats Group Container
   ============================================ */
.rsl-stats {
    display: flex;
    flex-wrap: wrap;
    gap: var(--rsl-stats-gap, 2rem);
    align-items: stretch;
}

/* Row layout (default) */
.rsl-stats[data-layout="row"],
.rsl-stats:not([data-layout]) {
    flex-direction: row;
    justify-content: center;
}

/* Column layout */
.rsl-stats[data-layout="column"] {
    flex-direction: column;
    align-items: stretch;
}

/* Grid layout - uses slot-layout integration */
.rsl-stats[data-layout="grid"] {
    display: grid;
    grid-template-columns: repeat(var(--rsl-stats-cols, 3), 1fr);
}

/* Dividers between stats */
.rsl-stats[data-dividers] > .rsl-stat:not(:last-child) {
    border-right: 1px solid var(--rsl-stat-border);
    padding-right: var(--rsl-stats-gap, 2rem);
}

.rsl-stats[data-layout="column"][data-dividers] > .rsl-stat:not(:last-child) {
    border-right: none;
    border-bottom: 1px solid var(--rsl-stat-border);
    padding-right: 0;
    padding-bottom: var(--rsl-stats-gap, 2rem);
}

/* Gap customization */
.rsl-stats[data-gap="sm"] { --rsl-stats-gap: 1rem; }
.rsl-stats[data-gap="md"] { --rsl-stats-gap: 2rem; }
.rsl-stats[data-gap="lg"] { --rsl-stats-gap: 3rem; }
.rsl-stats[data-gap="xl"] { --rsl-stats-gap: 4rem; }

/* ============================================
   Single Stat Base
   ============================================ */
.rsl-stat {
    display: flex;
    flex-direction: column;
    align-items: var(--rsl-stat-align, center);
    text-align: var(--rsl-stat-align, center);
    padding: 1rem;
    background: var(--rsl-stat-bg);
    border-radius: 8px;
    transition: all var(--rsl-stat-transition);
    position: relative;
    text-decoration: none;
    color: inherit;
}

/* Alignment variants */
.rsl-stat[data-align="left"] {
    --rsl-stat-align: flex-start;
    text-align: left;
}

.rsl-stat[data-align="center"] {
    --rsl-stat-align: center;
    text-align: center;
}

.rsl-stat[data-align="right"] {
    --rsl-stat-align: flex-end;
    text-align: right;
}

/* Hover effect for non-clickable stats */
.rsl-stat:not([data-clickable]):hover {
    transform: translateY(-2px);
}

/* Clickable stats */
.rsl-stat[data-clickable],
a.rsl-stat {
    cursor: pointer;
}

.rsl-stat[data-clickable]:hover,
a.rsl-stat:hover {
    transform: translateY(-3px);
    background: var(--rsl-stat-scheme-light, rgba(110, 123, 255, 0.05));
}

/* ============================================
   Focus States (ADA Compliant)
   ============================================ */
.rsl-stat:focus {
    outline: var(--rsl-stat-focus-ring);
    outline-offset: var(--rsl-stat-focus-offset);
}

.rsl-stat:focus:not(:focus-visible) {
    outline: none;
}

.rsl-stat:focus-visible {
    outline: var(--rsl-stat-focus-ring);
    outline-offset: var(--rsl-stat-focus-offset);
    box-shadow: 0 0 0 6px var(--rsl-stat-scheme-light, var(--rsl-stat-primary-light));
}

/* High contrast focus for accessibility */
@media (forced-colors: active) {
    .rsl-stat:focus-visible {
        outline: 3px solid CanvasText;
        outline-offset: 4px;
    }
}

/* ============================================
   Stat Icon
   ============================================ */
.rsl-stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--rsl-stat-scheme-light, var(--rsl-stat-primary-light));
    color: var(--rsl-stat-scheme-color, var(--rsl-stat-primary));
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    transition: all var(--rsl-stat-transition);
}

.rsl-stat:hover .rsl-stat-icon {
    transform: scale(1.05);
}

/* Icon sizes */
.rsl-stat[data-size="sm"] .rsl-stat-icon {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    border-radius: 8px;
}

.rsl-stat[data-size="lg"] .rsl-stat-icon,
.rsl-stat[data-size="xl"] .rsl-stat-icon {
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
    border-radius: 14px;
}

/* ============================================
   Stat Value (The Number)
   ============================================ */
.rsl-stat-value {
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.025em;
    color: var(--rsl-stat-scheme-color, var(--rsl-stat-text));
    display: flex;
    align-items: baseline;
    justify-content: inherit;
    gap: 0.125em;
    transition: color var(--rsl-stat-transition);
}

/* Size variants */
.rsl-stat[data-size="xs"] .rsl-stat-value {
    font-size: 1.125rem;
}

.rsl-stat[data-size="sm"] .rsl-stat-value {
    font-size: 1.5rem;
}

.rsl-stat .rsl-stat-value,
.rsl-stat[data-size="md"] .rsl-stat-value {
    font-size: 2.25rem;
}

.rsl-stat[data-size="lg"] .rsl-stat-value {
    font-size: 3rem;
}

.rsl-stat[data-size="xl"] .rsl-stat-value {
    font-size: 4rem;
}

/* Prefix and suffix */
.rsl-stat-prefix,
.rsl-stat-suffix {
    font-size: 0.65em;
    font-weight: 600;
    color: var(--rsl-stat-scheme-color, var(--rsl-stat-text-muted));
    opacity: 0.8;
}

/* Gradient text effect */
.rsl-stat[data-gradient] .rsl-stat-value {
    background: linear-gradient(135deg, var(--rsl-stat-scheme-color, #6E7BFF) 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   Stat Label
   ============================================ */
.rsl-stat-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--rsl-stat-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.5rem;
    transition: color var(--rsl-stat-transition);
}

/* Size variants */
.rsl-stat[data-size="xs"] .rsl-stat-label {
    font-size: 0.625rem;
    margin-top: 0.25rem;
}

.rsl-stat[data-size="sm"] .rsl-stat-label {
    font-size: 0.75rem;
    margin-top: 0.375rem;
}

.rsl-stat[data-size="lg"] .rsl-stat-label {
    font-size: 1rem;
    margin-top: 0.625rem;
}

.rsl-stat[data-size="xl"] .rsl-stat-label {
    font-size: 1.25rem;
    margin-top: 0.75rem;
}

/* Description (optional longer text) */
.rsl-stat-description {
    font-size: 0.8125rem;
    color: var(--rsl-stat-text-muted);
    margin-top: 0.25rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    opacity: 0.8;
}

/* ============================================
   Variant: Compact
   ============================================ */
.rsl-stat[data-variant="compact"] {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
}

.rsl-stat[data-variant="compact"] .rsl-stat-icon {
    margin-bottom: 0;
    width: 40px;
    height: 40px;
}

.rsl-stat[data-variant="compact"] .rsl-stat-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.rsl-stat[data-variant="compact"] .rsl-stat-value {
    font-size: 1.5rem;
}

.rsl-stat[data-variant="compact"] .rsl-stat-label {
    margin-top: 0;
    font-size: 0.75rem;
}

/* ============================================
   Variant: Inline (Badge-like)
   ============================================ */
.rsl-stat[data-variant="inline"] {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--rsl-stat-scheme-light, var(--rsl-stat-primary-light));
    border-radius: 9999px;
}

.rsl-stat[data-variant="inline"] .rsl-stat-icon {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
    margin-bottom: 0;
    background: transparent;
}

.rsl-stat[data-variant="inline"] .rsl-stat-value {
    font-size: 1rem;
    font-weight: 700;
}

.rsl-stat[data-variant="inline"] .rsl-stat-label {
    font-size: 0.75rem;
    margin-top: 0;
    text-transform: none;
    letter-spacing: normal;
}

/* ============================================
   Variant: Featured (Hero stat)
   ============================================ */
.rsl-stat[data-variant="featured"] {
    padding: 2rem;
    background: var(--rsl-stat-scheme-light, var(--rsl-stat-primary-light));
    border-radius: 16px;
    border: 1px solid var(--rsl-stat-border);
}

.rsl-stat[data-variant="featured"] .rsl-stat-icon {
    width: 64px;
    height: 64px;
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

.rsl-stat[data-variant="featured"] .rsl-stat-value {
    font-size: 3.5rem;
}

.rsl-stat[data-variant="featured"] .rsl-stat-label {
    font-size: 1.125rem;
    margin-top: 0.75rem;
}

.rsl-stat[data-variant="featured"] .rsl-stat-description {
    font-size: 0.9375rem;
    max-width: 300px;
}

/* ============================================
   Variant: Card (with background)
   ============================================ */
.rsl-stat[data-variant="card"] {
    background: #ffffff;
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--rsl-stat-border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.rsl-stat[data-variant="card"]:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Color Schemes
   ============================================ */
.rsl-stat[data-color-scheme="primary"] {
    --rsl-stat-scheme-color: var(--rsl-stat-primary);
    --rsl-stat-scheme-light: var(--rsl-stat-primary-light);
}

.rsl-stat[data-color-scheme="success"] {
    --rsl-stat-scheme-color: var(--rsl-stat-success);
    --rsl-stat-scheme-light: var(--rsl-stat-success-light);
}

.rsl-stat[data-color-scheme="warning"] {
    --rsl-stat-scheme-color: var(--rsl-stat-warning);
    --rsl-stat-scheme-light: var(--rsl-stat-warning-light);
}

.rsl-stat[data-color-scheme="danger"] {
    --rsl-stat-scheme-color: var(--rsl-stat-danger);
    --rsl-stat-scheme-light: var(--rsl-stat-danger-light);
}

.rsl-stat[data-color-scheme="info"] {
    --rsl-stat-scheme-color: var(--rsl-stat-info);
    --rsl-stat-scheme-light: var(--rsl-stat-info-light);
}

/* ============================================
   Animation States
   ============================================ */
.rsl-stat[data-animate] .rsl-stat-value {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.rsl-stat[data-animate].rsl-stat-animated .rsl-stat-value {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger animation for groups */
.rsl-stats[data-stagger] > .rsl-stat:nth-child(1) { --rsl-stat-delay: 0ms; }
.rsl-stats[data-stagger] > .rsl-stat:nth-child(2) { --rsl-stat-delay: 100ms; }
.rsl-stats[data-stagger] > .rsl-stat:nth-child(3) { --rsl-stat-delay: 200ms; }
.rsl-stats[data-stagger] > .rsl-stat:nth-child(4) { --rsl-stat-delay: 300ms; }
.rsl-stats[data-stagger] > .rsl-stat:nth-child(5) { --rsl-stat-delay: 400ms; }
.rsl-stats[data-stagger] > .rsl-stat:nth-child(6) { --rsl-stat-delay: 500ms; }

.rsl-stats[data-stagger] > .rsl-stat[data-animate] .rsl-stat-value {
    transition-delay: var(--rsl-stat-delay, 0ms);
}

/* ============================================
   Reduced Motion (Accessibility)
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .rsl-stat,
    .rsl-stat-value,
    .rsl-stat-icon {
        transition: none !important;
        animation: none !important;
    }

    .rsl-stat[data-animate] .rsl-stat-value {
        opacity: 1;
        transform: none;
    }

    .rsl-stat:hover {
        transform: none;
    }
}

/* ============================================
   FilterBus States
   ============================================ */
.rsl-stat.rsl-stat-hidden {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
    position: absolute;
    visibility: hidden;
}

.rsl-stat.rsl-stat-filtered {
    /* Visual indicator that value is filtered */
}

.rsl-stat.rsl-stat-filtered::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background: var(--rsl-stat-scheme-color, var(--rsl-stat-primary));
    border-radius: 50%;
    opacity: 0.6;
}

/* ============================================
   Dark Mode
   ============================================ */
[data-theme="dark"] {
    --rsl-stat-bg: transparent;
    --rsl-stat-text: #f1f5f9;
    --rsl-stat-text-muted: #94a3b8;
    --rsl-stat-border: #334155;

    --rsl-stat-primary-light: rgba(110, 123, 255, 0.15);
    --rsl-stat-success-light: rgba(16, 185, 129, 0.15);
    --rsl-stat-warning-light: rgba(245, 158, 11, 0.15);
    --rsl-stat-danger-light: rgba(239, 68, 68, 0.15);
    --rsl-stat-info-light: rgba(6, 182, 212, 0.15);
}

[data-theme="dark"] .rsl-stat[data-variant="card"] {
    background: #1e293b;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .rsl-stat[data-variant="card"]:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .rsl-stat[data-variant="featured"] {
    border-color: #334155;
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
    .rsl-stats[data-layout="row"]:not([data-cols-xs]) {
        flex-direction: column;
        align-items: center;
    }

    .rsl-stats[data-layout="row"][data-dividers]:not([data-cols-xs]) > .rsl-stat:not(:last-child) {
        border-right: none;
        border-bottom: 1px solid var(--rsl-stat-border);
        padding-right: 0;
        padding-bottom: var(--rsl-stats-gap, 2rem);
    }

    .rsl-stat[data-size="xl"] .rsl-stat-value {
        font-size: 3rem;
    }

    .rsl-stat[data-variant="featured"] .rsl-stat-value {
        font-size: 2.5rem;
    }
}

@media (max-width: 480px) {
    .rsl-stat[data-size="lg"] .rsl-stat-value {
        font-size: 2.25rem;
    }

    .rsl-stat[data-size="xl"] .rsl-stat-value {
        font-size: 2.5rem;
    }

    .rsl-stat[data-variant="featured"] {
        padding: 1.5rem;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .rsl-stat {
        background: transparent !important;
        box-shadow: none !important;
        border: 1px solid #ccc !important;
    }

    .rsl-stat-value {
        color: #000 !important;
    }
}
