/* ==========================================================================
   MAIN CONTAINER LAYOUT
   ========================================================================== */
.imgaipress-bg-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    margin-top: 30px;
}
.imgaipress-change-bg-wrap {
    display: flex;
    gap: 32px;
    width: 100%;
    max-width: 1300px;
}

/* ==========================================================================
   LEFT PANEL: UPLOAD & STYLE CONTROLS
   ========================================================================== */
.imgaipress-bg-left {
    width: 340px;
    background: #fff;
    border: 1px solid #eee;
    padding: 24px 18px 18px 18px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-sizing: border-box;
}

/* Upload Section */
.imgaipress-bg-upload-col {
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
    border-radius: 0;
    margin-bottom: 0;
}
#imgaipress-bg-preview {
    display: none;
    max-width: 100%;
    max-height: 220px;
}
#imgaipress-bg-upload-box {
    border: 2px dashed #ccc;
    border-radius: 8px;
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-bottom: 18px;
    position: relative;
    overflow: hidden;
    transition: width 0.2s, height 0.2s;
    background: #fafbfc;
}
#imgaipress-bg-upload-box:hover {
    border-color: #2196f3;
}
#imgaipress-bg-upload-label {
    color: #888;
    font-size: 16px;
}

/* Style Selection Section */
.imgaipress-bg-style-col {
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
    border-radius: 0;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.imgaipress-bg-style-wrap {
    margin-bottom: 16px;
}
#imgaipress-bg-style-label,
#imgaipress-bg-custom-prompt-label {
    font-weight: 600;
}
#imgaipress-bg-style {
    width: 100%;
    margin-top: 8px;
    height: 30px;
}

/* Generate Button */
#imgaipress-bg-generate {
    margin-top: 20px;
    height: 50px;
    width: 100%;
    font-size: 1.1rem;
    background: linear-gradient(90deg, #212a6e 0%, #0297c6 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    box-shadow: 0 2px 8px #0001;
    transition: opacity 0.2s;
    font-weight: 600;
    padding: 5px 0;
    margin-top: 8px;
}
#imgaipress-bg-generate:hover,
#imgaipress-bg-generate:focus {
    opacity: 0.85;
}

/* Custom Prompt Section */
#imgaipress-bg-custom-prompt-wrap {
    margin-bottom: 16px;
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.2s;
    width: 100%;
}
#imgaipress-bg-custom-prompt-wrap.active {
    opacity: 1;
    pointer-events: auto;
}
#imgaipress-bg-custom-prompt {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    font-size: 1rem;
    padding: 8px 12px;
    border-radius: 5px;
    border: 1px solid #ddd;
    box-sizing: border-box;
    margin-top: 6px;
}

/* Color Picker Section */
#imgaipress-bg-color-wrap {
    margin-bottom: 12px;
    display: none;
}
#imgaipress-bg-color-wrap label {
    font-weight: 600;
}
#imgaipress-bg-color {
    margin-left: 8px;
    vertical-align: middle;
    width: 38px;
    height: 40px;
    border: none;
    padding: 0;
    border-radius: 0;
}

/* ==========================================================================
   RIGHT PANEL: RESULT DISPLAY
   ========================================================================== */
.imgaipress-bg-right {
    display: grid;
    align-items: center;
    flex: 1;
    min-width: 320px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 24px;
    min-height: 320px;
    overflow: auto; /* Prevent overflow */
}
#imgaipress-bg-right-result {
    margin-top: 0;
}

/* ==========================================================================
   BEFORE/AFTER IMAGE COMPARISON
   ========================================================================== */
