/* ============================================================
 * COD Order Booster - COMPLETE FRONTEND STYLES (Final Version)
 * Optimized for Guatemala Locations + Icon Overlap Fix + Dynamic Asterisk (*) + Error Messages
 * ============================================================ */

.cob-order-button-wrapper {
    margin: 20px 0;
}

.cob-order-btn {
    display: inline-flex;
    align-items: center;       /* الأيقونة والنص نفس الخط */
    justify-content: center;   /* يجي النص وسط */
    gap: 10px;                  /* مسافة بين الأيقونة والنص */
    width: 100%;                /* full width */
    background: #42c955;
    color: #fff;
    border: none;
    padding: 16px 20px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    min-height: 48px;
    line-height: 1.4;
}

.cob-order-btn:hover {
    background: #db9711;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.3);
}

.cob-order-btn:active {
    transform: translateY(0);
}

.cob-btn-icon {
    flex-shrink: 0;
    color: #fff; /* الأيقونة تبقى بيضاء */
}

/* لمنع التمرير في الخلفية عند فتح الـ Popup */
body.cob-no-scroll {
    overflow: hidden !important;
    height: 100vh !important;
    position: fixed;
    width: 100%;
}

/* Popup Overlay */
.cob-popup-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    animation: cobFadeIn 0.3s ease-out;
}
.cob-popup-overlay.active { display: flex; }

/* Main Popup */
.cob-popup {
    background: #fff;
    border-radius: 16px;
    max-width: 450px;
    width: 90%;
    max-height: 90vh; /* الطول الماكسيموم للشاشة */
    overflow-y: auto; /* تفعيل السكرول */
    box-shadow: 0 25px 50px rgba(0,0,0,.25);
    animation: cobSlideUp 0.4s ease-out;
    position: relative;
    /* تحسين السكرول داخل الموبايل */
    -webkit-overflow-scrolling: touch;
    margin-top: 2vh;
}

