/* ===== 全局 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    background: #0a0e14;
    color: #c9d1d9;
    font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    font-size: 14px;
    height: 100vh;
    overflow: hidden;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #0d1117; border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* ===== 顶栏 ===== */
.topbar {
    background: #131821;
    border-bottom: 1px solid #252d3a;
    padding: 10px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 56px;
    flex-shrink: 0;
    flex-wrap: wrap;
    row-gap: 8px;
}
.logo { font-size: 20px; font-weight: 700; color: #58a6ff; }
.topbar-right { display: flex; align-items: center; gap: 16px; font-size: 13px; color: #6e7681; }
.status-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    background: rgba(63,185,80,0.15);
    color: #3fb950;
}

/* ===== Tab导航 ===== */
.main-tabs {
    background: #131821;
    border-bottom: 1px solid #252d3a;
    padding: 0 24px;
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.main-tab {
    padding: 12px 20px;
    cursor: pointer;
    color: #6e7681;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    user-select: none;
}
.main-tab:hover { color: #c9d1d9; }
.main-tab.active { color: #58a6ff; border-bottom-color: #58a6ff; }

/* ===== Tab内容容器 ===== */
.tab-content {
    display: none;
    height: calc(100vh - 112px);
    padding: 12px 24px;
    overflow: auto;
}
.tab-content.active { display: block; }

/* ===== 面板 ===== */
.panel {
    background: #131821;
    border: 1px solid #252d3a;
    border-radius: 8px;
    resize: vertical;
    overflow: hidden;
    min-height: 120px;
    max-height: none;
    display: flex;
    flex-direction: column;
    flex: 0 1 auto;
    flex-shrink: 0; /* 防止flex容器重算导致面板缩回 */
}
.panel-header {
    padding: 8px 16px;
    border-bottom: 1px solid #252d3a;
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    min-height: 40px;
    flex-wrap: wrap;
    background: rgba(255,255,255,0.02);
}
.panel-body {
    flex: 1 1 0;
    overflow-y: auto !important;
    overflow-x: auto;
    padding: 4px 0;
    min-height: 60px;
    max-height: none;
}

/* [明日预测] CSS：panel 撑满 tab-content 可用高度，内容区自适应滚动 */
#tab-prediction .panel { display: flex; flex-direction: column; height: 100%; }
#tab-prediction .panel-body { flex: 1; overflow-y: auto !important; }



/* ===== 交易看板网格 ===== */
.dashboard-grid {
    display: flex;
    gap: 0;
    height: 100%;
    min-height: 0;
}
.left-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    min-width: 320px;
    flex-shrink: 0;
}
.right-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    min-width: 300px;
    flex: 1;
}

/* 列宽拖拽分割条（竖向） */
.col-splitter {
    width: 6px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.15s;
    position: relative;
    flex-shrink: 0;
    z-index: 5;
}
.col-splitter:hover,
.col-splitter.dragging {
    background: var(--accent, #58a6ff);
}
.col-splitter::before {
    content: '';
    position: absolute;
    top: 20%;
    bottom: 20%;
    left: 2px;
    width: 2px;
    background: rgba(88,166,255,0.3);
    border-radius: 1px;
    transition: background 0.15s;
}
.col-splitter:hover::before,
.col-splitter.dragging::before {
    background: var(--accent, #58a6ff);
}

/* 行高拖拽分割条（横向） */
.row-splitter {
    height: 6px;
    cursor: ns-resize;
    background: transparent;
    transition: background 0.15s;
    position: relative;
    flex-shrink: 0;
    z-index: 5;
}
.row-splitter:hover,
.row-splitter.dragging {
    background: var(--accent, #58a6ff);
}
.row-splitter::before {
    content: '';
    position: absolute;
    left: 20%;
    right: 20%;
    top: 2px;
    height: 2px;
    background: rgba(88,166,255,0.3);
    border-radius: 1px;
    transition: background 0.15s;
}
.row-splitter:hover::before,
.row-splitter.dragging::before {
    background: var(--accent, #58a6ff);
}

/* 全宽面板 */
.full-width { height: 100%; display: flex; flex-direction: column; }
.full-width .panel-body { flex: 1; overflow-y: auto; max-height: none; }

/* ===== 按钮 ===== */
.btn-refresh {
    background: transparent;
    border: 1px solid #252d3a;
    color: #6e7681;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-refresh:hover { background: #252d3a; color: #c9d1d9; }

/* ===== 选股方案切换 ===== */
.scheme-tabs {
    display: flex;
    gap: 4px;
    background: #0a0e14;
    border-radius: 6px;
    padding: 3px;
    flex-wrap: wrap;
}
.scheme-tab {
    padding: 4px 12px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #6e7681;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}
.scheme-tab:hover { color: #c9d1d9; background: rgba(255,255,255,0.05); }
.scheme-tab.active { background: #1a2030; color: #58a6ff; }

/* ===== 选股 A/B/C 三视图切换 ===== */
.view-toggle { display: inline-flex; gap: 4px; background: #0a0e14; border-radius: 6px; padding: 3px; margin-left: 8px; flex-wrap: wrap; }
.view-btn { padding: 4px 12px; border: none; border-radius: 4px; background: transparent; color: #6e7681; cursor: pointer; font-size: 12px; font-weight: 500; transition: all 0.2s; white-space: nowrap; }
.view-btn:hover { color: #c9d1d9; background: rgba(255,255,255,0.05); }
.view-btn.active { background: #1a2030; color: #58a6ff; }
/* B 视图五维进度条 */
.dim-cell { display: flex; flex-direction: column; gap: 2px; min-width: 140px; }
.dim-row { display: flex; align-items: center; gap: 4px; font-size: 10px; color: #8b949e; }
.dim-bar { flex: 1; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.06); overflow: hidden; }
.dim-bar > i { display: block; height: 100%; border-radius: 2px; }
.dim-tag { font-size: 10px; color: #8b949e; }

/* ===== 新闻切换 ===== */
.news-tabs {
    display: flex;
    gap: 4px;
    background: #0a0e14;
    border-radius: 6px;
    padding: 3px;
    margin-left: auto;
}
.news-tab {
    padding: 3px 12px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #6e7681;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    white-space: nowrap;
}
.news-tab:hover { color: #c9d1d9; }
.news-tab.active { background: #1a2030; color: #58a6ff; }

/* ===== 筛选器 ===== */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-left: auto;
    flex-wrap: wrap;
    align-items: center;
}
.filter-bar select {
    background: #0a0e14;
    border: 1px solid #252d3a;
    color: #c9d1d9;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    outline: none;
}
.filter-bar select:focus { border-color: #58a6ff; }

/* ===== 表格 ===== */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
    text-align: left;
    padding: 6px 12px;
    font-size: 11px;
    color: #6e7681;
    border-bottom: 2px solid #252d3a;
    position: sticky;
    top: 0;
    background: #131821;
    z-index: 2;
    white-space: nowrap;
}
td {
    padding: 6px 12px;
    border-bottom: 1px solid rgba(37,45,58,0.25);
    vertical-align: middle;
}
tr:hover td { background: rgba(88,166,255,0.03); }

/* ===== 标签 ===== */
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}
.tag-s { background: rgba(248,81,73,0.15); color: #f85149; }
.tag-a { background: rgba(210,153,34,0.15); color: #d29922; }
.tag-b { background: rgba(88,166,255,0.15); color: #58a6ff; }
.tag-mode { background: rgba(163,113,247,0.15); color: #a371f7; }

/* ===== 状态 ===== */
.empty-state { text-align: center; padding: 40px 20px; color: #6e7681; font-size: 13px; }
.loading { text-align: center; padding: 40px 20px; color: #6e7681; }

/* ===== 收益颜色 ===== */
.profit { color: #f85149; font-weight: 600; }
.loss { color: #3fb950; font-weight: 600; }

/* ===== 风险报警条 ===== */
.risk-alert {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    flex-shrink: 0;
}
.risk-alert.blink { animation: blinkRed 1s infinite; }
@keyframes blinkRed {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ===== T+2 加急提醒脉冲 ===== */
@keyframes pulseUrgent {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248,81,73,0.55); }
    50% { box-shadow: 0 0 0 4px rgba(248,81,73,0); }
}

/* ===== 涨停股标签 ===== */
.limit-up-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    background: rgba(248,81,73,0.1);
    border: 1px solid rgba(248,81,73,0.2);
    color: #f85149;
    cursor: pointer;
    margin: 2px;
    transition: all 0.15s;
}
.limit-up-tag:hover { background: rgba(248,81,73,0.2); }
.limit-up-tag .code { color: #6e7681; font-size: 10px; margin-left: 4px; }

/* ===== 指数 ===== */
#indicesRow {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 4px 12px;
    gap: 4px;
}
.idx-item {
    padding: 6px 8px;
    text-align: center;
    border-right: 1px solid #252d3a;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.6;
}
.idx-item:last-child { border-right: none; }
.idx-item.up { color: #f85149; }
.idx-item.down { color: #3fb950; }
.idx-item .idx-price { font-size: 16px; }
.idx-item .idx-change { font-size: 12px; }

/* ===== 新闻/题材 ===== */
.news-item, .theme-item {
    padding: 8px 16px;
    border-bottom: 1px solid rgba(37,45,58,0.2);
    font-size: 13px;
    line-height: 1.6;
}
.news-item:hover, .theme-item:hover { background: rgba(255,255,255,0.01); }
.news-time, .theme-score {
    font-size: 11px;
    color: #6e7681;
    margin-right: 12px;
}
.theme-bar {
    display: inline-block;
    height: 6px;
    border-radius: 3px;
    margin-left: 8px;
}

/* ===== 持仓操作 ===== */
.pos-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.pos-actions button {
    background: transparent;
    border: 1px solid #252d3a;
    color: #6e7681;
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.15s;
}
.pos-actions button:hover { background: #252d3a; color: #c9d1d9; }
.pos-actions .btn-sell {
    border-color: rgba(248,81,73,0.3);
    color: #f85149;
}
.pos-actions .btn-sell:hover { background: rgba(248,81,73,0.1); }

.btn-add-pos {
    background: #58a6ff;
    color: #fff;
    border: none;
    padding: 2px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: opacity 0.15s;
}
.btn-add-pos:hover { opacity: 0.8; }

/* ===== 提醒项 ===== */
.alert-item {
    padding: 8px 16px;
    border-left: 3px solid #6e7681;
    border-bottom: 1px solid rgba(37,45,58,0.2);
    font-size: 13px;
    line-height: 1.6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.alert-item:hover { background: rgba(255,255,255,0.01); }

/* ===== 交易记录表格包装 ===== */
.trade-table-wrap {
    border: 1px solid #252d3a;
    border-radius: 6px;
    margin: 8px 12px;
    overflow: auto;
}

/* ===== 模态框 ===== */
#positionModal, #stockDetailModal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 999;
    justify-content: center;
    align-items: center;
}
#positionModal.active, #stockDetailModal.active { display: flex; }
.modal-box {
    background: #131821;
    border: 1px solid #252d3a;
    border-radius: 10px;
    width: 420px;
    max-width: 90%;
    padding: 24px;
}

/* ===== 环境状态栏 ===== */
.env-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: #0a0e14;
    border: 1px solid #252d3a;
    border-radius: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    font-size: 13px;
}
.env-bar #envLabel {
    font-weight: 700;
    padding: 2px 12px;
    border-radius: 4px;
}

/* ===== 回测报告专用 ===== */
.bt-metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #252d3a;
}
.bt-metric-card {
    background: #0a0e14;
    border: 1px solid #252d3a;
    border-radius: 6px;
    padding: 12px 16px;
    text-align: center;
}
.bt-metric-label { font-size: 11px; color: #6e7681; }
.bt-metric-value { font-size: 20px; font-weight: 700; }
.bt-section {
    padding: 12px 16px;
    border-bottom: 1px solid #252d3a;
}
.bt-section-title {
    font-weight: 600;
    font-size: 14px;
    color: #c9d1d9;
    margin-bottom: 8px;
}
.bt-heatmap-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
}
.bt-heatmap-cell {
    padding: 8px;
    border-radius: 4px;
    text-align: center;
    font-size: 12px;
    color: #fff;
}
.bt-corr-cell {
    padding: 4px 8px;
    border-radius: 4px;
    text-align: center;
}

/* ===== 响应式（自适配屏幕大小） ===== */
/* 中等屏幕：收窄内边距，仍保持双列 */
@media (max-width: 1280px) {
    .topbar { padding: 10px 16px; }
    .main-tabs { padding: 0 16px; }
    .tab-content { padding: 12px 16px; }
    .panel-header { padding: 8px 12px; }
}
/* 平板 / 小屏笔记本：双列堆叠为单列，索引与指标降列，导航与筛选器换行 */
@media (max-width: 900px) {
    .dashboard-grid { flex-direction: column; }
    .dashboard-grid .left-col { width: 100% !important; min-width: 0; }
    .dashboard-grid .right-col { min-width: 0; }
    .col-splitter, .row-splitter { display: none; }
    .left-col, .right-col { min-height: 0; }
    .main-tabs { flex-wrap: wrap; overflow-x: visible; }
    .scheme-tabs, .news-tabs, .alert-filters, .filter-bar { flex-wrap: wrap; }
    #indicesRow { grid-template-columns: repeat(3, 1fr); }
    .bt-metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .bt-heatmap-grid { grid-template-columns: repeat(3, 1fr); }
    .env-bar { gap: 12px; }
}
/* 手机竖屏：进一步收紧，避免横向溢出 */
@media (max-width: 600px) {
    .topbar { flex-wrap: wrap; row-gap: 6px; }
    .main-tabs { gap: 2px; }
    .main-tab { padding: 10px 12px; font-size: 13px; }
    #indicesRow { grid-template-columns: repeat(2, 1fr); }
    .bt-metrics-grid { grid-template-columns: 1fr; }
    .env-bar { gap: 8px; font-size: 12px; }
    .panel-header { font-size: 12px; }
    .topbar-right { gap: 10px; }
}
/* 矮屏（笔记本压短窗口）：面板高度已由 clamp(vh) 自适应，此处让运维看板内联固定高度改为自适应，避免整页溢出 */
@media (max-height: 760px) {
    #tab-ops [style*="height:"] { height: auto !important; min-height: 120px !important; }
}

/* ============================================================
 * [layout-fix] 面板撑满：统一模型（覆盖上方默认布局，消除底部空白）
 * 每个激活 tab 用 flex 纵向列 → 子面板/容器 flex:1 撑满视口高度
 * .panel 本身已是 flex 列(style.css L79)，.panel-body 已是 flex:1(L98)
 * ============================================================ */
.tab-content.active {
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

/* 单面板 tab（明日预测/回测/交易记录/因子投研）：唯一面板撑满整 tab */
#tab-prediction > .panel,
#tab-backtest   > .panel,
#tab-trades     > .panel,
#tab-factors    > .panel {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    height: auto !important;
}

/* 交易看板：env-bar 固定 → dashboard-grid 撑满剩余 → 列内末只撑满 */
#tab-dashboard > .env-bar       { flex: 0 0 auto !important; }
#tab-dashboard > .dashboard-grid { flex: 1 1 0 !important; min-height: 0 !important; }
#tab-dashboard .right-col > #alertPanel,
#tab-dashboard .left-col  > #recommendPanel { flex: 1 1 0 !important; min-height: 0 !important; }

/* 运维看板：面板多(左5+右4≈900px)，视口够时撑满、不够时整个 tab 可滚动 */
#tab-ops.tab-content.active            { overflow-y: auto !important; }
#tab-ops > .panel.full-width           { flex: 0 0 auto !important; }
/* flex:1 1 auto → 空间富余时撑满消除空白；min-height 保底 → 空间不足时不压缩，触发 #tab-ops 整体滚动条 */
#tab-ops > .dashboard-grid             { flex: 1 1 auto !important; min-height: 900px !important; height: auto !important; }
#tab-ops .dashboard-grid > .left-col  > .panel,
#tab-ops .dashboard-grid > .right-col > .panel { flex: 1 1 0 !important; min-height: 0 !important; }
/* ===== [次日涨停倾向 TOP20] 盘后研究 + 盘中实时监控 ===== */
.top20-table { width:100%; border-collapse:collapse; font-size:12px; }
.top20-table th, .top20-table td { padding:5px 8px; text-align:right; border-bottom:1px solid #21262d; white-space:nowrap; }
.top20-table th { color:#8b949e; font-weight:600; background:#0d1117; position:sticky; top:0; }
.top20-table td:nth-child(2), .top20-table td:nth-child(3), .top20-table th:nth-child(2), .top20-table th:nth-child(3) { text-align:left; }
.top20-table tbody tr:hover { background:#161b22; }
.top20-table .pos { color:#f85149; font-weight:600; }
.top20-table .neg { color:#3fb950; font-weight:600; }
.top20-flag { display:inline-block; margin:1px 3px 1px 0; padding:1px 6px; border-radius:10px; font-size:10px; line-height:1.5; }
.top20-flag.flag-a { background:rgba(248,81,73,0.14); color:#f85149; border:1px solid rgba(248,81,73,0.3); }
.top20-flag.flag-b { background:rgba(210,153,34,0.14); color:#d29922; border:1px solid rgba(210,153,34,0.3); }
.top20-flag.breakout { background:rgba(88,166,255,0.14); color:#58a6ff; border:1px solid rgba(88,166,255,0.3); font-weight:600; }
