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

/* 全域滾動條 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a3d4a; }

:root {
    --bg: #0f1419;
    --surface: #1a1f2a;
    --border: #2a323e;
    --text: #d4d7dd;
    --text-dim: #6b7280;
    --accent: #5b8c93;
    --accent-blue: #7a93b8;
    --green: #6a9970;
    --red: #b56a72;
    --yellow: #b59a5e;
    --purple: #8c7fa8;
    --cyan: #5b8c93;
    --glow: rgba(91,140,147,0.08);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════════════════════
   版面骨架：左 sidebar + 上 topbar + 主內容
   ═══════════════════════════════════════════════════════════════ */
:root {
    --sidebar-w: 220px;
    --topbar-h: 56px;
}

/* 頂部資訊條 */
header.topbar {
    position: fixed;
    top: 0; left: var(--sidebar-w); right: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    z-index: 50;
}
header.topbar::after {
    content: '';
    position: absolute; bottom: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--cyan), transparent);
    opacity: 0.3;
}

.sidebar-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    width: 36px; height: 36px;
    cursor: pointer;
    font-size: 1.15rem;
}

.topbar-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.info-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.42rem 0.75rem;
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.82rem;
    line-height: 1.1;
    white-space: nowrap;
    transition: border-color 0.2s;
}
.info-chip .chip-icon { font-size: 0.95rem; }
.info-chip .chip-main { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.info-chip .chip-sub  { color: var(--text-dim); font-size: 0.74rem; }

/* 圓點燈號 */
.dot {
    width: 10px; height: 10px; border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 6px currentColor;
}
.dot-gray        { background: #6b7280; color: #6b7280; box-shadow: none; }
.dot-green       { background: var(--green);  color: var(--green);  }
.dot-red         { background: var(--red);    color: var(--red);    }
.dot-yellow      { background: var(--yellow); color: var(--yellow); }
.dot-yellow-red  { background: #b88a64; color: #b88a64; }   /* 黃紅燈 */
.dot-yellow-blue { background: #7a93b8; color: #7a93b8; }   /* 黃藍燈 */
.dot-blue        { background: #7a93b8; color: #7a93b8; }
.dot.pulse { animation: dotPulse 1.6s ease-in-out infinite; }
@keyframes dotPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.55; transform: scale(0.85); }
}

/* 加權指數漲跌色 */
.info-taiex.up   .chip-main,
.info-taiex.up   .chip-sub  { color: var(--red);   }   /* 台股慣例：紅漲綠跌 */
.info-taiex.down .chip-main,
.info-taiex.down .chip-sub  { color: var(--green); }
.info-taiex.flat .chip-sub  { color: var(--text-dim); }

/* 新聞跑馬燈 */
.news-ticker {
    flex: 1;
    min-width: 0;
    height: 38px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 0.85rem;
    background: rgba(91,140,147,0.04);
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    color: var(--text);
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.2s, background 0.2s;
}
.news-ticker:hover { border-color: rgba(91,140,147,0.45); background: rgba(91,140,147,0.07); }
.ticker-icon { font-size: 1rem; flex-shrink: 0; }
.ticker-window {
    flex: 1;
    height: 100%;
    overflow: hidden;
    position: relative;
}
.ticker-track {
    position: absolute; left: 0; right: 0;
    height: 100%;
    display: flex;
    align-items: center;
    transition: transform 0.5s cubic-bezier(.5,0,.2,1), opacity 0.4s;
    will-change: transform, opacity;
}
.ticker-track.swap-out { transform: translateY(-100%); opacity: 0; }
.ticker-track.swap-in-init { transform: translateY(100%); opacity: 0; transition: none; }
.ticker-item {
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}
.ticker-item .src {
    color: var(--text-dim);
    font-size: 0.76rem;
    margin-left: 0.6rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.btn-restart {
    flex-shrink: 0;
    width: 36px; height: 36px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
}
.btn-restart:hover    { border-color: var(--yellow); color: var(--yellow); }
.btn-restart:disabled { opacity: 0.5; cursor: not-allowed; }

.user-menu {
    display: none;
    align-items: center;
    gap: 10px;
}
.user-name {
    color: var(--text-dim);
    font-size: 0.82rem;
}
.btn-logout {
    padding: 0.35rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.78rem;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-logout:hover { border-color: #b56a72; color: #b56a72; }

/* 左側 Sidebar */
aside.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #131820 0%, #0f1419 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 60;
    overflow: hidden;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 1.1rem 1.2rem 1rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand .brand-mark {
    color: var(--cyan);
    font-size: 1.4rem;
    text-shadow: 0 0 12px var(--cyan);
}
.sidebar-brand h1 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--cyan);
    letter-spacing: 1.5px;
    line-height: 1.15;
}
.sidebar-brand .brand-sub {
    color: var(--text-dim);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 2px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0.6rem 0.5rem;
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
}

/* Sidebar 底部：使用者區（重啟、姓名、登出） */
.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding: 0.6rem 0.7rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: rgba(0,0,0,0.18);
}
.sidebar-footer .btn-restart {
    width: 100%;
    height: 34px;
    padding: 0 0.6rem;
    font-size: 0.82rem;
    color: var(--text-dim);
    letter-spacing: 0.4px;
}
.sidebar-footer .btn-restart:hover { color: var(--yellow); border-color: var(--yellow); }
.sidebar-footer .user-menu {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-footer .user-name {
    flex: 1;
    min-width: 0;
    color: var(--text);
    font-size: 0.82rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-footer .btn-logout {
    flex-shrink: 0;
    padding: 0.32rem 0.7rem;
    font-size: 0.78rem;
}
.sidebar-nav .nav-btn {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid transparent;
    padding: 0.55rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.88rem;
    text-align: left;
    letter-spacing: 0.3px;
    position: relative;
}
.sidebar-nav .nav-btn .nav-ic {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-nav .nav-btn:hover {
    color: var(--text);
    background: rgba(91,140,147,0.05);
}
.sidebar-nav .nav-btn.active {
    background: rgba(91,140,147,0.12);
    color: var(--cyan);
    border-color: rgba(91,140,147,0.3);
}
/* 自創策略可折疊群組 */
.sidebar-nav .nav-group { display: flex; flex-direction: column; gap: 0; }
.sidebar-nav .nav-group-header {
    width: 100%; cursor: pointer;
    display: flex; align-items: center; gap: 0.5rem;
}
.sidebar-nav .nav-group-caret {
    margin-left: auto;
    font-size: 0.7rem; color: var(--text-dim);
    transition: transform 0.15s;
}
.sidebar-nav .nav-group.collapsed .nav-group-caret { transform: rotate(-90deg); }
.sidebar-nav .nav-group-children {
    display: flex; flex-direction: column; gap: 0.2rem;
    margin-left: 0.8rem; padding-left: 0.4rem;
    border-left: 1px solid var(--border);
    margin-top: 0.2rem;
}
.sidebar-nav .nav-group.collapsed .nav-group-children { display: none; }
.sidebar-nav .nav-btn.nav-child {
    font-size: 0.85rem;
    padding: 0.4rem 0.7rem;
}
.sidebar-nav .nav-btn.nav-child .nav-ic { font-size: 0.85rem; }

.sidebar-nav .nav-btn.active::before {
    content: '';
    position: absolute;
    left: -0.5rem;
    top: 25%; bottom: 25%;
    width: 3px;
    background: var(--cyan);
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 6px var(--cyan);
}

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 55;
}

/* 行動裝置：抽屜式 */
@media (max-width: 900px) {
    /* 手機 topbar：fixed + max-height 確保視覺高度恆定，避免 iOS Safari pinch-zoom 跑版。
       重啟與登出已搬到 sidebar-footer，topbar 僅剩 chips + ticker，2 行足夠。 */
    :root { --topbar-h: 100px; }
    header.topbar {
        left: 0; right: 0;
        padding: 0 0.6rem;
        gap: 0.5rem;
        height: auto;
        min-height: var(--topbar-h);
        max-height: var(--topbar-h);
        overflow: hidden;
    }
    .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
    aside.sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    aside.sidebar.open { transform: translateX(0); }
    .sidebar-backdrop.open { display: block; }
    .topbar-info { gap: 0.35rem; }
    .info-chip { padding: 0.32rem 0.55rem; font-size: 0.76rem; }
    .info-clock .chip-sub { display: none; }
    /* +1rem 緩衝避免搜尋區與跑馬燈視覺貼齊 */
    main { padding: 1rem; padding-top: calc(var(--topbar-h) + 1rem); }
    /* 防止意外的水平捲動 */
    html, body { overflow-x: hidden; max-width: 100%; }
}
@media (max-width: 600px) {
    .info-cycle .chip-sub { display: none; }
    .info-taiex .chip-sub { font-size: 0.7rem; }
}

main {
    padding: calc(var(--topbar-h) + 1.2rem) 1.5rem 2rem;
    margin-left: var(--sidebar-w);
    max-width: none;
}
@media (max-width: 900px) {
    main { margin-left: 0; }
}

/* 舊版相容：原本遺留的 nav / .header-top 樣式（避免其他頁面內出現的 nav-btn 影響） */
.nav-btn {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid transparent;
    padding: 0.4rem 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.82rem;
    letter-spacing: 0.3px;
}
.nav-btn:hover { color: var(--text); background: rgba(91,140,147,0.06); }
.nav-btn.active {
    background: rgba(91,140,147,0.12);
    color: var(--cyan);
    border-color: rgba(91,140,147,0.3);
}

.page { display: none; }
.page.active { display: block; }

.search-bar {
    display: flex; gap: 0.5rem; margin-bottom: 1.5rem;
}
.search-bar input {
    flex: 1; padding: 0.65rem 1rem;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: 0.9rem;
    outline: none; transition: border-color 0.2s;
}
.search-bar input:focus { border-color: var(--cyan); }
.search-bar button, .btn-primary {
    padding: 0.65rem 1.4rem;
    background: linear-gradient(135deg, var(--cyan) 0%, #5b8c93 100%);
    border: none; border-radius: 6px; color: #0f1419;
    cursor: pointer; font-size: 0.9rem; font-weight: 700;
    letter-spacing: 0.5px; transition: all 0.2s;
}
.btn-primary:hover { opacity: 0.85; transform: translateY(-1px); }

.stock-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem; margin-bottom: 2rem;
}

.stock-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 1rem; cursor: pointer;
    transition: all 0.2s; position: relative; overflow: hidden;
}
.stock-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, var(--cyan), transparent); opacity: 0;
    transition: opacity 0.2s;
}
.stock-card:hover { border-color: rgba(91,140,147,0.4); transform: translateY(-2px); }
.stock-card:hover::before { opacity: 0.6; }
.stock-card .symbol { font-size: 1.15rem; font-weight: 700; color: var(--cyan); font-family: 'Consolas', monospace; }
.stock-card .name { color: var(--text-dim); margin-top: 0.3rem; font-size: 0.85rem; }
.stock-card .industry { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.4rem; }

.chart-container {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 1.2rem; margin-bottom: 1rem;
}

.backtest-form {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 1.5rem; margin-bottom: 1.5rem;
    max-width: 500px;
}
.backtest-form h2 { margin-bottom: 1.2rem; font-size: 1rem; }
.form-row { margin-bottom: 0.8rem; }
.form-row label {
    display: block; margin-bottom: 0.3rem; color: var(--text-dim);
    font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px;
}
.form-row input, .form-row select {
    width: 100%; padding: 0.55rem 0.8rem;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: 0.9rem;
    outline: none; transition: border-color 0.2s;
}
.form-row input:focus, .form-row select:focus { border-color: var(--cyan); }

.result-cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.result-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 1rem; text-align: center;
    position: relative; overflow: hidden;
}
.result-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, var(--cyan), transparent); opacity: 0.4;
}
.result-card .label { font-size: 0.72rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.result-card .value { font-size: 1.4rem; font-weight: 700; margin-top: 0.3rem; font-family: 'Consolas', monospace; }
.result-card .value.positive { color: var(--red); }    /* 正報酬（台股慣例：紅） */
.result-card .value.negative { color: var(--green); }  /* 負報酬（台股慣例：綠） */

footer {
    text-align: center; padding: 1.5rem;
    color: var(--text-dim); font-size: 0.75rem;
    letter-spacing: 0.5px;
    border-top: 1px solid var(--border);
}
.changelog-btn {
    background: none; border: 1px solid var(--border);
    color: var(--text-dim); border-radius: 4px;
    padding: .2rem .6rem; font-size: .78rem;
    cursor: pointer; margin-left: .8rem;
    transition: all .2s;
}
.changelog-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── 版本更新 Modal ──────────────────────────────────────────── */
.changelog-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.6); z-index: 1000;
    align-items: center; justify-content: center;
}
.changelog-backdrop.open { display: flex; }
.changelog-modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; width: min(720px, 95vw);
    max-height: 85vh; display: flex; flex-direction: column;
    box-shadow: 0 16px 48px rgba(0,0,0,.5);
}
.changelog-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.2rem 1.6rem; border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.changelog-header h2 { font-size: 1.05rem; }
.changelog-close {
    background: none; border: none; color: var(--text-dim);
    font-size: 1.1rem; cursor: pointer; padding: .2rem .5rem;
    border-radius: 4px; transition: color .2s;
}
.changelog-close:hover { color: var(--text); }
.changelog-body {
    overflow-y: auto; padding: 1.4rem 1.6rem;
    display: flex; flex-direction: column; gap: 2rem;
}
.cl-version { display: flex; flex-direction: column; gap: .9rem; }
.cl-ver-tag {
    font-size: 1rem; font-weight: 700; color: var(--accent);
    padding-bottom: .6rem; border-bottom: 1px solid var(--border);
}
.cl-date { font-size: .82rem; color: var(--text-dim); font-weight: 400; margin-left: .6rem; }
.cl-section { padding: .6rem .9rem; border-radius: 8px; }
.cl-section.added   { background: rgba(106,153,112,.06);   border-left: 3px solid var(--green); }
.cl-section.modified{ background: rgba(91,140,147,.06); border-left: 3px solid var(--accent); }
.cl-section.removed { background: rgba(181,106,114,.06);  border-left: 3px solid var(--red); }
.cl-section-title { font-size: .85rem; font-weight: 600; margin-bottom: .5rem; }
.cl-section.added    .cl-section-title { color: var(--green); }
.cl-section.modified .cl-section-title { color: var(--accent); }
.cl-section.removed  .cl-section-title { color: var(--red); }
.cl-section ul { padding-left: 1.2rem; display: flex; flex-direction: column; gap: .3rem; }
.cl-section li { font-size: .85rem; color: var(--text); line-height: 1.5; }

