/* Smart Fin Reports — 5.4.15.3 Theme Contrast Contract
 * Purpose: one deterministic light/dark contract for platform chrome, tools,
 * semantic badges, step numbers and report documents.
 * This layer is visual only: no dimensions, calculations, storage or accounting
 * behavior are changed. It intentionally loads after tool CSS and typography. */

:root{
  --sfr-theme-bg:#f8fafc;
  --sfr-theme-surface:#ffffff;
  --sfr-theme-surface-2:#f1f5f9;
  --sfr-theme-surface-3:#e2e8f0;
  --sfr-theme-text:#0f172a;
  --sfr-theme-muted:#526179;
  --sfr-theme-border:#cbd5e1;
  --sfr-theme-control:#ffffff;
  --sfr-theme-focus:#3b82f6;
  --sfr-theme-success-bg:#dcfce7;
  --sfr-theme-success-text:#166534;
  --sfr-theme-warning-bg:#fef3c7;
  --sfr-theme-warning-text:#92400e;
  --sfr-theme-danger-bg:#fee2e2;
  --sfr-theme-danger-text:#991b1b;
  --sfr-theme-info-bg:#dbeafe;
  --sfr-theme-info-text:#1e3a8a;
}
html[data-sfr-theme="dark"],html[data-theme="dark"]{
  color-scheme:dark;
  --sfr-theme-bg:#07111f;
  --sfr-theme-surface:#0f1d31;
  --sfr-theme-surface-2:#14263d;
  --sfr-theme-surface-3:#1b304b;
  --sfr-theme-text:#f8fafc;
  --sfr-theme-muted:#c0cede;
  --sfr-theme-border:#3b5878;
  --sfr-theme-control:#0b192a;
  --sfr-theme-focus:#60a5fa;
  --sfr-theme-success-bg:rgba(16,185,129,.18);
  --sfr-theme-success-text:#86efac;
  --sfr-theme-warning-bg:rgba(245,158,11,.18);
  --sfr-theme-warning-text:#fde68a;
  --sfr-theme-danger-bg:rgba(239,68,68,.18);
  --sfr-theme-danger-text:#fca5a5;
  --sfr-theme-info-bg:rgba(59,130,246,.20);
  --sfr-theme-info-text:#bfdbfe;
}

html[data-sfr-theme="dark"],html[data-sfr-theme="dark"] body,
html[data-theme="dark"],html[data-theme="dark"] body{
  background:#07111f!important;
}
html[data-sfr-theme="light"],html[data-sfr-theme="light"] body,
html[data-theme="light"],html[data-theme="light"] body{
  background:#f8fafc!important;
}

/* Make the root a real theme provider. Several historic tool sheets expect
 * data-theme on the platform root rather than only on html/body. */
#sfr-platform-root{
  --sfr-bg:var(--sfr-theme-bg);
  --sfr-surface:var(--sfr-theme-surface);
  --sfr-surface-muted:var(--sfr-theme-surface-2);
  --sfr-card:var(--sfr-theme-surface);
  --sfr-text:var(--sfr-theme-text);
  --sfr-muted:var(--sfr-theme-muted);
  --sfr-border:var(--sfr-theme-border);
  background:var(--sfr-theme-bg);
  color:var(--sfr-theme-text);
}
html[data-sfr-theme="dark"] #sfr-platform-root,
#sfr-platform-root[data-sfr-theme="dark"],#sfr-platform-root[data-theme="dark"]{
  color-scheme:dark;
  --sfr-bg:var(--sfr-theme-bg)!important;
  --sfr-surface:var(--sfr-theme-surface)!important;
  --sfr-surface-muted:var(--sfr-theme-surface-2)!important;
  --sfr-card:var(--sfr-theme-surface)!important;
  --sfr-text:var(--sfr-theme-text)!important;
  --sfr-muted:var(--sfr-theme-muted)!important;
  --sfr-border:var(--sfr-theme-border)!important;
}
html[data-sfr-theme="light"] #sfr-platform-root,
#sfr-platform-root[data-sfr-theme="light"],#sfr-platform-root[data-theme="light"]{
  color-scheme:light;
}

/* Tool-level baseline. Tool-specific semantic variables still win where they
 * are correct; these values close gaps left by sheets that only define light. */
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root],
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root]{
  color:var(--sfr-theme-text);
  --text:var(--sfr-theme-text);
  --muted:var(--sfr-theme-muted);
  --line:var(--sfr-theme-border);
  --card:var(--sfr-theme-surface);
  --surface:var(--sfr-theme-surface);
  --soft:var(--sfr-theme-surface-2);
}

