/**
 * HuyTech Power_IDE — Cursor-style split workspace
 * Left: sandbox canvas · Right: agent + tool calling
 * Requires html.lab-ide
 */

html.lab-ide,
html.lab-ide body {
    height: 100%;
    max-height: 100dvh;
    overflow: hidden;
}

html.lab-ide {
    padding-top: env(safe-area-inset-top, 0px);
    background: #0a0a0a;
}

html.lab-ide body {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    /* navbar 改为文档流后不再需要顶 padding 硬顶开 */
    padding: 0 !important;
    margin: 0 !important;
    min-height: 100dvh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    background: #070707;
    box-sizing: border-box;
    overflow: hidden !important;
}

html.lab-ide .lab-ide-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px 16px;
    flex: 0 0 auto;
    padding: 8px 14px;
    max-width: none;
    width: 100%;
    box-sizing: border-box;
    background: #090909;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

html.lab-ide .lab-ide-header-main {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    flex: 1 1 auto;
}

html.lab-ide .lab-ide-header h1 {
    margin: 0;
    font-size: 13px;
    font-weight: 650;
    letter-spacing: 0.02em;
    line-height: 1.2;
    color: #f0f0f0;
    white-space: nowrap;
    flex-shrink: 0;
}

html.lab-ide .lab-ide-header p {
    display: none;
}

html.lab-ide .lab-ide-header-links {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

html.lab-ide .lab-ide-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-left: 4px;
    border-radius: 50%;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, 0.16);
    flex-shrink: 0;
}

html.lab-ide .lab-ide-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

html.lab-ide .lab-ide-collapse-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #d4d4d4;
    background: rgba(255, 255, 255, 0.04);
    font-size: 12px;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1.2;
    font-family: inherit;
}

html.lab-ide .lab-ide-collapse-btn:hover {
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

html.lab-ide .lab-ide-link {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border: 1px solid rgba(212, 165, 116, 0.4);
    color: #e8c4a0;
    text-decoration: none;
    font-size: 12px;
    border-radius: 6px;
    background: rgba(212, 165, 116, 0.06);
    line-height: 1.2;
    white-space: nowrap;
}

html.lab-ide .lab-ide-link:hover {
    border-color: rgba(212, 165, 116, 0.85);
    color: #fff;
}

/* 项目条已上移到顶栏 navbar；header 内不再占位 */
html.lab-ide .lab-ide-header .lab-project-bar {
    display: none;
}

html.lab-ide .lab-project-label {
    font-size: 11px;
    opacity: 0.55;
    margin-right: 2px;
}

html.lab-ide .lab-project-btn {
    padding: 4px 9px;
    font-size: 11px;
    line-height: 1.25;
    border-radius: 5px;
}

@media (max-width: 720px) {
    html.lab-ide .lab-ide-header {
        flex-wrap: wrap;
        padding: 8px 10px;
        gap: 8px;
    }

    html.lab-ide .lab-ide-header-main {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }

    html.lab-ide .lab-ide-header-links {
        width: 100%;
        justify-content: flex-start;
    }
}

/* 工况条占高，IDE 下隐藏（DOM 保留供 sync 写数） */
html.lab-ide .lab-sync-strip {
    display: none !important;
}

html.lab-ide .lab-ide-workspace {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    display: block;
    width: 100%;
    max-width: none;
    overflow: hidden;
}

/* 收缩 AI → 仅保留全幅画布 */
html.lab-ide.lab-ide-agent-collapsed .lab-ide-right {
    display: none !important;
}

html.lab-ide .lab-ide-expand-fab {
    display: none;
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 40;
    padding: 10px 12px;
    border: 1px solid rgba(212, 165, 116, 0.55);
    border-right: none;
    border-radius: 8px 0 0 8px;
    background: rgba(20, 16, 12, 0.94);
    color: #e8c4a0;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    writing-mode: vertical-rl;
    letter-spacing: 0.08em;
    box-shadow: -4px 0 18px rgba(0, 0, 0, 0.45);
}

html.lab-ide.lab-ide-agent-collapsed .lab-ide-expand-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

html.lab-ide .lab-ide-expand-fab:hover,
html.lab-ide .lab-ide-collapse-fab:hover {
    color: #fff;
    border-color: rgba(212, 165, 116, 0.9);
}

html.lab-ide .lab-ide-expand-fab,
html.lab-ide .lab-ide-collapse-fab {
    right: 0 !important;
    left: auto !important;
    top: 50% !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
}

html.lab-ide .lab-ide-collapse-fab {
    display: none;
    position: fixed;
    z-index: 40;
    padding: 10px 12px;
    border: 1px solid rgba(212, 165, 116, 0.55);
    border-right: none;
    border-radius: 8px 0 0 8px;
    background: rgba(20, 16, 12, 0.94);
    color: #e8c4a0;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    writing-mode: vertical-rl;
    letter-spacing: 0.08em;
    box-shadow: -4px 0 18px rgba(0, 0, 0, 0.45);
}

html.lab-ide:not(.lab-ide-agent-collapsed) .lab-ide-collapse-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* 画布铺满 workspace；AI 叠在右侧/底部 HUD */
html.lab-ide .lab-ide-left {
    position: absolute;
    inset: 0;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #050505;
    z-index: 1;
}

html.lab-ide .lab-ide-right {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: clamp(280px, 34vw, 420px);
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 30;
    background: transparent;
    pointer-events: none;
}

/* Both panels visible */
html.lab-ide #modeViz.mode-panel,
html.lab-ide #modeAgent.mode-panel,
html.lab-ide #modeViz.mode-panel.active,
html.lab-ide #modeAgent.mode-panel.active {
    display: flex !important;
    flex: 1 1 auto;
    min-height: 0;
    max-width: none;
    width: 100%;
}

