/* Desktop Environment */
body {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%) !important;
    margin: 0;
    overflow: hidden !important;
    height: 100vh;
}

#desktop-environment {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

#desktop-window {
    position: absolute;
    width: 940px;
    height: 690px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg);
    border-radius: 12px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.15);
    transition: width 0.3s, height 0.3s, border-radius 0.3s;
    z-index: 100;
    contain: paint; /* Forces it to be a containing block for fixed elements */
}

#desktop-window.maximized {
    width: 100vw !important;
    height: 100vh !important;
    left: 0 !important;
    top: 0 !important;
    transform: none !important;
    border-radius: 0;
}

#desktop-titlebar {
    height: 42px;
    background: #111a2c;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    user-select: none;
    cursor: grab;
    border-bottom: 1px solid #263550;
    flex-shrink: 0;
}

#desktop-titlebar:active {
    cursor: grabbing;
}

.desktop-title {
    color: #eef3fb;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.desktop-title span.size-badge {
    background: #3ecf8e;
    color: #000;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: bold;
}

.desktop-controls {
    display: flex;
    gap: 8px;
}

.win-btn {
    background: rgba(255,255,255,0.05);
    border: none;
    color: #eef3fb;
    font-size: 14px;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: 0.2s;
}

.win-btn:hover {
    background: rgba(255,255,255,0.15);
}

.win-close-btn:hover {
    background: #ff5f56 !important;
    color: #fff;
}

#desktop-content {
    flex: 1;
    position: relative;
    overflow: hidden; /* Changed to hidden to let inner app handle scroll */
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

/* ---------------------------------
   Overrides to fit desktop mode
--------------------------------- */
.auth-gate {
    position: absolute !important;
    inset: 0 !important;
    height: 100% !important;
    min-height: 100% !important;
    padding: 0 !important; /* Optional: remove outer padding if you want it flush */
}

.furniture-login-window {
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    border-radius: 0 !important;
    border: none !important;
}

.app {
    height: 100% !important;
    min-height: 100% !important;
    flex: 1;
}

.app > aside {
    height: 100% !important;
}

main {
    height: 100% !important;
}

#content {
    min-height: calc(100% - 76px) !important; /* 76px is header height */
}

/* Adjustments for contained app */
#toast {
    position: absolute !important;
}
.modal {
    position: absolute !important;
}


/* Mobile Responsiveness */
@media (max-width: 950px) {
    #desktop-window {
        width: 100vw !important;
        height: 100vh !important;
        left: 0 !important;
        top: 0 !important;
        transform: none !important;
        border-radius: 0;
    }
    body {
        background: var(--bg) !important;
    }
    #desktop-titlebar {
        border-radius: 0;
    }
}

/* Resize Handles */
.resizer {
    position: absolute;
    z-index: 1000;
}
.resizer-n { top: -2px; left: 10px; right: 10px; height: 6px; cursor: n-resize; }
.resizer-s { bottom: -2px; left: 10px; right: 10px; height: 6px; cursor: s-resize; }
.resizer-e { top: 10px; bottom: 10px; right: -2px; width: 6px; cursor: e-resize; }
.resizer-w { top: 10px; bottom: 10px; left: -2px; width: 6px; cursor: w-resize; }
.resizer-ne { top: -2px; right: -2px; width: 12px; height: 12px; cursor: ne-resize; }
.resizer-nw { top: -2px; left: -2px; width: 12px; height: 12px; cursor: nw-resize; }
.resizer-se { bottom: -2px; right: -2px; width: 12px; height: 12px; cursor: se-resize; }
.resizer-sw { bottom: -2px; left: -2px; width: 12px; height: 12px; cursor: sw-resize; }


/* Mobile Responsiveness & Fixes */
@media (max-width: 950px) {
    /* Title bar fix to prevent overlap/wrapping */
    .desktop-title {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .desktop-title span.size-badge {
        font-size: 9px;
        padding: 2px 5px;
    }

    /* Override original fixed 900px width */
    .app {
        min-width: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
    }

    /* Sidebar to Top Horizontal Bar */
    .app > aside {
        width: 100% !important;
        height: auto !important;
        flex-direction: row !important;
        align-items: center;
        padding: 8px 10px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--line);
        flex-wrap: wrap;
        gap: 5px !important;
    }

    /* Hide less important sidebar items on mobile */
    .logo b, .logo small, .side-contact, .local-ready, .side-foot {
        display: none !important;
    }

    /* Make navigation scroll horizontally */
    nav {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        width: 100%;
        gap: 5px;
        padding-bottom: 2px;
    }

    nav::-webkit-scrollbar {
        height: 4px;
    }
    nav::-webkit-scrollbar-thumb {
        background: #263550;
        border-radius: 4px;
    }

    .navbtn {
        white-space: nowrap !important;
        padding: 8px 12px !important;
        font-size: 11px !important;
        background: #121c2e;
    }

    /* Adjust main content */
    main {
        width: 100% !important;
        flex: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    #content {
        padding: 10px !important;
        min-height: auto !important;
    }

    header {
        padding: 0 10px !important;
        height: auto !important;
        min-height: 56px;
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Make all grids responsive (stack them) */
    .cards {
        grid-template-columns: 1fr !important;
    }
    .grid2, .grid3, .dashboard-middle, .calc-grid, .detail-grid, .form-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }

    /* Tables scroll horizontally */
    .table-wrap {
        width: 100%;
        overflow-x: auto;
    }
    
    /* Login Page Mobile Fixes */
    .furniture-login-window {
        display: flex !important;
        flex-direction: column !important;
    }
    .login-visual {
        display: none !important;
    }
}
@media (max-width: 950px) {
    .quick-grid {
        display: flex !important;
        flex-direction: column !important;
    }
}

/* Print Preview Support */
@media print {
    body {
        background: #fff !important;
        overflow: visible !important;
        height: auto !important;
    }
    
    #desktop-environment, 
    #desktop-window, 
    #desktop-content,
    .app,
    main {
        position: static !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        transform: none !important;
        left: 0 !important;
        top: 0 !important;
        box-shadow: none !important;
        border: none !important;
        display: block !important;
        background: transparent !important;
    }
    
    #desktop-titlebar,
    .resizer,
    .win-btn {
        display: none !important;
    }

    #content {
        min-height: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }
    
    .table-wrap {
        overflow: visible !important;
    }
}

/* Fix for Modals going behind desktop window */
.modal {
    z-index: 99999 !important;
}

/* Hide action columns in print */
@media print {
    .table th:last-child,
    .table td:last-child {
        display: none !important;
    }
}