/* Form controls must never inherit a pale foreground or transparent white
 * surface in dark mode. Primary/semantic buttons are intentionally excluded. */
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] :where(input,select,textarea),
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] :where(input,select,textarea){
  background-color:var(--sfr-theme-control);
  color:var(--sfr-theme-text);
  border-color:var(--sfr-theme-border);
  caret-color:#93c5fd;
}
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] :where(input,textarea)::placeholder,
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] :where(input,textarea)::placeholder{
  color:#94a3b8!important;
  opacity:1!important;
}
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] select option,
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] select option{
  background:#0b192a;
  color:#f8fafc;
}
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] :where(input,select,textarea):focus-visible,
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] :where(input,select,textarea):focus-visible{
  outline:3px solid rgba(96,165,250,.34);
  outline-offset:1px;
  border-color:#60a5fa;
}
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] button:not([class*="primary"]):not([class*="success"]):not([class*="danger"]):not([class*="warning"]):not([class*="accent"]):not([class*="active"]),
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] button:not([class*="primary"]):not([class*="success"]):not([class*="danger"]):not([class*="warning"]):not([class*="accent"]):not([class*="active"]){
  color:var(--sfr-theme-text);
  border-color:var(--sfr-theme-border);
}
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] button:disabled,
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] button:disabled{
  opacity:.62!important;
  color:#cbd5e1!important;
}
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] :where(button,a,[role="button"]):focus-visible,
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] :where(button,a,[role="button"]):focus-visible{
  outline:3px solid rgba(96,165,250,.42)!important;
  outline-offset:2px!important;
}

/* Tables are a common source of pale-on-pale collisions. This baseline leaves
 * branded header fills intact while guaranteeing readable body cells. */
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] table:not(:where([data-sfr-document-theme="light"] table)),
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] table:not(:where([data-sfr-document-theme="light"] table)){
  color:var(--sfr-theme-text);
  border-color:var(--sfr-theme-border);
}
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] table:not(:where([data-sfr-document-theme="light"] table)) :where(td,th),
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] table:not(:where([data-sfr-document-theme="light"] table)) :where(td,th){
  border-color:var(--sfr-theme-border);
}
html[data-sfr-theme="dark"] #sfr-platform-root [data-sfr-module-root] table:not(:where([data-sfr-document-theme="light"] table)) tbody tr:nth-child(even) td,
#sfr-platform-root[data-theme="dark"] [data-sfr-module-root] table:not(:where([data-sfr-document-theme="light"] table)) tbody tr:nth-child(even) td{
  background-color:rgba(148,163,184,.055);
}

/* Runtime contrast audit classes. Only neutral light leaks and genuinely low
 * text contrast receive these classes; branded/semantic colors are preserved. */
html[data-sfr-theme="dark"] #sfr-platform-root .sfr-theme-light-leak:not(:where([data-sfr-document-theme="light"],[data-sfr-document-theme="light"] *)),
#sfr-platform-root[data-theme="dark"] .sfr-theme-light-leak:not(:where([data-sfr-document-theme="light"],[data-sfr-document-theme="light"] *)){
  background-color:var(--sfr-theme-surface-2)!important;
  background-image:none!important;
  color:var(--sfr-theme-text)!important;
  border-color:var(--sfr-theme-border)!important;
  -webkit-text-fill-color:currentColor!important;
}
html[data-sfr-theme="dark"] #sfr-platform-root .sfr-theme-low-contrast:not(:where([data-sfr-document-theme="light"],[data-sfr-document-theme="light"] *)),
#sfr-platform-root[data-theme="dark"] .sfr-theme-low-contrast:not(:where([data-sfr-document-theme="light"],[data-sfr-document-theme="light"] *)){
  color:var(--sfr-theme-text)!important;
  -webkit-text-fill-color:var(--sfr-theme-text)!important;
  opacity:1!important;
}
html[data-sfr-theme="dark"] #sfr-platform-root .sfr-theme-muted-contrast:not(:where([data-sfr-document-theme="light"],[data-sfr-document-theme="light"] *)),
#sfr-platform-root[data-theme="dark"] .sfr-theme-muted-contrast:not(:where([data-sfr-document-theme="light"],[data-sfr-document-theme="light"] *)){
  color:var(--sfr-theme-muted)!important;
  -webkit-text-fill-color:var(--sfr-theme-muted)!important;
  opacity:1!important;
}

/* Status badges, notes and ranking/step numbers use explicit foreground and
 * background pairs in both themes. */
