/* ===================================
   صانع القوالب - أنماط الواجهة الأمامية
   =================================== */

:root {
    --qtm-primary: #6366f1;
    --qtm-success: #10b981;
    --qtm-danger: #ef4444;
    --qtm-dark: #1e293b;
    --qtm-gray: #64748b;
    --qtm-light: #f1f5f9;
    --qtm-white: #ffffff;
    --qtm-border: #e2e8f0;
    --qtm-radius: 16px;
    --qtm-radius-sm: 10px;
}

/* ===== معرض القوالب ===== */
.qtm-gallery {
    display: grid;
    grid-template-columns: repeat(var(--qtm-cols, 3), 1fr);
    gap: 20px;
    direction: rtl;
    font-family: 'Tajawal', sans-serif;
}

@media (max-width: 768px) {
    .qtm-gallery { grid-template-columns: 1fr !important; }
}

.qtm-gallery-card {
    background: var(--qtm-white);
    border-radius: var(--qtm-radius);
    padding: 24px;
    text-align: center;
    text-decoration: none;
    color: var(--qtm-dark);
    border: 1px solid var(--qtm-border);
    transition: transform 0.3s, box-shadow 0.3s;
    display: block;
}

.qtm-gallery-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.12);
}

.qtm-gallery-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    color: var(--qtm-white);
    font-size: 24px;
}

.qtm-gallery-card h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
}

.qtm-gallery-card p {
    font-size: 14px;
    color: var(--qtm-gray);
    margin-bottom: 12px;
}

.qtm-usage-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--qtm-gray);
    background: var(--qtm-light);
    padding: 4px 10px;
    border-radius: 20px;
}

.qtm-no-templates {
    text-align: center;
    padding: 40px;
    color: var(--qtm-gray);
    font-family: 'Tajawal', sans-serif;
}

/* ===== نموذج استخدام القالب ===== */
.qtm-template-form {
    max-width: 700px;
    margin: 0 auto;
    font-family: 'Tajawal', sans-serif;
    direction: rtl;
}

.qtm-tform-header {
    text-align: center;
    padding: 32px;
    background: var(--qtm-white);
    border-radius: var(--qtm-radius);
    margin-bottom: 24px;
    border-top: 4px solid;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.qtm-tform-header i {
    font-size: 48px;
    margin-bottom: 12px;
    display: block;
}

.qtm-tform-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--qtm-dark);
}

.qtm-tform-header p {
    color: var(--qtm-gray);
    font-size: 15px;
}

.qtm-tform-fields {
    background: var(--qtm-white);
    border-radius: var(--qtm-radius);
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.qtm-field-group {
    margin-bottom: 20px;
}

.qtm-field-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 15px;
    color: var(--qtm-dark);
}

.qtm-required {
    color: var(--qtm-danger);
}

.qtm-field {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--qtm-border);
    border-radius: var(--qtm-radius-sm);
    font-family: 'Tajawal', sans-serif;
    font-size: 15px;
    transition: border-color 0.2s;
    direction: rtl;
    box-sizing: border-box;
}