.realtime-widget {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 1rem 1.5rem; margin-bottom: 1.5rem;
}
.rt-header {
    display: flex; align-items: center; gap: 0.8rem;
    font-size: 1rem; font-weight: 600; margin-bottom: 0.8rem; flex-wrap: wrap;
}
.rt-badge {
    padding: 0.2rem 0.6rem; border-radius: 20px; font-size: 0.78rem;
    font-weight: 600;
}
.rt-badge.open   { background: rgba(106,153,112,0.15); color: var(--green); }
.rt-badge.closed { background: rgba(139,143,163,0.15); color: var(--text-dim); }
.rt-countdown { font-size: 0.82rem; color: var(--text-dim); margin-left: auto; }
.rt-body { display: flex; align-items: center; gap: 2rem; flex-wrap: wrap; }
.rt-price-block { display: flex; align-items: baseline; gap: 0.8rem; }
.rt-price { font-size: 2rem; font-weight: 700; font-family: 'Consolas', monospace; }
.rt-change { font-size: 1rem; font-weight: 600; }
.rt-stats {
    display: flex; gap: 1.2rem; flex-wrap: wrap;
    font-size: 0.88rem; color: var(--text-dim);
}
.rt-stats strong { color: var(--text); }
.rt-time { font-size: 0.8rem; color: var(--text-dim); }

/* 短線交易設定區 */
.short-term-section {
    border: 1px solid var(--border); border-radius: 8px;
    padding: 1rem; margin-bottom: 1rem;
}
.short-term-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 0.8rem; font-size: 0.9rem; color: var(--text-dim);
}
.preset-btns { display: flex; gap: 0.4rem; }
.btn-preset {
    padding: 0.3rem 0.7rem; background: var(--bg);
    border: 1px solid var(--border); border-radius: 5px;
    color: var(--text-dim); cursor: pointer; font-size: 0.8rem;
}
.btn-preset:hover { border-color: var(--accent); color: var(--accent); }
.short-term-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.5rem;
}

/* 智慧選股 */
.screener-info {
    padding: 0.6rem 1rem; background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.9rem; color: var(--text-dim); margin-bottom: 1.5rem;
}
.screener-tabs {
    display: flex; gap: 0.5rem; margin-bottom: 1.5rem;
}
.screener-tab {
    padding: 0.4rem 1rem; background: transparent;
    border: 1px solid transparent; border-radius: 4px;
    color: var(--text-dim); cursor: pointer; font-size: 0.82rem;
    transition: all 0.15s;
}
.screener-tab:hover { background: rgba(91,140,147,0.06); color: var(--text); }
.screener-tab.active { background: rgba(91,140,147,0.12); color: var(--cyan); border-color: rgba(91,140,147,0.3); }
.filter-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.5rem;
}
.screener-table {
    width: 100%; border-collapse: collapse; font-size: 0.92rem; margin-top: 1rem;
}
.screener-table th {
    text-align: left; padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border); color: var(--text-dim); white-space: nowrap;
}
.screener-table td {
    padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border);
}
.screener-table tr:hover td { background: rgba(91,140,147,0.05); }
.screener-table tr:last-child td { border-bottom: none; }
.tag { display: inline-block; padding: 0.13rem 0.45rem; border-radius: 4px; font-size: 0.78rem; white-space: nowrap; }
.tag-buy  { background: rgba(181,106,114,0.15);    color: var(--red); }
.tag-conf { background: rgba(91,140,147,0.15);  color: var(--accent); }
/* 維度專屬標籤色彩系統（排序：趨勢→反轉→量價→籌碼→基本面）
   每個維度定義 --dim-color / --dim-bg，供 .tag-best-combo 繼承使用 */
