/**
 * Quiz Results Plugin - Frontend Styles
 */

/* ==================== المتغيرات ==================== */
.qr-quiz-container {
    --qrf-primary: #2ba39a;
    --qrf-primary-hover: #E37B5C;
    --qrf-primary-light: #eef2ff;
    --qrf-success: #10b981;
    --qrf-success-light: #d1fae5;
    --qrf-danger: #ef4444;
    --qrf-danger-light: #fee2e2;
    --qrf-warning: #f59e0b;
    --qrf-bg: #f9fafb;
    --qrf-white: #ffffff;
    --qrf-gray-100: #f3f4f6;
    --qrf-gray-200: #e5e7eb;
    --qrf-gray-300: #d1d5db;
    --qrf-gray-400: #9ca3af;
    --qrf-gray-500: #6b7280;
    --qrf-gray-600: #4b5563;
    --qrf-gray-700: #374151;
    --qrf-gray-800: #1f2937;
    --qrf-gray-900: #111827;
    
    --qrf-radius: 14px;
    --qrf-radius-sm: 8px;
    --qrf-radius-lg: 20px;
    
    --qrf-shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --qrf-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --qrf-shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    --qrf-shadow-xl: 0 25px 50px -12px rgba(0,0,0,0.25);
    
    --qrf-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== الحاوية الرئيسية ==================== */
.qr-quiz-container {
    font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, sans-serif;
    max-width: 720px;
    margin: 30px auto;
    background: var(--qrf-white);
    border-radius: var(--qrf-radius-lg);
    box-shadow: var(--qrf-shadow-lg);
    overflow: hidden;
    position: relative;
    color: var(--qrf-gray-800);
    line-height: 1.6;
    text-align: start;
}

.qr-quiz-container.qr-is-rtl {
    direction: rtl;
}

.qr-quiz-container.qr-is-ltr {
    direction: ltr;
}

/* ==================== الشاشات ==================== */
.qr-screen {
    display: none;
    padding: 40px;
    animation: qrf-fadeIn 0.4s ease;
}

.qr-screen.active {
    display: block;
}

@keyframes qrf-fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==================== الشاشة التمهيدية ==================== */
.qr-intro-screen {
    text-align: center;
    padding: 50px 40px;
    background: 
        radial-gradient(circle at top left, var(--qrf-primary-light) 0%, transparent 50%),
        radial-gradient(circle at bottom right, var(--qrf-success-light) 0%, transparent 50%),
        var(--qrf-white);
}

.qr-intro-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 25px;
    background: linear-gradient(135deg, var(--qrf-primary) 0%, var(--qrf-primary) 100%);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 10px 30px -10px var(--qrf-primary);
    transform: rotate(-5deg);
    animation: qrf-bounce 2s ease-in-out infinite;
}

.qr-intro-icon svg {
    width: 40px;
    height: 40px;
}

.qr-quiz-container.qr-is-rtl form.qr-quiz-form {
    direction: rtl;
    text-align: right;
}

.qr-quiz-container.qr-is-ltr form.qr-quiz-form {
    direction: ltr;
    text-align: left;
}

@keyframes qrf-bounce {
    0%, 100% { transform: rotate(-5deg) translateY(0); }
    50% { transform: rotate(-5deg) translateY(-8px); }
}

.qr-quiz-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--qrf-gray-900);
    margin: 0 0 15px;
    line-height: 1.3;
}

.qr-quiz-description {
    color: var(--qrf-gray-600);
    font-size: 16px;
    line-height: 1.7;
    margin-bottom: 30px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.qr-quiz-description p {
    margin: 0 0 10px;
}

.qr-intro-stats {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-bottom: 35px;
    flex-wrap: wrap;
}

.qr-stat-card {
    background: var(--qrf-white);
    padding: 16px 28px;
    border-radius: var(--qrf-radius);
    box-shadow: var(--qrf-shadow-sm);
    border: 1px solid var(--qrf-gray-200);
    min-width: 100px;
}

.qr-stat-value {
    font-size: 32px;
    font-weight: 800;
    color: var(--qrf-primary);
    line-height: 1;
}

.qr-stat-label {
    font-size: 13px;
    color: var(--qrf-gray-500);
    margin-top: 4px;
}

/* ==================== الأزرار ==================== */
.qr-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    border-radius: var(--qrf-radius-sm);
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    transition: var(--qrf-transition);
    text-decoration: none;
    position: relative;
    overflow: hidden;
    line-height: 1;
}

.qr-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.qr-btn-primary {
    background: linear-gradient(135deg, var(--qrf-primary) 0%, var(--qrf-primary) 100%);
    color: white;
    box-shadow: 0 4px 14px -2px rgba(43, 163, 154, 0.4);
}

.qr-btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px -4px rgba(43, 163, 154, 0.5);
}

