/*
  Foundational production styles for the current shell. Colours come from
  warm-blue-tokens.css.

  RWP11-T01 owns the signed-in viewport: sticky header, primary column, and the
  clearance variables below. When the viewport is shorter than 152px + 6rem, the
  header scrolls with the page and --wb-header-clearance drops to 8px so a focused
  control is not covered by the sticky header and the dock.   RWP12 owns creation presentation in src/creation-presentation.js and places the
  creation stage and Review sheet from --wb-shell-header-block and
  --wb-shell-notice-block. The notice stays in normal flow above .creation-stage.
  The stage minimum height subtracts that recorded block once.   RWP13 owns the conversation column and the composer dock. The column is the
  centered 800 px content width. The dock stays at the usable viewport bottom
  and reads --wb-header-clearance and --wb-dock-clearance. It does not pad the
  transcript by the dock height. Those packages keep their own surfaces. The synthetic notice stays in normal
  flow inside .product-main; --wb-shell-notice-block records its border box and
  is not added to the header clearance. .page-footer is the run-context landmark.
  It stays in the accessibility tree and out of document flow, so it cannot sit
  under the composer as a spacer. Focusing it reveals the active-run text.
*/

:root {
  --wb-shell-header-block: var(--wb-measured-header, var(--wb-header-height));
  --wb-shell-notice-block: 0px;
  --wb-header-clearance: calc(var(--wb-shell-header-block) + var(--wb-space-2));
  --wb-composer-field-block: max(
    var(--wb-action-height),
    calc(2 * var(--wb-space-3) + var(--wb-font-size-conversation) * var(--wb-line-height-label))
  );
  --wb-composer-block: calc(
    var(--wb-composer-field-block) + 2 * (var(--wb-space-1) + var(--wb-border-width))
  );
  --wb-dock-clearance: calc(
    var(
        --wb-measured-composer,
        calc(
          var(--wb-space-6) + var(--wb-composer-block) + var(--wb-space-5) +
            var(--wb-safe-area-bottom)
        )
      ) +
      var(--wb-space-2)
  );
}

/*
  While the draft holds text the field may grow. Clearance uses the maximum
  height so a focused control is not covered before the next measurement.
*/
body.conversation-active:has(#chat-preview-input:not(:placeholder-shown)) {
  --wb-dock-clearance: calc(
    var(--wb-space-6) + var(--wb-composer-max-height) + 2 *
      (var(--wb-space-1) + var(--wb-border-width)) + var(--wb-space-5) +
      var(--wb-safe-area-bottom) + var(--wb-space-2)
  );
}

html {
  background: var(--wb-color-canvas);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--wb-color-canvas);
  color: var(--wb-color-text-primary);
}

.product-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--wb-color-canvas);
  box-shadow: none;
}

.page-footer {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  white-space: nowrap;
}

.page-footer:focus {
  position: fixed;
  z-index: 4;
  right: auto;
  bottom: calc(var(--wb-space-4) + var(--wb-safe-area-bottom));
  left: var(--wb-space-4);
  width: auto;
  height: auto;
  margin: 0;
  padding: var(--wb-space-2) var(--wb-space-3);
  overflow: visible;
  clip: auto;
  border-radius: var(--wb-radius-action);
  background: var(--wb-color-field-surface);
  outline: var(--wb-focus-width) solid var(--wb-color-focus);
  outline-offset: var(--wb-focus-offset);
  white-space: normal;
}

.product-main {
  flex: 1 0 auto;
  width: 100%;
  min-width: 0;
  max-width: none;
}

/*
  One creation composition. Desktop centres it and lifts it with the approved
  extra bottom padding. Narrow is top-aligned at 64px, with 16px sides.
  --wb-shell-notice-block is the measured synthetic notice above this stage.
*/
.creation-stage {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: min(100%, var(--wb-column-width));
  max-width: var(--wb-column-width);
  margin-inline: auto;
  min-height: calc(100dvh - var(--wb-shell-header-block) - var(--wb-shell-notice-block));
  padding: var(--wb-space-7) var(--wb-space-5)
    calc(var(--wb-space-7) + (2 * var(--wb-creation-lift)));
  text-align: center;
}

