/* ========== 主题变量 ========== */
:root {
    --color-up: #ea3800;
    --color-down: #56b7aa;
    --accent-blue: #58a6ff;
    --accent-gold: #f0b429;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #1c2128;
    --border-color: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --hover-bg: rgba(88, 166, 255, 0.08);
    --color-down: #56b7aa;
}

[data-theme="light"] {
    --bg-primary: #f6f8fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --border-color: #d0d7de;
    --text-primary: #1f2328;
    --text-secondary: #57606a;
    --text-muted: #6e7781;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --hover-bg: rgba(37, 99, 235, 0.07);
    --color-up: #d93a3a;
    --color-down: #047857;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.logo-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), #3b82f6);
    box-shadow: 0 0 8px rgba(88, 166, 255, 0.6);
}

.topbar-title { font-size: 17px; font-weight: 700; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.stage-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    background: var(--bg-card);
}

.stage-badge.trading { color: #3fb950; border-color: rgba(63, 185, 80, 0.5); }
.stage-badge.closed { color: var(--text-muted); }

.clock {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover { background: var(--hover-bg); color: var(--accent-blue); border-color: var(--accent-blue); }

.dashboard { padding: 14px 16px 24px; max-width: 1720px; margin: 0 auto; }

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 6px;
}

.panel-title { font-size: 14px; font-weight: 700; }
.panel-sub { font-size: 12px; color: var(--text-muted); }

.index-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 10px;
}

.index-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s;
}

.index-card:hover { border-color: var(--accent-blue); transform: translateY(-1px); }
.index-card.active { border-color: var(--accent-blue); box-shadow: 0 0 0 1px var(--accent-blue); }

.index-card .idx-name { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.index-card .idx-price { font-size: 24px; font-weight: 700; font-family: var(--font-mono); line-height: 1.2; }
.index-card .idx-meta { display: flex; gap: 10px; font-size: 12px; color: var(--text-secondary); margin-top: 3px; font-family: var(--font-mono); }

.stat-cards {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    margin-bottom: 10px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 14px;
}

.stat-card .st-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-card .st-value { font-size: 17px; font-weight: 700; font-family: var(--font-mono); }
.stat-card .st-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; font-family: var(--font-mono); }

.mid-section {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 10px;
    margin-bottom: 10px;
}

.chart-tabs { display: flex; gap: 4px; }

.chart-tabs button {
    padding: 4px 12px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.chart-tabs button:hover { color: var(--accent-blue); border-color: var(--accent-blue); }
.chart-tabs button.active { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }

.chart-legend { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 14px; height: 2px; vertical-align: middle; }
.lg-price { background: var(--accent-blue); }
.lg-avg { background: var(--accent-gold); }
.lg-pre { background: repeating-linear-gradient(90deg, var(--text-muted) 0 3px, transparent 3px 6px); height: 1px; }

.chart-box { height: 300px; padding: 0 6px 6px; }

.timeline-list {
    height: 300px;
    overflow-y: auto;
    padding: 4px 10px 10px;
}

.timeline-list::-webkit-scrollbar { width: 5px; }
.timeline-list::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

.tl-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 13px;
}

.tl-item:hover { background: var(--hover-bg); }

.tl-time {
    flex: 0 0 40px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
}

.tl-name { font-weight: 600; color: var(--color-up); min-width: 70px; }
.tl-tag {
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
    background: rgba(234, 56, 0, 0.12);
    color: var(--color-up);
    white-space: nowrap;
}
.tl-tag.high { background: rgba(240, 180, 41, 0.15); color: var(--accent-gold); }
.tl-hy { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-fund { margin-left: auto; font-size: 11px; color: var(--text-secondary); font-family: var(--font-mono); white-space: nowrap; }

.empty { text-align: center; color: var(--text-muted); font-size: 13px; padding: 40px 0; }

.tables-section {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.table-panel { min-width: 0; }

.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }

.data-table th {
    text-align: left;
    padding: 6px 8px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    font-family: var(--font-mono);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--hover-bg); }

.data-table .num { text-align: right; }
.data-table th.num { text-align: right; }

.stock-name { font-family: var(--font-sans); font-weight: 500; }

.pos { color: var(--color-up); }
.neg { color: var(--color-down); }
.muted { color: var(--text-muted); }

.dashboard-footer {
    margin-top: 14px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.8;
}

@media (max-width: 1200px) {
    .stat-cards { grid-template-columns: repeat(3, 1fr); }
    .mid-section { grid-template-columns: 1fr; }
    .tables-section { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
    .index-cards { grid-template-columns: repeat(2, 1fr); }
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
    .tables-section { grid-template-columns: 1fr; }
}

/* ========== 暗盘资金面板 ========== */
.darkpool-panel { margin-top: 10px; }

.dp-search-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 14px 6px;
    flex-wrap: wrap;
}

.dp-search-wrap { position: relative; width: 420px; max-width: 100%; }

.dp-search {
    width: 100%;
    padding: 9px 12px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
    font-family: var(--font-sans);
}

