/* The Builder chat column (builder-chat-layout.mjs): the chat gets the room.
   Project memory, Milestones and Mission Control sit in one row of buttons
   above the composer and open as a sheet over the chat. Self-themed: both
   palettes are set here, so no generated light twin is needed. */
body.builder-mode .editor-chat-panel[data-chat-layout] {
  --dock-ink: #f1eaf2;
  --dock-muted: #ab9fb0;
  --dock-line: rgba(255,255,255,.1);
  --dock-line-strong: rgba(255,255,255,.17);
  --dock-chip: rgba(255,255,255,.04);
  --dock-chip-hover: rgba(240,68,145,.12);
  --dock-chip-open: rgba(240,68,145,.2);
  --dock-accent: #ff7db5;
  --dock-warn: #f2b35f;
  --dock-sheet: #1c1821;
  --dock-shadow: 0 24px 64px rgba(0,0,0,.46), 0 0 0 1px rgba(255,255,255,.03);
}
html[data-theme="light"] body.builder-mode .editor-chat-panel[data-chat-layout] {
  --dock-ink: #2f2430;
  --dock-muted: #786a7b;
  --dock-line: #ecdfe8;
  --dock-line-strong: #dcc6d4;
  --dock-chip: #ffffff;
  --dock-chip-hover: #fff0f7;
  --dock-chip-open: #fbdfee;
  --dock-accent: #b0306f;
  --dock-warn: #a8610b;
  --dock-sheet: #fffdfe;
  --dock-shadow: 0 22px 56px rgba(84,37,65,.16), 0 0 0 1px rgba(84,37,65,.04);
}
/* The sheets are placed inside the column. On a phone the column already
   floats over the preview (position:absolute in styles.css). */
@media (min-width: 761px) {
  body.builder-mode .editor-chat-panel[data-chat-layout] { position: relative; }
}

