/* Background Image Grid Styles */
#background-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 10px;
    padding: 15px;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    margin: 10px 0;
}

.grid-item {
    aspect-ratio: 16/9;
    background-size: cover;
    background-position: center;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
    overflow: hidden;
    min-height: 75px;
}

.grid-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.grid-item.active {
    border-color: #4CAF50;
    box-shadow: 0 0 0 2px #4CAF50;
}

.grid-item.loading {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.1) 25%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.1) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border: 2px solid rgba(255, 255, 255, 0.1);
    /* Ensure consistent sizing during loading */
    width: 100%;
    height: 100%;
    min-height: 75px;
    aspect-ratio: 16/9;
}

/* Skeleton loading states */
.grid-item.skeleton {
    background: #f0f0f0;
    border: 2px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
}

.grid-item.skeleton::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: skeleton-loading 1.5s infinite;
}

.skeleton-content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.skeleton-image {
    width: 60%;
    height: 60%;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    margin-bottom: 4px;
}

.skeleton-text {
    width: 80%;
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.grid-item.loaded {
    transition: opacity 0.3s ease-in-out;
}

/* Loading container for initial load */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #666;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #4CAF50;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-text {
    font-size: 14px;
    color: #666;
}

/* Error states */
.error-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #f44336;
    font-size: 12px;
}

.error-icon {
    font-size: 20px;
    margin-bottom: 4px;
}

.error-text {
    font-size: 10px;
    text-align: center;
}

/* Animations */
@keyframes skeleton-loading {
    0% {
        left: -100%;
    }

    100% {
        left: 100%;
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.grid-item.error {
    background: #ffebee;
    border: 2px solid #f44336;
    opacity: 0.7;
}

.grid-item.error::after {
    content: '!';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #f44336;
    font-size: 24px;
    font-weight: bold;
}


/* Solid Color Toggle Section */
.solid-color-toggle-section {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 30px !important;
}

.toggle-label {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 500;
    margin: 0;
    flex: 1;
}

.solid-color-toggle-section .toggle-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}

/* Simple Checkbox Styling */
.simple-checkbox-container {
    display: flex;
    align-items: center;
}

.simple-checkbox {
    display: none;
}

.simple-checkbox-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.simple-checkbox-label:hover {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.05);
}

.checkmark {
    color: transparent;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s ease;
    transform: scale(0);
}

.simple-checkbox:checked+.simple-checkbox-label {
    border-color: #4CAF50;
    background: #4CAF50;
}

.simple-checkbox:checked+.simple-checkbox-label .checkmark {
    color: white;
    transform: scale(1);
}

