:root {
    /* Graphite dark is the default so the first frame remains polished before
       a saved theme preference is restored. */
    --bg-body: #0c1017;
    --bg-navbar: #111722;
    --bg-card: #171e29;
    --bg-input: #202938;
    --text-main: #f1f5f9;
    --text-muted: #9aa7b8;
    --text-subtle: #718096;
    --text-on-primary: #ffffff;
    --primary: #35b77e;
    --primary-hover: #47c88d;
    --primary-soft: rgba(53, 183, 126, .10);
    --primary-soft-strong: rgba(53, 183, 126, .14);
    --primary-border: rgba(53, 183, 126, .54);
    --focus-ring: rgba(53, 183, 126, .18);
    --primary-red: #e05d52;
    --danger-soft: rgba(224, 93, 82, .12);
    --bear-green: #48a97a;
    --border-color: #2b3748;
    --border-subtle: rgba(154, 167, 184, .24);
    --surface-hover: rgba(255, 255, 255, .045);
    --surface-raised: rgba(255, 255, 255, .025);
    --modal-backdrop: rgba(8, 12, 18, .84);
    --shadow-login: 0 25px 50px -12px rgba(0, 0, 0, .62);
    --shadow-popover: 0 16px 30px rgba(0, 0, 0, .32);
    --scrollbar-thumb: #425066;
    --scrollbar-thumb-hover: #58677d;
    --avatar-start: #48c68b;
    --avatar-end: #1e8a60;
    --native-color-scheme: dark;

    /* Chart colors are deliberately exposed to JavaScript through
       getComputedStyle(), keeping chart and interface themes in lockstep. */
    --chart-text: #9aa7b8;
    --chart-axis: #344155;
    --chart-split: rgba(52, 65, 85, .62);
    --chart-tooltip-bg: #111722;
    --chart-tooltip-border: #334155;
    --chart-tooltip-muted: #aebbd0;
    --chart-volume: rgba(135, 148, 168, .42);
    --chart-line-muted: #64748b;
    --chart-gold: #d9b55a;
    --chart-gold-line: rgba(217, 181, 90, .76);
    --chart-gold-bg: rgba(217, 181, 90, .12);
    --chart-point-border: #f5deb0;
    --chart-bull: #e05d52;
    --chart-bear: #48a97a;
    --chart-null: #637186;
    --chart-ma-1: #f7b84b;
    --chart-ma-2: #6fa8ff;
    --chart-ma-3: #d68af7;
    --chart-ma-4: #57c7b1;
    --chart-ma-5: #ff8a7a;
    --chart-ma-6: #d5df6a;
    --chart-regime-1: #38bdf8;
    --chart-regime-2: #fbbf24;
    --chart-regime-3: #a855f7;
    --chart-regime-4: #f43f5e;

    --nav-height: 58px;
    --layout-gap: 16px;
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --control-height: 38px;
    --control-height-sm: 32px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* Cloud-paper light mode shares the same cool, restrained palette rather
   than switching to harsh pure white and black. */
body.light-theme {
    --bg-body: #f5f7fa;
    --bg-navbar: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #eef2f6;
    --text-main: #17212e;
    --text-muted: #66758a;
    --text-subtle: #8794a7;
    --primary: #238a60;
    --primary-hover: #176f4c;
    --primary-soft: rgba(35, 138, 96, .10);
    --primary-soft-strong: rgba(35, 138, 96, .15);
    --primary-border: rgba(35, 138, 96, .48);
    --focus-ring: rgba(35, 138, 96, .16);
    --primary-red: #c9433d;
    --danger-soft: rgba(201, 67, 61, .11);
    --bear-green: #25845f;
    --border-color: #d8e0ea;
    --border-subtle: rgba(102, 117, 138, .24);
    --surface-hover: rgba(23, 33, 46, .045);
    --surface-raised: rgba(23, 33, 46, .025);
    --modal-backdrop: rgba(245, 247, 250, .78);
    --shadow-login: 0 25px 50px -12px rgba(23, 33, 46, .20);
    --shadow-popover: 0 16px 30px rgba(23, 33, 46, .14);
    --scrollbar-thumb: #bac5d2;
    --scrollbar-thumb-hover: #9daaba;
    --avatar-start: #46ad7d;
    --avatar-end: #238a60;
    --native-color-scheme: light;

    --chart-text: #66758a;
    --chart-axis: #cfd8e3;
    --chart-split: rgba(207, 216, 227, .78);
    --chart-tooltip-bg: #ffffff;
    --chart-tooltip-border: #d8e0ea;
    --chart-tooltip-muted: #66758a;
    --chart-volume: rgba(129, 143, 160, .42);
    --chart-line-muted: #8c9aad;
    --chart-gold: #b88318;
    --chart-gold-line: rgba(184, 131, 24, .76);
    --chart-gold-bg: rgba(184, 131, 24, .12);
    --chart-point-border: #f1d99f;
    --chart-bull: #c9433d;
    --chart-bear: #25845f;
    --chart-null: #8a97a8;
    --chart-ma-1: #9a6500;
    --chart-ma-2: #246bce;
    --chart-ma-3: #7940ab;
    --chart-ma-4: #187969;
    --chart-ma-5: #bd4538;
    --chart-ma-6: #607d10;
    --chart-regime-1: #1678ad;
    --chart-regime-2: #9a6500;
    --chart-regime-3: #7940ab;
    --chart-regime-4: #bd2948;
}

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

body.dark-theme,
body.light-theme {
    background-color: var(--bg-body);
    color: var(--text-main);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body.state-page {
    height: 100dvh;
    overflow: hidden;
}

/* ================= 全屏蒙板登录弹窗 (仅首页展示) ================= */
.login-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background: var(--modal-backdrop);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}

/* 隐藏时使用 !important 保证优先级 */
.login-modal-overlay.hidden {
    display: none !important;
}

.login-card {
    width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-login);
}

