/**
 * Background Settings Styles
 *
 * Styles for the Background Settings section in popup editor
 * Scoped to .ipb-background-settings to avoid affecting other sections
 */

/* Background Settings Section - 2-Column Layout */
.ipb-background-settings {
    text-align: left;
}

/* Restore visible outer spacing for Add New popup background panel only */
.ipb-background-settings.ipb-background-settings-new {
    margin: 0 20px 20px;
}

.ipb-background-row {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
}

.ipb-background-row:last-child {
    margin-bottom: 0;
}

.ipb-background-label {
    align-self: center;
    text-align: left;
}

.ipb-background-label label {
    font-size: 14px;
    font-weight: 500;
    color: #1d2327;
    margin: 0;
    line-height: 1.4;
    text-align: left;
}

.ipb-background-control {
    display: flex;
    flex-direction: column;
    gap: 0;
    align-self: center;
    text-align: left;
}

.ipb-background-control .regular-text {
    width: 100%;
    max-width: 100%;
}

/* Select Background dropdown: half-width on desktop (Add + Edit) */
.ipb-background-settings #background_selection.regular-text {
    width: 50%;
    max-width: 50%;
}

/* Opacity controls: keep same horizontal footprint as Select Background */
.ipb-background-settings #backcolor_opacity,
.ipb-background-settings #backimage_opacity {
    width: calc(50% - 92px) !important;
    flex: 0 0 calc(50% - 92px) !important;
}

.ipb-background-helper {
    margin: 8px 0 0 0;
    font-size: 12px;
    color: #646970;
    line-height: 1.4;
    text-align: left;
}

/* Master Toggle Row */
.ipb-background-row .ipb-background-control .input.toggle.switch {
    margin: 0;
    align-self: flex-start;
}

.ipb-background-row .ipb-background-control .ipb-background-helper {
    margin-top: 8px;
}

/* Toggle Switch Styles - Use Original WordPress-native Styles */
.ipb-background-settings .input.toggle.switch {
    flex: 0 0 auto;
    width: 38px !important;
    height: 22px;
    padding: 1px 5px !important;
}

/* Input Styles */
.ipb-background-settings input[type="color"] {
    width: 80px;
    height: 40px;
    padding: 2px;
    border: 1px solid #8c8f94;
    border-radius: 2px;
    cursor: pointer;
}

.ipb-background-settings input[type="file"] {
    height: 40px;
    padding: 0 8px;
    border: 1px solid #8c8f94;
    border-radius: 2px;
    font-size: 14px;
    color: #2c3338;
    background-color: #fff;
}

.ipb-background-settings input[type="file"]:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
    outline: none;
}

.ipb-background-settings select.regular-text {
    height: 40px;
    padding: 0 12px;
    border: 1px solid #8c8f94;
    border-radius: 2px;
    font-size: 14px;
    color: #2c3338;
    background-color: #fff;
}

.ipb-background-settings select.regular-text:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
    outline: none;
}

/* Range Slider Styles */
.ipb-background-settings input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.ipb-background-settings input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #2271b1;
    cursor: pointer;
}

.ipb-background-settings input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #2271b1;
    cursor: pointer;
    border: none;
}

.ipb-background-settings input[type="range"]:focus {
    outline: none;
}

.ipb-background-settings input[type="range"]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.2);
}

.ipb-background-settings input[type="range"]:focus::-moz-range-thumb {
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.2);
}

/* Number Input Styles */
.ipb-background-settings input[type="number"] {
    height: 40px;
    padding: 0 8px;
    border: 1px solid #8c8f94;
    border-radius: 2px;
    font-size: 14px;
    color: #2c3338;
    background-color: #fff;
    text-align: center;
    transition: border-color 0.15s ease-in-out;
}

.ipb-background-settings input[type="number"]:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
    outline: none;
}

/* Image Preview (must override any legacy global img.ipb_back_img rules) */
.ipb-background-settings .ipb_back_img {
    position: relative;
    top: auto;
    left: auto;
    display: block;
    width: auto;
    max-width: 200px;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-top: 8px;
}

.ipb-background-settings .ipb-background-selected-summary {
    margin: 4px 0 0;
    font-size: 13px;
    color: #50575e;
    word-break: break-all;
}

.ipb-background-settings .ipb-background-selected-summary.is-empty {
    display: none;
}

/* Background Content Wrapper */
.ipb-background-content {
    margin-top: 0;
    clear: both;
}

/* Responsive Adjustments */
@media (max-width: 782px) {
    .ipb-background-settings #background_selection.regular-text {
        width: 100%;
        max-width: 100%;
    }

    .ipb-background-settings #backcolor_opacity,
    .ipb-background-settings #backimage_opacity {
        width: 100% !important;
        flex: 1 1 auto !important;
    }

    .ipb-background-row {
        grid-template-columns: 1fr;
        gap: 8px;
        align-items: flex-start;
    }
    
    .ipb-background-label {
        align-self: flex-start;
    }
    
    .ipb-background-control {
        align-self: flex-start;
    }
}