.tag-radar         { --dim-color: #8c7fa8; --dim-bg: rgba(140,127,168,0.20); background: rgba(140,127,168,0.12); color: #8c7fa8; margin-bottom: 0.15rem; }
.tag-trend         { --dim-color: #b56a72; --dim-bg: rgba(181,106,114,0.20);  background: rgba(181,106,114,0.12);  color: #b56a72; margin-bottom: 0.15rem; }
.tag-reversion     { --dim-color: #7a93b8; --dim-bg: rgba(91,140,147,0.20); background: rgba(91,140,147,0.12); color: #7a93b8; margin-bottom: 0.15rem; }
.tag-volume        { --dim-color: #b59a5e; --dim-bg: rgba(181,140,94,0.20);  background: rgba(181,140,94,0.12);  color: #b59a5e; margin-bottom: 0.15rem; }
.tag-institutional { --dim-color: #8c7fa8; --dim-bg: rgba(140,127,168,0.20); background: rgba(140,127,168,0.12); color: #8c7fa8; margin-bottom: 0.15rem; }
.tag-fundamental   { --dim-color: #6a9970; --dim-bg: rgba(106,153,112,0.20);   background: rgba(106,153,112,0.12);   color: #6a9970; margin-bottom: 0.15rem; }
/* .tag-best-combo 疊加維度同色外框 + 稍深底色，繼承 --dim-color / --dim-bg */
.tag-best-combo {
    background:  var(--dim-bg, rgba(181,140,94,0.20)) !important;
    color:       var(--dim-color, #b59a5e) !important;
    font-weight: 700;
    outline:     1.5px solid var(--dim-color, #b59a5e);
}

/* 策略 Mega Preview — 固定中央彈窗 */
#strategy-tooltip {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%);
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transition: opacity .2s ease;
}
#strategy-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
}
/* 半透明遮罩 */
#strategy-tooltip-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 9998;
    cursor: pointer;
}
.strategy-tooltip-inner {
    width: 800px;
    background: rgba(13, 22, 35, 0.97);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(122,147,184, 0.4);
    border-radius: 14px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.75), 0 0 0 1px rgba(91,140,147,0.15);
    overflow: hidden;
}
.strategy-tooltip-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 1.2rem;
    font-weight: 700;
    color: #7a93b8;
    padding: .85rem 1.2rem .7rem;
    border-bottom: 1px solid rgba(45,63,85,0.9);
    letter-spacing: .04em;
}
.strategy-tooltip-title .tp-close {
    font-size: .9rem;
    color: var(--text-dim);
    cursor: pointer;
    padding: .1rem .4rem;
    border-radius: 4px;
    transition: background .15s;
    pointer-events: auto;
}
.strategy-tooltip-title .tp-close:hover { background: rgba(255,255,255,0.08); color: #fff; }
#strategy-tooltip-chart { width: 760px; height: 500px; margin: .5rem auto .4rem; display: block; }

/* 策略 tag 點擊效果 */
.strategy-preview-trigger {
    cursor: pointer;
    transition: opacity .15s, transform .1s;
}
.strategy-preview-trigger:hover  { opacity: .8; }
.strategy-preview-trigger:active { opacity: .6; transform: scale(.96); }

/* 個股 K 線載入指示器 */
#strategy-tooltip-loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    height: 500px;
    color: var(--text-dim);
    font-size: .95rem;
}
.tp-loading-spinner {
    display: inline-block;
    width: 22px; height: 22px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: tp-spin .7s linear infinite;
}
@keyframes tp-spin { to { transform: rotate(360deg); } }

/* 策略雷達說明卡 */
.radar-guide-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 1.2rem 1.4rem; }
.radar-guide-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.radar-guide-group { display: flex; flex-direction: column; gap: .4rem; }
.radar-guide-label { font-size: .75rem; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .2rem; border-bottom: 1px solid var(--border); padding-bottom: .25rem; }
.radar-guide-item { font-size: .82rem; color: var(--text-dim); line-height: 1.5; display: flex; gap: .4rem; align-items: flex-start; }
.radar-guide-item .tag { flex-shrink: 0; margin-top: .1rem; }
.no-data  { padding: 2rem; text-align: center; color: var(--text-dim); }
.pager { display:flex; align-items:center; gap:.8rem; margin-bottom:.6rem; font-size:.9rem; color:var(--text-dim); }
.pager .btn-sm { padding:.3rem .8rem; }
.screener-table th[onclick]:hover { color:var(--accent); }

/* 區段標題列 */
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.section-header h3 { font-size: 1rem; color: var(--text-dim); }
.btn-clear {
    background: transparent; border: 1px solid var(--border);
    color: var(--text-dim); padding: 0.3rem 0.8rem;
    border-radius: 6px; cursor: pointer; font-size: 0.82rem;
}
.btn-clear:hover { border-color: var(--red); color: var(--red); }

/* Toast 通知 */
#toast-container {
    position: fixed; top: 1.5rem; right: 1.5rem;
    z-index: 99999; display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
    padding: 0.7rem 1.2rem; border-radius: 6px;
    font-size: 0.85rem; max-width: 360px;
    animation: slideIn 0.3s ease, fadeOut 0.4s ease 3.6s forwards;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5);
    backdrop-filter: blur(8px);
}
.toast-error   { background: rgba(120,70,75,0.9); color: white; border: 1px solid rgba(181,106,114,0.4); }
.toast-success { background: rgba(70,110,80,0.9); color: white; border: 1px solid rgba(106,153,112,0.4); }
.toast-info    { background: rgba(17,24,39,0.95); color: var(--text); border: 1px solid var(--border); }

@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(120%); } }

/* 按鈕停用狀態 */
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* 策略比較表格 */
.table-container {
    overflow: auto;                       /* 雙向 scroll，配合 sticky thead */
    max-height: calc(100vh - 220px);      /* 限高以啟用 sticky；扣掉 topbar/邊距 */
    margin-top: 1.5rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 1.5rem;
}
.compare-table {
    width: 100%; border-collapse: collapse; font-size: 0.95rem;
}
.compare-table th {
    text-align: left; padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim); cursor: pointer; user-select: none;
    white-space: nowrap;
}
.compare-table th:hover { color: var(--accent); }
.compare-table td {
    padding: 0.7rem 1rem; border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.compare-table tr:last-child td { border-bottom: none; }
.compare-table tr:hover td { background: rgba(91,140,147,0.05); }
.compare-table .best { color: var(--red); font-weight: 700; }

.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex; justify-content: center; align-items: center;
    z-index: 9999;
    color: white;
    font-size: 1.5rem;
    flex-direction: column;
}

.loading-spinner {
    border: 3px solid var(--border);
    border-top: 3px solid var(--cyan);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 基本 768px — 由下方完整版處理 */

/* ══════════════════════════════════════════════════════════
   圖表標題列 + 工具列（原始佈局）
══════════════════════════════════════════════════════════ */

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.8rem;
}
.chart-header h3 { margin: 0; }

.chart-toolbar-inline {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

/* ── 搜尋列（儀表板頂部） */
.db-search-bar {
    display: flex; gap: 0.5rem; margin-bottom: 0.8rem;
}
.db-search-bar input {
    flex: 1; padding: 0.65rem 1rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); font-size: 0.95rem;
}
.db-search-bar button {
    padding: 0.65rem 1.4rem; background: var(--accent);
    border: none; border-radius: 8px; color: white;
    cursor: pointer; font-size: 0.95rem; font-weight: 600;
}

/* 主佈局：側邊欄 + 圖表區 */
.dashboard-layout {
    display: flex;
    gap: 0.8rem;
    min-height: 620px;
}

/* ── 自選股側邊欄 ── */
.watchlist-sidebar {
    width: 210px;
    min-width: 170px;
    flex-shrink: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
    font-weight: 600;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.sidebar-section-title {
    padding: 0.5rem 1rem 0.3rem;
    font-size: 0.72rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-top: 1px solid var(--border);
    margin-top: 0.3rem;
}

/* 自選股列表項目 */
.wl-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 0.8rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    border-left: 2px solid transparent;
}
.wl-item:hover  { background: rgba(91,140,147,0.05); }
.wl-item.active { background: rgba(91,140,147,0.08); border-left-color: var(--cyan); }
.wl-item:last-child { border-bottom: none; }

