/* Shared dashboard/admin palette. Marketing keeps its existing appearance. */
html[data-fe-portal] {
  color-scheme: light;
  --muted: #465b71;
  --subtle: #586b80;
  --gray: #506278;
  --amber: #805415;
  --green: #14774c;
  --red: #bb3043;
}

/* Match ELEV8's sun/moon switch: a 32px track inside a 44px touch target. */
.header-actions .fe-theme-toggle {
  --theme-track: #edf1f6;
  --theme-line: #d4dde8;
  --theme-thumb: #fff;
  --theme-active: #334155;
  --theme-inactive: #64748b;
  position: relative;
  isolation: isolate;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  justify-items: center;
  flex: 0 0 72px;
  width: 72px;
  min-width: 72px;
  height: 44px;
  min-height: 44px;
  padding: 0 8px;
  gap: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--theme-inactive);
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
}
.fe-theme-toggle::before {
  content: "";
  position: absolute;
  inset: 6px 4px;
  z-index: -2;
  border: 1px solid var(--theme-line);
  border-radius: 999px;
  background: var(--theme-track);
  transition: border-color 160ms ease;
}
.fe-theme-toggle::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: -1;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--theme-thumb);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .14);
  transition: transform 180ms ease;
}
.fe-theme-toggle svg { display: block; width: 15px; height: 15px; pointer-events: none; }
.fe-theme-toggle .fe-theme-sun { color: var(--theme-active); }
.header-actions .fe-theme-toggle:hover { background: transparent; box-shadow: none; transform: none; }
.fe-theme-toggle:hover::before { border-color: #94a3b8; }
html[data-theme="dark"] .fe-theme-toggle {
  --theme-track: #101b2d;
  --theme-line: #334155;
  --theme-thumb: #2b3c53;
  --theme-active: #e0f2fe;
  --theme-inactive: #94a3b8;
}
html[data-theme="dark"] .fe-theme-toggle::after { transform: translateX(28px); box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
html[data-theme="dark"] .fe-theme-toggle .fe-theme-sun { color: var(--theme-inactive); }
html[data-theme="dark"] .fe-theme-toggle .fe-theme-moon { color: var(--theme-active); }
html[data-theme="dark"] .fe-theme-toggle:hover::before { border-color: #64748b; }
@media (prefers-reduced-motion: reduce) {
  .fe-theme-toggle::before, .fe-theme-toggle::after { transition: none; }
}
html[data-fe-portal] :focus-visible { outline: 3px solid #3579b8; outline-offset: 3px; }
html[data-fe-portal] th { color: #52667d; }
html[data-fe-portal] .account-modal-detail-label { color: var(--muted); }
html[data-fe-portal] .admin-performance-journal .performance-portal-form label { color: var(--muted); }
html[data-fe-portal] .public-chart-page .page-heading p { color: var(--muted); }
html[data-fe-portal] :is(.public-history small, .chart-editor p) { color: var(--muted); }
html[data-fe-portal] .lc-conn.idle { color: #526278; }
html[data-fe-portal] .lc-conn.warn { color: #805415; }
html[data-fe-portal] .lc-trade-px strong:not(.pos):not(.neg) { color: var(--lc-strong); }
html[data-fe-portal] :is(.fe-perf-panel-head em, .fe-perf-weekdays span, .fe-perf-caption) { color: var(--muted); }
html[data-fe-portal] .fe-perf-axis { fill: var(--muted); }
/* White lettering stays clear across the entire button, including gradient edges. */
html[data-fe-portal] :is(.account-enable-button, .dashboard-live-connect-button,
  .admin-docusign-send-button-signed, .admin-client-status-badge-approved),
html[data-fe-portal] .strategy-lane-controls .strategy-lane-toggle.account-enable-button,
html[data-fe-portal] #admin-clients-page .admin-client-upgrade-button {
  background: linear-gradient(135deg, #145337, #197047) !important;
  color: #fff !important;
}
html[data-fe-portal] :is(.button-danger, .account-disable-button, .dashboard-disconnect-button,
  .admin-client-delete-button, .admin-billing-delete-button, .admin-client-status-badge-cancelled),
html[data-fe-portal] .strategy-lane-controls .strategy-lane-toggle.account-disable-button {
  background: linear-gradient(135deg, #781b2b, #aa2c43) !important;
  background-image: linear-gradient(135deg, #781b2b, #aa2c43) !important;
  color: #fff !important;
}
html[data-fe-portal] .admin-client-status-badge-past-due { background: #805415; color: #fff !important; }
html[data-fe-portal] .table-actions :is(.admin-billing-open-modal-sent, .admin-billing-open-modal-awaiting-signature) {
  background: #475569 !important;
  color: #fff !important;
}

html[data-fe-portal][data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1422;
  --bg-strong: #101d2e;
  --surface: #142338;
  --surface-soft: #192b42;
  --surface-muted: #20344d;
  --ink: #f0f5fc;
  --text: #dce7f4;
  --muted: #b0c1d5;
  --subtle: #a7bad1;
  --line: #334961;
  --line-strong: #58728e;
  --steel: #a0d2ff;
  --blue: #7cbcff;
  --blue-soft: #1c3854;
  --green: #70e0a5;
  --green-soft: #153e32;
  --red: #ff9eaa;
  --red-soft: #482632;
  --amber: #f8d08b;
  --amber-soft: #45351e;
  --gray: #bfccdc;
  --gray-soft: #2a3a50;
  --shadow-sm: 0 8px 20px rgba(0, 0, 0, .16);
  --shadow: 0 18px 50px rgba(0, 0, 0, .22);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, .3);
}

html[data-theme="dark"] body {
  background: radial-gradient(ellipse at 10% 0%, #172e48 0, transparent 42rem), var(--bg);
  color: var(--text);
}
html[data-theme="dark"] .site-header {
  background: rgba(11, 20, 34, .96);
  border-color: var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset;
}
/* Theme-specific originals retain their transparency and brand colors. */
.brand-logo-dark { display: none; }
html[data-theme="dark"] .brand-logo-light { display: none; }
html[data-theme="dark"] .brand-logo-dark { display: block; }
html[data-theme="dark"] .main-nav a { color: var(--muted); }
html[data-theme="dark"] .main-nav a:is(:hover, .active) {
  color: var(--steel);
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
html[data-theme="dark"] .footer {
  background: var(--bg-strong);
  border-color: var(--line);
}
html[data-theme="dark"] .footer-bottom { border-color: var(--line); }
html[data-theme="dark"] .footer-links a:hover { color: var(--steel); }

/* Primary surfaces, nested data panels, dialogs and sticky table controls. */
html[data-theme="dark"] :is(
  .card, .table-card, .form-card, .metric-card, .chart-card, .panel-card,
  .faq-item, .faq-accordion, .modal-card, .journey-card, .chart-editor,
  .public-history, .process-sidebar, .risk-sidebar, .reporting-sidebar,
  .billing-plan-choice, .admin-account-group, .admin-account-group-summary-shell,
  .admin-account-group-metric, .admin-account-group-body, .admin-application-details,
  .admin-application-detail-pair, .admin-application-notes, .admin-message-meta-card,
  .admin-message-modal-message-card, .admin-message-reply-card, .account-modal-detail-grid,
  .auto-scaling-option, .performance-source-panel, .backtest-card, .backtest-metric,
  .backtest-chart-shell, .performance-auto-scaling-box, .hypothetical-results-modal-panel
) {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}
html[data-theme="dark"] :is(.panel-card, .performance-source-panel)::before {
  background: radial-gradient(ellipse at top right, rgba(124, 188, 255, .08), transparent 60%);
}
html[data-theme="dark"] :is(
  th, .admin-table-scroll-vertical thead th, .admin-table-card-header,
  .admin-table-scroll-sync, .admin-table-scroll-floating, .admin-table-pagination,
  .account-login-group-header, .admin-message-full-text, .performance-rule-modal-detail,
  .account-modal-detail-label, .admin-client-form label, .journey-checklist li,
  .journey-demo, .journey-note, .backtest-metric.primary, .performance-contract-toggle,
  .performance-calendar-cell.empty, .performance-calendar-cell.calendar-outside
) {
  background: var(--surface-soft);
  border-color: var(--line);
  color: var(--muted);
}
html[data-theme="dark"] :is(td, th, .journey-table td, .journey-table th) { border-color: var(--line); }
html[data-theme="dark"] tbody tr:hover td,
html[data-theme="dark"] .admin-application-details-row td { background: var(--surface-soft); }
html[data-theme="dark"] .empty-state {
  background: var(--surface-soft);
  border-color: var(--line-strong);
  color: var(--muted);
}
html[data-theme="dark"] :is(.banner, .account-disabled-note, .account-sizing-notice) {
  background: var(--blue-soft);
  color: var(--text);
  border-color: var(--blue);
}
html[data-theme="dark"] :is(.eyebrow, .pill, .trust-pill, .fe-status-chip,
  .account-auto-scaling-pill, .admin-account-group-meta-chip, .backtest-period-pill,
  .journey-offer, .admin-account-group-toggle) {
  background: var(--blue-soft);
  border-color: var(--line);
  color: var(--steel);
}
html[data-theme="dark"] :is(code, .admin-json-block) { background: #0c1a2b; color: #c5e3ff; }
html[data-theme="dark"] .journey-card :is(p, li) { color: var(--muted); }
html[data-theme="dark"] .account-reconnect-dismiss button { color: var(--red); }
html[data-theme="dark"] .admin-message-error { color: var(--red); }
html[data-theme="dark"] .chart-editor p,
html[data-theme="dark"] .public-history small { color: var(--muted); }
html[data-theme="dark"] .chart-editor-option { border-color: var(--line); }
html[data-theme="dark"] :is(h1, h2, h3, h4, label) { color: var(--ink); }
html[data-theme="dark"] .admin-application-details summary { color: var(--ink); }
html[data-theme="dark"] .billing-plan-choice .billing-upgrade-price { color: var(--ink); }
html[data-theme="dark"] :is(.billing-current-line, .billing-plan-choice p) { color: var(--muted); }
html[data-theme="dark"] :is(.secondary-strategy-lane, .strategy-lane-controls, .broker-choice-card) {
  background: var(--surface-soft) !important;
  border-color: var(--line-strong) !important;
}
html[data-theme="dark"] .strategy-lane-conflict { background: var(--red-soft) !important; border-color: var(--red) !important; }

/* Form fields keep readable native menus, date pickers, placeholders and focus states. */
html[data-theme="dark"] :is(input, select, textarea):not(.lc-shell *):not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]) {
  background: #0e1c2e;
  color: var(--ink);
  border-color: var(--line-strong);
  color-scheme: dark;
}
html[data-theme="dark"] :is(select option, select optgroup):not(.lc-shell *) { background: #0e1c2e; color: var(--ink); }
html[data-theme="dark"] :is(input, textarea)::placeholder { color: #9aacbf; opacity: 1; }
html[data-theme="dark"] :is(input, select, textarea):focus:not(.lc-shell *) { border-color: var(--blue); }
html[data-theme="dark"] :is(input, select, textarea):disabled:not(.lc-shell *) {
  background: var(--surface-muted);
  color: var(--muted);
  opacity: 1;
}
html[data-theme="dark"] .auto-scaling-option:has(input:checked) { background: #302940; border-color: #c99aea; }
html[data-theme="dark"] :is(.admin-toggle-field, .performance-toggle-field) { background: var(--surface-soft) !important; border-color: var(--line); }
html[data-theme="dark"] :is(.admin-toggle-switch-input, .performance-toggle-switch-input):not(:checked) { background: #3f5672; }
html[data-theme="dark"] :focus-visible { outline-color: var(--blue); }

/* Buttons use dedicated foreground/background pairs, independent of heading colors. */
html[data-theme="dark"] :is(.button-secondary, .mobile-nav-toggle,
  .performance-portal-form button, .performance-export-button, .journey-tabs button) {
  background: var(--surface-muted);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
html[data-theme="dark"] :is(.button-secondary, .mobile-nav-toggle):hover { background: #2b4664; color: #fff; }
html[data-theme="dark"] :is(.button-primary, input[type="submit"]) { background: #225b8c; color: #fff; }
html[data-theme="dark"] :is(.dashboard-sync-button, .account-action-buttons .account-auto-scaling-button) {
  background: #203f5d !important;
  color: #c6e5ff !important;
  border-color: #587fa3 !important;
}
html[data-theme="dark"] .strategy-lane-controls .strategy-lane-scaling.is-on {
  background: #203f5d !important;
  color: #c6e5ff !important;
  border-color: #587fa3 !important;
}
html[data-theme="dark"] .account-sizing-toggle { background: var(--surface-muted); color: var(--ink); border-color: var(--line-strong); }
html[data-theme="dark"] .account-sizing-toggle[aria-pressed="true"] { background: #225b8c; color: #fff; }
html[data-theme="dark"] :is(.account-action-buttons .account-auto-scaling-button, .strategy-lane-controls .strategy-lane-scaling):disabled,
html[data-theme="dark"] .account-action-buttons .account-auto-scaling-locked {
  background: var(--surface-muted) !important;
  color: var(--muted) !important;
}
html[data-theme="dark"] .account-name-edit-button { color: var(--muted) !important; }
html[data-theme="dark"] .account-name-edit-button:hover { color: var(--steel) !important; }
html[data-theme="dark"] .performance-contract-toggle-button:not(.is-active) {
  background: var(--surface) !important;
  color: var(--muted) !important;
  border-color: var(--line) !important;
}
html[data-theme="dark"] .performance-contract-toggle-button.is-active,
html[data-theme="dark"] .journey-tabs button[aria-pressed="true"] { background: #225b8c !important; color: #fff !important; }
html[data-theme="dark"] .hypothetical-results-modal-footer button { background: #225b8c; color: #fff; }
html[data-theme="dark"] .modal-overlay { background: rgba(2, 7, 15, .8); }

/* Status and P&L colors are paired with their own tinted surfaces. */
html[data-theme="dark"] :is(.calendar-cell, .admin-account-group-metric-neutral) { background: var(--surface-soft); border-color: var(--line); }
html[data-theme="dark"] :is(.calendar-cell.positive, .admin-account-group-metric-positive) { background: var(--green-soft); }
html[data-theme="dark"] :is(.calendar-cell.negative, .admin-account-group-metric-negative) { background: var(--red-soft); }
html[data-theme="dark"] .calendar-cell.neutral { background: var(--blue-soft); }
html[data-theme="dark"] .admin-account-group-metric-positive :is(strong, .admin-account-group-metric-label) { color: var(--green); }
html[data-theme="dark"] .admin-account-group-metric-negative :is(strong, .admin-account-group-metric-label) { color: var(--red); }
/* This page has ID-scoped styles, including important metric colors. Match that
   scope so populated and expanded client workspaces use the portal palette. */
html[data-theme="dark"] #admin-accounts-page :is(.admin-account-group, .admin-account-group-summary-shell) {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}
html[data-theme="dark"] #admin-accounts-page .admin-account-group-summary-shell { background: var(--surface-soft); }
html[data-theme="dark"] #admin-accounts-page .admin-account-group-toggle {
  background: var(--surface-muted);
  border-color: var(--line-strong);
  box-shadow: none;
}
html[data-theme="dark"] #admin-accounts-page .admin-account-group-toggle::before,
html[data-theme="dark"] #admin-accounts-page .admin-account-group-toggle::after { background: var(--ink); }
html[data-theme="dark"] #admin-accounts-page .admin-account-group-metric {
  background: var(--surface) !important;
  border-color: var(--line) !important;
  box-shadow: none !important;
}
html[data-theme="dark"] #admin-accounts-page .admin-account-group-metric strong { color: var(--ink) !important; }
html[data-theme="dark"] #admin-accounts-page .admin-account-group-metric-neutral { background: var(--blue-soft) !important; }
html[data-theme="dark"] #admin-accounts-page .admin-account-group-metric-positive {
  background: var(--green-soft) !important;
  border-color: #2f6b4e !important;
}
html[data-theme="dark"] #admin-accounts-page .admin-account-group-metric-positive :is(strong, .admin-account-group-metric-label) { color: var(--green) !important; }
html[data-theme="dark"] #admin-accounts-page .admin-account-group-metric-negative {
  background: var(--red-soft) !important;
  border-color: #87505c !important;
}
html[data-theme="dark"] #admin-accounts-page .admin-account-group-metric-negative :is(strong, .admin-account-group-metric-label) { color: var(--red) !important; }
html[data-theme="dark"] #admin-accounts-page .admin-emergency-close-results-summary {
  background: var(--surface-soft);
  border-color: var(--line);
}

/* The equity/calendar illustration uses the same dark surfaces as real charts. */
html[data-theme="dark"] .fe-perf-track {
  background: radial-gradient(circle at 8% 0%, rgba(112, 224, 165, .07), transparent 16rem), var(--surface-soft);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}
html[data-theme="dark"] .fe-perf-panel { background: var(--surface); border-color: var(--line); }
html[data-theme="dark"] .fe-perf-panel-head span { color: var(--ink); }
html[data-theme="dark"] :is(.fe-perf-panel-head em, .fe-perf-weekdays span, .fe-perf-caption) { color: var(--muted); }
html[data-theme="dark"] .fe-perf-axis { fill: var(--muted); }
html[data-theme="dark"] .fe-perf-grid { stroke: var(--line); }
html[data-theme="dark"] .fe-perf-line { stroke: var(--green); }
html[data-theme="dark"] .fe-perf-track stop { stop-color: var(--green); }
html[data-theme="dark"] .fe-perf-dot-core { fill: var(--green); stroke: var(--surface); }
html[data-theme="dark"] .fe-perf-dot-glow { fill: rgba(112, 224, 165, .22); }
html[data-theme="dark"] .fe-perf-day { background: var(--surface-muted); }
html[data-theme="dark"] .fe-perf-day.is-up { background: linear-gradient(180deg, #225b45, #3ca476); }
html[data-theme="dark"] .fe-perf-day.is-down { background: linear-gradient(180deg, #4c2a35, #af5464); }
html[data-theme="dark"] .calendar-outside :is(.performance-calendar-day, .helper-text) { opacity: 1; color: var(--subtle); }
html[data-theme="dark"] .performance-calendar-cell.calendar-today { box-shadow: inset 0 0 0 2px var(--blue); }
html[data-theme="dark"] .live-safety-toast { background: #45351e; border-color: var(--amber); color: #ffe5b4; }
html[data-theme="dark"] .live-safety-toast :is(strong, p, a) { color: #ffe5b4; }
html[data-theme="dark"] .hypothetical-results-notice { background: var(--surface-soft); border-color: var(--line); }
html[data-theme="dark"] .backtest-grid-line { stroke: var(--line); }
html[data-theme="dark"] .backtest-axis-line { stroke: var(--line-strong); }
html[data-theme="dark"] :is(.backtest-y-label, .backtest-x-label) { fill: var(--muted); }
html[data-theme="dark"] .backtest-end-label text { fill: #0b2419; }
html[data-theme="dark"] .lc-history { background: var(--surface); }
html[data-theme="dark"] .lc-history-badge { color: #c7a5ff; }
html[data-theme="dark"] .lc-history[data-state="caught_up"] .lc-history-badge { color: var(--green); }
html[data-theme="dark"] .lc-history[data-state="error"] .lc-history-badge { color: var(--red); }
html[data-theme="dark"] :is(.lc-history-auto, .lc-parity-head, .lc-parity-foot) { color: var(--muted); }
html[data-theme="dark"] .lc-parity-foot strong { color: var(--ink); }
html[data-fe-portal] .lc-shell :is(.lc-primary, .lc-segment button.active) { background: #235ea8; color: #fff; }

/* Existing navy account panels stay navy in both themes. */
html[data-fe-portal] .portal-panel :is(.button-secondary, .performance-export-button, .performance-portal-form button) {
  background: #e8f2fb;
  color: #113a63;
  border-color: #8daac4;
}
html[data-fe-portal] .portal-panel .button-secondary span { color: inherit; }
html[data-theme="dark"] .portal-panel :is(.button-secondary, .performance-export-button, .performance-portal-form button) {
  background: #203f5d;
  color: #e5f2ff;
  border-color: #587fa3;
}
html[data-theme="dark"] .portal-panel :is(select, input, textarea) { color-scheme: dark; }

@media (max-width: 720px) {
  html[data-theme="dark"] .main-nav { background: var(--surface); border-color: var(--line); }
}
