/**
 * ============================================================================
 * QENEX UNIFIED DESIGN SYSTEM - KPI & PERFORMANCE VISUALIZATION
 * Version: 2.0.0
 * ============================================================================
 *
 * Specialized components for showcasing technical performance metrics.
 * Designed to communicate speed, reliability, and engineering depth.
 */

/* ============================================================================
   KPI STATS BAR - Hero Performance Metrics
   ============================================================================ */

.stats-bar {
    display: flex;
    justify-content: center;
    gap: var(--space-16);
    padding: var(--space-12) 0;
    flex-wrap: wrap;
}

.stat-item {
    text-align: center;
    position: relative;
}

.stat-item::after {
    content: '';
    position: absolute;
    right: calc(var(--space-16) * -0.5);
    top: 50%;
    transform: translateY(-50%);
    width: 1px;
    height: 60%;
    background: linear-gradient(
        180deg,
        transparent,
        var(--border-default),
        transparent
    );
}

.stat-item:last-child::after {
    display: none;
}

.stat-value {
    font-size: var(--text-5xl);
    font-weight: var(--font-extrabold);
    line-height: 1;
    margin-bottom: var(--space-2);
    background: var(--gradient-text);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-widest);
    color: var(--text-muted);
}

/* Animated counter variant */
.stat-value[data-counter] {
    animation: countUp 0.5s ease-out forwards;
}

/* Pulsing highlight for "live" metrics */
.stat-live .stat-value::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -16px;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    background: var(--color-success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

/* ============================================================================
   KPI CARDS - Large Performance Display
   ============================================================================ */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-6);
}

.kpi-card {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    position: relative;
    overflow: hidden;
    transition: var(--transition-all-base);
}

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

.kpi-card:hover {
    border-color: var(--brand-accent);
    transform: translateY(-4px);
    box-shadow: var(--glow-cyan), var(--shadow-lg);
}

.kpi-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-2xl);
    margin-bottom: var(--space-6);
    background: var(--surface-overlay);
    box-shadow: var(--glow-cyan-sm);
}

.kpi-label {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    color: var(--brand-accent);
    margin-bottom: var(--space-2);
}

.kpi-title {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-4);
}

.kpi-value {
    font-size: var(--text-4xl);
    font-weight: var(--font-extrabold);
    background: var(--gradient-text);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-4);
}

.kpi-description {
    color: var(--text-muted);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
}

/* KPI Metrics Row */
.kpi-metrics {
    display: flex;
    gap: var(--space-6);
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-subtle);
    margin-top: var(--space-4);
}

.kpi-metric {
    text-align: left;
}

.kpi-metric-value {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--brand-accent);
}

.kpi-metric-label {
    font-size: var(--text-xs);
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

/* ============================================================================
   TECH STACK CARDS
   ============================================================================ */

.stack-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
}

.stack-card {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    position: relative;
    overflow: hidden;
    transition: var(--transition-all-base);
}

/* Tech-specific accent colors */
.stack-card[data-tech="rust"] { --tech-color: var(--brand-magenta); }
.stack-card[data-tech="elixir"] { --tech-color: var(--brand-secondary); }
.stack-card[data-tech="webgpu"] { --tech-color: var(--brand-accent); }
.stack-card[data-tech="ai"] { --tech-color: var(--brand-accent); }
.stack-card[data-tech="redis"] { --tech-color: var(--brand-magenta); }

.stack-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--tech-color, var(--brand-accent));
    opacity: 0;
    transition: opacity var(--transition-base);
}

.stack-card:hover {
    transform: translateY(-6px);
    border-color: var(--tech-color, var(--brand-accent));
    box-shadow: 0 0 20px rgba(var(--brand-accent-rgb), 0.3), var(--shadow-lg);
}

.stack-card:hover::before {
    opacity: 1;
}

.stack-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-3xl);
    margin-bottom: var(--space-5);
    background: rgba(var(--brand-accent-rgb), 0.1);
    box-shadow: 0 0 15px rgba(var(--brand-accent-rgb), 0.2);
}

.stack-label {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    color: var(--tech-color, var(--brand-accent));
    margin-bottom: var(--space-2);
}

.stack-title {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-4);
}

.stack-desc {
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
    margin-bottom: var(--space-6);
}

.stack-metrics {
    display: flex;
    gap: var(--space-6);
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-subtle);
}

.stack-metric {
    text-align: left;
}

.stack-metric-value {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    color: var(--tech-color, var(--brand-accent));
}

.stack-metric-label {
    font-size: var(--text-xs);
    color: var(--text-dim);
    text-transform: uppercase;
}

/* ============================================================================
   DATA FLOW PIPELINE VISUALIZATION
   ============================================================================ */

.data-flow {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-12) var(--space-8);
    margin: var(--space-10) 0;
}

.flow-pipeline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-5);
    flex-wrap: wrap;
}

.flow-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
}

.flow-box {
    width: 130px;
    height: 85px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-semibold);
    font-size: var(--text-sm);
    border: 2px solid;
    position: relative;
    transition: var(--transition-all-base);
    text-align: center;
    padding: var(--space-2);
}

.flow-box:hover {
    transform: scale(1.05);
    box-shadow: var(--glow-cyan);
}

/* Tech-specific flow box colors */
.flow-box.source {
    background: rgba(245, 158, 11, 0.1);
    border-color: #f59e0b;
    color: #f59e0b;
}

.flow-box.rust {
    background: rgba(var(--brand-magenta-rgb), 0.1);
    border-color: var(--brand-magenta);
    color: var(--brand-magenta);
}

.flow-box.redis {
    background: rgba(var(--brand-magenta-rgb), 0.1);
    border-color: var(--brand-magenta);
    color: var(--brand-magenta);
}