.dp-search:focus { border-color: var(--accent-blue); }

.dp-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--shadow-color);
    max-height: 280px;
    overflow-y: auto;
    display: none;
}

.dp-dropdown.open { display: block; }

.dp-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    cursor: pointer;
    font-size: 13px;
}

.dp-item:hover { background: var(--hover-bg); }

.dp-item .dp-item-name { font-weight: 600; }
.dp-item .dp-item-code { font-family: var(--font-mono); color: var(--text-secondary); }
.dp-item .dp-item-mkt { margin-left: auto; font-size: 11px; color: var(--text-muted); }
.dp-item .dp-item-py { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

.dp-empty { padding: 12px; text-align: center; color: var(--text-muted); font-size: 12px; }

.dp-stock-head { font-size: 14px; font-weight: 700; }
.dp-stock-head .dp-head-pct { margin-left: 10px; font-family: var(--font-mono); }
.dp-stock-head .dp-head-muted { color: var(--text-muted); font-weight: 400; font-size: 12px; margin-left: 8px; }

.dp-refresh { margin-left: auto; }

#dp-daily-table { table-layout: fixed; width: 100%; }
#dp-daily-table th, #dp-daily-table td { text-align: left; }

.dp-summary-row td {
    background: var(--bg-primary);
    border-bottom: 2px solid var(--border-color);
    padding: 10px 8px;
    vertical-align: top;
}

.dp-sum-label { font-size: 11px; color: var(--text-secondary); margin-bottom: 3px; white-space: nowrap; }
.dp-sum-value { font-size: 16px; font-weight: 700; font-family: var(--font-mono); line-height: 1.2; white-space: nowrap; }
.dp-sum-value.small { font-size: 13px; }

.dp-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 8px 14px 4px;
}

.dp-chart-wrap {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
}

.dp-chart-title { font-size: 12px; color: var(--text-secondary); padding: 2px 4px 4px; }
.dp-chart { height: 260px; }

.dp-table-wrap {
    max-height: 240px;
    overflow-y: auto;
    margin: 8px 14px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.dp-table-wrap::-webkit-scrollbar { width: 5px; }
.dp-table-wrap::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

.dp-table-wrap .data-table th { position: sticky; top: 0; background: var(--bg-card); z-index: 1; }

@media (max-width: 1200px) {
    .dp-charts { grid-template-columns: 1fr; }
}
/* ========== 榜单表格对齐（固定列宽） ========== */
.tables-section .data-table { table-layout: fixed; }
.tables-section .data-table th,
.tables-section .data-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ========== 可点击的统计卡片 / 时间轴 ========== */
.stat-card[data-modal] { cursor: pointer; }
.stat-card[data-modal]:hover { border-color: var(--accent-blue); background: var(--hover-bg); }
.tl-item { cursor: pointer; }

/* ========== 个股弹窗 ========== */
.sm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.sm-overlay[hidden] { display: none; }

.sm-modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 100%;
    max-width: 860px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.sm-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 2;
}

.sm-title { font-size: 15px; font-weight: 700; }
.sm-sub { font-size: 12px; color: var(--text-muted); flex: 1; }

.sm-list { padding: 10px 14px 14px; }

.sm-list table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

.sm-list th {
    text-align: left;
    padding: 8px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    white-space: nowrap;
}

.sm-list td {
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sm-list td:first-child, .sm-list th:first-child {
    width: 26%;
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--text-primary);
}

.sm-row { cursor: pointer; }
.sm-row:hover { background: var(--hover-bg); }

.sm-chart-wrap { padding: 10px 14px 14px; }

.sm-chart-head {
    font-size: 13px;
    padding: 2px 4px 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.sm-back {
    padding: 4px 12px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.sm-back:hover { color: var(--accent-blue); border-color: var(--accent-blue); }

.sm-chart { height: 380px; }

/* ========== 连板天梯（金字塔） ========== */
.ladder-panel { margin-top: 10px; }

.lt-ladder { padding: 6px 4px; }

/* 弹窗标签页内的表格 */
#sm-tabcontent table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
#sm-tabcontent th {
    text-align: left; padding: 8px; font-weight: 600; color: var(--text-muted);
    border-bottom: 1px solid var(--border-color); white-space: nowrap;
}
#sm-tabcontent td {
    padding: 8px; border-bottom: 1px solid var(--border-color);
    font-family: var(--font-mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#sm-tabcontent td:first-child, #sm-tabcontent th:first-child { font-family: var(--font-sans); font-weight: 600; color: var(--text-primary); }
#sm-tabcontent tr.sm-row { cursor: pointer; }
#sm-tabcontent tr.sm-row:hover { background: var(--hover-bg); }

.tables-section { margin-top: 10px; }

/* ========== 弹窗标签页 ========== */
.sm-tabs {
    display: flex;
    gap: 6px;
    padding: 12px 14px 0;
}

.sm-tab {
    padding: 5px 16px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.sm-tab:hover { color: var(--accent-blue); border-color: var(--accent-blue); }
.sm-tab.active { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }

#sm-tabcontent { padding: 12px 14px 14px; }

#sm-tabcontent .lt-ladder-lt { width: 100%; }

@media (max-width: 900px) {
    .lt-row { gap: 4px; }
    .lt-chip { padding: 3px 7px; font-size: 11px; }
}
/* ========== 连板天梯（卡片式） ========== */
.lt-date {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    padding: 2px 2px 8px;
}

.lt-date-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-gold);
    box-shadow: 0 0 6px rgba(240, 180, 41, 0.7);
}

.lt-ladder-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 4px 2px 8px;
}

