/**
 * Ability.ICU - Universal Popout Workspace CSS
 * Enables multi-window floating, dragging, resizing, and maximizing
 * for all graphs, charts, and data tables across the platform.
 */

/* Inline Trigger Button on Cards / Headers */
.popout-trigger-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.35rem !important;
    padding: 0.25rem 0.55rem !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    line-height: 1 !important;
    border-radius: 6px !important;
    border: 1px solid rgba(136, 192, 208, 0.35) !important;
    background: rgba(46, 52, 64, 0.85) !important;
    color: #88c0d0 !important;
    cursor: pointer !important;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1) !important;
    user-select: none !important;
    backdrop-filter: blur(8px) !important;
    z-index: 5 !important;
}

[data-theme="nordic-light"] .popout-trigger-btn,
[data-theme="light"] .popout-trigger-btn {
    border-color: rgba(32, 94, 166, 0.35) !important;
    background: #E6E4D9 !important;
    color: #205EA6 !important;
}

[data-theme="brand"] .popout-trigger-btn {
    border-color: rgba(217, 249, 157, 0.35) !important;
    background: #14161C !important;
    color: #D9F99D !important;
}

.popout-trigger-btn:hover {
    background: #88c0d0 !important;
    color: #111827 !important;
    border-color: #88c0d0 !important;
    box-shadow: 0 2px 8px rgba(136, 192, 208, 0.35) !important;
    transform: translateY(-1px) !important;
}

[data-theme="light"] .popout-trigger-btn:hover {
    background: #205EA6 !important;
    color: #ffffff !important;
    border-color: #205EA6 !important;
}

[data-theme="brand"] .popout-trigger-btn:hover {
    background: #D9F99D !important;
    color: #0A0A0C !important;
    border-color: #D9F99D !important;
}

.popout-trigger-btn .popout-icon {
    font-size: 0.85rem;
    display: inline-block;
    transition: transform 0.2s ease;
}

.popout-trigger-btn:hover .popout-icon {
    transform: scale(1.15);
}

/* Floating Hover Trigger for containers without explicit headers */
.popout-hover-anchor {
    position: relative !important;
}

.popout-floating-trigger {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    opacity: 0.85;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10;
}

.popout-hover-anchor:hover .popout-floating-trigger,
.popout-floating-trigger:focus-within {
    opacity: 1;
}

/* Inline Placeholder Left Behind */
.popout-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: 2px dashed rgba(136, 192, 208, 0.35);
    border-radius: 12px;
    background: rgba(46, 52, 64, 0.25);
    padding: 2rem 1.5rem;
    min-height: 180px;
    text-align: center;
    color: #88c0d0;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

[data-theme="nordic-light"] .popout-placeholder,
[data-theme="light"] .popout-placeholder {
    border-color: rgba(94, 129, 172, 0.3);
    background: rgba(236, 239, 244, 0.4);
    color: #4c566a;
}

.popout-placeholder-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(136, 192, 208, 0.2);
    border: 1px solid rgba(136, 192, 208, 0.4);
    color: #88c0d0;
    padding: 0.35rem 0.8rem;
    font-size: 0.78rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

.popout-placeholder-btn:hover {
    background: #88c0d0;
    color: #2e3440;
}

/* Floating Window Container */
.popout-window {
    position: fixed;
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(136, 192, 208, 0.35);
    border-radius: 14px;
    box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
    resize: both;
    min-width: 380px;
    min-height: 260px;
    box-sizing: border-box;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
    will-change: transform, width, height, top, left;
}

