/* Window Manager Specific Styles */
#window-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through empty areas to desktop */
    z-index: 10;
}

.window {
    position: absolute;
    min-width: 300px;
    min-height: 200px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    pointer-events: auto; /* Catch clicks on the window itself */
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
    transition: transform 0.2s, opacity 0.2s;
    overflow: hidden;
}

.window.focused {
    box-shadow: 0 8px 30px rgba(0,0,0,0.7);
}

.window.minimized {
    transform: scale(0.1) translateY(500px);
    opacity: 0;
    pointer-events: none;
}

.window.maximized {
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: calc(100% - 40px) !important;
    border-radius: 0;
    transform: none;
}

.window-titlebar {
    height: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 5px 0 10px;
    cursor: default; /* Will be changed to move cursor on drag */
    background: linear-gradient(to bottom, rgba(230, 240, 250, 0.8) 0%, rgba(190, 210, 230, 0.8) 50%, rgba(160, 190, 220, 0.9) 51%, rgba(180, 200, 230, 0.8) 100%);
    border-bottom: 1px solid rgba(255,255,255,0.5);
}

.window.focused .window-titlebar {
    background: linear-gradient(to bottom, rgba(162, 189, 219, 0.8) 0%, rgba(132, 168, 205, 0.8) 50%, rgba(100, 142, 186, 0.9) 51%, rgba(119, 159, 199, 0.8) 100%);
}

.window-title {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    pointer-events: none;
}

.window-title img {
    width: 16px;
    height: 16px;
    margin-right: 8px;
}

.window-controls {
    display: flex;
    gap: 2px;
}

.win-btn {
    width: 25px;
    height: 18px;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 3px;
    background: linear-gradient(to bottom, rgba(255,255,255,0.5) 0%, rgba(200,200,200,0.5) 100%);
    box-shadow: inset 0 1px 1px rgba(255,255,255,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.win-btn:hover {
    background: linear-gradient(to bottom, rgba(255,255,255,0.8) 0%, rgba(220,220,220,0.8) 100%);
}

.win-btn.close {
    background: linear-gradient(to bottom, rgba(250, 150, 150, 0.5) 0%, rgba(200, 50, 50, 0.5) 100%);
    border-color: rgba(200, 0, 0, 0.4);
}

.win-btn.close:hover {
    background: linear-gradient(to bottom, rgba(255, 100, 100, 0.8) 0%, rgba(220, 0, 0, 0.8) 100%);
}

.win-btn svg {
    width: 10px;
    height: 10px;
    fill: #000;
}

.win-btn.close svg {
    fill: #fff;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.5));
}

.window-content {
    flex: 1;
    background: #fff;
    position: relative;
    border: 1px solid rgba(0,0,0,0.2);
    /* For iframe covering */
}

.window-content iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    opacity: 0;
    transition: opacity 0.16s ease;
    background: #fff;
}

.window-content iframe.is-ready {
    opacity: 1;
}

.window-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(to bottom, rgba(250, 252, 255, 0.95), rgba(235, 242, 250, 0.95));
    color: #244b73;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.2px;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.window-loading-label {
    font-size: 12px;
    opacity: 0.9;
}

.window-loading.hidden {
    opacity: 0;
}

.window-loading.error {
    color: #8f1b1b;
    text-align: center;
    padding: 0 20px;
}

.window-loading-spinner {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #9cb6d3;
    border-top-color: #2d7dd2;
    animation: window-spin 0.7s linear infinite;
}

.window-loading.error .window-loading-spinner {
    display: none;
}

@keyframes window-spin {
    to { transform: rotate(360deg); }
}

/* Invisible overlay to prevent iframe stealing mouse events during drag */
.window-drag-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 100;
    display: none;
}

.window.dragging .window-drag-overlay,
.window.resizing .window-drag-overlay {
    display: block;
}

/* Aero Snap specific styles */
.window.snapping {
    transition: transform 0.2s, opacity 0.2s, left 0.15s cubic-bezier(0.2, 0.9, 0.3, 1.1), top 0.15s cubic-bezier(0.2, 0.9, 0.3, 1.1), width 0.15s cubic-bezier(0.2, 0.9, 0.3, 1.1), height 0.15s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

.snap-preview {
    position: absolute;
    border: 4px solid rgba(135, 206, 250, 0.5);
    background: rgba(135, 206, 250, 0.15);
    border-radius: 8px;
    pointer-events: none;
    z-index: 99;
    transition: all 0.15s cubic-bezier(0.2, 0.9, 0.3, 1.1), opacity 0.15s ease;
    opacity: 0;
    box-sizing: border-box;
}

.snap-preview.active {
    opacity: 1;
}

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

@media (max-width: 820px) {
    .window {
        min-width: 0;
        min-height: 140px;
        border-radius: 0;
        box-shadow: 0 3px 14px rgba(0, 0, 0, 0.42);
    }

    .window-titlebar {
        height: 34px;
        padding: 0 4px 0 8px;
    }

    .window-title {
        font-size: 13px;
        max-width: calc(100% - 114px);
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    .window-title img {
        width: 14px;
        height: 14px;
        margin-right: 6px;
    }

    .window-controls {
        gap: 4px;
    }

    .win-btn {
        width: 28px;
        height: 22px;
    }

    .win-btn.maximize {
        display: none;
    }

    .resizer {
        display: none;
    }

    .window.maximized {
        height: calc(100% - 36px) !important;
    }
}