.lt-row {
    display: flex;
    align-items: stretch;
    gap: 14px;
}

.lt-rail {
    flex: 0 0 76px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    border-radius: 12px;
    background: linear-gradient(160deg, rgba(240, 180, 41, 0.18), rgba(240, 180, 41, 0.05));
    border: 1px solid rgba(240, 180, 41, 0.35);
    padding: 8px 4px;
}

.lt-num {
    font-size: 22px;
    font-weight: 800;
    color: var(--accent-gold);
    font-family: var(--font-mono);
    line-height: 1.1;
}

.lt-lb { font-size: 10px; color: var(--accent-gold); opacity: 0.9; }
.lt-cnt { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

.lt-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
    gap: 8px;
}

.lt-cell {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.12s, box-shadow 0.12s;
    overflow: hidden;
}

.lt-cell b {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-gold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lt-cell:hover {
    border-color: var(--accent-blue);
    background: var(--hover-bg);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.lt-gao {
    flex: 0 0 auto;
    display: inline-block;
    padding: 1px 5px;
    font-size: 10px;
    line-height: 15px;
    border-radius: 4px;
    background: #e5484d;
    color: #fff;
    font-weight: 700;
}

/* ========== 手机端适配 ========== */
@media (max-width: 480px) {
    .topbar { padding: 8px 10px; }
    .topbar-left { gap: 8px; }
    .topbar-title { font-size: 15px; }
    .topbar-right { gap: 6px; }
    .stage-badge { font-size: 11px; padding: 2px 8px; }
    .clock { font-size: 12px; }

    .dashboard { padding: 10px 10px 20px; }

    .index-card { padding: 10px 12px; }
    .index-card .idx-price { font-size: 20px; }
    .index-card .idx-meta { gap: 8px; font-size: 11px; flex-wrap: wrap; }

    .stat-card { padding: 8px 10px; }
    .stat-card .st-value { font-size: 15px; }

    .panel-head { padding: 8px 10px 4px; flex-wrap: wrap; gap: 4px; }

    .chart-box { height: 240px; }
    .timeline-list { height: 240px; padding: 4px 6px 8px; -webkit-overflow-scrolling: touch; }
    .tl-item { gap: 6px; font-size: 12px; padding: 6px; }
    .tl-hy { display: none; }
    .tl-name { min-width: 0; flex: 1; }
    .tl-fund { margin-left: 0; }

    /* 输入框 16px 防止 iOS 聚焦自动放大 */
    .dp-search-row { padding: 10px 10px 6px; gap: 8px; }
    .dp-search { font-size: 16px; padding: 8px 10px; }
    .dp-stock-head { font-size: 13px; }
    .dp-charts { padding: 8px 10px 4px; }
    .dp-chart { height: 210px; }

    /* 暗盘明细表：整表横向滚动，避免压扁 */
    .dp-table-wrap { margin: 8px 10px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    #dp-daily-table { min-width: 620px; }
    .dp-summary-row td { padding: 8px 6px; }
    .dp-sum-label { font-size: 10px; }
    .dp-sum-value { font-size: 14px; }

    /* 个股弹窗改为底部抽屉 */
    .sm-overlay { padding: 0; align-items: flex-end; }
    .sm-modal { max-height: 92vh; border-radius: 14px 14px 0 0; }
    .sm-chart { height: 300px; }
    .sm-list { padding: 8px 10px 12px; }

    .dashboard-footer { padding: 0 8px; }
}

/* ========== 手机端抽屉菜单 ========== */
.nav-burger { display: none; }

.nav-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 250px;
    max-width: 80vw;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    z-index: 300;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    overflow-y: auto;
    padding-bottom: 20px;
    -webkit-overflow-scrolling: touch;
}

.nav-drawer.open { transform: translateX(0); }

.nav-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 290;
}

.nav-drawer-overlay[hidden] { display: none; }

.nav-head { font-size: 13px; font-weight: 700; color: var(--text-muted); padding: 16px 18px 8px; }

.nav-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 20px;
    font-size: 14px;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-family: var(--font-sans);
}

.nav-item:active { background: var(--hover-bg); color: var(--accent-blue); }

.nav-sep { height: 1px; background: var(--border-color); margin: 8px 14px; }

#index-cards, .panel, .darkpool-panel { scroll-margin-top: 60px; }

@media (max-width: 480px) {
    .nav-burger { display: inline-flex; }
    .topbar-left { min-width: 0; flex: 1; margin-right: 8px; }
    .topbar-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}