.creation-stage[hidden] {
  display: none !important;
}

.processing-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
}

.processing-stage h2,
.creation-heading {
  margin: 0 0 var(--wb-space-6);
  font-family: var(--wb-font-serif);
  font-size: var(--wb-font-size-creation-heading);
  font-weight: var(--wb-font-weight-display);
  line-height: var(--wb-line-height-creation-heading);
}

.creation-failure-accent {
  display: block;
  width: var(--wb-space-7);
  height: var(--wb-activity-height);
  margin: 0 0 var(--wb-space-5);
  border-radius: var(--wb-activity-height);
  background: var(--wb-color-error-accent);
}

.creation-recovery-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--wb-space-3);
  width: 100%;
}

#creation-try-again,
#creation-review-files:not(.quiet-action) {
  min-width: var(--wb-action-min-width);
  min-height: var(--wb-action-height);
  padding: 0 var(--wb-space-5);
  border: 0;
  border-radius: var(--wb-radius-action);
  background: var(--wb-color-action-primary);
  color: var(--wb-color-text-on-action);
  font-size: var(--wb-font-size-label);
  font-weight: var(--wb-font-weight-strong);
  box-shadow: none;
}

#creation-try-again:hover,
#creation-review-files:not(.quiet-action):hover,
#creation-try-again:focus-visible,
#creation-review-files:not(.quiet-action):focus-visible {
  border-color: transparent;
  background: var(--wb-color-action-hover);
  color: var(--wb-color-text-on-action);
}

#creation-try-again:disabled,
#creation-review-files:disabled {
  background: var(--wb-color-disabled-surface);
  color: var(--wb-color-disabled-text);
  cursor: default;
}

[hidden] {
  display: none !important;
}

.app-header {
  position: sticky;
  top: 0;
  /* The account menu lives in this stacking context. Stay above the composer dock. */
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--wb-space-4);
  box-sizing: border-box;
  min-height: var(--wb-header-height);
  margin: 0;
  padding: 0 var(--wb-space-6);
  border: 0;
  background: var(--wb-color-header);
  box-shadow: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--wb-space-3);
  min-width: 0;
  color: var(--wb-color-text-primary);
}

.brand-mark {
  display: block;
  flex: none;
  height: var(--wb-brand-logo-height);
  /* Both served Friday marks are 366×101. Height is the token; width follows the asset. */
  aspect-ratio: 366 / 101;
  width: auto;
  background-image: var(--logo-image);
  background-repeat: no-repeat;
  background-position: left center;
  background-size: contain;
  filter: var(--wb-brand-logo-filter);
}

.brand-wordmark {
  color: var(--wb-color-text-primary);
  font-family: var(--wb-font-sans);
  font-size: var(--wb-font-size-label);
  font-weight: var(--wb-font-weight-strong);
  letter-spacing: var(--wb-letter-spacing-brand);
  line-height: var(--wb-line-height-label);
}

:root[data-theme="dark"] .brand-mark {
  filter: none;
}

.account-menu {
  position: relative;
  margin-left: auto;
}

.account-menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--wb-target-size);
  height: var(--wb-target-size);
  min-width: var(--wb-target-size);
  min-height: var(--wb-target-size);
  padding: 0;
  border: 0;
  border-radius: var(--wb-radius-action);
  background: transparent;
  color: var(--wb-color-text-secondary);
  box-shadow: none;
}

.account-menu-button:hover,
.account-menu-button[aria-expanded="true"] {
  background: var(--wb-color-interaction-surface);
  color: var(--wb-color-text-secondary);
}

.account-menu-button:focus-visible {
  outline: var(--wb-focus-width) solid var(--wb-color-focus);
  outline-offset: var(--wb-focus-offset);
}