/* ---- The row of panel buttons ------------------------------------------ */
body.builder-mode .builder-panel-dock {
  display: flex; flex: none; align-items: center; gap: 6px;
  min-width: 0; margin: 0; padding: 8px 14px 0;
}
body.builder-mode .builder-panel-dock[hidden],
body.builder-mode .builder-panel-chip[hidden] { display: none !important; }
body.builder-mode .builder-panel-chip {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  flex: 0 1 auto; min-width: 0; min-height: 30px; margin: 0; padding: 0 11px 0 9px;
  border: 1px solid var(--dock-line) !important; border-radius: 999px;
  background: var(--dock-chip) !important; color: var(--dock-ink);
  font: inherit; font-size: 12px; font-weight: 650; line-height: 1;
  cursor: pointer; white-space: nowrap;
  transition: background .14s ease, border-color .14s ease, color .14s ease;
}
/* !important answers the app-wide transparent-button reset in styles.css. */
body.builder-mode .builder-panel-chip:hover { border-color: color-mix(in srgb, var(--dock-accent) 55%, transparent) !important; background: var(--dock-chip-hover) !important; }
body.builder-mode .builder-panel-chip[aria-expanded="true"] { border-color: var(--dock-accent) !important; background: var(--dock-chip-open) !important; }
body.builder-mode .builder-panel-chip:focus-visible { outline: 2px solid var(--dock-accent) !important; outline-offset: 2px; }
.builder-panel-chip-icon {
  flex: none; width: 14px; height: 14px; color: var(--dock-accent);
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.builder-panel-chip-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.builder-panel-chip-status { color: var(--dock-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.builder-panel-chip-status:empty { display: none; }
.builder-panel-chip-sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
/* Mission Control is live while the Agent works, and warns when updates stop. */
.builder-panel-chip[data-live="true"] .builder-panel-chip-icon { fill: currentColor; animation: builder-dock-live 1.3s ease-in-out infinite; }
.builder-panel-chip[data-warn="true"] .builder-panel-chip-icon { color: var(--dock-warn); }
@keyframes builder-dock-live { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .55; transform: scale(.82); } }
/* While the Agent's questions wait for an answer, the card gets the room. */
body.builder-mode .editor-chat-panel[data-chat-layout]:has(#editorChatThread form.builder-questions) > .builder-panel-dock { display: none !important; }

/* ---- Panels: hidden until opened, then a sheet over the chat ----------- */
body.builder-mode .editor-chat-panel[data-chat-layout] > :is(.bh-brain-memory-panel, .bh-brain-milestone-panel, .mission-control):not([data-dock-sheet]) { display: none !important; }
body.builder-mode .editor-chat-panel[data-chat-layout] > [data-dock-sheet] {
  position: absolute; z-index: 12; inset-inline: 10px;
  top: calc(var(--dock-sheet-top, 112px) + 8px);
  height: max(200px, calc(var(--dock-sheet-height, 360px) - 16px));
  max-height: none; margin: 0; overflow: auto; overscroll-behavior: contain;
  border: 1px solid var(--dock-line-strong); border-radius: 16px;
  background: var(--dock-sheet); color: var(--dock-ink); box-shadow: var(--dock-shadow);
  animation: builder-dock-sheet-in .16s ease-out;
}
@keyframes builder-dock-sheet-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
/* The panel's own header stays on top and closes the sheet (✕). */
body.builder-mode .editor-chat-panel[data-chat-layout] > [data-dock-sheet] > summary,
body.builder-mode .editor-chat-panel[data-chat-layout] > .mission-control[data-dock-sheet] > .mission-control-toggle {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 9px;
  min-height: 50px; margin: 0; padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--dock-line) !important; background: var(--dock-sheet) !important;
  list-style: none; cursor: pointer;
}
body.builder-mode .editor-chat-panel[data-chat-layout] > [data-dock-sheet] > summary::-webkit-details-marker { display: none; }
body.builder-mode .editor-chat-panel[data-chat-layout] > [data-dock-sheet] > summary::marker { content: ''; }
body.builder-mode .editor-chat-panel[data-chat-layout] > [data-dock-sheet] > summary::after,
body.builder-mode .editor-chat-panel[data-chat-layout] > .mission-control[data-dock-sheet] > .mission-control-toggle::after {
  content: '✕'; display: grid; place-items: center; flex: none;
  width: 30px; height: 30px; margin-inline-start: auto; border-radius: 9px;
  color: var(--dock-muted); font-size: 13px; font-weight: 600;
}
body.builder-mode .editor-chat-panel[data-chat-layout] > [data-dock-sheet] > summary:hover::after,
body.builder-mode .editor-chat-panel[data-chat-layout] > .mission-control[data-dock-sheet] > .mission-control-toggle:hover::after { background: var(--dock-chip-hover); color: var(--dock-ink); }
/* The row's button shows the tally; the sheet's header shows only its name. */
body.builder-mode .editor-chat-panel[data-chat-layout] > .mission-control[data-dock-sheet] :is(.mission-control-chevron, .mission-control-stat) { display: none; }
body.builder-mode .editor-chat-panel[data-chat-layout] > .mission-control[data-dock-sheet] .mission-control-content { max-height: none; overflow: visible; padding-top: 12px; }
body.builder-mode .editor-chat-panel[data-chat-layout] > .bh-brain-memory-panel[data-dock-sheet] .bh-brain-memory-body { padding-top: 12px; }
body.builder-mode .editor-chat-panel[data-chat-layout] > .bh-brain-milestone-panel[data-dock-sheet] .bh-brain-milestone-container { padding-top: 10px; }
/* The Files tab shows neither the row nor a sheet. */
body.builder-mode .editor-chat-panel.show-assets > .builder-panel-dock,
body.builder-mode .editor-chat-panel.show-assets > [data-dock-sheet] { display: none !important; }

/* ---- The chat keeps its room -------------------------------------------- */
/* The chat takes all the height left over. On a very low screen it still
   keeps a third of the column, and the composer scrolls instead. */
body.builder-mode .editor-chat-panel[data-chat-layout] > #editorChatThread { flex: 1 1 0; min-height: min(33%, 300px); }
body.builder-mode .editor-chat-panel[data-chat-layout] > #editorComposerForm {
  display: flex; flex-direction: column; flex: 0 1 auto; min-height: 0;
  overflow-y: auto; scrollbar-width: thin; margin-top: 8px;
}
body.builder-mode .editor-chat-panel[data-chat-layout] > #editorComposerForm > * { flex: none; }
/* The prompt starts at two lines and grows with what is typed. */
body.builder-mode .editor-chat-panel[data-chat-layout] #editorPrompt {
  flex: 0 1 auto; field-sizing: content;
  min-height: 56px; max-height: min(232px, 34vh); overflow-y: auto; resize: none;
}
@media (max-height: 780px) {
  body.builder-mode .editor-chat-panel[data-chat-layout] #editorPrompt { min-height: 42px; }
  body.builder-mode .editor-chat-panel[data-chat-layout] .builder-chat-tools { margin-block: 5px 7px; }
}
@media (max-width: 760px) {
  body.builder-mode .editor-chat-panel[data-chat-layout] #editorPrompt { min-height: 46px; max-height: 150px; }
  body.builder-mode .builder-panel-dock { gap: 4px; padding-inline: 10px; }
  body.builder-mode .builder-panel-chip { gap: 5px; padding-inline: 7px 8px; }
  /* Keep the Brain line's "i" clear of the round Messenger button. */
  body.builder-mode .editor-chat-panel[data-chat-layout] .agent-brain-consent-row { padding-inline-end: 52px; }
  /* Right to left the button sits on the left; the column itself stays ltr. */
  html[dir="rtl"] body.builder-mode .editor-chat-panel[data-chat-layout] .agent-brain-consent-row { padding-inline: 52px 0; }
}
@media (prefers-reduced-motion: reduce) {
  body.builder-mode .builder-panel-chip { transition: none; }
  .builder-panel-chip[data-live="true"] .builder-panel-chip-icon,
  body.builder-mode .editor-chat-panel[data-chat-layout] > [data-dock-sheet] { animation: none; }
}
