/* Black Security — complete theme layer. Keep light and dark palettes isolated. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090c14;
  --surface: #111622;
  --surface-2: #171e2d;
  --surface-3: #202a3d;
  --line: #293247;
  --line-strong: #3a4761;
  --text: #eef2fb;
  --muted: #a0abc1;
  --purple: #8b5cf6;
  --purple-2: #b5a0ff;
  --blue: #70aaff;
  --green: #38d9a9;
  --orange: #ffb454;
  --red: #ff718c;
  --cyan: #67d9ed;
  --shadow: 0 18px 48px rgba(0,0,0,.28);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --surface-3: #e5eaf3;
  --line: #dce3ee;
  --line-strong: #b9c5d7;
  --text: #182236;
  --muted: #596780;
  --purple: #6842c2;
  --purple-2: #5834ad;
  --blue: #2458b8;
  --green: #087a58;
  --orange: #9b520d;
  --red: #b42345;
  --cyan: #087b91;
  --shadow: 0 12px 32px rgba(28,43,70,.09);
}

/* Shared structure; every surface consumes the active theme tokens. */
html, body { background: var(--bg); color: var(--text); }
body:before { opacity: .75; }
.site-header, .topbar, .sidebar, .panel, .module-card, .stat-card,
.guild-card, .settings-panel, .preview-window, .preview-stats>div,
.preview-panel, .steps-grid article, .faq-grid details, .final-cta,
.search-box, .invite-banner, .server-current, .security-status,
.empty-state, .loading-card, .toast, .feature-card, .details-modal,
.setup-alert, .id-list li { color: var(--text); border-color: var(--line); }
.sidebar, .topbar, .panel, .module-card, .stat-card, .guild-card,
.settings-panel, .preview-window, .preview-panel, .steps-grid article,
.faq-grid details, .final-cta, .search-box, .invite-banner,
.server-current, .security-status, .empty-state, .loading-card,
.toast, .feature-card, .details-modal, .id-list li { background: var(--surface); }
.main-column, .main-content, .app-shell { background: var(--bg); color: var(--text); }
.field input, .field select, input:not([type="checkbox"]):not([type="radio"]),
select, textarea, .search-box input { background: var(--surface-2); color: var(--text); border-color: var(--line-strong); }
input::placeholder, textarea::placeholder, .search-box input::placeholder { color: var(--muted); opacity: 1; }
option { background: var(--surface); color: var(--text); }
.button.outline, .icon-button { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.button.ghost { background: color-mix(in srgb, var(--purple) 11%, var(--surface)); color: var(--purple-2); }
.button.primary { background: var(--purple); color: #fff; }
.button.primary:hover { background: color-mix(in srgb, var(--purple) 86%, white); }
.nav-item { color: var(--muted); }
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active, .nav-item[aria-current="page"] { color: var(--purple-2); background: color-mix(in srgb, var(--purple) 12%, var(--surface)); }
.data-table th { background: var(--surface-2); color: var(--muted); }
.data-table td, .health-row b, .health-row span, .field>span, .inline-check,
.module-title h3, .bucket-heading h3, .page-heading h1, .section-intro h2,
.panel-header h2, .stat-card b, .details-modal-head h2, .details-modal-body h3 { color: var(--text); }
.module-title p, .page-heading p, .panel-header p, .guild-id, .setting-row small,
.muted-text, .empty-state p, .details-modal-body p, .details-modal-body li,

.bar-track, .skeleton-line { background: var(--surface-3); }
.module-controls, .setting-row, .guild-card-bottom, .data-table td { border-color: var(--line); }
.details-modal-head, .details-modal-foot { border-color: var(--line); }
.details-modal-body h3 { color: var(--purple-2); }
.details-note { background: color-mix(in srgb, var(--purple) 7%, var(--surface)); border-color: color-mix(in srgb, var(--purple) 22%, var(--line)); }
.setup-alert { background: color-mix(in srgb, var(--orange) 8%, var(--surface)); }
.setup-alert b { color: var(--orange); }

/* Dark palette: deliberately dark surfaces and bright readable text only here. */
:root[data-theme="dark"] body:before { background: radial-gradient(ellipse at 75% 0,rgba(99,62,190,.14),transparent 46%), radial-gradient(ellipse at 0 80%,rgba(31,93,154,.09),transparent 38%); }
:root[data-theme="dark"] .preview-window { background: #0f1420; }
:root[data-theme="dark"] .preview-stats>div { background: #171e2c; }
:root[data-theme="dark"] .preview-title small, :root[data-theme="dark"] .preview-stats small,
:root[data-theme="dark"] .preview-stats em, :root[data-theme="dark"] .module-row small { color: #9aa7bd; }
:root[data-theme="dark"] .module-row { border-color: #ffffff10; }
:root[data-theme="dark"] .floating-note { background: #171d2c; color: var(--text); }
:root[data-theme="dark"] .steps-section { background: linear-gradient(180deg,#101522,#141a29,#101522); }
:root[data-theme="dark"] .feature-card { background: linear-gradient(145deg,#171d2b,#111622); }
:root[data-theme="dark"] .final-cta { background: radial-gradient(ellipse at 100% 0,#6544a41e,transparent 60%),#111622; }
:root[data-theme="dark"] .field input, :root[data-theme="dark"] .field select { background: #0d1320; color: #eef2fb; }
:root[data-theme="dark"] .data-table td { color: #d2daea; }
:root[data-theme="dark"] .details-modal { background: #111622; }
:root[data-theme="dark"] .details-modal-backdrop { background: rgba(3,5,10,.82); }

/* Light palette: no dark fixed surfaces or white foregrounds leak into the page. */
:root[data-theme="light"] body:before { background: radial-gradient(ellipse at 80% 0,rgba(116,87,202,.08),transparent 48%), radial-gradient(ellipse at 0 85%,rgba(48,117,180,.045),transparent 42%); opacity: 1; }
:root[data-theme="light"] .sidebar, :root[data-theme="light"] .topbar, :root[data-theme="light"] .site-header { background: rgba(255,255,255,.96); box-shadow: 0 8px 28px rgba(25,42,70,.045); }
:root[data-theme="light"] .preview-window { background: #fff; border-color: var(--line); box-shadow: 0 24px 70px rgba(28,43,70,.12); }
:root[data-theme="light"] .preview-top { color: #66738a; }
:root[data-theme="light"] .preview-side { border-color: var(--line); }
:root[data-theme="light"] .preview-stats>div { background: #f5f7fb; }
:root[data-theme="light"] .preview-title small, :root[data-theme="light"] .preview-stats small,
:root[data-theme="light"] .preview-stats em, :root[data-theme="light"] .module-row small { color: #65728a; }
:root[data-theme="light"] .preview-title h3, :root[data-theme="light"] .module-row b { color: #182236; }
:root[data-theme="light"] .module-row { border-color: #e8edf5; }
:root[data-theme="light"] .floating-note { background: #fff; color: var(--text); border-color: var(--line); }
:root[data-theme="light"] .steps-section { background: linear-gradient(180deg,#edf1f8,#f7f9fc,#edf1f8); }
:root[data-theme="light"] .feature-card { background: #fff; box-shadow: 0 7px 22px rgba(26,42,69,.035); }
:root[data-theme="light"] .final-cta { background: radial-gradient(ellipse at 100% 0,rgba(104,66,194,.07),transparent 60%),#fff; }
:root[data-theme="light"] .hero-trust { color: #596780; }
:root[data-theme="light"] .online-pill { color: var(--green); }
:root[data-theme="light"] .preview-status { background: #e8f8f1; border-color: #c3efdf; color: #087a58; }
:root[data-theme="light"] .mini-nav { color: #69758c; }
:root[data-theme="light"] .mini-nav.active { background: #eee8fc; color: #5834ad; }
:root[data-theme="light"] .toggle-off { background: #b7c1d1; }
:root[data-theme="light"] .toggle-on:after, :root[data-theme="light"] .toggle-off:after { background: #fff; }
:root[data-theme="light"] .field input, :root[data-theme="light"] .field select,
:root[data-theme="light"] input:not([type="checkbox"]):not([type="radio"]),
:root[data-theme="light"] select, :root[data-theme="light"] textarea,
:root[data-theme="light"] .search-box input { background: #f7f9fc; color: #182236; border-color: #c9d3e2; }
:root[data-theme="light"] .button.outline, :root[data-theme="light"] .icon-button { background: #fff; color: #26334a; border-color: #cbd5e3; }
:root[data-theme="light"] .button.ghost { background: #f0ebfc; color: #5834ad; }
:root[data-theme="light"] .button.primary { background: #6842c2; color: #fff; }
:root[data-theme="light"] .button.primary:hover { background: #5834ad; }
:root[data-theme="light"] .guild-state.state-missing { background: #fff5e7; color: #92500b; }
:root[data-theme="light"] .guild-state.state-present { background: #e8f8f1; color: #087a58; }
:root[data-theme="light"] .empty-state { background: #fff; }
:root[data-theme="light"] .loading-card { background: #fff; }
:root[data-theme="light"] .skeleton-line { background: linear-gradient(90deg,#edf1f7,#e1e7f1,#edf1f7); background-size: 200% 100%; }
:root[data-theme="light"] .details-modal-backdrop { background: rgba(22,32,51,.45); }
:root[data-theme="light"] .details-modal { background: #fff; box-shadow: 0 28px 90px rgba(20,32,54,.2); }
:root[data-theme="light"] .details-modal-body h3 { color: #5834ad; }
:root[data-theme="light"] .details-modal-body p, :root[data-theme="light"] .details-modal-body li { color: #45536b; }
:root[data-theme="light"] .log-event { background: #f0ebfc; color: #5834ad; }
:root[data-theme="light"] .module-symbol, :root[data-theme="light"] .empty-icon,
:root[data-theme="light"] .invite-symbol { background: #f0ebfc; color: #5834ad; }
:root[data-theme="light"] .switch span { background: #b9c4d5; }
:root[data-theme="light"] .switch input:checked+span { background: #6842c2; }
:root[data-theme="light"] .switch input:focus-visible+span { outline-color: #6842c2; }
:root[data-theme="light"] .sidebar-open::before { background: rgba(24,34,54,.25); }
:root[data-theme="light"] ::selection { background: #d8ccfa; color: #182236; }

/* Focus, hover and motion states remain visible and consistent in both palettes. */
.button:focus-visible, .nav-item:focus-visible, .icon-button:focus-visible,
.text-button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--purple-2); outline-offset: 2px; }
.module-card:hover, .guild-card:hover, .stat-card:hover { border-color: color-mix(in srgb, var(--purple) 42%, var(--line)); }
.field input:focus, .field select:focus, .search-box:focus-within { border-color: var(--purple); box-shadow: 0 0 0 3px color-mix(in srgb, var(--purple) 14%, transparent); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }

/* v2.3.17: Light-mode visibility recovery. Explicitly reset legacy dark-only surfaces. */
html[data-theme="light"] body,
html[data-theme="light"] .app-shell,
html[data-theme="light"] .main-column,
html[data-theme="light"] .main-content,
html[data-theme="light"] .dashboard-page,
html[data-theme="light"] .page-content {
  background-color: var(--bg) !important;
  color: var(--text) !important;
}
html[data-theme="light"] .sidebar,
html[data-theme="light"] .topbar,
html[data-theme="light"] .panel,
html[data-theme="light"] .module-card,
html[data-theme="light"] .stat-card,
html[data-theme="light"] .guild-card,
html[data-theme="light"] .settings-panel,
html[data-theme="light"] .server-current,
html[data-theme="light"] .security-status,
html[data-theme="light"] .empty-state,
html[data-theme="light"] .loading-card,
html[data-theme="light"] .toast,
html[data-theme="light"] .details-modal,
html[data-theme="light"] .module-controls,
html[data-theme="light"] .setting-row,
html[data-theme="light"] .log-row,
html[data-theme="light"] .log-item,
html[data-theme="light"] .overview-card,
html[data-theme="light"] .category-card {
  background-color: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}
html[data-theme="light"] .page-heading h1,
html[data-theme="light"] .page-heading h2,
html[data-theme="light"] .page-heading h3,
html[data-theme="light"] .section-intro h2,
html[data-theme="light"] .panel-header h2,
html[data-theme="light"] .panel-header h3,
html[data-theme="light"] .module-title h3,
html[data-theme="light"] .module-card h3,
html[data-theme="light"] .stat-card b,
html[data-theme="light"] .stat-card strong,
html[data-theme="light"] .setting-row label,
html[data-theme="light"] .setting-row b,
html[data-theme="light"] .field label,
html[data-theme="light"] .field > span,
html[data-theme="light"] .data-table td,
html[data-theme="light"] .data-table th,
html[data-theme="light"] .breadcrumb,
html[data-theme="light"] .breadcrumb strong,
html[data-theme="light"] .nav-item,
html[data-theme="light"] .topbar,
html[data-theme="light"] .topbar strong {
  color: var(--text) !important;
}
html[data-theme="light"] p,
html[data-theme="light"] small,
html[data-theme="light"] .muted-text,
html[data-theme="light"] .page-heading p,
html[data-theme="light"] .panel-header p,
html[data-theme="light"] .setting-row small,
html[data-theme="light"] .guild-id,
html[data-theme="light"] .empty-state p,
html[data-theme="light"] .data-table th,
html[data-theme="light"] .module-card .description {
  color: var(--muted) !important;
}
html[data-theme="light"] .data-table th,
html[data-theme="light"] .module-controls,
html[data-theme="light"] .module-card-foot,
html[data-theme="light"] .guild-card-bottom,
html[data-theme="light"] .table-toolbar,
html[data-theme="light"] .search-box {
  background-color: var(--surface-2) !important;
  border-color: var(--line) !important;
}
html[data-theme="light"] .button:not(.primary),
html[data-theme="light"] button.icon-button,
html[data-theme="light"] .text-button {
  color: var(--text);
}
html[data-theme="light"] .button.primary,
html[data-theme="light"] .button.primary * { color: #fff !important; }
html[data-theme="light"] .nav-item.active,
html[data-theme="light"] .nav-item[aria-current="page"] {
  color: var(--purple) !important;
  background-color: color-mix(in srgb, var(--purple) 10%, var(--surface)) !important;
}
html[data-theme="light"] .status-pill,
html[data-theme="light"] .badge,
html[data-theme="light"] .module-state { color: var(--text); }
html[data-theme="light"] .details-modal-backdrop { background: rgba(24,34,54,.42) !important; }
html[data-theme="light"] ::selection { background: #d8ccfa; color: #172033; }
