/* ========================================
   قياس أونلاين — بنك الأسئلة (Explanations v2)
   ======================================== */

/* Page Layout */
.explain-page {
    padding-top: 100px;
    min-height: 100vh;
    padding-bottom: 40px;
}

.explain-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ========================================
   Stats Header
   ======================================== */
.explain-stats-header {
    text-align: center;
    margin-bottom: 32px;
    animation: fadeInUp 0.6s ease;
}

.stats-hero {
    margin-bottom: 20px;
}

.stats-hero h1 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.stats-hero h1 .gradient-text {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stats-hero p {
    color: var(--text-secondary);
    font-size: 1.05rem;
}

/* Stats Chips Row */
.stats-chips {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.stats-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 14px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.stats-chip:hover {
    border-color: var(--border-glow);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.stats-chip-icon {
    font-size: 1.2rem;
}

.stats-chip-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.stats-chip-count {
    font-size: 0.9rem;
    font-weight: 800;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    direction: ltr;
    display: inline-block;
}

/* Bookmark Counter */
.bookmark-counter {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 50px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: var(--warning);
    font-size: 0.88rem;
    font-weight: 600;
    margin-top: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    justify-content: center;
}

.bookmark-counter.has-bookmarks {
    display: inline-flex;
}

.bookmark-counter:hover {
    background: rgba(245, 158, 11, 0.18);
    transform: translateY(-1px);
}

.bookmark-counter.active {
    background: rgba(245, 158, 11, 0.25);
    border-color: var(--warning);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.15);
}

.bookmark-counter svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* ========================================
   Search & Filters
   ======================================== */
.explain-toolbar {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid var(--border-color);
    padding: 24px;
    margin-bottom: 24px;
    animation: fadeInUp 0.6s ease 0.1s both;
}

.search-box {
    position: relative;
    margin-bottom: 16px;
}

.search-box input {
    width: 100%;
    padding: 14px 20px 14px 48px;
    border-radius: 14px;
    border: 2px solid var(--border-color);
    background: var(--bg-glass-light);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.3s ease;
    direction: rtl;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-box input:focus {
    outline: none;
    border-color: var(--green-400);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.search-box .search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
}

/* Filter Groups */
.filter-groups {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 80px;
    flex-shrink: 0;
}

.filter-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-chip {
    padding: 6px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-glass-light);
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.85rem;
    font-family: inherit;
    white-space: nowrap;
}

.filter-chip:hover {
    border-color: var(--green-400);
    color: var(--green-400);
}

.filter-chip.active {
    background: var(--gradient-accent);
    border-color: transparent;
    color: white;
    -webkit-text-fill-color: white;
}

.bookmark-toggle.active {
    background: rgba(245, 158, 11, 0.15);
    border-color: var(--warning);
    color: var(--warning);
    -webkit-text-fill-color: var(--warning);
}

.bookmark-toggle.active svg {
    fill: var(--warning);
}

/* ========================================
   Results Info
   ======================================== */
.results-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 0 4px;
    animation: fadeInUp 0.6s ease 0.2s both;
}

.results-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.results-count strong {
    color: var(--text-primary);
}

/* ========================================
   Question Cards
   ======================================== */
.explain-questions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: fadeInUp 0.6s ease 0.2s both;
}

.explain-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid var(--border-color);
    padding: 28px;
    transition: all 0.3s ease;
    position: relative;
}

.explain-card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-sm);
}

/* Card Header */
.explain-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.explain-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-section {
    background: rgba(59, 130, 246, 0.1);
    color: var(--blue-400);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.badge-easy {
    background: rgba(99, 102, 241, 0.1);
    color: var(--success);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.badge-medium {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge-hard {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge-exam {
    background: rgba(124, 58, 237, 0.1);
    color: #A78BFA;
    border: 1px solid rgba(124, 58, 237, 0.2);
}

/* ========================================
   Bookmark Button (Heart)
   ======================================== */
.explain-bookmark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-glass-light);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-muted);
    flex-shrink: 0;
}

.explain-bookmark:hover {
    border-color: #ef4444;
    color: #ef4444;
}

.explain-bookmark.active {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #ef4444;
}

.explain-bookmark svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    transition: transform 0.3s ease;
}

.explain-bookmark.active svg {
    fill: #ef4444;
}

@keyframes bookmarkPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.explain-bookmark.bookmark-pulse svg {
    animation: bookmarkPop 0.4s ease;
}

/* ========================================
   Question Text
   ======================================== */
.explain-question-text {
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.8;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.explain-question-text.ltr-text,
.ltr-text {
    direction: ltr;
    text-align: left;
}

/* ========================================
   Passage Preview
   ======================================== */
.passage-preview {
    background: var(--bg-glass-light);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.8;
    direction: ltr;
    text-align: left;
    max-height: 120px;
    overflow: hidden;
    position: relative;
}

.passage-preview::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(transparent, var(--bg-card));
    pointer-events: none;
}

.passage-preview.expanded {
    max-height: none;
}

.passage-preview.expanded::after {
    display: none;
}

.passage-toggle {
    display: block;
    text-align: center;
    padding: 6px;
    margin-top: 4px;
    color: var(--green-400);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.3s ease;
}

.passage-toggle:hover {
    color: var(--green-300);
}

/* ========================================
   Options
   ======================================== */
