/* ERPPlus AI dashboard theme compatibility layer.
   Loaded after component-isolated styles so the /ai workspace follows the active app theme. */

body.erpdb-light .erp-ai-dashboard-v2 {
    --ai-page-bg: #f5f7fc;
    --ai-surface: #ffffff;
    --ai-surface-raised: #ffffff;
    --ai-surface-soft: #f8fafc;
    --ai-surface-muted: #f1f5f9;
    --ai-border: #e2e8f0;
    --ai-border-strong: #cbd5e1;
    --ai-text: #0f172a;
    --ai-muted: #64748b;
    --ai-muted-strong: #475569;
    --ai-blue-soft: #eff6ff;
    --ai-green-soft: #f0fdf4;
    --ai-amber-soft: #fffbeb;
    --ai-red-soft: #fef2f2;
    --ai-purple-soft: #f5f3ff;
    --ai-shadow: 0 18px 42px rgba(15, 23, 42, .07);
    color-scheme: light;
}

body.erpdb-dark .erp-ai-dashboard-v2 {
    --ai-page-bg: #020617;
    --ai-surface: #0f172a;
    --ai-surface-raised: #111c31;
    --ai-surface-soft: #172033;
    --ai-surface-muted: #1e293b;
    --ai-border: #2b3950;
    --ai-border-strong: #475569;
    --ai-text: #f8fafc;
    --ai-muted: #a8b3c7;
    --ai-muted-strong: #cbd5e1;
    --ai-blue-soft: rgba(37, 99, 235, .15);
    --ai-green-soft: rgba(16, 185, 129, .13);
    --ai-amber-soft: rgba(245, 158, 11, .13);
    --ai-red-soft: rgba(239, 68, 68, .13);
    --ai-purple-soft: rgba(124, 58, 237, .14);
    --ai-shadow: 0 18px 44px rgba(0, 0, 0, .28);
    color-scheme: dark;
}

body.erpdb-light .erp-ai-dashboard-v2,
body.erpdb-dark .erp-ai-dashboard-v2 {
    background:
        radial-gradient(circle at top right, rgba(37, 99, 235, .10), transparent 34%),
        radial-gradient(circle at bottom left, rgba(124, 58, 237, .08), transparent 30%),
        var(--ai-page-bg) !important;
    color: var(--ai-text) !important;
}

/* Primary light-surface sections */
body.erpdb-light .erp-ai-dashboard-v2 :is(
    .ai-enterprise-command-bar,
    .erp-ai-dashboard-v2__management-alerts,
    .ai-data-connector-panel,
    .ai-executive-control-center,
    .ai-global-health-monitor,
    .ai-decision-queue,
    .ai-executive-timeline,
    .ai-sales-trend-board,
    .ai-sales-intelligence-panel,
    .ai-analysis-center,
    .ai-module-health-map,
    .ai-forecast-card,
    .ai-forecast-chart,
    .ai-report-generator-panel,
    .ai-automation-engine-panel,
    .ai-assistant-panel
),
body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-enterprise-command-bar,
    .erp-ai-dashboard-v2__management-alerts,
    .ai-data-connector-panel,
    .ai-executive-control-center,
    .ai-global-health-monitor,
    .ai-decision-queue,
    .ai-executive-timeline,
    .ai-sales-trend-board,
    .ai-sales-intelligence-panel,
    .ai-analysis-center,
    .ai-module-health-map,
    .ai-forecast-card,
    .ai-forecast-chart,
    .ai-report-generator-panel,
    .ai-automation-engine-panel,
    .ai-assistant-panel
) {
    background: var(--ai-surface) !important;
    border-color: var(--ai-border) !important;
    color: var(--ai-text) !important;
    box-shadow: var(--ai-shadow) !important;
}

