/* ========================================
   Mobile Responsive — iPhone / Android 适配
   三栏 → 单栏 + 底部 Tab Bar
   ======================================== */

#mobileTabBar { display: none; }

@media (max-width: 768px) {

    /* ===== body 高度扣掉 tab bar ===== */
    body {
        flex-direction: column !important;
        overflow: hidden !important;
        height: calc(100vh - 56px) !important;
        height: calc(100dvh - 56px) !important;
        max-height: calc(100vh - 56px) !important;
        max-height: calc(100dvh - 56px) !important;
    }

    /* 隐藏左侧导航栏 */
    body > aside:first-of-type { display: none !important; }

    /* 隐藏右侧订单栏 */
    #orderSidebar {
        display: none !important;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 56px;
        width: 100% !important;
        z-index: 90;
        border: none !important;
    }
    #orderSidebar.mobile-visible { display: flex !important; }

    /* main */
    main {
        width: 100% !important;
        flex: 1 1 0% !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    .panel-content { max-height: 100% !important; }
    #panelChat {
        height: 100% !important;
        max-height: 100% !important;
    }

    /* ===== Tab Bar ===== */
    #mobileTabBar {
        display: flex !important;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: calc(56px + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: #1A1412;
        border-top: 2px solid rgba(198, 153, 58, 0.35);
        z-index: 100;
        justify-content: space-around;
        align-items: stretch;
    }
    .mobile-tab {
        flex: 1; display: flex; flex-direction: column;
        align-items: center; justify-content: center; gap: 2px;
        background: none; border: none;
        color: rgba(250, 246, 240, 0.4);
        font-size: 10px; font-family: 'Noto Sans SC', sans-serif; font-weight: 500;
        cursor: pointer; -webkit-tap-highlight-color: transparent;
        padding: 6px 0; min-height: 44px;
    }
    .mobile-tab svg { width: 22px; height: 22px; }
    .mobile-tab.active { color: #C6993A; }
    .mobile-tab:active { opacity: 0.7; }
    .mobile-tab .tab-badge {
        position: absolute; top: 4px; right: calc(50% - 16px);
        width: 8px; height: 8px; border-radius: 50%;
        background: #8B2D2D; display: none;
    }
    .mobile-tab .tab-badge.visible { display: block; }

    /* ===== 移动端新增元素 ===== */
    #mobileMenuBtn { display: inline-block !important; }
    #mobileNewChatBtn { display: inline-block !important; }

    .back-to-chat { display: none !important; }

    /* ===== 对话面板 ===== */
    #chatMessages {
        padding-left: 12px !important;
        padding-right: 12px !important;
        padding-top: 12px !important;
        padding-bottom: 12px !important;
    }

    /* 对话气泡字体加大 */
    .chat-bubble {
        font-size: 15px !important;
        line-height: 1.8 !important;
        max-width: 88% !important;
    }
    .chat-bubble p { font-size: 15px !important; }
    .chat-bubble li { font-size: 14px !important; }
    .chat-bubble h1, .chat-bubble h2, .chat-bubble h3 { font-size: 16px !important; }
    .chat-msg.user .chat-bubble { font-size: 15px !important; }

    .chat-welcome { padding: 16px !important; }
    .chat-welcome h2 { font-size: 1.3rem !important; }
    .chat-welcome p { font-size: 0.8rem !important; margin-bottom: 1rem !important; }
    .chat-welcome .quick-prompt,
    .chat-welcome button[data-prompt] {
        padding: 10px 12px !important;
        font-size: 13px !important;
        display: block !important;
    }

    /* 输入区紧凑 */
    #panelChat > div.border-t {
        padding: 6px 10px 4px !important;
    }
    #panelChat > div.border-t > div {
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    #agentQuickSelect {
        overflow-x: auto; flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch; scrollbar-width: none;
        gap: 6px !important; margin-bottom: 6px !important;
    }
    #agentQuickSelect::-webkit-scrollbar { display: none; }
    #agentQuickSelect .agent-tag {
        flex-shrink: 0; padding: 6px 10px !important; font-size: 11px !important;
    }

    #chatInput { font-size: 16px !important; padding: 8px 10px !important; }
    #btnSend { padding: 8px 14px !important; font-size: 14px !important; min-height: 40px; }
    #mentionDropdown { left: 0 !important; right: 0 !important; }

    /* ===== 持仓面板 ===== */
    #panelPortfolio .p-6 { padding: 10px !important; }
    #portfolioSummary {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    #portfolioSummary .text-lg,
    #portfolioSummary .font-bold {
        font-size: 17px !important;
    }
    #portfolioSummary .text-xs {
        font-size: 11px !important;
    }

    /* 隐藏桌面表头 */
    #portfolioList > div:first-child { display: none !important; }

    /* 持仓表头 sticky */
    #portfolioList > div:first-child {
        display: grid !important;
        position: sticky !important;
        top: 0;
        z-index: 5;
        grid-template-columns: 2fr 1.2fr 1.2fr 1fr !important;
        padding: 6px 10px !important;
        font-size: 10px !important;
        background: #1A1412 !important;
        color: rgba(250,246,240,0.5) !important;
    }
    /* 表头：只显示 股票/持仓/盈亏/市值，隐藏其余 */
    #portfolioList > div:first-child > span { display: none !important; }
    #portfolioList > div:first-child > span:nth-child(1),
    #portfolioList > div:first-child > span:nth-child(2),
    #portfolioList > div:first-child > span:nth-child(7),
    #portfolioList > div:first-child > span:nth-child(4) {
        display: block !important;
    }

    /* 持仓行 → 单行水平排列 */
    .portfolio-row {
        display: grid !important;
        grid-template-columns: 2fr 1.2fr 1.2fr 1fr !important;
        gap: 0 !important;
        padding: 8px 10px !important;
        margin: 0 !important;
        border: none !important;
        border-bottom: 1px solid rgba(26,20,18,0.08) !important;
        background: transparent !important;
        align-items: center !important;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    }
    .portfolio-row:active { background: rgba(26,20,18,0.05) !important; }

    /* checkbox 隐藏 */
    .portfolio-row > div:first-child { display: none !important; }

    /* 股票名+代码：紧凑 */
    .portfolio-row .stock-cell {
        padding: 0 !important;
        border: none !important;
        background: none !important;
    }
    .portfolio-row .stock-cell > div:first-child { font-size: 13px !important; }
    .portfolio-row .stock-cell > div:last-child { font-size: 10px !important; }

    /* 数据格：去掉标签，只显示数值 */
    .portfolio-row .data-cell {
        padding: 0 !important;
        font-size: 12px !important;
        font-weight: 600 !important;
        border: none !important;
    }
    .portfolio-row .data-cell::before { display: none !important; }

    /* 只显示：持仓、盈亏、市值 */
    .portfolio-row .data-cell[data-label="成本"],
    .portfolio-row .data-cell[data-label="现价"],
    .portfolio-row .data-cell[data-label="占比"] {
        display: none !important;
    }

    /* 盈亏格：紧凑单行 */
    .portfolio-row .data-cell[data-label="盈亏"] {
        display: block !important;
        padding: 0 !important;
    }
    .portfolio-row .data-cell[data-label="盈亏"] > div:last-child { display: none !important; }

    /* 操作按钮：手机端隐藏（整行可点击替代） */
    .portfolio-row .action-cell { display: none !important; }

    /* ===== 筛选/雷达面板 ===== */
    #panelScreener .p-6 { padding: 12px !important; }
    #panelRadar .p-6 { padding: 12px !important; }
    #panelRadar > div:first-child { flex-wrap: wrap; gap: 6px; }
    #panelRadar > div:first-child button {
        padding: 8px 10px !important; min-height: 34px; font-size: 11px !important;
    }
    #panelRadar .flex.border-2.border-ink.mb-4 button {
        padding: 10px 4px !important; min-height: 44px; font-size: 12px !important;
    }

    /* ===== 订单浮层 ===== */
    #orderSidebar.mobile-visible { animation: slideUp 0.25s ease-out; }
    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    #mobileOrderClose { display: flex !important; }
    #orderSidebar > .p-4 button { min-height: 48px; font-size: 15px !important; }

    /* 手动下单弹窗 */
    #manualOrderOverlay { z-index: 200 !important; align-items: stretch !important; }
    #manualOrderModal {
        width: 100% !important; max-height: 100vh !important;
        height: 100%; border: none !important; box-shadow: none !important;
    }
    #manualOrderModal input,
    #manualOrderModal select,
    #manualOrderModal textarea {
        font-size: 16px !important; min-height: 44px;
    }

    /* ===== 通用 ===== */
    * { -webkit-touch-callout: none; }
    input, textarea, [contenteditable] {
        -webkit-touch-callout: default; -webkit-user-select: auto;
    }

    /* ===== Demo 面板：在 agent 标签同层，不遮挡输入框 ===== */
    #demoControls {
        position: fixed !important;
        top: auto !important;
        /* 放在输入区上方 */
        bottom: auto !important;
        right: 8px !important;
        left: auto !important;
        /* 让它贴着屏幕顶部（标题栏下方） */
        top: 48px !important;
        width: auto !important;
        max-width: 220px !important;
        max-height: 45vh;
        overflow-y: auto;
        font-size: 11px;
        padding: 6px !important;
    }
    #demoControls.demo-collapsed { padding: 4px 8px !important; }

    .fixed.bottom-4 {
        bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

@media (max-width: 375px) {
    #chatMessages { padding-left: 8px !important; padding-right: 8px !important; }
    .chat-welcome h2 { font-size: 1.1rem !important; }
}