.account-menu-button svg {
  width: var(--wb-icon-size);
  height: var(--wb-icon-size);
  fill: none;
  stroke: currentColor;
  stroke-width: var(--wb-icon-stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.account-menu-panel {
  position: absolute;
  top: calc(100% + var(--wb-space-2));
  right: 0;
  z-index: 3;
  display: grid;
  gap: var(--wb-space-1);
  min-width: 240px;
  margin: 0;
  padding: var(--wb-space-2);
  border: var(--wb-border-width) solid var(--wb-color-border-subtle);
  border-radius: var(--wb-radius-action);
  background: var(--wb-color-field-surface);
  color: var(--wb-color-text-primary);
  box-shadow: var(--wb-sheet-shadow);
}

.account-menu-panel[hidden] {
  display: none;
}

.account-menu-panel a,
.account-menu-panel button {
  display: flex;
  align-items: center;
  min-height: var(--wb-target-size);
  padding: var(--wb-space-2) var(--wb-space-3);
  border: 0;
  border-radius: var(--wb-radius-action);
  background: transparent;
  color: var(--wb-color-text-primary);
  font: inherit;
  font-size: var(--wb-font-size-label);
  line-height: var(--wb-line-height-label);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.account-menu-panel a:hover,
.account-menu-panel button:hover {
  background: var(--wb-color-interaction-surface);
}

.account-menu-panel a[hidden],
.account-menu-panel button[hidden] {
  display: none;
}

.product-surface-backdrop {
  position: fixed;
  inset: 0;
  z-index: 19;
  background: transparent;
}

.product-surface-backdrop[hidden] {
  display: none;
}

.product-surface-host {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.product-surface {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: var(--wb-sheet-width);
  max-width: 100%;
  border-left: var(--wb-border-width) solid var(--wb-color-border-subtle);
  background: var(--wb-color-sheet-surface);
  color: var(--wb-color-text-primary);
  box-shadow: var(--wb-sheet-shadow);
  text-align: left;
}

.product-surface[hidden] {
  display: none;
}

.product-surface-header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--wb-space-4);
  min-height: var(--wb-target-size);
  padding: var(--wb-space-4) var(--wb-space-2) var(--wb-space-2) var(--wb-space-5);
}

.product-surface-title,
.product-surface-subheading {
  margin: 0;
  font-family: var(--wb-font-sans);
  font-weight: var(--wb-font-weight-strong);
}

.product-surface-title {
  font-size: var(--wb-font-size-conversation);
}

.product-surface-subheading {
  margin-bottom: var(--wb-space-2);
  font-size: var(--wb-font-size-label);
}

.product-surface-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--wb-space-5) var(--wb-space-5);
}

.product-surface-help,
#theme-mode-explanation {
  margin: 0 0 var(--wb-space-3);
  color: var(--wb-color-text-secondary);
  font-size: var(--wb-font-size-helper);
  line-height: var(--wb-line-height-label);
}

.product-surface button,
.product-surface select,
.product-surface input[type="text"] {
  border-radius: var(--wb-radius-action);
}

.settings-appearance,
.settings-provider,
.settings-trust {
  margin: 0 0 var(--wb-space-5);
}

.settings-appearance .theme-controls {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.settings-appearance .theme-options {
  display: grid;
  gap: var(--wb-space-1);
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--wb-radius-action);
  background: transparent;
}

.settings-appearance .theme-options label {
  display: flex;
  align-items: center;
  gap: var(--wb-space-2);
  min-height: var(--wb-target-size);
  margin: 0;
  padding: var(--wb-space-2) var(--wb-space-3);
  border-radius: var(--wb-radius-action);
  background: transparent;
  color: var(--wb-color-text-primary);
  font-size: var(--wb-font-size-label);
  line-height: var(--wb-line-height-label);
  cursor: pointer;
}

.settings-appearance .theme-options label:hover {
  background: var(--wb-color-interaction-surface);
}

.settings-appearance .theme-options input {
  margin: 0;
  accent-color: var(--wb-color-action-primary);
}

@media (max-width: 640px) {
  .product-surface {
    left: 0;
    width: 100%;
    padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
    border-left: 0;
    box-shadow: none;
  }
}

@media (forced-colors: active) {
  .account-menu-button:focus-visible,
  .account-menu-panel a:focus-visible,
  .account-menu-panel button:focus-visible {
    outline: var(--wb-focus-width) solid CanvasText;
    outline-offset: var(--wb-focus-offset);
  }
}

