/* =========================================================================
   Access·Lens, dark mode
   Activated by html.theme-dark (set by assets/theme.js from the saved
   choice, or from prefers-color-scheme when there is none).
   Palette keeps the brand (rose / plum / hot) and every text pairing
   passes WCAG 2.2 AA (4.5:1) against the dark surfaces.
   The class is deliberately NOT prefixed "al-" so the comfort toolbar,
   which strips al-* classes, never removes it.
   ========================================================================= */

html.theme-dark{
  color-scheme: dark;
  --dm-bg:        #17131A;  /* page background (was paper)          */
  --dm-surface:   #221C26;  /* cards, inputs (was white)            */
  --dm-surface-2: #2C2431;  /* raised / mist                         */
  --dm-deep:      #0E0B10;  /* blocks that were ink                  */
  --dm-text:      #F3ECEF;  /* body text (was ink)       15.6:1      */
  --dm-text-2:    #E3D8DE;  /* smoke                     13.0:1      */
  --dm-muted:     #BDB0B9;  /* ash                        8.9:1      */
  --dm-plum:      #D4AEDB;  /* plum as text               9.3:1      */
  --dm-hot:       #F47AA3;  /* hot as text                6.4:1      */
  --dm-violet:    #C4A8DC;
  --dm-border:    #5A4553;
  --dm-border-2:  #3E313B;

  --shadow-pink-sm: 3px 3px 0 0 #3D2A37;
  --shadow-pink:    5px 5px 0 0 #3D2A37;
  --shadow-pink-lg: 8px 8px 0 0 #3D2A37;
  --shadow-pink-soft: 0 8px 28px -8px rgba(0,0,0,.6);
  --border-pink:      var(--dm-border);
  --border-pink-soft: var(--dm-border-2);
  --border-soft:      rgba(90,69,83,.7);
  /* page-local tokens used by the content pages */
  --paper: #17131A; --ink: #F3ECEF; --ash: #BDB0B9;
  --pink: #3D2A37; --border: #5A4553; --softborder: #3E313B;
}
html.theme-dark .checkbox-list li{ color: var(--dm-text-2); }
html.theme-dark .phase-card{ background: var(--dm-surface); }

html.theme-dark, html.theme-dark body{ background: var(--dm-bg) !important; color: var(--dm-text) !important; }
html.theme-dark .grain::before{ opacity:.25; mix-blend-mode:screen; background-image: radial-gradient(rgba(255,255,255,.05) 1px, transparent 1px); }

/* ---------- Tailwind colour utilities ---------- */
html.theme-dark .bg-paper{ background-color: var(--dm-bg) !important; }
html.theme-dark .bg-white{ background-color: var(--dm-surface) !important; }
html.theme-dark [class*="bg-white/"]{ background-color: rgba(34,28,38,.85) !important; }
html.theme-dark [class*="bg-paper/"]{ background-color: rgba(23,19,26,.85) !important; }
html.theme-dark .bg-mist, html.theme-dark [class*="bg-mist/"]{ background-color: var(--dm-surface-2) !important; }
html.theme-dark .bg-ink, html.theme-dark .bg-smoke, html.theme-dark .bg-black{ background-color: var(--dm-deep) !important; border-color: var(--dm-border) !important; }
html.theme-dark [class*="bg-rose/"]{ background-color: rgba(242,166,187,.14) !important; }
html.theme-dark [class*="bg-gray-"], html.theme-dark [class*="bg-slate-"], html.theme-dark [class*="bg-neutral-"]{ background-color: var(--dm-surface-2) !important; }

html.theme-dark .text-ink, html.theme-dark .text-black{ color: var(--dm-text) !important; }
html.theme-dark .text-smoke{ color: var(--dm-text-2) !important; }
html.theme-dark .text-ash, html.theme-dark [class*="text-gray-"], html.theme-dark [class*="text-slate-"]{ color: var(--dm-muted) !important; }
html.theme-dark .text-plum{ color: var(--dm-plum) !important; }
html.theme-dark .text-hot{ color: var(--dm-hot) !important; }
html.theme-dark .text-violet{ color: var(--dm-violet) !important; }
/* text-paper stays light: it sits on plum / ink blocks, which stay dark */

html.theme-dark .border-borderpink, html.theme-dark [class*="border-borderpink/"],
html.theme-dark .border-pink, html.theme-dark [class*="border-gray-"]{ border-color: var(--dm-border) !important; }
html.theme-dark .border-borderpinkSoft, html.theme-dark [class*="border-borderpinkSoft/"],
html.theme-dark .border-mist{ border-color: var(--dm-border-2) !important; }
html.theme-dark .border-ink{ border-color: var(--dm-border) !important; }
html.theme-dark .border-plum{ border-color: var(--dm-plum) !important; }
html.theme-dark .divide-borderpinkSoft > * + *{ border-color: var(--dm-border-2) !important; }