.imgaipress-before-after-container {
    position: relative;
    margin: 0 auto;
    max-width: 100%;
    user-select: none;
}
.imgaipress-before-after-imgwrap {
    position: relative;
    display: block;
    margin: 0 auto;
    background: 
        linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%),
        linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%);
    background-size: 32px 32px;
    background-position: 0 0, 16px 16px;
    overflow: hidden;
    max-width: 850px;
    max-height: 700px;
    width: 100%;
    height: auto;
}
.imgaipress-before-after-imgwrap img {
    display: block;
    pointer-events: none;
    user-drag: none;
    user-select: none;
}
.imgaipress-before-img {
    position: absolute;
    left: 0; top: 0;
    z-index: 1;
}
.imgaipress-after-img-clip {
    position: absolute;
    left: 0; top: 0;
    z-index: 2;
    overflow: hidden;
    width: 50%;
    height: 100%;
}
.imgaipress-after-img {
    position: absolute;
    left: 0; top: 0;
}
.imgaipress-before-after-handle {
    position: absolute;
    top: 0;
    z-index: 10;
    height: 100%;
    background: none;
    border: 0;
    padding: 0;
    pointer-events: all;
    appearance: none;
    outline: 0;
    transform: translate3d(-50%, 0, 0);
    cursor: ew-resize;
}
.__rcs-handle-root {
    display: flex;
    flex-direction: column;
    place-items: center;
    height: 100%;
    cursor: ew-resize;
    pointer-events: none;
    color: #fff;
}
.__rcs-handle-line {
    flex-grow: 1;
    height: 100%;
    width: 2px;
    background-color: currentcolor;
    pointer-events: auto;
    box-shadow: rgba(0,0,0,0.5) 0 0 4px;
}
.__rcs-handle-button {
    display: grid;
    grid-auto-flow: column;
    gap: 8px;
    place-content: center;
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border-style: solid;
    border-width: 2px;
    pointer-events: auto;
    backdrop-filter: blur(7px);
    background-color: rgba(0,0,0,0.125);
    box-shadow: rgba(0,0,0,0.35) 0 0 4px;
}
.__rcs-handle-arrow {
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-right: 10px solid;
    border-bottom: 8px solid transparent;
}
.imgaipress-before-after-label {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 15px;
    font-weight: bold;
    background: rgba(0,0,0,0.5);
    color: #fff;
    padding: 2px 12px;
    border-radius: 6px;
    z-index: 20;
    pointer-events: none;
    text-shadow: 0 1px 2px #000;
}
.imgaipress-before-after-label.before {
    left: 18px;
}
.imgaipress-before-after-label.after {
    right: 18px;
}
/* ==========================================================================
   IMAGE POPUP MODAL
   ========================================================================== */
.imgaipress-bg-image-popup-overlay {
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: popupIn 0.2s;
}
.imgaipress-bg-image-popup {
    /* Tăng kích thước popup */
    background: #fff;
    min-width: 320px;
    max-width: 900px;
    width: 95vw;
    max-height: 90vh;
    padding: 32px 32px 24px 32px;
    border-radius: 8px;
    box-shadow: 0 8px 32px #0003;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    animation: popupIn 0.2s;
}
.imgaipress-bg-image-popup img {
    max-width: 100%;
    max-height: 70vh; /* tăng lên nếu muốn */
    border-radius: 8px;
    box-shadow: 0 2px 8px #0001;
    margin-bottom: 20px;
    margin-top: 10px;
    background-image: 
        linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%),
        linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%);
    background-size: 32px 32px;
    background-position: 0 0, 16px 16px;
}
.imgaipress-bg-image-popup-actions {
    display: flex;
    gap: 18px;
    justify-content: center;
    width: 100%;
    margin-top: 0;
}
.imgaipress-bg-image-popup-actions .button {
    min-width: 105px;
    font-size: 1rem;
    padding: 0px 0;
}
.imgaipress-bg-image-popup-actions .button-primary {
    font-size: 16px;
    height: 46px;
    padding: 6px 22px;
    border-radius: 6px;
    border: none;
    background: linear-gradient(90deg, #212a6e 0%, #0297c6 100%);
    color: #fff;
    transition: opacity 0.2s;
}
.imgaipress-bg-image-popup-actions .button-primary:hover {
    opacity: 0.85;
}
.imgaipress-bg-image-popup-actions .button-danger {
    font-size: 16px;
    padding: 6px 22px;
    border-radius: 6px;
    border: none;
    background: #616161;
    color: #fff;
    transition: 0.2s;
}
.imgaipress-bg-image-popup-actions .button-danger:hover {
    background: #414141;
    color: #fff;
}
.imgaipress-bg-image-popup-close {
    position: absolute;
    top: 0px;
    right: 12px;
    font-size: 2rem;
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    z-index: 10;
    transition: color 0.2s;
}
.imgaipress-bg-image-popup-close:hover {
    color: #e74c3c;
}
@keyframes popupIn {
    from { opacity: 0; transform: scale(0.98);}
    to { opacity: 1; transform: scale(1);}
}

/* ==========================================================================
   RESULT GRID
   ========================================================================== */
#imgaipress-bg-result-grid {
    column-count: 4;
    column-gap: 18px;
    margin-top: 40px;
}
.imgaipress-bg-image-col {
    display: block;
    margin-bottom: 16px;
    break-inside: avoid;
}
.imgaipress-bg-image-box {
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: #fff;
    background-image: 
        linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%),
        linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%);
    background-size: 32px 32px;
    background-position: 0 0, 16px 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    flex-direction: column;
}
.imgaipress-bg-image-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 10px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 2;
}
.imgaipress-bg-image-box:hover .imgaipress-bg-image-controls {
    opacity: 1;
}
.imgaipress-bg-image-download, .imgaipress-bg-image-remove {
    width: 30px;
    height: 30px;
    display: inline-block;
    vertical-align: middle;
    transition: transform 0.18s;
}
.imgaipress-bg-image-download:hover, .imgaipress-bg-image-remove:hover {
    transform: scale(1.2);
}
.imgaipress-bg-image-box img {
    max-width: 100%;
    height: auto;
}
.imgaipress-bg-image-box.has-image {
    aspect-ratio: unset;
    height: auto;
    min-height: 0;
}

