/* ============================================
   STATS DIAGNOSIS - The Stroke Saver Narrative

   Premium sports analytics aesthetic inspired by
   ESPN broadcast graphics + Bloomberg terminal

   Design Philosophy:
   - Tell a story, not a data dump
   - Hierarchy: Grade → Diagnosis → Pillars → Details
   - Color communicates performance instantly
   ============================================ */

/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
    /* Performance colors */
    --stats-elite: #10b981;
    --stats-strong: #22c55e;
    --stats-average: #6b7280;
    --stats-below: #f59e0b;
    --stats-needs-work: #ef4444;

    /* Semantic colors */
    --stats-positive: #22c55e;
    --stats-negative: #ef4444;
    --stats-neutral: #6b7280;

    /* Grade colors */
    --grade-a: #10b981;
    --grade-b: #22c55e;
    --grade-c: #6b7280;
    --grade-d: #f59e0b;
    --grade-f: #ef4444;

    /* Pillar accent colors */
    --pillar-finishing: #22c55e;
    --pillar-attacking: #3b82f6;
    --pillar-surviving: #f59e0b;
}

/* ============================================
   MAIN CONTAINER
   ============================================ */
.stats-diagnosis {
    background: var(--surface-0);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    padding: 1.25rem;
    margin-top: 1rem;
}

/* ============================================
   HEADER
   ============================================ */
.stats-diagnosis__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.stats-diagnosis__title-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.stats-diagnosis__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--theme-text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stats-diagnosis__title i {
    color: var(--pillar-attacking);
}

.stats-diagnosis__rounds {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--theme-muted);
    background: var(--surface-1);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}

.stats-diagnosis__cohort {
    font-size: 0.75rem;
    color: var(--theme-muted);
}

/* ============================================
   GRADE SECTION - The Hero
   ============================================ */
.stats-diagnosis__grade-section {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, var(--surface-1), var(--surface-0));
    border-radius: 10px;
    margin-bottom: 1rem;
}