.flow-box.elixir {
    background: rgba(var(--brand-secondary-rgb), 0.1);
    border-color: var(--brand-secondary);
    color: var(--brand-tertiary);
}

.flow-box.webgpu,
.flow-box.browser {
    background: rgba(var(--brand-accent-rgb), 0.1);
    border-color: var(--brand-accent);
    color: var(--brand-accent);
}

.flow-box.ai {
    background: rgba(var(--brand-accent-rgb), 0.1);
    border-color: var(--brand-accent);
    color: var(--brand-accent);
}

.flow-arrow {
    width: 50px;
    height: 2px;
    background: linear-gradient(
        90deg,
        var(--border-subtle),
        var(--brand-accent),
        var(--border-subtle)
    );
    position: relative;
}

.flow-arrow::after {
    content: '';
    position: absolute;
    right: -8px;
    top: -5px;
    width: 0;
    height: 0;
    border-left: 10px solid var(--brand-accent);
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

.flow-latency {
    font-size: var(--text-xs);
    color: var(--text-dim);
    font-family: var(--font-mono);
    text-transform: uppercase;
}

/* ============================================================================
   PERFORMANCE METERS / GAUGES
   ============================================================================ */

.perf-gauge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
}

.gauge-ring {
    position: relative;
    width: 120px;
    height: 120px;
}

.gauge-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.gauge-bg {
    fill: none;
    stroke: var(--surface-overlay);
    stroke-width: 8;
}

.gauge-fill {
    fill: none;
    stroke: url(#gaugeGradient);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 283; /* 2 * PI * 45 (radius) */
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 1s ease-out;
}

.gauge-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--text-primary);
}

.gauge-label {
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
}

/* ============================================================================
   LIVE TICKER / REAL-TIME DATA BAR
   ============================================================================ */

.live-ticker {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--border-subtle);
    padding: var(--space-2) var(--space-6);
    display: flex;
    align-items: center;
    gap: var(--space-5);
    overflow-x: auto;
    z-index: var(--z-fixed);
    font-size: var(--text-sm);
}

.ticker-label {
    color: var(--brand-accent);
    font-weight: var(--font-semibold);
    white-space: nowrap;
}

.ticker-status {
    width: 8px;
    height: 8px;
    background: var(--color-success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.ticker-items {
    display: flex;
    gap: var(--space-6);
    overflow-x: auto;
}

.ticker-item {
    display: flex;
    gap: var(--space-2);
    white-space: nowrap;
    color: var(--text-secondary);
}

.ticker-item strong {
    color: var(--text-primary);
}

.ticker-change {
    font-weight: var(--font-semibold);
}

.ticker-change.up {
    color: var(--color-success);
}

.ticker-change.down {
    color: var(--color-error);
}

/* ============================================================================
   UPTIME / RELIABILITY INDICATOR
   ============================================================================ */

.uptime-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    background: var(--surface-raised);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    padding: var(--space-2) var(--space-5);
}

.uptime-indicator {
    width: 10px;
    height: 10px;
    background: var(--color-success);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--color-success);
    animation: pulse 2s infinite;
}

.uptime-text {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.uptime-text strong {
    color: var(--color-success);
    font-weight: var(--font-bold);
}

/* ============================================================================
   LATENCY COMPARISON BAR
   ============================================================================ */

.latency-compare {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.latency-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.latency-label {
    width: 100px;
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-align: right;
}

.latency-bar-container {
    flex: 1;
    height: 24px;
    background: var(--surface-dark);
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
}

.latency-bar {
    height: 100%;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    padding: 0 var(--space-3);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--text-inverse);
    transition: width 1s ease-out;
}

.latency-bar.fast {
    background: linear-gradient(90deg, var(--brand-accent), var(--brand-secondary));
}

.latency-bar.slow {
    background: linear-gradient(90deg, var(--color-error), #ff7676);
}

.latency-value {
    font-size: var(--text-sm);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    width: 80px;
    text-align: right;
}

/* ============================================================================
   CODE BLOCK - Terminal Style
   ============================================================================ */

.code-block {
    background: #0d1117;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.code-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--border-subtle);
}

.code-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.code-dot.red { background: #ff5f56; }
.code-dot.yellow { background: #ffbd2e; }
.code-dot.green { background: #27ca40; }

.code-title {
    margin-left: var(--space-3);
    font-size: var(--text-sm);
    color: var(--text-dim);
    font-family: var(--font-mono);
}

.code-content {
    padding: var(--space-6);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: var(--leading-loose);
    overflow-x: auto;
    color: var(--text-secondary);
}

.code-content .comment { color: #6a737d; }
.code-content .keyword { color: #ff7b72; }
.code-content .function { color: #d2a8ff; }
.code-content .string { color: #a5d6ff; }
.code-content .number { color: #79c0ff; }
.code-content .type { color: #7ee787; }

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 1024px) {
    .stack-grid {
        grid-template-columns: 1fr;
    }

    .stats-bar {
        gap: var(--space-10);
    }

    .stat-item::after {
        display: none;
    }
}

@media (max-width: 768px) {
    .flow-pipeline {
        flex-direction: column;
    }

    .flow-arrow {
        width: 2px;
        height: 30px;
        background: linear-gradient(
            180deg,
            var(--border-subtle),
            var(--brand-accent),
            var(--border-subtle)
        );
    }

    .flow-arrow::after {
        right: auto;
        left: -5px;
        top: auto;
        bottom: -8px;
        border-left: 6px solid transparent;
        border-right: 6px solid transparent;
        border-top: 10px solid var(--brand-accent);
    }

    .stat-value {
        font-size: var(--text-4xl);
    }

    .live-ticker {
        font-size: var(--text-xs);
    }
}