.qtm-field:focus {
    outline: none;
    border-color: var(--qtm-primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

.qtm-image-upload {
    position: relative;
}

.qtm-image-preview {
    margin-top: 8px;
}

.qtm-image-preview img {
    max-width: 200px;
    border-radius: 8px;
    border: 2px solid var(--qtm-border);
}

.qtm-tform-actions {
    text-align: center;
    margin-bottom: 24px;
}

.qtm-execute-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 40px;
    border: none;
    border-radius: var(--qtm-radius-sm);
    font-family: 'Tajawal', sans-serif;
    font-size: 17px;
    font-weight: 700;
    color: var(--qtm-white);
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

.qtm-execute-btn:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

.qtm-execute-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* النتيجة */
.qtm-tform-result {
    background: var(--qtm-white);
    border-radius: var(--qtm-radius);
    padding: 32px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-top: 4px solid var(--qtm-success);
}

.qtm-tform-result h3 {
    color: var(--qtm-success);
    font-size: 18px;
    margin-bottom: 16px;
}

.qtm-result-content {
    font-size: 15px;
    line-height: 1.8;
    color: var(--qtm-dark);
}

.qtm-result-content pre {
    background: var(--qtm-dark);
    color: #e2e8f0;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
}

/* ===== إخراج بنمط شاشة الجوال (9:16) ===== */
.qtm-mobile-stage {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 0 auto;
}

.qtm-mobile-device {
    width: min(100%, 420px);
    aspect-ratio: 9 / 16;
    background: linear-gradient(145deg, #0f172a 0%, #1e293b 55%, #111827 100%);
    border-radius: 34px;
    padding: 10px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.35);
    position: relative;
}

.qtm-mobile-device::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36%;
    height: 18px;
    border-radius: 0 0 12px 12px;
    background: rgba(0, 0, 0, 0.55);
    z-index: 3;
}

.qtm-mobile-screen {
    width: 100%;
    height: 100%;
    border-radius: 24px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    position: relative;
}

.qtm-mobile-scroll {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    box-sizing: border-box;
}

.qtm-mobile-scroll--text {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
}

.qtm-mobile-text {
    width: 100%;
    font-size: clamp(18px, 2.8vw, 24px);
    font-weight: 700;
    line-height: 1.8;
    color: var(--qtm-dark);
}

.qtm-mobile-stage .qtm-interactive-frame {
    width: 100%;
    height: 100% !important;
    min-height: 100% !important;
    border: 0 !important;
    border-radius: 0 !important;
    display: block;
}

.qtm-mobile-stage--image .qtm-mobile-screen {
    background: #020617;
}

.qtm-mobile-stage--image .qtm-image-result {
    height: 100%;
    margin: 0;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #020617;
}

.qtm-mobile-stage--image .qtm-image-result img {
    width: 100%;
    height: 100%;
    max-width: none !important;
    object-fit: cover;
    border-radius: 0 !important;
    box-shadow: none !important;
}

.qtm-mobile-stage--image .qtm-image-result > div {
    display: none;
}

.qtm-mobile-stage .qtm-info-grid {
    grid-template-columns: 1fr;
}

.qtm-mobile-stage .qtm-fc-front,
.qtm-mobile-stage .qtm-fc-back,
.qtm-mobile-stage .qtm-quiz-q,
.qtm-mobile-stage .qtm-info-card {
    border-radius: 14px;
}

.qtm-mobile-stage .qtm-output-table {
    font-size: 12px;
}

.qtm-mobile-stage .qtm-output-table th,
.qtm-mobile-stage .qtm-output-table td {
    padding: 8px 10px;
}

.qtm-output-actions {
    justify-content: center;
}

@media (max-width: 640px) {
    .qtm-tform-result {
        padding: 18px;
    }

    .qtm-mobile-device {
        width: 100%;
        border-radius: 26px;
        padding: 8px;
    }

    .qtm-mobile-screen {
        border-radius: 18px;
    }
}

/* التحميل */
.qtm-tform-loading {
    text-align: center;
    padding: 40px;
}

.qtm-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--qtm-border);
    border-top-color: var(--qtm-primary);
    border-radius: 50%;
    animation: qtm-spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes qtm-spin {
    to { transform: rotate(360deg); }
}

.qtm-tform-loading p {
    color: var(--qtm-gray);
    font-size: 15px;
}

/* ===== صفحة القالب المفرد ===== */
.qtm-single-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 20px;
    font-family: 'Tajawal', sans-serif;
    direction: rtl;
}

.qtm-single-meta {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-bottom: 32px;
    flex-wrap: wrap;
}

.qtm-single-meta span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--qtm-gray);
    background: var(--qtm-light);
    padding: 6px 14px;
    border-radius: 20px;
}

/* ===== صفحة الأرشيف ===== */
.qtm-archive-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 20px;
    font-family: 'Tajawal', sans-serif;
    direction: rtl;
}

.qtm-archive-header {
    text-align: center;
    margin-bottom: 40px;
}

.qtm-archive-header h1 {
    font-size: 32px;
    font-weight: 800;
    color: var(--qtm-dark);
    margin-bottom: 8px;
}

.qtm-archive-header p {
    font-size: 16px;
    color: var(--qtm-gray);
}

.qtm-search-bar {
    max-width: 500px;
    margin: 24px auto 0;
    position: relative;
}

.qtm-search-bar input {
    width: 100%;
    padding: 14px 20px 14px 48px;
    border: 2px solid var(--qtm-border);
    border-radius: 30px;
    font-family: 'Tajawal', sans-serif;
    font-size: 15px;
    direction: rtl;
    box-sizing: border-box;
}

.qtm-search-bar input:focus {
    outline: none;
    border-color: var(--qtm-primary);
}

.qtm-search-bar i {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--qtm-gray);
}

/* ===== أزرار إجراءات المخرجات ===== */
.qtm-output-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.qtm-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: 2px solid var(--qtm-border);
    border-radius: 8px;
    background: var(--qtm-white);
    font-family: 'Tajawal', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--qtm-gray);
    cursor: pointer;
    transition: all 0.2s;
}

.qtm-action-btn:hover {
    border-color: var(--qtm-primary);
    color: var(--qtm-primary);
    background: rgba(99,102,241,0.05);
}

.qtm-action-btn.saved {
    border-color: var(--qtm-success);
    color: var(--qtm-success);
}

/* ===== بطاقات الفلاش (Flashcards) ===== */
.qtm-flashcards {
    direction: rtl;
}

.qtm-fc-counter {
    text-align: center;
    font-size: 14px;
    color: var(--qtm-gray);
    margin-bottom: 20px;
    font-weight: 600;
}

.qtm-flashcard {
    perspective: 1000px;
    margin-bottom: 16px;
    cursor: pointer;
    min-height: 140px;
}