.login-header {
    text-align: center;
    margin-bottom: 20px;
}

.login-header .brand-logo {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 6px;
    color: var(--text-main);
}

.login-header .brand-logo span {
    color: var(--primary);
}

.login-header p {
    font-size: 13px;
    color: var(--text-muted);
}

.login-header h1 {
    margin: 14px 0 6px;
    font-size: 18px;
    color: var(--text-main);
}

/* 测试账号速查条 */
.test-accounts-tip {
    background: var(--bg-input);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 18px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}

.test-accounts-tip strong {
    color: var(--primary);
}

.login-form .input-field {
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-form label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.login-form input {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--text-main);
    outline: none;
    font-size: 14px;
}

.login-form input:focus {
    border-color: var(--primary);
}

.btn-login {
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-login:hover {
    background: var(--primary-hover);
}

.auth-feedback {
    min-height: 18px;
    margin-top: 12px;
    color: var(--primary-red);
    font-size: 12px;
    line-height: 1.5;
    text-align: center;
}

.auth-feedback.is-success { color: var(--primary); }
.auth-form[hidden] { display: none; }
.auth-switch { margin-top: 4px; color: var(--text-muted); font-size: 13px; text-align: center; }
.auth-switch button { padding: 0; border: 0; background: transparent; color: var(--primary); cursor: pointer; font: inherit; }
.auth-switch button:hover { color: var(--primary-hover); text-decoration: underline; }

/* ================= 雅虎风格顶部导航栏 ================= */
.navbar {
    height: 64px;
    background-color: var(--bg-navbar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 20px;
    font-weight: 800;
    color: #ffffff;
    text-decoration: none;
}

.nav-brand span {
    color: var(--primary);
}

.nav-center {
    flex: 0 1 520px;
}

.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 28px;
    height: 40px;
    padding: 2px 4px 2px 14px;
    transition: all 0.2s ease;
}

.search-bar:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 176, 116, 0.2);
}

.source-picker {
    position: relative;
    display: flex;
    flex: 0 0 84px;
    align-items: center;
    height: 100%;
}

.source-picker-trigger {
    display: inline-flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 4px 0 0;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.source-picker-trigger:hover,
.source-picker.is-open .source-picker-trigger {
    color: var(--text-main);
}

.source-picker-trigger svg {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
}

.source-picker.is-open .source-picker-trigger svg {
    transform: rotate(180deg);
}

.source-picker-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: -8px;
    z-index: 200;
    display: none;
    min-width: 132px;
    padding: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
}

.source-picker.is-open .source-picker-menu {
    display: grid;
    gap: 3px;
}