/* Popup Header */
.cob-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
    border-radius: 16px 16px 0 0;
    position: sticky; top: 0; z-index: 100; /* الهيدر يبقى لاصق الفوق ملي تسكرولي */
}
.cob-popup-title { font-size: 18px; font-weight: 600; color: #1f2937; }
.cob-popup-close {
    background: none; border: none; font-size: 24px; cursor: pointer; color: #6b7280;
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    border-radius: 8px; transition: all .2s;
}
.cob-popup-close:hover { background: #f3f4f6; color: #374151; }

/* Popup Content */
.cob-popup-content { padding: 20px; }

/* Section Titles */
.cob-section-title {
    background: #fbbf24; color: #fff; padding: 8px 16px; border-radius: 8px;
    font-size: 14px; font-weight: 600; margin: 0 0 16px 0; text-align: center;
    text-transform: uppercase; letter-spacing: .5px;
}

/* Quantity Offers */
.cob-quantity-offers { margin-bottom: 24px; }
.cob-quantity-option {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px; border: 2px solid #e5e7eb; border-radius: 12px; margin-bottom: 8px;
    cursor: pointer; transition: all .2s; position: relative;
}
.cob-quantity-option:hover {
    border-color: #3b82f6; transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59,130,246,.15);
}
.cob-quantity-option.selected {
    border-color: #10b981; background: #f0fdf4;
    box-shadow: 0 4px 12px rgba(16,185,129,.15);
}
.cob-quantity-content { display: flex; align-items: center; gap: 12px; }
.cob-product-image { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.cob-quantity-info { display: flex; flex-direction: column; gap: 2px; }
.cob-quantity-text { font-weight: 600; color: #1f2937; font-size: 14px; }
.cob-quantity-discount {
    background: #dc2626; color: #fff; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 600; width: fit-content;
}
.cob-original-price { text-decoration: line-through; color: #9ca3af; font-size: 12px; }
.cob-quantity-price { font-weight: 700; color: #1f2937; font-size: 16px; }

/* Shipping Options */
.cob-shipping-section { margin-bottom: 24px; }
.cob-shipping-option { margin-bottom: 8px; }
.cob-shipping-option input[type="radio"] { display: none; }
.cob-shipping-option label {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px; border: 2px solid #e5e7eb; border-radius: 8px; cursor: pointer; transition: all .2s;
}
.cob-shipping-option input[type="radio"]:checked + label { border-color: #3b82f6; background: #eff6ff; }
.cob-shipping-name { font-weight: 600; color: #1f2937; }
.cob-shipping-time { color: #6b7280; font-size: 14px; }
.cob-shipping-price { font-weight: 600; color: #059669; }

/* Form Styles */
.cob-form { margin-top: 20px; }
.cob-form-group { margin-bottom: 16px; }
.cob-form-row { display: flex; gap: 12px; }
.cob-form-row .cob-form-group { flex: 1; }
.cob-form-group label {
    display: block; margin-bottom: 6px; font-weight: 600; color: #374151; font-size: 14px;
}

/* --- 🔥 ASTERISK (*) FOR REQUIRED FIELDS 🔥 --- */
/* هذا الكود كيضيف نجمة حمراء أوتوماتيكياً لأي خانة فيها required */
.cob-form-group label:has(+ .cob-input-group input[required]):after,
.cob-form-group label:has(+ .cob-input-group select[required]):after {
    content: " *";
    color: #dc2626;
    font-weight: bold;
    margin-left: 4px;
}

/* --- 🔥 إعداد مجموعة الإدخال وإصلاح التداخل --- */
.cob-input-group { 
    position: relative; 
    display: flex; 
    align-items: center; 
}

.cob-input-icon { 
    position: absolute; 
    left: 15px; 
    z-index: 10; 
    font-size: 18px; 
    color: #6b7280; 
    pointer-events: none; /* يمنع التداخل مع الكليك */
}

/* فرض مسافة 50px من اليسار لضمان عدم ملامسة النص للأيقونة */
.cob-input-group input,
.cob-input-group select {
    width: 100%; 
    padding: 14px 12px 14px 50px !important; /* المسافة الذهبية لمنع التداخل */
    border: 2px solid #e5e7eb; 
    border-radius: 10px;
    font-size: 16px; 
    transition: all .2s;
    background-color: #ffffff !important;
    color: #1f2937 !important; /* لون نص واضح للزبون */
    -webkit-appearance: none; 
    appearance: none;
    height: 50px; /* توحيد الطول */
}

/* إصلاح سهم الـ Select في آيفون وتنسيقه لغواتيمالا */
.cob-input-group select {
    -webkit-text-fill-color: #1f2937 !important;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2212%22%20height%3D%2212%22%20viewBox%3D%220%200%2012%2012%22%3E%3Cpath%20fill%3D%22%236b7280%22%20d%3D%22M10.293%203.293L6%207.586%201.707%203.293A1%201%200%2000.293%204.707l5%205a1%201%200%20001.414%200l5-5a1%201%200%2010-1.414-1.414z%22%2F%3E%3C%2Fsvg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 14px center !important;
    background-size: 12px !important;
}

/* حالة القائمة المعطلة (قبل اختيار الإقليم) */
.cob-input-group select:disabled {
    background-color: #f3f4f6 !important;
    cursor: not-allowed;
    opacity: 0.7;
}

.cob-input-group input:focus,
.cob-input-group select:focus {
    outline: none; 
    border-color: #3b82f6; 
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .1);
    color: #000 !important;
}

/* Upsells */
.cob-upsells-section { margin: 24px 0; }
.cob-upsell-item { margin-bottom: 12px; }
.cob-upsell-item label {
    display: flex; align-items: flex-start; gap: 12px; padding: 16px; border: 2px solid #e5e7eb;
    border-radius: 12px; cursor: pointer; transition: all .2s; margin-bottom: 0;
}
.cob-upsell-item label:hover { border-color: #10b981; background: #f0fdf4; }
.cob-upsell-item input[type="checkbox"] { margin-top: 2px; width: 18px; height: 18px; accent-color: #10b981; }
.cob-upsell-content { display: flex; align-items: flex-start; gap: 12px; flex: 1; }
.cob-upsell-icon { font-size: 20px; margin-top: 2px; }
.cob-upsell-info { display: flex; flex-direction: column; gap: 4px; }
.cob-upsell-name { font-weight: 600; color: #1f2937; font-size: 14px; }
.cob-upsell-description { color: #6b7280; font-size: 12px; line-height: 1.4; }

/* Order Summary */
.cob-order-summary {
    background: #f8fafc; padding: 16px; border-radius: 12px; margin: 24px 0;
}
.cob-summary-row { display: flex; justify-content: space-between; margin-bottom: 8px; color: #374151; }
.cob-summary-row:last-child { margin-bottom: 0; }
.cob-total-row { border-top: 1px solid #e5e7eb; padding-top: 8px; font-weight: 700; font-size: 16px; color: #1f2937; }

/* Submit Button */
.cob-submit-btn {
    width: 100%; background: linear-gradient(135deg,#1f2937 0%,#374151 100%);
    color: #fff; border: none; padding: 16px; border-radius: 12px; font-size: 16px; font-weight: 600;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: all .2s; margin-top: 20px;
}
.cob-submit-btn:hover {
    background: linear-gradient(135deg,#374151 0%,#4b5563 100%);
    transform: translateY(-1px); box-shadow: 0 8px 25px rgba(31,41,55,.25);
}
.cob-submit-btn:active { transform: translateY(0); }
.cob-submit-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.cob-btn-icon { font-size: 18px; }

/* Downsell Popup */
.cob-downsell-popup .cob-popup { max-width: 400px; text-align: center; }

.cob-downsell-popup .cob-popup-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.cob-downsell-content { padding: 30px 20px; }

.cob-downsell-header h3 {
    color: #dc2626; font-size: 24px; margin: 0 0 8px 0; font-weight: 700; text-align: center;
}
.cob-downsell-header p { color: #6b7280; margin: 0 0 16px 0; text-align: center; }
.cob-downsell-header h2 {
    color: #1f2937; font-size: 20px; margin: 0 0 24px 0; font-weight: 600; text-align: center;
}

.cob-downsell-discount {
    margin: 20px 0;
    display: flex;
    justify-content: center;
}

/* Badge */
.cob-discount-badge {
    display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
    width: 100px; height: 100px; background: linear-gradient(135deg,#dc2626 0%,#ef4444 100%);
    border-radius: 50%; color: #fff; position: relative;
}
.cob-discount-badge::after {
    content: ''; position: absolute; top: -8px; right: -8px; width: 0; height: 0;
    border-left: 20px solid transparent; border-right: 20px solid transparent; border-bottom: 30px solid #fbbf24;
    transform: rotate(45deg);
}
.cob-discount-percent { font-size: 28px; font-weight: 700; line-height: 1; }
.cob-discount-text { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }

.cob-downsell-question { color: #374151; margin: 24px 0; font-size: 16px; }

.cob-downsell-buttons {
    display: flex; flex-direction: column; gap: 12px;
    align-items: center;
    width: 100%;
}
.cob-downsell-buttons .cob-downsell-btn {
    width: 80%;
    max-width: 320px;
    text-align: center;
}

.cob-downsell-btn {
    padding: 14px 20px; border-radius: 8px; font-weight: 600; cursor: pointer; transition: all .2s; border: none; font-size: 14px;
}
.cob-downsell-accept {
    background: linear-gradient(135deg,#dc2626 0%,#ef4444 100%); color: #fff;
}
.cob-downsell-accept:hover {
    background: linear-gradient(135deg,#b91c1c 0%,#dc2626 100%);
    transform: translateY(-1px); box-shadow: 0 6px 20px rgba(220,38,38,.3);
}
.cob-downsell-decline { background: #f3f4f6; color: #6b7280; border: 1px solid #d1d5db; }
.cob-downsell-decline:hover { background: #e5e7eb; color: #374151; }

/* Loading States */
.cob-loading { position: relative; overflow: hidden; }
.cob-loading::after {
    content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
    background: linear-gradient(90deg,transparent,rgba(255,255,255,.4),transparent);
    animation: cobShimmer 1.5s infinite;
}

/* Animations */
@keyframes cobFadeIn { from {opacity:0;} to {opacity:1;} }
@keyframes cobSlideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes cobShimmer { 0%{left:-100%;} 100%{left:100%;} }

/* Mobile Responsive */
@media (max-width: 768px) {
    .cob-popup { 
        width: 95%; 
        max-height: 92vh !important; /* طول مناسب للشاشات الصغيرة */
        margin: auto;
    }
    .cob-popup-content { padding: 16px; }
    .cob-form-row { flex-direction: column; gap: 0; }
    .cob-input-group select, .cob-input-group input { font-size: 16px !important; } /* منع التكبير في الآيفون */
}

/* --- ⚠️ ستايل رسائل الخطأ (Error Messages) --- */
/* هذا هو الجزء اللي كان ناقص وزدتو ليك دابا */
.cob-field-error {
    color: #dc2626;       /* لون أحمر */
    font-size: 12px;      /* خط صغير */
    margin-top: 5px;      /* مسافة صغيرة من الفوق */
    font-weight: 600;
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

/* إطار أحمر للخانة اللي فيها المشكل */
.cob-input-group.has-error input, 
.cob-input-group.has-error select {
    border-color: #dc2626 !important;
    background-color: #fff5f5 !important; /* خلفية حمرة خفيفة */
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
}

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