/**
 * تنسيقات الواجهة الأمامية ووثيقة الشراء - CNCPro Wizard SPA
 * الإصدار المحدث: دعم توافق RTL، إجبار ألوان العناوين، وإصلاح Fallback لشبكة Masonry
 */

/* ==========================================================================
   1. الإعدادات العامة وتطبيق الويب
   ========================================================================== */
.cnc-wizard-wrapper {
    max-width: 1000px;
    margin: 30px auto;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    padding: 30px;
    direction: rtl;
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    color: #333;
    border: 1px solid #eaeaea;
    position: relative;
    overflow: hidden;
}

/* شريط التقدم */
.cnc-progress-container {
    background: #e9ecef;
    height: 24px;
    border-radius: 12px;
    position: relative;
    margin-bottom: 30px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}
.cnc-progress-bar {
    background: linear-gradient(90deg, #0056b3, #0073aa);
    height: 100%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.cnc-progress-text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    text-align: center;
    line-height: 24px;
    font-size: 13px;
    color: #fff;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* التنبيهات */
.cnc-alert {
    background: #f8d7da;
    color: #721c24;
    padding: 15px 20px;
    border-radius: 6px;
    border: 1px solid #f5c6cb;
    margin-bottom: 20px;
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

/* عناوين الخطوات */
.cnc-step-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px dashed #eee;
}
.cnc-step-header h2 {
    color: #d32f2f !important;
    margin: 0 0 10px 0;
    font-size: 26px;
    font-weight: bold;
}
.cnc-step-header p {
    color: #666 !important;
    font-size: 16px;
    margin: 0;
}

/* ==========================================================================
   2. شبكة المنتجات (Masonry Grid) والتحديد
   ========================================================================== */
.cnc-masonry-grid {
    margin-bottom: 30px;
}
.cnc-masonry-grid::after {
    content: '';
    display: block;
    clear: both;
}

.cnc-grid-item {
    margin-bottom: 15px;
    cursor: pointer;
    box-sizing: border-box;
    float: right; /* إصلاح محوري: يمنع التكدس العمودي قبل عمل الجافاسكريبت */
}

/* إعدادات أحجام المربعات */
.cnc-grid-item--small { width: calc(25% - 15px); }
.cnc-grid-item--large { width: calc(50% - 15px); }
.cnc-grid-item--width2 { width: calc(50% - 15px); }
.cnc-grid-item--height2 { width: calc(25% - 15px); }

/* التصميم الداخلي للمنتج */
.cnc-item-inner {
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
    height: 100%;
    position: relative;
}
.cnc-item-inner:hover {
    border-color: #aaa;
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

/* تأثير التحديد (الإطار الأصفر) */
.cnc-grid-item.cnc-selected .cnc-item-inner {
    border-color: #ffc107;
    background-color: #fffdf5;
    box-shadow: 0 0 0 4px rgba(255, 193, 7, 0.3);
    transform: scale(1.02);
}
.cnc-check-mark {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #ffc107;
    color: #fff;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border-radius: 50%;
    font-size: 16px;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
}
.cnc-grid-item.cnc-selected .cnc-check-mark {
    opacity: 1;
    transform: scale(1);
}

.cnc-item-thumb img {
    width: 100%;
    height: auto;
    display: block;
    border-bottom: 1px solid #eee;
}
.cnc-no-thumb {
    background: #f5f5f5;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    border-bottom: 1px solid #eee;
}
.cnc-item-content {
    padding: 15px;
}
.cnc-item-content h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: #0056b3 !important; /* إصلاح محوري: منع اللون الأبيض من القالب */
    font-weight: bold;
}
.cnc-item-content p {
    margin: 0;
    font-size: 13px;
    color: #777 !important;
    line-height: 1.4;
}

/* ==========================================================================
   3. البطاقات (خيارات الليزر ومساحة العمل)
   ========================================================================== */
.cnc-options-list {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    margin-bottom: 30px;
}
.cnc-option-card {
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 25px 20px;
    text-align: center;
    width: calc(33.333% - 20px);
    cursor: pointer;
    transition: all 0.3s;
}
.cnc-option-card:hover {
    border-color: #0073aa;
    background: #f0f8ff;
}
.cnc-option-card.selected {
    border-color: #0073aa;
    background: #e1f0fa;
    box-shadow: 0 5px 15px rgba(0, 115, 170, 0.2);
    transform: translateY(-5px);
}
.cnc-option-card h3 {
    color: #0056b3 !important; /* إصلاح محوري: إجبار ظهور العنوان باللون الأزرق */
    font-size: 22px;
    margin: 0 0 10px 0;
    font-weight: bold;
}
.cnc-option-card p {
    color: #555 !important;
    font-size: 14px;
    margin: 0;
}

/* تنسيق الليزر المعطل (إذا اختار العميل منتجاً يحتاج ليزر أقوى) */
.cnc-option-card.cnc-disabled-laser {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #ddd;
    background: #f9f9f9;
    position: relative;
    pointer-events: auto; /* ضروري للسماح للمتصفح بالتقاط النقرة وعرض رسالة الخطأ */
}
.cnc-option-card.cnc-disabled-laser::after {
    content: "⚠️ لا يدعم خياراتك";
    display: block;
    color: #d32f2f;
    font-size: 13px;
    margin-top: 15px;
    font-weight: bold;
    background: #ffeeee;
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #f5c6cb;
}

/* ==========================================================================
   4. الأزرار والنماذج
   ========================================================================== */
.cnc-step-actions {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    clear: both;
}
.cnc-step-actions.double {
    display: flex;
    justify-content: space-between;
}
.cnc-btn {
    padding: 12px 30px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    transition: 0.3s;
}
.cnc-btn-primary { background: #0073aa; color: #fff; box-shadow: 0 4px 10px rgba(0,115,170,0.3); }
.cnc-btn-primary:hover { background: #0056b3; }
.cnc-btn-secondary { background: #6c757d; color: #fff; }
.cnc-btn-secondary:hover { background: #5a6268; }
.cnc-btn-success { background: #28a745; color: #fff; font-size: 18px; padding: 15px 40px; box-shadow: 0 4px 10px rgba(40,167,69,0.3); }
.cnc-btn-success:hover { background: #218838; }
.cnc-btn-outline { background: transparent; border: 2px solid #0073aa; color: #0073aa; margin-top: 10px; }
.cnc-btn-outline:hover { background: #0073aa; color: #fff; }

.cnc-form-group {
    margin-bottom: 20px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}
.cnc-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #444;
}
.cnc-form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 16px;
    font-family: inherit;
}

/* ==========================================================================
   5. النافذة المنبثقة (Modal) وصور الصيانة
   ========================================================================== */
.cnc-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.8);
}
.cnc-modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border-radius: 8px;
    width: 80%;
    max-width: 800px;
    position: relative;
}
.cnc-close-modal {
    color: #aaa;
    float: left;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.cnc-close-modal:hover { color: #d32f2f; }

.cnc-maintenance-grid {
    display: flex;
    gap: 20px;
}
.cnc-maint-item {
    flex: 1;
    background: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}
.cnc-maint-img img { max-width: 100%; border-radius: 4px; }
.cnc-no-img { background: #ddd; padding: 40px 0; color: #888; border-radius: 4px; }

/* ==========================================================================
   6. تنسيقات وثيقة الـ PDF (رسمية واحترافية)
   ========================================================================== */
.cnc-pdf-content {
    background: #fff;
    padding: 40px;
    color: #222;
    font-family: 'Arial', sans-serif;
    direction: rtl;
    text-align: right;
    box-sizing: border-box;
}
.pdf-header {
    text-align: center;
    border-bottom: 3px solid #d32f2f;
    padding-bottom: 20px;
    margin-bottom: 30px;
}
.pdf-header h1 { color: #d32f2f; font-size: 28px; margin: 0 0 5px 0; }
.pdf-header h2 { color: #555; font-size: 18px; margin: 0; font-weight: normal; }

.pdf-meta-box {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: #f9f9f9;
    padding: 20px;
    border: 1px solid #ccc;
    border-radius: 8px;
    margin-bottom: 30px;
}
.pdf-customer-info p { margin: 8px 0; font-size: 16px; }
.pdf-qr-box {
    background: #fff;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.pdf-section-title {
    color: #0056b3;
    border-bottom: 2px solid #0056b3;
    padding-bottom: 8px;
    margin-top: 30px;
    margin-bottom: 15px;
    font-size: 20px;
}

.pdf-specs-box, .pdf-products-box {
    background: #e3f2fd;
    padding: 15px 20px;
    border-radius: 6px;
    border-right: 5px solid #0073aa;
    margin-bottom: 20px;
}
.pdf-specs-box p { margin: 5px 0; font-size: 16px; }
.pdf-products-box ul { margin: 0; padding-right: 20px; font-size: 16px; font-weight: bold; }

.pdf-legal-terms p { font-size: 13px; line-height: 1.8; text-align: justify; margin-bottom: 10px; }

.pdf-maint-steps { display: flex; gap: 15px; margin-bottom: 40px; }
.pdf-maint-item { flex: 1; text-align: center; border: 1px solid #eee; padding: 10px; background: #fafafa; border-radius: 4px; }
.pdf-maint-item img { max-width: 100%; height: 120px; object-fit: cover; border-radius: 4px; margin-bottom: 10px; }
.pdf-maint-item p { font-size: 12px; margin: 0; }

.pdf-signatures { display: flex; justify-content: space-between; margin-top: 50px; }
.pdf-sig { text-align: center; width: 40%; }
.pdf-sig p { font-weight: bold; margin-bottom: 40px; }
.pdf-line { border-top: 1px dashed #777; padding-top: 10px; font-size: 14px; }

/* ==========================================================================
   7. التجاوب مع الهواتف (Responsive)
   ========================================================================== */
@media (max-width: 768px) {
    .cnc-grid-item--small, .cnc-grid-item--large, .cnc-grid-item--width2, .cnc-grid-item--height2 {
        width: calc(50% - 15px);
    }
    .cnc-option-card { width: 100%; margin-bottom: 15px; }
    .cnc-step-actions.double { flex-direction: column-reverse; gap: 15px; }
    .cnc-maintenance-grid { flex-direction: column; }
    .pdf-meta-box { flex-direction: column; text-align: center; }
    .pdf-qr-box { margin: 20px auto 0; }
}
@media (max-width: 480px) {
    .cnc-grid-item--small, .cnc-grid-item--large, .cnc-grid-item--width2, .cnc-grid-item--height2 {
        width: 100%;
    }
}