/* =============================================================
   CERIVIO · DARK-MODE READABILITY NORMALISER
   v0.17.0-vio-darkmode · 2026-08-14
   -------------------------------------------------------------
   WCAG AA compliant. Every muted text token is bumped so that
   contrast against the dark surface (var(--surface) ~ #0F172A /
   #161B22) meets or exceeds the 4.5:1 body-text minimum.
   -------------------------------------------------------------
   Load order · after cerivio-drawer.css on every SPA so that
   these tokens win over any theme-dark rules defined in the
   individual SPA <style> blocks. Central, reusable, ~90 LOC.
   ============================================================= */
body.theme-dark {
  /* Canonical muted-text tokens · every SPA now shares them. */
  --text-muted:   #94A3B8;   /* 6.35:1 on #0F172A · AA body pass    */
  --text-muted-2: #CBD5E1;   /* 11.8:1 · AAA · critical microcopy   */
  --text-caption: #B7C3D1;   /* 8.6:1  · captions, byline, kickers  */
  --text-strong:  #E5E9EE;   /* 14:1   · headings / values          */
  --border:       rgba(148,163,184,0.24);
  --border-soft:  rgba(148,163,184,0.14);
}

/* ---- inline hex greys used across the buyer/seller/admin SPAs
   (case-insensitive matching not supported by [style*=] so we
   list the most common forms in both upper and mixed case) ---- */
body.theme-dark [style*="color:#64748B"],
body.theme-dark [style*="color: #64748B"],
body.theme-dark [style*="color:#64748b"],
body.theme-dark [style*="color: #64748b"],
body.theme-dark [style*="color:#6B7280"],
body.theme-dark [style*="color: #6B7280"],
body.theme-dark [style*="color:#6b7280"],
body.theme-dark [style*="color: #6b7280"],
body.theme-dark [style*="color:#71717A"],
body.theme-dark [style*="color: #71717A"],
body.theme-dark [style*="color:#71717a"],
body.theme-dark [style*="color: #71717a"],
body.theme-dark [style*="color:#94A3B8"],
body.theme-dark [style*="color: #94A3B8"],
body.theme-dark [style*="color:#94a3b8"],
body.theme-dark [style*="color: #94a3b8"],
body.theme-dark [style*="color:#9CA3AF"],
body.theme-dark [style*="color: #9CA3AF"],
body.theme-dark [style*="color:#9ca3af"],
body.theme-dark [style*="color: #9ca3af"] { color: var(--text-muted) !important; }

/* CSS custom-property references resolve automatically via the
   token overrides above — no per-selector work required.        */

/* Very small microcopy (<= 11px) needs the higher-contrast tier. */
body.theme-dark [style*="font-size:10px"],
body.theme-dark [style*="font-size: 10px"],
body.theme-dark [style*="font-size:10.5px"],
body.theme-dark [style*="font-size: 10.5px"],
body.theme-dark [style*="font-size:11px"],
body.theme-dark [style*="font-size: 11px"],
body.theme-dark .microcopy,
body.theme-dark .caption,
body.theme-dark .card-subtitle,
body.theme-dark .kpi-delta,
body.theme-dark .kpi-label,
body.theme-dark .page-subtitle,
body.theme-dark .v013-sub,
body.theme-dark .ch-info,
body.theme-dark .synth-pill,
body.theme-dark .real-pill,
body.theme-dark .wired-pill { color: var(--text-caption) !important; }

/* Headings, KPI values and card titles stay bright. */
body.theme-dark .kpi-value,
body.theme-dark .card-h,
body.theme-dark .v013-val,
body.theme-dark .v013-label { color: var(--text-strong) !important; }

/* Legal / draft ribbon at bottom of every SPA. */
body.theme-dark .ce-legal-strip .toggle,
body.theme-dark .ce-legal-strip .menu,
body.theme-dark .ce-legal-strip .menu a,
body.theme-dark .ce-legal-strip .menu .h,
body.theme-dark .ce-legal-strip .menu .sub,
body.theme-dark .legal-ribbon,
body.theme-dark [class*="legal"][class*="ribbon"],
body.theme-dark [class*="legal"][class*="strip"] { color: var(--text-muted-2) !important; }