.wl-info { flex: 1; min-width: 0; }
.wl-sym  { font-weight: 700; color: var(--cyan); font-size: 0.85rem; display: block; font-family: 'Consolas', monospace; }
.wl-name { font-size: 0.74rem; color: var(--text-dim); white-space: nowrap;
           overflow: hidden; text-overflow: ellipsis; display: block; margin-top: 0.1rem; }

.wl-price {
    text-align: right;
    font-size: 0.78rem;
    line-height: 1.6;
    min-width: 52px;
}
.wl-price span { display: block; }

.wl-del {
    background: transparent; border: none;
    color: var(--text-dim); cursor: pointer;
    font-size: 1rem; padding: 0 0.2rem;
    border-radius: 3px; line-height: 1;
}
.wl-del:hover { color: var(--red); }

.wl-empty {
    padding: 1.8rem 1rem;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85rem;
    line-height: 1.6;
}

/* 自選股產業分組標題 */
.wl-group-header {
    padding: 0.5rem 0.8rem 0.3rem;
    font-size: 0.72rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.wl-group-header:first-child { border-top: none; }
.wl-group-count {
    font-size: 0.68rem;
    color: var(--text-dim);
    background: var(--bg);
    padding: 0.05rem 0.4rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* ── 圖表主區 ── */
.chart-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

/* 未選股佔位 */
.chart-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-dim);
    font-size: 1rem;
    min-height: 400px;
}

/* ── 工具列 ── */
.chart-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.toolbar-symbol {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--cyan);
    margin-right: 0.3rem;
    white-space: nowrap;
    font-family: 'Consolas', monospace;
}

.toolbar-group {
    display: flex;
    gap: 1px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px;
}

.tf-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 0.22rem 0.65rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s;
    white-space: nowrap;
}
.tf-btn:hover  { color: var(--text); background: rgba(255,255,255,0.06); }
.tf-btn.active { background: rgba(91,140,147,0.2); color: var(--cyan); }

.ind-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.22rem 0.65rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s;
}
.ind-btn:hover  { border-color: var(--cyan); color: var(--cyan); }
.ind-btn.active { background: rgba(91,140,147,0.12); color: var(--cyan); border-color: var(--cyan); }

/* ── 風險指標分頁卡片 ── */
.risk-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.8rem;
}
.risk-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-left: 4px solid var(--cyan);
    border-radius: 6px;
    padding: 0.7rem 0.9rem;
}
.risk-card .risk-label {
    color: var(--text-dim);
    font-size: 0.8rem;
    margin-bottom: 0.3rem;
}
.risk-card .risk-value {
    font-size: 1.4rem;
    font-weight: 600;
    line-height: 1.2;
}
.risk-card .risk-detail {
    color: var(--text-dim);
    font-size: 0.78rem;
    margin-top: 0.4rem;
    line-height: 1.4;
}
.risk-card.risk-mdd .risk-detail {
    color: var(--text);
}
.risk-period-btn.active {
    background: rgba(91,140,147,0.15);
    color: var(--cyan);
    border-color: var(--cyan);
}

/* ── 指標參數設定 modal 分頁 ── */
.ind-set-tab {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.3rem 0.85rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}
.ind-set-tab:hover  { border-color: var(--cyan); color: var(--cyan); }
.ind-set-tab.active { background: rgba(91,140,147,0.15); color: var(--cyan); border-color: var(--cyan); }

/* ── 即時報價 inline ── */
.rt-inline {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.4rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    flex-wrap: wrap;
}
.rt-inline .rt-price  { font-size: 1.5rem; font-weight: 700; font-family: 'Consolas', monospace; }
.rt-inline .rt-change { font-size: 0.9rem; font-weight: 600; font-family: 'Consolas', monospace; }

.rt-stats-inline {
    display: flex;
    gap: 0.7rem;
    font-size: 0.8rem;
    color: var(--text-dim);
    flex-wrap: wrap;
}
.rt-stats-inline strong { color: var(--text); }

/* ── LW 圖表窗格 ── */
.lw-pane {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.lw-main { height: 420px; }
.lw-vol  { height: 100px; }
.lw-sub  { height: 130px; }

/* ── Stock Combo Autocomplete ──────────────────────────────── */
.sc-wrap {
    position: relative;
    display: flex;
    flex: 1;
    min-width: 0;
}
.sc-wrap input {
    flex: 1;
    min-width: 0;
}
.sc-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    max-width: 380px;
    max-height: 260px;
    overflow-y: auto;
    background: #1e2130;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.5);
    z-index: 9999;
    padding: 4px 0;
    list-style: none;
    margin: 0;
}
.sc-item {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.5rem 0.9rem;
    cursor: pointer;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    transition: background 0.1s;
}
.sc-item:hover,
.sc-item.sc-active {
    background: rgba(91,140,147,0.15);
}
.sc-sym {
    font-weight: 700;
    color: var(--cyan);
    min-width: 3.5rem;
    flex-shrink: 0;
    font-family: 'Consolas', monospace;
}
.sc-name {
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
}
.sc-industry {
    font-size: 0.75rem;
    color: var(--text-dim);
    flex-shrink: 0;
}
.sc-item mark {
    background: rgba(181,154,94,.35);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}
.sc-dropdown::-webkit-scrollbar { width: 4px; }
.sc-dropdown::-webkit-scrollbar-track { background: transparent; }
.sc-dropdown::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* 顏色輔助（台股慣例：漲＝紅、跌＝綠） */
.positive { color: var(--red); }    /* 漲、獲利 */
.negative { color: var(--green); }  /* 跌、虧損 */
.up       { color: var(--red); }    /* 同 positive（用於自選股卡片） */
.down     { color: var(--green); }  /* 同 negative */

/* 900px — 由下方完整版處理 */

/* ══════════════════════════════════════════════════════════
   股票詳細資料面板（三大法人 / 基本面 / 財務報表）
══════════════════════════════════════════════════════════ */

.detail-tabs {
    display: flex;
    gap: 0.4rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
    margin-bottom: 0;
}

.detail-tab {
    background: transparent;
    border: 1px solid var(--border);
    border-bottom: none;
    color: var(--text-dim);
    padding: 0.4rem 1rem;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
    position: relative;
    top: 1px;
}
.detail-tab:hover  { color: var(--text); }
.detail-tab.active {
    background: var(--surface);
    color: var(--cyan);
    border-color: var(--border);
    border-bottom-color: var(--surface);
}

.detail-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0 8px 8px 8px;
    padding: 1.2rem 1.5rem;
}

/* ── 三大法人 ── */
.inst-summary {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.inst-card {
    flex: 1;
    min-width: 130px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    text-align: center;
}
.inst-card .ic-label { font-size: 0.72rem; color: var(--text-dim); margin-bottom: 0.3rem; text-transform: uppercase; letter-spacing: 0.5px; }
.inst-card .ic-value { font-size: 1.2rem; font-weight: 700; font-family: 'Consolas', monospace; }
.inst-card .ic-sub   { font-size: 0.7rem; color: var(--text-dim); margin-top: 0.2rem; }

.inst-table-el { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 0.5rem; }
.inst-table-el th {
    text-align: left; padding: 0.5rem 0.7rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim); white-space: nowrap;
}
.inst-table-el td {
    padding: 0.45rem 0.7rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.inst-table-el tr:last-child td { border-bottom: none; }
.inst-table-el tr:hover td { background: rgba(91,140,147,0.04); }

/* ── 基本面 ── */
.fund-cards {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.fund-card {
    flex: 1;
    min-width: 150px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.2rem;
    text-align: center;
}
.fund-card .fc-label { font-size: 0.72rem; color: var(--text-dim); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.5px; }
.fund-card .fc-value { font-size: 1.8rem; font-weight: 700; font-family: 'Consolas', monospace; }
.fund-card .fc-hint  { font-size: 0.7rem; color: var(--text-dim); margin-top: 0.3rem; }

/* ── 財務報表 ── */
.fin-table-el { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.fin-table-el th {
    text-align: right; padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim); white-space: nowrap;
}
.fin-table-el th:first-child { text-align: left; }
.fin-table-el td {
    padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--border);
    text-align: right; white-space: nowrap;
}
.fin-table-el td:first-child { text-align: left; font-weight: 600; }
.fin-table-el tr:last-child td { border-bottom: none; }
.fin-table-el tr:hover td { background: rgba(91,140,147,0.04); }
.fin-table-el .margin-col { color: var(--text-dim); font-size: 0.82rem; }

/* ── 財務指標列 ── */
.fin-metrics-bar {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 0.9rem 1.4rem; margin-bottom: 1.2rem;
    display: flex; flex-direction: column; gap: 0.65rem;
}
.fin-row {
    display: flex; gap: 1.6rem; flex-wrap: wrap; align-items: center;
    font-size: 0.88rem; color: var(--text-dim);
    border-bottom: 1px solid var(--border); padding-bottom: 0.55rem;
}
.fin-row:last-child { border-bottom: none; padding-bottom: 0; }
.fin-item {
    position: relative; cursor: default; white-space: nowrap;
}
.fin-item strong {
    color: var(--text); font-weight: 600; margin-left: 0.3rem;
}
.fin-item.positive strong { color: var(--red); }
.fin-item.negative strong { color: var(--green); }
.fin-period {
    margin-left: auto; font-size: 0.78rem; color: var(--text-dim); font-style: italic;
}

/* ══════════════════════════════════════════════════════════
   通知設定頁面
══════════════════════════════════════════════════════════ */

/* 通用卡片容器 */
.section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
    position: relative;
}