.source-picker-option {
    width: 100%;
    padding: 9px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.source-picker-option:hover,
.source-picker-option.is-selected {
    background: rgba(0, 176, 116, 0.14);
    color: var(--text-main);
}

.source-picker-option.is-selected::after {
    content: "✓";
    float: right;
    color: var(--primary);
}

.search-divider {
    width: 1px;
    height: 18px;
    background-color: var(--border-color);
    margin: 0 10px;
}

.search-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    font-size: 13px;
}

.search-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: var(--primary);
    border: none;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-btn svg {
    width: 16px;
    height: 16px;
}

.search-btn:hover {
    background-color: var(--primary-hover);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 18px;
}

.nav-pages {
    display: flex;
    align-items: center;
    gap: 16px;
}

.page-link {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}

.page-link:hover {
    color: var(--text-main);
}

.page-link.active {
    color: var(--primary);
    font-weight: 700;
    background-color: rgba(0, 176, 116, 0.1);
}

.nav-divider {
    width: 1px;
    height: 20px;
    background-color: var(--border-color);
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
}

.icon-btn .badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background-color: var(--primary-red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    height: 16px;
    min-width: 16px;
    padding: 0 4px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #047857);
    color: #ffffff;
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border-color);
    text-transform: uppercase;
}

.logout-link {
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 12px;
    cursor: pointer;
}

.logout-link:hover {
    color: var(--primary-red);
}

/* ================= 页面布局结构 ================= */
.main-container {
    flex: 1;
    padding: 24px 32px;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.dash-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 32px;
    line-height: 1.6;
}

.dash-card h3 {
    margin-bottom: 8px;
}

.dash-card p {
    color: var(--text-muted);
    font-size: 14px;
}

/* ================= 状态识别页面 (state.html) 独有布局 ================= */
.state-layout {
    display: grid;
    grid-template-columns: minmax(272px, 300px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    height: 100%;
    min-height: 0;
}

/* The filter and parameter areas remain in place. Only the chart workspace
   scrolls, so this page never needs a browser-level vertical scrollbar. */
.state-page .main-container {
    height: calc(100dvh - 64px);
    min-height: 0;
    overflow: hidden;
}

/* ================= 首页行情看板 ================= */
.dashboard-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(272px, 320px);
    gap: 20px;
    height: calc(100vh - 112px);
    align-items: stretch;
}

.watchlist-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--quote-title-control-size);
    height: var(--quote-title-control-size);
    padding: 0;
    border: 1px solid rgba(0, 176, 116, 0.5);
    border-radius: 50%;
    background: rgba(0, 176, 116, 0.1);
    color: var(--primary);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.watchlist-picker { position: relative; }
.watchlist-toggle svg { width: 18px; height: 18px; }
.watchlist-toggle:hover:not(:disabled) { background: var(--primary); color: #fff; }
.watchlist-toggle.is-saved { border-color: var(--primary); background: var(--primary); color: #fff; }
.watchlist-toggle.is-saved:hover:not(:disabled) { background: #43a979; border-color: #43a979; color: #fff; }
.watchlist-toggle:disabled { cursor: not-allowed; opacity: 0.45; }
.watchlist-membership-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 30;
    width: 196px;
    padding: 7px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-card);
    box-shadow: 0 16px 28px rgba(0, 0, 0, .3);
}
.watchlist-membership-menu[hidden] { display: none; }
.watchlist-membership-options { display: grid; gap: 3px; }
.watchlist-membership-option {
    display: flex;
    min-height: 36px;
    align-items: center;
    gap: 9px;
    padding: 7px 8px;
    border-radius: 7px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}
.watchlist-membership-option:hover { background: rgba(0, 176, 116, .1); color: var(--text-main); }
.watchlist-membership-option input { width: 15px; height: 15px; margin: 0; accent-color: var(--primary); }
.watchlist-membership-option span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watchlist-membership-feedback { padding: 9px 8px; color: var(--text-muted); font-size: 12px; }

.quote-card,
.watchlist-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
}

