/* Desktop Styles */
.desktop {
    width: 100vw;
    height: calc(var(--real-vh, 1vh) * 100);
    min-height: 100dvh;
    background-image: url('../assets/images/zaratexp-hd-wallpaper.png');
    background-image: image-set(
        url('../assets/images/zaratexp-hd-wallpaper.webp') type('image/webp'),
        url('../assets/images/zaratexp-hd-wallpaper.png') type('image/png')
    );
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease-in-out;
}

.wallpaper-default {
    background-image: url('../assets/images/zaratexp-hd-wallpaper.png');
    background-image: image-set(
        url('../assets/images/zaratexp-hd-wallpaper.webp') type('image/webp'),
        url('../assets/images/zaratexp-hd-wallpaper.png') type('image/png')
    );
}

/* Desktop Icons Container */
.desktop-icons {
    padding: 10px;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    height: calc((var(--real-vh, 1vh) * 100) - var(--taskbar-height));
    width: 100%;
    overflow: hidden;
}

/* Desktop Icon */
.desktop-icon {
    width: calc(86px * var(--icon-scale, 1));
    min-height: calc(92px * var(--icon-scale, 1));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    padding: 5px 4px;
    border: 1px solid transparent;
    border-radius: 3px;
    position: absolute;
    transition: background-color 0.1s ease, border-color 0.1s ease, transform 0.08s ease, opacity 0.08s ease;
    -webkit-tap-highlight-color: transparent; /* Eliminar resaltado en Safari */
    -webkit-touch-callout: none; /* Desactivar menú contextual en iOS */
    user-select: none; /* Prevenir selección de texto */
    touch-action: none;
}

.desktop-icon:hover {
    background: rgba(0, 84, 227, 0.2);
    border-color: rgba(0, 84, 227, 0.5);
}

.desktop-icon:hover img {
    transform: translateY(-2px);
    filter: drop-shadow(0 5px 5px rgba(0,0,0,0.42));
}

.desktop-icon:focus-visible {
    outline: 1px dotted #fff;
    outline-offset: -2px;
    background: rgba(0, 84, 227, 0.24);
    border-color: rgba(255, 255, 255, 0.65);
}

.desktop-icon.selected {
    background: rgba(0, 84, 227, 0.3);
    border-color: rgba(0, 84, 227, 0.8);
}

.desktop-icon:active {
    transform: scale(0.98);
}

.desktop-icon:active img {
    transform: translateY(0) scale(0.96);
}

.desktop-icon img {
    width: calc(56px * var(--icon-scale, 1));
    height: calc(56px * var(--icon-scale, 1));
    margin-bottom: 4px;
    object-fit: contain;
    filter: drop-shadow(0 3px 3px rgba(0,0,0,0.35));
    image-rendering: auto;
    transition:
        filter var(--xp-motion-fast) var(--xp-ease-out),
        transform var(--xp-motion-fast) var(--xp-ease-out);
}