.stats-diagnosis__grade {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 900;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.stats-diagnosis__grade--a { background: linear-gradient(135deg, var(--grade-a), #059669); }
.stats-diagnosis__grade--b { background: linear-gradient(135deg, var(--grade-b), #16a34a); }
.stats-diagnosis__grade--c { background: linear-gradient(135deg, var(--grade-c), #4b5563); }
.stats-diagnosis__grade--d { background: linear-gradient(135deg, var(--grade-d), #d97706); }
.stats-diagnosis__grade--f { background: linear-gradient(135deg, var(--grade-f), #dc2626); }

.stats-diagnosis__grade-letter {
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.stats-diagnosis__grade-context {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.stats-diagnosis__grade-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--theme-text);
}

.stats-diagnosis__grade-desc {
    font-size: 0.8rem;
    color: var(--theme-muted);
}

/* ============================================
   DIAGNOSTIC INSIGHT
   ============================================ */
.stats-diagnosis__insight {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    line-height: 1.4;
}

.stats-diagnosis__insight i {
    font-size: 1rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.stats-diagnosis__insight--opportunity {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.25);
    color: var(--theme-text);
}

.stats-diagnosis__insight--opportunity i {
    color: #f59e0b;
}

.stats-diagnosis__insight--strength {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.25);
    color: var(--theme-text);
}

.stats-diagnosis__insight--strength i {
    color: #22c55e;
}

.stats-diagnosis__insight--neutral {
    background: rgba(107, 114, 128, 0.1);
    border: 1px solid rgba(107, 114, 128, 0.2);
    color: var(--theme-muted);
}

.stats-diagnosis__insight--neutral i {
    color: #6b7280;
}

/* ============================================
   THREE PILLARS
   ============================================ */
.stats-diagnosis__pillars {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

/* Individual Pillar Card */
.stats-pillar {
    background: var(--surface-1);
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
}

.stats-pillar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--stats-neutral);
    transition: background 0.2s ease;
}

/* Performance-based top border */
.stats-pillar--elite::before { background: var(--stats-elite); }
.stats-pillar--strong::before { background: var(--stats-strong); }
.stats-pillar--average::before { background: var(--stats-average); }
.stats-pillar--below-average::before { background: var(--stats-below); }
.stats-pillar--needs-work::before { background: var(--stats-needs-work); }

.stats-pillar:hover {
    border-color: var(--theme-muted);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

/* Pillar Header */
.stats-pillar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stats-pillar__name {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--theme-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stats-pillar__name i {
    font-size: 0.7rem;
}

/* Pillar-specific icon colors */
.stats-pillar:nth-child(1) .stats-pillar__name i { color: var(--pillar-finishing); }
.stats-pillar:nth-child(2) .stats-pillar__name i { color: var(--pillar-attacking); }
.stats-pillar:nth-child(3) .stats-pillar__name i { color: var(--pillar-surviving); }

/* Trend indicator */
.stats-pillar__trend {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
}

.stats-pillar__trend--improving {
    background: rgba(34, 197, 94, 0.15);
    color: var(--stats-positive);
}

.stats-pillar__trend--declining {
    background: rgba(239, 68, 68, 0.15);
    color: var(--stats-negative);
}

.stats-pillar__trend--stable {
    background: rgba(107, 114, 128, 0.1);
    color: var(--stats-neutral);
}

/* Hero Stat */
.stats-pillar__hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 0;
}

.stats-pillar__value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--theme-text);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.stats-pillar__label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--theme-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

/* Regional Comparison */
.stats-pillar__comparison {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    margin: 0 auto;
}

.stats-pillar__comparison--above {
    background: rgba(34, 197, 94, 0.12);
    color: var(--stats-positive);
}

.stats-pillar__comparison--below {
    background: rgba(239, 68, 68, 0.12);
    color: var(--stats-negative);
}

.stats-pillar__comparison--neutral {
    background: rgba(107, 114, 128, 0.1);
    color: var(--stats-neutral);
}

/* Secondary Stat */
.stats-pillar__secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--surface-border);
    margin-top: 0.25rem;
}

.stats-pillar__secondary-label {
    font-size: 0.7rem;
    color: var(--theme-muted);
}

.stats-pillar__secondary-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--theme-text);
}

.stats-pillar__secondary-delta {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.1rem 0.25rem;
    border-radius: 3px;
}

.stats-pillar__secondary-delta--above {
    background: rgba(34, 197, 94, 0.12);
    color: var(--stats-positive);
}

.stats-pillar__secondary-delta--below {
    background: rgba(239, 68, 68, 0.12);
    color: var(--stats-negative);
}

/* Sparkline */
.stats-pillar__sparkline {
    margin-top: 0.25rem;
    padding-top: 0.5rem;
}

.stats-pillar__sparkline-svg {
    width: 100%;
    height: 60px;
    display: block;
}

.stats-pillar__sparkline-area {
    fill: rgba(59, 130, 246, 0.1);
}

.stats-pillar__sparkline-line {
    fill: none;
    stroke: var(--pillar-attacking);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.stats-pillar__sparkline-dot {
    fill: var(--surface-0);
    stroke: var(--pillar-attacking);
    stroke-width: 1.5;
}

/* Sparkline colors per pillar */
.stats-pillar:nth-child(1) .stats-pillar__sparkline-area { fill: rgba(34, 197, 94, 0.1); }
.stats-pillar:nth-child(1) .stats-pillar__sparkline-line { stroke: var(--pillar-finishing); }
.stats-pillar:nth-child(1) .stats-pillar__sparkline-dot { stroke: var(--pillar-finishing); }

.stats-pillar:nth-child(2) .stats-pillar__sparkline-area { fill: rgba(59, 130, 246, 0.1); }
.stats-pillar:nth-child(2) .stats-pillar__sparkline-line { stroke: var(--pillar-attacking); }
.stats-pillar:nth-child(2) .stats-pillar__sparkline-dot { stroke: var(--pillar-attacking); }

.stats-pillar:nth-child(3) .stats-pillar__sparkline-area { fill: rgba(245, 158, 11, 0.1); }
.stats-pillar:nth-child(3) .stats-pillar__sparkline-line { stroke: var(--pillar-surviving); }
.stats-pillar:nth-child(3) .stats-pillar__sparkline-dot { stroke: var(--pillar-surviving); }

.stats-pillar__sparkline-label {
    display: block;
    text-align: center;
    font-size: 0.6rem;
    color: var(--theme-muted);
    margin-top: 0.25rem;
    opacity: 0.7;
}

/* Sample Size */
.stats-pillar__sample {
    text-align: center;
    font-size: 0.7rem;
    color: var(--theme-muted);
    opacity: 0.8;
}

/* ============================================
   DETAILS SECTION (Expandable)
   ============================================ */
.stats-diagnosis__details {
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    overflow: hidden;
}

.stats-diagnosis__details-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--theme-muted);
    cursor: pointer;
    background: var(--surface-1);
    transition: all 0.2s ease;
    list-style: none;
}

.stats-diagnosis__details-toggle::-webkit-details-marker {
    display: none;
}

.stats-diagnosis__details-toggle:hover {
    background: var(--surface-2, var(--surface-1));
    color: var(--theme-text);
}

.stats-diagnosis__details-toggle i {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.stats-diagnosis__details[open] .stats-diagnosis__details-toggle i {
    transform: rotate(180deg);
}

.stats-diagnosis__details-content {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Detail Groups */
.stats-diagnosis__detail-group h5 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--theme-text);
    margin: 0 0 0.5rem 0;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.stats-diagnosis__detail-group h5 i {
    font-size: 0.75rem;
    color: var(--pillar-attacking);
}

.stats-diagnosis__detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.stats-diagnosis__detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--surface-1);
    border-radius: 6px;
}

.stats-diagnosis__detail-item .label {
    font-size: 0.75rem;
    color: var(--theme-muted);
}

.stats-diagnosis__detail-item .value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--theme-text);
}

.stats-diagnosis__detail-item--highlight {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(251, 191, 36, 0.05));
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.stats-diagnosis__detail-item--highlight .value {
    color: #f59e0b;
}

/* Windows Table */
.stats-diagnosis__windows-table {
    font-size: 0.8rem;
    background: var(--surface-1);
    border-radius: 8px;
    overflow: hidden;
}

.stats-diagnosis__windows-header {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr 1fr;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    background: var(--surface-2, rgba(255,255,255,0.03));
    font-weight: 600;
    color: var(--theme-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.stats-diagnosis__windows-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr 1fr;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--surface-border);
    align-items: center;
}

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

.stats-diagnosis__windows-row .window-label {
    font-weight: 600;
    color: var(--theme-muted);
    font-size: 0.75rem;
}

.stats-diagnosis__windows-row > span:not(.window-label) {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    font-weight: 600;
    color: var(--theme-text);
}

.stats-diagnosis__windows-row .stats-diagnosis__delta.delta--up {
    color: var(--stats-positive) !important;
}

.stats-diagnosis__windows-row .stats-diagnosis__delta.delta--down {
    color: var(--stats-negative) !important;
}

/* Delta indicators */
.stats-diagnosis__delta {
    font-size: 0.65rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
}

.stats-diagnosis__delta.delta--up {
    color: var(--stats-positive);
}

.stats-diagnosis__delta.delta--down {
    color: var(--stats-negative);
}

/* ============================================
   DATA QUALITY CAVEAT
   ============================================ */
.stats-diagnosis__caveat {
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.12);
    font-size: 0.75rem;
    color: var(--theme-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stats-diagnosis__caveat i {
    color: #3b82f6;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .stats-diagnosis__pillars {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .stats-pillar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 0.75rem;
    }

    .stats-pillar__header {
        width: 100%;
        margin-bottom: 0.25rem;
    }

    .stats-pillar__hero {
        flex-direction: row;
        align-items: baseline;
        gap: 0.25rem;
        padding: 0;
    }

    .stats-pillar__value {
        font-size: 1.5rem;
    }

    .stats-pillar__comparison {
        margin: 0;
        margin-left: 0.5rem;
    }

    .stats-pillar__secondary {
        border-top: none;
        padding-top: 0;
        margin-top: 0;
        margin-left: auto;
    }

    .stats-pillar__sparkline {
        width: 100%;
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid var(--surface-border);
    }

    .stats-pillar__sample {
        position: absolute;
        top: 0.5rem;
        right: 0.75rem;
        font-size: 0.65rem;
    }

    .stats-diagnosis__grade-section {
        padding: 0.75rem;
    }

    .stats-diagnosis__grade {
        width: 52px;
        height: 52px;
        font-size: 1.5rem;
    }

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

    .stats-diagnosis__windows-header,
    .stats-diagnosis__windows-row {
        grid-template-columns: 1.4fr 1fr 1fr 1fr;
        font-size: 0.7rem;
        gap: 0.25rem;
        padding: 0.5rem;
    }

    .stats-diagnosis__windows-header {
        font-size: 0.6rem;
    }

    .stats-diagnosis__delta {
        font-size: 0.6rem;
    }
}

/* ============================================
   DARK MODE ENHANCEMENTS
   ============================================ */
.dark-theme .stats-diagnosis {
    background: linear-gradient(145deg, var(--surface-0), rgba(0, 0, 0, 0.3));
}

.dark-theme .stats-diagnosis__grade {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.dark-theme .stats-pillar {
    background: rgba(255, 255, 255, 0.02);
}

.dark-theme .stats-pillar:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stats-diagnosis__grade-section {
    animation: fadeInUp 0.4s ease-out;
}

.stats-diagnosis__insight {
    animation: fadeInUp 0.4s ease-out 0.1s both;
}

.stats-pillar:nth-child(1) { animation: fadeInUp 0.4s ease-out 0.2s both; }
.stats-pillar:nth-child(2) { animation: fadeInUp 0.4s ease-out 0.3s both; }
.stats-pillar:nth-child(3) { animation: fadeInUp 0.4s ease-out 0.4s both; }
