<?php
session_start();
require_once '../config/database.php';
require_once '../includes/functions.php';

$current_year = date('Y');
$error = '';

// Lae üldstatistika
try {
    // Põhinumbrid
    $stmt = $pdo->prepare("SELECT COUNT(*) as count FROM users WHERE role = 'athlete' AND isActive = 1");
    $stmt->execute();
    $total_athletes = $stmt->fetch()['count'];
    
    $stmt = $pdo->prepare("SELECT COUNT(*) as count FROM competitions WHERE strftime('%Y', date) = ?");
    $stmt->execute([$current_year]);
    $total_competitions = $stmt->fetch()['count'];
    
    $stmt = $pdo->prepare("
        SELECT COUNT(*) as count 
        FROM results r 
        JOIN competitions c ON r.competitionId = c.id 
        WHERE strftime('%Y', c.date) = ?
    ");
    $stmt->execute([$current_year]);
    $total_results = $stmt->fetch()['count'];
    
    // Distsipliinide jaotus
    $stmt = $pdo->prepare("
        SELECT 
            r.discipline,
            COUNT(*) as count,
            AVG(r.points) as avg_points,
            MAX(r.points) as max_points
        FROM results r
        JOIN competitions c ON r.competitionId = c.id
        WHERE strftime('%Y', c.date) = ?
        GROUP BY r.discipline
        ORDER BY count DESC
    ");
    $stmt->execute([$current_year]);
    $discipline_stats = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    // Kuude aktiivsus
    $stmt = $pdo->prepare("
        SELECT 
            strftime('%m', c.date) as month,
            strftime('%Y-%m', c.date) as year_month,
            COUNT(DISTINCT c.id) as competitions,
            COUNT(r.id) as results
        FROM competitions c
        LEFT JOIN results r ON c.id = r.competitionId
        WHERE strftime('%Y', c.date) = ?
        GROUP BY strftime('%Y-%m', c.date)
        ORDER BY year_month
    ");
    $stmt->execute([$current_year]);
    $monthly_activity = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    // TOP võistlused (enim osalejaid)
    $stmt = $pdo->prepare("
        SELECT 
            c.name,
            c.date,
            c.location,
            c.discipline,
            COUNT(r.id) as participants
        FROM competitions c
        LEFT JOIN results r ON c.id = r.competitionId
        WHERE strftime('%Y', c.date) = ?
        GROUP BY c.id
        ORDER BY participants DESC, c.date DESC
        LIMIT 5
    ");
    $stmt->execute([$current_year]);
    $top_competitions = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    // Vanusegruppide jaotus
    $stmt = $pdo->prepare("
        SELECT 
            u.birthDate,
            COUNT(r.id) as results_count,
            AVG(r.points) as avg_points
        FROM users u
        JOIN results r ON u.id = r.userId
        JOIN competitions c ON r.competitionId = c.id
        WHERE u.isActive = 1 AND strftime('%Y', c.date) = ?
        GROUP BY u.id
    ");
    $stmt->execute([$current_year]);
    $user_stats = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    $age_groups = ['noored' => 0, 'täiskasvanud' => 0];
    foreach ($user_stats as $user) {
        $age_group = getAgeGroup($user['birthDate'], $current_year);
        if (isset($age_groups[$age_group])) {
            $age_groups[$age_group]++;
        }
    }
    
    // Punktide jaotus
    $stmt = $pdo->prepare("
        SELECT 
            CASE 
                WHEN r.points >= 10 THEN '10+'
                WHEN r.points >= 5 THEN '5-9.9'
                WHEN r.points >= 1 THEN '1-4.9'
                ELSE '0-0.9'
            END as point_range,
            COUNT(*) as count
        FROM results r
        JOIN competitions c ON r.competitionId = c.id
        WHERE strftime('%Y', c.date) = ?
        GROUP BY point_range
        ORDER BY MIN(r.points) DESC
    ");
    $stmt->execute([$current_year]);
    $point_distribution = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
} catch(PDOException $e) {
    $error = 'Statistika laadimine ebaõnnestus: ' . $e->getMessage();
    error_log('Stats error: ' . $e->getMessage());
}

$page_title = 'Statistika ja analüüs';
$page_description = 'Estreka Ratsaklubi hooaja statistika, graafikud ja analüüs.';

include '../includes/header.php';
?>

<main class="stats-main">
    <div class="container">
        <!-- Header -->
        <div class="page-header">
            <div class="page-header-content">
                <h1 class="page-title">Hooaja statistika</h1>
                <p class="page-subtitle">
                    Põhjalik ülevaade <?php echo $current_year; ?>. aasta tulemustest ja trendidest
                </p>
            </div>
            <div class="stats-info">
                <div class="info-badge">
                    <i class="icon-bar-chart"></i>
                    <span>Reaalajas andmed</span>
                </div>
            </div>
        </div>

        <?php if ($error): ?>
            <div class="alert alert-error">
                <i class="icon-alert-circle"></i>
                <span><?php echo htmlspecialchars($error); ?></span>
            </div>
        <?php else: ?>

        <!-- Üldstatistika -->
        <div class="overview-stats">
            <div class="stats-grid">
                <div class="stat-card">
                    <div class="stat-icon">
                        <i class="icon-users"></i>
                    </div>
                    <div class="stat-content">
                        <div class="stat-number"><?php echo $total_athletes; ?></div>
                        <div class="stat-label">Aktiivset sportlast</div>
                    </div>
                </div>

                <div class="stat-card">
                    <div class="stat-icon">
                        <i class="icon-calendar"></i>
                    </div>
                    <div class="stat-content">
                        <div class="stat-number"><?php echo $total_competitions; ?></div>
                        <div class="stat-label">Võistlusel osaletud</div>
                    </div>
                </div>

                <div class="stat-card">
                    <div class="stat-icon">
                        <i class="icon-trophy"></i>
                    </div>
                    <div class="stat-content">
                        <div class="stat-number"><?php echo $total_results; ?></div>
                        <div class="stat-label">Starti tehtu</div>
                    </div>
                </div>

                <div class="stat-card">
                    <div class="stat-icon">
                        <i class="icon-trending-up"></i>
                    </div>
                    <div class="stat-content">
                        <div class="stat-number">
                            <?php echo $total_athletes > 0 ? round($total_results / $total_athletes, 1) : 0; ?>
                        </div>
                        <div class="stat-label">Starti sportlase kohta</div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Põhianalüüs -->
        <div class="analysis-grid">
            <!-- Distsipliinide statistika -->
            <div class="analysis-card">
                <div class="card-header">
                    <h2 class="card-title">
                        <i class="icon-pie-chart"></i>
                        Distsipliinide jaotus
                    </h2>
                </div>
                <div class="card-content">
                    <?php if (empty($discipline_stats)): ?>
                        <div class="no-data">
                            <div class="no-data-icon">
                                <i class="icon-info"></i>
                            </div>
                            <p>Andmeid ei ole veel saadaval</p>
                        </div>
                    <?php else: ?>
                        <div class="discipline-chart">
                            <?php foreach ($discipline_stats as $stat): ?>
                                <div class="discipline-bar">
                                    <div class="discipline-info">
                                        <div class="discipline-name">
                                            <?php echo getDisciplineName($stat['discipline']); ?>
                                        </div>
                                        <div class="discipline-numbers">
                                            <span class="count"><?php echo $stat['count']; ?> tulemust</span>
                                            <span class="avg">Ø <?php echo formatPoints($stat['avg_points']); ?>p</span>
                                        </div>
                                    </div>
                                    <div class="bar-container">
                                        <div class="bar-fill <?php echo $stat['discipline']; ?>" 
                                             style="width: <?php echo ($stat['count'] / max(array_column($discipline_stats, 'count'))) * 100; ?>%">
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>

            <!-- Kuine aktiivsus -->
            <div class="analysis-card">
                <div class="card-header">
                    <h2 class="card-title">
                        <i class="icon-bar-chart"></i>
                        Kuine aktiivsus
                    </h2>
                </div>
                <div class="card-content">
                    <?php if (empty($monthly_activity)): ?>
                        <div class="no-data">
                            <div class="no-data-icon">
                                <i class="icon-info"></i>
                            </div>
                            <p>Andmeid ei ole veel saadaval</p>
                        </div>
                    <?php else: ?>
                        <div class="monthly-chart">
                            <?php 
                            $months = ['01' => 'Jan', '02' => 'Veeb', '03' => 'Märts', '04' => 'Apr', 
                                      '05' => 'Mai', '06' => 'Juuni', '07' => 'Juuli', '08' => 'Aug',
                                      '09' => 'Sept', '10' => 'Okt', '11' => 'Nov', '12' => 'Dets'];
                            $max_results = max(array_column($monthly_activity, 'results'));
                            
                            foreach ($monthly_activity as $month): 
                            ?>
                                <div class="month-bar">
                                    <div class="month-data">
                                        <div class="month-results" 
                                             style="height: <?php echo $max_results > 0 ? ($month['results'] / $max_results) * 100 : 0; ?>%">
                                        </div>
                                    </div>
                                    <div class="month-label">
                                        <?php echo $months[$month['month']]; ?>
                                    </div>
                                    <div class="month-count">
                                        <?php echo $month['results']; ?>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <!-- Täiendav analüüs -->
        <div class="detailed-analysis">
            <!-- TOP võistlused -->
            <div class="analysis-card">
                <div class="card-header">
                    <h2 class="card-title">
                        <i class="icon-star"></i>
                        Populaarsemad võistlused
                    </h2>
                </div>
                <div class="card-content">
                    <?php if (empty($top_competitions)): ?>
                        <div class="no-data">
                            <div class="no-data-icon">
                                <i class="icon-info"></i>
                            </div>
                            <p>Andmeid ei ole veel saadaval</p>
                        </div>
                    <?php else: ?>
                        <div class="competitions-list">
                            <?php foreach ($top_competitions as $index => $comp): ?>
                                <div class="competition-item">
                                    <div class="competition-rank">
                                        <?php echo $index + 1; ?>.
                                    </div>
                                    <div class="competition-info">
                                        <div class="competition-name">
                                            <?php echo htmlspecialchars($comp['name']); ?>
                                        </div>
                                        <div class="competition-meta">
                                            <span><?php echo formatDate($comp['date']); ?></span>
                                            <?php if ($comp['location']): ?>
                                                • <span><?php echo htmlspecialchars($comp['location']); ?></span>
                                            <?php endif; ?>
                                            • <span><?php echo getDisciplineName($comp['discipline']); ?></span>
                                        </div>
                                    </div>
                                    <div class="competition-participants">
                                        <div class="participants-count">
                                            <?php echo $comp['participants']; ?>
                                        </div>
                                        <div class="participants-label">Starti</div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>

            <!-- Vanusegruppide jaotus -->
            <div class="analysis-card">
                <div class="card-header">
                    <h2 class="card-title">
                        <i class="icon-users"></i>
                        Vanusegruppide jaotus
                    </h2>
                </div>
                <div class="card-content">
                    <div class="age-groups">
                        <?php foreach ($age_groups as $group => $count): ?>
                            <div class="age-group">
                                <div class="age-group-header">
                                    <div class="age-group-name">
                                        <?php echo getAgeGroupName($group); ?>
                                    </div>
                                    <div class="age-group-count">
                                        <?php echo $count; ?> sportlast
                                    </div>
                                </div>
                                <div class="age-group-bar">
                                    <div class="age-bar-fill" 
                                         style="width: <?php echo array_sum($age_groups) > 0 ? ($count / array_sum($age_groups)) * 100 : 0; ?>%">
                                    </div>
                                </div>
                                <div class="age-group-percentage">
                                    <?php echo array_sum($age_groups) > 0 ? round(($count / array_sum($age_groups)) * 100) : 0; ?>%
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>

            <!-- Punktide jaotus -->
            <div class="analysis-card">
                <div class="card-header">
                    <h2 class="card-title">
                        <i class="icon-award"></i>
                        Punktide jaotus
                    </h2>
                </div>
                <div class="card-content">
                    <?php if (empty($point_distribution)): ?>
                        <div class="no-data">
                            <div class="no-data-icon">
                                <i class="icon-info"></i>
                            </div>
                            <p>Andmeid ei ole veel saadaval</p>
                        </div>
                    <?php else: ?>
                        <div class="points-distribution">
                            <?php 
                            $total_points = array_sum(array_column($point_distribution, 'count'));
                            foreach ($point_distribution as $range): 
                            ?>
                                <div class="points-range">
                                    <div class="range-label">
                                        <?php echo $range['point_range']; ?> punkti
                                    </div>
                                    <div class="range-bar">
                                        <div class="range-fill" 
                                             style="width: <?php echo $total_points > 0 ? ($range['count'] / $total_points) * 100 : 0; ?>%">
                                        </div>
                                    </div>
                                    <div class="range-count">
                                        <?php echo $range['count']; ?> 
                                        (<?php echo $total_points > 0 ? round(($range['count'] / $total_points) * 100) : 0; ?>%)
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <!-- CTA Section -->
        <div class="cta-section">
            <div class="cta-card">
                <div class="cta-content">
                    <h2>Osale ka sina!</h2>
                    <p>Liitu Estreka Ratsaklubiga ja jälgi oma progressi hooaja jooksul.</p>
                    <div class="cta-actions">
                        <?php if (isLoggedIn()): ?>
                            <?php if (isAthlete()): ?>
                                <a href="<?php echo url('athlete/dashboard.php'); ?>" class="btn btn-primary">
                                    <i class="icon-user"></i>
                                    <span>Minu armatuurlaud</span>
                                </a>
                            <?php endif; ?>
                            <a href="<?php echo url('public/rankings.php'); ?>" class="btn btn-outline">
                                <i class="icon-list"></i>
                                <span>Vaata tabeleid</span>
                            </a>
                        <?php else: ?>
                            <a href="<?php echo url('register.php'); ?>" class="btn btn-primary">
                                <i class="icon-user"></i>
                                <span>Registreeru</span>
                            </a>
                            <a href="<?php echo url('login.php'); ?>" class="btn btn-outline">
                                <i class="icon-log-in"></i>
                                <span>Logi sisse</span>
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <?php endif; ?>
    </div>
</main>

<style>
/* Public Stats Page Styles - TÄIELIK CSS LISATUD */
.stats-main {
    padding: var(--spacing-8) 0;
    min-height: 100vh;
    background: var(--gray-50);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: var(--spacing-8);
    gap: var(--spacing-4);
}

.page-title {
    margin-bottom: var(--spacing-2);
    color: var(--gray-900);
}

.page-subtitle {
    color: var(--gray-600);
    font-size: var(--font-size-lg);
    margin: 0;
}

.stats-info {
    flex-shrink: 0;
}

.info-badge {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
    padding: var(--spacing-3) var(--spacing-4);
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--success-color);
}

.info-badge i {
    color: var(--success-color);
}

.info-badge span {
    color: var(--success-color);
    font-weight: 500;
    font-size: var(--font-size-sm);
}

/* Overview Stats */
.overview-stats {
    margin-bottom: var(--spacing-8);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-6);
}

.stat-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: var(--spacing-6);
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
    transition: transform var(--transition-fast);
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-number {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1;
}

.stat-label {
    color: var(--gray-600);
    font-size: var(--font-size-sm);
    margin-top: var(--spacing-1);
}

/* Analysis Grid */
.analysis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--spacing-6);
    margin-bottom: var(--spacing-8);
}

.detailed-analysis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: var(--spacing-6);
    margin-bottom: var(--spacing-8);
}

/* Analysis Cards */
.analysis-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: var(--spacing-5) var(--spacing-6);
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.card-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
    margin: 0;
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--gray-900);
}