.explain-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.explain-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    font-size: 0.95rem;
    transition: all 0.3s ease;
    line-height: 1.6;
}

.explain-option.correct-option {
    border-color: var(--success);
    border-width: 2px;
    background: rgba(99, 102, 241, 0.08);
}

.explain-option-letter {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.explain-option.correct-option .explain-option-letter {
    background: var(--success);
    color: white;
}

.explain-option-text {
    flex: 1;
}

.explain-option.correct-option .explain-option-text {
    color: var(--success);
    font-weight: 600;
}

.correct-check {
    width: 20px;
    height: 20px;
    color: var(--success);
    flex-shrink: 0;
}

/* ========================================
   Success Rate Stats
   ======================================== */
.question-stats {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 10px 16px;
    border-radius: 10px;
    background: var(--bg-glass-light);
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.stat-success-text {
    color: var(--text-secondary);
    white-space: nowrap;
    font-weight: 600;
    min-width: fit-content;
}

.stat-bar-container {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
}

.stat-bar-fill.high {
    background: var(--success);
}

.stat-bar-fill.medium {
    background: var(--warning);
}

.stat-bar-fill.low {
    background: var(--danger);
}

/* ========================================
   Expandable Explanation
   ======================================== */
.explain-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-glass-light);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    font-family: inherit;
    text-align: right;
}

.explain-toggle:hover {
    border-color: var(--green-400);
    color: var(--green-400);
    background: rgba(99, 102, 241, 0.05);
}

.explain-toggle.active {
    border-color: var(--green-400);
    color: var(--green-400);
    background: rgba(99, 102, 241, 0.08);
    border-radius: 12px 12px 0 0;
}

.explain-toggle svg {
    width: 18px;
    height: 18px;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.explain-toggle.active svg {
    transform: rotate(180deg);
}

.explain-toggle-text {
    flex: 1;
}

/* Explanation Content */
.explain-content {
    display: none;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 12px 12px;
    padding: 20px;
    background: var(--bg-glass-light);
    animation: fadeIn 0.3s ease;
}

.explain-content.active {
    display: block;
}

.explain-text {
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text-primary);
    margin-bottom: 16px;
    padding: 14px 18px;
    border-radius: 10px;
    background: rgba(99, 102, 241, 0.06);
    border-right: 3px solid var(--success);
}

.explain-text.explain-no-text {
    color: var(--text-muted);
    font-style: italic;
    background: rgba(100, 116, 139, 0.06);
    border-right-color: var(--text-muted);
}

/* Learning Tip */
.learning-tip {
    padding: 14px 18px;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.06);
    border-right: 3px solid var(--blue-400);
}

.learning-tip-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--blue-400);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.learning-tip-text {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-secondary);
    padding: 4px 0;
}

.learning-tip-text + .learning-tip-text {
    border-top: 1px dashed var(--border-color);
    margin-top: 8px;
    padding-top: 8px;
}

/* ========================================
   Pagination
   ======================================== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 32px;
    flex-wrap: wrap;
}

.pagination-btn {
    min-width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-glass-light);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    padding: 0 8px;
}

.pagination-btn:hover {
    border-color: var(--green-400);
    color: var(--green-400);
}

.pagination-btn.active {
    background: var(--gradient-accent);
    border-color: transparent;
    color: white;
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-btn:disabled:hover {
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.pagination-btn svg {
    width: 18px;
    height: 18px;
}

.pagination-dots {
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 0 4px;
}

/* ========================================
   Loading State
   ======================================== */
.explain-loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.explain-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--green-400);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

/* ========================================
   Empty State
   ======================================== */
.explain-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.explain-empty svg {
    width: 64px;
    height: 64px;
    color: var(--text-muted);
    margin-bottom: 16px;
    opacity: 0.5;
}

.explain-empty h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.explain-empty p {
    font-size: 0.95rem;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
    .explain-page {
        padding-top: 85px;
    }

    .stats-hero h1 {
        font-size: 1.5rem;
    }

    .stats-chips {
        gap: 8px;
    }

    .stats-chip {
        padding: 8px 14px;
        font-size: 0.85rem;
    }

    .explain-toolbar {
        padding: 18px;
    }

    .filter-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .filter-label {
        min-width: auto;
    }

    .filter-chips {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
        -ms-overflow-style: none;
        scrollbar-width: none;
        padding-bottom: 4px;
    }

    .filter-chips::-webkit-scrollbar {
        display: none;
    }

    .explain-card {
        padding: 20px 16px;
    }

    .explain-card-header {
        flex-direction: column;
        gap: 10px;
    }

    .explain-badges {
        order: 1;
    }

    .explain-bookmark {
        position: absolute;
        top: 16px;
        left: 16px;
    }

    .explain-question-text {
        font-size: 1rem;
    }

    .results-info {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .question-stats {
        flex-wrap: wrap;
    }

    .pagination {
        gap: 4px;
    }

    .pagination-btn {
        min-width: 36px;
        height: 36px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .stats-hero h1 {
        font-size: 1.3rem;
    }

    .stats-chips {
        flex-direction: column;
        align-items: center;
    }

    .explain-card {
        padding: 16px 14px;
    }

    .explain-option {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .explain-option-letter {
        width: 26px;
        height: 26px;
        font-size: 0.75rem;
    }
}
