/* =========================================================
   RIGHT DOCK
   右侧停靠栏
========================================================= */

#rightInspector {
    display: flex;

    flex: 0 0 auto;
    min-width: 0;
    min-height: 0;

    padding: 0;
    margin: 0;

    border: 0;
    overflow: hidden;

    background: #ffffff;
}


/* =========================================================
   DOCK LAYOUT
   面板在左，图标栏在右
========================================================= */

.right-dock {
    --right-panel-width: 320px;
    --right-rail-width: 48px;

    display: flex;
    flex-direction: row;
    align-items: stretch;

    flex: 0 0 auto;

    width: calc(
        var(--right-panel-width) +
        var(--right-rail-width)
    );

    height: 100%;

    min-width: 0;
    min-height: 0;

    margin: 0;
    padding: 0;

    gap: 0;

    overflow: hidden;

    box-sizing: border-box;

    background: #ffffff;

    border-left: 1px solid #e1e6ee;
    border-right: 0;

    border-radius: 0;

    box-shadow:
        -3px 0 12px rgb(25 42 70 / 3%);

    transition: width 180ms ease;
}


/* =========================================================
   CONTENT PANEL
   内容面板
========================================================= */

.right-dock-panel {
    display: flex;
    flex-direction: column;

    flex: 0 0 var(--right-panel-width);

    width: var(--right-panel-width);

    min-width: 0;
    min-height: 0;

    margin: 0;
    padding: 0;

    overflow: hidden;

    box-sizing: border-box;

    background: #ffffff;

    border: 0;

    transition:
        width 180ms ease,
        flex-basis 180ms ease,
        opacity 150ms ease;
}


/* =========================================================
   PANEL VIEWS
========================================================= */

.right-view {
    display: flex;
    flex-direction: column;

    flex: 1 1 auto;

    width: 100%;

    min-width: 0;
    min-height: 0;

    margin: 0;
    padding: 16px;

    gap: 12px;

    overflow-x: hidden;
    overflow-y: auto;

    box-sizing: border-box;

    background: #ffffff;
}


/* hidden 属性优先级 */

.right-view[hidden] {
    display: none !important;
}


/* =========================================================
   AI PANEL
========================================================= */

.right-view.ai-panel {
    padding: 0;
    gap: 0;

    overflow: hidden;
}


/* AI 标题 */

.right-view .ai-panel-head {
    flex: 0 0 auto;
}


/* AI 内容区域 */

.right-view .ai-panel-body {
    display: flex;
    flex-direction: column;

    flex: 1 1 auto;

    min-height: 0;

    overflow: hidden;
}


/* AI 消息列表 */

.right-view .ai-messages {
    flex: 1 1 auto;

    min-height: 0;

    overflow-x: hidden;
    overflow-y: auto;
}


/* AI 收起状态 */

#aiPanel.ai-collapsed .ai-panel-body {
    display: none;
}


/* =========================================================
   ACTIVITY BAR
   最右侧图标栏
========================================================= */

.right-activity-bar {
    position: relative;

    display: flex;
    flex-direction: column;
    align-items: stretch;

    flex: 0 0 var(--right-rail-width);

    width: var(--right-rail-width);
    min-width: var(--right-rail-width);

    height: 100%;

    margin: 0;
    padding: 6px 4px;

    gap: 4px;

    overflow: hidden;

    box-sizing: border-box;

    background: #f7f8fb;

    border: 0;
    border-left: 1px solid #e3e7ef;

    border-radius: 0;

    order: 2;
}


/* =========================================================
   ACTIVITY BUTTONS
========================================================= */

.right-activity-btn {
    position: relative;

    display: flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 40px;

    width: 100%;
    height: 40px;

    min-width: 0;

    margin: 0;
    padding: 0;

    box-sizing: border-box;

    color: #7b8798;

    background: transparent;

    border: 0;
    border-radius: 7px;

    cursor: pointer;

    transition:
        color 140ms ease,
        background-color 140ms ease,
        box-shadow 140ms ease;
}


/* 图标 */

.right-activity-btn svg {
    display: block;

    width: 21px;
    height: 21px;

    flex: 0 0 auto;

    fill: none;

    stroke: currentColor;

    stroke-width: 1.65;
    stroke-linecap: round;
    stroke-linejoin: round;

    transition:
        color 140ms ease,
        transform 140ms ease;
}


/* 悬停 */

.right-activity-btn:hover {
    color: #4f5fe3;

    background: #ecefff;
}


/* 当前选中 */

