/* Shared Dashboard color theme. Loaded after page-owned styles so legacy and React
   pages can opt into the same palette without duplicating theme state. */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a100d;
  --panel: #111a16;
  --panel-strong: #16211c;
  --panel-subtle: #17221d;
  --soft: #151f1b;
  --ink: #e7f0eb;
  --strong: #f4faf7;
  --muted: #91a39a;
  --line: #27372f;
  --line-strong: #385047;
  --accent: #32ae98;
  --accent-dark: #72d1bd;
  --accent-soft: #15362e;
  --good: #51c989;
  --bad: #ff7b70;
  --warn: #e5b85c;
  --gold: #e6b85b;
  --gold-soft: #382d17;
  --blue: #75a7ef;
  --blue-soft: #172b43;
  --red: #ff7b70;
  --red-soft: #3c211f;
  --up: #51c989;
  --up-soft: #17372a;
  --down: #ff7b70;
  --down-soft: #3c211f;
  --code: #070b09;
  --code-text: #a8e4d2;
  --shadow: 0 15px 38px rgba(0, 0, 0, .24);
}

html[data-theme="dark"] body {
  --quality-bg: #0a100d;
  --quality-panel: #111a16;
  --quality-ink: #e7f0eb;
  --quality-muted: #91a39a;
  --quality-line: #2a3a32;
  --quality-accent: #32ae98;
  --quality-good: #51c989;
  --quality-bad: #ff7b70;
  --quality-gold: #e6b85b;
  --history-ink: #e7f0eb;
  --history-line: #2a3a32;
  --history-soft: #17221d;
  --history-green: #51c989;
  --history-red: #ff7b70;
  --history-amber: #e5b85c;
  --sweep-ink: #e7f0eb;
  --sweep-muted: #91a39a;
  --sweep-line: #2a3a32;
  --sweep-soft: #17221d;
  --sweep-accent: #32ae98;
  --sweep-accent-dark: #72d1bd;
  --sweep-accent-soft: #15362e;
  --sweep-warm: #382d17;
  --teal: #32ae98;
  --teal-dark: #72d1bd;
  --navy: #a9c6ee;
  --night: #e7f0eb;
  --night-soft: #17221d;
  margin: 0;
  background-color: #0a100d !important;
  background-image: linear-gradient(180deg, #0e1713 0, #0a100d 520px) !important;
  color: var(--ink) !important;
}

html[data-theme="dark"] ::selection { background: #256b5c; color: #fff; }
html[data-theme="dark"] * { scrollbar-color: #40564d #101713; }
html[data-theme="dark"] a { color: #72d1bd; }
html[data-theme="dark"] a:hover { color: #9ce5d5; }

html[data-theme="dark"] body :where(input, select, textarea) {
  border-color: var(--line-strong) !important;
  background-color: #101914 !important;
  color: var(--ink) !important;
  box-shadow: none !important;
}
html[data-theme="dark"] body :where(input, textarea)::placeholder { color: #6f8178 !important; }
html[data-theme="dark"] body :where(input, select, textarea):disabled { background-color: #0d1411 !important; color: #687970 !important; }
html[data-theme="dark"] option { background: #111a16; color: #e7f0eb; }
html[data-theme="dark"] input[type="checkbox"],
html[data-theme="dark"] input[type="radio"] { accent-color: #32ae98; }

html[data-theme="dark"] body :where(button.ghost, .ghost, .secondary, .secondary-button, .refresh, .action-link.ghost) {
  border-color: var(--line-strong) !important;
  background: #15201b !important;
  color: var(--ink) !important;
  box-shadow: none !important;
}
html[data-theme="dark"] body :where(button.ghost, .ghost, .secondary, .secondary-button, .refresh, .action-link.ghost):hover {
  background: #1b2a23 !important;
  color: #9ce5d5 !important;
}

html[data-theme="dark"] body :where(
  .panel, .card, .metric, .wallet-section, .market-section, .tool-card,
  .review-side-panel, .access-panel, .filter-panel, .results-panel, .favorites,
  .filters, .results, .overview-card, .summary-card, .stat-card, .info-card,
  .workspace-card, .config-card, .chart-card, .chart-panel, .table-card,
  .detail-card, .position-card, .market-card, .wallet-card, .history-card,
  .subscription-card, .health-card, .service-card, .command-card, .param-card,
  .strategy-card, .copy-param-section, .tier-config-section, .tier-rule-row,
  .tier-logic-node, .tier-condition-card, .tier-channel-card, .tier-runtime,
  .tier-smart-step, .quality-panel, .event-card, .event-item, .market-item,
  .address-performance-item, .tier-result, .address-row, .market-row,
  .source-row, .result-row, .config-section, .form-section, .control-section,
  .chart-wrap, .table-wrap, .latest-table-inner
) {
  border-color: var(--line) !important;
  background-color: var(--panel) !important;
  background-image: none !important;
  color: var(--ink) !important;
  box-shadow: var(--shadow) !important;
}

html[data-theme="dark"] body :where(
  .statusbar, .status, .empty, .note, .hint, .help, .meta, .selection-meta,
  .tier-runtime-metric, .tier-runtime-tier, .metric-cell, .stat-cell,
  .summary-box, .detail-summary, .filter-summary, .result-summary,
  .operation-detail-status, .market-result-summary, .address-result-summary,
  .timeline-item, .latency-group, .trigger-profile, .confirmation-summary,
  .source-summary, .field-note
) {
  border-color: var(--line) !important;
  background-color: var(--panel-subtle) !important;
  color: var(--muted) !important;
  background-image: none !important;
}

html[data-theme="dark"] body :where(
  .selector-menu, .slug-options, .market-trade-popover, .popover, .dropdown,
  .dropdown-menu, .modal, .modal-card, .dialog, .drawer, .sheet
) {
  border-color: var(--line-strong) !important;
  background: rgba(17, 26, 22, .98) !important;
  color: var(--ink) !important;
  box-shadow: 0 22px 54px rgba(0, 0, 0, .5) !important;
}

html[data-theme="dark"] body :where(.selector-trigger, .selector-option, .slug-option, .market-option, .filter-option) {
  border-color: var(--line) !important;
  background-color: #131d18 !important;
  color: var(--ink) !important;
}
html[data-theme="dark"] body :where(.selector-option, .slug-option, .market-option, .filter-option):hover,
html[data-theme="dark"] body :where(.selector-option.active, .slug-option.active, .market-option.active, .filter-option.active) {
  border-color: #437769 !important;
  background-color: #19342c !important;
}

html[data-theme="dark"] body :where(table) { color: var(--ink); background-color: transparent !important; }
html[data-theme="dark"] body :where(th) { border-color: var(--line) !important; background-color: #17221d !important; color: #a4b5ac !important; }
html[data-theme="dark"] body :where(td) { border-color: var(--line) !important; background-color: transparent; color: inherit; }
html[data-theme="dark"] body :where(tbody tr:hover, tr.clickable:hover) { background-color: #152a23 !important; }

html[data-theme="dark"] body :where(.pill, .tool-chip, .badge, .summary-chip, .status-token, .tier-tag, .category) {
  border-color: #315f53 !important;
  background-color: #17372f !important;
  color: #8edbca !important;
}
html[data-theme="dark"] body :where(.good, .positive, [data-tone="good"], [data-tone="positive"]) { color: var(--good) !important; }
html[data-theme="dark"] body :where(.bad, .negative, [data-tone="bad"], [data-tone="negative"], [data-tone="error"]) { color: var(--bad) !important; }
html[data-theme="dark"] body :where(.warn, [data-tone="warn"], [data-tone="warning"]) { color: var(--warn) !important; }
html[data-theme="dark"] body :where(.warning, .notice, .safety-warning, .deploy-warning, [data-kind="warning"]) {
  border-color: #69562d !important;
  background: #302817 !important;
  color: #e6c577 !important;
}
html[data-theme="dark"] body :where(.error, .error-message, .form-error, .health-incident.active, [data-kind="error"]) {
  border-color: #70403b !important;
  background: #34201d !important;
  color: #ff9a91 !important;
}

html[data-theme="dark"] body :where(code, pre, .code, .console, .raw-json) {
  border-color: #27372f !important;
  background-color: #070b09 !important;
  color: #a8e4d2 !important;
}
html[data-theme="dark"] body :where(svg text) { fill: #a4b5ac; }
html[data-theme="dark"] body :where(svg .grid, svg [class*="grid"], svg [class*="axis"]) { stroke: #2c3b34; }

/* Legacy pages frequently use white as a nested control surface. These named
   selectors intentionally exclude the dark hero and navigation chrome. */
html[data-theme="dark"] body :where(
  .segmented, .module-tabs, .view-tabs, .tab-list, .filter-tabs,
  .field-group, .input-group, .settings-group, .logic-strip, .flow-step,
  .address-item, .market-result, .operation-row, .result-item, .history-item,
  .subscription-row, .quality-control, .quality-group, .tier-group,
  .tier-rule-card, .address-trigger-market-item, .address-market-curve,
  .market-operation-host, .event-market-list, .operations
) {
  border-color: var(--line) !important;
  background-color: #121c17 !important;
  color: var(--ink) !important;
  background-image: none !important;
}

html[data-theme="dark"] body :where(.page-head, .review-hero, .command-strip, .workbench-head, .market-hero, .wallet-hero, .hero) {
  border-color: #2c5145;
  box-shadow: 0 18px 42px rgba(0, 0, 0, .26);
}

@media (prefers-reduced-motion: no-preference) {
  body, .panel, .card, .metric, input, select, textarea { transition: background-color .18s ease, border-color .18s ease, color .18s ease; }
}
