:root {
    --desktop-titlebar-height: 38px;
}

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

.desktop-titlebar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 100001;
    display: flex;
    height: var(--desktop-titlebar-height);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    user-select: none;
}

.desktop-drag-region {
    display: flex;
    flex: 1;
    align-items: center;
    min-width: 0;
    gap: 24px;
    padding-left: 12px;
    cursor: default;
    touch-action: none;
}

.desktop-brand {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.desktop-brand-icon { display: block; width: 20px; height: 20px; }
.desktop-brand-name { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 1.8px; }
.desktop-status { min-width: 0; overflow: hidden; color: var(--text-secondary); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.desktop-window-controls { display: flex; flex-shrink: 0; height: 100%; }

.desktop-window-button {
    display: grid;
    place-items: center;
    width: 46px;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: default;
    transition: background 120ms ease, color 120ms ease;
}

.desktop-window-button:hover { background: var(--bg-hover); color: var(--accent); }
.desktop-window-button:active { background: var(--border-light); }
.desktop-window-button:disabled { opacity: 0.5; }
.desktop-window-button:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }
.desktop-window-close:hover { background: #c42b1c; color: #fff; }
.desktop-window-close:active { background: #a92317; }
.desktop-window-button > i { pointer-events: none; }

.desktop-resize-handles { position: fixed; inset: 0; z-index: 100002; pointer-events: none; }
.desktop-resize-handles[hidden], .desktop-maximized .desktop-resize-handles { display: none; }
.desktop-resize-handle { position: absolute; pointer-events: auto; }
.desktop-resize-handle[data-edge="n"], .desktop-resize-handle[data-edge="s"] { right: 8px; left: 8px; height: 5px; cursor: ns-resize; }
.desktop-resize-handle[data-edge="n"] { top: 0; }
.desktop-resize-handle[data-edge="s"] { bottom: 0; }
.desktop-resize-handle[data-edge="e"], .desktop-resize-handle[data-edge="w"] { top: 8px; bottom: 8px; width: 5px; cursor: ew-resize; }
.desktop-resize-handle[data-edge="e"] { right: 0; }
.desktop-resize-handle[data-edge="w"] { left: 0; }
.desktop-resize-handle[data-edge="ne"], .desktop-resize-handle[data-edge="se"], .desktop-resize-handle[data-edge="sw"], .desktop-resize-handle[data-edge="nw"] { width: 8px; height: 8px; }
.desktop-resize-handle[data-edge="ne"] { top: 0; right: 0; cursor: nesw-resize; }
.desktop-resize-handle[data-edge="se"] { bottom: 0; right: 0; cursor: nwse-resize; }
.desktop-resize-handle[data-edge="sw"] { bottom: 0; left: 0; cursor: nesw-resize; }
.desktop-resize-handle[data-edge="nw"] { top: 0; left: 0; cursor: nwse-resize; }

body.desktop-host { padding-top: var(--desktop-titlebar-height); }
body.desktop-host > .app { height: calc(100vh - var(--desktop-titlebar-height)); }
body.desktop-host :is(.license-gate, .modal-overlay, .scarp-dialog-overlay, #first-run-overlay) { top: var(--desktop-titlebar-height); }
body.desktop-host .scarp-toast-container { top: calc(16px + var(--desktop-titlebar-height)); }

@media (prefers-reduced-motion: reduce) {
    .desktop-window-button { transition: none; }
}