@media (prefers-reduced-motion: reduce) {
  .account-menu-button,
  .account-menu-panel a,
  .account-menu-panel button {
    transition: none;
  }
}

/* Conversation surface (canonical sections 12, 14, 16-19, 31-33, 36, 42-43). */

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--wb-space-1);
  margin-left: auto;
}

.header-actions .account-menu {
  margin-left: 0;
}

.wb-icon {
  flex: none;
  width: var(--wb-icon-size);
  height: var(--wb-icon-size);
  fill: none;
  stroke: currentColor;
  stroke-width: var(--wb-icon-stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.new-approximation-icon {
  display: none;
}

.wb-header-identity {
  position: absolute;
  left: 50%;
  display: flex;
  align-items: baseline;
  justify-content: center;
  max-width: 40%;
  margin: 0;
  overflow: hidden;
  color: var(--wb-color-text-secondary);
  font-family: var(--wb-font-sans);
  font-size: var(--wb-font-size-label);
  font-weight: var(--wb-font-weight-strong);
  line-height: var(--wb-line-height-label);
  white-space: nowrap;
  transform: translateX(-50%);
}

.wb-header-identity-name {
  min-width: 0;
  overflow: hidden;
  color: var(--wb-color-text-primary);
  text-overflow: ellipsis;
}

.wb-header-identity > :not(.wb-header-identity-name) {
  flex: none;
}

.wb-header-identity[hidden],
body.conversation-active .wb-header-identity[hidden] {
  display: none;
}

.chat-preview-earlier {
  display: block;
  margin: 0 auto var(--wb-space-4);
  min-height: var(--wb-target-size);
  padding: 0 var(--wb-space-3);
  border: 0;
  background: transparent;
  color: var(--wb-color-link);
  font: inherit;
  font-size: var(--wb-font-size-label);
  font-weight: var(--wb-font-weight-strong);
  cursor: pointer;
}

.chat-preview-earlier[hidden] {
  display: none;
}

.wb-identity-comma {
  font-size: 0;
}

body.conversation-active .product-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}

body.conversation-active .chat-preview {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
}

.chat-preview {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.chat-preview-column {
  box-sizing: border-box;
  flex: 1 0 auto;
  width: min(100%, calc(var(--wb-column-width) + 2 * var(--wb-space-5)));
  max-width: calc(var(--wb-column-width) + 2 * var(--wb-space-5));
  margin-inline: auto;
  padding: var(--wb-space-7) var(--wb-space-5) var(--wb-space-5);
}

#chat-preview-heading {
  scroll-margin-top: var(--wb-header-clearance);
}

.wb-identity {
  margin: 0 0 var(--wb-space-3);
  font-family: var(--wb-font-sans);
  font-size: var(--wb-font-size-identity);
  font-weight: var(--wb-font-weight-display);
  line-height: var(--wb-line-height-identity);
}

.wb-identity-name {
  font-family: var(--wb-font-serif);
  font-weight: var(--wb-font-weight-display);
}

.wb-identity-kind {
  white-space: nowrap;
}

.wb-identity-separator {
  padding: 0 var(--wb-space-2);
  color: var(--wb-color-text-secondary);
}

.wb-identity-kind {
  font-size: var(--wb-font-size-label);
  font-weight: var(--wb-font-weight-strong);
}

.wb-disclosure {
  margin: 0 0 var(--wb-space-7);
  padding: var(--wb-space-3) var(--wb-space-4);
  border: var(--wb-border-width) solid var(--wb-color-disclosure-border);
  border-radius: var(--wb-radius-action);
  background: var(--wb-color-disclosure-background);
  color: var(--wb-color-text-primary);
}

.wb-disclosure p {
  margin: 0;
}

.wb-disclosure-lead {
  color: var(--wb-color-disclosure-red);
  font-weight: var(--wb-font-weight-strong);
}

/* A long new visit puts the same disclosure after earlier messages, before this visit's replies. */
.chat-preview-transcript + .wb-disclosure {
  margin-top: var(--wb-space-7);
  scroll-margin-top: var(--wb-header-clearance);
  scroll-margin-bottom: var(--wb-dock-clearance);
}

.chat-preview-transcript[hidden] {
  display: none;
}

.chat-preview-transcript {
  display: flex;
  flex-direction: column;
  gap: var(--wb-space-6);
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  list-style: none;
  font-size: var(--wb-font-size-conversation);
  line-height: var(--wb-line-height-conversation);
}

.chat-preview-withheld-signal {
  margin: var(--wb-space-2) 0 0;
  color: var(--wb-color-text-secondary);
  font-size: var(--wb-font-size-label);
  line-height: var(--wb-line-height-label);
}

.chat-preview-turn-user {
  align-self: flex-end;
  max-width: var(--wb-user-message-max-width);
  padding: var(--wb-space-3) var(--wb-space-4);
  border-radius: var(--wb-radius-message);
  background: var(--wb-color-user-message);
}

.chat-preview-turn-assistant {
  align-self: flex-start;
  max-width: var(--wb-reading-width);
  padding: 0;
  background: transparent;
}

.chat-preview-turn-text {
  margin: 0;
  white-space: pre-wrap;
}

.chat-preview-turn-user .chat-preview-turn-text,
.chat-preview-turn-assistant .chat-preview-turn-text {
  padding: 0;
  border: 0;
  background: transparent;
}

.chat-preview-turn-notice {
  margin: var(--wb-space-3) 0 0;
  color: var(--wb-color-text-primary);
  font-size: var(--wb-font-size-label);
  line-height: var(--wb-line-height-label);
}

.chat-preview-typing {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--wb-color-text-secondary);
  font-size: var(--wb-font-size-conversation);
  line-height: var(--wb-line-height-conversation);
}

