/*
 * The assistant's ENGINE PICKER — @gemboss/ui 0.25.0 (src/assistant/engine.tsx and engine-settings.tsx import this file; its
 * own entry, not in gemboss-ui.css). A chip in the composer row (a door to Settings › AI & engines), that section's two cards
 * (EngineSettings, 0.52.0), and the one line a failed turn writes in the chat (BridgeNotice). The chip's own popup with
 * Engine · Setup · Status tabs went in 0.53.0.
 *
 * Polaris density: 12px type in the chip, the pane's 13px in Settings, 28px controls with the mouse, 44px under a coarse
 * pointer and at phone width (§9.1: controls). The cards are the kit's `.ui-card`, the copy button `.ui-btn`, the badges
 * `.ui-badge`: only what is the picker's own is here.
 */

/* ── The chip: quiet like the admin's composer chips (muted until hovered or open), a dot for the bridge ── */
.gb-engine { display: inline-flex; min-width: 0; max-width: 100%; }
.gb-engine-chip {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; box-sizing: border-box;
  height: var(--ui-btn-h, 28px); padding: 0 24px 0 8px;
  font: inherit; font-size: var(--ui-fs-caption, 12px); font-weight: 500; line-height: 20px; white-space: nowrap;
  color: var(--ui-text-muted); background-color: transparent; border: 1px solid transparent; border-radius: var(--ui-radius-md, 8px);
  cursor: pointer;
  /* The admin chip's caret, at its inset: one kind of control. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23686b71' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
@media (hover: hover) { .gb-engine-chip:hover { color: var(--ui-text); background-color: var(--gemboss-hover, rgba(0,0,0,.05)); } }
@media (hover: none) { .gb-engine-chip { color: var(--ui-text); } }
.gb-engine-chip:focus-visible { color: var(--ui-text); outline: 2px solid var(--ui-focus); outline-offset: 2px; }
.gb-engine-chiplabel { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.gb-engine-chipsub { font-weight: 450; }
.gb-engine-chip:disabled { cursor: default; opacity: .55; }
/* In a ChatComposer (0.29.0) the chip says less as the row narrows (`data-density`, measured by the composer): the model goes
   first, then the name gives way to the engine's mark. A chip with no mark keeps its name and ellipsises. */
.gemboss-engine-mark { display: block; width: 14px; height: 14px; flex: 0 0 auto; }
.gb-engine-chipmark { display: none; }
.gb-engine-chipmark .gemboss-engine-mark { width: 16px; height: 16px; }
.gemboss-ec-input:not([data-density="full"]) .gb-engine-chipsub { display: none; }
.gemboss-ec-input:is([data-density="icon"], [data-density="tight"]) .gb-engine-chip.has-mark .gb-engine-chiplabel { display: none; }
.gemboss-ec-input:is([data-density="icon"], [data-density="tight"]) .gb-engine-chip.has-mark .gb-engine-chipmark { display: block; }
.gemboss-ec-input:is([data-density="icon"], [data-density="tight"]) .gb-engine:has(.has-mark) { flex-shrink: 0; }

/* ── The dot: one tone per bridge state. Not colour alone: the chip's name and the Status tab say it in words. ── */
.gb-engine-dot { flex: none; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ui-text-muted); vertical-align: middle; }
.gb-engine-dot--ok { background: var(--gemboss-success, #007f5f); }
.gb-engine-dot--warn { background: #e8a10a; box-shadow: 0 0 0 1px var(--gemboss-warning, #9a6700) inset; }
.gb-engine-dot--down { background: var(--gemboss-danger, #d72c0d); }
.gb-engine-dot--idle { background: transparent; box-shadow: 0 0 0 1.5px var(--ui-text-muted) inset; }

/* ── The fields of the Engine card ── */
.gb-engine-field { display: grid; gap: 6px; }
.gb-engine-label { font-weight: 550; color: var(--ui-text-strong, var(--ui-text)); }
.gb-engine-note { color: var(--ui-text-muted); }

/* Engines: one row each, a radio. Rows touch (0px apart), so each is 44px under every pointer (§9.1). */
.gb-engine-list { display: grid; border: 1px solid var(--ui-border); border-radius: var(--ui-radius-md, 8px); overflow: hidden; }
.gb-engine-row {
  display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 2px 10px; align-items: center;
  min-height: 44px; padding: 8px 12px 8px 34px; box-sizing: border-box; position: relative;
  font: inherit; text-align: left; color: inherit; background: transparent; border: 0; cursor: pointer;
}
.gb-engine-row + .gb-engine-row { border-top: 1px solid var(--ui-border); }
.gb-engine-row::before {
  content: ""; position: absolute; left: 10px; top: 50%; width: 14px; height: 14px; margin-top: -7px; box-sizing: border-box;
  border: 1.5px solid var(--ui-text-muted); border-radius: 50%;
}
.gb-engine-row[aria-checked="true"] { background: var(--gemboss-active-bg, #f0f1f4); }
.gb-engine-row[aria-checked="true"]::before { border: 4.5px solid var(--ui-accent); }
.gb-engine-row[aria-checked="true"] .gb-engine-rowname { font-weight: 600; }
@media (hover: hover) { .gb-engine-row:hover:not(:disabled) { background: var(--ui-surface-2); } }
.gb-engine-row:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: -2px; }
.gb-engine-row:disabled { cursor: not-allowed; }
.gb-engine-row:disabled .gb-engine-rowname { color: var(--ui-text-muted); }
.gb-engine-rowhead { display: flex; align-items: center; gap: var(--ui-space-2, 8px); min-width: 0; }
.gb-engine-rowname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 450; }
/* The engine's picture (0.55.0): its mark, else its initial, in a quiet tile left of the name; the name and the note sit in
   the second column, so the text of every row starts at one edge. Monochrome, as the chip's mark. */
.gb-engine-row > .gb-engine-rowhead, .gb-engine-row > .gb-engine-note { grid-column: 2; }
.gb-engine-rowmark {
  grid-row: 1; display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: var(--ui-radius-md, 8px);
  background: var(--ui-surface-2); color: var(--ui-text); font-size: 12px; font-weight: 650; line-height: 1;
}
.gb-engine-row:has(> .gb-engine-note) > .gb-engine-rowmark { grid-row: 1 / span 2; } /* no empty second row when there is no note */
.gb-engine-rowmark .gemboss-engine-mark { width: 16px; height: 16px; }
.gb-engine-row[aria-checked="true"] .gb-engine-rowmark { background: var(--ui-surface); box-shadow: inset 0 0 0 1px var(--ui-border); }
.gb-engine-row:disabled .gb-engine-rowmark { opacity: .55; }
.gb-engine-group .gb-engine-rowmark { width: 22px; height: 22px; border-radius: 6px; font-size: 11px; }
.gb-engine-group .gb-engine-rowmark .gemboss-engine-mark { width: 14px; height: 14px; }

/* Models and efforts: pressed buttons, as the admin's model buttons. 8px apart, so 28px is allowed with a mouse. */
.gb-engine-opts { display: flex; flex-wrap: wrap; gap: var(--ui-space-2, 8px); }
.gb-engine-opt {
  height: var(--ui-btn-h, 28px); padding: 0 10px; box-sizing: border-box;
  font: inherit; font-weight: 500; color: var(--ui-text); background: transparent;
  border: 1px solid var(--ui-border); border-radius: var(--ui-radius-md, 8px); cursor: pointer;
}
@media (hover: hover) { .gb-engine-opt:hover:not(:disabled) { background: var(--ui-surface-2); } }
.gb-engine-opt[aria-pressed="true"] { background: var(--gemboss-active-bg, #f0f1f4); border-color: var(--ui-text); font-weight: 600; }
.gb-engine-opt:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 2px; }
.gb-engine-opt:disabled { opacity: .5; cursor: not-allowed; }
.gb-engine-select { width: 100%; }
/* Models per engine (0.29.0): each engine, its badge and note, its own model buttons; the current one's name is bold. */
.gb-engine-groups { display: grid; gap: var(--ui-space-3, 12px); }
.gb-engine-group { display: grid; gap: 6px; }
.gb-engine-group + .gb-engine-group { padding-top: var(--ui-space-3, 12px); border-top: 1px solid var(--ui-border); }
.gb-engine-group[data-current] .gb-engine-rowname { font-weight: 600; }
.gb-engine-problem { color: var(--gemboss-danger-strong, #b42318); }
.gb-engine-notes { display: grid; gap: 4px; color: var(--ui-text-muted); }
.gb-engine-notes p { margin: 0; }

/* Setup: what is wrong (one callout), how, the command, Copy. */
.gb-engine-callout { padding: 8px 10px; border-radius: var(--ui-radius-md, 8px); border: 1px solid; }
.gb-engine-callout--warn { background: var(--gemboss-warning-soft, #fff8e0); border-color: var(--gemboss-warning-border, #f5d569); color: var(--gemboss-warning, #9a6700); }
.gb-engine-callout--down { background: var(--gemboss-danger-soft, #fff0e9); border-color: var(--gemboss-danger-border, #f5c9bc); color: var(--gemboss-danger-strong, #b42318); }
/* The steps are the surface's own blocks (a hint and its Allow, a list and Check again, the pairing form): a grid keeps them
   apart, as the section takes paragraph margins (0.55.1). engine-plain.js's slot is display:contents, so its children are the
   grid's. A bare button (or a link drawn as one) keeps its own width. */
.gb-engine-steps { display: grid; gap: var(--ui-space-2, 8px); }
.gb-engine-steps .ui-btn { justify-self: start; }
.gb-engine-steps ol, .gb-engine-steps ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.gb-engine-cmd {
  margin: 0; padding: 8px 10px; border-radius: var(--ui-radius-md, 8px); background: var(--ui-surface-2); border: 1px solid var(--ui-border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; line-height: 16px;
  white-space: pre-wrap; word-break: break-all; user-select: all;
}
.gb-engine-cmd code { padding: 0; border: 0; background: none; font: inherit; color: inherit; } /* a surface's own `code` look (padding, tint) does not reach in */
.gb-engine-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ui-space-2, 8px); }
.gb-engine-said { color: var(--ui-text-muted); }
.gb-engine-said:empty { display: none; }
.gb-engine-code code { padding: 0; border: 0; background: none; color: inherit; font-size: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; letter-spacing: .04em; user-select: all; } /* as .gb-engine-cmd code: a surface's own `code` look does not reach in */

/* Status: label / value rows. */
.gb-engine-rows { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.gb-engine-rows dt { color: var(--ui-text-muted); }
.gb-engine-rows dd { margin: 0; display: flex; align-items: center; gap: 6px; min-width: 0; overflow-wrap: anywhere; }

/* ── Settings › AI & engines (EngineSettings): two cards, one under the other, at the pane's body size. One column of
   fields wide (the SettingsDialog's form measure), whatever measure the surface's popup uses. ── */
/* align-content: start: in a pane that stretches it (a flex column), the extra height stays below the cards, not in the gaps. */
.gb-engine-settings { display: grid; align-content: start; gap: var(--ui-space-4, 16px); max-width: 662px; font-size: var(--ui-fs-body, 13px); line-height: 20px; }
.gb-engine-sect { display: grid; gap: var(--ui-space-3, 12px); }
.gb-engine-settings > .gb-engine-sect { margin: 0; } /* the grid's gap is the only space between the cards, whatever a page gives a section */
.gb-engine-sect > .ui-card__title { margin: 0; }
/* The bridge card's head: its title, and its state as the kit's dotted badge (0.55.0, in place of a "State" row). */
.gb-engine-secthead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--ui-space-2, 8px); }
.gb-engine-secthead > .ui-card__title { margin: 0; }
.gb-engine-state {
  display: inline-flex; align-items: center; gap: 6px; height: 20px; padding: 0 8px; border-radius: 999px; white-space: nowrap;
  font-size: 12px; font-weight: 550; line-height: 16px; background: var(--ui-surface-2); color: var(--ui-text);
}
.gb-engine-state::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.gb-engine-state--ok { background: var(--gemboss-success-soft, #e3f8ec); color: var(--gemboss-success-strong, #0c5132); }
.gb-engine-state--warn { background: var(--gemboss-warning-soft, #fff8e0); color: var(--gemboss-warning, #9a6700); }
.gb-engine-state--down { background: var(--gemboss-danger-soft, #fff0e9); color: var(--gemboss-danger-strong, #b42318); }
.gb-engine-state--idle::before { background: transparent; box-shadow: 0 0 0 1.5px currentColor inset; }
.gb-engine-settings .gb-engine-sect p { margin: 0; } /* above a page's own `section > p` margins */
.gb-engine-sect:focus, .gb-engine-sub:focus { outline: none; }
.gb-engine-sub { display: grid; gap: var(--ui-space-3, 12px); padding-top: var(--ui-space-3, 12px); border-top: 1px solid var(--ui-border); scroll-margin-top: var(--ui-space-4, 16px); }
.gb-engine-subtitle { margin: 0; font-size: inherit; line-height: inherit; font-weight: 650; }

/* ── The one line a FAILED turn writes in the chat ── */
/* Dot | the sentence, and the action under the sentence (0.29.0: a flex row wrapped a long sentence away from its dot,
   which then sat alone on the first line). */
.gb-engine-notice {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 4px 6px; margin: 0; padding: 4px 0;
  font-size: var(--ui-fs-caption, 12px); line-height: 16px; color: var(--ui-text-muted);
}
.gb-engine-notice > .gb-engine-dot { margin-top: 4px; }
.gb-engine-notice > .gb-engine-notice-link { grid-column: 2; justify-self: start; }
.gb-engine-notice--down .gb-engine-notice-text { color: var(--ui-text); }
.gb-engine-notice--warn .gb-engine-notice-text { color: var(--ui-text); }
.gb-engine-notice-text { min-width: 0; overflow-wrap: anywhere; }
/* A BUTTON (it opens the picker), so a control: its own box is the target, not an overlay a measuring tool cannot see
   (0.29.0: the overlay read 16px in visual-gate on content-radar /v2/assistant). 24px with a mouse, 44px under touch and
   at phone width, both bought with negative margins so the line stays 16px tall. */
.gb-engine-notice-link {
  flex: none; display: inline-flex; align-items: center; min-height: 24px; margin: -4px 0 -4px -4px; padding: 0 4px;
  border: 0; border-radius: 4px; background: none; font: inherit; font-weight: 550;
  color: var(--ui-accent); text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.gb-engine-notice-link:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 0; }

/* ── Touch and phone width: every control 44px (§9.1). ── */
@media (pointer: coarse), (max-width: 47.9975em) {
  .gb-engine-chip { min-height: 44px; }
  .gb-engine-opt { min-height: 44px; min-width: 44px; }
  .gb-engine-notice-link { min-height: 44px; margin: -14px 0 -14px -8px; padding: 0 8px; }
}
@media (prefers-reduced-motion: no-preference) {
  .gb-engine-chip, .gb-engine-opt, .gb-engine-row { transition: background-color .12s ease, color .12s ease; }
}