.qr-btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.qr-btn-secondary {
    background: var(--qrf-white);
    color: var(--qrf-gray-700);
    border: 1px solid var(--qrf-gray-300);
}

.qr-btn-secondary:hover:not(:disabled) {
    background: var(--qrf-gray-100);
    border-color: var(--qrf-gray-400);
}

.qr-btn-start {
    margin-top: 10px;
    padding: 16px 40px;
    font-size: 16px;
}

/* ==================== شريط التقدم ==================== */
.qr-progress-wrapper {
    margin-bottom: 30px;
}

.qr-progress-text {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 14px;
    color: var(--qrf-gray-500);
    margin-bottom: 10px;
    font-weight: 600;
}

.qr-progress-current {
    background: var(--qrf-primary);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
}

.qr-progress-total {
    color: var(--qrf-gray-600);
}

.qr-progress-bar {
    background: var(--qrf-gray-200);
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.qr-progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--qrf-primary), var(--qrf-primary-hover));
    border-radius: 4px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.qr-progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    animation: qrf-shimmer 2s infinite;
}

@keyframes qrf-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ==================== الأسئلة ==================== */
.qr-questions-wrapper {
    min-height: 320px;
    position: relative;
}

.qr-question-card {
    display: none;
    animation: qrf-slideIn 0.4s ease;
}

.qr-question-card.active {
    display: block;
}

@keyframes qrf-slideIn {
    from { opacity: 0; transform: translateX(-15px); }
    to { opacity: 1; transform: translateX(0); }
}

.qr-question-number-badge {
    display: inline-block;
    background: var(--qrf-primary-light);
    color: var(--qrf-primary-hover);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 15px;
}

.qr-question-text {
    font-size: 22px;
    font-weight: 700;
    color: var(--qrf-gray-900);
    margin: 0 0 25px;
    line-height: 1.5;
}

/* ==================== الإجابات ==================== */
.qr-answers-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.qr-answer-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: var(--qrf-white);
    border: 2px solid var(--qrf-gray-200);
    border-radius: var(--qrf-radius);
    cursor: pointer;
    transition: var(--qrf-transition);
    position: relative;
}

.qr-answer-option:hover {
    border-color: var(--qrf-primary);
    background: var(--qrf-primary-light);
}

.qr-quiz-container.qr-is-rtl .qr-answer-option:hover {
    transform: translateX(-3px);
}

.qr-quiz-container.qr-is-ltr .qr-answer-option:hover {
    transform: translateX(3px);
}

.qr-answer-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.qr-answer-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--qrf-gray-100);
    color: var(--qrf-gray-600);
    border-radius: 10px;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    transition: var(--qrf-transition);
}

.qr-answer-text {
    flex: 1;
    color: var(--qrf-gray-700);
    font-size: 15px;
    font-weight: 500;
}

.qr-answer-check {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--qrf-gray-200);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5);
    transition: var(--qrf-transition);
}

.qr-answer-check svg {
    width: 16px;
    height: 16px;
}

.qr-answer-option:has(input:checked) {
    background: linear-gradient(135deg, var(--qrf-primary) 0%, var(--qrf-primary-hover) 100%);
    border-color: var(--qrf-primary);
    color: var(--qrf-primary);
    box-shadow: 0 8px 25px -8px var(--qrf-primary);
    transform: scale(1.01);
}

.qr-quiz-container.qr-is-rtl .qr-answer-option:has(input:checked) {
    transform: translateX(-3px) scale(1.01);
}

.qr-quiz-container.qr-is-ltr .qr-answer-option:has(input:checked) {
    transform: translateX(3px) scale(1.01);
}

.qr-answer-option:has(input:checked) .qr-answer-letter {
    background: rgba(255, 255, 255, 0.25);
    color: var(--qrf-primary);
}

.qr-answer-option:has(input:checked) .qr-answer-text {
    color: var(--qrf-primary);
}

.qr-answer-option:has(input:checked) .qr-answer-check {
    background: white;
    color: var(--qrf-primary);
    opacity: 1;
    transform: scale(1);
}

/* fallback لمتصفحات لا تدعم :has */
.qr-answer-option.selected {
    background: linear-gradient(135deg, var(--qrf-primary) 0%, var(--qrf-primary-hover) 100%);
    border-color: var(--qrf-primary);
    box-shadow: 0 8px 25px -8px var(--qrf-primary);
}

.qr-answer-option.selected .qr-answer-letter {
    background:#2ba39a !important;
    color: white;
}

.qr-answer-option.selected .qr-answer-text {
    color: white;
}

.qr-answer-option.selected .qr-answer-check {
    background: white;
    color: var(--qrf-primary);
    opacity: 1;
    transform: scale(1);
}

/* ==================== التنقل ==================== */
.qr-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 35px;
    padding-top: 25px;
    border-top: 1px solid var(--qrf-gray-200);
}