.qtm-fc-inner {
    position: relative;
    width: 100%;
    min-height: 140px;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.qtm-flashcard.flipped .qtm-fc-inner {
    transform: rotateX(180deg);
}

.qtm-fc-front,
.qtm-fc-back {
    position: absolute;
    width: 100%;
    min-height: 140px;
    backface-visibility: hidden;
    border-radius: var(--qtm-radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-sizing: border-box;
}

.qtm-fc-front {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--qtm-white);
    text-align: center;
}

.qtm-fc-front h3 {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 8px;
    line-height: 1.4;
}

.qtm-fc-num {
    position: absolute;
    top: 12px;
    right: 16px;
    background: rgba(255,255,255,0.25);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
}

.qtm-fc-hint {
    font-size: 12px;
    opacity: 0.7;
    margin: 0;
}

.qtm-fc-back {
    background: var(--qtm-white);
    border: 2px solid var(--qtm-border);
    color: var(--qtm-dark);
    transform: rotateX(180deg);
}

.qtm-fc-back p {
    font-size: 15px;
    line-height: 1.8;
    margin: 0;
}

/* ===== اختبار / مسابقة (Quiz) ===== */
.qtm-quiz {
    direction: rtl;
}

.qtm-quiz-header {
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--qtm-primary);
    margin-bottom: 24px;
    padding: 12px;
    background: rgba(99,102,241,0.08);
    border-radius: var(--qtm-radius-sm);
}

.qtm-quiz-q {
    background: var(--qtm-white);
    border: 1px solid var(--qtm-border);
    border-radius: var(--qtm-radius);
    padding: 24px;
    margin-bottom: 16px;
}

.qtm-quiz-q h4 {
    font-size: 16px;
    font-weight: 700;
    color: var(--qtm-dark);
    margin: 0 0 16px;
    line-height: 1.6;
}

.qtm-q-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--qtm-primary);
    color: var(--qtm-white);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 13px;
    margin-left: 8px;
}

.qtm-quiz-opts {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.qtm-quiz-opt {
    padding: 12px 18px;
    border: 2px solid var(--qtm-border);
    border-radius: var(--qtm-radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 15px;
}

.qtm-quiz-opt:hover {
    border-color: var(--qtm-primary);
    background: rgba(99,102,241,0.04);
}

.qtm-opt-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--qtm-light);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
    margin-left: 10px;
}

.qtm-quiz-q.answered .qtm-quiz-opt {
    cursor: default;
    pointer-events: none;
}

.qtm-quiz-opt.correct {
    border-color: var(--qtm-success);
    background: rgba(16,185,129,0.08);
}

.qtm-quiz-opt.selected-correct {
    border-color: var(--qtm-success);
    background: rgba(16,185,129,0.15);
}

.qtm-quiz-opt.selected-wrong {
    border-color: var(--qtm-danger);
    background: rgba(239,68,68,0.1);
}

.qtm-quiz-explain {
    margin-top: 12px;
    padding: 12px 16px;
    background: #fef9c3;
    border-radius: 8px;
    font-size: 14px;
    color: #854d0e;
    line-height: 1.6;
}

/* ===== بطاقات معلومات ===== */
.qtm-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    direction: rtl;
}

.qtm-info-card {
    background: var(--qtm-white);
    border: 1px solid var(--qtm-border);
    border-radius: var(--qtm-radius);
    padding: 24px;
    transition: box-shadow 0.2s;
}

.qtm-info-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.qtm-info-card h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--qtm-dark);
    margin: 0 0 10px;
}

.qtm-info-card p {
    font-size: 14px;
    color: var(--qtm-gray);
    line-height: 1.7;
    margin: 0;
}

/* ===== جدول مخرجات ===== */
.qtm-table-wrap {
    overflow-x: auto;
    direction: rtl;
}

.qtm-output-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.qtm-output-table th {
    background: var(--qtm-dark);
    color: var(--qtm-white);
    padding: 12px 16px;
    text-align: right;
    font-weight: 600;
}

.qtm-output-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--qtm-border);
}

.qtm-output-table tr:nth-child(even) {
    background: var(--qtm-light);
}

/* ===== كائن مفرد ===== */
.qtm-object-view {
    direction: rtl;
}

.qtm-obj-row {
    padding: 10px 0;
    border-bottom: 1px solid var(--qtm-border);
    font-size: 15px;
    line-height: 1.6;
}

.qtm-obj-row strong {
    color: var(--qtm-primary);
    margin-left: 8px;
}

/* ===== قائمة ===== */
.qtm-rendered-list {
    list-style: none;
    padding: 0;
    margin: 0;
    direction: rtl;
}

.qtm-rendered-list li {
    padding: 10px 16px;
    border-bottom: 1px solid var(--qtm-border);
    font-size: 15px;
    line-height: 1.6;
}

.qtm-rendered-list li::before {
    content: '•';
    color: var(--qtm-primary);
    font-weight: bold;
    margin-left: 8px;
}

/* ===== طباعة ===== */
@media print {
    .qtm-output-actions { display: none !important; }
    .qtm-flashcard { break-inside: avoid; }
    .qtm-fc-inner { transform: none !important; }
    .qtm-fc-back { position: relative; transform: none; backface-visibility: visible; margin-top: 8px; }
    .qtm-fc-hint { display: none; }
}