.quote-card { position: relative; display: flex; flex-direction: column; min-width: 0; height: 100%; padding: 18px 20px; }
.quote-card-header, .watchlist-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.watchlist-header { align-items: center; }
.quote-heading { --quote-title-control-size: 34px; display: flex; align-items: flex-end; gap: 14px; min-height: var(--quote-title-control-size); }
.quote-heading h1 { font-size: 28px; line-height: var(--quote-title-control-size); }
.quote-last-close { color: var(--text-muted); font-size: 15px; font-weight: 650; white-space: nowrap; }
.quote-last-close.is-up { color: var(--primary-red); }
.quote-last-close.is-down { color: var(--primary); }
.quote-last-close.is-flat { color: var(--text-muted); }
.quote-toolbar { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.chart-picker { position: relative; }
.chart-picker-trigger {
    display: inline-flex;
    min-height: 34px;
    align-items: center;
    gap: 7px;
    padding: 7px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
    color: var(--text-main);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}
.chart-picker-trigger:hover,
.chart-picker.is-open .chart-picker-trigger { border-color: rgba(0, 176, 116, .7); color: var(--primary); }
.fibonacci-toggle.is-active {
    border-color: var(--primary);
    background: rgba(0, 176, 116, .14);
    color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 176, 116, .12);
}
.chart-picker-trigger:disabled { cursor: not-allowed; opacity: .5; }
.chart-picker-trigger svg { width: 15px; height: 15px; transition: transform .18s ease; }
.chart-picker.is-open .chart-picker-trigger svg { transform: rotate(180deg); }
.chart-picker-menu {
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    z-index: 25;
    display: grid;
    min-width: 124px;
    padding: 7px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-card);
    box-shadow: 0 16px 28px rgba(0, 0, 0, .3);
}
.chart-picker-menu[hidden] { display: none; }
.chart-picker-option {
    min-height: 34px;
    padding: 7px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}
