.bom-builder-toolbar {
  position: relative;
  z-index: 25;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.bom-builder-tools { display: block; }
.bom-builder-tools > summary {
  display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none;
  min-height: 40px; padding: 8px 12px; font-size: 13px; border-radius: 12px;
  border: 1px solid var(--border); color: var(--text); background: rgba(255,255,255,.035);
}
.bom-builder-tools > summary::-webkit-details-marker { display: none; }
.bom-builder-tools > summary svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.bom-builder-tools[open] > summary svg { transform: rotate(180deg); }
.bom-builder-tools > summary:focus-visible { outline: 2px solid #9bc2ff; outline-offset: 2px; }
.bom-tab-editor .bom-builder-tools .bom-builder-lite__head-actions {
  position: absolute; top: calc(100% + 6px); right: 0;
  display: grid; grid-template-columns: minmax(0, 1fr);
  width: min(320px, calc(100vw - 32px)); max-height: 40dvh; overflow-y: auto;
  padding: 12px; gap: 10px; border: 1px solid var(--border); border-radius: 16px;
  background: #1a1c21; box-shadow: 0 14px 35px rgba(0,0,0,.35);
}
.bom-tab-editor .bom-builder-tools:not([open]) .bom-builder-lite__head-actions { display: none; }
.bom-tab-editor .bom-builder-tools .btn { min-height: 44px; font-size: 12px; }
.bom-tab-editor .bom-builder-tools .bom-builder-publication { justify-content: flex-start; }

/* Keep block settings above the keyboard, with only the fields scrolling. */
.bom-manual-block-modal {
  /* Reset native dialog defaults; showModal puts it above clipped editor layers. */
  margin: 0;
  border: 0;
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  background: transparent;
  color: var(--text);
  color-scheme: dark;
  box-sizing: border-box;
}
.bom-manual-block-modal::backdrop { background: transparent; }
.bom-manual-block-modal__dialog { min-width: 0; min-height: 0; }
.bom-manual-block-modal .bom-manual-editor__inspector {
  overscroll-behavior: contain;
  scroll-padding-block: 12px;
}
.bom-manual-block-modal .bom-manual-editor__inspector label {
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 900px), (pointer: coarse) {
  .bom-manual-block-modal {
    inset: auto;
    top: var(--bom-block-top, 0px);
    left: var(--bom-block-left, 0px);
    width: var(--bom-block-width, 100%);
    height: var(--bom-block-height, 100dvh);
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    box-sizing: border-box;
  }
  .bom-manual-block-modal__dialog {
    height: 100%;
    max-height: 100%;
    padding: 12px;
    overflow: hidden;
  }
  .bom-manual-block-modal__head button { width: 44px; height: 44px; flex-shrink: 0; }
  .bom-manual-block-modal .bom-manual-editor__inspector { padding: 12px 2px; }
  .bom-builder-manual-workspace input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  .bom-builder-manual-workspace textarea,
  .bom-builder-manual-workspace select,
  .bom-builder-manual-workspace .custom-dropdown__trigger {
    font-size: 16px;
    min-height: 44px;
  }
  .bom-manual-block-modal .bom-manual-options__head { flex-wrap: wrap; }
  .bom-manual-block-modal .bom-manual-options__head button { min-height: 44px; }
  .bom-manual-block-modal .bom-manual-option,
  .bom-manual-block-modal .bom-manual-options__labels {
    grid-template-columns: minmax(0, 1fr) minmax(76px, .5fr) 44px;
  }
  .bom-manual-block-modal [data-manual-option-remove] { min-height: 44px; }
  .bom-builder-manual-workspace input:focus-visible,
  .bom-builder-manual-workspace textarea:focus-visible,
  .bom-builder-manual-workspace select:focus-visible { outline: 2px solid #9bc2ff; outline-offset: 1px; }
}

@media (max-width: 640px) {
  /* Reserve the screen for the conversation, not repeated navigation descriptions. */
  .app:has(.bom-tab-editor) .topbar { min-height: 56px; padding-block: 6px; }
  .app:has(.bom-tab-editor) .topbar-context { display: none; }
  .app:has(.bom-tab-editor) .topbar-left { align-self: center; }
  .app:has(.bom-tab-editor) .content { padding: 6px 10px 8px; }
  .integrations-shell:has(.bom-tab-editor) .integrations-nav { padding: 0 0 4px; }
  .integrations-shell:has(.bom-tab-editor) .integrations-nav__item {
    min-width: 0; min-height: 44px; grid-template-columns: 24px auto; padding: 6px 10px; gap: 8px;
  }
  .integrations-shell:has(.bom-tab-editor) .integrations-nav__icon { width: 24px; height: 24px; border-radius: 7px; }
  .integrations-shell:has(.bom-tab-editor) .integrations-nav__icon img { width: 22px; height: 22px; }
  .integrations-shell:has(.bom-tab-editor) .integrations-nav__label strong { font-size: 13px; }
  .integrations-shell:has(.bom-tab-editor) .integrations-nav__label small { display: none; }
  .integrations-shell:has(.bom-tab-editor) .integrations-content { padding-top: 4px; }
  .bom-tab-editor .bom-workspace-nav { gap: 16px; min-height: 40px; }
  .bom-tab-editor .bom-workspace-nav__item { font-size: 12px; padding-block: 10px; }
  .bom-tab-editor .bom-builder-lite { gap: 6px; }
  .bom-tab-editor .bom-builder-lite__head { gap: 8px; align-items: stretch; padding-top: 4px; }
  .bom-tab-editor .bom-builder-lite__head .section-title { font-size: 15px; line-height: 1.35; }
  .bom-tab-editor [data-creation-stage="build"] .bom-builder-steps,
  .bom-tab-editor [data-creation-stage="build"] [data-bom-builder-description] { display: none; }
  .bom-tab-editor [data-creation-stage="start"] .bom-builder-toolbar { display: none; }
  .bom-tab-editor .bom-builder-toolbar { position: relative; gap: 8px; z-index: 25; }
  .bom-tab-editor .bom-builder-toolbar > .btn,
  .bom-builder-tools > summary {
    min-height: 40px; padding: 8px 12px; font-size: 12px; border-radius: 12px;
  }
  .bom-tab-editor .bom-builder-tools .bom-builder-lite__head-actions {
    left: 0; right: auto; width: min(320px, 100%);
  }
  .bom-tab-editor .bom-builder-mode { min-height: 32px; gap: 16px; }
  .bom-tab-editor .bom-builder-mode__item { font-size: 12px; padding-block: 6px; }
  .bom-tab-editor .bom-builder-chat-composer.chatgpt__composer {
    margin: 0 2px 2px; padding: 5px 6px; gap: 4px; border-radius: 22px;
  }
  .bom-tab-editor .bom-builder-chat-composer.chatgpt__composer textarea {
    max-height: 84px; padding-block: 5px; line-height: 1.4;
  }
  .bom-tab-editor .bom-builder-chat-composer.chatgpt__composer textarea:placeholder-shown {
    height: 34px !important; min-height: 34px; overflow-y: hidden !important;
  }
}