.chat-preview-typing p {
  margin: 0;
}

.chat-preview-reply-failure {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: var(--wb-reading-width);
  padding: 0;
  list-style: none;
}

.chat-preview-reply-failure-message {
  padding-left: var(--wb-space-4);
  border-left: 2px solid var(--wb-color-error-accent);
}

.chat-preview-reply-failure-message p {
  margin: 0;
}

.chat-preview-reply-failure-lead {
  font-weight: var(--wb-font-weight-strong);
}

.chat-preview-reply-failure-note {
  color: var(--wb-color-text-secondary);
  font-size: var(--wb-font-size-label);
  line-height: var(--wb-line-height-label);
}

.chat-preview-response-actions {
  position: relative;
  display: flex;
  margin: var(--wb-space-1) 0 0 calc(-1 * var(--wb-space-3));
}

.chat-preview-response-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--wb-target-size);
  height: var(--wb-target-size);
  padding: 0;
  border: 0;
  border-radius: var(--wb-radius-action);
  background: transparent;
  color: var(--wb-color-text-secondary);
  box-shadow: none;
}

.chat-preview-response-trigger:hover,
.chat-preview-response-trigger:focus-visible {
  background: var(--wb-color-interaction-surface);
  color: var(--wb-color-text-secondary);
}

.chat-preview-response-menu {
  position: absolute;
  z-index: 4;
  top: 100%;
  left: 0;
  display: grid;
  min-width: 10rem;
  padding: var(--wb-space-1);
  border: var(--wb-border-width) solid var(--wb-color-border-control);
  border-radius: var(--wb-radius-action);
  background: var(--wb-color-field-surface);
}

.chat-preview-response-menu-above {
  top: auto;
  bottom: 100%;
}

.chat-preview-response-menu[hidden] {
  display: none;
}

.chat-preview-response-menu button {
  justify-content: flex-start;
  min-height: var(--wb-target-size);
  padding: 0 var(--wb-space-3);
  border: 0;
  background: transparent;
  box-shadow: none;
  text-align: left;
}

.wb-composer-dock {
  position: sticky;
  bottom: 0;
  z-index: 2;
  flex: none;
  box-sizing: border-box;
  width: 100%;
  margin-top: auto;
  padding: var(--wb-space-6) var(--wb-space-5) calc(var(--wb-space-5) + var(--wb-safe-area-bottom));
  background: linear-gradient(to bottom, transparent, var(--wb-color-canvas) var(--wb-space-6));
}