.right-activity-btn.active {
    color: #4f5fe3;

    background: #ffffff;

    box-shadow:
        0 1px 3px rgb(32 48 80 / 8%),
        0 0 0 1px rgb(79 95 227 / 9%);
}


/* 左侧选中指示线 */

.right-activity-btn.active::before {
    content: "";

    position: absolute;

    top: 7px;
    bottom: 7px;
    left: -4px;

    width: 3px;

    background: #2563eb;

    border-radius: 0 3px 3px 0;
}


/* 键盘焦点 */

.right-activity-btn:focus-visible {
    outline: 2px solid #5667e8;
    outline-offset: -3px;
}


/* =========================================================
   COLLAPSED STATE
   收起时只保留最右侧图标栏
========================================================= */

.right-dock.is-collapsed {
    flex: 0 0 var(--right-rail-width);

    width: var(--right-rail-width);
    min-width: var(--right-rail-width);

    overflow: hidden;
}


/* 收起内容面板 */

.right-dock.is-collapsed .right-dock-panel {
    display: none;
}


/* 收起后图标栏宽度保持不变 */

.right-dock.is-collapsed .right-activity-bar {
    display: flex;

    flex: 0 0 var(--right-rail-width);

    width: var(--right-rail-width);
    min-width: var(--right-rail-width);

    height: 100%;

    margin: 0;
}


/* =========================================================
   PANEL HEADERS
========================================================= */

.right-dock .inspector-head {
    flex: 0 0 auto;

    margin: 0 0 4px;
    padding: 0 0 12px;

    border-bottom: 1px solid #e8ebf1;
}


.right-dock .inspector-head h2 {
    margin: 4px 0 0;
}


/* =========================================================
   FORM CONTROLS
   统一右侧面板中的控件边框
========================================================= */

.right-dock input,
.right-dock textarea,
.right-dock select {
    box-sizing: border-box;

    border-color: #dfe4ec;

    transition:
        border-color 140ms ease,
        box-shadow 140ms ease;
}


.right-dock input:focus,
.right-dock textarea:focus,
.right-dock select:focus {
    border-color: #8b98f0;

    outline: none;

    box-shadow:
        0 0 0 3px rgb(86 103 232 / 10%);
}


/* =========================================================
   CODE EDITOR
========================================================= */

.right-dock .code-view {
    gap: 10px;
}


.right-dock .code-editor-wrap {
    display: flex;
    flex-direction: column;

    flex: 1 1 auto;

    min-width: 0;
    min-height: 200px;

    overflow: hidden;
}


.right-dock .code-editor {
    flex: 1 1 auto;

    min-width: 0;
    min-height: 160px;

    resize: vertical;
}


/* =========================================================
   WORKSPACE LAYOUT COMPATIBILITY
   不让右侧栏脱离工作区布局
========================================================= */

.workspace {
    min-width: 0;
    min-height: 0;
}


/* 中间画布区域占据剩余空间 */

.workspace > .center-column {
    flex: 1 1 0;

    min-width: 0;
    min-height: 0;
}


/* 右侧容器不能被挤压 */

.workspace > #rightInspector {
    flex: 0 0 auto;

    min-width: 0;
    min-height: 0;

    margin-right: 0;
    padding-right: 0;
}


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

@media (max-width: 900px) {
    .right-dock {
        --right-panel-width: min(320px, 42vw);
        --right-rail-width: 44px;
    }

    .right-activity-bar {
        padding: 6px 3px;
    }

    .right-activity-btn {
        flex-basis: 38px;
        height: 38px;
    }
}


@media (max-width: 560px) {
    .right-dock {
        --right-panel-width: min(300px, calc(100vw - 44px));
        --right-rail-width: 44px;
    }
}


/* =========================================================
   REDUCED MOTION
========================================================= */

@media (prefers-reduced-motion: reduce) {
    .right-dock,
    .right-dock-panel,
    .right-activity-btn,
    .right-activity-btn svg {
        transition: none;
    }
}

/* =========================================================
   FIX: RIGHT DOCK EDGE ALIGNMENT
   修复右侧空隙，以及收起后图标栏位置错误
========================================================= */

/* 工作区必须占满可用宽度 */
.workspace {
    display: flex !important;
    flex-direction: row;
    align-items: stretch;

    width: 100%;
    max-width: none;

    min-width: 0;
    min-height: 0;

    padding-right: 0 !important;
    margin-right: 0 !important;

    gap: 0 !important;
    box-sizing: border-box;
}