.desktop-icon span {
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    font-size: 11px;
    font-family: 'Tahoma', sans-serif;
    display: block;
    word-wrap: break-word;
    line-height: 1.2;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

/* Icon Scale for different screen sizes */
@media (max-width: 1024px) {
    .desktop-icons {
        --icon-scale: 0.9;
    }
    
    .desktop-icon img {
        width: calc(52px * var(--icon-scale));
        height: calc(52px * var(--icon-scale));
    }
}

@media (max-width: 768px) {
    .desktop-icons {
        --icon-scale: 0.8;
        grid-template-rows: repeat(auto-fill, 80px);
    }

    .desktop-icon:not([data-mobile-home="true"]) {
        display: none;
    }

    .desktop-icon[data-mobile-home="true"] {
        display: flex;
    }
    
    .desktop-icon span {
        font-size: 10px;
    }
}

/* Selection Overlay for multi-select */
.selection-overlay {
    position: absolute;
    border: 1px dotted #fff;
    background: rgba(0, 84, 227, 0.2);
    pointer-events: none;
    display: none;
    z-index: 100;
}

/* Context Menu (if needed) */
.context-menu {
    position: fixed;
    background: #ECE9D8;
    border: 1px solid #919B9C;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    padding: 2px;
    z-index: 10001;
    display: none;
    min-width: 178px;
    color: #000;
}

.context-menu[aria-hidden="false"] {
    animation: contextMenuOpen 80ms steps(2, end);
}

.context-menu-item {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    padding: 4px 26px 4px 22px;
    cursor: pointer;
    font-size: 11px;
    font-family: 'Tahoma', sans-serif;
    text-align: left;
    color: #000;
    min-height: 22px;
}

.context-menu-item[hidden] {
    display: none;
}

.context-menu-item:hover:not(:disabled) {
    background: #316AC5;
    color: white;
}

.context-menu-item:focus-visible {
    outline: 1px dotted currentColor;
    outline-offset: -3px;
    background: #316AC5;
    color: #fff;
}

.context-menu-item:active:not(:disabled) {
    transform: translateY(1px);
}

.context-menu-open,
.context-menu-refresh {
    font-weight: 700;
}

.context-menu-item:disabled,
.context-menu-item.disabled {
    color: #8a867a;
    text-shadow: 1px 1px 0 #fff;
}

.context-menu-separator {
    height: 1px;
    background: #D4D0C8;
    margin: 2px 0;
}

.context-menu-separator[hidden] {
    display: none;
}

.desktop-refresh-status {
    position: absolute;
    top: 14px;
    left: 50%;
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 5px 10px;
    border: 1px solid #003c74;
    border-radius: 3px;
    background: #ece9d8;
    box-shadow: 2px 3px 7px rgba(0, 0, 0, 0.36);
    color: #111;
    font: 11px Tahoma, sans-serif;
    pointer-events: none;
    transform: translateX(-50%);
}

.desktop-refresh-status[hidden] {
    display: none;
}

.desktop.is-refreshing::after {
    content: "";
    position: absolute;
    inset: 0 0 var(--taskbar-height) 0;
    z-index: 9998;
    background: rgba(255, 255, 255, 0.14);
    pointer-events: none;
    animation: desktopRefreshFlash 520ms steps(2, end);
}

.desktop.is-refreshing .desktop-icons {
    animation: desktopRefreshIcons 520ms steps(2, end);
}

body.xp-hide-desktop-icons .desktop-icon {
    visibility: hidden;
    opacity: 0 !important;
    pointer-events: none;
}

@keyframes contextMenuOpen {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes desktopRefreshFlash {
    0%, 100% { opacity: 0; }
    28%, 48% { opacity: 1; }
}

@keyframes desktopRefreshIcons {
    0%, 100% { opacity: 1; transform: translateY(0); }
    28%, 48% { opacity: 0; transform: translateY(2px); }
}

/* Desktop Shortcuts Animation */
@keyframes iconAppear {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.94);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.desktop-icon {
    animation: iconAppear 0.18s var(--xp-ease-out);
    animation-fill-mode: both;
}

.desktop-icon:nth-child(1) { animation-delay: 0.03s; }
.desktop-icon:nth-child(2) { animation-delay: 0.06s; }
.desktop-icon:nth-child(3) { animation-delay: 0.09s; }
.desktop-icon:nth-child(4) { animation-delay: 0.12s; }
.desktop-icon:nth-child(5) { animation-delay: 0.15s; }
.desktop-icon:nth-child(6) { animation-delay: 0.18s; }
.desktop-icon:nth-child(7) { animation-delay: 0.21s; }
.desktop-icon:nth-child(8) { animation-delay: 0.24s; }
.desktop-icon:nth-child(9) { animation-delay: 0.27s; }
.desktop-icon:nth-child(10) { animation-delay: 0.3s; }
.desktop-icon:nth-child(11) { animation-delay: 0.33s; }
.desktop-icon:nth-child(12) { animation-delay: 0.36s; }
.desktop-icon:nth-child(13) { animation-delay: 0.39s; }
.desktop-icon:nth-child(14) { animation-delay: 0.42s; }
.desktop-icon:nth-child(15) { animation-delay: 0.45s; }

/* Drag and Drop Styles */
.desktop-icon.dragging {
    opacity: 0.9;
    cursor: grabbing;
    transform: scale(1.05);
    z-index: 900 !important;
    will-change: left, top, transform;
}

.desktop-icon.drag-over {
    background: rgba(0, 84, 227, 0.4);
    border-color: rgba(0, 84, 227, 1);
}

@media (prefers-reduced-motion: reduce) {
    .context-menu[aria-hidden="false"],
    .desktop.is-refreshing::after,
    .desktop.is-refreshing .desktop-icons {
        animation: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .desktop,
    .desktop-icon,
    .desktop-icon img {
        animation: none !important;
        transition: none !important;
    }

    .desktop-icon:hover img,
    .desktop-icon:active img {
        transform: none;
    }
}

/* Responsive Desktop */
@media (max-height: 600px) {
    .desktop-icons {
        grid-template-rows: repeat(auto-fill, 70px);
    }
    
    .desktop-icon {
        min-height: 76px;
    }
    
    .desktop-icon img {
        width: 42px;
        height: 42px;
    }
}

/* High DPI Support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .desktop-icon img {
        image-rendering: auto;
    }
}

/* Print Styles */
@media print {
    .desktop {
        display: none;
    }
}