.qr-navigation .qr-btn {
    min-width: 130px;
}

/* ==================== شاشة التحميل ==================== */
.qr-loading-screen {
    text-align: center;
    padding: 80px 40px;
}

.qr-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.qr-loading-content p {
    color: var(--qrf-gray-600);
    font-size: 16px;
    font-weight: 500;
}

.qr-spinner {
    display: inline-block;
    position: relative;
    width: 60px;
    height: 60px;
}

.qr-spinner div {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--qrf-primary);
    border-radius: 50%;
    animation: qrf-spinner 1.2s linear infinite;
}

.qr-spinner div:nth-child(1) { top: 0; left: 24px; animation-delay: 0s; }
.qr-spinner div:nth-child(2) { top: 24px; left: 48px; animation-delay: -0.3s; }
.qr-spinner div:nth-child(3) { top: 48px; left: 24px; animation-delay: -0.6s; }
.qr-spinner div:nth-child(4) { top: 24px; left: 0; animation-delay: -0.9s; }

@keyframes qrf-spinner {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.3; transform: scale(0.7); }
}

/* ==================== شاشة النتيجة ==================== */
.qr-result-screen {
    padding: 0;
}

.qr-result-wrapper {
    padding: 0;
}

.qr-result-main {
    text-align: center;
    padding: 50px 40px;
    background: 
        radial-gradient(circle at 50% 0%, var(--qrf-primary-light) 0%, transparent 60%),
        var(--qrf-white);
    position: relative;
    overflow: hidden;
}

.qr-result-main::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: 
        radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.05) 0%, transparent 20%),
        radial-gradient(circle at 80% 80%, rgba(16, 185, 129, 0.05) 0%, transparent 20%);
    pointer-events: none;
}

.qr-result-icon-wrapper {
    margin-bottom: 25px;
    position: relative;
    z-index: 1;
}

