/* Window Manager Styles */
.window {
    position: absolute;
    background: var(--window-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.07),
        0 10px 24px rgba(0, 0, 0, 0.14),
        0 20px 48px rgba(0, 0, 0, 0.10);
    display: flex;
    flex-direction: column;
    min-width: 400px;
    min-height: 300px;
    pointer-events: all;
    overflow: hidden;
    transition: box-shadow 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
}

.window.active {
    box-shadow:
        0 6px 10px rgba(0, 0, 0, 0.12),
        0 16px 40px rgba(0, 0, 0, 0.22),
        0 32px 72px rgba(0, 0, 0, 0.16),
        0 0 0 1px var(--border-active);
    border-color: var(--border-active);
}

/* Inactive windows are slightly dimmed */
.window:not(.active) {
    opacity: 0.92;
}

.window.minimized {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.window.maximized {
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: calc(100% - 50px) !important;
    border-radius: 0;
    box-shadow: none;
    border-color: transparent;
}

.window.snapped {
    transition: left 0.18s cubic-bezier(0.2, 0, 0, 1),
                top 0.18s cubic-bezier(0.2, 0, 0, 1),
                width 0.18s cubic-bezier(0.2, 0, 0, 1),
                height 0.18s cubic-bezier(0.2, 0, 0, 1);
}

/* ── Titlebar ─────────────────────────────────────────────── */
.window-titlebar {
    background: var(--window-titlebar);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 0 12px;
    cursor: move;
    user-select: none;
    border-bottom: 1px solid var(--border-color);
    /* top corners match window, bottom is straight */
    border-radius: 9px 9px 0 0;
    flex-shrink: 0;
}

.window.maximized .window-titlebar {
    border-radius: 0;
}

/* Inactive titlebar is noticeably more muted */
.window:not(.active) .window-titlebar {
    opacity: 0.80;
}

.window-titlebar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.window-icon {
    font-size: 15px;
    flex-shrink: 0;
    opacity: 0.85;
}

.window-title {
    color: var(--text-primary);
    font-size: 12.5px;
    font-weight: 500;
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Dim title when inactive */
.window:not(.active) .window-title {
    opacity: 0.55;
}

/* ── Window Controls ──────────────────────────────────────── */
.window-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.window-control {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 400;
    line-height: 1;
    transition: background 0.12s ease, color 0.12s ease, opacity 0.12s ease;
    cursor: pointer;
    opacity: 0.50;
}

.window.active .window-control {
    opacity: 0.70;
}

.window-control:hover {
    opacity: 1 !important;
    background: var(--hover-overlay);
}

.window-control.minimize:hover {
    background: rgba(255, 189, 68, 0.22);
    color: #ffbd44;
}

.window-control.maximize:hover {
    background: rgba(40, 205, 65, 0.18);
    color: #28cd41;
}

.window-control.close:hover {
    background: rgba(255, 69, 58, 0.85);
    color: #ffffff;
}

/* Larger hit target on close for fat-finger safety */
.window-control.close {
    font-size: 16px;
}

/* ── Window Content ───────────────────────────────────────── */
.window-content {
    flex: 1;
    overflow: auto;
    color: var(--text-primary);
    /* Glassmorphism: enabled via .glass class on .window */
}

/* Optional glassmorphism — toggled by Settings */
.window.glass .window-content {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(10px) saturate(1.2);
    -webkit-backdrop-filter: blur(10px) saturate(1.2);
}

/* ── 8-direction resize handles ──────────────────────────── */
.window-resize-handle {
    position: absolute;
    z-index: 10;
    /* Invisible but interactive */
}

/* Corner handles — 12×12 hit area, larger corners = easier grab */
.window-resize-handle[data-dir="nw"] { top: 0;    left: 0;     width: 12px; height: 12px; cursor: nwse-resize; }
.window-resize-handle[data-dir="ne"] { top: 0;    right: 0;    width: 12px; height: 12px; cursor: nesw-resize; }
.window-resize-handle[data-dir="se"] { bottom: 0; right: 0;    width: 12px; height: 12px; cursor: nwse-resize; }
.window-resize-handle[data-dir="sw"] { bottom: 0; left: 0;     width: 12px; height: 12px; cursor: nesw-resize; }

/* Edge handles — 4px wide/tall, between corners */
.window-resize-handle[data-dir="n"]  { top: 0;    left: 12px;  right: 12px;  height: 4px;  cursor: ns-resize; }
.window-resize-handle[data-dir="s"]  { bottom: 0; left: 12px;  right: 12px;  height: 4px;  cursor: ns-resize; }
.window-resize-handle[data-dir="w"]  { left: 0;   top: 12px;   bottom: 12px; width: 4px;   cursor: ew-resize; }
.window-resize-handle[data-dir="e"]  { right: 0;  top: 12px;   bottom: 12px; width: 4px;   cursor: ew-resize; }

.window.maximized .window-resize-handle {
    display: none;
}

/* ── Window Animations ────────────────────────────────────── */
@keyframes windowOpen {
    from {
        opacity: 0;
        transform: scale(0.90) translateY(12px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes windowClose {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.90) translateY(12px);
    }
}

@keyframes windowMinimize {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.5) translateY(80px);
    }
}

@keyframes windowRestore {
    from {
        opacity: 0;
        transform: scale(0.5) translateY(80px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.window.opening {
    animation: windowOpen 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.window.closing {
    animation: windowClose 0.16s ease-in forwards;
    pointer-events: none;
}

.window.minimizing {
    animation: windowMinimize 0.2s cubic-bezier(0.4, 0, 1, 1) forwards;
    pointer-events: none;
}

.window.restoring {
    animation: windowRestore 0.22s cubic-bezier(0, 0, 0.2, 1) forwards;
}

/* ── Snap overlay ─────────────────────────────────────────── */
#snap-overlay {
    position: fixed;
    pointer-events: none;
    z-index: 8000;
    transition: all 0.12s cubic-bezier(0.2, 0, 0, 1);
    background: rgba(102, 126, 234, 0.16);
    border: 2px solid rgba(102, 126, 234, 0.65);
    border-radius: 10px;
    display: none;
}

#snap-overlay.visible {
    display: block;
}

/* ── Snap Layouts Picker ──────────────────────────────────── */
.snap-layouts-picker {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-elevated);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    display: none;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    width: 220px;
    box-shadow: 0 8px 32px var(--shadow-color);
    z-index: 9999;
}

.snap-layouts-picker.visible {
    display: grid;
    animation: fadeIn 0.12s ease-out;
}

.snap-layout-btn {
    height: 52px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    display: flex;
    gap: 3px;
    padding: 6px;
    transition: all 0.15s;
    overflow: hidden;
}

.snap-layout-btn:hover {
    background: rgba(102, 126, 234, 0.25);
    border-color: rgba(102, 126, 234, 0.5);
}

.snap-layout-btn .layout-block {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    flex: 1;
    transition: background 0.15s;
}

.snap-layout-btn:hover .layout-block {
    background: rgba(102, 126, 234, 0.6);
}

.snap-layout-btn .layout-block.active {
    background: rgba(102, 126, 234, 0.9);
}
