/* Statistics Page Styles */

/* ========================================
   Statistics Sections
   ======================================== */

.stats-section {
    margin-top: 3rem;
}

.stats-section h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--accent-primary);
    padding-bottom: 0.5rem;
}

.stats-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.stats-empty-message {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

/* ========================================
   Session Card
   ======================================== */

.session-card {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.session-card:hover,
.session-card:focus {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    box-shadow: 0 4px 12px rgba(74, 105, 133, 0.15);
    outline: none;
}

.session-card-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.session-info {
    flex: 1;
}

.session-info strong {
    color: var(--text-primary);
    font-size: 1.1rem;
}

.session-info small {
    color: var(--text-secondary);
}

.stats-detail-link {
    color: var(--accent-primary) !important;
    font-weight: 500;
}

.session-stats {
    text-align: right;
    min-width: 100px;
}

.session-stats strong {
    color: var(--accent-primary);
    font-size: 1.3rem;
}

.session-stats small {
    color: var(--text-secondary);
}

/* ========================================
   Category Card
   ======================================== */

.category-card {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid var(--accent-primary);
}

.category-info {
    flex: 1;
}

.category-info strong {
    color: var(--text-primary);
    font-size: 1.1rem;
}

.record-meta {
    color: var(--text-secondary) !important;
}

.category-stats {
    text-align: right;
    min-width: 100px;
}

.category-stats strong {
    color: var(--accent-primary);
    font-size: 1.3rem;
}

.category-stats small {
    color: var(--text-secondary);
}

/* ========================================
   Modal Styles
   ======================================== */

.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    overflow: auto;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 5% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    color: var(--text-primary);
    margin: 0;
    font-size: 1.5rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.3s ease;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 2rem;
    max-height: 70vh;
    overflow-y: auto;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

/* ========================================
   Session Detail
   ======================================== */

.session-detail-header {
    background: var(--bg-tertiary);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.session-detail-header h3 {
    color: var(--accent-primary);
    margin-top: 0;
}

.session-detail-header p {
    color: var(--text-primary);
    margin: 0.5rem 0;
}

.session-detail-header strong {
    color: var(--text-secondary);
    font-weight: 600;
}

/* ========================================
   Question List
   ======================================== */

.question-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1.5rem 0;
}

.question-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid;
}

.question-item.correct {
    background: rgba(46, 204, 113, 0.1);
    border-left-color: #2ecc71;
}

.question-item.incorrect {
    background: rgba(231, 76, 60, 0.1);
    border-left-color: #e74c3c;
}

.question-icon {
    font-size: 1.5rem;
    font-weight: bold;
    min-width: 24px;
}

.question-item.correct .question-icon {
    color: #2ecc71;
}

.question-item.incorrect .question-icon {
    color: #e74c3c;
}

.question-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.question-char {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
}

.question-answer,
.question-user-answer {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.question-user-answer {
    color: #e74c3c;
}

.question-time {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
}

/* ========================================
   Session Actions
   ======================================== */

.session-actions {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.retry-btn {
    background: var(--accent-primary);
    color: white;
    padding: 1rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.retry-btn:hover {
    background: var(--accent-secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 105, 133, 0.3);
}

.error-message {
    text-align: center;
    color: #e74c3c;
    padding: 2rem;
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 2% auto;
    }

    .modal-body {
        padding: 1.5rem;
        max-height: 80vh;
    }

    .session-card-content,
    .category-card {
        flex-direction: column;
        gap: 1rem;
    }

    .session-stats,
    .category-stats {
        text-align: left;
        width: 100%;
    }

    .question-item {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ========================================
   CLS Guards (reserve space to prevent jumps)
   ======================================== */
/* Reserve header height because navbar is injected later by JS */
#statistics-page header { min-height: 64px; }

/* Keep overall content tall enough so footer doesn't jump when data arrives */
#statistics-page .content-container { min-height: 70vh; }

/* Reserve space for grids and lists before async data fills them */
.stats-grid { min-height: 120px; }
.stats-section { min-height: 320px; }  /* was margin-top only; add min-height */
.stats-list { min-height: 240px; }

/* Avoid big reflow when switching from login prompt to stats content:
   keep layout space by using visibility instead of display:none for this page */
#statistics-page #stats-content.hidden { display: block; visibility: hidden; }

/* Ensure cards have a minimum height to prevent collapse/expand jumps */
.stat-card { min-height: 88px; }
.category-card,
.session-card { min-height: 64px; }