/* Tab 列 */
.tab-bar {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.75rem;
}
.tab-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-dim);
    padding: 0.4rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: all 0.15s;
    letter-spacing: 0.3px;
}
.tab-btn:hover  { color: var(--text); background: rgba(91,140,147,0.06); }
.tab-btn.active { background: rgba(91,140,147,0.12); color: var(--cyan); border-color: rgba(91,140,147,0.3); }

/* 渠道卡片 */
.noti-channel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1.2rem;
    margin-bottom: 1rem;
}
.noti-channel-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
}
.noti-channel-card h3 {
    margin-bottom: 0.3rem;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.noti-hint {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 1rem;
    line-height: 1.5;
}

/* 通知頁面 form-row（覆寫 backtest 版以適應通知佈局） */
#page-notifications .form-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}
#page-notifications .form-row label {
    min-width: 110px;
    flex-shrink: 0;
    color: var(--text-dim);
    font-size: 0.88rem;
    margin-bottom: 0;
}
#page-notifications .form-row input[type="text"],
#page-notifications .form-row input[type="password"],
#page-notifications .form-row input[type="number"],
#page-notifications .form-row select {
    flex: 1;
    padding: 0.55rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    min-width: 0;
}
#page-notifications .form-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}
#page-notifications .form-row input:focus,
#page-notifications .form-row select:focus {
    outline: none;
    border-color: var(--accent);
}

/* 按鈕列 */
.btn-row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-top: 1.1rem;
}

/* 次要按鈕 */
.btn-secondary {
    padding: 0.6rem 1.2rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

/* 小型按鈕（表格操作） */
.btn-sm {
    padding: 0.25rem 0.7rem;
    background: rgba(91,140,147,0.06);
    border: 1px solid rgba(91,140,147,0.2);
    border-radius: 4px;
    color: var(--cyan);
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.12s;
    letter-spacing: 0.3px;
}
.btn-sm:hover { background: rgba(91,140,147,0.15); border-color: var(--cyan); }

/* 通知頁面按鈕尺寸對齊 */
#page-notifications .btn-primary {
    padding: 0.6rem 1.4rem;
    font-size: 0.9rem;
}

/* 警報 / 記錄表格 */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    margin-top: 0.8rem;
}
.data-table th {
    text-align: left;
    padding: 0.5rem 0.7rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.data-table td {
    padding: 0.5rem 0.7rem;
    border-bottom: 1px solid rgba(30,42,58,0.6);
    vertical-align: middle;
    font-family: 'Consolas', monospace;
    font-size: 0.8rem;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(91,140,147,0.03); }

/* 警報新增表單子標題 */
.noti-channel-card h3 + .form-row { margin-top: 0.5rem; }

/* 700px — 由下方完整版處理 */

/* Tooltip — 通用 [data-tooltip] */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
    background: #20243a; border: 1px solid var(--border);
    color: var(--text); font-size: 0.78rem; line-height: 1.5;
    padding: 0.55rem 0.85rem; border-radius: 7px;
    width: 240px; white-space: pre-line; text-align: left;
    pointer-events: none; opacity: 0; transition: opacity 0.15s;
    z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
[data-tooltip]:hover::after { opacity: 1; }
/* ind-btn tooltip 靠右對齊，避免超出畫面 */
.ind-btn[data-tooltip]::after { left: auto; right: 0; transform: none; }

/* ── 自選股 / 持股管理 / 模擬交易 共用 ────────────────────── */
.page-header-row {
    display: flex; align-items: center; gap: 1rem;
    margin-bottom: 1.2rem; flex-wrap: wrap;
}
.page-header-row h2 { margin: 0; font-size: 1.15rem; }

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.85);
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center; z-index: 500;
}
.modal-box {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; padding: 1.5rem; width: min(420px, 92vw);
    display: flex; flex-direction: column; gap: .75rem;
}
.modal-box h3 { margin: 0 0 .25rem; font-size: 1rem; }

/* 模擬交易預覽列 */
.paper-preview {
    background: var(--bg-panel); border-radius: 6px;
    padding: .5rem .85rem; font-size: .85rem; color: var(--text-dim);
    min-height: 1.8rem;
}

/* ══════════════════════════════════════════════════════════
   即時策略監控 — 交易終端風格
══════════════════════════════════════════════════════════ */

/* KPI 儀表板 */
.live-kpi-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}
.live-kpi-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.live-kpi-item::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, #5b8c93, transparent);
    opacity: 0.6;
}
.live-kpi-label {
    font-size: 0.72rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}
.live-kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'Consolas', 'Monaco', monospace;
    line-height: 1.2;
}
.live-kpi-sub {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-top: 2px;
}

/* 主面板佈局 */
.live-terminal-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 16px;
    align-items: start;
}

/* 左側持倉面板 */
.live-main-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    min-height: 400px;
}
.live-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.live-panel-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
}
.live-panel-title::before {
    content: '';
    width: 3px; height: 16px;
    background: #5b8c93;
    border-radius: 2px;
}

/* 篩選按鈕群 */
.live-filter-group { display: flex; gap: 4px; }
.live-filter-btn {
    padding: 4px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.15s;
}
.live-filter-btn:hover { border-color: #5b8c93; color: #5b8c93; }
.live-filter-btn.active {
    background: rgba(91,140,147,0.1);
    border-color: #5b8c93;
    color: #5b8c93;
}

/* Session 卡片格線 */
.live-session-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 單一持倉卡片 */
.live-pos-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    transition: border-color 0.2s;
    position: relative;
}
.live-pos-card:hover { border-color: rgba(91,140,147,0.4); }
.live-pos-card.pos-long { border-left: 3px solid var(--red); }   /* 多單看漲：台股慣例紅 */
.live-pos-card.pos-none { border-left: 3px solid var(--border); }
.live-pos-card.pos-stopped { border-left: 3px solid var(--text-dim); opacity: 0.7; }

.live-pos-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.live-pos-symbol {
    font-size: 1.05rem;
    font-weight: 700;
    font-family: 'Consolas', monospace;
    color: var(--text);
}
.live-pos-name {
    font-size: 1.05rem;
    font-weight: 700;
    font-family: 'Consolas', monospace;
    color: var(--text);
    margin-left: 6px;
}
.live-pos-badge {
    padding: 2px 10px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.live-pos-badge.badge-running {
    background: rgba(106,153,112,0.15);
    color: #6a9970;
    border: 1px solid rgba(106,153,112,0.3);
}
.live-pos-badge.badge-stopped {
    background: rgba(139,143,163,0.15);
    color: #8b8fa3;
    border: 1px solid rgba(139,143,163,0.3);
}
.live-pos-badge.badge-long {
    background: rgba(106,153,112,0.15);
    color: #6a9970;
    border: 1px solid rgba(106,153,112,0.3);
}

.live-pos-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}
.live-pos-metric {
    text-align: center;
}
.live-pos-metric-label {
    font-size: 0.65rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.live-pos-metric-value {
    font-size: 0.9rem;
    font-weight: 600;
    font-family: 'Consolas', monospace;
}

.live-pos-strats {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}
.live-strat-tag {
    padding: 2px 8px;
    background: rgba(91,140,147,0.12);
    border: 1px solid rgba(91,140,147,0.25);
    border-radius: 3px;
    font-size: 0.68rem;
    color: #7a93b8;
}

.live-pos-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.72rem;
    color: var(--text-dim);
}
.live-pos-actions { display: flex; gap: 6px; }
.live-btn-stop {
    padding: 3px 12px;
    background: rgba(181,106,114,0.1);
    border: 1px solid rgba(181,106,114,0.35);
    border-radius: 4px;
    color: #b56a72;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 600;
    transition: all 0.15s;
}
.live-btn-stop:hover { background: rgba(181,106,114,0.25); }
.live-btn-trades {
    padding: 3px 12px;
    background: rgba(91,140,147,0.1);
    border: 1px solid rgba(91,140,147,0.3);
    border-radius: 4px;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.72rem;
    transition: all 0.15s;
}
.live-btn-trades:hover { background: rgba(91,140,147,0.2); }

