/**
 * Custom Popup Box - نسخه نهایی با هدر ثابت و اسکرول کامل
 */

/* ===== پاپ‌آپ اصلی ===== */
.custom-popup-box {
    position: fixed;
    bottom: 20px;
    z-index: 99999;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.18);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.35s ease;
    max-width: calc(100vw - 30px);
    
    /* محدودیت ارتفاع */
    max-height: 80vh;
    height: auto;
    
    /* overflow در خود پاپ‌آپ */
    overflow: hidden;
    
    box-sizing: border-box;
}

.custom-popup-box.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ===== موقعیت‌ها ===== */
.custom-popup-box.position-right {
    right: 20px;
}

.custom-popup-box.position-left {
    left: 20px;
}

/* ===== محتوای داخلی با ساختار جدید ===== */
.custom-popup-box-inner {
    /* استفاده از flex برای کنترل ارتفاع */
    display: flex;
    flex-direction: column;
    
    /* ارتفاع کامل */
    height: 100%;
    max-height: 80vh;
    
    /* حذف padding از این بخش */
    padding: 0;
    
    box-sizing: border-box;
    overflow: hidden;
}

/* ===== هدر پاپ‌آپ (ثابت) ===== */
.custom-popup-box-header {
    /* هدر همیشه در بالا می‌ماند */
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 20;
    
    /* پس‌زمینه برای پوشش محتوای زیر */
    background: #ffffff;
    
    /* padding و چینش */
    padding: 18px 18px 10px 18px;
    
    /* خط جداکننده در پایین هدر */
    border-bottom: 1px solid #f0f0f0;
    
    /* سایه برای جداسازی بهتر */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    
    /* چینش دکمه بستن */
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

/* ===== دکمه بستن (در هدر ثابت) ===== */
.custom-popup-box-close {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border: none;
    border-radius: 50%;
    background: #f1f1f1;
    font-size: 20px;
    line-height: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    margin: 0;
    z-index: 10;
    
    /* حذف float و استفاده از flex */
    float: none;
    
    color: #666;
}

.custom-popup-box-close:hover {
    background: #e0e0e0;
    transform: scale(1.1);
}

.custom-popup-box-close:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* ===== محتوای پست (بخش اسکرول‌شونده) ===== */
.custom-popup-box-content {
    /* این بخش اسکرول می‌خورد */
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    
    /* padding برای محتوا */
    padding: 15px 18px 18px 18px;
    
    font-size: 14px;
    line-height: 1.7;
    color: #333333;
    
    word-wrap: break-word;
    word-break: break-word;
    
    /* فضای اضافی برای اسکرول */
    padding-bottom: 20px;
}

/* ===== استایل اسکرول بار ===== */
.custom-popup-box-content::-webkit-scrollbar {
    width: 5px;
}

.custom-popup-box-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.custom-popup-box-content::-webkit-scrollbar-thumb {
    background: #d1d1d1;
    border-radius: 10px;
}

.custom-popup-box-content::-webkit-scrollbar-thumb:hover {
    background: #b1b1b1;
}

/* فایرفاکس */
.custom-popup-box-content {
    scrollbar-width: thin;
    scrollbar-color: #d1d1d1 #f1f1f1;
}

/* ===== استایل‌های داخلی محتوا ===== */
.custom-popup-box-content p:last-child {
    margin-bottom: 0;
}

.custom-popup-box-content img {
    max-width: 100%;
    height: auto;
}

.custom-popup-box-content table {
    width: 100%;
    overflow-x: auto;
    display: block;
}

.custom-popup-box-content ul,
.custom-popup-box-content ol {
    padding-left: 20px;
}

.custom-popup-box-content pre,
.custom-popup-box-content code {
    white-space: pre-wrap;
    word-wrap: break-word;
    max-width: 100%;
}

.custom-popup-box-content iframe,
.custom-popup-box-content video {
    max-width: 100%;
}

/* ===== RTL ===== */
.rtl .custom-popup-box-content {
    direction: rtl;
    text-align: right;
}

.rtl .custom-popup-box-content ul,
.rtl .custom-popup-box-content ol {
    padding-left: 0;
    padding-right: 20px;
}

/* دکمه بستن در RTL در سمت چپ */
.rtl .custom-popup-box-header {
    justify-content: flex-start;
}

/* ===== موبایل ===== */
@media (max-width: 767px) {
    .custom-popup-box.mobile-hide {
        display: none !important;
    }
    
    .custom-popup-box {
        bottom: 15px;
        left: 15px;
        right: 15px;
        max-width: calc(100vw - 30px);
        width: auto !important;
        max-height: 70vh;
    }
    
    .custom-popup-box.position-right,
    .custom-popup-box.position-left {
        right: 15px;
        left: 15px;
    }
    
    .rtl .custom-popup-box.position-right,
    .rtl .custom-popup-box.position-left {
        right: 15px;
        left: 15px;
    }
    
    .custom-popup-box-inner {
        max-height: 70vh;
    }
    
    .custom-popup-box-header {
        padding: 12px 12px 8px 12px;
    }
    
    .custom-popup-box-content {
        padding: 10px 12px 15px 12px;
        font-size: 13px;
    }
    
    .custom-popup-box-close {
        width: 28px;
        height: 28px;
        min-width: 28px;
        font-size: 18px;
        line-height: 28px;
    }
}

/* ===== دسکتاپ ===== */
@media (min-width: 768px) {
    .custom-popup-box.desktop-hide {
        display: none !important;
    }
}

/* ===== انیمیشن ===== */
.custom-popup-box.is-visible {
    animation: cpb-fade-in 0.35s ease;
}

@keyframes cpb-fade-in {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}