.card-title i {
    color: var(--primary-color);
}

.card-content {
    padding: var(--spacing-6);
}

/* No Data State */
.no-data {
    text-align: center;
    padding: var(--spacing-8) var(--spacing-4);
    color: var(--gray-500);
}

.no-data-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--spacing-4);
    background: var(--gray-100);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.no-data p {
    margin: 0;
    font-size: var(--font-size-sm);
}

/* Discipline Chart */
.discipline-chart {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
}

.discipline-bar {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
}

.discipline-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.discipline-name {
    font-weight: 500;
    color: var(--gray-900);
}

.discipline-numbers {
    display: flex;
    gap: var(--spacing-3);
    font-size: var(--font-size-sm);
}

.count {
    color: var(--gray-600);
}

.avg {
    color: var(--primary-color);
    font-weight: 500;
}

.bar-container {
    height: 8px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.8s ease;
}

.bar-fill.koolisoit { background: linear-gradient(90deg, var(--primary-color), var(--primary-light)); }
.bar-fill.takistussoit { background: linear-gradient(90deg, var(--success-color), #10b981); }
.bar-fill.kestvusratsutamine { background: linear-gradient(90deg, #8b5cf6, #a855f7); }

/* Monthly Chart */
.monthly-chart {
    display: flex;
    align-items: end;
    gap: var(--spacing-3);
    height: 150px;
    padding: var(--spacing-4) 0;
}

.month-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-2);
    height: 100%;
}

.month-data {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: end;
}

.month-results {
    width: 100%;
    background: linear-gradient(to top, var(--primary-color), var(--primary-light));
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    min-height: 4px;
    transition: height 0.8s ease;
}

.month-label {
    font-size: var(--font-size-xs);
    color: var(--gray-600);
    font-weight: 500;
}

.month-count {
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    font-weight: 600;
}

/* Competitions List */
.competitions-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
}

.competition-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
    padding: var(--spacing-4);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    transition: all var(--transition-fast);
}