/* 中央区域自动填充剩余空间 */
.workspace > .center-column {
    flex: 1 1 0 !important;

    width: 0;
    min-width: 0;
    min-height: 0;
}

/* 右侧容器紧贴工作区最右侧 */
.workspace > #rightInspector {
    display: flex !important;
    flex: 0 0 auto !important;

    width: auto;

    min-width: 0;
    min-height: 0;

    margin: 0 !important;
    padding: 0 !important;

    border: 0 !important;

    overflow: hidden;
    box-sizing: border-box;
}

/* 右侧主体：面板 + 图标栏 */
#rightInspector .right-dock {
    display: flex !important;
    flex-direction: row;

    flex: 0 0 auto;

    width: calc(
        var(--right-panel-width, 320px) +
        var(--right-rail-width, 48px)
    );

    min-width: 0;
    height: 100%;

    margin: 0 !important;

    border-radius: 0;
    border-right: 0;

    box-sizing: border-box;
}

/* 图标栏固定在主体的最右侧 */
#rightInspector .right-activity-bar {
    order: 2;

    flex: 0 0 var(--right-rail-width, 48px);

    width: var(--right-rail-width, 48px);
    min-width: var(--right-rail-width, 48px);

    margin: 0 !important;
}

/* 内容面板位于图标栏左侧 */
#rightInspector .right-dock-panel {
    order: 1;

    flex: 0 0 var(--right-panel-width, 320px);

    width: var(--right-panel-width, 320px);
    min-width: 0;
}

/* 收起时主体宽度必须等于图标栏宽度 */
#rightInspector .right-dock.is-collapsed {
    flex: 0 0 var(--right-rail-width, 48px) !important;

    width: var(--right-rail-width, 48px) !important;
    min-width: var(--right-rail-width, 48px) !important;

    margin: 0 !important;
    padding: 0 !important;
}

/* 收起内容面板 */
#rightInspector .right-dock.is-collapsed .right-dock-panel {
    display: none !important;

    flex: 0 0 0 !important;
    width: 0 !important;
    min-width: 0 !important;
}

/* 收起后图标栏不缩小、不移动 */
#rightInspector .right-dock.is-collapsed .right-activity-bar {
    display: flex !important;

    order: 2;

    flex: 0 0 var(--right-rail-width, 48px) !important;

    width: var(--right-rail-width, 48px) !important;
    min-width: var(--right-rail-width, 48px) !important;
}

/* 防止右侧内部元素产生额外宽度 */
#rightInspector,
#rightInspector *,
#rightInspector *::before,
#rightInspector *::after {
    box-sizing: border-box;
}


/* =========================================================
   MOBILE FIX
   手机端隐藏整个右侧停靠栏
   注意：必须放在 right_dock.css 最末尾
========================================================= */

@media screen and (max-width: 900px) {

    /*
     * 1. 隐藏右侧最外层容器
     *
     * 覆盖文件中原有的：
     * .workspace > #rightInspector {
     *     display: flex !important;
     * }
     */
    .workspace > #rightInspector,
    #rightInspector {
        display: none !important;

        flex: 0 0 0 !important;

        width: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;

        margin: 0 !important;
        padding: 0 !important;

        border: 0 !important;

        overflow: hidden !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    /*
     * 2. 中央编辑区域占据剩余空间
     */
    .workspace > .center-column {
        display: flex;

        flex: 1 1 0 !important;

        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;

        margin: 0 !important;
    }

    /*
     * 3. 画布区域允许正常收缩
     */
    .workspace .stage-wrap {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .workspace .stage-frame {
        max-width: 100% !important;
        box-sizing: border-box;
    }
}

/* =========================================================
   SMALL MOBILE
========================================================= */

@media screen and (max-width: 560px) {

    .workspace > #rightInspector,
    #rightInspector {
        display: none !important;

        flex: 0 0 0 !important;

        width: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;

        margin: 0 !important;
        padding: 0 !important;

        border: 0 !important;

        overflow: hidden !important;
        visibility: hidden !important;
    }

    .workspace > .center-column {
        flex: 1 1 0 !important;

        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }
}

/* =========================================================
   右侧栏与左侧栏细节对齐
   ========================================================= */

.right-activity-btn.active {
    background: #eef3ff;
    color: #2563eb;

    box-shadow: none;
}

@media (min-width: 901px) {

    .right-activity-bar {
        padding: 8px 4px;
        gap: 6px;
    }

    .right-activity-btn {
        flex-basis: 40px;

        height: 40px;

        border-radius: 8px;
    }
}