/* Standard nested cards and form-like surfaces */
body.erpdb-light .erp-ai-dashboard-v2 :is(
    .erp-ai-dashboard-v2__status > div,
    .erp-ai-alert-card,
    .ai-executive-kpi-strip__card:not(.is-ai),
    .ai-enterprise-command-bar__search,
    .ai-enterprise-command-bar__actions button:not(.primary),
    .ai-data-connector-panel__time,
    .ai-data-connector-panel__metric,
    .ai-data-connector-panel__signal,
    .ai-executive-kpi-wall__item,
    .ai-global-health-monitor__item,
    .ai-executive-action-center__action,
    .ai-decision-queue__item,
    .ai-executive-timeline__items article,
    .ai-sales-trend-board__total,
    .ai-sales-trend-board__chart,
    .ai-sales-intelligence-panel__summary > div,
    .ai-sales-intelligence-panel__executive,
    .ai-sales-intelligence-panel__insight,
    .ai-sales-intelligence-panel__signal,
    .ai-analysis-center__score,
    .ai-analysis-center__card,
    .ai-analysis-center__footer,
    .ai-module-health-map__cell,
    .ai-forecast-card__main,
    .ai-forecast-card__summary-kpis > div,
    .ai-forecast-card__metrics,
    .ai-forecast-card__insight,
    .ai-forecast-card__empty,
    .ai-forecast-chart__empty,
    .ai-report-generator-panel__summary,
    .ai-report-generator-panel__section,
    .ai-report-generator-panel__footer,
    .ai-automation-engine-panel__summary,
    .ai-automation-engine-panel__rule,
    .ai-automation-engine-panel__rule-body > p,
    .ai-automation-engine-panel__footer,
    .ai-conversations,
    .ai-conversation,
    .ai-assistant-panel__messages,
    .ai-message:not(.user),
    .ai-assistant-panel__input
),
body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .erp-ai-dashboard-v2__status > div,
    .erp-ai-alert-card,
    .ai-executive-kpi-strip__card:not(.is-ai),
    .ai-enterprise-command-bar__search,
    .ai-enterprise-command-bar__actions button:not(.primary),
    .ai-data-connector-panel__time,
    .ai-data-connector-panel__metric,
    .ai-data-connector-panel__signal,
    .ai-executive-kpi-wall__item,
    .ai-global-health-monitor__item,
    .ai-executive-action-center__action,
    .ai-decision-queue__item,
    .ai-executive-timeline__items article,
    .ai-sales-trend-board__total,
    .ai-sales-trend-board__chart,
    .ai-sales-intelligence-panel__summary > div,
    .ai-sales-intelligence-panel__executive,
    .ai-sales-intelligence-panel__insight,
    .ai-sales-intelligence-panel__signal,
    .ai-analysis-center__score,
    .ai-analysis-center__card,
    .ai-analysis-center__footer,
    .ai-module-health-map__cell,
    .ai-forecast-card__main,
    .ai-forecast-card__summary-kpis > div,
    .ai-forecast-card__metrics,
    .ai-forecast-card__insight,
    .ai-forecast-card__empty,
    .ai-forecast-chart__empty,
    .ai-report-generator-panel__summary,
    .ai-report-generator-panel__section,
    .ai-report-generator-panel__footer,
    .ai-automation-engine-panel__summary,
    .ai-automation-engine-panel__rule,
    .ai-automation-engine-panel__rule-body > p,
    .ai-automation-engine-panel__footer,
    .ai-conversations,
    .ai-conversation,
    .ai-assistant-panel__messages,
    .ai-message:not(.user),
    .ai-assistant-panel__input
) {
    background: var(--ai-surface-soft) !important;
    border-color: var(--ai-border) !important;
    color: var(--ai-text) !important;
}

/* Headings, values and secondary copy */
body.erpdb-light .erp-ai-dashboard-v2 :is(
    .ai-data-connector-panel,
    .ai-executive-control-center,
    .ai-global-health-monitor,
    .ai-executive-kpi-wall,
    .ai-executive-action-center,
    .ai-decision-queue,
    .ai-executive-timeline,
    .ai-sales-trend-board,
    .ai-sales-intelligence-panel,
    .ai-analysis-center,
    .ai-module-health-map,
    .ai-forecast-card,
    .ai-forecast-chart,
    .ai-report-generator-panel,
    .ai-automation-engine-panel,
    .ai-assistant-panel
) :is(h2, h3, h4, strong, b),
body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-data-connector-panel,
    .ai-executive-control-center,
    .ai-global-health-monitor,
    .ai-executive-kpi-wall,
    .ai-executive-action-center,
    .ai-decision-queue,
    .ai-executive-timeline,
    .ai-sales-trend-board,
    .ai-sales-intelligence-panel,
    .ai-analysis-center,
    .ai-module-health-map,
    .ai-forecast-card,
    .ai-forecast-chart,
    .ai-report-generator-panel,
    .ai-automation-engine-panel,
    .ai-assistant-panel
) :is(h2, h3, h4, strong, b) {
    color: var(--ai-text) !important;
}

