/* CEMFORGE dark theme for cemforge.ai (Sunnyday dark navy tokens).
   Applies when <html data-sdt-theme="dark">. Loaded last in <head>; the light stylesheets are unchanged,
   so every rule here carries the html[data-sdt-theme] prefix and !important on color and background.
   Presentation only: no layout, content, script or protected-data change. Screen only; print keeps
   the original light stylesheets. */

@media screen {
  html[data-sdt-theme="dark"] {
    color-scheme: dark;
    background-color: #061321;
    --d-bg: #061321;
    --d-panel: rgba(11, 28, 48, 0.9);
    --d-panel-solid: #0b1c30;
    --d-panel-2: #10243b;
    --d-line: #1d3552;
    --d-line-2: #2a4566;
    --d-ink: #f0f4f7;
    --d-text: #c9d6e0;
    --d-muted: #9fb2c2;
    --d-link: #a8e81a;
    --d-link-hover: #c9f56a;
    --d-green: #97d700;
    --d-steel: #a9cbef;
    /* The light stylesheets read these; re-pointing them darkens any rule not listed below. */
    --paper: #061321;
    --ink: #c9d6e0;
    --muted: #9fb2c2;
    --line: #1d3552;
    --soft: #10243b;
    --white: #0b1c30;
  }

  /* Base: navy glow over near-black navy, behind everything (the constellation canvas sits above it). */
  html[data-sdt-theme="dark"] body {
    background: transparent !important;
    color: var(--d-text) !important;
  }
  html[data-sdt-theme="dark"] body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    pointer-events: none;
    background:
      radial-gradient(1100px 560px at 80% -8%, rgba(1, 58, 115, 0.55), rgba(1, 58, 115, 0) 70%),
      radial-gradient(900px 620px at -10% 45%, rgba(1, 58, 115, 0.26), rgba(1, 58, 115, 0) 70%),
      linear-gradient(180deg, #061321, #040d18);
  }
  html[data-sdt-theme="dark"] ::selection { background: var(--d-green); color: #061321; }

  /* ---- Text ---- */
  html[data-sdt-theme="dark"] body :is(p, li, dd, dt, label, address, td, figcaption, small, summary) { color: var(--d-text) !important; }
  html[data-sdt-theme="dark"] body :is(h1, h2, h3, h4, h5, h6, .page-title, strong, b, th) { color: var(--d-ink) !important; }
  html[data-sdt-theme="dark"] body :is(.intro, .article-meta, .recovery-note, .scope-note, .supporting, .policy-version, .small, .note, .access-note, figcaption) { color: var(--d-muted) !important; }
  html[data-sdt-theme="dark"] body .eyebrow { color: var(--d-link) !important; }
  html[data-sdt-theme="dark"] body hr { border-color: var(--d-line) !important; background: var(--d-line) !important; }
  html[data-sdt-theme="dark"] body blockquote { color: var(--d-text) !important; border-left-color: var(--d-green) !important; }
  html[data-sdt-theme="dark"] body .rule { background: var(--d-green) !important; }

  /* Links in page content. Header, footer, buttons and the hero CTA have their own rules below. */
  html[data-sdt-theme="dark"] body a { color: var(--d-link) !important; text-decoration-color: rgba(168, 232, 26, 0.45); }
  html[data-sdt-theme="dark"] body a:hover { color: var(--d-link-hover) !important; }
  html[data-sdt-theme="dark"] body :is(a, button, summary, input, select, textarea, [tabindex]):focus-visible { outline-color: var(--d-green) !important; }

  /* ---- Header: dark glass, white wordmark, light links, the CEMFORGE lime rule kept ---- */
  html[data-sdt-theme="dark"] body .site-header {
    background: rgba(4, 13, 24, 0.82) !important;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 4px solid var(--d-green) !important;
  }
  html[data-sdt-theme="dark"] body .site-header .brand { color: #ffffff !important; }
  html[data-sdt-theme="dark"] body .site-header .brand small { color: #c3d3df !important; }
  html[data-sdt-theme="dark"] body .site-header .sd-wordmark { filter: brightness(0) invert(1); }
  html[data-sdt-theme="dark"] body .site-nav a { color: #e8eff4 !important; }
  html[data-sdt-theme="dark"] body .site-nav a:is(:hover, [aria-current="page"]) { color: var(--d-link) !important; }
  html[data-sdt-theme="dark"] body .skip { background: var(--d-panel-solid) !important; color: var(--d-ink) !important; }

  /* ---- Footer ---- */
  html[data-sdt-theme="dark"] body .site-footer {
    background: rgba(3, 10, 19, 0.88) !important;
    border-top: 1px solid var(--d-line) !important;
    color: var(--d-muted) !important;
  }
  html[data-sdt-theme="dark"] body .site-footer p { color: var(--d-muted) !important; }
  html[data-sdt-theme="dark"] body .site-footer a { color: #e8eff4 !important; }
  html[data-sdt-theme="dark"] body .site-footer a:hover { color: var(--d-link) !important; }
  html[data-sdt-theme="dark"] body .site-footer .brand-name { color: #ffffff !important; }

  /* ---- Panels, cards, notices, tables, code, details, forms ---- */
  html[data-sdt-theme="dark"] body :is(.card, details, .policy-toc, .reports-story .offer, .metric, .system-card, .cost-card,
    .metric-grid > div, .human-example, .walkthrough, .policy-access-update) {
    background: var(--d-panel) !important;
    border-color: var(--d-line) !important;
    box-shadow: none !important;
  }
  html[data-sdt-theme="dark"] body :is(.notice, .policy-document .intro) {
    background: rgba(16, 36, 59, 0.92) !important;
    border-left-color: var(--d-green) !important;
    color: var(--d-text) !important;
  }
  html[data-sdt-theme="dark"] body .card :is(p, span) { color: var(--d-muted) !important; }
  html[data-sdt-theme="dark"] body table { background: var(--d-panel) !important; color: var(--d-text) !important; }
  html[data-sdt-theme="dark"] body :is(th, td) { border-color: var(--d-line) !important; }
  html[data-sdt-theme="dark"] body th { background: var(--d-panel-2) !important; }
  html[data-sdt-theme="dark"] body :is(pre, code, kbd, samp) { background: #0d2036 !important; color: #dce8f0 !important; }
  html[data-sdt-theme="dark"] body :is(.article-meta, .policy-nav, .policy-end, .reports-story .story-row, .bot-access) { border-color: var(--d-line) !important; }
  html[data-sdt-theme="dark"] body :is(input, select, textarea) {
    background: var(--d-panel-solid) !important;
    color: var(--d-ink) !important;
    border-color: var(--d-line-2) !important;
  }
  html[data-sdt-theme="dark"] body ::placeholder { color: var(--d-muted) !important; }

  /* Buttons: lime with navy text, as on the homepage hero. */
  html[data-sdt-theme="dark"] body :is(.button, .farmstead-hero__button) {
    background: var(--d-green) !important;
    color: #061321 !important;
    text-decoration: none;
  }
  html[data-sdt-theme="dark"] body :is(.button, .farmstead-hero__button):hover { background: var(--d-link-hover) !important; color: #061321 !important; }

  /* ---- Homepage (sd-polished) ---- */
  html[data-sdt-theme="dark"] body.sd-polished .hero article section > p:first-child { color: var(--d-muted) !important; }
  html[data-sdt-theme="dark"] body.sd-polished .hero article section > p:nth-child(3) a { background: var(--d-green) !important; color: #061321 !important; }
  html[data-sdt-theme="dark"] body.sd-polished .hero article section > ul li {
    background: var(--d-panel) !important;
    border-color: var(--d-line) !important;
    border-top-color: var(--d-green) !important;
  }
  html[data-sdt-theme="dark"] body.sd-polished .hero article section > ul li strong { color: var(--d-ink) !important; }
  html[data-sdt-theme="dark"] body.sd-polished .cf-thermal .eyebrow { color: #bde663 !important; }
  html[data-sdt-theme="dark"] body.sd-polished .cf-thermal-controls { color: #e1eaee !important; }
  html[data-sdt-theme="dark"] body.sd-polished .cf-thermal-controls button { color: #ffffff !important; }

  /* ---- LOGiMIX Reports and Wisconsin example shell (the report itself stays a white document sheet) ---- */
  html[data-sdt-theme="dark"] body #report-access-status { color: var(--d-text) !important; }
  html[data-sdt-theme="dark"] body #report-frame { border-color: var(--d-line-2) !important; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45); }
  html[data-sdt-theme="dark"] body .human-example { border-left-color: var(--d-green) !important; }

  /* ---- Farmstead and Idaho Falls examples ---- */
  html[data-sdt-theme="dark"] body .systems-section {
    background: linear-gradient(145deg, rgba(14, 33, 54, 0.92), rgba(9, 24, 41, 0.92)) !important;
    border-color: var(--d-line) !important;
    box-shadow: none !important;
  }
  html[data-sdt-theme="dark"] body :is(.systems-heading > p:last-child, .metric span, .metric-grid span, .machine small, .crew-row small) { color: var(--d-muted) !important; }
  html[data-sdt-theme="dark"] body :is(.metric strong, .systems-heading h3, .system-card h4, .crew-row b, .crew-row small strong, .machine) { color: var(--d-ink) !important; }
  html[data-sdt-theme="dark"] body .systems-heading .eyebrow,
  html[data-sdt-theme="dark"] body .system-kicker { color: var(--d-link) !important; }
  html[data-sdt-theme="dark"] body .system-card { border-top-color: #7bab18 !important; }
  html[data-sdt-theme="dark"] body .system-card--house { border-top-color: #2d8e83 !important; }
  html[data-sdt-theme="dark"] body .system-card--barn { border-top-color: #3b86c4 !important; }
  html[data-sdt-theme="dark"] body .mass-tag { background: rgba(151, 215, 0, 0.16) !important; color: #d4f38a !important; }
  html[data-sdt-theme="dark"] body .system-card--house .mass-tag { background: rgba(45, 142, 131, 0.22) !important; color: #a9eadf !important; }
  html[data-sdt-theme="dark"] body .system-card--barn .mass-tag { background: rgba(59, 134, 196, 0.22) !important; color: #b9dcf7 !important; }
  html[data-sdt-theme="dark"] body .system-photo + .equipment-flow .machine { background: var(--d-panel-2) !important; border-color: var(--d-line) !important; }
  html[data-sdt-theme="dark"] body .crew-row { background: rgba(16, 36, 59, 0.92) !important; border-color: var(--d-line) !important; }
  html[data-sdt-theme="dark"] body .crew-caveat { background: rgba(214, 156, 45, 0.13) !important; color: #f1dfb8 !important; }
  html[data-sdt-theme="dark"] body .status-chip { background: rgba(151, 215, 0, 0.16) !important; color: #d4f38a !important; }
  /* The equipment pictograms stay light tiles: their CSS drawings are navy on light. */

  /* ---- LOGiMIX cost map shell (own header; data, access and Turnstile behavior unchanged) ---- */
  html[data-sdt-theme="dark"] body > header { border-bottom-color: var(--d-line) !important; }
  html[data-sdt-theme="dark"] body > header .brand { color: var(--d-link) !important; }
  html[data-sdt-theme="dark"] body :is(.stat, .panel, .access-panel, .cost-volume-block) {
    background: var(--d-panel) !important;
    border-color: var(--d-line) !important;
  }
  html[data-sdt-theme="dark"] body .badge { background: rgba(214, 170, 77, 0.16) !important; color: #f3dfae !important; border: 1px solid rgba(214, 170, 77, 0.35); }
  html[data-sdt-theme="dark"] body .warning { background: rgba(196, 149, 45, 0.13) !important; border-left-color: #c4952d !important; color: #f1dfb8 !important; }
  html[data-sdt-theme="dark"] body .cost-boundary { background: rgba(51, 125, 129, 0.16) !important; color: var(--d-text) !important; }
  html[data-sdt-theme="dark"] body :is(.cost-context-grid > div, .cost-result-card, .cost-line) {
    background: var(--d-panel-2) !important;
    border-color: var(--d-line) !important;
  }
  html[data-sdt-theme="dark"] body .chip { background: rgba(169, 203, 239, 0.14) !important; color: var(--d-ink) !important; }
  html[data-sdt-theme="dark"] body summary { background: rgba(16, 36, 59, 0.92) !important; }
  html[data-sdt-theme="dark"] body details summary { background: transparent !important; }
  html[data-sdt-theme="dark"] body :is(.row, .bot-access) { border-color: var(--d-line) !important; }
  html[data-sdt-theme="dark"] body tr[data-state]:hover { background: rgba(169, 203, 239, 0.08) !important; }
  html[data-sdt-theme="dark"] body button:not(.secondary) { background: #1d4d63 !important; color: #ffffff !important; border-color: #3f7489 !important; }
  html[data-sdt-theme="dark"] body button.secondary,
  html[data-sdt-theme="dark"] body .cost-anchor-lane button { background: var(--d-panel-solid) !important; color: var(--d-ink) !important; border-color: var(--d-line-2) !important; }
  html[data-sdt-theme="dark"] body .cost-anchor-lane button small { color: var(--d-muted) !important; }
  html[data-sdt-theme="dark"] body .cost-anchor-lane:before { border-top-color: var(--d-line-2) !important; }
  html[data-sdt-theme="dark"] body #cost-complete-total { color: #ffb59c !important; }
  html[data-sdt-theme="dark"] body #error { color: #ff9a9a !important; }
  html[data-sdt-theme="dark"] body #as-printed-panel { border-color: #3f8f93 !important; }
  /* Map drawing: base states darkened; priced markers keep their cost colors, labels keep their halo. */
  html[data-sdt-theme="dark"] body #map path[data-map-state] { fill: #15304b; stroke: #36587a; }
  html[data-sdt-theme="dark"] body .state { stroke: #0b1c30; }

  /* ---- Background layer (created by sdt-bg.js) ---- */
  html[data-sdt-theme="dark"] .sdt-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
  }
  html[data-sdt-theme="dark"] .sdt-bg canvas { display: block; width: 100%; height: 100%; }
}