/* 交易記錄展開區 */
.live-trades-expand {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.live-trades-expand .data-table { margin-top: 6px; font-size: 0.78rem; }
.live-trades-expand .data-table th { font-size: 0.7rem; }

/* 右側面板 */
.live-side-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.live-add-card, .live-strat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
}
.live-input-group {
    margin-bottom: 10px;
}
.live-input-group label {
    display: block;
    font-size: 0.72rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.live-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: 'Consolas', monospace;
    outline: none;
    transition: border-color 0.2s;
}
.live-input:focus { border-color: #5b8c93; }
.live-input::placeholder { color: var(--text-dim); opacity: 0.5; }

/* 啟動按鈕 */
.live-btn-start {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, #5b8c93 0%, #5b8c93 100%);
    border: none;
    border-radius: 6px;
    color: #0f1117;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 4px;
}
.live-btn-start:hover { opacity: 0.85; transform: translateY(-1px); }
.live-btn-start:active { transform: translateY(0); }

/* 策略格線 */
.live-strat-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 400px;
    overflow-y: auto;
}
.live-strat-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.78rem;
}
.live-strat-option:hover { border-color: rgba(91,140,147,0.5); }
.live-strat-option.checked {
    border-color: #5b8c93;
    background: rgba(91,140,147,0.06);
}
.live-strat-option input[type="checkbox"] { display: none; }
.live-strat-check {
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    font-size: 10px;
    color: transparent;
}
.live-strat-option.checked .live-strat-check {
    border-color: #5b8c93;
    background: #5b8c93;
    color: #0f1117;
}
.live-strat-option.analyzing {
    opacity: 0.5;
    animation: pulse-analyze 1s ease-in-out infinite;
    pointer-events: none;
}
@keyframes pulse-analyze {
    0%, 100% { opacity: 0.3; }
    50%      { opacity: 0.7; }
}

/* 空狀態 */
.live-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}
.live-empty-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.4;
}
.live-empty-text {
    font-size: 0.85rem;
}