body.erpdb-light .erp-ai-dashboard-v2 :is(
    .ai-data-connector-panel,
    .ai-executive-control-center,
    .ai-global-health-monitor,
    .ai-executive-action-center,
    .ai-decision-queue,
    .ai-executive-timeline,
    .ai-sales-trend-board,
    .ai-sales-intelligence-panel,
    .ai-analysis-center,
    .ai-module-health-map,
    .ai-forecast-card,
    .ai-forecast-chart,
    .ai-report-generator-panel,
    .ai-automation-engine-panel,
    .ai-assistant-panel
) :is(p, small),
body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-data-connector-panel,
    .ai-executive-control-center,
    .ai-global-health-monitor,
    .ai-executive-action-center,
    .ai-decision-queue,
    .ai-executive-timeline,
    .ai-sales-trend-board,
    .ai-sales-intelligence-panel,
    .ai-analysis-center,
    .ai-module-health-map,
    .ai-forecast-card,
    .ai-forecast-chart,
    .ai-report-generator-panel,
    .ai-automation-engine-panel,
    .ai-assistant-panel
) :is(p, small) {
    color: var(--ai-muted) !important;
}

body.erpdb-light .erp-ai-dashboard-v2 :is(
    .erp-ai-dashboard-v2__status span,
    .ai-data-connector-panel__time span,
    .ai-data-connector-panel__metric span,
    .ai-global-health-monitor__item small,
    .ai-executive-kpi-wall__top small,
    .ai-executive-kpi-wall__money-unit,
    .ai-executive-kpi-wall__item p,
    .ai-executive-action-center__action p,
    .ai-decision-queue__item p,
    .ai-sales-trend-board__total span,
    .ai-sales-trend-board__day span,
    .ai-sales-trend-board__legend span,
    .ai-sales-intelligence-panel__summary span,
    .ai-sales-intelligence-panel__executive span,
    .ai-sales-intelligence-panel__signal span,
    .ai-analysis-center__score span,
    .ai-analysis-center__footer span,
    .ai-module-health-map__cell small,
    .ai-forecast-card__header p,
    .ai-forecast-card__main > span,
    .ai-forecast-card__summary-kpis span,
    .ai-forecast-card__metrics span,
    .ai-forecast-chart__header span,
    .ai-forecast-chart__legend,
    .ai-forecast-chart__value,
    .ai-forecast-chart__bar small,
    .ai-report-generator-panel__footer span,
    .ai-automation-engine-panel__rule-header small,
    .ai-automation-engine-panel__footer span,
    .ai-conversation small
),
body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .erp-ai-dashboard-v2__status span,
    .ai-data-connector-panel__time span,
    .ai-data-connector-panel__metric span,
    .ai-global-health-monitor__item small,
    .ai-executive-kpi-wall__top small,
    .ai-executive-kpi-wall__money-unit,
    .ai-executive-kpi-wall__item p,
    .ai-executive-action-center__action p,
    .ai-decision-queue__item p,
    .ai-sales-trend-board__total span,
    .ai-sales-trend-board__day span,
    .ai-sales-trend-board__legend span,
    .ai-sales-intelligence-panel__summary span,
    .ai-sales-intelligence-panel__executive span,
    .ai-sales-intelligence-panel__signal span,
    .ai-analysis-center__score span,
    .ai-analysis-center__footer span,
    .ai-module-health-map__cell small,
    .ai-forecast-card__header p,
    .ai-forecast-card__main > span,
    .ai-forecast-card__summary-kpis span,
    .ai-forecast-card__metrics span,
    .ai-forecast-chart__header span,
    .ai-forecast-chart__legend,
    .ai-forecast-chart__value,
    .ai-forecast-chart__bar small,
    .ai-report-generator-panel__footer span,
    .ai-automation-engine-panel__rule-header small,
    .ai-automation-engine-panel__footer span,
    .ai-conversation small
) {
    color: var(--ai-muted) !important;
}

/* Search/input controls */
body.erpdb-light .erp-ai-dashboard-v2 :is(input, textarea, select),
body.erpdb-dark .erp-ai-dashboard-v2 :is(input, textarea, select) {
    background-color: var(--ai-surface-soft) !important;
    border-color: var(--ai-border) !important;
    color: var(--ai-text) !important;
}

body.erpdb-light .erp-ai-dashboard-v2 :is(input, textarea)::placeholder,
body.erpdb-dark .erp-ai-dashboard-v2 :is(input, textarea)::placeholder {
    color: var(--ai-muted) !important;
    opacity: 1;
}