.chart-picker-option:hover,
.chart-picker-option.is-selected { background: rgba(0, 176, 116, .1); color: var(--text-main); }
.chart-picker-option.is-selected::after { float: right; color: var(--primary); content: "✓"; }
.ma-picker-menu { width: 222px; }
.ma-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
.ma-option {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 31px;
    padding: 5px 6px;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
}
.ma-option:hover { background: rgba(0, 176, 116, .08); color: var(--text-main); }
.ma-option input { accent-color: var(--primary); }
.ma-color-swatch { width: 18px; height: 3px; margin-left: 2px; border-radius: 999px; }
.custom-ma-form { display: flex; gap: 5px; margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--border-color); }
.custom-ma-form input {
    width: 100%;
    min-width: 0;
    padding: 6px 7px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: rgba(255, 255, 255, .025);
    color: var(--text-main);
    font: inherit;
    font-size: 12px;
}
.custom-ma-form button { padding: 6px 8px; border: 0; border-radius: 6px; background: rgba(0, 176, 116, .12); color: var(--primary); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.watchlist-panel h2 { font-size: 18px; }
.eyebrow { margin-bottom: 5px; color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: .11em; }
.quote-status {
    position: absolute;
    top: 52%;
    left: 50%;
    z-index: 2;
    width: min(360px, calc(100% - 48px));
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    pointer-events: none;
}
.quote-status.is-error { color: var(--primary-red); }
.quote-chart { flex: 1; width: 100%; height: auto; min-height: 0; }

.watchlist-panel {
    position: sticky;
    top: 84px;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding: 20px;
    overflow: hidden;
}

.watchlist-count {
    display: inline-flex;
    min-width: 26px;
    height: 26px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(0, 176, 116, .13);
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
}

.watchlist-title-row { display: flex; align-items: center; gap: 4px; }
.watchlist-group-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 27px;
    height: 27px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.watchlist-group-trigger:hover,
.watchlist-group-trigger.is-open { background: rgba(255, 255, 255, .05); color: var(--primary); }
.watchlist-group-trigger svg { width: 18px; height: 18px; transition: transform .18s ease; }
.watchlist-group-trigger.is-open svg { transform: rotate(180deg); }

/* The group picker floats over the list like the data-source picker, so
   expanding it never moves the stock rows below. */
.watchlist-group-menu {
    position: absolute;
    top: 66px;
    left: 20px;
    z-index: 20;
    display: grid;
    gap: 3px;
    width: min(260px, calc(100% - 40px));
    max-height: min(260px, calc(100% - 86px));
    padding: 8px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 18px 30px rgba(0, 0, 0, .32);
}
.watchlist-group-menu[hidden] { display: none; }
.watchlist-group-options { display: grid; gap: 2px; }
.watchlist-group-row { display: grid; grid-template-columns: minmax(0, 1fr) 34px; gap: 4px; align-items: center; }
.watchlist-group-row.is-default { grid-template-columns: minmax(0, 1fr); }
.watchlist-group-option,
.add-watchlist-group,
.new-watchlist-group-input {
    width: 100%;
    min-height: 35px;
    padding: 8px 2px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 13px;
    text-align: left;
}

.watchlist-group-option { cursor: pointer; }
.watchlist-group-option:hover,
.watchlist-group-option.is-active { padding-left: 8px; background: rgba(0, 176, 116, .08); color: var(--text-main); }
.watchlist-group-option.is-active::before { content: "•"; margin-right: 7px; color: var(--primary); }
.delete-watchlist-group {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #64748b;
    font: inherit;
    font-size: 21px;
    line-height: 1;
    cursor: pointer;
}
.delete-watchlist-group:hover { background: rgba(234, 67, 53, .12); color: var(--primary-red); }
.add-watchlist-group { color: var(--primary); cursor: pointer; font-weight: 700; }
.add-watchlist-group:hover { background: rgba(0, 176, 116, .08); padding-left: 8px; }
.new-watchlist-group-input { border-bottom: 1px solid var(--primary); outline: none; color: var(--text-main); }
.new-watchlist-group-input::placeholder { color: #64748b; }

.watchlist-items { display: block; flex: 1; min-height: 0; margin-top: 16px; overflow-y: auto; }
.watchlist-items:empty { display: none; }
.watchlist-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 76px;
    padding: 12px 4px;
    box-sizing: border-box;
    border: 0;
    border-bottom: 1px dashed rgba(148, 163, 184, .24);
    background: transparent;
    color: var(--text-main);
    font: inherit;
    cursor: pointer;
    text-align: left;
}

.watchlist-row:hover { background: rgba(255, 255, 255, .035); }
.watchlist-row.is-selected {
    padding-left: 9px;
    background: rgba(0, 176, 116, .09);
    box-shadow: inset 3px 0 0 var(--primary);
}
.watchlist-row:hover .watchlist-symbol,
.watchlist-row:hover .watchlist-close,
.watchlist-row:hover .watchlist-source,
.watchlist-row:hover .watchlist-date,
.watchlist-row.is-selected .watchlist-symbol,
.watchlist-row.is-selected .watchlist-close,
.watchlist-row.is-selected .watchlist-source,
.watchlist-row.is-selected .watchlist-date { color: var(--text-main); }
.watchlist-quote-primary { display: inline-flex; align-items: baseline; min-width: 0; gap: 9px; }
.watchlist-symbol { color: var(--text-muted); font-size: 14px; font-weight: 700; }
.watchlist-quote-details { display: grid; justify-items: end; gap: 3px; min-width: 0; }
.watchlist-source { color: var(--text-muted); font-size: 11px; }
.watchlist-date { color: var(--text-muted); font-size: 11px; white-space: nowrap; }
.watchlist-close { color: var(--text-muted); font-size: 13px; font-weight: 700; white-space: nowrap; }
.watchlist-feedback { padding: 14px 2px; color: var(--text-muted); font-size: 12px; line-height: 1.5; }
.watchlist-feedback.is-error { color: var(--primary-red); }
.watchlist-empty { display: grid; flex: 1; align-content: center; justify-items: center; gap: 8px; padding: 32px 12px; color: var(--text-muted); text-align: center; }
.watchlist-empty[hidden] { display: none !important; }
.watchlist-empty svg { width: 30px; height: 30px; color: var(--primary); }
.watchlist-empty p { color: var(--text-main); font-size: 14px; font-weight: 600; }
.watchlist-empty span { font-size: 12px; line-height: 1.5; }

.sidebar-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    height: 100%;
    min-height: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.param-control {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-muted);
}

.param-control .num-input {
    width: 70px;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    text-align: center;
    outline: none;
    appearance: textfield;
    -moz-appearance: textfield;
}

/* 统一可编辑与只读数字框的外观，避免浏览器原生上下箭头打破对齐。 */
.param-control .num-input::-webkit-outer-spin-button,
.param-control .num-input::-webkit-inner-spin-button {
    margin: 0;
    appearance: none;
}

.slider-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-muted);
}

.slider-val {
    color: var(--primary);
    font-weight: bold;
}

