/* ==========================================================================
   Pane Layout, Pane Headers, Pane Controls, Extra Panes, Minimized/Maximized
   ========================================================================== */

/* ── Multi-chart layout area ── */
#chart-layout-area {
    position: absolute;
    top: calc(var(--topbar-h, 50px) + var(--chart-header-h, 28px));
    left: 44px;
    right: 46px;    /* leave room for right sidebar icon strip */
    bottom: 0;       /* no bottom bar */
    display: flex;
    flex-direction: column;
    background: var(--chart-bg, var(--ui-bg));
    transition: right 0.2s ease;
}

/* Each horizontal row of charts */
.chart-row {
    display: flex;
    flex-direction: row;
    flex: 1 1 0%;
    min-height: 0;
}
.chart-row > .chart-pane,
.chart-row > .chart-pane-main {
    min-width: 0;
    min-height: 0;
    flex: 1 1 0%;
}

/* ── Drag-resize handles ── */
.grid-rsz-hdl {
    z-index: 50;
    position: relative;
    background: rgba(255,255,255,0.06);
    transition: background 0.12s;
}
.grid-rsz-hdl:hover,
.grid-rsz-hdl:active { background: rgba(41,98,255,0.28); }

/* Visible drag icon in the center of each handle */
.grid-rsz-hdl::after {
    content: '';
    position: absolute;
    border-radius: 3px;
    background: rgba(180,180,200,0.0);
    transition: background 0.12s, opacity 0.12s;
    opacity: 0;
}
.grid-rsz-hdl:hover::after,
.grid-rsz-hdl:active::after { opacity: 1; background: rgba(41,98,255,0.7); }

/* Vertical handle (between columns) — show ⟺ grab pill */
.grid-rsz-v {
    cursor: col-resize;
    width: 8px;
    flex-shrink: 0;
}
.grid-rsz-v::after {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 36px;
}

/* Horizontal handle (between rows) — show ⟺ grab pill rotated */
.grid-rsz-h {
    cursor: row-resize;
    height: 8px;
    flex-shrink: 0;
    width: 100%;
}
.grid-rsz-h::after {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 4px;
}

/* Arrow icon overlaid on the handle — ◁▷ */
.grid-rsz-v .rsz-icon,
.grid-rsz-h .rsz-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    line-height: 1;
    color: rgba(160,170,200,0.0);
    pointer-events: none;
    user-select: none;
    transition: color 0.12s;
    white-space: nowrap;
}
.grid-rsz-hdl:hover .rsz-icon,
.grid-rsz-hdl:active .rsz-icon { color: #fff; }

/* ── Pane drag-to-reposition ── */
.pane-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 100%;
    font-size: 14px;
    color: rgba(150,155,175,0.4);
    cursor: grab;
    flex-shrink: 0;
    user-select: none;
    transition: color 0.12s;
    margin-right: 2px;
}
.pane-drag-handle:hover { color: rgba(150,155,175,0.9); }
.pane-drag-handle:active { cursor: grabbing; }

