/**
 * Container Panel Styles
 *
 * Styling for container panels that host other panels in a flex-grid layout.
 * Uses BEM naming: .container-panel__element--modifier
 */

/* =============================================================================
   CONTAINER PANEL BASE
   ============================================================================= */

.container-panel {
    /* Container inherits NodePanel base styles */
    min-width: 400px;
    min-height: 300px;
}

.container-panel .node-panel__content {
    padding: 0;
    position: relative;
    overflow: hidden;
}

.container-panel__content {
    position: relative;
    width: 100%;
    height: 100%;
}

/* =============================================================================
   GRID CONTAINER
   ============================================================================= */

.container-panel__grid {
    display: grid;
    width: 100%;
    height: 100%;
    gap: 4px;
    padding: 4px;
    box-sizing: border-box;
    /* Prevent overflow */
    overflow: hidden;
}

/* =============================================================================
   DOCKED CHILD PANELS
   ============================================================================= */

.node-panel.is-docked-in-container {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 0;
    /* Remove floating panel shadow, use subtle border */
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.05),
        0 2px 8px rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    /* Remove cursor grab (parent container handles drag) */
    cursor: default;
    /* Flex item behavior */
    overflow: hidden;
}

/* Docked panel header - more compact */
.node-panel.is-docked-in-container .node-panel__header {
    height: 36px;
    min-height: 36px;
    padding: 0 8px;
    cursor: grab;
    border-radius: 8px 8px 0 0;
}

.node-panel.is-docked-in-container.is-dragging .node-panel__header {
    cursor: grabbing;
}

/* Hide drag pill for docked panels */
.node-panel.is-docked-in-container .node-panel__header::before {
    display: none;
}

/* Docked panel content - fill remaining space */
.node-panel.is-docked-in-container .node-panel__content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

/* Docked panel footer */
.node-panel.is-docked-in-container .node-panel__footer {
    border-radius: 0 0 8px 8px;
}

/* Hide resize handles for docked panels (use splitters instead) */
.node-panel.is-docked-in-container .node-panel__resize,
.node-panel.is-docked-in-container .node-panel__resize-edge {
    display: none;
}

