:root {
    --bg: #0e1116;
    --panel: #161b22;
    --panel2: #1c2230;
    --border: #2a313c;
    --text: #e6edf3;
    --muted: #8b949e;
    --up: #ff4d4f;      /* 变热/上涨 用红(A股习惯) */
    --down: #24c98a;    /* 变冷/下跌 用绿 */
    --accent: #3b82f6;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
    overflow: hidden;
}

#app { display: flex; height: 100vh; }

/* ---------- 左侧 ---------- */
#sidebar {
    width: 264px;
    min-width: 264px;
    background: linear-gradient(180deg, #171d27 0%, var(--panel) 120px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.side-head { padding: 14px 14px 10px; }
.side-head h1 {
    margin: 0; font-size: 17px; font-weight: 800; letter-spacing: .5px;
    display: flex; align-items: center; gap: 7px;
}
.side-head h1::before {
    content: ""; width: 4px; height: 17px; border-radius: 2px;
    background: linear-gradient(180deg, var(--up), var(--accent));
}
.status { color: var(--muted); font-size: 11px; margin-top: 6px; }

.source-switch {
    display: flex; gap: 6px; margin-top: 12px;
    background: rgba(0,0,0,.2); padding: 3px; border-radius: 9px;
}
#source-tabs button {
    flex: 1; padding: 6px 8px; border-radius: 7px;
    border: none; background: transparent;
    color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 600;
    transition: all .18s;
}
#source-tabs button:hover { color: var(--text); }
#source-tabs button.active {
    color: #fff; background: var(--accent);
    box-shadow: 0 2px 8px rgba(59,130,246,.35);
}

#add-form { display: flex; gap: 6px; padding: 8px 14px 6px; }
#add-input {
    flex: 1; padding: 8px 10px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--panel2);
    color: var(--text); outline: none; font-size: 12px; transition: border-color .15s;
}
#add-input:focus { border-color: var(--accent); }
#add-btn, #collect-btn {
    padding: 8px 12px; border: none; border-radius: 8px;
    background: var(--accent); color: #fff; cursor: pointer; font-size: 12px; font-weight: 600;
    transition: filter .15s;
}
#add-btn:hover, #collect-btn:hover { filter: brightness(1.12); }

.side-tools {
    display: flex; align-items: center; justify-content: space-between;
    padding: 4px 14px 12px; border-bottom: 1px solid var(--border);
}
#collect-btn { background: var(--panel2); border: 1px solid var(--border); color: var(--text); }
.sound-toggle {
    color: var(--muted); font-size: 12px; cursor: pointer; user-select: none;
    display: inline-flex; align-items: center; gap: 4px;
}

#stock-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
#stock-list::-webkit-scrollbar { width: 7px; }
#stock-list::-webkit-scrollbar-thumb { background: #2a313c; border-radius: 4px; }
#stock-list::-webkit-scrollbar-thumb:hover { background: #3a4450; }