/* 損益顏色 */
.pnl-up    { color: #6a9970 !important; }
.pnl-down  { color: #b56a72 !important; }
.pnl-zero  { color: var(--text-dim) !important; }

/* ══════════════════════════════════════════════════════════
   RWD — 平板 (≤ 900px) + 手機 (≤ 600px) + 小手機 (≤ 400px)
══════════════════════════════════════════════════════════ */

/* ── 平板橫式 / 小筆電 (≤ 900px) ─────────────────────────── */
@media (max-width: 900px) {

    /* 即時監控 RWD */
    .live-terminal-grid { grid-template-columns: 1fr; }
    .live-kpi-bar { grid-template-columns: repeat(3, 1fr); }
    .live-pos-metrics { grid-template-columns: repeat(2, 1fr); }

    /* Topbar 換行：資訊列在前，跑馬燈獨佔第二行（topbar 為 fixed + max-height，主規則在前面 @900px 區塊） */
    header.topbar {
        flex-wrap: wrap;
        align-content: center;
        row-gap: 6px;
    }
    .topbar-info { flex-wrap: wrap; row-gap: 4px; }
    .news-ticker { flex-basis: 100%; order: 99; height: 36px; }

    /* 圖表 */
    .dashboard-layout { flex-direction: column; }
    .watchlist-sidebar { width: 100%; max-height: 200px; }
    .lw-main { height: 300px; }
    .lw-vol  { height: 80px; }
    .lw-sub  { height: 110px; }
    .chart-toolbar { gap: 0.3rem; flex-wrap: wrap; }
    .toolbar-symbol { display: none; }
    .chart-toolbar-inline { gap: 0.3rem; flex-wrap: wrap; }

    /* 表格 — 加橫向捲動 */
    .screener-table, .inst-table-el, .fin-table-el, .data-table, .compare-table {
        font-size: 0.82rem;
    }
    .table-container { padding: 0.75rem; }

    /* 回測表單 */
    .backtest-form { max-width: 100%; }

    /* 財務指標列 */
    .fin-metrics-bar { padding: 0.7rem 1rem; gap: 0.5rem; }
    .fin-row { gap: 1rem; font-size: 0.84rem; }

    /* 即時報價 */
    .rt-price { font-size: 1.6rem !important; }
    .rt-stats { gap: 0.8rem; font-size: 0.82rem; }
}

/* ── 手機直式 (≤ 600px) ──────────────────────────────────── */
@media (max-width: 600px) {

    /* Topbar — 沿用 @900px 的 wrap 配置，這裡縮小 chip 與跑馬燈字體 */
    header.topbar { padding: 5px 0.5rem; gap: 0.4rem; }
    .topbar-info { gap: 0.3rem; }
    .info-chip { padding: 0.28rem 0.5rem; font-size: 0.74rem; }
    .info-chip .chip-icon { font-size: 0.85rem; }
    .info-chip .chip-sub { font-size: 0.66rem; }
    .news-ticker { height: 34px; padding: 0 0.7rem; gap: 0.45rem; }
    .ticker-item { font-size: 0.82rem; }
    .ticker-item .src { font-size: 0.7rem; margin-left: 0.4rem; }

    /* 主內容（+1rem 緩衝避免搜尋區與跑馬燈視覺貼齊） */
    main { padding: 0.75rem; padding-top: calc(var(--topbar-h) + 1rem); }

    /* 搜尋列 */
    .search-bar, .db-search-bar { flex-direction: column; }
    .search-bar input, .db-search-bar input { width: 100%; }
    .search-bar button, .db-search-bar button { width: 100%; }

    /* 股票卡片 */
    .stock-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.7rem; }

    /* 即時報價 widget */
    .realtime-widget { padding: 0.8rem 1rem; }
    .rt-header { font-size: 0.88rem; }
    .rt-body { flex-direction: column; gap: 0.7rem; }
    .rt-price { font-size: 2rem !important; }
    .rt-stats { gap: 0.6rem 1rem; font-size: 0.8rem; }

    /* 財務指標列 — 手機折行 */
    .fin-metrics-bar { padding: 0.65rem 0.85rem; }
    .fin-row {
        gap: 0.5rem 1.2rem;
        font-size: 0.8rem;
        padding-bottom: 0.5rem;
    }
    .fin-period { width: 100%; margin-left: 0; margin-top: 0.2rem; }
    /* tooltip 在手機停用（tap 觸發 hover 不直覺） */
    .fin-item::after { display: none; }

    /* 圖表工具列 */
    .chart-header { flex-direction: column; align-items: flex-start; }
    .chart-toolbar-inline { width: 100%; justify-content: flex-start; }
    .lw-main { height: 260px; }
    .lw-vol  { height: 70px; }
    .lw-sub  { height: 100px; }
    .tf-btn  { padding: 0.2rem 0.55rem; font-size: 0.78rem; }
    .ind-btn { padding: 0.2rem 0.55rem; font-size: 0.78rem; }

    /* 圖表容器 */
    .chart-container { padding: 0.85rem; }

    /* 詳細資料 tab */
    .detail-tabs { flex-wrap: wrap; gap: 0.3rem; }
    .detail-tab  { font-size: 0.82rem; padding: 0.35rem 0.85rem; }
    .detail-panel { padding: 0.85rem; }

    /* 三大法人 */
    .inst-summary { gap: 0.6rem; }
    .inst-card { min-width: 100px; padding: 0.6rem 0.75rem; }
    .inst-card .ic-value { font-size: 1.1rem; }
    .inst-table-el { font-size: 0.78rem; }

    /* 基本面 */
    .fund-cards { gap: 0.6rem; }
    .fund-card { min-width: 120px; padding: 0.75rem 0.9rem; }
    .fund-card .fc-value { font-size: 1.6rem; }

    /* 回測 / 策略比較表單 */
    .backtest-form { padding: 1.2rem; }
    .backtest-form h2 { font-size: 1.1rem; margin-bottom: 1rem; }
    .short-term-grid { grid-template-columns: 1fr; gap: 0; }
    .short-term-grid .form-row[style*="span 2"] { grid-column: span 1; }
    .preset-btns { flex-wrap: wrap; gap: 0.3rem; }
    .result-cards { grid-template-columns: repeat(2, 1fr); }

    /* 策略比較表格 — 可橫捲 */
    #page-compare .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .compare-table { min-width: 560px; }

    /* 智慧選股 */
    .screener-tabs { flex-wrap: wrap; }
    .filter-grid { grid-template-columns: 1fr; }
    .screener-table { font-size: 0.78rem; }
    .screener-table th, .screener-table td { padding: 0.45rem 0.5rem; }
    #page-screener .table-container,
    #scan-results, #filter-results { overflow-x: auto; }

    /* 通知設定 */
    .section-card { padding: 1rem; }
    .tab-bar { gap: 0.3rem; margin-bottom: 1rem; }
    .tab-btn { padding: 0.4rem 0.9rem; font-size: 0.82rem; }
    .noti-channel-grid { grid-template-columns: 1fr; }
    .noti-channel-card { padding: 1rem 1.1rem; }
    #page-notifications .form-row { flex-direction: column; align-items: flex-start; gap: 0.35rem; }
    #page-notifications .form-row label { min-width: unset; font-size: 0.82rem; }
    #page-notifications .form-row input,
    #page-notifications .form-row select { width: 100%; }
    .btn-row { margin-top: 0.85rem; }
    .btn-row .btn-primary,
    .btn-row .btn-secondary { flex: 1; text-align: center; }

    /* 警報 / 記錄表格 */
    #alerts-list, #alert-logs-list { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .data-table { min-width: 520px; font-size: 0.8rem; }
    .data-table th, .data-table td { padding: 0.45rem 0.6rem; }

    /* Toast */
    #toast-container { right: 0.75rem; left: 0.75rem; }
    .toast { max-width: 100%; }

    /* Footer */
    footer { padding: 1.2rem 1rem; font-size: 0.8rem; }
}

/* ── 新聞面板 ──────────────────────────────────────────────────────────────── */
#detail-news { padding: 0.5rem 0; }
#news-list { display: flex; flex-direction: column; gap: 0.75rem; }

.news-loading, .news-empty {
    color: var(--text-dim);
    padding: 1.5rem 0;
    text-align: center;
    font-size: 0.9rem;
}

.news-item {
    display: flex;
    gap: 0.85rem;
    padding: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, background 0.15s;
    align-items: flex-start;
}
.news-item:hover {
    border-color: var(--accent);
    background: var(--bg-panel);
}

.news-thumb {
    width: 90px;
    height: 60px;
    object-fit: cover;
    border-radius: 5px;
    flex-shrink: 0;
    background: var(--bg-panel);
}

.news-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.news-title {
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.78rem;
    color: var(--text-dim);
    flex-wrap: wrap;
}

.news-source { color: var(--accent); font-weight: 500; }

/* ── K 線型態 ──────────────────────────────────────────────────────────────── */
.patterns-list { display: flex; flex-wrap: wrap; gap: .65rem; padding: .5rem 0; }
.pattern-badge {
    display: flex; flex-direction: column; gap: .25rem;
    padding: .6rem .9rem; border-radius: 8px; min-width: 140px; max-width: 220px;
    border: 1px solid var(--border);
}
.pattern-badge.buy  { background: rgba(181,106,114,.12);   border-color: var(--red); }
.pattern-badge.sell { background: rgba(106,153,112,.12);   border-color: var(--green); }
.pattern-badge .pb-name {
    font-weight: 600; font-size: .9rem;
}
.pattern-badge.buy  .pb-name { color: var(--red);   }
.pattern-badge.sell .pb-name { color: var(--green); }
.pattern-badge .pb-desc { font-size: .78rem; color: var(--text-dim); line-height: 1.4; }
.patterns-empty { color: var(--text-dim); font-size: .88rem; padding: .75rem 0; }

/* ── 智能分析 ──────────────────────────────────────────────────────────────── */
.auto-screen-legend {
    display: flex; gap: 1.2rem; flex-wrap: wrap;
    font-size: .8rem; color: var(--text-dim); margin-bottom: .8rem;
}
.legend-item { display: flex; align-items: center; gap: .35rem; }
.score-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.s-strong  { background: #6a9970; }
.s-watch   { background: #7a93b8; }
.s-caution { background: #b59a5e; }
.s-skip    { background: #6b7280; }

.as-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 10px; padding: 1rem 1.2rem; margin-bottom: .75rem;
    border-left: 4px solid var(--border);
    transition: border-color .15s;
}
.as-card.rec-strong  { border-left-color: #6a9970; }
.as-card.rec-watch   { border-left-color: #7a93b8; }
.as-card.rec-caution { border-left-color: #b59a5e; }
.as-card.rec-skip    { border-left-color: #6b7280; opacity: .7; }

.as-header {
    display: flex; align-items: center; gap: .75rem;
    margin-bottom: .6rem; flex-wrap: wrap;
}
.as-sym   { font-size: 1.05rem; font-weight: 700; }
.as-name  { color: var(--text-dim); font-size: .88rem; }
.as-price { font-size: 1rem; font-weight: 600; margin-left: auto; }
.as-rec   {
    padding: .2rem .65rem; border-radius: 20px;
    font-size: .78rem; font-weight: 600;
}
.rec-strong  .as-rec { background: rgba(106,153,112,.2); color: #6a9970; }
.rec-watch   .as-rec { background: rgba(122,147,184,.2); color: #7a93b8; }
.rec-caution .as-rec { background: rgba(181,154,94,.2); color: #b59a5e; }
.rec-skip    .as-rec { background: rgba(107,114,128,.2); color: #9ca3af; }

.as-scores {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: .5rem; margin-bottom: .6rem;
}
.as-score-item {
    background: var(--bg-panel); border-radius: 6px;
    padding: .35rem .6rem; text-align: center;
}
.as-score-item .si-label { font-size: .72rem; color: var(--text-dim); }
.as-score-item .si-val   { font-size: 1rem; font-weight: 700; }

.as-details {
    font-size: .8rem; color: var(--text-dim); line-height: 1.8;
}
.as-patterns { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; }
.as-pattern-tag {
    font-size: .75rem; padding: .15rem .5rem; border-radius: 4px;
    background: rgba(106,153,112,.15); color: #6a9970;
}
.as-actions {
    display: flex; gap: .5rem; margin-top: .75rem; flex-wrap: wrap;
}
.as-total-score {
    font-size: 1.5rem; font-weight: 800;
    min-width: 48px; text-align: center;
}

/* ── 個股筆記 ──────────────────────────────────────────────────────────────── */
.note-area {
    width: 100%; min-height: 180px; resize: vertical;
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); font-size: .88rem;
    padding: .75rem; font-family: inherit; line-height: 1.6;
    box-sizing: border-box;
}
.note-area:focus { outline: none; border-color: var(--accent); }
.note-hint { font-size: .75rem; color: var(--text-dim); margin-top: .4rem; }

/* ── 小手機 (≤ 400px) ────────────────────────────────────── */
@media (max-width: 400px) {
    header h1 { font-size: 0.92rem; }
    main { padding: 0.6rem; }
    .lw-main { height: 220px; }
    .result-cards { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
    .result-card .value { font-size: 1.2rem; }
    .stock-grid { grid-template-columns: 1fr 1fr; }
    .fund-card { min-width: 100px; }
    .fund-card .fc-value { font-size: 1.3rem; }
    .inst-summary { flex-direction: column; }
    .inst-card { min-width: unset; }
}


/* ── 管理頁面 ─────────────────────────────────────────────────── */
.admin-tabs {
    display: flex; gap: .4rem; margin-bottom: 1.2rem;
}
.admin-tab {
    background: transparent; border: 1px solid var(--border);
    border-radius: 6px; padding: .4rem .9rem;
    color: var(--text-dim); cursor: pointer; font-size: .88rem;
    transition: all .15s;
}
.admin-tab:hover  { border-color: var(--accent); color: var(--accent); }
.admin-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.admin-panel { }
.pagination button {
    background: transparent; border: 1px solid var(--border);
    border-radius: 4px; padding: .3rem .7rem;
    color: var(--text-dim); cursor: pointer; font-size: .82rem;
}
.pagination button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination button:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

/* ── 個人設定頁 ──────────────────────────────────────────────── */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.2rem;
    align-items: start;
}

/* ── 資料稽核卡片 ─────────────────────────────────────── */
.audit-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .8rem;
    margin-bottom: .4rem;
}
.audit-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .9rem 1rem;
}
.audit-card-label {
    font-size: .75rem;
    color: var(--text-dim);
    margin-bottom: .3rem;
}
.audit-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-main);
}
.audit-card-sub {
    font-size: .72rem;
    color: var(--text-dim);
    margin-top: .25rem;
}

/* ── 資料日曆格子圖 ─────────────────────────────────────── */
.cal-section { margin-bottom: 1.2rem; }
.cal-header {
    display: flex; align-items: center; gap: .8rem;
    margin-bottom: .8rem; flex-wrap: wrap;
}
.cal-year-nav { display: flex; align-items: center; gap: .4rem; }
.cal-year-btn {
    background: transparent; border: 1px solid var(--border);
    border-radius: 4px; padding: .15rem .45rem;
    color: var(--text-dim); cursor: pointer; font-size: .82rem;
    transition: all .15s;
}
.cal-year-btn:hover { border-color: var(--accent); color: var(--accent); }
.cal-year-label {
    font-size: .95rem; font-weight: 700; color: var(--text-main);
    min-width: 48px; text-align: center;
}
.cal-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem 1.2rem;
}
@media (max-width: 800px) {
    .cal-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 560px) {
    .cal-grid { grid-template-columns: repeat(2, 1fr); }
}
.cal-month-title {
    font-size: .78rem; color: var(--text-dim);
    margin-bottom: .25rem; font-weight: 600;
}
.cal-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}
.cal-day-header {
    font-size: .58rem; color: var(--text-dim);
    text-align: center; padding: 1px 0;
    user-select: none;
}
.cal-cell {
    aspect-ratio: 1;
    border-radius: 3px;
    cursor: default;
    position: relative;
    transition: transform .1s, box-shadow .1s;
    min-width: 0;
}
.cal-cell.clickable { cursor: pointer; }
.cal-cell.clickable:hover {
    transform: scale(1.35);
    z-index: 2;
    box-shadow: 0 0 6px rgba(255,255,255,.2);
}
.cal-legend {
    display: flex; gap: .8rem; margin-top: .6rem;
    font-size: .72rem; color: var(--text-dim);
    flex-wrap: wrap;
}
.cal-legend-item { display: flex; align-items: center; gap: .25rem; }
.cal-legend-dot {
    width: 11px; height: 11px;
    border-radius: 2px; flex-shrink: 0;
}
.cal-loading {
    color: var(--text-dim); font-size: .85rem;
    padding: .5rem 0;
}

/* ── 智能多因子分析 ─────────────────────────────────────── */
.mf-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: .8rem;
    border-bottom: 1px solid rgba(45,63,85,.5);
    flex-wrap: wrap;
}
.mf-factors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: .8rem;
}
.mf-factor-card {
    background: #0f1117;
    border: 1px solid #2d3f55;
    border-radius: 8px;
    padding: .9rem 1rem;
}
.mf-factor-header {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: .4rem;
}
.mf-factor-name {
    font-weight: 600;
    font-size: .9rem;
    flex: 1;
}
.mf-factor-weight {
    font-size: .72rem;
    color: var(--text-dim);
    white-space: nowrap;
}

/* ── 自選股除權息標示 ───────────────────────────────────── */
.wl-div-badge {
    font-size: .72rem;
    border-radius: 4px;
    padding: .15rem .45rem;
    margin-top: .35rem;
    font-weight: 600;
    display: inline-block;
}
.wl-div-today    { background: rgba(181,154,94,.2);   color: #b59a5e; border: 1px solid rgba(181,154,94,.4); }
.wl-div-soon     { background: rgba(181,106,114,.15);  color: var(--red); border: 1px solid rgba(181,106,114,.3); }
.wl-div-upcoming { background: rgba(181,140,94,.12); color: #b59a5e; border: 1px solid rgba(181,140,94,.3); }

/* 產業徽章（自選股卡片右上角） */
.wl-industry-badge {
    position: absolute;
    top: .35rem;
    right: .4rem;
    font-size: .68rem;
    padding: .1rem .42rem;
    border-radius: 10px;
    background: rgba(122,147,184,.12);
    color: #7a93b8;
    border: 1px solid rgba(122,147,184,.3);
    font-weight: 500;
    max-width: 8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    z-index: 1;
    pointer-events: none;
}

/* 產業分組標題 */
.wl-industry-group       { width: 100%; }
.wl-industry-header {
    font-size: .95rem;
    font-weight: 700;
    color: var(--cyan);
    border-left: 3px solid var(--cyan);
    padding: .1rem .6rem;
    margin: .8rem 0 .5rem;
    background: rgba(91,140,147,.05);
    border-radius: 0 4px 4px 0;
}
.wl-industry-inner {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: .8rem;
}

/* 檢視切換按鈕 */
.wl-view-btn {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: .3rem .8rem;
    font-size: .8rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all .15s;
}
.wl-view-btn:hover  { color: var(--text); border-color: var(--cyan); }
.wl-view-btn.active { background: rgba(91,140,147,.12); color: var(--cyan); border-color: var(--cyan); }

/* 漲停 / 跌停 整卡變色（台股慣例：紅漲綠跌） */
.stock-card.limit-up {
    background: rgba(255,59,48,.16);
    border: 2px solid #ff3b30;
    box-shadow: 0 0 0 1px rgba(255,59,48,.45) inset, 0 0 14px rgba(255,59,48,.35);
}
.stock-card.limit-up:hover { border-color: #ff5b50; }
.stock-card.limit-down {
    background: rgba(106,153,112,.18);
    border-color: var(--green);
    box-shadow: 0 0 0 1px rgba(106,153,112,.35) inset;
}
.stock-card.limit-down:hover { border-color: var(--green); }
.wl-limit-tag {
    display: inline-block;
    margin-left: .4rem;
    padding: .05rem .42rem;
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .08em;
    border-radius: 3px;
    vertical-align: middle;
    animation: wl-limit-blink 1.4s ease-in-out infinite;
}
.wl-limit-up-tag   { background: #ff3b30;     color: #fff; }
.wl-limit-down-tag { background: var(--green); color: #fff; }
@keyframes wl-limit-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: .55; }
}

/* ── 個股三大法人 & 主力 Widget ── */
.si-widget {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .9rem 1.1rem;
    margin-bottom: 1rem;
}
.si-header {
    display: flex; align-items: center; gap: .5rem;
    margin-bottom: .7rem; flex-wrap: wrap;
}
.si-title      { font-weight: 700; font-size: .88rem; color: var(--text); flex: 1; min-width: 0; }
.si-badge      { font-size: .65rem; padding: .12rem .45rem; border-radius: 4px; font-weight: 600; white-space: nowrap; }
.si-date-label { font-size: .75rem; color: var(--text-dim); white-space: nowrap; }
.si-countdown  { font-size: .72rem; color: var(--text-dim); white-space: nowrap; }

/* 表格 */
.si-table-head, .si-table-row {
    display: grid;
    grid-template-columns: 5.5rem 5rem 5rem 6.5rem 1fr;
    align-items: center;
    gap: .2rem;
    padding: .28rem .1rem;
    font-size: .8rem;
}
.si-table-head {
    color: var(--text-dim);
    font-size: .72rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: .4rem;
    margin-bottom: .15rem;
}
.si-col-label { color: var(--text-dim); }
.si-col-num   { text-align: right; font-variant-numeric: tabular-nums; }
.si-col-bar   { padding-left: .4rem; }

.si-sep { border-top: 1px solid var(--border); margin: .3rem 0; }

.si-row-total { border-top: none; }
.si-row-total .si-col-label { color: var(--text); font-weight: 600; }

.si-row-major { background: rgba(91,140,147,.06); border-radius: 5px; margin: .15rem -.2rem; }
.si-row-major .si-col-label { color: var(--accent, #7a93b8); font-weight: 700; }
.si-row-major small { font-size: .65rem; color: var(--text-dim); }

/* 5日走勢 mini bar */
.si-bar-wrap {
    height: 8px;
    background: rgba(255,255,255,.06);
    border-radius: 4px;
    overflow: hidden;
}
.si-bar {
    height: 100%;
    border-radius: 4px;
    min-width: 2px;
}
.si-bar.positive { background: var(--red, #b56a72); }
.si-bar.negative { background: var(--green, #6a9970); }

@media (max-width: 600px) {
    .si-table-head, .si-table-row {
        grid-template-columns: 4.5rem 4rem 4rem 5.5rem 1fr;
        font-size: .73rem;
    }
}

/* ════════════════════════════════════════════════════════════════════════
   表格凍結表頭（全域）— 所有 <table><thead> 自動 sticky
   ─ 預設 top: var(--topbar-h)：應對「整頁滾動」情境（避免被頂部 topbar 蓋住）
   ─ scroll 容器內的 table（.table-container 等）：top: 0（在容器內凍結）
   ──────────────────────────────────────────────────────────────────────── */
table thead th {
    position: sticky;
    top: var(--topbar-h, 0px);
    z-index: 5;
    background: var(--surface, #1a1d24);
    /* sticky 時 border-collapse 會吃掉下邊框，用 inset shadow 模擬 */
    box-shadow: inset 0 -1px 0 var(--border, #2d3140);
}

/* scroll 容器內的 table：表頭直接貼容器頂（不需要 topbar 偏移）*/
.table-container table thead th,
.scroll-area      table thead th,
.modal-body       table thead th,
.table-scroll-wrap table thead th {
    top: 0;
}

/* 自動 wrap 容器（由 table-sticky.js 為每個 table 產生）─────────────
   給 table 一個有「縱向 scroll + 限高」的 scroll context，sticky thead 才能生效。
*/
.table-scroll-wrap {
    max-height: calc(100vh - 220px);
    overflow: auto;
    margin: 0.5rem 0;
    /* 讓 wrap 沿用父層底色，避免水平滾動時露出底色不一致 */
    background: inherit;
    border-radius: inherit;
}
.table-scroll-wrap > table {
    margin: 0;   /* 移除 table 自身上下 margin，避免 wrap 內留白 */
}

/* 雙層表頭（rowspan / 兩列 th）：第二列疊在第一列下方 */
table thead tr:nth-child(2) th {
    top: calc(var(--topbar-h, 0px) + 2.2rem);
}
.table-container table thead tr:nth-child(2) th,
.scroll-area      table thead tr:nth-child(2) th,
.modal-body       table thead tr:nth-child(2) th,
.table-scroll-wrap table thead tr:nth-child(2) th {
    top: 2.2rem;
}

/* opt-out：不需要凍結的表格加 class="no-sticky-head" */
table.no-sticky-head thead th {
    position: static;
    box-shadow: none;
}
