/* ========== DESKTOP AREA ========== */
.desktop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(100vh - 50px); /* Trừ đi chiều cao taskbar */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-size: cover;
    background-position: center;
    overflow: hidden;
}

/* ========================================================
   Desktop Icons Container — Auto-flow layout (Windows style)
   ========================================================
   flex-direction: column + flex-wrap: wrap + fixed height
   → icons xếp CỘT từ trên xuống dưới, hết chiều cao thì tự
   nhảy sang cột mới bên phải. Giống Windows Desktop thật sự.

   Icon nào có position: absolute (user đã drag-drop, lưu
   trong localStorage) sẽ tự tách khỏi flow flex, không ảnh
   hưởng các icon còn lại. */
#desktop-icons {
    position: relative;   /* anchor cho children position:absolute */
    padding: 20px;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    align-content: flex-start;
    /* Gap 20px để mỗi ô lưới chiếm đúng 100px (icon) + 20 gap
       = 120px theo trục dọc và 100px + 20 = 120px theo trục ngang.
       (Thực ra icon chỉ cao 108, gap tổng 120-108=12px; trục ngang
       100+20=120px khớp snap-to-grid 120.) */
    gap: 12px 20px;       /* row-gap column-gap */
}

/* Khi icon có vị trí cá nhân (drag-drop đã lưu), nó sẽ dùng
   inline style position:absolute và tách khỏi flex flow. */
.desktop-icon.custom-pos {
    position: absolute !important;
    margin: 0;
}

/* ===== CONTEXT MENU ===== */
.desktop-context-menu {
    position: fixed;
    background: rgba(40, 44, 52, 0.97);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    padding: 6px 0;
    min-width: 200px;
    z-index: 99999;
    font-size: 13px;
    color: #e8e8e8;
    user-select: none;
    animation: desktopCtxFade 0.12s ease-out;
}
@keyframes desktopCtxFade {
    from { opacity: 0; transform: scale(0.95) translateY(-4px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.desktop-context-menu .ctx-item {
    padding: 9px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.1s;
}
.desktop-context-menu .ctx-item:hover {
    background: rgba(102, 126, 234, 0.5);
}
.desktop-context-menu .ctx-item i {
    width: 16px;
    text-align: center;
    opacity: 0.8;
}
.desktop-context-menu .ctx-separator {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 5px 0;
}

/* Desktop Icon — KÍCH THƯỚC CỐ ĐỊNH để các cột flex khớp hàng ngang */
.desktop-icon {
    /* Fix cả width và height → mọi icon chiếm 1 "ô" 100x108.
       Khi flex-wrap column, mọi row ở mọi cột đều cùng y-offset,
       icon thẳng hàng cả dọc lẫn ngang như Windows Desktop thật. */
    width: 100px;
    height: 108px;
    flex: 0 0 108px;       /* flex-basis = 108px trên main-axis (column) */
    box-sizing: border-box;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.desktop-icon:hover {
    transform: scale(1.05);
}

.desktop-icon .icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 6px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    transition: all 0.3s;
    flex-shrink: 0;
}

.desktop-icon:hover .icon {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.desktop-icon .label {
    /* Label clamp max 2 dòng — label dài bị cắt "..."
       height cố định 32px giữ mọi icon cùng cao. */
    color: white;
    font-size: 12px;
    font-weight: 500;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    padding: 0 2px;
    width: 100%;
    height: 32px;
    line-height: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

/* Desktop Icon Selected State */
.desktop-icon.selected .icon {
    border: 2px solid white;
}

.desktop-icon.selected .label {
    background: rgba(255,255,255,0.3);
    border-radius: 4px;
    padding: 2px 8px;
}