/* Solid Color Section */
.solid-color-section {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.solid-color-picker-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.solid-color-picker-container label {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 500;
}

/* Background Selection Menu - Mobile Optimized */
#background-selection-menu {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    background: rgba(30, 30, 40, 0.95);
    border-radius: 12px;
    padding: 20px;
    z-index: 1000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

/* Mobile-specific background modal styles */
@media (max-width: 767px) {
    #background-selection-menu {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        top: 0;
        left: 0;
        transform: none;
        border-radius: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        background: rgba(15, 23, 42, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    .menu-header {
        padding: 1rem;
        background: rgba(25, 35, 55, 0.9);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        flex-shrink: 0;
    }

    .menu-header h2 {
        font-size: 1.25rem;
        margin: 0;
        color: #a8d5ff;
    }

    .close-menu-btn {
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.1);
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        padding: 0.5rem;
        border-radius: 50%;
        transition: all 0.2s ease;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .close-menu-btn:hover {
        background: rgba(239, 68, 68, 0.2);
        border-color: rgba(239, 68, 68, 0.3);
        color: #fff;
        transform: scale(1.1);
    }

    /* Background tabs for mobile */
    .background-tabs {
        padding: 0 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        flex-shrink: 0;
        background: rgba(25, 35, 55, 0.9);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    .tab-btn {
        padding: 0.75rem 1rem;
        background: none;
        border: none;
        color: #aaa;
        cursor: pointer;
        font-size: 0.9rem;
        font-weight: 500;
        transition: all 0.2s;
        border-bottom: 2px solid transparent;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .tab-btn.active {
        color: #fff;
        border-bottom-color: #4CAF50;
    }

    .tab-btn:hover {
        color: #fff;
    }

    /* Tab content for mobile */
    .tab-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 1rem;
    }

    /* Background grid mobile optimization */
    #background-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 12px;
        padding: 0;
        max-height: none;
        overflow-y: visible;
        margin: 0;
    }

    /* Live wallpaper items mobile - DISABLED (Coming Soon) */

    /* Upload button mobile */
    #menu-custom-upload-btn {
        display: block;
        width: 100%;
        padding: 1rem;
        margin: 1rem 0;
        background: rgba(255, 255, 255, 0.1);
        border: 2px dashed rgba(255, 255, 255, 0.3);
        color: #fff;
        border-radius: 8px;
        cursor: pointer;
        text-align: center;
        transition: all 0.3s;
        font-weight: 500;
        min-height: 44px;
        font-size: 1rem;
    }

    #menu-custom-upload-btn:hover {
        background: rgba(255, 255, 255, 0.15);
        border-color: rgba(255, 255, 255, 0.6);
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }

    /* Custom backgrounds section mobile */
    .custom-backgrounds-section {
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .custom-backgrounds-section h3 {
        color: #fff;
        font-size: 1.1rem;
        margin-bottom: 1rem;
        font-weight: 500;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .custom-backgrounds-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 8px;
        margin-bottom: 1rem;
        max-height: none;
        overflow-y: visible;
        padding: 0;
    }

    .custom-background-item {
        aspect-ratio: 16/9;
        background-size: cover;
        background-position: center;
        border-radius: 6px;
        cursor: pointer;
        transition: transform 0.2s, box-shadow 0.2s;
        border: 2px solid transparent;
        position: relative;
        overflow: hidden;
        min-height: 60px;
    }

    .custom-background-item:hover {
        transform: scale(1.05);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        z-index: 10;
    }

    .custom-background-item.active {
        border-color: #4CAF50;
        box-shadow: 0 0 0 2px #4CAF50;
    }

    .custom-background-item .delete-btn {
        position: absolute;
        top: 4px;
        right: 4px;
        background: #ff4444;
        color: white;
        border: none;
        border-radius: 50%;
        width: 24px;
        height: 24px;
        font-size: 12px;
        cursor: pointer;
        opacity: 0;
        transition: opacity 0.2s;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 24px;
        min-height: 24px;
    }

    .custom-background-item:hover .delete-btn {
        opacity: 1;
    }

    /* Solid color section mobile */
    .solid-color-section {
        margin-bottom: 1rem;
        padding: 1rem;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 8px;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }

    .solid-color-toggle-section {
        margin-bottom: 1rem;
        padding: 1rem;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 8px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .toggle-label {
        color: rgba(255, 255, 255, 0.9);
        font-size: 1rem;
        font-weight: 500;
        margin: 0;
        flex: 1;
    }

    .solid-color-toggle-section .toggle-container {
        display: flex;
        align-items: center;
        gap: 12px;
        margin: 0;
    }

    /* Scrollbar styling for mobile */
    #background-selection-menu::-webkit-scrollbar {
        width: 6px;
    }

    #background-selection-menu::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 3px;
    }

    #background-selection-menu::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 3px;
    }

    #background-selection-menu::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.5);
    }
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.close-menu-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.close-menu-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Background Tabs */
.background-tabs {
    display: flex;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tab-btn {
    padding: 8px 16px;
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: #fff;
    border-bottom-color: #4CAF50;
}

.tab-btn:hover {
    color: #fff;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Live Wallpaper Items - DISABLED (Coming Soon) */

/* Upload Button */
#menu-custom-upload-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    background: rgba(255, 255, 255, 0.1);
    border: 2px dashed rgba(255, 255, 255, 0.3);
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    transition: all 0.3s;
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

#menu-custom-upload-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.6);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#menu-custom-upload-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

#menu-custom-upload-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#bg-upload-input {
    display: none;
}

/* Custom Backgrounds Section */
.custom-backgrounds-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.custom-backgrounds-section h3 {
    color: #fff;
    font-size: 16px;
    margin-bottom: 15px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-backgrounds-section h3::before {
    content: "🎨";
    font-size: 18px;
}

.custom-backgrounds-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 8px;
    margin-bottom: 15px;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 5px;
}

.custom-background-item {
    aspect-ratio: 16/9;
    background-size: cover;
    background-position: center;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
    min-height: 60px;
}

.custom-background-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.custom-background-item.active {
    border-color: #4CAF50;
    box-shadow: 0 0 0 2px #4CAF50;
}

.custom-background-item .delete-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.custom-background-item:hover .delete-btn {
    opacity: 1;
}

.no-custom-backgrounds {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px;
    color: #aaa;
    font-style: italic;
}

.upload-info {
    text-align: center;
    margin-top: 8px;
}

.upload-info small {
    color: #aaa;
    font-size: 11px;
}

/* Fix for invisible images and better error handling */
.custom-background-item {
    background-color: rgba(255, 255, 255, 0.05);
}

.custom-background-item[style*="background-image"] {
    background-color: transparent;
}

/* Loading state for custom backgrounds */
.custom-background-item.loading {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.1) 25%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.1) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    /* Ensure consistent sizing during loading */
    width: 100%;
    height: 100%;
    min-height: 60px;
    aspect-ratio: 16/9;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Better spacing for custom backgrounds section */
.custom-backgrounds-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
}

/* Loading State */
.loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px;
    color: #aaa;
}