.competition-item:hover {
    border-color: var(--primary-color);
    background: var(--gray-50);
}

.competition-rank {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--primary-color);
    min-width: 24px;
}

.competition-info {
    flex: 1;
}

.competition-name {
    font-weight: 500;
    color: var(--gray-900);
    margin-bottom: var(--spacing-1);
}

.competition-meta {
    font-size: var(--font-size-sm);
    color: var(--gray-600);
}

.competition-participants {
    text-align: center;
}

.participants-count {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--primary-color);
}

.participants-label {
    font-size: var(--font-size-xs);
    color: var(--gray-600);
}

/* Age Groups */
.age-groups {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
}

.age-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
}

.age-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.age-group-name {
    font-weight: 500;
    color: var(--gray-900);
}

.age-group-count {
    font-size: var(--font-size-sm);
    color: var(--gray-600);
}

.age-group-bar {
    height: 8px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.age-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), #10b981);
    border-radius: var(--radius-full);
    transition: width 0.8s ease;
}

.age-group-percentage {
    font-size: var(--font-size-sm);
    color: var(--primary-color);
    font-weight: 500;
    text-align: right;
}

/* Points Distribution */
.points-distribution {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-3);
}

.points-range {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
}

.range-label {
    min-width: 80px;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--gray-700);
}

