/* Keep these five member views in the existing dark CGB palette when the shell
   uses Light or Beige. The public /partners and Pricing pages are excluded. */
html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) #app #main:has(> :is(.risk-page, .cgbx-partner-page, .market-dashboard, .autotrade-hub, .jh-root)),
html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) #app > .cgbx-partner-page,
html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) #modal-root .hub-modal,
html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) body > .jh-popup-layer .jh-popup {
  --bg: #03101e;
  --panel: #06172a;
  --panel-2: #09131f;
  --border: rgba(56, 189, 248, .18);
  --border-strong: rgba(70, 244, 255, .42);
  --text: #f8fafc;
  --muted: #a9c8d9;
  --cyan: #38bdf8;
  --cyan-2: #46f4ff;
  --theme-page: #03101e;
  --theme-surface: #06172a;
  --theme-surface-alt: #09131f;
  --theme-ink: #f8fafc;
  --theme-muted: #a9c8d9;
  --theme-line: rgba(56, 189, 248, .18);
  --theme-blue: #38bdf8;
  --theme-blue-soft: #38bdf817;
  --theme-action: #38bdf8;
  --theme-shadow: none;
  color-scheme: dark;
  color: var(--theme-ink);
}

html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) #app #main:has(> :is(.risk-page, .cgbx-partner-page, .market-dashboard, .autotrade-hub, .jh-root)),
html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) #app > .cgbx-partner-page {
  background: var(--theme-page);
}

html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]):has(#app > .cgbx-partner-page) body,
html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) #app:has(> .cgbx-partner-page) {
  background: #03101e;
}

/* The shared Light/Beige button rule otherwise places pale text on cyan. */
#app #main:has(> :is(.risk-page, .cgbx-partner-page, .market-dashboard, .jh-root)) :is(.btn.primary, .info-button.primary, .jh-open),
#app > .cgbx-partner-page .btn.primary {
  color: #001016;
  background: var(--theme-action, #38bdf8);
  border-color: var(--cyan, #38bdf8);
}

#app #main > .risk-page .info-button:not(.primary),
#app #main > .jh-root .jh-full {
  color: #f8fafc;
  background: #09131f;
  border-color: rgba(56, 189, 248, .18);
}

#app #main:has(> :is(.risk-page, .cgbx-partner-page, .market-dashboard, .autotrade-hub, .jh-root)) :is(input, select, textarea),
#app > .cgbx-partner-page :is(input, select, textarea),
#modal-root .hub-modal :is(input, select, textarea),
body > .jh-popup-layer .jh-popup :is(input, select, textarea) {
  color-scheme: dark;
  color: #f8fafc;
  background-color: #06172a;
  border-color: rgba(56, 189, 248, .42);
}

#app #main:has(> :is(.risk-page, .cgbx-partner-page, .market-dashboard, .autotrade-hub, .jh-root)) :is(input, textarea)::placeholder,
#app > .cgbx-partner-page :is(input, textarea)::placeholder,
body > .jh-popup-layer .jh-popup :is(input, textarea)::placeholder {
  color: #a9c8d9;
}

#app #main:has(> :is(.risk-page, .cgbx-partner-page, .market-dashboard, .autotrade-hub, .jh-root)) :focus-visible,
#app > .cgbx-partner-page :focus-visible,
#modal-root .hub-modal :focus-visible,
body > .jh-popup-layer .jh-popup :focus-visible {
  outline: 2px solid #46f4ff;
  outline-offset: 2px;
}

#app #main:has(> :is(.risk-page, .cgbx-partner-page, .market-dashboard, .autotrade-hub, .jh-root)) button:disabled,
#app > .cgbx-partner-page button:disabled,
#modal-root .hub-modal button:disabled,
body > .jh-popup-layer .jh-popup button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

/* Risk copy and market metadata retain their hierarchy on dark panels. */
#app #main > .risk-page :is(.risk-meter small, .risk-scale, .volatility-grid span, .volatility-grid p, .info-section-head p),
#app #main > .market-dashboard .market-dashboard-meta span {
  color: #a9c8d9;
}

#app #main > .risk-page :is(.market-truth h2, .info-section-head h2, .risk-principles h3),
#app #main > .market-dashboard :is(h1, .market-summary-card h2) {
  color: #f8fafc;
}

/* Table surfaces are confined to All Trade Journals and the CGBX program. */
#app #main > .jh-root .jh-table th,
body > .jh-popup-layer .jh-popup .jh-table th,
#app .cgbx-partner-page .data-table th {
  color: #f8fafc;
  background: #0b2b47;
}

#app #main > .jh-root .jh-table tbody tr:nth-child(odd) td,
body > .jh-popup-layer .jh-popup .jh-table tbody tr:nth-child(odd) td,
#app .cgbx-partner-page .data-table tbody tr:nth-child(odd) td {
  background: #071b2d;
}

#app #main > .jh-root .jh-table tbody tr:nth-child(even) td,
body > .jh-popup-layer .jh-popup .jh-table tbody tr:nth-child(even) td,
#app .cgbx-partner-page .data-table tbody tr:nth-child(even) td {
  background: #0a2037;
}

#app #main > .jh-root .jh-table td,
body > .jh-popup-layer .jh-popup .jh-table td,
#app .cgbx-partner-page .data-table td {
  color: #dcecff;
}

html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) #app #main > .jh-root .jh-side.long {
  color: #57f4bf;
}

html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) #app #main > .jh-root .jh-side.short {
  color: #ffb1bd;
}

#app #main > .jh-root .jh-table-wrap,
body > .jh-popup-layer .jh-popup .jh-table-wrap,
#app .cgbx-partner-page .table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

/* Preserve the existing mobile dialog scroll and make its controls readable. */
html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) #modal-root .hub-modal,
html:is([data-cgb-theme="light"], [data-cgb-theme="beige"]) body > .jh-popup-layer .jh-popup {
  background: var(--theme-surface);
  border-color: var(--theme-line);
  color: var(--theme-ink);
}

#modal-root .hub-modal .hub-modal-scroll,
body > .jh-popup-layer .jh-popup .jh-popup-body {
  scrollbar-color: #287ba1 #061321;
  scrollbar-width: thin;
}

@media (max-width: 600px) {
  #modal-root .hub-modal,
  body > .jh-popup-layer .jh-popup {
    max-height: 100dvh;
  }
}
