/* DS-01 theme shell: approved existing palettes, scoped adaptations.
   Real imagery, finish swatches and technical drawings retain their source colors. */

/* Functional viewer: theme utility belongs to the first visible content heading. */
.ui-theme-context-row {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 6px 14px;
  min-width: 0; margin-bottom: 8px;
}
.ui-theme-context-row > .eyebrow { flex: 0 1 auto; min-width: 0; margin: 0; }
.ui-theme-context-row > .ui-theme-toggle {
  margin-left: auto; min-height: 44px; min-width: 44px;
  padding: 8px 12px; font-size: 12px;
}
@media (max-width: 480px) {
  .ui-theme-context-row { gap: 6px 8px; }
  .ui-theme-context-row .ui-theme-toggle__label-long { display: none; }
  .ui-theme-context-row .ui-theme-toggle__label-short { display: inline; }
}

/* Top-of-page utility fallback for functional screens without a contextual heading. */
.ui-theme-utility {
  display: flex; align-items: center; justify-content: flex-start;
  width: min(calc(100% - 48px), 1280px); margin: 0 auto; padding: 8px 0 0;
}
.ui-theme-utility--viewer { width: min(calc(100% - 44px), 1380px); }
.ui-theme-utility--access { width: min(calc(100% - 32px), 1040px); }
@media (max-width: 760px) {
  .ui-theme-utility, .ui-theme-utility--viewer { width: calc(100% - 28px); }
}
html[data-theme="light"] {
  --ui-theme-focus: #6e512e;
  --ui-theme-control-bg: #f0ede8;
  --ui-theme-control-border: #c7b7a2;
}
html[data-theme="dark"] {
  --ui-theme-focus: #d8bc7c;
  --ui-theme-control-bg: #20211f;
  --ui-theme-control-border: #7b766c;
}
.ui-theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; min-width: 40px; width: max-content; max-width: 100%; padding: 7px 11px;
  border: 1px solid var(--ui-theme-control-border); border-radius: 999px;
  background: var(--ui-theme-control-bg); color: inherit;
  font: inherit; font-size: 12px; font-weight: 650; line-height: 1.2;
  cursor: pointer; white-space: nowrap; flex: 0 0 auto;
}
.ui-theme-toggle:hover { filter: brightness(.96); }
.ui-theme-toggle:focus-visible { outline: 3px solid var(--ui-theme-focus); outline-offset: 2px; }
.ui-theme-toggle__glyph {
  width: 18px; height: 18px; flex: 0 0 18px; border: 1.5px solid currentColor; border-radius: 50%;
  background: linear-gradient(90deg, #f9f2e9 50%, #22211f 50%);
}
.ui-theme-toggle[data-mode="light"] .ui-theme-toggle__glyph { background: #f9f2e9; }
.ui-theme-toggle[data-mode="dark"] .ui-theme-toggle__glyph { background: #22211f; }
.ui-theme-toggle__label-short { display: none; }

/* Presentation headers: accessible, compact secondary action; no extra row.
   Keep the logo/nav/CTA hierarchy and 44px interactive hit area. */
.site-header .ui-theme-toggle--header {
  width: auto; max-width: 96px; height: 44px; min-width: 44px; min-height: 44px;
  padding: 0 9px; gap: 6px; flex: 0 0 auto;
  font-size: 12px; font-weight: 600;
  border-color: transparent; background: transparent;
}
.site-header .ui-theme-toggle--header:hover {
  background: var(--ui-theme-control-bg); filter: none;
}
.site-header .ui-theme-toggle--header .ui-theme-toggle__label-long { display: none; }
.site-header .ui-theme-toggle--header .ui-theme-toggle__label-short { display: inline; }
@media (max-width: 1150px) {
  .site-header:not(.site-header--public) .ui-theme-toggle--header { width: 44px; padding: 0; }
  .site-header:not(.site-header--public) .ui-theme-toggle--header .ui-theme-toggle__label-short { display: none; }
}
@media(max-width: 380px) {
  .ui-theme-toggle { padding: 7px 9px; gap: 6px; }
  .ui-theme-toggle__label-long { display: none; }
  .ui-theme-toggle__label-short { display: inline; }
}
@media(max-width: 400px) {
  .site-header .header-actions { gap: 5px; }
  .site-header .ui-theme-toggle--header { font-size: 12px; padding: 0; }
  .viewer-header { gap: 7px; }
  .viewer-brand__logo { width: min(34vw, 124px); }
}

/* Public pages: semantic palette rather than route-based theme assumptions. */
html[data-theme="dark"] {
  --public-bg: #111210;
  --public-surface: #1b1c1a;
  --public-surface-soft: #20211f;
  --public-text: #f4f1eb;
  --public-muted: #c4bcb2;
  --public-line: #4a4843;
  --public-accent: #d8bc7c;
  --public-accent-dark: #e2c991;
  --public-accent-highlight: #d8bc7c;
  --public-shadow: 0 18px 48px rgb(0 0 0 / 16%);
}
html[data-theme="dark"] .site-header { background: rgb(27 28 26 / 94%); border-bottom-color: var(--public-line); }
html[data-theme="dark"] .menu-open .site-header nav { background: rgb(27 28 26 / 98%); }
html[data-theme="dark"] .hero { background: var(--public-surface-soft); }
html[data-theme="dark"] .story-section { background: var(--public-surface-soft); }
html[data-theme="dark"] .button-dark { background: #6e512e; color: #f9f2e9; }
html[data-theme="dark"] .button-dark:hover { background: #8b6a40; }
html[data-theme="dark"] .header-cta,
html[data-theme="dark"] .button-primary,
html[data-theme="dark"] .button-copper { background: #8b6a40; color: #ffffff; }
html[data-theme="dark"] .header-cta:hover,
html[data-theme="dark"] .button-primary:hover,
html[data-theme="dark"] .button-copper:hover { background: #6e512e; color: #fff; }
html[data-theme="light"] :focus-visible { outline-color: #6e512e; }
html[data-theme="dark"] :focus-visible { outline-color: #d8bc7c; }

/* Public how-it-works: reverse interface surfaces, not editorial graphics. */
html[data-theme="dark"] .study-band,
html[data-theme="dark"] .production-panel,
html[data-theme="dark"] .quality-copy,
html[data-theme="dark"] .process-section { background: var(--public-surface-soft); }
html[data-theme="dark"] .module-card,
html[data-theme="dark"] .foundation-item,
html[data-theme="dark"] .study-topics details { background: var(--public-surface); }
html[data-theme="dark"] .study-copy > p:not(.eyebrow),
html[data-theme="dark"] .production-intro > p:last-child,
html[data-theme="dark"] .quality-lead,
html[data-theme="dark"] .study-topics details > p { color: var(--public-muted); }
html[data-theme="dark"] .comparison-marker-featured,
html[data-theme="dark"] .foundation-number,
html[data-theme="dark"] .process-flow li > span,
html[data-theme="dark"] .stage-number { color: #22211f; }
html[data-theme="dark"] .study-topics details { border-color: var(--public-line); }
/* Integration callout is interface content, not a pinned editorial sheet.
   Keep the original illustration file; use semantic dark surfaces and readable text. */
html[data-theme="dark"] .integration-callout {
  background: var(--public-surface-soft);
  border-color: var(--public-line);
}
html[data-theme="dark"] .integration-callout p { color: var(--public-muted); }
html[data-theme="dark"] .integration-callout strong { color: var(--public-text); }
html[data-theme="dark"] .integration-callout img { mix-blend-mode: normal; }
/* Pinned decorative/tutorial surfaces must preserve original drawings. */
html[data-theme="dark"] .study-art { --study-illustration-surface: #fcf9ef; color: #22211f; }

/* DS-01 #205: information cards are UI surfaces, not technical sheets.
   DS-01 #206: SVG dimensions remain unchanged; dark palette via classes only. */
html[data-theme="dark"] .viewer-header { background: var(--public-surface); }
html[data-theme="dark"] .overview-highlights li,
html[data-theme="dark"] .dimension-pill { color: var(--public-text); }
html[data-theme="dark"] .detail-row {
  background: var(--public-surface-soft);
  color: var(--public-text);
  border-color: var(--public-line);
}
html[data-theme="dark"] .detail-row img { border-radius: 3px; }
html[data-theme="dark"] .technical-view {
  background: #252622;
  color: #f9f2e9;
  border-color: #69655e;
}
html[data-theme="dark"] .technical-view h3 { color: #f9f2e9; }
html[data-theme="dark"] .technical-view p { color: #d7cec2; }
html[data-theme="dark"] .technical-view svg { color: #ddd5c9; }
html[data-theme="dark"] .technical-view svg text { color: #f9f2e9; fill: currentColor; }
html[data-theme="dark"] .technical-view svg .module-detail__view-shape {
  fill: rgb(174 91 9 / 10%);
  stroke: #ddd5c9;
}
html[data-theme="dark"] .technical-view svg .module-detail__dimension-line { stroke: #ddd5c9; }
/* The focus crop embeds original scene photography, not geometry; do not recolor. */
html[data-theme="dark"] .technical-view--focus svg { background: #f7f5f2; }
/* Dark-mode A/B: ?technical=neutral keeps the previous light-neutral sheet. */
html[data-theme="dark"][data-technical-palette="neutral"] .technical-view {
  background: #f0ede8;
  color: #403c37;
  border-color: #c7bba8;
}
html[data-theme="dark"][data-technical-palette="neutral"] .technical-view h3 { color: #403c37; }
html[data-theme="dark"][data-technical-palette="neutral"] .technical-view p { color: #514a43; }
html[data-theme="dark"][data-technical-palette="neutral"] .technical-view svg { color: #514a43; }
html[data-theme="dark"][data-technical-palette="neutral"] .technical-view svg text { color: #3f3a34; fill: currentColor; }
html[data-theme="dark"][data-technical-palette="neutral"] .technical-view svg .module-detail__view-shape {
  fill: rgb(139 106 64 / 8%);
  stroke: #514a43;
}
html[data-theme="dark"][data-technical-palette="neutral"] .technical-view svg .module-detail__dimension-line { stroke: #514a43; }

/* Internal configurator: override only authored UI surfaces, not scene materials or drawings. */
html[data-theme="light"] {
  --background: #f7f5f2;
  --surface: #ffffff;
  --surface-raised: #f0ede8;
  --text: #22211f;
  --muted: #706c66;
  --border: rgb(34 33 31 / 16%);
  --accent: #8b6a40;
  --accent-strong: #6e512e;
}
html[data-theme="light"] .topbar,
html[data-theme="light"] .flow-nav { background: #ffffff; }
html[data-theme="light"] .flow-nav { border-color: var(--border); }
html[data-theme="light"] .price-state { background: #F0EDE8; }
html[data-theme="light"] .price-state__breakdown > div { border-top-color: #D6CCC0; }
html[data-theme="light"] .price-state__breakdown dt { color: #292723; }
html[data-theme="light"] .button--secondary { background: rgb(34 33 31 / 5%); border-color: var(--border); }
html[data-theme="light"] .button--secondary:hover { background: rgb(34 33 31 / 9%); }
html[data-theme="light"] .module-card,
html[data-theme="light"] .global-option,
html[data-theme="light"] .handle-option,
html[data-theme="light"] .summary-list li { background: rgb(34 33 31 / 3%); }
html[data-theme="light"] .module-card:hover,
html[data-theme="light"] .global-option:hover,
html[data-theme="light"] .handle-option:hover { background: rgb(34 33 31 / 7%); }
html[data-theme="light"] .module-card__inspect:hover { background: rgb(34 33 31 / 7%); }
html[data-theme="light"] .flow-step.is-active,
html[data-theme="light"] .module-card.is-selected,
html[data-theme="light"] .global-option.is-selected,
html[data-theme="light"] .handle-option.is-selected { background: rgb(139 106 64 / 10%); }
html[data-theme="light"] .module-detail__price { background: #28241f; color: #f6f2e9; }
/* Keep the technical module-detail views on their validated pale canvas. */

html[data-theme="light"] .flow-actions[data-bottom-dock-enabled="true"] {
  background: var(--surface);
  box-shadow: 0 -10px 28px rgb(34 33 31 / 10%);
}

/* Internal administration: scoped light UI equivalents. The auth API remains untouched. */
html[data-theme="light"] {
  --bg: #f7f5f2;
  --raised: #f0ede8;
}
html[data-theme="light"] .admin-topbar,
html[data-theme="light"] .stage-unassigned { background: #f0ede8; }
html[data-theme="light"] .admin-form label,
html[data-theme="light"] .stage-name,
html[data-theme="light"] .admin-field > label,
html[data-theme="light"] .data-field { color: #22211f; }
html[data-theme="light"] input[type=email],
html[data-theme="light"] input[type=password],
html[data-theme="light"] input[type=text],
html[data-theme="light"] input[type=number],
html[data-theme="light"] select,
html[data-theme="light"] textarea { background: #ffffff; color: var(--text); border-color: var(--border); }
html[data-theme="light"] .button--primary { background: #8b6a40; color: #ffffff; }
html[data-theme="light"] .button--secondary { background: rgb(34 33 31 / 5%); }
html[data-theme="light"] .stage-pool-item { color: var(--text); border-color: var(--border); background: var(--surface-raised); }
html[data-theme="light"] .hierarchy-section,
html[data-theme="light"] .hierarchy-choice-options,
html[data-theme="light"] .material-targets,
html[data-theme="light"] .multi-picker,
html[data-theme="light"] .material-availability-list { background: #f0ede8; border-color: var(--border); }
html[data-theme="light"] .hierarchy-item { background: rgb(34 33 31 / 3%); border-color: var(--border); }
html[data-theme="light"] .admin-topbar__actions { flex-wrap: wrap; justify-content: flex-end; }
html[data-theme="light"] .text-button { color: #6e512e; }
html[data-theme="light"] code { background: #f0ede8; color: #22211f; }
@media(max-width: 650px) {
  .admin-topbar { flex-wrap: wrap; }
  .admin-topbar__actions { flex-wrap: wrap; justify-content: flex-end; }
}

/* Access management page has scoped inline CSS; adapt only its explicit white control. */
html[data-theme="dark"] .access-page > header .access-brand-logo { width: 160px; }
html[data-theme="dark"] .access-page .panel { background: var(--public-surface); }
html[data-theme="dark"] .access-page button.secondary { background: var(--public-surface-soft); color: var(--public-text); }
html[data-theme="dark"] .access-page input { background: var(--public-surface); color: var(--public-text); }

/* Shared private-page header and role-aware menu. */
.private-header {
  position: relative; z-index: 60; display: flex; align-items: center;
  justify-content: space-between; gap: 18px; width: 100%; min-height: 68px;
  padding: 10px clamp(16px, calc((100vw - 1380px) / 2), 60px);
  border-bottom: 1px solid var(--public-line, #ded9d2);
  background: var(--public-surface, #fff); color: var(--public-text, #22211f);
}
.private-header__brand { display: flex; align-items: center; gap: 16px; min-width: 0; color: inherit; text-decoration: none; }
.private-header__brand img { display: block; width: clamp(120px, 15vw, 160px); max-width: 38vw; height: auto; object-fit: contain; }
.private-header__page-name { color: var(--public-muted, #706c66); font-size: 15px; line-height: 1.3; white-space: nowrap; }
.private-header__actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 0 0 auto; }
.private-menu-toggle {
  display: grid; place-content: center; gap: 5px; width: 44px; height: 44px; padding: 10px;
  border: 1px solid var(--public-line, #ded9d2); border-radius: 10px;
  background: var(--public-surface, #fff); color: inherit; cursor: pointer;
}
.private-menu-toggle:hover { background: var(--public-surface-soft, #f0ede8); }
.private-menu-toggle span { display: block; width: 18px; height: 2px; border-radius: 2px; background: currentColor; }
.private-menu {
  position: absolute; top: calc(100% + 8px); right: clamp(12px, calc((100vw - 1380px) / 2), 60px);
  z-index: 80; display: grid; gap: 15px; width: min(340px, calc(100vw - 24px));
  max-height: min(75vh, 620px); overflow: auto; padding: 18px;
  border: 1px solid var(--public-line, #ded9d2); border-radius: 14px;
  background: var(--public-surface, #fff); color: var(--public-text, #22211f);
  box-shadow: 0 18px 48px rgb(34 33 31 / 18%);
}
.private-menu[hidden] { display: none !important; }
.private-menu__group { display: grid; gap: 7px; }
.private-menu__group + .private-menu__group { padding-top: 13px; border-top: 1px solid var(--public-line, #ded9d2); }
.private-menu__group h2 { margin: 0 0 2px; color: var(--public-muted, #706c66); font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.private-menu__links { display: grid; gap: 3px; }
.private-menu__links a { display: block; padding: 9px 10px; border-radius: 8px; color: inherit; text-decoration: none; font-size: 13px; }
.private-menu__links a:hover, .private-menu__links a[aria-current="page"] { background: var(--public-surface-soft, #f0ede8); color: var(--public-accent-dark, #6e512e); }
.private-menu__note { margin: 2px 0 0; padding: 8px 10px; color: var(--public-muted, #706c66); font-size: 12px; }
.private-menu__account { display: grid; gap: 9px; padding-top: 12px; border-top: 1px solid var(--public-line, #ded9d2); }
.private-menu__account[hidden] { display: none !important; }
.private-menu__email { overflow-wrap: anywhere; color: var(--public-muted, #706c66); font-size: 12px; }
.private-menu__logout {
  display: inline-flex; align-items: center; justify-content: center; width: 100%;
  min-height: 42px; margin: 0; padding: 9px 12px; border: 1px solid var(--public-line, #ded9d2);
  border-radius: 8px; background: var(--public-surface-soft, #f0ede8);
  color: var(--public-text, #22211f); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
.private-header .ui-theme-toggle { min-height: 44px; }
/* Keep page-specific actions first, then the shared theme control and menu. */
.private-header__actions > #restoreButton { order: 1; }
.private-header__actions > .ui-theme-toggle { order: 2; }
.private-header__actions > .private-menu-toggle { order: 3; }
.private-header__actions > [data-private-menu] { order: 4; }
.private-header .private-menu-toggle { flex: 0 0 44px; }
.topbar.private-header { padding-inline: 0; }
.topbar.private-header .topbar__inner { position: relative; width: 100%; max-width: 1380px; margin-inline: auto; padding-inline: clamp(16px, calc((100vw - 1380px) / 2), 60px); }
.topbar.private-header .private-header__actions { margin-left: auto; }
html[data-theme="dark"] .private-header { border-color: #4a4843; background: #171816; color: #f4f1eb; }
html[data-theme="dark"] .private-header__page-name { color: #c4bcb2; }
html[data-theme="dark"] .private-menu { border-color: #4a4843; background: #1b1c1a; color: #f4f1eb; box-shadow: 0 18px 48px rgb(0 0 0 / 34%); }
html[data-theme="dark"] .private-menu__group + .private-menu__group,
html[data-theme="dark"] .private-menu__account { border-color: #4a4843; }
html[data-theme="dark"] .private-menu__links a:hover,
html[data-theme="dark"] .private-menu__links a[aria-current="page"] { background: #292a27; color: #e2c991; }
html[data-theme="dark"] .private-menu-toggle { border-color: #7b766c; background: #20211f; }
html[data-theme="dark"] .private-menu-toggle:hover { background: #292a27; }
html[data-theme="dark"] .private-menu__logout { border-color:#4a4843; background:#20211f; color:#f4f1eb; }
.private-header .ui-theme-toggle--header { border-color: var(--ui-theme-control-border); background: var(--ui-theme-control-bg); }
.private-header .ui-theme-toggle--header:hover { filter: brightness(.96); }
@media (max-width: 650px) {
  .private-header { min-height: 62px; gap: 8px; padding: 9px 14px; }
  .private-header__brand { gap: 9px; }
  .private-header__brand img { width: min(34vw, 132px); max-width: 132px; }
  .private-header__page-name { font-size: 12px; white-space: normal; }
  .private-header__actions { gap: 5px; }
  .private-header .ui-theme-toggle { padding-inline: 8px; gap: 6px; }
  .private-header .ui-theme-toggle__label-long { display: none; }
  .private-header .ui-theme-toggle__label-short { display: inline; }
  .private-menu { right: 8px; }
  .topbar.private-header .topbar__inner { padding-inline: 14px; }
}
@media (max-width: 380px) {
  .private-header__brand img { width: 105px; }
  .private-header__page-name { font-size: 11px; }
  .private-header .ui-theme-toggle { min-width: 40px; min-height: 40px; padding-inline: 6px; }
  .private-header .private-menu-toggle { flex-basis: 40px; width: 40px; height: 40px; }
}


/* NAV-005: keep the approved private-header hierarchy at compact widths.
   The logo may shrink by at most 30%; the page identifier stays complete. */
@media (max-width: 650px) {
  .private-header {
    flex-wrap: wrap;
    gap: 8px;
  }
  .private-header__brand {
    flex: 1 1 158.4px;
    min-width: 0;
  }
  .private-header__brand img {
    flex: 0 1 132px;
    width: min(34vw, 132px);
    min-width: 92.4px;
    max-width: 132px;
  }
  .private-header__actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 8px;
  }
  .private-header .private-menu-toggle {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
  }
  .private-header .ui-theme-toggle {
    min-width: 44px;
    min-height: 44px;
    padding-inline: 8px;
    gap: 6px;
  }
  .topbar.private-header .topbar__inner {
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar.private-header .private-header__brand {
    flex: 1 1 158.4px;
    min-width: 0;
  }
  .topbar.private-header .private-header__actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 8px;
    margin-left: auto;
  }
  .access-page > header .private-header__brand img.access-brand-logo {
    flex: 0 1 132px;
    width: min(34vw, 132px);
    min-width: 92.4px;
    max-width: 132px;
  }
}

/* The existing narrow logo size is the 105 px reference for the approved
   30% shrink limit; the page identifier remains a separate, wrapping item. */
@media (max-width: 380px) {
  .private-header__brand img {
    flex-basis: 105px;
    width: 105px;
    min-width: 73.5px;
    max-width: 105px;
  }
  .access-page > header .private-header__brand img.access-brand-logo {
    flex-basis: 105px;
    width: 105px;
    min-width: 73.5px;
    max-width: 105px;
  }
}

/* The theme state remains available to assistive technology through the
   control's aria-label while the visible label yields space at 320 px. */
@media (max-width: 320px) {
  /* The public shell has a 320px floor; private access pages must be allowed
     to reach the approved 291px one-row minimum. */
  html:has(body.access-page) { min-width: 0; }
  body.access-page { min-width: 0; }
  .private-header .ui-theme-toggle {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    padding: 0;
    gap: 0;
  }
  .private-header .ui-theme-toggle__label-long,
  .private-header .ui-theme-toggle__label-short {
    display: none;
  }
}

/* Below the approved one-row minimum, keep all content and controls visible
   by moving the action group to a second row. */
@media (max-width: 290px) {
  .private-header__brand,
  .topbar.private-header .private-header__brand {
    flex-basis: 100%;
  }
  .private-header__actions,
  .topbar.private-header .private-header__actions {
    margin-left: auto;
  }
}


/* NAV-005: override page-level button minimums for the 44px private menu target. */
.private-header .private-menu-toggle { min-height: 44px; }
html[data-theme="light"] .module-number { background: rgb(34 33 31 / 8%); color: var(--text); }