.range-bar {
    flex: 1;
    height: 6px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.range-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--warning-color), #f59e0b);
    border-radius: var(--radius-full);
    transition: width 0.8s ease;
}

.range-count {
    min-width: 80px;
    text-align: right;
    font-size: var(--font-size-sm);
    color: var(--gray-600);
}

/* CTA Section */
.cta-section {
    margin-top: var(--spacing-12);
}

.cta-card {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.cta-content {
    padding: var(--spacing-8);
    text-align: center;
}

.cta-content h2 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    margin-bottom: var(--spacing-4);
}

.cta-content p {
    font-size: var(--font-size-lg);
    opacity: 0.9;
    margin-bottom: var(--spacing-6);
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.cta-actions {
    display: flex;
    gap: var(--spacing-4);
    justify-content: center;
    flex-wrap: wrap;
}

.btn-outline {
    background: transparent;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
    color: white;
}

/* Responsive */
@media (max-width: 1024px) {
    .analysis-grid {
        grid-template-columns: 1fr;
    }
    
    .detailed-analysis {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-4);
        text-align: center;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .monthly-chart {
        gap: var(--spacing-2);
    }
    
    .competition-item {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-3);
    }
    
    .competition-rank {
        align-self: center;
    }
    
    .cta-actions {
        flex-direction: column;
        align-items: center;
    }
    
    .cta-content {
        padding: var(--spacing-6);
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .points-range {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-2);
    }
    
    .range-label,
    .range-count {
        min-width: auto;
    }
}
</style>

<?php include '../includes/footer.php'; ?>