/* Form control placeholders. */
body.theme-dark input::placeholder,
body.theme-dark textarea::placeholder,
body.theme-dark select { color: var(--text-muted) !important; }

/* Lineage panels & fine-print rows. */
body.theme-dark .lineage-panel summary,
body.theme-dark .lineage-body,
body.theme-dark .lineage-source,
body.theme-dark .lineage-etl,
body.theme-dark .lineage-field td { color: var(--text-caption) !important; }

/* =============================================================
   v0.18-36 · FULL-SOFTWARE DARK CONTRAST PASS · 2026-08-21
   Driven by an automated in-DOM contrast audit across every
   panel of all 4 SPAs (118 offenders in buyer alone).
   Two root causes, fixed centrally here:

   A · INLINE LIGHT BACKGROUNDS survive into dark mode while the
       text tokens flip light → light-on-light (worst: 35× light
       blue links on background:#fff cards).
   B · INLINE DARK INK COLOURS stay dark on dark surfaces
       (e.g. color:#0F172A headings · color:#78350F amber notes).
   ============================================================= */

/* ---- A1 · pure white card/section backgrounds → dark surface */
body.theme-dark [style*="background:#fff"],
body.theme-dark [style*="background: #fff"],
body.theme-dark [style*="background:#FFF"],
body.theme-dark [style*="background: #FFF"],
body.theme-dark [style*="background:#FFFFFF"],
body.theme-dark [style*="background: #FFFFFF"],
body.theme-dark [style*="background-color:#fff"],
body.theme-dark [style*="background-color: #fff"],
body.theme-dark [style*="background-color:#FFFFFF"],
body.theme-dark [style*="background-color: #FFFFFF"] {
  background-color: var(--surface-2, #161B22) !important;
}

/* ---- A2 · light grey surfaces → slightly raised dark surface */
body.theme-dark [style*="background:#F8FAFC"],
body.theme-dark [style*="background: #F8FAFC"],
body.theme-dark [style*="background-color:#F8FAFC"],
body.theme-dark [style*="background-color: #F8FAFC"],
body.theme-dark [style*="background:#F1F5F9"],
body.theme-dark [style*="background: #F1F5F9"],
body.theme-dark [style*="background-color:#F1F5F9"],
body.theme-dark [style*="background-color: #F1F5F9"],
body.theme-dark [style*="background:#FAFBFC"],
body.theme-dark [style*="background: #FAFBFC"],
body.theme-dark [style*="background:#F7FAFC"],
body.theme-dark [style*="background: #F7FAFC"],
body.theme-dark [style*="background:#F3F4F6"],
body.theme-dark [style*="background: #F3F4F6"],
body.theme-dark [style*="background:#F9FAFB"],
body.theme-dark [style*="background: #F9FAFB"] {
  background-color: rgba(148, 163, 184, 0.08) !important;
}

/* ---- A3 · coloured soft backgrounds → translucent dark tints
        (keeps the semantic colour cue · readable light text) --- */
body.theme-dark [style*="background:#D1FAE5"],
body.theme-dark [style*="background: #D1FAE5"],
body.theme-dark [style*="background:#F0FDF4"],
body.theme-dark [style*="background: #F0FDF4"],
body.theme-dark [style*="background-color:#D1FAE5"],
body.theme-dark [style*="background-color: #D1FAE5"] {
  background-color: rgba(45, 212, 160, 0.14) !important;
}
body.theme-dark [style*="background:#FEF3C7"],
body.theme-dark [style*="background: #FEF3C7"],
body.theme-dark [style*="background:#FFF7ED"],
body.theme-dark [style*="background: #FFF7ED"],
body.theme-dark [style*="background:#FFFBEB"],
body.theme-dark [style*="background: #FFFBEB"] {
  background-color: rgba(245, 158, 11, 0.14) !important;
}
body.theme-dark [style*="background:#FEE2E2"],
body.theme-dark [style*="background: #FEE2E2"],
body.theme-dark [style*="background:#FEF2F2"],
body.theme-dark [style*="background: #FEF2F2"] {
  background-color: rgba(220, 38, 38, 0.14) !important;
}
body.theme-dark [style*="background:#EFF6FF"],
body.theme-dark [style*="background: #EFF6FF"],
body.theme-dark [style*="background:#DBEAFE"],
body.theme-dark [style*="background: #DBEAFE"] {
  background-color: rgba(59, 130, 246, 0.14) !important;
}
body.theme-dark [style*="background:#F3E8FF"],
body.theme-dark [style*="background: #F3E8FF"] {
  background-color: rgba(139, 92, 246, 0.16) !important;
}

/* ---- B1 · dark ink text → strong light text ------------------ */
body.theme-dark [style*="color:#0F172A"],
body.theme-dark [style*="color: #0F172A"],
body.theme-dark [style*="color:#0f172a"],
body.theme-dark [style*="color: #0f172a"],
body.theme-dark [style*="color:#0D1117"],
body.theme-dark [style*="color: #0D1117"],
body.theme-dark [style*="color:#111827"],
body.theme-dark [style*="color: #111827"],
body.theme-dark [style*="color:#1E293B"],
body.theme-dark [style*="color: #1E293B"] {
  color: var(--text-strong, #E5E9EE) !important;
}
body.theme-dark [style*="color:#334155"],
body.theme-dark [style*="color: #334155"] {
  color: var(--text-caption, #B7C3D1) !important;
}

/* ---- B2 · dark semantic colours → light equivalents ---------- */
body.theme-dark [style*="color:#78350F"],
body.theme-dark [style*="color: #78350F"],
body.theme-dark [style*="color:#92400E"],
body.theme-dark [style*="color: #92400E"],
body.theme-dark [style*="color:#B45309"],
body.theme-dark [style*="color: #B45309"] {
  color: #FCD34D !important;
}
body.theme-dark [style*="color:#065F46"],
body.theme-dark [style*="color: #065F46"],
body.theme-dark [style*="color:#047857"],
body.theme-dark [style*="color: #047857"] {
  color: #6EE7B7 !important;
}
body.theme-dark [style*="color:#1E3A8A"],
body.theme-dark [style*="color: #1E3A8A"],
body.theme-dark [style*="color:#1D4ED8"],
body.theme-dark [style*="color: #1D4ED8"],
body.theme-dark [style*="color:#1a5eb8"],
body.theme-dark [style*="color: #1a5eb8"] {
  color: #93C5FD !important;
}
body.theme-dark [style*="color:#991B1B"],
body.theme-dark [style*="color: #991B1B"],
body.theme-dark [style*="color:#7F1D1D"],
body.theme-dark [style*="color: #7F1D1D"] {
  color: #FCA5A5 !important;
}

/* ---- v0.18-36b · class-based light buttons (all 4 SPAs define
        .btn-secondary{background:white} · dark text-token flip
        left light-blue text on a white pill · 35× in buyer alone) */
body.theme-dark .btn-secondary {
  background: rgba(148, 163, 184, 0.10) !important;
  color: #A8C8FF !important;
  border-color: rgba(148, 163, 184, 0.35) !important;
}
body.theme-dark .btn-secondary:hover {
  background: rgba(148, 163, 184, 0.18) !important;
}

/* ---- v0.18-36c · residuals from the corrected (alpha-composited)
        audit · 12 remaining offenders in buyer ------------------- */
/* blue-800 uppercase hex variant missed in B2 */
body.theme-dark [style*="color:#1A5EB8"],
body.theme-dark [style*="color: #1A5EB8"] { color: #93C5FD !important; }
/* solid-mint buttons must keep DARK ink text · token flip made it light */
body.theme-dark .btn-mint,
body.theme-dark [style*="background:var(--mint)"] ,
body.theme-dark [style*="background: var(--mint)"] {
  color: #0D1117 !important;
}
/* half-transparent white overlays (planner cards) → dark equivalent */
body.theme-dark [style*="background:rgba(255,255,255,0.5)"],
body.theme-dark [style*="background: rgba(255,255,255,0.5)"],
body.theme-dark [style*="background:rgba(255, 255, 255, 0.5)"],
body.theme-dark [style*="background: rgba(255, 255, 255, 0.5)"] {
  background-color: rgba(148, 163, 184, 0.10) !important;
}
/* dark semantic badge colours on tints · lift to light equivalents */
body.theme-dark [style*="color:#0F7A52"],
body.theme-dark [style*="color: #0F7A52"] { color: #34D399 !important; }
body.theme-dark [style*="color:#A06208"],
body.theme-dark [style*="color: #A06208"] { color: #FBBF24 !important; }

/* ---- v0.18-36d · seller-portal residuals + B1 over-application fix.
        Elements with LIGHT ACCENT backgrounds (mint/amber pills+buttons)
        carry inline color:#0F172A which B1 flipped light → light-on-light.
        These rules come AFTER B1 so they win at equal specificity. ------ */
body.theme-dark [style*="background:#2DD4A0"],
body.theme-dark [style*="background: #2DD4A0"],
body.theme-dark [style*="background-color:#2DD4A0"],
body.theme-dark [style*="background-color: #2DD4A0"],
body.theme-dark [style*="background:#FCD34D"],
body.theme-dark [style*="background: #FCD34D"],
body.theme-dark [style*="background:#FDE68A"],
body.theme-dark [style*="background: #FDE68A"],
body.theme-dark [style*="background:#6EE7B7"],
body.theme-dark [style*="background: #6EE7B7"] {
  color: #0D1117 !important;
}

/* near-black inline/inherited ink · seller topbar + empty states */
body.theme-dark [style*="color:#0F141B"],
body.theme-dark [style*="color: #0F141B"] { color: var(--text-strong, #E5E9EE) !important; }

/* dark navy HELD pills · text + border lift */
body.theme-dark [style*="color:#0A2F66"],
body.theme-dark [style*="color: #0A2F66"] {
  color: #93C5FD !important;
  border-color: rgba(147, 197, 253, 0.45) !important;
}

/* violet-800 amounts + violet-soft backgrounds */
body.theme-dark [style*="color:#5B21B6"],
body.theme-dark [style*="color: #5B21B6"] { color: #C4B5FD !important; }
body.theme-dark [style*="background:#EDE9FE"],
body.theme-dark [style*="background: #EDE9FE"],
body.theme-dark [style*="background:#F5F3FF"],
body.theme-dark [style*="background: #F5F3FF"] {
  background-color: rgba(139, 92, 246, 0.16) !important;
}

/* ---- v0.18-36e · admin residuals -------------------------------- */
/* --ink token · SPAs use color:var(--ink) for primary text but no
   SPA flips the token in dark theme · ink text vanished on dark
   surfaces (8× in admin lumen-decomp alone). Mint-background
   buttons keep dark text via the !important rules in 36b/36d. */
body.theme-dark { --ink: #E5E9EE; }
/* dark navy escalation pills (DSA moderation) */
body.theme-dark [style*="color:#0F3F8A"],
body.theme-dark [style*="color: #0F3F8A"] {
  color: #93C5FD !important;
  border-color: rgba(147, 197, 253, 0.45) !important;
}

/* ---- v0.18-36f · admin block-tabs · light chip + active-white fixes */
body.theme-dark .bt-count {
  background: rgba(148, 163, 184, 0.18) !important;
  color: var(--text-muted, #94A3B8) !important;
}
body.theme-dark .block-tab.active {
  background: rgba(148, 163, 184, 0.14) !important;
  color: var(--text-strong, #E5E9EE) !important;
}
body.theme-dark .block-tab:hover {
  background: rgba(148, 163, 184, 0.10) !important;
  color: var(--text-strong, #E5E9EE) !important;
}
body.theme-dark .block-tab.active .bt-count {
  background: rgba(45, 212, 160, 0.20) !important;
  color: #6EE7B7 !important;
}

/* block-tab GROUP rail keeps a light class background in dark ·
   flips the whole tab strip dark + bumps idle tab text */
body.theme-dark .block-tab-group {
  background: rgba(148, 163, 184, 0.08) !important;
}
body.theme-dark .block-tab {
  color: var(--text-caption, #B7C3D1);
}
