/* AudienceLens report dark mode lockdown */

html[data-theme="dark"] {
  --al-page: #020617;
  --al-surface: #0f172a;
  --al-surface-2: #111827;
  --al-surface-3: #1e293b;
  --al-input: #08111f;
  --al-border: #243044;
  --al-border-2: #334155;
  --al-heading: #f8fafc;
  --al-text: #e5e7eb;
  --al-soft: #cbd5e1;
  --al-muted: #94a3b8;
  --al-orange: #ea580c;
  --al-orange-soft: #fed7aa;
  --al-green: #047857;
  --al-green-soft: #d1fae5;
  --al-blue-soft: #dbeafe;
}

/* Scope to report-like pages only */
html[data-theme="dark"] body:has(.report-section),
html[data-theme="dark"] body:has(.report-evidence-nav),
html[data-theme="dark"] body:has(.review-queue-summary),
html[data-theme="dark"] body:has(.score-breakdown-group),
html[data-theme="dark"] body:has(.report-rewrite-panel) {
  background: var(--al-page) !important;
  color: var(--al-text) !important;
}

/* All report-prefixed containers */
html[data-theme="dark"] body:has(.report-section) :is(
  [class^="report-"],
  [class*=" report-"],
  [class^="score-breakdown"],
  [class*=" score-breakdown"],
  [class^="review-queue"],
  [class*=" review-queue"],
  [class^="history-"],
  [class*=" history-"],
  [class^="comparison-"],
  [class*=" comparison-"],
  [class^="signal-"],
  [class*=" signal-"],
  [class^="evidence-"],
  [class*=" evidence-"],
  .panel-head,
  .al-surface-card,
  .al-surface-action
),
html[data-theme="dark"] body:has(.review-queue-summary) :is(
  [class^="report-"],
  [class*=" report-"],
  [class^="score-breakdown"],
  [class*=" score-breakdown"],
  [class^="review-queue"],
  [class*=" review-queue"],
  [class^="history-"],
  [class*=" history-"],
  [class^="comparison-"],
  [class*=" comparison-"],
  [class^="signal-"],
  [class*=" signal-"],
  [class^="evidence-"],
  [class*=" evidence-"],
  .panel-head,
  .al-surface-card,
  .al-surface-action
) {
  border-color: var(--al-border) !important;
}

/* Main report cards/sections */
html[data-theme="dark"] :is(
  .report-section,
  .report-section-card,
  .report-fix-plan-section,
  .report-rewrite-panel,
  .report-uk-map-guidance,
  .report-evidence-nav,
  .score-breakdown-group,
  .review-queue-summary,
  .history-card,
  .comparison-panel,
  .al-surface-card,
  .al-surface-action
) {
  background: linear-gradient(135deg, var(--al-surface-2), var(--al-surface)) !important;
  background-image: linear-gradient(135deg, var(--al-surface-2), var(--al-surface)) !important;
  color: var(--al-text) !important;
  border: 1px solid var(--al-border) !important;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.34) !important;
}

/* Nested report panels/cards/rows */
html[data-theme="dark"] :is(
  .report-fix-plan,
  .report-fix-step,
  .report-fix-step--primary,
  .report-fix-step--secondary,
  .report-fix-step-body,
  .report-fix-step-rewrite,
  .report-rewrite-box,
  .report-uk-map-guidance-card,
  .report-evidence-nav-item,
  .score-breakdown-row,
  .score-breakdown-details,
  .review-queue-score,
  .review-queue-main,
  .review-queue-meta,
  .review-queue-weakest,
  .review-queue-date,
  .review-queue-actions,
  .evidence-cue-list,
  .signal-row-evidence
) {
  background: var(--al-surface) !important;
  background-image: none !important;
  color: var(--al-text) !important;
  border: 1px solid var(--al-border-2) !important;
  box-shadow: none !important;
}