.stock-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 10px; cursor: pointer;
    border: 1px solid transparent; margin-bottom: 6px;
    background: var(--panel2);
    transition: transform .12s, border-color .15s, background .15s;
}
.stock-item:hover { border-color: #3a4450; transform: translateX(2px); }
.stock-item.active {
    border-color: var(--accent);
    background: linear-gradient(90deg, rgba(59,130,246,.14), var(--panel2) 60%);
    box-shadow: 0 2px 10px rgba(0,0,0,.25);
}

/* 名次徽章：圆角方块，前3名红、前10橙、其余中性；无数据/榜外弱化 */
.si-rank {
    flex-shrink: 0; width: 38px; height: 38px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-size: 17px; font-weight: 800; color: var(--text);
    background: #232b38; border: 1px solid var(--border);
}
.si-rank.hot { color: #fff; background: linear-gradient(135deg, #ff4d4f, #ff7a45); border-color: transparent; }
.si-rank.warm { color: #fff; background: linear-gradient(135deg, #f5a623, #f7c948); border-color: transparent; }
.si-rank.na { background: transparent; border-style: dashed; }
.si-rank .off { font-size: 11px; color: var(--muted); font-weight: 500; }

.si-main { flex: 1; min-width: 0; }
.si-name {
    font-weight: 700; font-size: 14px; line-height: 1.3;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.si-meta { display: flex; align-items: center; gap: 7px; margin-top: 2px; }
.si-code { color: var(--muted); font-size: 11px; letter-spacing: .3px; }
.si-delta {
    font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px;
}
.si-delta.up { color: var(--up); background: rgba(255,77,79,.14); }
.si-delta.down { color: var(--down); background: rgba(36,201,138,.14); }
.si-delta.flat { color: var(--muted); background: rgba(139,148,158,.12); }

.si-right {
    display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
    flex-shrink: 0; min-width: 56px;
}
.si-price { font-size: 15px; font-weight: 800; color: var(--text); line-height: 1.1; }
.si-chg { font-size: 12px; font-weight: 700; }
.si-chg.up { color: var(--up); }
.si-chg.down { color: var(--down); }
.si-chg.flat { color: var(--muted); }

.si-del {
    border: none; background: transparent; color: #4a5464;
    cursor: pointer; font-size: 14px; padding: 2px 3px; line-height: 1;
    flex-shrink: 0; opacity: 0; transition: opacity .15s, color .15s;
}
.stock-item:hover .si-del { opacity: 1; }
.si-del:hover { color: var(--up); }

.side-foot { padding: 8px 14px; color: var(--muted); font-size: 11px; border-top: 1px solid var(--border); }

/* ---------- 右侧 ---------- */
#detail { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#detail-head {
    display: flex; align-items: center; gap: 20px;
    padding: 18px 24px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.dh-left { flex-shrink: 0; }
.dh-left h2 { margin: 0; font-size: 22px; }
.dh-left #d-code { color: var(--muted); font-size: 13px; }

/* 中间顶部一组：现价+涨跌幅(大显示) 靠在当日分时线左侧，整组居中撑开 */
.dh-center {
    flex: 1; min-width: 220px;
    display: flex; align-items: center; justify-content: center; gap: 18px;
}
.dh-quote { text-align: right; flex-shrink: 0; }
.d-price { font-size: 32px; font-weight: 800; line-height: 1.05; }
.d-chg { font-size: 16px; font-weight: 700; }
.d-chg.up { color: var(--up); }
.d-chg.down { color: var(--down); }
.d-chg.flat { color: var(--muted); }
/* 当日分时线：撑满中间一组的剩余宽度 */
.spark { flex: 1; min-width: 140px; max-width: 520px; height: 60px; }

.dh-rank { text-align: right; flex-shrink: 0; }
.d-rank { font-size: 30px; font-weight: 800; }
.d-sub { font-size: 13px; color: var(--muted); }
.range-tabs { margin-left: auto; display: flex; gap: 4px; }
.range-tabs button {
    background: var(--panel2); border: 1px solid var(--border); color: var(--muted);
    padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.range-tabs button.active { color: #fff; border-color: var(--accent); background: var(--accent); }

/* 主图区 = 左侧图表 + 右侧常驻榜 */
#detail-body { flex: 1; min-height: 0; display: flex; }
#chart-wrap { flex: 1; min-width: 0; position: relative; display: flex; align-items: center; }
#chart { width: 100%; height: 90%; min-width: 0; }
.empty-hint {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    color: var(--muted); pointer-events: none;
}

/* 右侧常驻变化榜 */
#board-side {
    width: 220px; min-width: 220px; border-left: 1px solid var(--border);
    display: flex; flex-direction: column; overflow: hidden; background: var(--panel);
}
.board-box { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.board-box + .board-box { border-top: 1px solid var(--border); }
.board-title {
    padding: 8px 12px; font-size: 13px; font-weight: 700; flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}
.board-title.up { color: var(--up); }
.board-title.down { color: var(--down); }
.board-sub { color: var(--muted); font-size: 10px; font-weight: 400; }
.board-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; flex: 1; }
.board-list li {
    padding: 6px 8px; border-radius: 5px; cursor: pointer; margin-bottom: 3px;
}
.board-list li:hover { background: var(--panel2); }
.board-list .bl-top { display: flex; justify-content: space-between; align-items: baseline; }
.board-list .bl-name { font-weight: 600; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-list .bl-pct { font-size: 12px; font-weight: 700; flex-shrink: 0; margin-left: 6px; }
.board-list .bl-pct.up { color: var(--up); }
.board-list .bl-pct.down { color: var(--down); }
.board-list .bl-meta { font-size: 10px; color: var(--muted); margin-top: 1px; }
.board-empty { color: var(--muted); font-size: 11px; padding: 10px 8px; text-align: center; }

/* ---------- 报警浮层 ---------- */
#toast-wrap {
    position: fixed; top: 16px; right: 16px; z-index: 999;
    display: flex; flex-direction: column; gap: 10px; max-width: 360px;
}
.toast {
    background: var(--panel2); border: 1px solid var(--border);
    border-left-width: 4px; border-radius: 8px; padding: 12px 14px;
    box-shadow: 0 6px 24px rgba(0,0,0,.4); animation: slidein .25s ease;
}
.toast.up { border-left-color: var(--up); }
.toast.down { border-left-color: var(--down); }
.toast .t-title { font-weight: 700; margin-bottom: 2px; }
.toast .t-title.up { color: var(--up); }
.toast .t-title.down { color: var(--down); }
.toast .t-body { font-size: 13px; color: var(--text); }
.toast .t-time { font-size: 11px; color: var(--muted); margin-top: 4px; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 760px) {
    #app { flex-direction: column; }
    #sidebar { width: 100%; min-width: 0; height: 40vh; }
    #detail { height: 60vh; }
    /* 窄屏把榜单移到图表下方，横向两栏 */
    #detail-body { flex-direction: column; }
    #board-side {
        width: 100%; min-width: 0; height: 150px; flex-direction: row;
        border-left: none; border-top: 1px solid var(--border);
    }
    .board-box + .board-box { border-top: none; border-left: 1px solid var(--border); }
}