.wb-composer {
  box-sizing: border-box;
  display: flex;
  align-items: flex-end;
  gap: var(--wb-space-2);
  width: 100%;
  max-width: var(--wb-column-width);
  margin-inline: auto;
  padding: var(--wb-space-1) var(--wb-space-1) var(--wb-space-1) var(--wb-space-4);
  border: var(--wb-border-width) solid var(--wb-color-border-control);
  border-radius: var(--wb-radius-composer);
  background: var(--wb-color-field-surface);
}

.wb-composer:focus-within {
  outline: var(--wb-focus-width) solid var(--wb-color-focus);
  outline-offset: var(--wb-focus-offset);
}

#chat-preview-input {
  flex: 1;
  width: auto;
  min-height: var(--wb-action-height);
  max-height: var(--wb-composer-max-height);
  padding: var(--wb-space-3) 0;
  border: 0;
  background: transparent;
  color: var(--wb-color-text-primary);
  font: inherit;
  font-size: var(--wb-font-size-conversation);
  line-height: var(--wb-line-height-label);
  resize: none;
  field-sizing: content;
  overflow-y: auto;
}

#chat-preview-input:focus-visible {
  outline: none;
}

#chat-preview-input::placeholder {
  color: var(--wb-color-text-secondary);
  opacity: 1;
}

#chat-preview-send {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: var(--wb-send-size);
  height: var(--wb-send-size);
  margin: var(--wb-space-1);
  padding: 0;
  border: 0;
  border-radius: var(--wb-radius-round);
  background: var(--wb-color-action-primary);
  color: var(--wb-color-text-on-action);
  box-shadow: none;
  opacity: 1;
}

#chat-preview-send:hover,
#chat-preview-send:focus-visible {
  border-color: transparent;
  background: var(--wb-color-action-hover);
  color: var(--wb-color-text-on-action);
}

#chat-preview-send:disabled,
#chat-preview-send:disabled:hover {
  background: var(--wb-color-disabled-surface);
  color: var(--wb-color-disabled-text);
  opacity: 1;
  cursor: default;
}

.chat-preview-jump {
  position: sticky;
  bottom: var(--wb-dock-clearance);
  margin: 0 auto var(--wb-space-3);
}

.chat-preview :is(button, textarea, a, summary) {
  scroll-margin-top: var(--wb-header-clearance);
  scroll-margin-bottom: var(--wb-dock-clearance);
}

body.conversation-active
  :is(
    .creation-stage,
    .creation-entry,
    .primary-action,
    #file-checklist-workspace,
    #processing-stage-workspace
  ) {
  display: none;
}

.discard-draft-dialog {
  position: fixed;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--wb-space-5);
  background: transparent;
}

.discard-draft-dialog[hidden] {
  display: none;
}

.discard-draft-panel {
  display: grid;
  gap: var(--wb-space-4);
  max-width: 28rem;
  padding: var(--wb-space-5);
  border: var(--wb-border-width) solid var(--wb-color-border-control);
  border-radius: var(--wb-radius-action);
  background: var(--wb-color-field-surface);
}

.discard-draft-actions {
  display: flex;
  gap: var(--wb-space-3);
}