/* Semantic surfaces stay meaningful without turning white in dark mode. */
body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-data-connector-panel .is-success,
    .ai-global-health-monitor__item.is-success,
    .ai-module-health-map__cell.is-success
) {
    background: var(--ai-green-soft) !important;
    border-color: rgba(16, 185, 129, .45) !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-data-connector-panel .is-warning,
    .ai-global-health-monitor__item.is-warning,
    .ai-module-health-map__cell.is-warning,
    .ai-automation-engine-panel__counter
) {
    background: var(--ai-amber-soft) !important;
    border-color: rgba(245, 158, 11, .45) !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-module-health-map__cell.is-danger,
    .erp-ai-alert-card.severity-critical
) {
    background: var(--ai-red-soft) !important;
    border-color: rgba(239, 68, 68, .45) !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-module-health-map__cell.is-info,
    .erp-ai-alert-card.severity-attention,
    .erp-ai-alert-card.severity-info
) {
    background: var(--ai-blue-soft) !important;
    border-color: rgba(59, 130, 246, .42) !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 .erp-ai-alert-card.severity-warning {
    background: var(--ai-amber-soft) !important;
    border-color: rgba(245, 158, 11, .45) !important;
}

/* Dark-mode chart canvases and separators */
body.erpdb-dark .erp-ai-dashboard-v2 .ai-sales-trend-board__chart {
    background:
        linear-gradient(180deg, rgba(17, 28, 49, .94), rgba(15, 23, 42, .98)),
        repeating-linear-gradient(0deg, transparent, transparent 53px, rgba(148, 163, 184, .10) 54px) !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 .ai-forecast-chart__bars {
    border-bottom-color: var(--ai-border) !important;
    background: repeating-linear-gradient(to top, transparent 0, transparent 64px, rgba(148, 163, 184, .10) 65px) !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .erp-ai-dashboard-v2__management-alerts > header,
    .ai-automation-engine-panel__rule-header,
    .ai-forecast-card__metrics > div + div
) {
    border-color: var(--ai-border) !important;
}

/* Icon wells and neutral buttons */
body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-executive-kpi-strip__icon,
    .ai-sales-intelligence-panel__insight > span,
    .ai-report-generator-panel__section > span,
    .ai-automation-engine-panel__rule-header > span
) {
    background: var(--ai-surface-muted) !important;
    color: var(--ai-text) !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-decision-queue__item button.ghost,
    .ai-enterprise-command-bar__actions button:not(.primary),
    .ai-chat-actions button
) {
    background: var(--ai-surface-muted) !important;
    border-color: var(--ai-border) !important;
    color: var(--ai-text) !important;
}

/* Preserve intentionally dark/brand panels and primary controls. */
body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-live-business-radar,
    .ai-decision-funnel,
    .ai-copilot-panel,
    .ai-executive-kpi-strip__card.is-ai,
    .ai-forecast-card__confidence
) {
    color: #ffffff !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-live-business-radar,
    .ai-decision-funnel,
    .ai-copilot-panel
) :is(h2, h3, h4, strong, b) {
    color: #ffffff !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-live-business-radar,
    .ai-decision-funnel,
    .ai-copilot-panel
) :is(p, small) {
    color: #cbd5e1 !important;
}

/* Keep badges readable while avoiding white slabs. */
body.erpdb-dark .erp-ai-dashboard-v2 :is(
    .ai-data-connector-panel__eyebrow,
    .ai-executive-control-center__eyebrow,
    .ai-global-health-monitor__header > span,
    .ai-executive-kpi-wall__header > span,
    .ai-executive-action-center__header > span,
    .ai-decision-queue__header > span,
    .ai-executive-timeline__header > span,
    .ai-sales-trend-board__eyebrow,
    .ai-sales-intelligence-panel__eyebrow,
    .ai-analysis-center__eyebrow,
    .ai-module-health-map__header > span,
    .ai-forecast-card__eyebrow,
    .ai-report-generator-panel__eyebrow,
    .ai-automation-engine-panel__eyebrow,
    .ai-assistant-panel__eyebrow
) {
    background: var(--ai-blue-soft) !important;
    color: #93c5fd !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 .ai-executive-control-center__status {
    background: var(--ai-green-soft) !important;
    border-color: rgba(16, 185, 129, .42) !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 .ai-executive-control-center__status :is(span, strong) {
    color: #86efac !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 .ai-assistant-panel__status {
    background: var(--ai-green-soft) !important;
    color: #86efac !important;
}

body.erpdb-dark .erp-ai-dashboard-v2 .ai-conversation.active {
    background: rgba(20, 184, 166, .14) !important;
    border-color: rgba(20, 184, 166, .45) !important;
}

@media (max-width: 760px) {
    body.erpdb-light .erp-ai-dashboard-v2,
    body.erpdb-dark .erp-ai-dashboard-v2 {
        padding-inline: 14px !important;
    }
}