html.lab-ide .lab-ide-left #modeViz,
html.lab-ide .lab-ide-right #modeAgent {
    margin: 0;
    padding: 0;
}

html.lab-ide .viz-main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    gap: 0;
    height: 100%;
    min-height: 0;
}

html.lab-ide .viz-control-panel {
    display: none !important;
}

html.lab-ide .canvas-area {
    border-radius: 0;
    border: none;
    height: 100%;
    min-height: 0;
}

html.lab-ide .sandbox-fs-open {
    display: none;
}

html.lab-ide .lab-ide-right #modeAgent {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    width: 100%;
}

html.lab-ide .lab-ide-right #modeAgent,
html.lab-ide .agent-shell,
html.lab-ide .agent-chat-panel {
    pointer-events: none;
}

html.lab-ide .agent-messages,
html.lab-ide .agent-messages-container,
html.lab-ide .agent-input-row,
html.lab-ide .agent-media-hamburger,
html.lab-ide #ide-image-preview,
html.lab-ide .agent-msg {
    pointer-events: auto;
}

html.lab-ide .agent-shell {
    display: flex !important;
    flex-direction: column;
    flex: 1 1 auto;
    max-height: none !important;
    min-height: 0 !important;
    height: 100%;
    gap: 0;
    grid-template-columns: none;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
}

html.lab-ide .agent-data-panel {
    display: none !important;
}

html.lab-ide .agent-chat-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    height: 100%;
    border-radius: 0;
    border: none;
    background: transparent;
}

html.lab-ide .agent-messages,
html.lab-ide .agent-messages-container {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 0;
    -webkit-overflow-scrolling: touch;
}

/* 消息少时贴底；溢出后可正常上下滚动（勿用 justify-content:flex-end） */
html.lab-ide .agent-messages > .agent-msg:first-child,
html.lab-ide .agent-messages-container > .agent-msg:first-child {
    margin-top: auto;
}

/* 设计工具坞：从 stash 挪到左侧沙盒画布后仍可见 */
html.lab-ide #canvasContainer .design-tool-dock {
    display: flex;
    z-index: 8;
}

html.lab-ide #canvasContainer .canvas-floating-controls {
    z-index: 7;
}

/* 1. 去掉走马灯推荐问题 */
html.lab-ide .agent-chips {
    display: none !important;
}

/* 2. 发送键更矮更窄 */
html.lab-ide .agent-input-row {
    flex: 0 0 auto;
    align-items: flex-end;
    gap: 8px;
    margin-top: 0;
    padding: 8px 10px max(10px, env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(8, 8, 8, 0.78);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

html.lab-ide .agent-input-row textarea {
    min-height: 36px;
    max-height: 96px;
    padding: 8px 10px;
    font-size: 13px;
    border-radius: 8px;
}

html.lab-ide .agent-send-btn {
    min-width: 0;
    width: auto;
    min-height: 0;
    height: 36px;
    padding: 0 12px;
    gap: 4px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    align-self: flex-end;
}

html.lab-ide .agent-send-btn .send-icon {
    width: 14px;
    height: 14px;
}

html.lab-ide .agent-send-btn .send-icon svg {
    width: 14px;
    height: 14px;
}

html.lab-ide .lab-ide-stash {
    display: none !important;
}

/* agent 多媒体按钮 */
html.lab-ide .agent-media-hamburger {
    position: relative;
    flex-shrink: 0;
}
html.lab-ide .agent-media-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.15);
    background: transparent;
    color: rgba(255,255,255,0.55);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
html.lab-ide .agent-media-toggle:hover,
html.lab-ide .agent-media-hamburger.open .agent-media-toggle {
    background: rgba(255,255,255,0.12);
    color: #fff;
}
html.lab-ide .agent-media-popup {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    border-radius: 10px;
    background: #1a1a1a;
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    min-width: 120px;
    z-index: 100;
}
html.lab-ide .agent-media-hamburger.open .agent-media-popup {
    display: flex;
}
html.lab-ide .agent-media-popup .agent-media-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    font-size: 13px;
    text-decoration: none;
    transition: background 0.15s;
}
html.lab-ide .agent-media-popup .agent-media-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}
html.lab-ide .agent-media-popup .media-label {
    white-space: nowrap;
}
html.lab-ide .agent-media-btns {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}
html.lab-ide .agent-media-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    color: #cbd5e1;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    padding: 0;
}
html.lab-ide .agent-media-btn:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.25);
    color: #fff;
}
html.lab-ide .agent-media-btn.voice-recording {
    background: rgba(239,68,68,0.25);
    border-color: rgba(239,68,68,0.5);
    color: #f87171;
}
html.lab-ide #ide-image-preview {
    padding: 6px 8px;
    background: rgba(8, 8, 8, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
html.lab-ide #ide-image-preview img {
    max-height: 80px;
    border-radius: 6px;
}
html.lab-ide #ide-image-preview .ai-image-preview-clear {
    margin-left: 6px;
    background: rgba(200,40,40,0.7);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
}

@media (max-width: 900px) {
    html.lab-ide,
    html.lab-ide body {
        overflow: hidden;
        height: 100dvh;
        max-height: 100dvh;
    }

    /* 窄屏：画布全幅，AI 贴底浮层（必须给明确高度，避免 flex 子项塌成 0） */
    html.lab-ide .lab-ide-right {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: min(52vh, 420px);
        min-height: 112px;
        max-height: min(52vh, 420px);
    }

    html.lab-ide .agent-messages,
    html.lab-ide .agent-messages-container {
        flex: 1 1 auto;
        min-height: 0;
    }
}