@media (max-width: 640px) {
  :root {
    --wb-shell-header-block: var(
      --wb-measured-header,
      calc(var(--wb-header-height-narrow) + var(--wb-safe-area-top))
    );
  }

  .app-header {
    min-height: calc(var(--wb-header-height-narrow) + var(--wb-safe-area-top));
    padding: var(--wb-safe-area-top) var(--wb-space-2) 0 var(--wb-space-4);
  }

  .brand {
    gap: var(--wb-space-2);
  }

  .brand-mark {
    height: var(--wb-brand-logo-height-narrow);
  }

  .header-actions {
    gap: 0;
  }

  /*
    Compact identity takes a second row under the 52 px product row. The row
    minimum can grow with text or the safe area; the header is not locked to 88 px.
  */
  body.conversation-active .app-header:has(#chat-compact-identity:not([hidden])) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: minmax(var(--wb-header-height-narrow), auto) minmax(
        var(--wb-header-identity-height-narrow),
        auto
      );
    align-items: center;
    height: auto;
    padding: var(--wb-safe-area-top) 0 0;
    row-gap: 0;
    column-gap: 0;
  }

  body.conversation-active .app-header:has(#chat-compact-identity:not([hidden])) .brand {
    grid-column: 1;
    grid-row: 1;
    padding-left: var(--wb-space-4);
  }

  body.conversation-active .app-header:has(#chat-compact-identity:not([hidden])) .header-actions {
    grid-column: 2;
    grid-row: 1;
    margin-left: 0;
    padding-right: var(--wb-space-2);
  }

  .new-approximation-icon {
    display: block;
  }

  .new-approximation-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  #new-approximation {
    width: var(--wb-target-size);
    min-width: var(--wb-target-size);
    padding: 0;
    color: var(--wb-color-text-secondary);
  }

  .creation-stage {
    justify-content: flex-start;
    width: 100%;
    max-width: none;
    min-height: 0;
    padding: var(--wb-space-8) var(--wb-space-4) var(--wb-space-7);
  }

  .creation-heading,
  .processing-stage h2 {
    font-size: var(--wb-font-size-creation-heading-narrow);
    overflow-wrap: anywhere;
  }

  #creation-try-again,
  #creation-review-files:not(.quiet-action),
  #create-approximation-run {
    width: 100%;
    max-width: var(--wb-creation-action-max-width);
  }

  .chat-preview-column {
    width: 100%;
    max-width: none;
    padding: var(--wb-space-6) var(--wb-space-4) var(--wb-space-4);
  }

  .wb-identity {
    font-size: var(--wb-font-size-identity-narrow);
  }

  .wb-disclosure {
    margin-bottom: var(--wb-space-6);
  }

  .chat-preview-transcript {
    gap: var(--wb-space-5);
  }

  body.conversation-active:has(#chat-preview-input:not(:placeholder-shown)) {
    --wb-dock-clearance: calc(
      var(--wb-space-5) + var(--wb-composer-max-height-narrow) + 2 *
        (var(--wb-space-1) + var(--wb-border-width)) + var(--wb-space-3) +
        var(--wb-safe-area-bottom) + var(--wb-space-2)
    );
  }

  .chat-preview-turn-user {
    max-width: var(--wb-user-message-max-width-narrow);
  }

  .wb-composer-dock {
    padding: var(--wb-space-5) var(--wb-space-3)
      calc(var(--wb-space-3) + var(--wb-safe-area-bottom));
  }

  #chat-preview-input {
    max-height: var(--wb-composer-max-height-narrow);
  }

  body.conversation-active
    .app-header:has(#chat-compact-identity:not([hidden]))
    .wb-header-identity {
    position: static;
    display: flex;
    grid-column: 1 / -1;
    grid-row: 2;
    align-self: center;
    align-items: baseline;
    justify-content: center;
    max-width: none;
    min-width: 0;
    min-height: var(--wb-header-identity-height-narrow);
    padding: 0 var(--wb-space-4);
    transform: none;
    text-align: center;
  }

  body.conversation-active .wb-header-identity-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: calc(11.5rem + 48px)) {
  body.conversation-active .wb-header-identity {
    flex-direction: column;
    align-items: center;
    white-space: normal;
  }

  body.conversation-active .wb-header-identity .wb-identity-separator {
    display: none;
  }

  body.conversation-active .wb-header-identity-name {
    max-width: 100%;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }
}

/*
  WCAG 2.4.11. Below this height the sticky header, the dock, and one 44 px
  control cannot share the viewport with their clearances. The header scrolls
  with the content. Focus clearance drops to the 8 px spacing token. The dock
  stays put. 6rem lets enlarged text reach the fallback sooner.
*/
@media (max-height: calc(152px + 6rem)) {
  :root {
    --wb-header-clearance: var(--wb-space-2);
  }

  .app-header {
    position: relative;
  }
}
