/* ============================================
   ANALYTICS PAGE STYLES
   ============================================ */

/* Time Period Selector */
.time-period-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.period-btn {
    padding: 0.5rem 1rem;
    background: var(--card-bg);
    border: 2px solid rgba(74, 124, 184, 0.6);
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.period-btn:hover {
    border-color: rgba(74, 124, 184, 0.9);
    color: var(--text-primary);
}

.period-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}

/* Stats Overview Grid */
.stats-overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.analytics-stat-card {
    background: var(--card-bg);
    border: 1px solid rgba(74, 124, 184, 0.2);
    border-radius: 12px;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.analytics-stat-card:hover {
    border-color: rgba(74, 124, 184, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.analytics-stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--accent-primary), rgba(138, 92, 246, 0.5));
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(74, 124, 184, 0.2), rgba(138, 92, 246, 0.2));
}

.stat-change {
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stat-change.positive {
    background: rgba(16, 185, 129, 0.15);
    color: #10B981;
}

.stat-change.negative {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.stat-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--card-bg);
    border: 1px solid rgba(74, 124, 184, 0.2);
    border-radius: 12px;
    padding: 1.5rem;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.chart-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.chart-legend {
    display: flex;
    gap: 1.5rem;
    font-size: 0.85rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
}

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

/* Performance Chart */
.performance-chart {
    height: 300px;
    position: relative;
}

.chart-canvas {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 1rem 0;
}

.chart-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.chart-bars {
    width: 100%;
    display: flex;
    gap: 0.25rem;
    align-items: flex-end;
    height: 250px;
}

.chart-bar {
    flex: 1;
    background: linear-gradient(180deg, var(--accent-primary) 0%, rgba(74, 124, 184, 0.5) 100%);
    border-radius: 4px 4px 0 0;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.chart-bar:hover {
    filter: brightness(1.2);
}

.chart-bar.wins {
    background: linear-gradient(180deg, #10B981 0%, rgba(16, 185, 129, 0.5) 100%);
}

.chart-bar.losses {
    background: linear-gradient(180deg, #EF4444 0%, rgba(239, 68, 68, 0.5) 100%);
}

.chart-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* Donut Chart */
.donut-chart {
    width: 100%;
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.donut-svg {
    width: 200px;
    height: 200px;
}

.donut-segment {
    transition: all 0.3s ease;
    cursor: pointer;
}

.donut-segment:hover {
    opacity: 0.8;
    transform: scale(1.05);
}

.donut-center-text {
    position: absolute;
    text-align: center;
}

.donut-center-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.donut-center-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Realtime Insights */
.realtime-insights {
    margin-bottom: 2rem;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.kpi-card {
    background: var(--card-bg);
    border: 1px solid rgba(74, 124, 184, 0.2);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    transition: border-color 0.3s ease, transform 0.3s ease;
}

.kpi-card:hover { 
    border-color: rgba(74, 124, 184, 0.5);
    transform: translateY(-2px);
}

.kpi-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
}

.kpi-sub {
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Filters Toolbar */
.filters-toolbar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) auto;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1.5rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.filter-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.filter-select {
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid rgba(74, 124, 184, 0.3);
    border-radius: 8px;
    padding: 0.55rem 0.75rem;
    outline: none;
    color-scheme: dark;
}
.filter-select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(138, 92, 246, 0.25);
}

/* Ensure dropdown list uses dark background and readable text */
.filters-toolbar { color-scheme: dark; }
.filter-select option {
    background-color: var(--card-bg) !important;
    color: var(--text-primary) !important;
}
.filter-select option:disabled { color: var(--text-muted) !important; }

/* Custom Select (dark, accessible) */
.custom-select {
    position: relative;
}

.custom-select-button {
    width: 100%;
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid rgba(74, 124, 184, 0.35);
    border-radius: 10px;
    padding: 0.6rem 0.9rem;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    transition: border-color .2s ease, box-shadow .2s ease, transform .06s ease;
}

.custom-select-button:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(138, 92, 246, 0.25);
}

.custom-select-button:hover {
    border-color: rgba(74, 124, 184, 0.6);
}

.custom-select-button:active {
    transform: translateY(1px);
}

.custom-select-button::after {
    content: '\25BE'; /* downwards triangle */
    font-size: 0.9rem;
    color: var(--text-muted);
}

.custom-select-list {
    position: absolute;
    z-index: 50;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 260px;
    overflow: auto;
    /* Solid, opaque dark panel */
    background: var(--dropdown-bg, #0f172a);
    background-color: var(--dropdown-bg, #0f172a);
    border: 1px solid rgba(74, 124, 184, 0.35);
    border-radius: 10px;
    box-shadow: 0 18px 36px rgba(0,0,0,0.45);
    padding: 4px;
    opacity: 0;
    transform: translateY(6px) scale(0.98);
    pointer-events: none;
    transition: opacity .15s ease, transform .15s ease;
    backdrop-filter: none;
}

.custom-select-item {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.custom-select-item[aria-selected="true"] {
    background: rgba(138, 92, 246, 1);
    color: #ffffff;
}

.custom-select-item:hover {
    background: rgba(74, 124, 184, 0.2);
}

.custom-select-item[aria-selected="true"]::after {
    content: '\2713'; /* checkmark */
    color: var(--accent-primary);
    font-size: 0.9rem;
}

.custom-select-hidden {
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 0 !important;
    height: 0 !important;
}

.custom-select.open .custom-select-list {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Scrollbar styling */
.custom-select-list::-webkit-scrollbar { width: 10px; }
.custom-select-list::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 8px; }
.custom-select-list::-webkit-scrollbar-thumb { background: rgba(138,92,246,0.35); border-radius: 8px; }
.custom-select-list { scrollbar-color: rgba(138,92,246,0.35) rgba(255,255,255,0.05); scrollbar-width: thin; }

.filter-checkbox {
    width: 18px;
    height: 18px;
}

.filter-help {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.filter-actions {
    display: flex;
    justify-content: flex-end;
}

.filter-reset {
    padding: 0.5rem 0.9rem;
    background: transparent;
    border: 1px solid rgba(74, 124, 184, 0.4);
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-reset:hover {
    color: var(--text-primary);
    border-color: rgba(74, 124, 184, 0.8);
}

/* Advanced Charts Grid */
.charts-advanced {
    margin-bottom: 2rem;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.chart-card canvas {
    width: 100% !important;
    height: 280px !important;
}

/* Game Performance Table */
.game-performance-section {
    margin-bottom: 2rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.performance-table-container {
    background: var(--card-bg);
    border: 1px solid rgba(74, 124, 184, 0.2);
    border-radius: 12px;
    overflow: hidden;
}

.performance-table {
    width: 100%;
    border-collapse: collapse;
}

.performance-table thead {
    background: rgba(74, 124, 184, 0.15);
}

.performance-table th {
    padding: 1rem;
    text-align: left;
    color: var(--text-primary);
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.performance-table tbody tr {
    border-bottom: 1px solid rgba(74, 124, 184, 0.1);
    transition: all 0.3s ease;
}

.performance-table tbody tr:hover {
    background: rgba(74, 124, 184, 0.1);
}

.performance-table td {
    padding: 1rem;
    color: var(--text-primary);
}

.game-name-cell {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.game-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: linear-gradient(135deg, #4A7CB8 0%, #8A5CF6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.progress-bar-cell {
    width: 150px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(74, 124, 184, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), rgba(138, 92, 246, 0.7));
    border-radius: 4px;
    transition: width 0.6s ease;
}

.performance-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.performance-badge.excellent {
    background: rgba(16, 185, 129, 0.2);
    color: #10B981;
}

.performance-badge.good {
    background: rgba(59, 130, 246, 0.2);
    color: #3B82F6;
}

.performance-badge.average {
    background: rgba(251, 191, 36, 0.2);
    color: #FBBF24;
}

.performance-badge.poor {
    background: rgba(239, 68, 68, 0.2);
    color: #EF4444;
}

/* Achievements Section */
.achievements-section {
    margin-bottom: 2rem;
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.achievement-card {
    background: var(--card-bg);
    border: 1px solid rgba(74, 124, 184, 0.2);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
    transition: all 0.3s ease;
}

.achievement-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.achievement-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.achievement-info {
    flex: 1;
}

.achievement-name {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.achievement-description {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.achievement-progress {
    font-size: 0.75rem;
    color: var(--accent-primary);
    font-weight: 600;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .charts-section {
        grid-template-columns: 1fr;
    }

    .stats-overview-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
    .chart-card canvas { height: 240px !important; }
}

@media (max-width: 1024px) {
    .time-period-selector {
        gap: 0.4rem;
    }

    .period-btn {
        padding: 0.45rem 0.85rem;
        font-size: 0.8rem;
    }

    .analytics-stat-card {
        padding: 1.25rem;
    }

    .stat-value {
        font-size: 1.75rem;
    }
}

@media (max-width: 900px) {
    .stats-overview-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1rem;
    }

    .performance-table-container {
        overflow-x: auto;
    }

    .performance-table {
        min-width: 500px;
    }
}

@media (max-width: 768px) {
    .stats-overview-grid {
        grid-template-columns: 1fr;
    }

    .analytics-stat-card {
        padding: 1rem;
    }

    .stat-icon {
        width: 42px;
        height: 42px;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .performance-table {
        font-size: 0.875rem;
    }

    .performance-table th,
    .performance-table td {
        padding: 0.75rem 0.5rem;
    }

    .game-icon {
        width: 30px;
        height: 30px;
    }

    .chart-canvas {
        gap: 0.25rem;
    }
    .filters-toolbar {
        grid-template-columns: 1fr;
    }

    .chart-card canvas { height: 220px !important; }

    .achievements-grid {
        grid-template-columns: 1fr;
    }

    .time-period-selector {
        flex-wrap: wrap;
    }
}

@media (max-width: 600px) {
    .analytics-stat-card {
        padding: 0.85rem;
    }

    .stat-icon {
        width: 38px;
        height: 38px;
    }

    .stat-label {
        font-size: 0.8rem;
    }

    .stat-value {
        font-size: 1.3rem;
    }

    .period-btn {
        padding: 0.4rem 0.75rem;
        font-size: 0.75rem;
    }

    .achievement-card {
        padding: 1rem;
        gap: 0.75rem;
    }

    .achievement-icon {
        width: 50px;
        height: 50px;
        font-size: 1.25rem;
    }
}

@media (max-width: 480px) {
    .stats-overview-grid {
        gap: 0.75rem;
    }

    .stat-change {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }

    .performance-table {
        font-size: 0.8rem;
    }

    .performance-table th,
    .performance-table td {
        padding: 0.6rem 0.4rem;
    }
}