input[type="range"] {
    accent-color: var(--primary);
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn {
    width: 100%;
    min-height: 46px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-secondary {
    background-color: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sidebar-status {
    margin-top: auto;
}

.status-title {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
}

.status-box {
    background: var(--bg-input);
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.5;
    min-height: 76px;
    max-height: 132px;
    overflow-y: auto;
}

.content-area {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    min-width: 0;
    gap: 18px;
}

.filter-panel {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.1fr) minmax(0, 1.45fr) repeat(2, minmax(0, 0.95fr));
    gap: 12px;
    background: var(--bg-card);
    padding: 14px 18px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    align-items: start;
    flex: 0 0 auto;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.filter-group > label {
    display: flex;
    align-items: center;
    min-height: 20px;
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: 13px;
    font-weight: 600;
    line-height: 20px;
}

.filter-group input[type="text"],
.filter-group input[type="date"] {
    width: 100%;
    min-width: 0;
    height: 42px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 14px;
    color: var(--text-main);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    outline: none;
}

/* 让浏览器原生日期选择器采用页面的深色配色，无需额外脚本或组件。 */
.filter-group input[type="date"] {
    color-scheme: dark;
}

.filter-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 176, 116, 0.12);
}

.radio-group {
    display: flex;
    gap: 18px;
    align-items: center;
    width: 100%;
    min-width: 0;
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-input);
}

.radio-group label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    white-space: nowrap;
}

.radio-group input[type="radio"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--primary);
}

.adjustment-group {
    gap: 16px;
}

.adjustment-group label.is-disabled {
    color: #64748b;
    cursor: not-allowed;
}

.adjustment-group input:disabled {
    cursor: not-allowed;
}

.analysis-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    min-width: 0;
    border-radius: 14px;
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
    scrollbar-color: #3f4a60 transparent;
}

.analysis-panel::-webkit-scrollbar {
    width: 10px;
}

.analysis-panel::-webkit-scrollbar-track {
    background: transparent;
}

.analysis-panel::-webkit-scrollbar-thumb {
    background: #3f4a60;
    border: 3px solid var(--bg-card);
    border-radius: 999px;
}

.analysis-panel::-webkit-scrollbar-thumb:hover {
    background: #526079;
}

.analysis-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.analysis-chart {
    min-width: 0;
    padding: 20px;
}

.analysis-chart:first-child {
    border-right: 1px solid var(--border-color);
}

.analysis-chart-wide {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border-color);
}

.chart-header-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 14px;
}

.chart-container {
    width: 100%;
    height: clamp(320px, 25vw, 410px);
}

.chart-container.large {
    height: clamp(380px, 30vw, 500px);
}

/* 桌面端首行 GMM 图略加高，避免下一行 HMM 图的标题或图例露出。 */
@media (min-width: 681px) {
    .state-page .analysis-chart:not(.analysis-chart-wide) .chart-container {
        height: clamp(340px, 26vw, 425px);
    }
}

/* ================= Theme-aware refinement layer =================
   The original component rules above describe structure. This final layer
   centralizes theme-sensitive paint and applies a deliberately tighter
   desktop rhythm without changing interaction or layout semantics. */
::selection {
    background: var(--primary-soft-strong);
    color: var(--text-main);
}

.login-modal-overlay { background: var(--modal-backdrop); }
.login-card { border-radius: var(--radius-lg); padding: 28px; box-shadow: var(--shadow-login); }
.login-header .brand-logo,
.nav-brand { color: var(--text-main); }
.test-accounts-tip { border-radius: var(--radius-sm); }
.login-form input { border-radius: var(--radius-sm); padding: 9px 12px; color: var(--text-main); }
.btn-login {
    min-height: 40px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-on-primary);
    font-size: 13px;
}

