/* ==============================
   Panel Window System
   ============================== */

/* パネルレイヤー（全パネルの親） */
.panel-layer {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 50;
}

/* パネルウィンドウ */
.panel-window {
    position: absolute;
    background: var(--color-bg-light, #252540);
    border: 1px solid #444;
    border-radius: 5px;
    overflow: hidden;
    box-shadow: 0 3px 10px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    transition: box-shadow 0.15s;
}

.panel-window.panel-focused {
    border-color: var(--color-primary, #4a90d9);
    box-shadow: 0 3px 14px rgba(74,144,217,0.25);
}

/* ====== タイトルバー ====== */
.panel-titlebar {
    display: flex;
    align-items: center;
    background: #1a1a30;
    border-bottom: 1px solid #333;
    min-height: 24px;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
    overflow: hidden;
}
.panel-titlebar:active { cursor: grabbing; }

/* 単体パネルのタイトル */
.panel-title {
    padding: 2px 8px;
    font-size: 11px;
    color: var(--color-text-muted, #aaa);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* タブヘッダー */
.panel-tabs {
    display: flex;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    min-width: 0;
}
.panel-tabs::-webkit-scrollbar { height: 0; }

.panel-tab {
    padding: 3px 10px;
    font-size: 11px;
    color: var(--color-text-muted, #aaa);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
    transition: color 0.12s;
}
.panel-tab:hover { color: var(--color-text, #fff); }
.panel-tab.active {
    color: var(--color-primary, #4a90d9);
    border-bottom-color: var(--color-primary, #4a90d9);
}

/* タブドラッグ中のスタイル */
.panel-tab.dragging {
    opacity: 0.5;
}

/* ====== ウィンドウコントロール ====== */
.panel-controls {
    display: flex;
    gap: 1px;
    padding: 0 3px;
    margin-left: auto;
    flex-shrink: 0;
}

.panel-ctrl-btn {
    width: 18px; height: 18px;
    border: none;
    background: transparent;
    color: var(--color-text-muted, #aaa);
    font-size: 11px;
    cursor: pointer;
    border-radius: 3px;
    line-height: 18px;
    text-align: center;
    padding: 0;
}
.panel-ctrl-btn:hover {
    background: rgba(255,255,255,0.12);
    color: var(--color-text, #fff);
}

/* ====== コンテンツ領域 ====== */
.panel-content {
    flex: 1;
    overflow: auto;
    min-height: 0;
    position: relative;
}

/* タブ非アクティブのコンテンツを非表示 */
.panel-content-hidden {
    display: none !important;
}

/* ====== 最小化 ====== */
.panel-window.minimized .panel-content {
    display: none;
}
.panel-window.minimized .panel-resize {
    display: none;
}
.panel-window.minimized {
    height: auto !important;
}

/* ====== リサイズハンドル ====== */
.panel-resize {
    position: absolute;
    z-index: 10;
}
.panel-resize-n  { top: -3px; left: 8px; right: 8px; height: 6px; cursor: n-resize; }
.panel-resize-s  { bottom: -3px; left: 8px; right: 8px; height: 6px; cursor: s-resize; }
.panel-resize-e  { top: 8px; right: -3px; bottom: 8px; width: 6px; cursor: e-resize; }
.panel-resize-w  { top: 8px; left: -3px; bottom: 8px; width: 6px; cursor: w-resize; }
.panel-resize-ne { top: -3px; right: -3px; width: 10px; height: 10px; cursor: ne-resize; }
.panel-resize-nw { top: -3px; left: -3px; width: 10px; height: 10px; cursor: nw-resize; }
.panel-resize-se { bottom: -3px; right: -3px; width: 10px; height: 10px; cursor: se-resize; }
.panel-resize-sw { bottom: -3px; left: -3px; width: 10px; height: 10px; cursor: sw-resize; }

/* SE corner visual indicator */
.panel-resize-se::after {
    content: '';
    position: absolute;
    right: 2px; bottom: 2px;
    width: 6px; height: 6px;
    border-right: 2px solid rgba(255,255,255,0.2);
    border-bottom: 2px solid rgba(255,255,255,0.2);
}

/* ====== ドックインジケーター ====== */
.panel-window.dock-target {
    border-color: var(--color-primary, #4a90d9);
    border-style: dashed;
    box-shadow: 0 0 16px rgba(74,144,217,0.35);
}

/* ====== ドロップゾーンオーバーレイ (AE/UE5スタイル) ====== */
.dock-zone-overlay {
    position: absolute;
    pointer-events: none;
    z-index: 9998;
}
/* 各ゾーンの共通スタイル */
.dock-zone {
    position: absolute;
    border: 2px solid transparent;
    border-radius: 3px;
    transition: background 0.1s, border-color 0.1s;
}
.dock-zone.active {
    background: rgba(74,144,217,0.2);
    border-color: rgba(74,144,217,0.6);
}
/* プレビュー領域 */
.dock-preview {
    position: absolute;
    background: rgba(74,144,217,0.15);
    border: 2px dashed rgba(74,144,217,0.5);
    border-radius: 4px;
    z-index: 9997;
    pointer-events: none;
    transition: all 0.12s ease;
}
/* ドロップゾーンのアイコン表示 */
.dock-zone-icon {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 9998;
}
.dock-zone-diamond {
    position: absolute;
    width: 120px;
    height: 120px;
    pointer-events: none;
    z-index: 9998;
}
.dock-zone-diamond .dz {
    position: absolute;
    width: 30px;
    height: 30px;
    background: rgba(30,30,60,0.85);
    border: 1px solid rgba(74,144,217,0.4);
    border-radius: 4px;
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: rgba(255,255,255,0.5);
    transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.dock-zone-diamond .dz:hover,
.dock-zone-diamond .dz.active {
    background: rgba(74,144,217,0.5);
    border-color: var(--color-primary, #4a90d9);
    color: #fff;
}
.dock-zone-diamond .dz-top    { left: 45px; top: 0; }
.dock-zone-diamond .dz-bottom { left: 45px; bottom: 0; }
.dock-zone-diamond .dz-left   { left: 0; top: 45px; }
.dock-zone-diamond .dz-right  { right: 0; top: 45px; }
.dock-zone-diamond .dz-center { left: 45px; top: 45px; }

/* ====== マルチセレクト ====== */
.panel-window.panel-selected {
    outline: 2px solid rgba(255,180,50,0.7);
    outline-offset: -1px;
}
.panel-window.panel-selected .panel-titlebar {
    background: #2a2a10;
}

/* ====== 操作ツールバー ====== */
.panel-toolbar {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 950;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(20,20,40,0.92);
    border: 1px solid #555;
    border-radius: 8px;
    padding: 6px 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    backdrop-filter: blur(8px);
}
.panel-toolbar-label {
    font-size: 11px;
    color: var(--color-primary, #4a90d9);
    font-weight: bold;
    margin-right: 6px;
    white-space: nowrap;
}
.panel-toolbar-btn {
    background: rgba(255,255,255,0.08);
    color: #ccc;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
}
.panel-toolbar-btn:hover {
    background: rgba(255,255,255,0.18);
    color: #fff;
}
.panel-toolbar-btn.ptb-exit {
    background: rgba(200,60,60,0.25);
    border-color: rgba(200,60,60,0.5);
    color: #e88;
}
.panel-toolbar-btn.ptb-exit:hover {
    background: rgba(200,60,60,0.5);
    color: #fff;
}

/* ====== ドラッグ中のオーバーレイ ====== */
.panel-drag-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 9999;
    cursor: grabbing;
}

/* ====== パネルモード時の背景 ====== */
.battle-screen.panel-mode .battle-screen-inner {
    display: block;
    position: relative;
    width: 100%;
    height: 100%;
}
.battle-screen.panel-mode .battle-main {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    pointer-events: none;
}
/* 背景レイヤーだけはそのまま表示 */
.battle-screen.panel-mode .battle-bg-layer {
    pointer-events: none;
}
/* battle-main内の子要素はパネル化されるので非表示 */
.battle-screen.panel-mode .battle-main > *:not(.battle-bg-layer):not(.battle-bg-layer-a):not(.battle-bg-layer-b) {
    visibility: hidden;
    position: absolute;
    pointer-events: none;
}
/* サイドパネルも非表示 */
.battle-screen.panel-mode .battle-side-panel {
    display: none;
}
/* BGMバーとステータスバーもパネル化される */
.battle-screen.panel-mode > .bgm-control-bar,
.battle-screen.panel-mode > .game-status-bar {
    visibility: hidden;
    position: absolute;
    pointer-events: none;
}

/* パネル内にリペアレントされた要素はvisible */
.panel-content > * {
    visibility: visible !important;
    position: relative !important;
    pointer-events: auto !important;
}

/* ====== Layoutボタン ====== */
.layout-toggle-btn {
    background: rgba(74,144,217,0.15);
    color: var(--color-primary, #4a90d9);
    border: 1px solid rgba(74,144,217,0.3);
    border-radius: 4px;
    padding: 2px 10px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 8px;
    transition: background 0.15s;
}
.layout-toggle-btn:hover {
    background: rgba(74,144,217,0.3);
}
.layout-toggle-btn.active {
    background: var(--color-primary, #4a90d9);
    color: #fff;
}

.layout-settings-btn {
    background: transparent;
    color: var(--color-text-muted, #aaa);
    border: 1px solid #555;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 4px;
}
.layout-settings-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--color-text, #fff);
}