/* ==========================================================================
   LOADING SPINNER
   ========================================================================== */
.imgaipress-ai-image-progress {
    width: 48px;
    height: 48px;
    border: 5px solid #ddd;
    border-top: 5px solid #2271b1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: auto;
}
@keyframes spin {
    100% { transform: rotate(360deg);}
}

/* ==========================================================================
   REMOVE IMAGE BUTTON
   ========================================================================== */
#imgaipress-bg-remove-img {
    display: none;
    border: none;
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    width: 28px;
    height: 28px;
    cursor: pointer;
    z-index: 2;
}

.imgaipress-bg-remove-img-icon {
    width: 24px;
    height: 24px;
    pointer-events: none;
}

/* ==========================================================================
   CREDIT BOX
   ========================================================================== */
.imgaipress-bg-credit-box {
    position: absolute;
    right: 40px;
    background: #f0f7ff;
    color: #2271b1;
    border: 1px solid #b6d4fa;
    border-radius: 8px;
    padding: 8px 18px;
    font-size: 1.08rem;
    font-weight: 600;
    box-shadow: 0 2px 12px rgba(34,113,177,0.07);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 30;
}
.imgaipress-bg-credit-box span#imgaipress-bg-credit-value {
    font-size: 1.12em;
}
/* ==========================================================================
   GENERAL IMPROVEMENTS
   ========================================================================== */
.imgaipress-bg-left,
.imgaipress-bg-right,
.imgaipress-bg-container,
.imgaipress-change-bg-wrap {
    box-sizing: border-box;
}
.imgaipress-bg-image-box img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ==========================================================================
   RESPONSIVE STYLES
   ========================================================================== */
/* ========================= TABLET ========================= */
@media (max-width: 900px) {
    .imgaipress-change-bg-wrap {
        flex-direction: column;
        gap: 18px;
        width: 100%;
        max-width: 100vw;
    }
    .imgaipress-bg-left,
    .imgaipress-bg-right {
        max-width: 100%;
        width: 100%;
        min-width: unset;
        padding: 18px 10px;
        box-sizing: border-box;
    }
    .imgaipress-bg-left {
        align-items: stretch;
    }
    #imgaipress-bg-result-grid {
        column-count: 2;
        column-gap: 10px;
    }
    .imgaipress-bg-credit-box {
        position: static;
        width: fit-content;
        margin: 8px auto 0px auto;
        right: unset;
        top: unset;
    }
    
}

/* ========================= MOBILE ========================= */
@media (max-width: 600px) {
    .imgaipress-bg-container {
        margin-top: 12px;
    }
    .imgaipress-bg-left,
    .imgaipress-bg-right {
        padding: 10px 2vw;
        border-radius: 6px;
    }
    .imgaipress-bg-left {
        gap: 12px;
        min-width: unset;
        width: 100%;
        max-width: 100%;
    }
    .imgaipress-bg-upload-col #imgaipress-bg-upload-box {
        height: 140px;
        min-height: 100px;
    }
    #imgaipress-bg-preview {
        max-height: 120px;
    }
    .imgaipress-bg-style-col {
        gap: 10px;
    }
    #imgaipress-bg-style,
    #imgaipress-bg-custom-prompt {
        font-size: 1rem;
        padding: 7px 8px;
    }
    #imgaipress-bg-generate {
        font-size: 1rem;
        padding: 8px 0;
        min-height: 40px;
    }
    .imgaipress-bg-credit-box {
        width: fit-content;
        font-size: 1rem;
        padding: 6px 10px;
        border-radius: 6px;
        margin: 8px auto 0px auto;
    }
    .imgaipress-before-after-imgwrap {
        max-width: 98vw;
        min-width: unset;
    }
    #imgaipress-bg-result-grid {
        column-count: 1;
        column-gap: 0;
        width: 100vw;
        padding: 0;
    }
    .imgaipress-bg-image-box {
        min-height: 90px;
        border-radius: 6px;
    }
    .imgaipress-bg-image-popup {
        padding: 12px 4vw 12px 4vw;
        min-width: unset;
        max-width: 98vw;
    }
    .imgaipress-bg-image-popup img {
        max-width: 96vw;
        max-height: 50vh;
    }
    .imgaipress-bg-image-popup-actions .button,
    .imgaipress-bg-image-popup-actions .button-primary,
    .imgaipress-bg-image-popup-actions .button-danger {
        font-size: 0.98rem;
        padding: 6px 10px;
        min-width: 80px;
    }
    .imgaipress-bg-image-popup-close {
        font-size: 1.5rem;
        top: 4px;
        right: 8px;
    }
}