#sfr-platform-root [data-sfr-contrast-tone="success"]{
  background:var(--sfr-theme-success-bg)!important;
  color:var(--sfr-theme-success-text)!important;
  border-color:color-mix(in srgb,var(--sfr-theme-success-text) 42%,transparent)!important;
  -webkit-text-fill-color:var(--sfr-theme-success-text)!important;
}
#sfr-platform-root [data-sfr-contrast-tone="warning"]{
  background:var(--sfr-theme-warning-bg)!important;
  color:var(--sfr-theme-warning-text)!important;
  border-color:color-mix(in srgb,var(--sfr-theme-warning-text) 42%,transparent)!important;
  -webkit-text-fill-color:var(--sfr-theme-warning-text)!important;
}
#sfr-platform-root [data-sfr-contrast-tone="danger"]{
  background:var(--sfr-theme-danger-bg)!important;
  color:var(--sfr-theme-danger-text)!important;
  border-color:color-mix(in srgb,var(--sfr-theme-danger-text) 42%,transparent)!important;
  -webkit-text-fill-color:var(--sfr-theme-danger-text)!important;
}
#sfr-platform-root [data-sfr-contrast-tone="info"],
#sfr-platform-root [data-sfr-contrast-tone="neutral"]{
  background:var(--sfr-theme-info-bg)!important;
  color:var(--sfr-theme-info-text)!important;
  border-color:color-mix(in srgb,var(--sfr-theme-info-text) 38%,transparent)!important;
  -webkit-text-fill-color:var(--sfr-theme-info-text)!important;
}
#sfr-platform-root [data-sfr-contrast-tone] :where(span,strong,b,small,i){color:inherit!important;-webkit-text-fill-color:currentColor!important}

#sfr-platform-root .sfr-theme-step-number{
  display:inline-grid;
  place-items:center;
  min-width:30px;
  min-height:30px;
  background:#dbeafe!important;
  color:#1e3a8a!important;
  border:1px solid #93c5fd!important;
  -webkit-text-fill-color:#1e3a8a!important;
}
html[data-sfr-theme="dark"] #sfr-platform-root .sfr-theme-step-number,
#sfr-platform-root[data-theme="dark"] .sfr-theme-step-number{
  background:#17345a!important;
  color:#dbeafe!important;
  border-color:#4f78aa!important;
  -webkit-text-fill-color:#dbeafe!important;
}
#sfr-platform-root .sfr-theme-step-number:is(.active,.is-active,[aria-current="step"]),
#sfr-platform-root :is(.active,.is-active,[aria-current="step"])>.sfr-theme-step-number{
  background:#1e3a8a!important;
  color:#fff!important;
  border-color:#3b82f6!important;
  -webkit-text-fill-color:#fff!important;
}
#sfr-platform-root .sfr-theme-step-number:is(.complete,.completed,.is-complete,.is-completed),
#sfr-platform-root :is(.complete,.completed,.is-complete,.is-completed)>.sfr-theme-step-number{
  background:#047857!important;
  color:#fff!important;
  border-color:#10b981!important;
  -webkit-text-fill-color:#fff!important;
}

/* Explicit light-document contract. Applied only when a tool deliberately sets
 * data-sfr-document-theme="light"; no report is classified automatically. */
#sfr-platform-root [data-sfr-document-theme="light"]{
  color-scheme:light!important;
  --sfr-bg:#ffffff!important;
  --sfr-surface:#ffffff!important;
  --sfr-surface-muted:#f8fafc!important;
  --sfr-card:#ffffff!important;
  --sfr-text:#0f172a!important;
  --sfr-muted:#526179!important;
  --sfr-border:#cbd5e1!important;
  background:#ffffff!important;
  color:#0f172a!important;
  border-color:#cbd5e1!important;
  -webkit-text-fill-color:initial!important;
}
#sfr-platform-root [data-sfr-document-theme="light"] :where(h1,h2,h3,h4,h5,h6,strong,b){color:#173b67}
#sfr-platform-root [data-sfr-document-theme="light"] :where(p,li,dt,dd,label,td,caption){color:#334155}
#sfr-platform-root [data-sfr-document-theme="light"] :where(small,.muted,[class*="muted"],[class*="meta"] span){color:#526179}
#sfr-platform-root [data-sfr-document-theme="light"] :where(table){background:#fff;color:#0f172a;border-color:#cbd5e1}
#sfr-platform-root [data-sfr-document-theme="light"] :where(td){background:#fff;color:#0f172a;border-color:#cbd5e1}
#sfr-platform-root [data-sfr-document-theme="light"] :where(th){background:#1e3a8a;color:#fff;border-color:#94a3b8}
#sfr-platform-root [data-sfr-document-theme="light"] :where(th *){color:#fff!important;-webkit-text-fill-color:#fff!important}
#sfr-platform-root [data-sfr-document-theme="light"] :where(input,select,textarea){background:#fff;color:#0f172a;border-color:#94a3b8}
#sfr-platform-root [data-sfr-document-theme="light"] .sfr-theme-light-leak{background:inherit!important;color:inherit!important}

@media print{
  html,body,#sfr-platform-root{background:#fff!important;color:#0f172a!important;color-scheme:light!important}
  #sfr-platform-root [data-sfr-document-theme="light"]{box-shadow:none!important;background:#fff!important;color:#0f172a!important}
  #sfr-platform-root .sfr-theme-light-leak,#sfr-platform-root .sfr-theme-low-contrast,#sfr-platform-root .sfr-theme-muted-contrast{-webkit-text-fill-color:initial!important}
}

@media (prefers-contrast:more){
  #sfr-platform-root{--sfr-theme-border:#64748b}
  html[data-sfr-theme="dark"] #sfr-platform-root{--sfr-theme-border:#6f8bad}
}
