/* Fondo personalizable de la página principal */
body {
    isolation: isolate;
}

#mainBgLayer,
#mainBgShade {
    position: fixed;
    pointer-events: none;
}

#mainBgLayer {
    inset: -28px;
    z-index: -2;
    background-color: #0f172a;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    filter: blur(var(--main-bg-blur, 4px));
    transform: scale(1.035);
    will-change: filter, background-image;
}

#mainBgShade {
    inset: 0;
    z-index: -1;
    background: rgba(15, 23, 42, 0.35);
}

.main-bg-modal-overlay[hidden] {
    display: none !important;
}

.main-bg-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(4px);
}

.main-bg-modal-content {
    width: min(1100px, 96vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 22px;
    color: #f8fafc;
    background: #0f172a;
    border: 2px solid #334155;
    border-radius: 16px;
    box-shadow: 0 20px 65px rgba(0, 0, 0, 0.55);
}

.main-bg-modal-header,
.main-bg-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.main-bg-modal-header {
    padding-bottom: 14px;
    border-bottom: 1px solid #334155;
}

.main-bg-modal-header h2 {
    margin: 0;
    font-size: clamp(18px, 2vw, 24px);
}

.main-bg-modal-header p,
.main-bg-modal-footer span {
    color: #94a3b8;
    font-size: 13px;
    margin-top: 5px;
}

.main-bg-controls {
    display: grid;
    grid-template-columns: minmax(200px, 0.85fr) minmax(220px, 1.15fr);
    gap: 14px;
    align-items: center;
}

.main-bg-blur-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
    color: #e2e8f0;
}

.main-bg-blur-control input {
    width: 100%;
    accent-color: #3b82f6;
    cursor: pointer;
}

.main-bg-search {
    width: 100%;
    min-width: 0;
    padding: 11px 13px;
    color: #f8fafc;
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 9px;
    outline: none;
    font: inherit;
}

.main-bg-search:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.main-bg-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 12px;
    min-height: 150px;
    max-height: 52vh;
    padding: 3px 5px 5px 2px;
    overflow: auto;
    overscroll-behavior: contain;
}

.main-bg-card {
    position: relative;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 6px;
    text-align: center;
    color: #e2e8f0;
    background: #1e293b;
    border: 2px solid #334155;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.main-bg-card:hover {
    transform: translateY(-2px);
    border-color: #60a5fa;
}

.main-bg-card.selected {
    border-color: #3b82f6;
    background: #1d355f;
    box-shadow: 0 0 0 1px #3b82f6, 0 0 16px rgba(59, 130, 246, 0.2);
}

.main-bg-card img {
    display: block;
    width: 100%;
    height: 86px;
    object-fit: cover;
    border-radius: 5px;
    background: #0f172a;
}

.main-bg-card span {
    overflow: hidden;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.main-bg-card.missing {
    opacity: 0.42;
    cursor: not-allowed;
}

.main-bg-card.missing img::after {
    content: 'No encontrada';
}

.main-bg-modal-footer {
    flex-wrap: wrap;
    padding-top: 12px;
    border-top: 1px solid #334155;
}

#exportImageBtn:disabled {
    opacity: 0.65;
    cursor: wait;
}

@media (max-width: 640px) {
    .main-bg-modal-content {
        padding: 14px;
        gap: 12px;
    }
    .main-bg-controls {
        grid-template-columns: 1fr;
    }
    .main-bg-gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
        max-height: 55vh;
    }
    .main-bg-modal-footer {
        align-items: flex-start;
        flex-direction: column;
    }
}
