:root[data-theme="dark"] {
  --bg:#0d141b;
  --panel:#131d26;
  --text:#d9e6f2;
  --muted:#8fa4b6;
  --line:#2a3a47;
  --brand:#4b9fbd;
  --up:#ff7a73;
  --down:#4fc18b;
  --warn:#d6a34f;
  --error:#ff6975;
}

html[data-theme="dark"] {
  color-scheme:dark;
}

html[data-theme="dark"] body {
  background:var(--bg);
  color:var(--text);
}

.control-group-theme {
  flex:0 0 auto;
}

.theme-toggle {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:7px;
  min-width:78px;
  height:30px;
  border:1px solid color-mix(in srgb,var(--brand) 20%,var(--line));
}

.theme-toggle-icon {
  position:relative;
  width:16px;
  height:16px;
  border-radius:999px;
  background:color-mix(in srgb,var(--warn) 84%,#fff);
  box-shadow:0 0 0 2px color-mix(in srgb,var(--warn) 18%,transparent);
}

:root[data-theme="dark"] .theme-toggle-icon {
  background:#d6e8ff;
  box-shadow:inset -5px -2px 0 #6f89a2,0 0 0 2px rgba(90,159,189,.22);
}

:root[data-theme="dark"] .theme-toggle {
  background:color-mix(in srgb,var(--brand) 16%,var(--panel));
  color:var(--text);
}

:root[data-theme="dark"] .about-panel-head {
  background:#152330;
  border-color:var(--line);
}

:root[data-theme="dark"] .about-backdrop {
  background:rgba(0,0,0,.58);
}

:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .login-card,
:root[data-theme="dark"] .account-panel,
:root[data-theme="dark"] .about-panel,
:root[data-theme="dark"] .trader-workbench,
:root[data-theme="dark"] .ai-live-panel,
:root[data-theme="dark"] .price-action-toolbar,
:root[data-theme="dark"] .price-action-object-bar,
:root[data-theme="dark"] .price-action-chart,
:root[data-theme="dark"] .price-action-evidence,
:root[data-theme="dark"] .quant-signal-head,
:root[data-theme="dark"] .quant-detail-panel,
:root[data-theme="dark"] .asset-drawer-head,
:root[data-theme="dark"] .observation-shell,
:root[data-theme="dark"] .related-panel-shell,
:root[data-theme="dark"] .related-panel-empty {
  background:var(--panel);
  border-color:var(--line);
  color:var(--text);
}

:root[data-theme="dark"] .sidebar-resize,
:root[data-theme="dark"] .chart-resize-handle {
  background:#1b2a35;
}

:root[data-theme="dark"] .tabs {
  background:color-mix(in srgb,var(--bg) 88%,var(--panel));
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  background:#0f1922;
  border-color:var(--line);
  color:var(--text);
}

:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder {
  color:#667d91;
}

:root[data-theme="dark"] :is(.account-card,.about-version-item,.about-feature-card,.about-release,.about-note,.market-group,.m-item,.card,.fund-detail-card,.etf-detail-card,.stock-detail-card,.related-panel-field,.observation-target,.observation-item,.observation-empty,.asset-drawer-tabs,.asset-drawer .related-panel-shell,.asset-drawer .related-panel-empty,.asset-drawer .observation-shell,.asset-drawer .fund-detail-card,.asset-drawer .etf-detail-card,.hot-source,.quant-signal-matrix,.quant-signal-side>section,.quant-matrix-wrap,.quant-detail-factor-panel,.quant-detail-chart,.quant-drawdown-detail,.quant-ai-review,.bar-summary-card,.calendar-month-total,.cal-day,.vol-range-block,.risk-missing-panel,.risk-threshold-editor,.risk-history-card,.risk-explain-table-wrap,.risk-explain-grid>div,.risk-threshold-field,.risk-history-card,.fund-history-kline,.etf-price-kline,.tw-focus-table-wrap,.tw-anomaly-list,.tw-anomaly-row,.ai-live-summary>div,.ai-live-block,.ai-live-empty,.ai-live-references,.ai-live-reference,.ai-live-source-option) {
  background:#121d26;
  border-color:var(--line);
  color:var(--text);
}

:root[data-theme="dark"] :is(#chart,.flow-chart,.trading-lw-chart,.volatility-chart,.treemap-chart,.price-action-echart,.fund-history-chart,.fund-history-kline,.etf-flow-chart,.etf-price-kline,.etf-chart-wrap,.chart-wrap) {
  background:var(--panel);
}

:root[data-theme="dark"] :is(.price-action-echart,.fund-history-kline,.etf-price-kline) canvas {
  background:transparent !important;
}

:root[data-theme="dark"] :is(.view-presets button,.fund-view-presets button,.quant-signal-actions>button,.quant-signal-actions .quant-presets button,.tw-filter-bar button,.tw-card-button,.risk-config-btn,.asset-drawer-tabs button) {
  background:#101a23;
  border-color:var(--line);
  color:var(--text);
}

:root[data-theme="dark"] :is(.workspace-nav .tab-btn:hover,.view-presets button:hover:not(:disabled),.fund-view-presets button:hover:not(:disabled),.quant-signal-actions>button:hover:not(:disabled),.quant-signal-actions .quant-presets button:hover:not(:disabled),.tw-filter-bar button:hover:not(:disabled),.tw-card-button:hover) {
  background:#172837;
  border-color:var(--brand);
  color:#dff5ff;
}

:root[data-theme="dark"] :is(.workspace-nav .tab-btn.active,.tab-btn.active,.view-presets button.active,.fund-view-presets button.active,.quant-signal-actions>button:first-child,#quantTrend7Btn.active,#quantTrend30Btn.active) {
  background:var(--brand);
  border-color:var(--brand);
  color:#06131a;
}

:root[data-theme="dark"] :is(h1,h2,h3,h4,.login-card h2,.workspace-nav .tab-btn:not(.active),.tab-btn:not(.active),.nav-group-label,.account-panel-title,.account-card-title,.account-user-name,.about-panel-title,.about-section-title,.about-version-item strong,.about-feature-card strong,.about-release-title,.about-note strong,.trader-workbench .tw-title,.trader-workbench .tw-section-label,.tw-focus-label,.tw-focus-value,.tw-anomaly-title,.tw-anomaly-metric,.asset-drawer h2,.asset-drawer-section-title,.fund-detail-card strong,.etf-detail-card strong,.stock-detail-card strong,.fund-live-value,.m-price,.m-change,.mg-title,.chart-head strong,.observation-title,.observation-target strong,.observation-item-head strong,.related-panel-eyebrow,.related-panel-empty-title,.price-action-object-bar h3,.price-action-chart h3,.price-action-evidence h3,.price-action-section-title,.price-action-proxy-title,.price-action-decision strong,.quant-signal-title,.quant-block-title,.quant-matrix-label,.quant-matrix-value,.quant-top-reading,.quant-dist-row b,.quant-version-table td,.quant-ai-review-head,.quant-drawdown-detail summary,.risk-explain-title,.risk-history-title,.ai-live-title,.ai-live-summary strong,.ai-live-reference a,.ai-live-reference span) {
  color:var(--text);
}

:root[data-theme="dark"] :is(.meta,.hot-meta,.m-name,.m-clock,.account-panel-meta,.account-user-meta,.account-ai-status,.about-panel-subtitle,.about-hero p,.about-version-item span,.about-feature-card li,.about-release li,.about-release-meta time,.about-note p,.price-action-field span,.price-action-preset-meta,.price-action-stat-grid span,.price-action-stat-grid em,.price-action-decision span,.asset-drawer-meta,.asset-drawer-eyebrow,.observation-subtitle,.related-panel-subtitle,.related-panel-empty small,.quant-signal-subtitle,.quant-block-title span,.quant-dist-row em,.quant-version-table th,.quant-reading-note,.quant-methodology,.fund-live-sub,.k,.hint,.mg-title,.hot-section-title,.ai-live-meta,.ai-live-summary span,.ai-live-summary p,.ai-live-block-title,.ai-live-block li,.ai-live-sourcebar,.ai-live-reference em,.ai-live-reference-empty) {
  color:var(--muted);
}

:root[data-theme="dark"] :is(th,.quant-matrix-table th,.quant-version-table th,.tw-focus-table th,.hot-source-title,.section,.list-toolbar,.chart-head,.asset-drawer-tabs) {
  background:#152330;
  border-color:var(--line);
  color:#a8c0d4;
}

:root[data-theme="dark"] :is(td,th,.quant-matrix-table td,.quant-version-table td,.tw-focus-table td,.fund-holdings-table td,.fund-holdings-table th,.etf-holdings-table td,.etf-holdings-table th) {
  border-color:var(--line);
}

:root[data-theme="dark"] tr:hover td,
:root[data-theme="dark"] .tw-focus-row.tw-active,
:root[data-theme="dark"] .tw-focus-row:hover,
:root[data-theme="dark"] .tw-anomaly-row:hover,
:root[data-theme="dark"] .quant-matrix-highlight,
:root[data-theme="dark"] .account-user-row.active {
  background:#172837;
}

:root[data-theme="dark"] .fund-table th:nth-child(1),
:root[data-theme="dark"] .fund-table th:nth-child(2),
:root[data-theme="dark"] .fund-table th:nth-child(3),
:root[data-theme="dark"] .fund-table td:not([colspan]):nth-child(1),
:root[data-theme="dark"] .fund-table td:not([colspan]):nth-child(2),
:root[data-theme="dark"] .fund-table td:not([colspan]):nth-child(3) {
  background:#121d26;
}

:root[data-theme="dark"] :is(.quant-status-strip,.quant-reading-note,.quant-dist-track,.quant-review-stats span,.quant-factor,.quant-factor-driver,.quant-validation,.quant-shadow,.quant-shadow-head em,.quant-drawdown-grid span,.quant-ai-review-note,.quant-trend-spark,.quant-detail-desc,.quant-backtest-note,.tw-freshness-line,.tw-freshness-chip,.tw-radar-summary,.bar-summary-card.total,.hot-word-cloud-panel) {
  background:#101a23;
  border-color:var(--line);
  color:var(--muted);
}

:root[data-theme="dark"] :is(.risk-none,.quant-watch,.quant-direction,.quant-notice,.quant-reason,.quant-shadow-watch,.quant-shadow-drawdown,.observation-tags span,.theme-link) {
  background:#172837;
  border-color:#33495a;
  color:#b7c9d8;
}

:root[data-theme="dark"] :is(.risk-caution,.quant-caution,.quant-shadow-caution,.quant-shadow-drawdown-caution,.quant-validation-light,.quant-notice-warning) {
  background:#342910;
  border-color:#735d1d;
  color:#f0c76e;
}

:root[data-theme="dark"] :is(.risk-danger,.risk-overheat,.quant-danger,.quant-strong,.quant-shadow-danger,.quant-shadow-drawdown-danger,.quant-shadow-strong,.quant-validation-positive,.quant-notice-positive,.quant-ai-error,.tw-type-pill,.tw-card-badge) {
  background:#3a1719;
  border-color:#7e3337;
  color:#ff9b9b;
}

:root[data-theme="dark"] :is(.quant-hold,.quant-direction-new,.quant-notice-info) {
  background:#10283a;
  border-color:#245c82;
  color:#9fd6ff;
}

:root[data-theme="dark"] :is(.quant-validation-negative,.quant-notice-negative,.risk-badge.risk-none) {
  background:#113022;
  border-color:#2f7555;
  color:#8be0b2;
}

:root[data-theme="dark"] :is(.flow-grid,.vol-history-grid,.quant-detail-grid) {
  stroke:#263946;
}

:root[data-theme="dark"] :is(.flow-grid.soft) {
  stroke:#1d2d38;
}

:root[data-theme="dark"] :is(.flow-axis,.vol-history-axis) {
  stroke:#496174;
}

:root[data-theme="dark"] :is(.flow-axis-label,.flow-section-label,.flow-bar-name,.flow-bar-value,.flow-empty,.vol-history-label,.vol-history-band-label,.quant-detail-axis) {
  fill:#9eb4c7;
}

:root[data-theme="dark"] .flow-point,
:root[data-theme="dark"] .quant-detail-dot {
  stroke:#101a23;
}

:root[data-theme="dark"] .flow-end-label {
  stroke:#101a23;
}

:root[data-theme="dark"] :is(.fund-history-chart,.etf-flow-chart) :is(line,path) {
  stroke-opacity:.92;
}

:root[data-theme="dark"] :is(.fund-history-chart,.etf-flow-chart) line {
  stroke:#344858;
}

:root[data-theme="dark"] :is(.fund-history-chart,.etf-flow-chart) text {
  fill:#9eb4c7;
}

:root[data-theme="dark"] .hot-cloud-bg {
  fill:#101a23;
  stroke:#2b4254;
}

:root[data-theme="dark"] .hot-cloud-orbit {
  stroke:#31495c;
}

:root[data-theme="dark"] .hot-cloud-text {
  stroke:#101a23;
}

:root[data-theme="dark"] .hot-cloud-caption {
  fill:#7f95a7;
}

:root[data-theme="dark"] .ai-live-error {
  background:#3a1719;
  border-color:#7e3337;
  color:#ff9b9b;
}

:root[data-theme="dark"] .asset-drawer {
  background:var(--bg);
  border-color:var(--line);
  box-shadow:-10px 0 28px rgba(0,0,0,.28);
}

:root[data-theme="dark"] .asset-drawer-backdrop {
  background:rgba(4,10,14,.58);
}

:root[data-theme="dark"] .chart-tooltip {
  background:rgba(6,13,18,.96);
  border:1px solid var(--line);
}

@media (max-width:800px) {
  .control-group-theme {
    width:100%;
  }

  .theme-toggle {
    flex:1 1 120px;
  }
}
