/* =========================================
   Floating Windows & Modals
   ========================================= */

.floating-window {
    position: absolute;
    background: var(--bg-surface-2);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 200px;
    min-height: 100px;
    z-index: 100;
    touch-action: none;
    user-select: none; 
}

.floating-window.active-window {
    border-color: var(--accent);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.95), 0 0 8px rgba(0, 255, 136, 0.2);
}

.floating-window.is-dragging,
.floating-window.is-resizing {
    will-change: left, top, width, height;
}

.floating-window.is-dragging .window-content,
.floating-window.is-resizing .window-content {
    pointer-events: none;
}

.floating-window.maximized {
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0;
    border: none;
    z-index: 200;
}

/* Maximized window content fills like a primary tile */
.floating-window.maximized .window-content.is-fill {
    height: calc(100% - 32px);
    display: flex;
    flex-direction: column;
    padding: 0;
}

.floating-window.maximized .window-content.is-fill > .view-host,
.floating-window.maximized .window-content.is-fill > .arrange-view-root,
.floating-window.maximized .window-content.is-fill > .seq-session-host-root,
.floating-window.maximized .window-content.is-fill > .instrument-rack-root,
.floating-window.maximized .window-content.is-fill > .automation-editor-root,
.floating-window.maximized .window-content.is-fill > .piano-roll-editor,
.floating-window.maximized .window-content.is-fill > .seq-root {
    flex: 1;
    min-height: 0;
    height: 100%;
}

.floating-window.minimized {
    height: auto !important;
    min-height: 0 !important;
    border-radius: 6px 6px 0 0;
}
.floating-window.minimized .window-content,
.floating-window.minimized .window-resizer { 
    display: none !important; 
}

.window-header {
    background: #1e1e1e;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    border-bottom: 1px solid var(--border-main);
    user-select: none;
    touch-action: none;
}
.window-header:active { cursor: grabbing; }
.window-title { color: var(--accent); font-weight: bold; font-size: 14px; pointer-events: none; }

.window-controls { display: flex; gap: 5px; }
.win-btn {
    background: var(--bg-elevated);
    color: var(--text-main);
    border: none; border-radius: 3px;
    width: 24px; height: 24px;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.win-btn:hover { background: var(--border-focus); }
.win-btn.close:hover { background: var(--danger); }

.window-content {
    flex-grow: 1;
    overflow: auto;
    background: var(--bg-surface);
    padding: 20px;
}

.window-content.is-fill {
    height: calc(100% - 32px);
    display: flex;
    flex-direction: column;
    padding: 0;
}

/* Expanded Window Content List */
.piano-roll-window .window-content,
.step-sequencer-window .window-content,
.automation-editor-window .window-content,
.session-step-seq-window .window-content,
.arrange-view-window .window-content,
.instrument-window .window-content,
.effect-editor-window .window-content,
.track-effects-window .window-content {
    height: calc(100% - 32px);
    display: flex;
    flex-direction: column;
    padding: 0;
}

.window-resizer { 
    position: absolute; 
    z-index: 10; 
    touch-action: none;
    user-select: none;
}

.resizer-n  { top: 0; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.resizer-s  { bottom: 0; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.resizer-e  { top: 8px; bottom: 8px; right: 0; width: 8px; cursor: ew-resize; }
.resizer-w  { top: 8px; bottom: 8px; left: 0; width: 8px; cursor: ew-resize; }
.resizer-nw { top: 0; left: 0; width: 10px; height: 10px; cursor: nwse-resize; }
.resizer-ne { top: 0; right: 0; width: 10px; height: 10px; cursor: nesw-resize; }
.resizer-sw { bottom: 0; left: 0; width: 10px; height: 10px; cursor: nesw-resize; }
.resizer-se { bottom: 0; right: 0; width: 10px; height: 10px; cursor: nwse-resize; }


/* =========================================
   Modals & Notifications
   ========================================= */

.modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.modal-dialog {
    background: var(--bg-surface-2);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    width: 440px;
    max-width: 90vw;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.8);
    color: var(--text-main);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #1e1e1e;
    border-bottom: 1px solid var(--border-main);
}

.modal-title {
    color: var(--accent);
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 0.5px;
}

.modal-content {
    background: var(--bg-surface);
    color: var(--text-main);
}

.loading-modal-message {
    padding: 30px 20px;
    text-align: center;
    font-size: 1.1rem;
}


/* =========================================
   Layout Hosts & Tiles Drop-ins
   ========================================= */

.editor-tile-host {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.editor-tile-host.is-primary-fill {
    flex: 1 1 auto;
    max-width: none;
    min-width: 0;
    border-left: none;
}

/* Side tile only — never fight primary slot */
.editor-tile-host.is-side-tile {
    flex: 0 0 42%;
    max-width: 55%;
    min-width: 280px;
    min-height: 0;
    border-left: 1px solid var(--border-main, #333);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-tile-host.is-side-tile > * {
    flex: 1;
    min-height: 0;
    min-width: 0;
}

.editor-tile-host:empty {
    display: none;
}

.daw-content-host {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: row;
    position: relative;
    overflow: hidden;
}

.primary-view-slot {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.primary-view-slot > * {
    flex: 1;
    min-height: 0;
    min-width: 0;
    height: 100%;
}

.arrange-view-root,
.seq-session-host-root {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    width: 100%;
}

.arrange-view-root > .timeline-area,
.seq-session-host-root > .seq-session-root {
    flex: 1;
    min-height: 0;
    min-width: 0;
}

.daw-app.has-primary-tile .editor-tile-host.is-primary-fill {
    position: absolute;
    inset: 0;
}

.view-host,
.instrument-rack-root,
.waveform-editor-host-root,
.fx-editor-root {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}


/* =========================================
   Piano Roll & Editor UI Components
   ========================================= */

.piano-roll-editor {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.pr-main-area {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.pr-piano-column {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pr-piano {
    overflow-y: hidden;
}


/* =========================================
   Media Queries
   ========================================= */

@media (max-width: 850px) {
    .floating-window {
        width: 100vw !important; 
        height: 100vh !important;
        top: 0 !important; 
        left: 0 !important;
        border-radius: 0; 
        border: none;
    }
}