.navbar { height: var(--nav-height); padding-inline: 24px; }
.nav-brand { font-size: 19px; }
.nav-center { flex-basis: 500px; }
.search-bar {
    height: var(--control-height);
    padding: 2px 4px 2px 12px;
    border-radius: 999px;
}
.search-bar:focus-within { box-shadow: 0 0 0 2px var(--focus-ring); }
.source-picker-menu { border-radius: var(--radius-md); box-shadow: var(--shadow-popover); }
.source-picker-option { padding: 8px 9px; border-radius: var(--radius-xs); }
.source-picker-option:hover,
.source-picker-option.is-selected { background: var(--primary-soft-strong); }
.search-divider { margin-inline: 9px; }
.search-btn { width: 28px; height: 28px; color: var(--text-on-primary); }
.nav-right { gap: 16px; }
.nav-pages { gap: 12px; }
.page-link { padding: 6px 10px; border-radius: var(--radius-xs); font-size: 13px; }
.page-link.active { background-color: var(--primary-soft); }
.user-actions { gap: 12px; }
.icon-btn {
    width: 30px;
    height: 30px;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: color .18s ease, background-color .18s ease;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text-main); }
.theme-toggle {
    position: relative;
    display: inline-flex;
    width: 42px;
    height: 24px;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-input);
    color: var(--text-subtle);
    font: inherit;
    line-height: 1;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    transition: border-color .18s ease, background-color .18s ease;
}
.theme-toggle:hover,
.theme-toggle:focus-visible { border-color: var(--primary-border); outline: none; }
.theme-toggle:focus-visible { box-shadow: 0 0 0 2px var(--focus-ring); }
.theme-toggle:disabled { cursor: wait; opacity: .62; }
.theme-icon {
    z-index: 1;
    width: 12px;
    height: 12px;
    stroke-width: 2.15;
    transition: color .18s ease;
}
.theme-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 3px;
    width: 18px;
    height: 18px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    box-shadow: 0 2px 5px rgba(0, 0, 0, .14);
    transform: translateX(18px);
    transition: transform .2s ease, background-color .18s ease, border-color .18s ease;
}
.theme-toggle[aria-pressed="true"] .theme-toggle-thumb { transform: translateX(0); }
.theme-toggle[aria-pressed="false"] .theme-icon-moon,
.theme-toggle[aria-pressed="true"] .theme-icon-sun { color: var(--primary); }
.theme-toggle[aria-pressed="false"] .theme-icon-sun,
.theme-toggle[aria-pressed="true"] .theme-icon-moon { color: var(--text-subtle); }
.icon-btn .badge { color: var(--text-on-primary); }
.avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--avatar-start), var(--avatar-end));
    color: var(--text-on-primary);
}
.logout-link { color: var(--text-subtle); }

.main-container { padding: 18px 24px; }
.state-page .main-container { height: calc(100dvh - var(--nav-height)); }
.state-layout,
.dashboard-layout { gap: var(--layout-gap); }
.dashboard-layout {
    grid-template-columns: minmax(0, 1fr) minmax(264px, 304px);
    height: calc(100dvh - 94px);
}

.quote-card,
.watchlist-panel,
.sidebar-panel,
.filter-panel,
.analysis-panel,
.dash-card { border-radius: var(--radius-md); }
.quote-card { padding: 16px 18px; }
.quote-card-header,
.watchlist-header { gap: 12px; }
.quote-heading { --quote-title-control-size: 32px; gap: 11px; }
.quote-heading h1 { font-size: 25px; }
.quote-last-close { font-size: 14px; }
.quote-toolbar { gap: 6px; }
.chart-picker-trigger {
    min-height: var(--control-height-sm);
    gap: 6px;
    padding: 6px 9px;
    border-radius: var(--radius-sm);
    background: var(--surface-raised);
}
.chart-picker.is-open .chart-picker-trigger { border-color: var(--primary-border); }
.fibonacci-toggle.is-active {
    background: var(--primary-soft-strong);
    box-shadow: 0 0 0 2px var(--focus-ring);
}
.chart-picker-menu,
.watchlist-membership-menu,
.watchlist-group-menu {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-popover);
}
.chart-picker-option { min-height: var(--control-height-sm); padding: 6px 8px; border-radius: var(--radius-xs); }
.chart-picker-option:hover,
.chart-picker-option.is-selected { background: var(--primary-soft); }
.ma-option { min-height: 29px; padding: 4px 6px; }
.ma-option:hover,
.watchlist-membership-option:hover,
.watchlist-group-option:hover,
.watchlist-group-option.is-active,
.add-watchlist-group:hover { background: var(--primary-soft); }
.custom-ma-form input { background: var(--surface-raised); }
.custom-ma-form button { background: var(--primary-soft-strong); }
.watchlist-toggle {
    border-color: var(--primary-border);
    background: var(--primary-soft);
}
.watchlist-toggle:hover:not(:disabled),
.watchlist-toggle.is-saved { color: var(--text-on-primary); }
.watchlist-toggle.is-saved:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.watchlist-panel { top: calc(var(--nav-height) + 16px); padding: 18px; }
.watchlist-panel h2 { font-size: 17px; }
.watchlist-count { width: 24px; min-width: 24px; height: 24px; background: var(--primary-soft-strong); }
.watchlist-items { margin-top: 12px; }
.watchlist-row {
    height: 64px;
    padding-block: 10px;
    border-bottom-color: var(--border-subtle);
}
.watchlist-row:hover,
.watchlist-group-trigger:hover,
.watchlist-group-trigger.is-open,
.btn-secondary:hover { background: var(--surface-hover); }
.watchlist-row.is-selected { background: var(--primary-soft); }
.delete-watchlist-group,
.new-watchlist-group-input::placeholder { color: var(--text-subtle); }
.delete-watchlist-group:hover { background: var(--danger-soft); }