[data-theme="nordic-light"] .popout-window,
[data-theme="light"] .popout-window {
    background: rgba(248, 250, 252, 0.97);
    border-color: rgba(94, 129, 172, 0.4);
    box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.popout-window.active-focus {
    border-color: #88c0d0;
    box-shadow: 0 25px 55px -10px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(136, 192, 208, 0.5);
}

/* Window Header (Draggable Titlebar) */
.popout-window-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    background: rgba(30, 41, 59, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

[data-theme="nordic-light"] .popout-window-header,
[data-theme="light"] .popout-window-header {
    background: rgba(229, 233, 240, 0.95);
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.popout-window-header:active {
    cursor: grabbing;
}

.popout-window-title-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 0.75rem;
}

.popout-window-icon {
    font-size: 1rem;
    color: #88c0d0;
}

.popout-window-title {
    font-weight: 700;
    font-size: 0.88rem;
    color: #eceff4;
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

[data-theme="nordic-light"] .popout-window-title,
[data-theme="light"] .popout-window-title {
    color: #2e3440;
}

.popout-window-badge {
    font-size: 0.68rem;
    padding: 0.15rem 0.45rem;
    background: rgba(136, 192, 208, 0.18);
    border: 1px solid rgba(136, 192, 208, 0.35);
    color: #88c0d0;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Origin Badge for Cross-Page Persisted Windows */
.popout-origin-badge {
    font-size: 0.68rem;
    padding: 0.15rem 0.45rem;
    background: rgba(163, 190, 140, 0.2);
    border: 1px solid rgba(163, 190, 140, 0.45);
    color: #a3be8c;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

[data-theme="nordic-light"] .popout-origin-badge,
[data-theme="light"] .popout-origin-badge {
    background: rgba(143, 188, 187, 0.2);
    border-color: rgba(94, 129, 172, 0.4);
    color: #4c566a;
}

/* Control Buttons Cluster in Top Right */
.popout-window-controls {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.popout-ctrl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: #d8dee9;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    line-height: 1;
}

[data-theme="nordic-light"] .popout-ctrl-btn,
[data-theme="light"] .popout-ctrl-btn {
    border-color: rgba(0, 0, 0, 0.12);
    background: rgba(0, 0, 0, 0.05);
    color: #4c566a;
}

.popout-ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    transform: scale(1.05);
}

[data-theme="nordic-light"] .popout-ctrl-btn:hover,
[data-theme="light"] .popout-ctrl-btn:hover {
    background: rgba(0, 0, 0, 0.12);
    color: #2e3440;
}

/* Close 'X' Button in Top-Right */
.popout-close-btn {
    border-color: rgba(191, 97, 106, 0.4);
    background: rgba(191, 97, 106, 0.15);
    color: #bf616a;
    font-weight: bold;
}

.popout-close-btn:hover {
    background: #bf616a !important;
    color: #ffffff !important;
    border-color: #bf616a !important;
    box-shadow: 0 2px 8px rgba(191, 97, 106, 0.4);
}

/* Window Content Body */
.popout-window-body {
    flex: 1 1 auto;
    padding: 1rem;
    overflow: auto;
    min-height: 0;
    min-width: 0;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Ensure canvas and tables inside popout stretch smoothly */
.popout-window-body canvas {
    max-width: 100% !important;
    max-height: 100% !important;
    width: 100% !important;
    height: 100% !important;
}

.popout-window-body table {
    margin-bottom: 0 !important;
    width: 100% !important;
}

.popout-window-body .chart-container,
.popout-window-body .chart-card-container {
    height: 100% !important;
    min-height: 0 !important;
    flex: 1 1 auto;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

/* Maximized Viewport State */
.popout-window.popout-maximized {
    top: 2.5vh !important;
    left: 2.5vw !important;
    width: 95vw !important;
    height: 95vh !important;
    max-width: 95vw !important;
    max-height: 95vh !important;
    resize: none !important;
    border-radius: 12px;
    z-index: 99999 !important;
}

/* Visual Resize Grip in Bottom-Right Corner */
.popout-resize-handle {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    pointer-events: none;
    opacity: 0.45;
    background: linear-gradient(135deg, transparent 50%, #88c0d0 50%, #88c0d0 60%, transparent 60%, transparent 70%, #88c0d0 70%, #88c0d0 80%, transparent 80%, transparent 90%, #88c0d0 90%);
}

/* Mobile & Touch Viewports */
@media (max-width: 768px) {
    .popout-window {
        min-width: 92vw;
        max-width: 96vw;
    }
    .popout-window.popout-maximized {
        top: 0.5rem !important;
        left: 0.5rem !important;
        width: calc(100vw - 1rem) !important;
        height: calc(100vh - 1rem) !important;
    }
}

/* ==========================================================================
   Quill Editor Popout Workspace Styling
   ========================================================================== */

/* Quill Toolbar Popout Button */
.ql-toolbar .ql-formats.ql-popout-group {
    margin-left: auto !important;
    margin-right: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
}

.ql-toolbar .ql-popout-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.35rem !important;
    width: auto !important;
    height: 28px !important;
    padding: 0.2rem 0.65rem !important;
    font-size: 0.76rem !important;
    font-weight: 600 !important;
    border-radius: 6px !important;
    border: 1px solid rgba(136, 192, 208, 0.45) !important;
    background: rgba(136, 192, 208, 0.15) !important;
    color: #88c0d0 !important;
    cursor: pointer !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    line-height: 1 !important;
    white-space: nowrap !important;
}

.ql-toolbar .ql-popout-btn:hover {
    background: #88c0d0 !important;
    color: #1e293b !important;
    border-color: #88c0d0 !important;
    box-shadow: 0 2px 10px rgba(136, 192, 208, 0.4) !important;
    transform: translateY(-1px);
}

.ql-toolbar .ql-popout-btn .popout-icon {
    font-size: 0.85rem;
    line-height: 1;
}

.ql-toolbar .ql-popout-btn .popout-btn-label {
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* Light Theme overrides for Quill Toolbar Popout Button */
[data-theme="nordic-light"] .ql-toolbar .ql-popout-btn,
[data-theme="light"] .ql-toolbar .ql-popout-btn {
    border-color: rgba(94, 129, 172, 0.45) !important;
    background: rgba(94, 129, 172, 0.12) !important;
    color: #434c5e !important;
}

[data-theme="nordic-light"] .ql-toolbar .ql-popout-btn:hover,
[data-theme="light"] .ql-toolbar .ql-popout-btn:hover {
    background: #5e81ac !important;
    color: #ffffff !important;
    border-color: #5e81ac !important;
    box-shadow: 0 2px 10px rgba(94, 129, 172, 0.35) !important;
}

/* Editor Window Layout */
.popout-editor-window {
    min-width: 520px;
    min-height: 420px;
}

.popout-editor-body {
    padding: 0.75rem !important;
    background: rgba(15, 23, 42, 0.6);
}

[data-theme="nordic-light"] .popout-editor-body,
[data-theme="light"] .popout-editor-body {
    background: rgba(241, 245, 249, 0.85);
}

/* Ensure editor wrapper takes 100% height inside popout window */
.popout-window .cms-quill-wrapper,
.popout-window .quill-editor-wrapper {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    height: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 8px !important;
    overflow: hidden !important;
}

.popout-window .ql-toolbar.ql-snow {
    flex-shrink: 0 !important;
    background: rgba(30, 41, 59, 0.95) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    padding: 0.6rem 0.85rem !important;
}

[data-theme="nordic-light"] .popout-window .ql-toolbar.ql-snow,
[data-theme="light"] .popout-window .ql-toolbar.ql-snow {
    background: rgba(229, 233, 240, 0.95) !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08) !important;
}

.popout-window .ql-container.ql-snow {
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    min-height: 0 !important;
    border: none !important;
    background: rgba(15, 23, 42, 0.85) !important;
}

[data-theme="nordic-light"] .popout-window .ql-container.ql-snow,
[data-theme="light"] .popout-window .ql-container.ql-snow {
    background: #ffffff !important;
}

.popout-window .ql-editor {
    flex: 1 1 auto !important;
    height: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    padding: 1.5rem 2rem !important;
    font-size: 1.05rem !important;
    line-height: 1.8 !important;
}

/* Distraction-Free Maximized Mode for Editor */
.popout-window.popout-maximized .ql-editor {
    padding: 2.5rem 5rem !important;
    font-size: 1.15rem !important;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

/* Editor Placeholder styling */
.popout-placeholder.popout-editor-placeholder {
    min-height: 160px;
    border: 2px dashed rgba(56, 189, 248, 0.45);
    background: rgba(56, 189, 248, 0.06);
}

/* Inside any popped out window (minimal or floating), hide all redundant popout triggers */
.popout-window .popout-trigger-btn:not(.ql-popout-btn),
.popout-window .popout-floating-trigger,
.popout-window #popoutChartBtn,
.popout-window [data-popout-trigger="true"] {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Minimal Detached Window Shell Styles */
html.popout-minimal-window,
body.popout-minimal-window-body {
    margin: 0 !important;
    padding: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    overflow: hidden !important;
    background: var(--pico-background-color, #0f172a) !important;
    box-sizing: border-box !important;
    font-family: inherit;
}

[data-theme="nordic-light"].popout-minimal-window,
[data-theme="light"].popout-minimal-window {
    background: #f8fafc !important;
}

.popout-window-minimal-shell {
    position: absolute !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    resize: none !important;
}

.popout-window-minimal-shell .popout-resize-handle {
    display: none !important;
}

.popout-dock-btn {
    width: auto !important;
    padding: 0 0.55rem !important;
    gap: 0.25rem;
    font-size: 0.76rem !important;
    font-weight: 600;
    border-color: rgba(56, 189, 248, 0.35) !important;
    background: rgba(56, 189, 248, 0.12) !important;
    color: #38bdf8 !important;
}

.popout-dock-btn:hover {
    background: #38bdf8 !important;
    color: #0f172a !important;
}

.popout-detach-btn {
    border-color: rgba(136, 192, 208, 0.35) !important;
    color: #88c0d0 !important;
}

.popout-detach-btn:hover {
    background: #88c0d0 !important;
    color: #2e3440 !important;
}