/* Report heads/bodies should not keep pale backgrounds */
html[data-theme="dark"] :is(
  .panel-head,
  .report-fix-step-head,
  .report-fix-step-summary,
  .report-rewrite-head,
  .report-rewrite-copy,
  .report-rewrite-actions,
  .score-breakdown-group-head,
  .score-breakdown-group-body,
  .score-breakdown-row-head,
  .score-breakdown-row-copy,
  .score-breakdown-dimension,
  .review-queue-titleline
) {
  background: transparent !important;
  background-image: none !important;
  color: var(--al-text) !important;
  border-color: var(--al-border-2) !important;
  box-shadow: none !important;
}

/* Text */
html[data-theme="dark"] body:has(.report-section) :is(h1,h2,h3,h4,h5,h6,strong),
html[data-theme="dark"] body:has(.review-queue-summary) :is(h1,h2,h3,h4,h5,h6,strong) {
  color: var(--al-heading) !important;
}

html[data-theme="dark"] body:has(.report-section) :is(p,li,span,small,label,summary),
html[data-theme="dark"] body:has(.review-queue-summary) :is(p,li,span,small,label,summary) {
  color: var(--al-text) !important;
}

html[data-theme="dark"] :is(.section-label,.metric-label,[class*="note"],[class*="intro"],[class*="scoreline"]) {
  color: var(--al-muted) !important;
}

/* Fix plan specific */
html[data-theme="dark"] .report-fix-step-marker {
  background: var(--al-surface-3) !important;
  color: var(--al-heading) !important;
  border: 1px solid var(--al-border-2) !important;
}

html[data-theme="dark"] .report-fix-step--primary {
  border-color: #f97316 !important;
}

html[data-theme="dark"] .report-fix-step--secondary {
  border-color: var(--al-border-2) !important;
}

html[data-theme="dark"] .report-fix-step-rewrite span,
html[data-theme="dark"] .report-rewrite-box span {
  color: var(--al-muted) !important;
}

html[data-theme="dark"] .report-fix-step-rewrite strong,
html[data-theme="dark"] .report-rewrite-box strong {
  color: var(--al-heading) !important;
}

/* Rewrite panel */
html[data-theme="dark"] .report-rewrite-panel {
  border-color: #f97316 !important;
}

html[data-theme="dark"] .report-rewrite-why {
  color: var(--al-soft) !important;
  background: transparent !important;
}

/* UK map guidance */
html[data-theme="dark"] .report-uk-map-guidance-card--proof {
  border-color: #2563eb !important;
}

html[data-theme="dark"] .report-uk-map-guidance-card--watch {
  border-color: #92400e !important;
}

html[data-theme="dark"] .report-uk-map-guidance-card--localise {
  border-color: var(--al-green) !important;
}

/* Evidence nav */
html[data-theme="dark"] .report-evidence-nav-item {
  cursor: pointer;
}

html[data-theme="dark"] .report-evidence-nav-item.is-active,
html[data-theme="dark"] .report-evidence-nav-item[aria-pressed="true"] {
  background: var(--al-surface-3) !important;
  color: var(--al-heading) !important;
  border-color: #60a5fa !important;
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.24) !important;
}

html[data-theme="dark"] .report-evidence-nav-item span {
  color: var(--al-muted) !important;
}

html[data-theme="dark"] .report-evidence-nav-item.is-active span,
html[data-theme="dark"] .report-evidence-nav-item[aria-pressed="true"] span {
  color: #bfdbfe !important;
}

/* Score breakdown */
html[data-theme="dark"] .score-breakdown-group--needs-attention {
  border-color: #92400e !important;
}

html[data-theme="dark"] .score-breakdown-group--mixed {
  border-color: #ca8a04 !important;
}

html[data-theme="dark"] .score-breakdown-group--working {
  border-color: var(--al-green) !important;
}

html[data-theme="dark"] .score-breakdown-row.is-priority {
  border-color: #f97316 !important;
}

html[data-theme="dark"] .score-breakdown-badge,
html[data-theme="dark"] .status-pill,
html[data-theme="dark"] .chip,
html[data-theme="dark"] .evidence-cue {
  background: var(--al-surface-3) !important;
  color: var(--al-blue-soft) !important;
  border: 1px solid var(--al-border-2) !important;
}

