/* Evulgare RC47 semantic surface and visual-availability contract.

   This sheet is intentionally loaded after route-specific styles. Major theme
   boundaries own a foreground, background, body-text, accent, border, focus,
   and control-state palette. Route CSS may refine these values, but a section
   cannot depend on an unrelated page-level foreground crossing into it.
*/

:root {
  --surface-light-fg: var(--ink, #101820);
  --surface-light-bg: var(--paper, #f3f2ed);
  --surface-light-body: var(--muted-dark, #52636e);
  --surface-light-muted: #5f6d75;
  --surface-light-card: #faf9f5;
  --surface-light-border: #7c888e;
  --surface-light-border-strong: #44535b;
  --surface-light-accent: var(--cyan-deep, #126d79);
  --surface-light-focus: #126d79;

  --surface-dark-fg: #f3f2ed;
  --surface-dark-bg: #071016;
  --surface-dark-body: #c4ced4;
  --surface-dark-muted: #9cabb4;
  --surface-dark-card: #0b171f;
  --surface-dark-card-raised: #101f28;
  --surface-dark-callout: #09151d;
  --surface-dark-border: rgba(110, 208, 219, .30);
  --surface-dark-border-strong: rgba(110, 208, 219, .62);
  --surface-dark-accent: #77e4ec;
  --surface-dark-focus: #8cf2f7;

  --surface-graphite-fg: #f3f2ed;
  --surface-graphite-bg: #17242d;
  --surface-graphite-body: #c4ced4;
  --surface-graphite-card: #1d2d37;
  --surface-graphite-border: rgba(255, 255, 255, .22);

  /* Compatibility names used by route-level workbench styles. */
  --font-mono: var(--mono, ui-monospace, monospace);
  --font-sans: var(--sans, ui-sans-serif, sans-serif);
  --accent: var(--cyan, #6ed0db);
}

/* Major surfaces own both sides of the contrast relationship. */
.surface-light,
.section-light {
  color: var(--surface-light-fg);
  background-color: var(--surface-light-bg);
  color-scheme: light;
}

.surface-dark,
.section-dark {
  color: var(--surface-dark-fg);
  background-color: var(--surface-dark-bg);
  color-scheme: dark;
}

.surface-graphite,
.section-graphite {
  color: var(--surface-graphite-fg);
  background-color: var(--surface-graphite-bg);
  color-scheme: dark;
}

/* Zero-specificity descendant defaults protect inherited text without
   defeating a component's more specific, intentionally chosen palette. */
:where(.surface-light, .section-light) :where(p, li, dd, figcaption, blockquote) {
  color: var(--surface-light-body);
}
:where(.surface-dark, .section-dark) :where(p, li, dd, figcaption, blockquote),
:where(.surface-graphite, .section-graphite) :where(p, li, dd, figcaption, blockquote) {
  color: var(--surface-dark-body);
}
:where(.surface-light, .section-light) :where(h1, h2, h3, h4, h5, h6, strong, legend) {
  color: var(--surface-light-fg);
}
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) :where(h1, h2, h3, h4, h5, h6, strong, legend) {
  color: var(--surface-dark-fg);
}
:where(.surface-light, .section-light) .eyebrow { color: var(--surface-light-accent); }
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .eyebrow { color: var(--surface-dark-accent); }
:where(.surface-light, .section-light) .section-intro { color: var(--surface-light-body); }
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .section-intro { color: var(--surface-dark-body); }

/* Focus indicators must remain visible on both theme families. */
:where(.surface-light, .section-light) :focus-visible { outline-color: var(--surface-light-focus); }
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) :focus-visible { outline-color: var(--surface-dark-focus); }

/* Controls own their state colors. Ambient currentColor is never the sole
   source of button visibility on a theme boundary. */
:where(.surface-light, .section-light) .button-secondary {
  color: var(--surface-light-fg);
  background: transparent;
  border-color: var(--surface-light-border-strong);
}
:where(.surface-light, .section-light) .button-secondary:hover,
:where(.surface-light, .section-light) .button-secondary:focus-visible {
  color: var(--surface-light-bg);
  background: var(--surface-light-fg);
  border-color: var(--surface-light-fg);
}

:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .button-secondary {
  color: var(--surface-dark-fg);
  background: rgba(255, 255, 255, .025);
  border-color: var(--surface-dark-border-strong);
}
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .button-secondary:hover,
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .button-secondary:focus-visible {
  color: var(--surface-dark-bg);
  background: var(--surface-dark-fg);
  border-color: var(--surface-dark-fg);
}
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .button-quiet {
  color: var(--surface-dark-body);
  background: transparent;
  border-color: var(--surface-dark-border);
}
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .text-link {
  color: var(--surface-dark-accent);
  text-decoration-color: currentColor;
}
:where(.surface-light, .section-light) .text-link { color: var(--surface-light-accent); }

.button:is(:disabled, [aria-disabled="true"]),
[role="button"]:is([aria-disabled="true"], .is-disabled) {
  cursor: not-allowed;
  opacity: 1;
  color: #75838b;
  background: #26323a;
  border-color: #52616a;
  transform: none;
}
:where(.surface-light, .section-light) .button:is(:disabled, [aria-disabled="true"]),
:where(.surface-light, .section-light) [role="button"]:is([aria-disabled="true"], .is-disabled) {
  color: #5c6970;
  background: #d6d4cc;
  border-color: #7c888e;
}
.button[aria-busy="true"], .button.is-loading { cursor: progress; }
.button[aria-busy="true"]::after, .button.is-loading::after {
  content: "";
  width: .72rem;
  height: .72rem;
  margin-left: .55rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: evulgare-surface-spin .8s linear infinite;
}
@keyframes evulgare-surface-spin { to { transform: rotate(1turn); } }

/* Status chips use separate dark- and light-surface palettes. */
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .status-supported { color: #a9e8bd; background: rgba(91, 192, 128, .12); }
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .status-qualified { color: #ffd28a; background: rgba(214, 163, 75, .12); }
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .status-invalidated { color: #ffaaa7; background: rgba(217, 106, 103, .12); }

/* Reusable named component surfaces. */
.surface-card-light,
.surface-table-light,
.surface-dialog-light,
.surface-callout-light {
  color: var(--surface-light-fg);
  background: var(--surface-light-card);
  border-color: var(--surface-light-border);
  color-scheme: light;
}
.surface-card-dark,
.surface-table-dark,
.surface-dialog-dark,
.surface-callout-dark {
  color: var(--surface-dark-fg);
  background: var(--surface-dark-card);
  border-color: var(--surface-dark-border);
  color-scheme: dark;
}
:is(.surface-table-light, .surface-table-dark) :where(th, td) { border-color: currentColor; }
:is(.surface-dialog-light, .surface-dialog-dark)[open] { opacity: 1; visibility: visible; }

/* Explicit foreground ownership for established light components mounted
   inside dark page shells. */
.admin-page,
.admin-warning,
.defense-systems-page .defense-pillars article,
.defense-systems-page .defense-proof-grid a,
.confidential-release-review-page .crr-establishes-grid article,
.confidential-derivative-lineage-page .cdl-representations,
.confidential-derivative-lineage-page .cdl-representations th,
.eviulon-partnership-page .eviulon-contract-section,
.eviulon-partnership-page .eviulon-requirement-card,
.eviulon-partnership-page .eviulon-source-card,
.eviulon-partnership-page .source-difference-summary > div,
.release-acceptance-page .acceptance-card,
.release-acceptance-page .acceptance-checks li,
.release-acceptance-page .acceptance-artifacts li,
.release-acceptance-page .qualification-note,
.simulation-explorer-page .sim-filter-bar label,
.simulation-explorer-page .sim-filter-summary,
.simulation-explorer-page .sim-explorer-card,
.simulation-workbench-page .sim-wb-representations,
.simulation-workbench-page .sim-wb-tabs,
.simulation-workbench-page .sim-wb-tabs button,
.simulation-workbench-page .sim-wb-metric,
.simulation-workbench-page .sim-wb-compare-column,
.simulation-workbench-page .sim-wb-difference,
.simulation-workbench-page .sim-wb-event-log button {
  color: var(--surface-light-fg);
  color-scheme: light;
}

/* Compact traceability index after the simulation workbench. */
.section-light .compact-link-grid a {
  min-height: 5rem;
  align-items: center;
  color: var(--surface-light-fg);
  background: var(--surface-light-card);
  border-color: var(--surface-light-border);
  font-weight: 720;
  line-height: 1.35;
}
.section-light .compact-link-grid a .mono,
.section-light .compact-link-grid a b { color: var(--surface-light-accent); }
.section-light .compact-link-grid a:hover,
.section-light .compact-link-grid a:focus-visible {
  color: var(--surface-light-fg);
  background: var(--cyan, #6ed0db);
  border-color: var(--surface-light-fg);
}
.section-light .compact-link-grid a:hover .mono,
.section-light .compact-link-grid a:hover b,
.section-light .compact-link-grid a:focus-visible .mono,
.section-light .compact-link-grid a:focus-visible b { color: var(--surface-light-fg); }

.simulation-workbench-page .section-light { padding-block: clamp(2.75rem, 5vw, 5rem); }
.simulation-workbench-page .section-light .split-heading {
  align-items: center;
  gap: clamp(1.25rem, 3vw, 2.75rem);
  margin-bottom: 1.5rem;
}
.simulation-workbench-page .section-light .split-heading h2 {
  max-width: 20ch;
  font-size: clamp(2rem, 3.45vw, 3.75rem);
  line-height: .98;
}
.simulation-workbench-page .section-light .split-heading .button {
  width: min(100%, 31rem);
  justify-self: end;
}
.simulation-workbench-page .section-light .compact-link-grid { margin-top: 0; gap: .75rem; }

/* Explicit empty/error state surfaces prevent "nothing loaded" ambiguity. */
.surface-empty,
.surface-error {
  display: grid;
  gap: .5rem;
  min-height: 7rem;
  align-content: center;
  padding: 1rem;
  border: 1px dashed currentColor;
}
:where(.surface-dark, .section-dark, .surface-graphite, .section-graphite) .surface-empty { color: var(--surface-dark-body); background: var(--surface-dark-card); }
:where(.surface-light, .section-light) .surface-empty { color: var(--surface-light-body); background: var(--surface-light-card); }
.surface-error { color: #ffb3b0; background: rgba(147, 31, 31, .16); border-style: solid; }

@media (max-width: 48rem) {
  .simulation-workbench-page .section-light .split-heading .button { width: 100%; justify-self: stretch; }
  .section-light .compact-link-grid a { min-height: 4.25rem; }
}

@media (prefers-contrast: more) {
  .surface-dark,
  .section-dark,
  .surface-graphite,
  .section-graphite { --surface-dark-body: #e2e9ec; --surface-dark-border: rgba(255,255,255,.55); --surface-dark-border-strong: #ffffff; }
  .section-light .compact-link-grid a { background: #fff; border-width: 2px; border-color: var(--surface-light-fg); }
  .button { border-width: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .button[aria-busy="true"]::after,
  .button.is-loading::after { animation-duration: 1.6s; }
}

@media (forced-colors: active) {
  .surface-light,
  .section-light,
  .surface-dark,
  .section-dark,
  .surface-graphite,
  .section-graphite { color: CanvasText; background: Canvas; forced-color-adjust: auto; }
  .button,
  .compact-link-grid a,
  .surface-card-light,
  .surface-card-dark,
  .surface-empty,
  .surface-error { color: ButtonText; background: ButtonFace; border: 2px solid ButtonText; forced-color-adjust: auto; }
  .button:focus-visible,
  .compact-link-grid a:focus-visible { outline: 3px solid Highlight; outline-offset: 3px; }
  .section-light .compact-link-grid a .mono,
  .section-light .compact-link-grid a b { color: LinkText; }
}

/* RC48 institutional-recognition workbench surface inventory. */
.mir-page,
.mir-shell,
.mir-hero {
  color: var(--surface-dark-fg);
  background-color: var(--surface-dark-bg);
  color-scheme: dark;
}
.mir-hero-copy,
.mir-boundary,
.mir-command,
.mir-counterfactual,
.mir-tabs,
.mir-view,
.mir-footer-boundary,
.mir-summary article,
.mir-node,
.mir-institution-pair article,
.mir-two-column > article,
.mir-table,
.mir-facts > div,
.mir-events li,
.mir-proof-grid article {
  color: var(--surface-dark-fg);
  background-color: var(--surface-dark-card);
  border-color: var(--surface-dark-border);
  color-scheme: dark;
}
.mir-shell :where(p, li, dd, small) { color: var(--surface-dark-body); }
.mir-shell :where(h1, h2, h3, h4, strong, legend) { color: var(--surface-dark-fg); }
.mir-shell :where(.eyebrow, .text-link) { color: var(--surface-dark-accent); }

/* RC49 federation-conflict and remedy-review workbench surface inventory. */
.cfr-page,
.cfr-shell,
.cfr-hero {
  color: var(--surface-dark-fg);
  background-color: var(--surface-dark-bg);
  color-scheme: dark;
}
.cfr-hero-copy,
.cfr-boundary,
.cfr-command,
.cfr-counterfactual,
.cfr-tabs,
.cfr-view,
.cfr-footer-boundary,
.cfr-summary article,
.cfr-node,
.cfr-authority-pair article,
.cfr-two-column > article,
.cfr-table,
.cfr-facts > div,
.cfr-events li,
.cfr-proof-grid article {
  color: var(--surface-dark-fg);
  background-color: var(--surface-dark-card);
  border-color: var(--surface-dark-border);
  color-scheme: dark;
}
.cfr-shell :where(p, li, dd, small) { color: var(--surface-dark-body); }
.cfr-shell :where(h1, h2, h3, h4, strong, legend) { color: var(--surface-dark-fg); }
.cfr-shell :where(.eyebrow, .text-link) { color: var(--surface-dark-accent); }
.cfr-shell :where(button, select) {
  color: var(--surface-dark-fg);
  background-color: var(--surface-dark-card);
  border-color: var(--surface-dark-border-strong);
  color-scheme: dark;
}


/* RC51 Remedy compliance audit surface contract */
.rca-page,
.rca-shell,
.rca-hero,
.rca-hero-copy,
.rca-boundary,
.rca-command,
.rca-summary > article,
.rca-counterfactual,
.rca-tabs,
.rca-view,
.rca-node,
.rca-table,
.rca-facts,
.rca-events,
.rca-proof-grid,
.rca-footer-boundary {
  color: var(--surface-dark-fg);
  background-color: var(--surface-dark-bg);
  border-color: var(--surface-dark-border);
  color-scheme: dark;
}
.rca-hero-copy,
.rca-command,
.rca-summary > article,
.rca-counterfactual,
.rca-tabs,
.rca-view,
.rca-node { background-color: var(--surface-dark-card); }
.rca-boundary,
.rca-footer-boundary { background-color: var(--surface-dark-callout); }
.rca-page :is(p, li, dd, small, output) { color: var(--surface-dark-body); }
.rca-page :is(h1, h2, h3, strong, th, dt, label) { color: var(--surface-dark-fg); }
.rca-page :is(.eyebrow, .rca-evidence-line, .rca-boundary-label, .rca-view-state) { color: var(--surface-dark-accent); }
.rca-page :is(button, select, a):focus-visible { outline: 3px solid var(--surface-dark-focus); outline-offset: 3px; }

/* RC52 Remedy completion, residual harm, reopening, and closure review surface contract */
.rcr-page,
.rcr-shell,
.rcr-hero,
.rcr-hero-copy,
.rcr-boundary,
.rcr-command,
.rcr-summary > article,
.rcr-counterfactual,
.rcr-tabs,
.rcr-view,
.rcr-node,
.rcr-table,
.rcr-facts,
.rcr-events,
.rcr-footer {
  color: var(--surface-dark-fg);
  background-color: var(--surface-dark-bg);
  border-color: var(--surface-dark-border);
  color-scheme: dark;
}
.rcr-hero-copy,
.rcr-command,
.rcr-summary > article,
.rcr-counterfactual,
.rcr-tabs,
.rcr-view,
.rcr-node { background-color: var(--surface-dark-card); }
.rcr-boundary,
.rcr-footer { background-color: var(--surface-dark-callout); }
.rcr-page :is(p, li, dd, small, output) { color: var(--surface-dark-body); }
.rcr-page :is(h1, h2, h3, strong, th, dt, label) { color: var(--surface-dark-fg); }
.rcr-page :is(.eyebrow, .rcr-evidence-line, .rcr-boundary-label, .rcr-view-state) { color: var(--surface-dark-accent); }
.rcr-page :is(button, select, a):focus-visible { outline: 3px solid var(--surface-dark-focus); outline-offset: 3px; }
