.theme-toggle:not([hidden]) {
    display: inline-grid;
    flex: 0 0 auto;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel-alt);
    color: var(--muted-strong);
    box-shadow: none;
}

.theme-toggle:not([hidden]):hover {
    background: var(--brand-soft);
    color: var(--brand);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.theme-toggle svg { width: 17px; height: 17px; }
@media (max-width: 480px) {
    .topbar-right:has(.theme-toggle:not([hidden])) {
        grid-template-columns: minmax(62px, 1fr) minmax(62px, 1fr) 32px 30px minmax(58px, .9fr);
    }
    .topbar-right .theme-toggle:not([hidden]) {
        width: 30px;
        height: 30px;
    }
}
.theme-toggle .theme-sun,
[data-theme="dark"] .theme-toggle .theme-moon { display: none; }
[data-theme="dark"] .theme-toggle .theme-sun { display: block; }
[data-theme="dark"] .theme-toggle:not([hidden]):hover {
    background: var(--brand-soft);
    color: var(--brand);
}

.auth-theme-switch {
    position: absolute;
    inset-block-start: 12px;
    inset-inline-end: 12px;
    z-index: 2;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #101522;
    --shell: #111827;
    --sidebar: #151d2c;
    --panel: #1a2435;
    --panel-alt: #202c40;
    --text: #e9eef7;
    --muted-strong: #c4d0e3;
    --muted: #a7b6cd;
    --muted-soft: #8b9cb7;
    --line: #354359;
    --gray-100: #263349;
    --brand: #8bb5ff;
    --brand-dark: #2452c2;
    --brand-soft: #24395e;
    --primary: var(--brand);
    --ok: #18874d;
    --ok-soft: #163e30;
    --ok-strong: #92e7b2;
    --danger: #b93449;
    --warn: #f0b862;
    --warn-soft: #433321;
    --warn-strong: #ffd39a;
    --status-muted-soft: #2a3548;
    --status-muted-strong: #c4d0e3;
    --shadow: 0 8px 30px #0003;
    --shadow-hover: 0 12px 40px #0005;
    --theme-action: #2856c8;
    --ink: var(--text);
    --blue: var(--theme-action);
    --blue-dark: var(--brand);
    --danger-soft: #422733;
    --danger-text: #ffadb9;
}

[data-theme="dark"] body { background: var(--bg); }
[data-theme="dark"] body::before { opacity: .2; }

[data-theme="dark"] :is(.dashboard-shell, .dashboard-main, .content-wrap) {
    background: var(--shell);
    color: var(--text);
}

[data-theme="dark"] :is(.sidebar, .topbar, .brand-block, .main-footer) {
    background: var(--sidebar);
    border-color: var(--line);
    color: var(--text);
}

[data-theme="dark"] :is(.topbar-title, .brand-title, .brand-full, .brand-short, .modal-title, .auth-modern-logo) { color: var(--text); }
[data-theme="dark"] :is(.brand-description, .brand-subtitle, .menu-link, .menu-toggle, .mobile-menu-btn, .footer-section p, .footer-links a) { color: var(--muted-strong); }
[data-theme="dark"] :is(.menu-link:hover, .menu-link.active, .mobile-menu-btn:hover) {
    background: var(--brand-soft);
    color: var(--brand);
}

[data-theme="dark"] :is(
    .page-head, .panel, .ui-card, .project-card, .stat-card, .cascade-stat-card,
    .dashboard-project-mobile-card, .dashboard-projects-shell-card, .upload-form,
    .keys-section, .filter-section, .no-keys, .no-projects, .auth-card,
    .modal-panel, .wallet-modal, .notif-dropdown, .user-menu-dropdown, .rank-column-picker-menu,
    .auth-modern-info, .auth-modern-form, .rank-project-table
) {
    background: var(--panel);
    border-color: var(--line);
    color: var(--text);
}

[data-theme="dark"] :is(.dashboard-hero, .auth-modern-info) {
    background: linear-gradient(120deg, var(--panel) 30%, #223653);
    border-color: var(--line);
    color: var(--text);
}

[data-theme="dark"] :is(.dashboard-stats-shell, .panel-alt, .auth-modern-feature, .notif-item-unread) {
    background: var(--panel-alt);
    border-color: var(--line);
    color: var(--text);
}

[data-theme="dark"] .dashboard-stat-card::after {
    border-color: var(--line);
    opacity: .3;
}
[data-theme="dark"] :is(.dashboard-hero-title, .dashboard-project-table-project-name, .dashboard-project-mobile-title, .auth-modern-form h2, .auth-modern-info h1, .notif-title) { color: var(--text); }
[data-theme="dark"] :is(.dashboard-hero-text, .dashboard-project-table-project-group, .dashboard-project-mobile-group, .dashboard-projects-head-meta, .dashboard-projects-head-copy p, .auth-modern-info p, .auth-modern-sub, .auth-modern-form label, .notif-msg, .notif-meta, .notif-empty) { color: var(--muted); }
[data-theme="dark"] :is(.footer-section h4, .auth-links a, .auth-modern-info h1 span) { color: var(--brand); }

[data-theme="dark"] :is(.dashboard-stat-badge, .dashboard-stat-icon, .dashboard-hero-eyebrow, .dashboard-project-table-metric-plan, .dashboard-project-mobile-metric-plan, .auth-modern-badge) {
    background: var(--brand-soft);
    color: var(--brand);
    border-color: var(--line);
}

[data-theme="dark"] :is(.dashboard-project-table-metric-today, .dashboard-project-mobile-metric-today, .dashboard-stat-card-today .dashboard-stat-badge, .dashboard-stat-card-today .dashboard-stat-icon) {
    background: var(--warn-soft);
    color: var(--warn-strong);
    border-color: var(--line);
}

[data-theme="dark"] :is(.dashboard-project-table-metric, .dashboard-project-mobile-metric) :is(span, strong) { color: inherit; }
[data-theme="dark"] :is(.dashboard-client-alert, .dashboard-client-alert-kpi, .dashboard-client-alert-row) {
    background: var(--warn-soft);
    border-color: #635035;
}
[data-theme="dark"] :is(.dashboard-client-alert-eyebrow, .dashboard-client-alert-title, .dashboard-client-alert-text, .dashboard-client-alert-project, .dashboard-client-alert-domain, .dashboard-client-alert-kpi strong, .dashboard-client-alert-kpi span, .dashboard-client-alert-meta strong, .dashboard-client-alert-meta span) { color: var(--warn-strong); }

[data-theme="dark"] :is(.wallet-pill, .user-pill, .notif-btn, .modal-close, .mobile-menu-btn, .user-menu-dropdown a) {
    background: var(--panel-alt);
    color: var(--muted-strong);
    border-color: var(--line);
}
[data-theme="dark"] :is(.wallet-pill:hover, .user-pill:hover, .notif-btn:hover, .modal-close:hover, .user-menu-dropdown a:hover) {
    background: var(--brand-soft);
    color: var(--brand);
}

[data-theme="dark"] :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea) {
    background: var(--bg);
    border-color: var(--line);
    color: var(--text);
}
[data-theme="dark"] :is(input, textarea)::placeholder { color: var(--muted-soft); }
[data-theme="dark"] :is(input, select, textarea):focus { border-color: var(--brand); }
[data-theme="dark"] :is(input[type="checkbox"], input[type="radio"]) { accent-color: var(--theme-action); }

[data-theme="dark"] :is(.btn-primary, .submit-btn, .auth-button, .view-keys-btn) {
    background: var(--theme-action);
    color: #fff;
    border-color: #4874da;
}
[data-theme="dark"] :is(.btn-primary, .submit-btn, .auth-button, .view-keys-btn):hover { background: var(--brand-dark); }
[data-theme="dark"] :is(.btn-secondary, .back-btn) {
    background: var(--brand-soft);
    color: var(--brand);
    border-color: var(--line);
}

[data-theme="dark"] table { background: var(--panel); color: var(--text); }
[data-theme="dark"] table th { background: var(--panel-alt); color: var(--muted-strong); border-color: var(--line); }
[data-theme="dark"] table td { border-color: var(--line); }
[data-theme="dark"] table tbody tr:hover { background: var(--panel-alt); }

[data-theme="dark"] :is(.status-active, .status-badge.status-active, .clicks-status-badge.is-ok) {
    background: var(--ok-soft);
    color: var(--ok-strong);
}
[data-theme="dark"] :is(.status-stopped, .status-badge.status-stopped, .clicks-status-badge.is-muted) {
    background: var(--status-muted-soft);
    color: var(--status-muted-strong);
}

[data-theme="dark"] :is(.click-purchase-tabs, .click-purchase-summary, .click-package-card) {
    background: var(--panel-alt);
    border-color: var(--line);
}
[data-theme="dark"] :is(.click-purchase-tabs button[aria-selected="true"], .click-package-card:has(input:checked)) {
    background: var(--brand-soft);
    color: var(--brand);
    border-color: var(--brand);
}
[data-theme="dark"] :is(.click-package-main, .click-purchase-summary strong) { color: var(--text); }
[data-theme="dark"] :is(.click-purchase-intro, .click-purchase-hint, .click-purchase-tabs button, .click-package-rate, .click-package-base, .click-purchase-summary small) { color: var(--muted); }
[data-theme="dark"] .click-package-saving { color: var(--ok-strong); }
[data-theme="dark"] .click-purchase-message { color: var(--warn-strong); }

[data-theme="dark"] :is(.tickets-badge, .tickets-notice) {
    background: var(--panel-alt);
    border-color: var(--line);
    color: var(--muted-strong);
}
[data-theme="dark"] .tickets-team { background: var(--ok-soft); color: var(--ok-strong); }
[data-theme="dark"] :is(.tickets-filters label, .tickets-meta, .tickets-hint) { color: var(--muted); }
[data-theme="dark"] :is(.tickets-choices label, .tickets-comment, .tickets-screenshot) { border-color: var(--line); }
[data-theme="dark"] .tickets-choices label:has(input:checked) {
    border-color: var(--brand);
    background: var(--brand-soft);
    color: var(--brand);
}
[data-theme="dark"] .tickets-tabs [aria-current="page"] {
    background: var(--theme-action);
    color: #fff;
}

[data-theme="dark"] :is(.clicks-filters-grid, .clicks-table-wrap, .queue-kpi-section) {
    background: var(--panel);
    border-color: var(--line);
    color: var(--text);
}

/* Page-specific surfaces. Keep this scoped: light mode and chart series retain their colours. */
[data-theme="dark"] :is(
    .stats-section, .cascade-stats-section, .project-controls, .form-section, .api-links-content,
    .project-menu-dropdown, .infinite-toggle, .work-status-toggle, .user-mode-chip,
    .keys-hero-stat, .columns-popover, .region-dropdown, .region-item,
    .service-card, .services-footer, .payments-mobile-card, .payments-topup, .payment-method-card,
    .welcome-card, .about-card, .chart-wrap, .queue-kpi-card, .queue-forecast-box,
    .queue-results-panel .table-container, .queue-day-panel .table-container, .queue-profiles-panel .table-container,
    .rank-project-card, .rank-actions-menu, .rank-actions-menu a, .rank-actions-menu button,
    .rank-region-summary-table, .rank-pricing-table, .rank-pricing-custom-item,
    .rank-date-range-menu, .rank-toolbar-menu, .rank-settings-panel, .rank-relevance-dialog,
    .rank-guest-url-dialog, .rank-donut-tooltip, .rank-distribution-tooltip, .rank-line-chart-tooltip,
    .rank-distribution-donut > div, .rank-position-matrix-wrap, .rank-region-suggestions,
    .rank-search-target-row, .rank-tool-settings, .rank-project-competitor-editor,
    .rank-keyword-create-popover form, .rank-keyword-add-popover form,
    .webmaster-dash-card, .webmaster-summary-card, .webmaster-status-pill, .webmaster-summary-chip,
    .webmaster-matrix-wrap, .wm-export-menu, .webmaster-query-filter-popover, .webmaster-calendar-popover,
    .documentation-card, .documentation-result, .wm-settings-card, .wm-region-popover,
    .wm-site-picker .wm-site-option, .wm-linked-project, .wm-history-added-now li,
    .api-delivery-server-card, .api-delivery-copy-history, .api-delivery-primary-card,
    .api-delivery-chart-wrap, .api-delivery-table, .notif-item,
    .dashboard-projects-skeleton-card, .dashboard-projects-skeleton-table
) {
    background: var(--panel);
    border-color: var(--line);
    color: var(--text);
}

[data-theme="dark"] :is(
    .project-schedule-summary > div, .project-schedule-hourly, .project-schedule-grid,
    .project-auto-boost-grid, .project-auto-boost-cell, .project-hard-delete-message,
    .service-feature, .payments-mobile-grid div, .clicks-summary-icon,
    .queue-filters-grid, .queue-kpi-note, .queue-meta-compact-note,
    .rank-view-switch, .rank-pricing-custom-box, .rank-project-card dl div, .rank-project-detail-grid div,
    .rank-check-live, .rank-segmented, .rank-tool-roadmap > span, .rank-keywords-add-panel,
    .rank-keyword-sidebar, .rank-keyword-bulk-bar, .rank-relevance-progress, .rank-relevance-note,
    .rank-analytics-metrics > div, .rank-competitor-comparison, .rank-dynamics-tabs,
    .rank-distribution-card, .rank-history-card, .rank-table-filter details, .rank-guest-url-value,
    .rank-summary-strip, .rank-check-timeline span, .rank-project-wizard-nav, .rank-search-engine-card,
    .rank-setting-options, .rank-project-keyword-meta, .rank-project-competitor-suggestions,
    .webmaster-steps, .webmaster-dash-legend span, .webmaster-chart-wrap,
    .users-sparkline, .users-overview-metric, .users-top-spender-row,
    .wm-last-check, .wm-settings-hint, .wm-project-metric, .wm-manual-update,
    .wm-history-bulk-actions, .wm-bulk-actions, .wm-import-progress, .wm-import .wm-update-mode,
    .wm-site-picker-heading .badge, .wm-help [role=tooltip], .wm-row-reason,
    .api-delivery-summary-card, .api-delivery-card-metric,
    .api-delivery-server-hours .api-delivery-card-metric, .api-delivery-copy-summary-grid .api-delivery-card-metric,
    .api-delivery-copy-history-row > td, .api-delivery-efficiency-period,
    .api-profile-status, .api-steps li, .api-example-tabs summary, .error-log pre,
    .clicks-attempt-stages > td
) {
    background: var(--panel-alt);
    border-color: var(--line);
    color: var(--muted-strong);
}

[data-theme="dark"] :is(.services-hero, .documentation-hero) {
    background: linear-gradient(120deg, var(--panel), #223653);
}
[data-theme="dark"] :is(.keys-hero-stat strong, .wm-project-metric strong,
    .wm-manual-copy strong, .wm-history-added-now h3, .clicks-attempt-stage-title,
    .documentation-content, .documentation-card strong) { color: var(--text); }
[data-theme="dark"] :is(label, .user-mode-chip, .infinite-toggle, .work-status-toggle,
    .users-overview-title, .users-overview-metric span, .users-top-spender-meta,
    .users-sparkline-labels, .clicks-attempt-tail, .clicks-attempt-tail b,
    .clicks-attempt-stage-time, .clicks-attempt-stage-query, .clicks-attempt-stage-billing,
    .documentation-card span, .documentation-result p, .documentation-empty,
    .documentation-tree-link, .documentation-tree-heading,
    .wm-import-progress-head, .wm-bulk-actions > strong, .wm-settings-field label,
    .wm-manual-feedback [role="status"], .wm-history-row-status) { color: var(--muted-strong); }

/* Neutral controls and popovers must not inherit the white primary-button label. */
[data-theme="dark"] :is(.rank-column-picker summary, .rank-view-switch button,
    .rank-device-icon, .rank-region-summary-trigger, .rank-date-range-trigger,
    .rank-date-range-presets button, .rank-toolbar-action, .rank-toolbar-icon,
    .rank-guest-url-button, .rank-matrix-target-button, .rank-schedule-day-options span,
    .rank-project-wizard-step > span, .webmaster-period-btn, .webmaster-calendar-nav,
    .webmaster-calendar-day, .pagination a, .region-section-title,
    .wm-region-picker > summary, .wm-history-plan-save, .wm-history-exclude,
    .wm-history-add, .wm-import .wm-help > button, .users-window-tab) {
    background: var(--panel-alt);
    color: var(--muted-strong);
    border-color: var(--line);
}
[data-theme="dark"] :is(.region-item:hover, .documentation-card:hover,
    .rank-actions-menu a:hover, .rank-actions-menu button:hover,
    .rank-keyword-table tbody tr:hover, .wm-region-options label:hover,
    .wm-site-option:hover, .wm-linked-project:hover, .api-doc-nav a:hover,
    .api-doc-nav-toggle:hover, .clicks-attempt-toggle:hover,
    .documentation-tree-link:hover, .documentation-tree-heading:hover) {
    background: var(--brand-soft);
    color: var(--brand);
}
[data-theme="dark"] :is(.documentation-result a, .documentation-content a,
    .documentation-article-back, .documentation-tree-overview, .clicks-attempt-toggle,
    .users-top-spender-value) { color: var(--brand); }
[data-theme="dark"] :is(.wm-project-recommendation, .wm-history-added-now,
    .wm-site-option:has(input:checked), .documentation-tree-link.is-active,
    .documentation-tree-heading.is-current) {
    background: var(--brand-soft);
    border-color: var(--line);
    color: var(--brand);
}
[data-theme="dark"] :is(.pagination a.active, .rank-view-switch button.is-active,
    .rank-dynamics-tabs button.is-active, .rank-date-days button.is-start,
    .rank-date-days button.is-end, .rank-segmented input:checked + span,
    .rank-schedule-day-options input:checked + span, .users-window-tab.is-active) {
    background: var(--theme-action);
    color: #fff;
    border-color: #4874da;
}
[data-theme="dark"] :is(.project-controls .btn-primary, .keys-section button[type="submit"]) {
    background: var(--theme-action);
    color: #fff;
}

/* Sticky cells need an opaque surface, including on horizontal scroll. */
[data-theme="dark"] :is(.webmaster-matrix, .rank-position-matrix) :is(th, td) {
    border-color: var(--line);
}
[data-theme="dark"] .webmaster-matrix td:nth-child(-n+4),
[data-theme="dark"] .rank-position-matrix td:first-child { background: var(--panel); }
[data-theme="dark"] .webmaster-matrix thead th:nth-child(-n+4),
[data-theme="dark"] .rank-position-matrix th:first-child { background: var(--panel-alt); }

/* State colours remain distinct from ordinary dark surfaces. */
[data-theme="dark"] :is(.error-message, .error, .badge-danger, .documentation-notice,
    .queue-status-badge--danger, .rank-share-status.is-error, .rank-check-live-head span.is-error,
    .rank-position-low, .rank-position-matrix th.is-problem, .rank-matrix-cell-low,
    .webmaster-matrix td.is-cold, .users-metric-pill--danger,
    .api-delivery-offline-summary, .api-delivery-offline-server,
    .api-delivery-badge--offline, .api-delivery-badge--no_data,
    .wm-import-progress.wm-progress-error, .project-card.project-card-deleted-admin,
    .project-card.project-card-deleted-client) {
    background: var(--danger-soft);
    color: var(--danger-text);
    border-color: #76404e;
}
[data-theme="dark"] :is(.warning, .badge-warning, .queue-status-badge--warning,
    .queue-type-pill--boost, .project-auto-boost-badge, .project-individual-boost-badge,
    .rank-visibility-value.is-low, .rank-relevance-cta, .rank-position-mid,
    .rank-matrix-empty-cell, .rank-development-badge, .webmaster-matrix td.is-mid,
    .documentation-freshness.needs-review, .users-metric-pill--warn,
    .api-callout.is-warning, .error-log-alert, .api-delivery-status--stale,
    .api-delivery-error, .api-delivery-badge--stalled, .wm-row-reason-warning,
    .rank-date-days button.is-check-day) {
    background: var(--warn-soft);
    color: var(--warn-strong);
    border-color: #705737;
}
[data-theme="dark"] :is(.success-message, .success, .rank-toast, .rank-visibility-value.is-high,
    .documentation-freshness, .api-delivery-status--fresh, .wm-import-status-success) {
    background: var(--ok-soft);
    color: var(--ok-strong);
    border-color: #35634b;
}
[data-theme="dark"] :is(.rank-position-not-found, .queue-status-badge--muted,
    .webmaster-matrix td.is-empty, .wm-history-table tr.wm-history-excluded) {
    background: var(--status-muted-soft);
    color: var(--status-muted-strong);
}
[data-theme="dark"] :is(.rank-project-delete, .rank-search-target-remove,
    .rank-project-competitor-row button, .rank-matrix-row-action.is-delete,
    .rank-matrix-delete-button, .api-delivery-delete-button, .wm-history-added-remove,
    .wm-row-exclude) {
    background: var(--danger-soft);
    color: var(--danger-text);
    border-color: #76404e;
}
[data-theme="dark"] .users-top-spender-value--danger { color: var(--danger-text); }
[data-theme="dark"] .users-top-spender-value--balance { color: var(--ok-strong); }
[data-theme="dark"] .documentation-content code { background: var(--brand-soft); color: var(--brand); }
[data-theme="dark"] .documentation-content pre code { background: transparent; color: inherit; }
[data-theme="dark"] .hint-tip-btn::after { background: var(--panel-alt); color: var(--text); border-color: var(--line); }

/* Legacy inline styles and disabled editor fields otherwise outrank the theme. */
[data-theme="dark"] .user-actions-menu { background: var(--panel) !important; border-color: var(--line) !important; }
[data-theme="dark"] .keys-modern-table tr.key-row.is-editing .key-row-field:disabled {
    background: var(--bg); color: var(--text);
}
[data-theme="dark"] .tickets-page .tickets-field textarea,
[data-theme="dark"] .wm-import :is(input:not([type="checkbox"]), select, textarea),
[data-theme="dark"] .wm-bulk-actions :is(input:not([type="checkbox"]), select),
[data-theme="dark"] .wm-settings-field :is(input, select, textarea) {
    background: var(--bg); color: var(--text); border-color: var(--line);
}
[data-theme="dark"] .dashboard-skeleton {
    background: linear-gradient(90deg, var(--panel-alt), var(--line), var(--panel-alt));
}

/* Text inside specialised report widgets has its own legacy palette. */
[data-theme="dark"] :is(
    .rank-dynamics-item strong, .rank-pricing-table td, .rank-pricing-table td strong,
    .rank-pricing-table td + td, .rank-pricing-custom-item strong,
    .rank-check-live-head strong, .rank-date-calendar h4, .rank-analytics-cost strong,
    .rank-competitor-settings-summary strong, .rank-tool-settings-form legend,
    .rank-keyword-sidebar-head strong, .rank-keyword-table td strong,
    .rank-analytics-metrics strong, .rank-competitor-comparison-head strong,
    .rank-competitor-comparison-head b, .rank-competitor-empty strong,
    .rank-distribution-donut strong, .rank-distribution-tooltip > strong,
    .rank-distribution-tooltip span b, .rank-distribution-tooltip .rank-distribution-tooltip-total,
    .rank-summary-strip strong, .rank-project-wizard-step strong,
    .rank-tool-setting strong, .rank-project-keyword-meta strong,
    .rank-project-competitor-head strong, .rank-project-competitor-suggestions strong,
    .api-delivery-hero h1, .api-delivery-section-head h2, .api-delivery-summary-value,
    .api-delivery-primary-value, .api-delivery-server-name, .api-delivery-copy-summary h3,
    .api-delivery-card-value, .api-delivery-table td,
    .payments-mobile-grid strong, .payments-mobile-user, .queue-kpi-section-title,
    .keys-modern-table .key-row-field:disabled, .infinite-toggle span:last-child,
    .work-status-toggle span:last-child
) { color: var(--text); }

[data-theme="dark"] :is(
    .muted, .auth-links, .auth-credit, .wallet-note, .payment-method-sub, .payments-scroll-hint,
    .payments-mobile-type, .payments-mobile-grid span, .payments-mobile-comment, .payments-mobile-empty,
    .rank-check-control, .rank-region-summary-trigger small, .rank-region-summary-project span,
    .rank-pricing-empty, .rank-pricing-meta, .rank-check-overview span, .rank-check-progress,
    .rank-check-live-head span, .rank-analytics-toolbar label, .rank-date-range-footer span,
    .rank-analytics-cost, .rank-competitor-settings-summary, .rank-segmented span,
    .rank-keyword-sidebar-head span, .rank-keyword-content-head p,
    .rank-keyword-scope-list a, .rank-keyword-tree-link, .rank-keyword-kicker,
    .rank-keyword-location, .rank-relevance-progress span, .rank-relevance-dialog header p,
    .rank-relevance-dialog-body label, .rank-relevance-dialog-body > p,
    .rank-keyword-empty, .rank-analytics-compare, .rank-competitor-comparison-head span,
    .rank-competitor-comparison-head small, .rank-competitor-empty p,
    .rank-dynamics-tabs button, .rank-table-filter summary, .rank-filter-help, .rank-filter-status,
    .rank-guest-url-dialog #rank-guest-url-description, .rank-distribution-legend span,
    .rank-history-column small, .rank-distribution-tooltip span, .rank-chart-empty,
    .rank-summary-strip span, .rank-project-wizard-step, .rank-search-engine-title small,
    .rank-region-suggestion, .rank-region-suggestion span, .rank-region-suggestion-empty,
    .rank-project-step-head > span, .rank-schedule-days legend,
    .rank-setting-options > span, .rank-setting-options label span,
    .rank-project-competitor-head, .rank-position-miss,
    .api-delivery-hero p, .api-delivery-section-head p, .api-delivery-efficiency-period button,
    .api-delivery-update-block, .api-delivery-view-tab, .api-delivery-scope-meta,
    .api-delivery-summary-label, .api-delivery-chart-legend, .api-delivery-primary-label,
    .api-delivery-chart-tooltip-time, .api-delivery-table caption,
    .api-delivery-copy-summary-note, .api-delivery-copy-chart-head p,
    .api-delivery-copy-history-table caption, .api-delivery-copy-history-loading,
    .api-delivery-copy-history-empty, .api-delivery-empty,
    .api-delivery-server-card-meta, .api-delivery-server-card-details summary,
    .api-delivery-card-label, .webmaster-calendar-weekdays, .webmaster-query-filter-help
) { color: var(--muted); }

[data-theme="dark"] :is(.pos-cell-btn, .queue-type-pill, .queue-status-badge--info,
    .queue-hour-chip--base, .project-schedule-badge, .rank-keyword-tags span,
    .rank-visibility-value, .rank-top-value, .rank-keyword-status,
    .region-selected-chip, .wizard-step.active span, .wizard-step.done span) {
    background: var(--brand-soft); color: var(--brand); border-color: var(--line);
}
[data-theme="dark"] :is(.message, .badge-success, .queue-status-badge--success,
    .rank-position-top, .rank-position-high, .rank-position-middle,
    .webmaster-matrix td.is-hot, .webmaster-matrix td.is-good,
    .api-delivery-badge--healthy) { background: var(--ok-soft); color: var(--ok-strong); }
[data-theme="dark"] :is(.rank-matrix-position, .rank-position-link:hover .rank-matrix-position,
    .rank-table-actions summary, .rank-keyword-target-button.has-target,
    .rank-matrix-target-button.has-target, .webmaster-matrix td:first-child a,
    .sidebar-submenu-toggle, .sidebar-submenu-toggle:hover, .menu-link-child,
    .api-delivery-copy-history-toggle, .api-delivery-copy-history-toggle--icon,
    .services-eyebrow, .auth-credit a) { color: var(--brand); }
[data-theme="dark"] :is(.rank-position-delta.is-up, .rank-matrix-delta.is-up,
    .rank-dynamics-item.is-improved) { color: var(--ok-strong); }
[data-theme="dark"] :is(.rank-visibility-value.is-medium, .queue-hour-chip--debt,
    .queue-hour-chip--recovery) { background: var(--warn-soft); color: var(--warn-strong); }
[data-theme="dark"] :is(.badge-neutral, .api-delivery-badge--idle,
    .rank-keyword-status.is-disabled) { background: var(--panel-alt); color: var(--muted); }
[data-theme="dark"] .api-delivery-badge--unspecified { background: #372b50; color: #d5b7ff; }
[data-theme="dark"] .api-delivery-chart-tooltip { background: var(--panel-alt); color: var(--text); border-color: var(--line); }
[data-theme="dark"] :is(.rank-date-days button, .rank-date-range-nav button) { color: var(--text); }
[data-theme="dark"] :is(.rank-date-days button:hover, .rank-date-days button.is-between) { background: var(--brand-soft); }
[data-theme="dark"] :is(.rank-view-switch button.is-active, .rank-dynamics-tabs button.is-active,
    .api-delivery-view-tab.is-active, .api-delivery-efficiency-period button.is-active,
    .rank-keyword-scope-list a.is-active, .rank-keyword-tree-link.is-active) { color: #fff; }
[data-theme="dark"] .services-eyebrow { background: var(--brand-soft); }
[data-theme="dark"] .documentation-hero p { color: var(--muted); }
[data-theme="dark"] .documentation-eyebrow { color: var(--brand); }
[data-theme="dark"] .positions-legend { color: var(--muted) !important; }
[data-theme="dark"] .warning-message { background: var(--warn-soft); color: var(--warn-strong); border-color: #705737; }
[data-theme="dark"] .dashboard-projects-error { background: var(--danger-soft); color: var(--danger-text); border-color: #76404e; }
[data-theme="dark"] :is(.webmaster-kicker, .api-token-box, .api-callout, .api-doc-nav a) {
    background: var(--brand-soft); color: var(--brand); border-color: var(--line);
}
[data-theme="dark"] :is(.api-delivery-status, .api-delivery-view-switcher) {
    background: var(--panel-alt); color: var(--muted-strong); border-color: var(--line);
}
[data-theme="dark"] :is(.api-profile-note, .api-profile-status.is-active) {
    background: var(--ok-soft); color: var(--ok-strong); border-color: #35634b;
}
[data-theme="dark"] :is(.api-profile-hero p, .api-profile-meta span, .api-steps p,
    .api-doc-lead, .api-doc-table code, .error-log p, .error-log small,
    .error-log-empty, .seo-finance-table .small-text, .seo-finance-global-price) { color: var(--muted); }
[data-theme="dark"] :is(.api-profile-kicker, .api-token-box code, .api-token-box input,
    .api-resource-list code, .error-log summary) { color: var(--brand); }
[data-theme="dark"] .error-log-total { color: var(--text); }
[data-theme="dark"] .api-callout.is-warning { background: var(--warn-soft); color: var(--warn-strong); }
[data-theme="dark"] .api-toggle-btn { background: var(--theme-action); color: #fff; border-color: #4874da; }
[data-theme="dark"] .api-delivery-status--fresh { background: var(--ok-soft); color: var(--ok-strong); border-color: #35634b; }
[data-theme="dark"] .api-delivery-status--stale { background: var(--warn-soft); color: var(--warn-strong); border-color: #705737; }
[data-theme="dark"] .payments-scroll-hint { background: var(--panel-alt); border-color: var(--line); }
[data-theme="dark"] .copy-btn { background: var(--theme-action); color: #fff; border-color: #4874da; }

/* Populated reports and wizard states (verified against production markup). */
[data-theme="dark"] :is(.wm-head-stats > div, .rank-keyword-location) {
    background: var(--panel-alt); border-color: var(--line); color: var(--muted-strong);
}
[data-theme="dark"] :is(.rank-analytics-compare, .users-contact-badge,
    .rank-project-status-tabs a.is-active, .rank-project-step-head > span) {
    background: var(--brand-soft); color: var(--brand); border-color: var(--line);
}
[data-theme="dark"] .users-metric-pill--good {
    background: var(--ok-soft); color: var(--ok-strong);
}
[data-theme="dark"] .wm-linked-project :is(strong, .wm-linked-project-new-link) { color: var(--brand); }
[data-theme="dark"] .quickstart-form .wizard-pane > .form-group > label:first-child { color: var(--muted-strong); }
[data-theme="dark"] :is(.wizard-step span, .wizard-counter, .region-selection-preview) {
    background: var(--panel-alt); color: var(--muted-strong); border-color: var(--line);
}
[data-theme="dark"] :is(.wizard-step.active span, .wizard-step.done span) { background: var(--brand-soft); color: var(--brand); }
[data-theme="dark"] .rank-project-wizard-step:hover,
[data-theme="dark"] .rank-project-wizard-step.is-active,
[data-theme="dark"] .rank-project-wizard-step.is-active:hover {
    background: var(--brand-soft); color: var(--muted-strong);
}
[data-theme="dark"] .rank-project-wizard-step.is-active :is(strong, span) { color: var(--brand); }
[data-theme="dark"] .rank-project-wizard-step.is-complete > span { background: var(--ok-soft); color: var(--ok-strong); }
[data-theme="dark"] .rank-project-wizard-step small { color: var(--muted); }
[data-theme="dark"] .rank-keyword-scope-list a.is-active :is(span, b),
[data-theme="dark"] .rank-keyword-tree-link.is-active :is(span, b) { color: #fff; }
[data-theme="dark"] .rank-keyword-create-popover > summary { color: var(--brand); }

[data-theme="dark"] .rank-position-matrix th:first-child { color: var(--muted-strong); }
[data-theme="dark"] .rank-position-matrix td.rank-matrix-cell-top { background: #203e59; }
[data-theme="dark"] .rank-position-matrix td.rank-matrix-cell-high { background: #1a4638; }
[data-theme="dark"] .rank-position-matrix td.rank-matrix-cell-middle { background: #293e37; }
[data-theme="dark"] .rank-position-matrix td.rank-matrix-cell-low { background: var(--danger-soft); }
[data-theme="dark"] .rank-position-matrix :is(.rank-matrix-position, .rank-position-link:hover .rank-matrix-position) { color: var(--text); }
[data-theme="dark"] .rank-matrix-scrollbar { background: var(--panel-alt); border-color: var(--line); }
[data-theme="dark"] :is(.rank-matrix-scrollbar, .rank-matrix-table-scroll) { scrollbar-color: var(--muted-soft) var(--panel-alt); }
[data-theme="dark"] .rank-position-matrix th.rank-matrix-sortable:hover,
[data-theme="dark"] .rank-position-matrix th.rank-matrix-sortable:focus-visible { background: var(--brand-soft); color: var(--brand); }

/* These controls use generic .btn or more specific active selectors. */
[data-theme="dark"] .rank-project-results .btn,
[data-theme="dark"] .rank-analytics-toolbar .btn { background: var(--theme-action); color: #fff; border-color: #4874da; }
[data-theme="dark"] .api-delivery-view-tab.is-active,
[data-theme="dark"] .api-delivery-efficiency-period button.is-active { background: var(--theme-action); color: #fff; }
[data-theme="dark"] .create-project-big-btn { background: #168044; }
[data-theme="dark"] .create-project-big-btn:hover { background: #116c38; }
[data-theme="dark"] .rank-toolbar-action > span { background: var(--brand-soft); color: var(--brand); }
/* Legacy status labels carry inline colors; keep their semantic distinction. */
[data-theme="dark"] .users-analytics-card strong[style*="#17663c"] { color: var(--ok-strong) !important; }
[data-theme="dark"] .users-analytics-card strong[style*="#b42318"] { color: var(--danger-text) !important; }
[data-theme="dark"] .users-analytics-card strong[style*="#667085"] { color: var(--muted-strong) !important; }
[data-theme="dark"] .page-preloader { background: var(--page-bg, #101724); }
[data-theme="dark"] .project-boost-warning { background: var(--danger-soft); color: var(--danger-text); border-color: #76404e; }
[data-theme="dark"] .project-boost-estimate { background: var(--brand-soft); color: var(--brand); border-color: var(--line); }
