/**
 * Dynamic Popup Builder - Frontend Styles
 * -----------------------------------------------------------
 */

/* === 1. Trigger (hiển thị ngoài trang) === */
.dyp-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 0;
    border: none;
    border-radius: 0;
    background-color: transparent;
    transition: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.dyp-trigger:hover {
    background-color: transparent;
    box-shadow: none;
}
.dyp-trigger-icon {
    width: 30px;
    height: 30px;
    object-fit: contain;
    flex-shrink: 0;
}
.dyp-trigger-text-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.3;
}
.dyp-trigger-text {
    font-size: 12px;
    font-weight: 500;
    color: #333;
}
.dyp-trigger-desc {
    font-size: 10px;
    font-weight: normal;
    color: #555;
}


/* === 2. Khung Popup chung === */
#dyp-popup-overlay {
    display: none;
}
.dyp-popup-wrapper {
    position: absolute;
    top: -9999px;
    left: -9999px;
    z-index: 99999;
}
.dyp-popup-box {
    position: relative;
    width: 375px;
    max-width: 95vw;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.dyp-popup-box::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 8px;
    border-style: solid;
    border-color: transparent transparent #ffffff transparent;
}

/* === BẮT ĐẦU SỬA LỖI THANH CUỘN === */
.dyp-popup-content {
    /* overflow-y: auto; */ /* <<< THAY ĐỔI: Xóa dòng này */
    padding: 0;
    display: flex; /* <<< THAY ĐỔI: Thêm dòng này để điều khiển layout con */
    flex-direction: column; /* <<< THAY ĐỔI: Thêm dòng này */
    min-height: 0; /* <<< THAY ĐỔI: Thêm dòng này để tương thích flexbox */
}
/* === KẾT THÚC SỬA LỖI THANH CUỘN === */

.dyp-popup-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background-color: transparent;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #888;
    transition: color 0.2s, background-color 0.2s;
    z-index: 2;
    padding: 0;
}
.dyp-popup-close:hover {
    color: #000;
    background-color: transparent;
}

/* === 3. Phần Header của Popup === */
.dyp-popup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: #fff;
    flex-shrink: 0; /* <<< THAY ĐỔI: Thêm dòng này để header không bị co lại */
}
.dyp-header-icon {
    width: 50px;
    height: 50px;
    object-fit: contain;
    flex-shrink: 0;
    position: relative;
    top: -8px;
}
.dyp-header-text-wrapper {
    display: flex;
    flex-direction: column;
}
.dyp-header-title {
    font-size: 18px;
    font-weight: 600;
    color: #111;
    margin: 0 0 2px 0;
    line-height: 1.3;
}
.dyp-header-description {
    margin: 0;
    padding: 0;
    font-size: 14px;
    color: #555;
    line-height: 1.5;
}

.dyp-divider {
    border: none;
    height: 1px;
    background-color: #eee;
    margin: 0;
}

/* === 4. Các Khối Nội dung === */
.dyp-popup-additional-content { /* <<< THAY ĐỔI: Thêm bộ chọn mới này */
    flex-shrink: 0;
}

.dyp-content-blocks-wrapper {
    padding: 0 10px 10px 10px;
    overflow-y: auto; /* <<< THAY ĐỔI: Chuyển thanh cuộn vào đây */
    flex-grow: 1; /* <<< THAY ĐỔI: Cho phép vùng này lấp đầy không gian còn lại */
}

.dyp-content-block {
    display: flex;
    gap: 15px;
    align-items: center;
    padding: 15px 10px;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s;
    border-top: 1px solid #eee;
}
.dyp-content-block:hover {
    background-color: #f9f9f9;
}

[class^="dyp-block-col-"]:empty {
    display: none;
}

.dyp-block-col-1 {
    flex: 0 0 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dyp-block-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.dyp-block-col-2 {
    flex: 3 1 0;
}
.dyp-block-col-3 {
    flex: 2 1 0;
    text-align: right;
}

.dyp-block-col-2 .dyp-block-title,
.dyp-block-col-3 .dyp-block-side-title {
    margin: 0 0 2px 0;
    font-size: 14px;
    font-weight: 500;
    color: #222;
}
.dyp-block-col-2 .dyp-block-content,
.dyp-block-col-3 .dyp-block-side-content {
    margin: 0;
    font-size: 10px;
    color: #666;
    line-height: 1.4;
}

.dyp-block-col-2 > *:last-child {
    margin-bottom: 0;
}

/* Tùy chỉnh giảm cỡ chữ cho Tiêu đề phụ */
.dyp-block-col-3 .dyp-block-side-title {
    font-size: 12px;
}


/* === 5. Loader === */
.dyp-loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 50px auto;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* === 6. Bố cục xếp chồng (Tùy chọn mới) === */
.dyp-content-block.layout-stacked {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
}

.dyp-content-block.layout-stacked .dyp-stacked-top {
    display: flex;
    align-items: center;
    gap: 15px;
}

.dyp-content-block.layout-stacked .dyp-stacked-bottom {
    margin-top: 0;
}

.dyp-content-block.layout-stacked .dyp-block-content {
     margin: 0;
     font-size: 10px;
     color: #666;
     line-height: 1.4;
}

/* CSS NÚT ĐĂNG XUẤT */
.dyp-logout-block {
    font-size: 14px;
    font-weight: 500;
    color: #222;
    transition: color 0.2s;
}
.dyp-logout-block:hover {
    color: #555;
}

/**
 * ===========================================================
 * 7. NÂNG CẤP HIỂN THỊ TRÊN DI ĐỘNG (MOBILE)
 * ===========================================================
 */
@media screen and (max-width: 768px) {

    /* Ngăn cuộn trang nền khi popup đang mở */
    body.dyp-popup-open {
        overflow: hidden;
    }

    /* Lớp phủ mờ phía sau */
    #dyp-popup-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.6);
        z-index: 99998;
    }

    /* Ghi đè cách định vị của JS, chuyển sang chế độ modal */
    .dyp-popup-wrapper {
        position: fixed;
        top: 0 !important;
        left: 0 !important;
        width: 100%;
        height: 100%;
        display: flex !important;
        justify-content: center;
        align-items: flex-end;
        pointer-events: none;
    }

    /* Box popup chính */
    .dyp-popup-box {
        width: 100%;
        max-height: 85vh;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -5px 25px rgba(0,0,0,0.1);
        pointer-events: auto;
        transform: translateY(100%);
        transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    }
    
    body.dyp-popup-open .dyp-popup-box {
        transform: translateY(0);
    }

    .dyp-popup-box::before {
        display: none;
    }

    .dyp-popup-close {
        top: 12px;
        right: 12px;
        font-size: 32px;
        color: #aaa;
    }
    .dyp-popup-close:hover {
        color: #333;
    }
    
    /* Các thay đổi cho mobile đã đúng logic từ trước nên không cần sửa */
    .dyp-popup-content {
        overflow-y: hidden; /* Đúng cho mobile */
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .dyp-popup-header {
        flex-shrink: 0;
        position: static; /* Đúng cho mobile */
    }

    .dyp-content-blocks-wrapper {
        overflow-y: auto;
        flex-grow: 1;
    }
}