html.theme-dark .shadow-pop, html.theme-dark .shadow-pink{ box-shadow: 6px 6px 0 0 #3D2A37 !important; }
html.theme-dark .shadow-popLg{ box-shadow: 10px 10px 0 0 #3D2A37 !important; }
html.theme-dark .shadow-soft{ box-shadow: 0 14px 36px -10px rgba(0,0,0,.6) !important; }

/* Light accent fills (rose, hot, violet, severity chips) keep dark text */
html.theme-dark .bg-rose, html.theme-dark .bg-hot, html.theme-dark .bg-violet,
html.theme-dark .sev-warn, html.theme-dark .sev-min, html.theme-dark .sev-ok{ color: #1F1A24 !important; }
html.theme-dark .bg-rose .text-ink, html.theme-dark .bg-rose.text-ink, html.theme-dark .bg-rose .text-ash,
html.theme-dark .bg-hot .text-ink,  html.theme-dark .bg-hot.text-ink,
html.theme-dark .bg-violet .text-ink, html.theme-dark .bg-violet.text-ink,
html.theme-dark .bg-rose .text-plum, html.theme-dark .bg-rose i{ color: #1F1A24 !important; }
html.theme-dark .bg-hot .bg-ink, html.theme-dark .bg-rose .bg-ink{ background-color:#1F1A24 !important; }

/* ---------- Components ---------- */
html.theme-dark .card-pop:not([class*="bg-"]){ background: var(--dm-surface); }
html.theme-dark .card-pop{ border-color: var(--dm-border); box-shadow: var(--shadow-pink-lg); }
html.theme-dark .card-pop:hover{ box-shadow: 10px 10px 0 0 #4A3343; }
html.theme-dark .btn-pop:hover{ box-shadow: 7px 7px 0 0 #4A3343; border-color: #7A5C6E; }
html.theme-dark .kbd{ background: var(--dm-surface); box-shadow: 2px 2px 0 0 #3D2A37; }
html.theme-dark .underline-pop{ background-image: linear-gradient(transparent 62%, rgba(242,166,187,.38) 62%); }
html.theme-dark #primaryNav{ background: var(--dm-bg); border-color: var(--dm-border); }
@media (min-width:1280px){ html.theme-dark #primaryNav{ background: transparent; } }
html.theme-dark .skip-link{ background: var(--dm-text); color: var(--dm-bg); }

html.theme-dark .fix-result{ background:#13291B; border-color:#3E8A58; color:#CDEBD7; }
html.theme-dark .fix-result pre{ background: var(--dm-deep); border-color:#2E5A3D; color:#CDEBD7; }

/* Forms */
html.theme-dark input:not([type="radio"]):not([type="checkbox"]):not([type="range"]),
html.theme-dark textarea, html.theme-dark select{
  background-color: var(--dm-surface) !important; color: var(--dm-text) !important; border-color: var(--dm-border) !important;
}
html.theme-dark ::placeholder{ color: #9C8E98 !important; opacity:1; }

/* Code / tables / misc */
html.theme-dark pre, html.theme-dark code{ background-color: var(--dm-deep); color: var(--dm-text-2); }
html.theme-dark hr{ border-color: var(--dm-border-2); }
html.theme-dark table th, html.theme-dark table td{ border-color: var(--dm-border-2); }
html.theme-dark details > summary{ color: inherit; }

/* Inline-styled surfaces produced by JS-rendered report markup */
html.theme-dark [style*="background:#fff" i], html.theme-dark [style*="background: #fff" i],
html.theme-dark [style*="background:#FFFFFF" i], html.theme-dark [style*="background: #FFFFFF" i],
html.theme-dark [style*="background:white" i], html.theme-dark [style*="background-color:#fff" i]{ background: var(--dm-surface) !important; }
html.theme-dark [style*="background:#F5F1F2" i], html.theme-dark [style*="background: #F5F1F2" i]{ background: var(--dm-bg) !important; }
html.theme-dark [style*="background:#E8E0E5" i], html.theme-dark [style*="background:#F5F5F5" i],
html.theme-dark [style*="background:#eee" i], html.theme-dark [style*="background:#E5DCEC" i],
html.theme-dark [style*="background:#FBD9E2" i], html.theme-dark [style*="background:#F4D9C9" i],
html.theme-dark [style*="background: #E8F5EC" i]{ background: var(--dm-surface-2) !important; color: var(--dm-text) !important; }
html.theme-dark [style*="color:#1F1A24" i], html.theme-dark [style*="color: #1F1A24" i]{ color: var(--dm-text) !important; }
html.theme-dark [style*="color:#524852" i]{ color: var(--dm-muted) !important; }
html.theme-dark [style*="color: #6B3A6E" i], html.theme-dark [style*="color:#6B3A6E" i]{ color: var(--dm-plum) !important; }
html.theme-dark [style*="border-color:#1F1A24" i]{ border-color: var(--dm-border) !important; }
/* …but keep dark text on light accent inline fills */
html.theme-dark [style*="background:#F2A6BB" i], html.theme-dark [style*="background: #F8C8D5" i],
html.theme-dark [style*="background:#E89B7E" i], html.theme-dark [style*="background:#C5B8D6" i],
html.theme-dark [style*="background:#FFC439" i]{ color:#1F1A24 !important; }

/* Comfort / reading toolbar */
html.theme-dark #comfortWidget{ border-color: var(--dm-border); }
html.theme-dark #comfortPanel{ background: var(--dm-surface); color: var(--dm-text); border-color: var(--dm-border); }
html.theme-dark #comfortPanel .ct-sub, html.theme-dark #comfortPanel .ct-label, html.theme-dark #comfortPanel .ct-close{ color: var(--dm-muted); }
html.theme-dark #comfortPanel .ct-btn, html.theme-dark #comfortPanel .ct-reset{ background: var(--dm-surface-2); color: var(--dm-text); border-color: var(--dm-border); }
html.theme-dark #comfortPanel .ct-btn:hover, html.theme-dark #comfortPanel .ct-reset:hover{ background: #3A2E38; }
html.theme-dark #comfortPanel .ct-btn[aria-pressed="true"]{ background:#6B3A6E; color:#F5F1F2; border-color:#D4AEDB; }

/* High-contrast comfort mode always wins over dark mode */
html.theme-dark.al-contrast-high body{ background:#000 !important; }

/* ---------- Theme toggle button (injected by theme.js) ---------- */
#themeToggle{
  position: fixed; left: 20px; bottom: 20px; z-index: 99999;
  width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: #F5F1F2; color: #1F1A24; border: 1.5px solid #E0AEC1;
  box-shadow: 3px 3px 0 0 #F8C8D5; font-size: 18px;
  transition: transform .25s cubic-bezier(.2,.8,.2,1);
}
#themeToggle:hover{ transform: scale(1.08); }
#themeToggle:focus-visible{ outline: 3px solid #E94B81; outline-offset: 4px; }
html.theme-dark #themeToggle{ background: var(--dm-surface); color: #F2A6BB; border-color: var(--dm-border); box-shadow: 3px 3px 0 0 #3D2A37; }
#themeToggle svg{ width: 20px; height: 20px; }
@media print{ #themeToggle{ display:none } }

/* ---------- AI-chat composer ---------- */
html.theme-dark .chat-box{ background: var(--dm-surface); border-color: var(--dm-border); box-shadow: 0 10px 30px -10px rgba(0,0,0,.7); }
html.theme-dark .chat-box:focus-within{ border-color: #F47AA3; box-shadow: 0 0 0 5px rgba(244,122,163,.22); }
html.theme-dark .chat-input{ background: transparent !important; color: var(--dm-text) !important; border: 0 !important; }
html.theme-dark .chat-send{ background: #F2A6BB; color: #1F1A24; }
html.theme-dark .chat-send:hover{ background: #F7BED0; }
html.theme-dark .chat-chip{ background: var(--dm-surface); border-color: var(--dm-border-2); color: var(--dm-text); }
html.theme-dark .chat-chip:hover{ border-color: var(--dm-border); background: var(--dm-surface-2); }
html.theme-dark .chat-chip i{ color: var(--dm-plum); }

/* ---------- Chat thread ---------- */
html.theme-dark .from-ai .chat-bubble{ background: var(--dm-surface); color: var(--dm-text); border-color: var(--dm-border-2); }
html.theme-dark .from-user .chat-bubble{ background: #6B3A6E; color: #F5F1F2; }
html.theme-dark .chat-body code{ background: var(--dm-deep); color: var(--dm-text-2); }
html.theme-dark .chat-body pre{ background: var(--dm-deep); border: 1px solid var(--dm-border-2); }
html.theme-dark .chat-body a{ color: var(--dm-plum); }
html.theme-dark .chat-status{ color: var(--dm-muted); }