.pane-dragging { opacity: 0.45; }
.pane-drag-over { outline: 2px solid #2962ff; outline-offset: -2px; }

/* Pane-0 wrapper — must fill its grid cell exactly */
.chart-pane-main {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Minimized state for pane-0 */
.chart-pane-main.pane-minimized {
    height: 28px !important;
    min-height: 28px !important;
    overflow: hidden;
}
.chart-pane-main.pane-minimized > .chart-container { display: none; }

/* Extra panes */
.chart-pane {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--ui-panel);
    border: 1px solid var(--ui-panel-border);
    border-radius: 2px;
}
/* Allow the buy/sell panel to escape the pane boundary when open */
.chart-pane:has(.tv-bs-panel.open),
.chart-pane-main:has(.tv-bs-panel.open) { overflow: visible; }

/* Pane title bar */
.pane-header {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 28px;
    padding: 0 6px 0 10px;
    background: var(--ui-panel);
    border-bottom: 1px solid var(--ui-panel-border);
    flex-shrink: 0;
    user-select: none;
}
.pane-icon   { color: #26a69a; font-size: 13px; letter-spacing: -1px; }
.pane-symbol { font-size: 13px; font-weight: 700; color: var(--ui-fg); }
.pane-tf {
    font-size: 11px;
    font-weight: 600;
    color: var(--ui-muted, #787b86);
    background: rgba(120,123,134,0.12);
    border: 1px solid rgba(120,123,134,0.18);
    border-radius: 3px;
    padding: 0 5px;
    line-height: 18px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    flex-shrink: 0;
}
.pane-tf:hover {
    background: rgba(120,123,134,0.28);
    color: var(--ui-fg, #d1d4dc);
}
/* Window control buttons */
.pane-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1px;
    flex-shrink: 0;
}
.pane-ctrl {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--ui-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    font-size: 12px;
    line-height: 1;
    padding: 0;
    transition: background 0.12s, color 0.12s;
    flex-shrink: 0;
}
.pane-ctrl:hover            { background: rgba(120,123,134,0.18); color: var(--ui-fg); }
.pane-ctrl-close:hover      { background: #ef5350 !important; color: #fff !important; }
.pane-ctrl-ind:hover        { background: rgba(33,150,243,0.15) !important; color: #2196F3 !important; }
.pane-ctrl svg              { pointer-events: none; }

/* Minimized pane — show header only */
.chart-pane.pane-minimized .pane-canvas { display: none; }
.chart-pane.pane-minimized > .chart-container { display: none; }
.chart-pane.pane-minimized {
    min-height: 0 !important;
    height: 28px !important;
    overflow: hidden;
}

/* Maximized pane — fills entire layout area */
.chart-pane.pane-maximized {
    position: absolute !important;
    inset: 0 !important;
    z-index: 10;
    width: 100% !important;
    height: 100% !important;
}



/* Pane canvas fills remaining space */
.pane-canvas {
    display: block;
    flex: 1;
    width: 100%;
    min-height: 0;
    cursor: crosshair;
    user-select: none;
}

/* ── Single chart mode: hide ALL pane headers (symbol name + min/max/close) ──
   Two selectors for belt-and-suspenders reliability:
   1. JS-toggled body class (kept for browsers without :has support)
   2. Pure CSS :has() — fires immediately when DOM changes, no JS timing required */
body.single-chart .pane-header { display: none !important; }

/* When no .chart-pane element exists anywhere in the layout area, only the
   main pane (chart-pane-main) is present = single chart mode */
#chart-layout-area:not(:has(.chart-pane)) .pane-header { display: none !important; }

/* In single-chart mode the pane-header is hidden, so chart-container can
   fill from the top of the pane — no 28px dead zone */
body.single-chart .chart-pane-main > .chart-container { top: 0 !important; }
#chart-layout-area:not(:has(.chart-pane)) .chart-pane-main > .chart-container { top: 0 !important; }

/* When any pane is maximized (fills full screen), hide its header too */
.pane-maximized .pane-header { display: none !important; }
/* When pane-0 is maximized, header is hidden so chart-container can fill from top:0.
   This prevents the 28px dead-zone from partially overlapping the buy/sell toggle. */
.chart-pane-main.pane-maximized > .chart-container { top: 0 !important; }
/* Same for extra panes: when maximized, header is hidden so chart-container fills from top:0 */
.chart-pane.pane-maximized > .chart-container { top: 0 !important; }
/* Ensure widget is always clickable above the canvas */
.tv-bs-wrap { z-index: 300 !important; pointer-events: all !important; }
.tv-bs-wrap * { pointer-events: auto; }

/* ── Main Header Restore Button ── */
.ch-restore-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(128,128,128,.12);
    border: 1px solid rgba(128,128,128,.2);
    border-radius: 4px;
    color: var(--ui-fg, #d1d4dc);
    font-size: 11px;
    font-weight: 500;
    padding: 3px 8px;
    margin-right: 12px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.ch-restore-btn:hover {
    background: rgba(128, 128, 128, 0.22);
    color: #ffffff;
}
.ch-restore-btn svg {
    margin-right: 4px;
}

/* Remove borders and radius for maximized panes */
.pane-maximized {
    border: none !important;
    border-radius: 0 !important;
}