.qr-result-icon {
    width: 100px;
    height: 100px;
    margin: 0 auto;
    color: var(--qrf-success);
    animation: qrf-popIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.qr-result-progress-circle {
    transition: stroke-dashoffset 1s ease;
}

@keyframes qrf-popIn {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

.qr-result-header {
    position: relative;
    z-index: 1;
    margin-bottom: 30px;
}

.qr-result-subtitle {
    color: var(--qrf-gray-500);
    font-size: 14px;
    margin: 0 0 8px;
    font-weight: 500;
}

.qr-result-title {
    font-size: 32px;
    font-weight: 800;
    color: var(--qrf-gray-900);
    margin: 0;
    line-height: 1.3;
    background: linear-gradient(135deg, var(--qrf-primary) 0%, var(--qrf-primary-hover) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.qr-result-stats {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    position: relative;
    z-index: 1;
}

.qr-stat-big {
    background: var(--qrf-white);
    padding: 20px 30px;
    border-radius: var(--qrf-radius);
    box-shadow: var(--qrf-shadow);
    border: 1px solid var(--qrf-gray-200);
    min-width: 140px;
}

.qr-stat-big-value {
    font-size: 36px;
    font-weight: 800;
    color: var(--qrf-primary);
    line-height: 1;
}

.qr-stat-big-label {
    font-size: 13px;
    color: var(--qrf-gray-500);
    margin-top: 6px;
    font-weight: 500;
}

.qr-result-description {
    background: var(--qrf-gray-100);
    padding: 20px 25px;
    border-radius: var(--qrf-radius);
    margin: 0 auto 30px;
    max-width: 500px;
    text-align: start;
    direction: inherit;
    color: var(--qrf-gray-700);
    line-height: 1.7;
    font-size: 15px;
    position: relative;
    z-index: 1;
    border-inline-start: 4px solid var(--qrf-primary);
}

.qr-result-description p {
    margin: 0 0 10px;
}

.qr-result-description p:last-child {
    margin-bottom: 0;
}

.qr-result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    position: relative;
    z-index: 1;
}

/* ==================== مراجعة الإجابات ==================== */
.qr-result-details {
    background: var(--qrf-gray-100);
    border-top: 1px solid var(--qrf-gray-200);
}

.qr-result-details summary {
    direction: inherit;
    padding: 18px 30px;
    cursor: pointer;
    font-weight: 600;
    color: var(--qrf-gray-700);
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: var(--qrf-transition);
}

.qr-result-details summary:hover {
    background: var(--qrf-gray-200);
}

.qr-result-details[open] summary svg {
    transform: rotate(180deg);
}

.qr-result-details summary svg {
    transition: transform 0.3s ease;
}

.qr-details-content {
    padding: 0 30px 30px;
}

.qr-detail-item {
    display: flex;
    gap: 15px;
    padding: 15px;
    background: var(--qrf-white);
    border-radius: var(--qrf-radius-sm);
    margin-bottom: 10px;
    border-inline-start: 4px solid var(--qrf-gray-300);
    direction: inherit;
    text-align: start;
}

.qr-detail-item.is-correct {
    border-inline-start-color: var(--qrf-success);
    background: var(--qrf-success-light);
}

.qr-detail-item.is-wrong {
    border-inline-start-color: var(--qrf-danger);
    background: var(--qrf-danger-light);
}

.qr-detail-number {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--qrf-gray-200);
    color: var(--qrf-gray-700);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.qr-detail-item.is-correct .qr-detail-number {
    background: var(--qrf-success);
    color: white;
}

.qr-detail-item.is-wrong .qr-detail-number {
    background: var(--qrf-danger);
    color: white;
}

.qr-detail-content {
    flex: 1;
}

.qr-detail-question {
    font-weight: 600;
    color: var(--qrf-gray-800);
    margin-bottom: 5px;
    font-size: 14px;
}

.qr-detail-answer {
    color: var(--qrf-gray-600);
    font-size: 13px;
}

.qr-detail-points {
    display: inline-block;
    background: var(--qrf-primary);
    color: white;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    margin-inline-start: 8px;
    font-weight: 600;
}

/* ==================== أخطاء ==================== */
.qr-error {
    background: var(--qrf-danger-light);
    color: #991b1b;
    padding: 15px 20px;
    border-radius: var(--qrf-radius-sm);
    border-inline-start: 4px solid var(--qrf-danger);
    margin: 20px 0;
    font-weight: 500;
}

.qr-validation-error {
    background: var(--qrf-danger-light);
    color: #991b1b;
    padding: 12px 18px;
    border-radius: var(--qrf-radius-sm);
    margin-bottom: 15px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    animation: qrf-shake 0.4s ease;
}

@keyframes qrf-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

/* ==================== Responsive ==================== */
@media (max-width: 600px) {
    .qr-quiz-container {
        margin: 0px;
        border-radius: var(--qrf-radius);
    }
    
    .qr-screen {
        padding: 25px 20px;
    }
    
    .qr-intro-screen {
        padding: 35px 20px;
    }
    
    .qr-quiz-title {
        font-size: 22px;
    }
    
    .qr-question-text {
        font-size: 18px;
    }
    
    .qr-result-title {
        font-size: 24px;
    }
    
    .qr-navigation {
        flex-direction: column;
        gap: 10px;
    }
    
    .qr-navigation .qr-btn {
        width: 100%;
    }
    
    .qr-intro-stats {
        gap: 12px;
    }
    
    .qr-stat-card {
        padding: 12px 20px;
    }
    
    .qr-stat-value {
        font-size: 24px;
    }
    
    .qr-answer-option {
        padding: 14px;
    }
    
    .qr-answer-letter {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }
}

/* ==================== الوضع الداكن (Dark Mode) ==================== */
@media (prefers-color-scheme: dark) {
    .qr-quiz-container.qr-auto-dark {
        background: #1e293b;
        color: #e2e8f0;
    }
    
    .qr-quiz-container.qr-auto-dark .qr-question-text,
    .qr-quiz-container.qr-auto-dark .qr-quiz-title,
    .qr-quiz-container.qr-auto-dark .qr-result-title {
        color: #f1f5f9;
    }
}

/* ==================== Toast (إشعارات) ==================== */
.qr-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translate(-50%, 30px);
    background: #1e293b;
    color: #fff;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 999999;
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 90%;
    text-align: center;
}

.qr-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.qr-toast-error {
    background: #ef4444;
}

.qr-toast-success {
    background: #10b981;
}

.qr-toast-info {
    background: #6366f1;
}

/* ==================== تأثير الاهتزاز ==================== */
@keyframes qr-shake-anim {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

.qr-question-card.qr-shake {
    animation: qr-shake-anim 0.5s ease;
}

/* ==================== صورة النتيجة ==================== */
.qr-result-image {
    margin: 20px auto;
    max-width: 300px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.qr-result-image img {
    width: 100%;
    height: auto;
    display: block;
}

/* ==================== خيار محدد ==================== */
.qr-answer-option.selected {
    border-color: var(--qr-primary) !important;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.05)) !important;
}

.qr-answer-option.selected .qr-answer-letter {
    background: #2ba39a !important;
    color: #fff !important;
}

.qr-answer-option.selected .qr-answer-check {
    opacity: 1 !important;
    transform: scale(1) !important;
}

.qr-quiz-container.qr-is-rtl .qr-btn-next svg,
.qr-quiz-container.qr-is-rtl .qr-btn-prev svg {
    transform: unset;
}

.qr-quiz-container.qr-is-ltr .qr-btn-next svg,
.qr-quiz-container.qr-is-ltr .qr-btn-prev svg {
    transform: rotate(180deg);
}