html[data-theme="dark"] .score-breakdown-badge--low,
html[data-theme="dark"] .review-queue-status-pill--urgent,
html[data-theme="dark"] .history-score-label--urgent,
html[data-theme="dark"] .history-weak-spot--urgent {
  background: #451a03 !important;
  color: var(--al-orange-soft) !important;
  border-color: #92400e !important;
}

html[data-theme="dark"] .score-breakdown-badge--medium {
  background: #422006 !important;
  color: #fde68a !important;
  border-color: #ca8a04 !important;
}

html[data-theme="dark"] .score-breakdown-badge--high {
  background: #064e3b !important;
  color: var(--al-green-soft) !important;
  border-color: var(--al-green) !important;
}

/* Buttons */
html[data-theme="dark"] :is(.primary-button,[class*="primary-button"],[class*="improve-button"]) {
  background: var(--al-orange) !important;
  color: #fff7ed !important;
  border: 1px solid #fb923c !important;
  box-shadow: 0 12px 30px rgba(234, 88, 12, 0.22) !important;
}

html[data-theme="dark"] :is(.ghost-button,[class*="ghost-button"],[class*="secondary-button"],[class*="outline-button"]) {
  background: var(--al-surface-2) !important;
  color: var(--al-text) !important;
  border: 1px solid var(--al-border-2) !important;
  box-shadow: none !important;
}

html[data-theme="dark"] button:disabled,
html[data-theme="dark"] button[disabled],
html[data-theme="dark"] [aria-disabled="true"] {
  background: var(--al-surface-3) !important;
  color: #64748b !important;
  border-color: var(--al-border-2) !important;
  box-shadow: none !important;
  opacity: 1 !important;
}

/* Light Tailwind / scanner leftovers inside report pages */
html[data-theme="dark"] body:has(.report-section) :is(
  [class*="bg-white"],
  [class*="bg-gray-50"],
  [class*="bg-gray-100"],
  [class*="bg-slate-50"],
  [class*="bg-slate-100"],
  [class*="bg-orange-50"],
  [class*="bg-amber-50"],
  [data-al-dark-bg="surface"]
),
html[data-theme="dark"] body:has(.review-queue-summary) :is(
  [class*="bg-white"],
  [class*="bg-gray-50"],
  [class*="bg-gray-100"],
  [class*="bg-slate-50"],
  [class*="bg-slate-100"],
  [class*="bg-orange-50"],
  [class*="bg-amber-50"],
  [data-al-dark-bg="surface"]
) {
  background: var(--al-surface) !important;
  background-image: none !important;
  color: var(--al-text) !important;
  border-color: var(--al-border-2) !important;
}

html[data-theme="dark"] body:has(.report-section) :is([data-al-dark-text="dark"],[class*="text-gray-900"],[class*="text-slate-900"]),
html[data-theme="dark"] body:has(.review-queue-summary) :is([data-al-dark-text="dark"],[class*="text-gray-900"],[class*="text-slate-900"]) {
  color: var(--al-text) !important;
}

html[data-theme="dark"] body:has(.report-section) :is([data-al-dark-text="muted"],[class*="text-gray-500"],[class*="text-slate-500"]),
html[data-theme="dark"] body:has(.review-queue-summary) :is([data-al-dark-text="muted"],[class*="text-gray-500"],[class*="text-slate-500"]) {
  color: var(--al-muted) !important;
}

html[data-theme="dark"] body:has(.report-section) [data-al-dark-border],
html[data-theme="dark"] body:has(.review-queue-summary) [data-al-dark-border] {
  border-color: var(--al-border-2) !important;
}

/* Report dark audit outlines, only when enabled from console */
html[data-theme="dark"] body.al-show-light-report-audit .al-report-light-leftover {
  outline: 3px solid #ef4444 !important;
  outline-offset: 2px !important;
}