/* Docked panel focus state */
.node-panel.is-docked-in-container.is-focused {
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.1),
        0 0 0 2px var(--node-accent, var(--color-cyan, #00D9FF)),
        0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1;
}

/* =============================================================================
   DROP ZONES
   ============================================================================= */

.container-panel__drop-zone {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 10;
    border-radius: 4px;
    /* Indicator styling */
    background: rgba(0, 217, 255, 0.1);
    border: 2px dashed rgba(0, 217, 255, 0.4);
}

/* Show drop zones when container is target */
.container-panel.is-showing-drop-zones .container-panel__drop-zone {
    opacity: 1;
    pointer-events: auto;
}

/* Active drop zone */
.container-panel__drop-zone.is-active {
    background: rgba(0, 217, 255, 0.2);
    border-color: rgba(0, 217, 255, 0.8);
    box-shadow:
        0 0 20px rgba(0, 217, 255, 0.3),
        inset 0 0 20px rgba(0, 217, 255, 0.1);
}

/* Drop zone positions */
.container-panel__drop-zone--top {
    top: 4px;
    left: 25%;
    right: 25%;
    height: 20%;
    min-height: 40px;
}

.container-panel__drop-zone--bottom {
    bottom: 4px;
    left: 25%;
    right: 25%;
    height: 20%;
    min-height: 40px;
}

.container-panel__drop-zone--left {
    top: 25%;
    bottom: 25%;
    left: 4px;
    width: 20%;
    min-width: 40px;
}

.container-panel__drop-zone--right {
    top: 25%;
    bottom: 25%;
    right: 4px;
    width: 20%;
    min-width: 40px;
}

.container-panel__drop-zone--center {
    top: 30%;
    bottom: 30%;
    left: 30%;
    right: 30%;
    border-radius: 8px;
}

/* Drop zone icons/labels */
.container-panel__drop-zone::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    opacity: 0.6;
    /* Arrow icons via CSS */
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.container-panel__drop-zone--top::after {
    content: '↑';
    font-size: 18px;
    color: var(--color-cyan, #00D9FF);
}

.container-panel__drop-zone--bottom::after {
    content: '↓';
    font-size: 18px;
    color: var(--color-cyan, #00D9FF);
}

.container-panel__drop-zone--left::after {
    content: '←';
    font-size: 18px;
    color: var(--color-cyan, #00D9FF);
}

.container-panel__drop-zone--right::after {
    content: '→';
    font-size: 18px;
    color: var(--color-cyan, #00D9FF);
}

.container-panel__drop-zone--center::after {
    content: '⊕';
    font-size: 20px;
    color: var(--color-cyan, #00D9FF);
}

.container-panel__drop-zone.is-active::after {
    opacity: 1;
    animation: drop-zone-pulse 0.6s ease-in-out infinite;
}

@keyframes drop-zone-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.2); }
}

/* =============================================================================
   SPLITTERS
   ============================================================================= */

.container-panel__splitter {
    position: relative;
    z-index: 5;
    background: transparent;
    transition: background-color 0.15s ease;
}

.container-panel__splitter--horizontal {
    width: 8px;
    margin: 0 -4px;
    cursor: col-resize;
}

.container-panel__splitter--vertical {
    height: 8px;
    margin: -4px 0;
    cursor: row-resize;
}

/* Splitter handle (visible bar) */
.container-panel__splitter-handle {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.container-panel__splitter--horizontal .container-panel__splitter-handle {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 32px;
}

.container-panel__splitter--vertical .container-panel__splitter-handle {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 4px;
}

/* Splitter hover state */
.container-panel__splitter:hover .container-panel__splitter-handle {
    background: rgba(0, 217, 255, 0.5);
    box-shadow: 0 0 8px rgba(0, 217, 255, 0.3);
}

/* Splitter active state (during drag) */
.container-panel__splitter:active .container-panel__splitter-handle,
body.is-resizing-splitter .container-panel__splitter-handle {
    background: rgba(0, 217, 255, 0.8);
    box-shadow: 0 0 12px rgba(0, 217, 255, 0.5);
}

.container-panel__splitter--horizontal:active .container-panel__splitter-handle {
    transform: translate(-50%, -50%) scaleX(1.5);
}

.container-panel__splitter--vertical:active .container-panel__splitter-handle {
    transform: translate(-50%, -50%) scaleY(1.5);
}

/* =============================================================================
   BODY STATES DURING CONTAINER OPERATIONS
   ============================================================================= */

/* During splitter resize */
body.is-resizing-splitter {
    cursor: col-resize !important;
    -webkit-user-select: none;
    user-select: none;
}

body.is-resizing-splitter * {
    cursor: inherit !important;
}

/* During panel drag over container */
body.is-container-drop-target {
    /* Can be used for global styling during dock operations */
}

/* =============================================================================
   MERGE INDICATOR (non-container panel being targeted)
   ============================================================================= */

.node-panel.is-merge-target {
    outline: 2px solid var(--color-cyan, #00D9FF);
    outline-offset: -2px;
    box-shadow:
        0 0 0 4px rgba(0, 217, 255, 0.2),
        0 0 30px rgba(0, 217, 255, 0.3),
        0 8px 32px rgba(0, 0, 0, 0.4);
    animation: merge-pulse 1s ease-in-out infinite;
}

@keyframes merge-pulse {
    0%, 100% {
        outline-offset: -2px;
        box-shadow:
            0 0 0 4px rgba(0, 217, 255, 0.2),
            0 0 30px rgba(0, 217, 255, 0.3),
            0 8px 32px rgba(0, 0, 0, 0.4);
    }
    50% {
        outline-offset: 2px;
        box-shadow:
            0 0 0 8px rgba(0, 217, 255, 0.15),
            0 0 40px rgba(0, 217, 255, 0.4),
            0 8px 32px rgba(0, 0, 0, 0.4);
    }
}

/* Merge hint label */
.node-panel.is-merge-target::before {
    content: 'Drop to group';
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 12px;
    background: var(--color-cyan, #00D9FF);
    color: #000;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 100;
    animation: merge-label-bounce 0.3s ease;
}

@keyframes merge-label-bounce {
    0% { opacity: 0; transform: translateX(-50%) translateY(8px); }
    100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* =============================================================================
   CONTAINER PANEL HEADER CUSTOMIZATION
   ============================================================================= */

.container-panel .node-panel__header {
    /* Container panels use a stacked icon */
    border-left-color: var(--color-purple, #8E24AA);
}

.container-panel .node-panel__icon {
    color: var(--color-purple, #8E24AA);
}

/* Container panel title shows child count */
.container-panel .node-panel__title::after {
    content: attr(data-child-count);
    margin-left: 8px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    opacity: 0.6;
}

/* =============================================================================
   UNDOCK THRESHOLD INDICATOR
   ============================================================================= */

.container-panel.is-child-near-undock {
    outline: 2px dashed rgba(255, 193, 7, 0.5);
    outline-offset: 4px;
}

/* Visual indicator when child is being dragged beyond threshold */
.node-panel.is-docked-in-container.is-near-undock {
    opacity: 0.7;
    transform: scale(0.95);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

/* =============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================= */

@media (max-width: 768px) {
    .container-panel {
        min-width: 300px;
    }

    .container-panel__grid {
        gap: 2px;
        padding: 2px;
    }

    .node-panel.is-docked-in-container .node-panel__header {
        height: 32px;
        min-height: 32px;
    }

    .container-panel__splitter--horizontal {
        width: 12px;
        margin: 0 -6px;
    }

    .container-panel__splitter--vertical {
        height: 12px;
        margin: -6px 0;
    }
}

/* =============================================================================
   ANIMATIONS
   ============================================================================= */

/* Panel docking animation */
@keyframes panel-dock {
    0% {
        opacity: 0.5;
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.node-panel.is-docked-in-container {
    animation: panel-dock 0.2s ease-out;
}

/* Panel undocking animation (added temporarily via JS) */
@keyframes panel-undock {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 1;
        transform: scale(1.02);
    }
}

.node-panel.is-undocking {
    animation: panel-undock 0.15s ease-out;
}