.sidebar-panel { padding: 18px; gap: 16px; }
.section-title { padding-bottom: 8px; font-size: 14px; }
.param-control,
.slider-header { font-size: 12px; }
.param-control .num-input { padding: 7px 9px; border-radius: var(--radius-xs); }
.action-buttons { gap: 7px; }
.btn { min-height: 40px; padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.btn-primary { color: var(--text-on-primary); }
.status-box { padding: 9px; border-radius: var(--radius-xs); min-height: 68px; }
.content-area { gap: var(--layout-gap); }
.filter-panel { gap: 10px; padding: 12px 16px; }
.filter-group { gap: 6px; }
.filter-group > label { min-height: 18px; font-size: 12px; line-height: 18px; }
.filter-group input[type="text"],
.filter-group input[type="date"] {
    height: var(--control-height);
    padding: 8px 11px;
    border-radius: var(--radius-xs);
    font-size: 13px;
}
.filter-group input[type="date"] { color-scheme: var(--native-color-scheme); }
.filter-group input:focus { box-shadow: 0 0 0 2px var(--focus-ring); }
.radio-group {
    min-height: var(--control-height);
    gap: 14px;
    padding-inline: 11px;
    border-radius: var(--radius-sm);
}
.radio-group label { gap: 6px; font-size: 13px; }
.adjustment-group label.is-disabled { color: var(--text-subtle); }
.analysis-panel { scrollbar-color: var(--scrollbar-thumb) transparent; }
.analysis-panel::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-color: var(--bg-card); }
.analysis-panel::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }
.analysis-chart { padding: 18px; }
.chart-header-text { margin-bottom: 12px; font-size: 14px; }

@media (max-width: 1300px) {
    .filter-panel {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .radio-group {
        gap: 12px;
        padding-inline: 10px;
    }

    .adjustment-group {
        gap: 10px;
    }
}

@media (max-width: 980px) {
    .dashboard-layout { grid-template-columns: 1fr; height: auto; }
    .quote-card { height: auto; }
    .quote-chart { flex: initial; height: clamp(360px, 58vw, 560px); }
    .watchlist-panel { position: relative; height: auto; min-height: 0; max-height: 440px; }
    .state-layout {
        grid-template-columns: 1fr;
        height: auto;
        min-height: initial;
    }

    body.state-page {
        height: auto;
        overflow-y: auto;
    }

    .state-page .main-container,
    .content-area {
        height: auto;
        min-height: initial;
        overflow: visible;
    }

    .sidebar-panel {
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .analysis-panel {
        flex: initial;
        min-height: initial;
        overflow: visible;
    }

    .filter-panel {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .quote-card-header { flex-direction: column; }
    .quote-toolbar { justify-content: flex-start; }
    .quote-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
    .quote-chart { height: clamp(300px, calc(100vh - 220px), 480px); }
    .state-page .main-container {
        padding: 16px;
    }

    .filter-panel,
    .analysis-grid {
        grid-template-columns: 1fr;
    }

    .filter-panel {
        padding: 16px;
    }

    .radio-group {
        width: 100%;
        flex-wrap: wrap;
        height: auto;
        min-height: 38px;
        padding: 8px 10px;
    }

    .analysis-chart:first-child {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .analysis-chart-wide {
        grid-column: auto;
    }
}
