/* The shared composer controls from controls.js: icons, chip, pair, stepper, menu, the Generate block, the inline
   notice and the prompt tags. Loaded after the older per-screen files, so these looks apply on every screen.
   Colours come from tokens.css only. */

/* Icons */
.ic {
  display: block;
  flex: none;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic.sm {
  width: 14px;
  height: 14px;
}
.ic.fill {
  fill: currentColor;
  stroke: none;
}

/* Chips: an icon and a value, 34 px tall with a 10 px radius. */
.chip,
.pair,
.stepper {
  height: 34px;
  border-radius: 10px;
  background: var(--chip);
  color: var(--text);
  font: 500 13.5px/1 var(--ui);
  font-variant-numeric: tabular-nums;
  flex: none;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  max-width: 100%;
  margin: 0;
  padding: 0 11px;
  border: 0;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 150ms var(--ease),
    color 150ms var(--ease),
    transform 80ms var(--ease);
}
.chip-lead {
  display: inline-flex;
  color: var(--muted);
}
.chip-lead:empty {
  display: none;
}
.chip-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-value:empty {
  display: none;
}
.chip-chev {
  margin-left: -2px;
  color: var(--faint);
}
.chip-dot {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 700 9px/1 var(--ui);
}
/* Hover looks only where there is a pointer that hovers, so a tap on a phone leaves no stuck highlight. */
@media (hover: hover) {
  .chip:hover:not(:disabled),
  .pair-half:hover:not(:disabled),
  .stepper button:hover:not(:disabled) {
    background: var(--chip-hover);
  }
  .icon-chip:hover:not(:disabled),
  .pair-half:hover:not(:disabled),
  .stepper button:hover:not(:disabled) {
    color: var(--text);
  }
  .gen:hover:not(:disabled) {
    background: linear-gradient(180deg, var(--generate-hover-top), var(--generate-hover-bottom));
  }
  .menu-item:hover:not(:disabled) {
    background: var(--chip);
  }
  .notice-action:hover:not(:disabled) {
    background: var(--warn-bg-hover);
  }
}
.chip:active:not(:disabled) {
  background: var(--chip-press);
  transform: scale(0.97);
}
.chip[aria-expanded='true'] {
  background: var(--chip-hover);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.toggle-chip[aria-pressed='true'] .chip-lead {
  color: var(--accent);
}
.chip:disabled {
  opacity: 1;
  color: var(--faint);
  cursor: default;
}
.chip:disabled .chip-lead {
  color: var(--off);
}
.chip[aria-busy='true'] .chip-lead > .ic {
  animation: ctl-spin 700ms linear infinite;
}
.icon-chip {
  justify-content: center;
  width: 34px;
  padding: 0;
  color: var(--muted);
}
.chip-input {
  gap: 4px;
  cursor: text;
}
.chip-input input {
  width: 3.4ch;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: right;
  -moz-appearance: textfield;
}
.chip-input input::-webkit-inner-spin-button {
  display: none;
}
.chip-input:focus-within {
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.chip-suffix {
  color: var(--muted);
}

/* Pair: + and @ in one chip, split by a divider. */
.pair {
  display: inline-flex;
  align-items: center;
}
.pair-half,
.stepper button {
  display: grid;
  place-items: center;
  height: 34px;
  min-height: 34px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    background 150ms var(--ease),
    color 150ms var(--ease),
    transform 80ms var(--ease);
}
.pair-half {
  width: 34px;
}
.pair-half:active:not(:disabled),
.stepper button:active:not(:disabled) {
  background: var(--chip-press);
  transform: scale(0.95);
}
.pair-half:disabled,
.stepper button:disabled {
  opacity: 1;
  color: var(--off);
  cursor: default;
}
.pair-half[aria-busy='true'] > .ic {
  animation: ctl-spin 700ms linear infinite;
}
.pair-div {
  width: 1px;
  height: 16px;
  background: var(--line-strong);
}
.pair:has(> .pair-half[hidden]) .pair-div,
.pair:not(:has(> .pair-half:not([hidden]))) {
  display: none;
}

/* Stepper: − n/max + */
.stepper {
  display: inline-flex;
  align-items: center;
}
.stepper button {
  width: 30px;
}
.stepper-value {
  min-width: 30px;
  text-align: center;
}
.stepper-value em {
  font-style: normal;
  color: var(--faint);
}

/* The hidden attribute wins over the display rules above. */
.chip[hidden],
.pair-half[hidden],
.stepper[hidden],
.menu[hidden],
.composer-notice[hidden] {
  display: none;
}

/* Focus */
.chip:focus-visible,
.pair-half:focus-visible,
.stepper button:focus-visible,
.chip-input:has(input:focus-visible),
.gen:focus-visible,
.notice-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chip-input input:focus-visible {
  outline: none;
}

/* The menu every dropdown opens. */
.menu {
  position: fixed;
  z-index: 60;
  min-width: 200px;
  max-width: min(380px, calc(100vw - 24px));
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--menu);
  box-shadow: 0 20px 50px -10px var(--shadow);
  animation: menu-in 140ms var(--ease);
  scrollbar-width: thin;
}
.menu[data-side='above'] {
  transform-origin: bottom left;
}
@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.98);
  }
}
.menu-title {
  padding: 6px 10px 4px;
  color: var(--faint);
  font: 500 12px/1.3 var(--ui);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font: 400 14px/1.3 var(--ui);
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--ease);
}
.menu-item:focus-visible {
  background: var(--chip);
  outline: none;
}
.menu-item:disabled {
  opacity: 1;
  color: var(--faint);
  cursor: default;
}
.menu-check {
  flex: none;
  width: 16px;
  color: var(--accent);
}
.menu-text {
  display: grid;
  flex: 1;
  gap: 1px;
  min-width: 0;
}
.menu-label {
  font-weight: 500;
}
.menu-text small {
  color: var(--faint);
  font-size: 12px;
}
.menu-price {
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* The model list: a dialog, because it has a search box, dressed and placed like the menu. */
#models-dialog {
  width: min(340px, calc(100vw - 16px));
  max-height: min(520px, calc(100vh - 16px));
  padding: 6px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--menu);
  box-shadow: 0 20px 50px -10px var(--shadow);
}
#models-dialog[open] {
  display: flex;
  flex-direction: column;
}
#models-dialog::backdrop {
  background: transparent;
  backdrop-filter: none;
}
#models-dialog .modal-heading {
  gap: 8px;
  margin: 0;
  padding: 4px 4px 4px 10px;
}
#models-dialog .modal-heading h2 {
  color: var(--faint);
  font: 500 12px/1.3 var(--ui);
  letter-spacing: 0;
}
#models-dialog .icon-button {
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
}
#model-search {
  flex: none;
  height: 34px;
  margin: 2px 0 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font: 400 13.5px/1 var(--ui);
}
#model-search:focus {
  border-color: var(--line-strong);
}
/* Rows keep their natural height and the list scrolls. As a grid of auto rows with a fixed height, the rows shrank
   to share the height and each name overlapped the next row's note. */
#models-dialog .model-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  max-height: none;
  margin: 0;
  overflow-y: auto;
}
#models-dialog .model-option {
  flex: none;
  justify-content: flex-start;
}
#models-dialog .model-list > p {
  margin: 0;
  padding: 8px 10px;
}

/* The Generate block: uppercase GENERATE with the price beneath, on the lime gradient with a 4 px inner bottom
   edge. A fixed minimum width stops it changing size as the price or state changes. */
.gen {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 172px;
  min-height: 64px;
  margin: 0;
  padding: 12px 18px 14px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--generate-top), var(--generate-bottom));
  box-shadow:
    inset 0 -4px 0 var(--generate-edge),
    0 10px 28px -10px var(--generate-glow);
  color: var(--accent-ink);
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 150ms var(--ease),
    color 150ms var(--ease),
    transform 80ms var(--ease),
    box-shadow 80ms var(--ease);
}
.gen-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 800 16px/1 var(--mark);
  font-stretch: 88%;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.gen-price {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: 600 14px/1 var(--ui);
  font-variant-numeric: tabular-nums;
}
.gen-cost {
  transition: opacity 150ms var(--ease);
}
.gen .spin,
.gen-price:has(.gen-cost:empty) .ic {
  display: none;
}
.gen:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 var(--generate-edge);
}
.gen:disabled {
  opacity: 1;
  cursor: not-allowed;
}
.gen[data-state='disabled'] {
  background: var(--chip);
  box-shadow: none;
  color: var(--faint);
}
.gen[data-state='updating'] {
  cursor: progress;
}
.gen[data-state='updating'] .gen-cost {
  opacity: 0.45;
}
.gen[data-state='updating'] .gen-price .spin {
  display: inline-block;
}
.gen[data-state='updating'] .gen-price .ic {
  display: none;
}
/* Before a composer's first estimate there is no price to dim, so the spinner says what it is doing. */
.gen[data-state='updating'] .gen-price:has(.gen-cost:empty)::after {
  content: 'Estimating…';
  font-weight: 500;
  opacity: 0.7;
}
.gen[data-state='generating'] {
  background: var(--generate-busy);
  box-shadow: inset 0 -4px 0 var(--generate-busy-edge);
  color: var(--accent);
  cursor: progress;
}
.gen[data-state='generating'] .gen-label .spin {
  display: inline-block;
}

/* Spinner */
.spin {
  display: inline-block;
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ctl-spin 700ms linear infinite;
}
.spin.sm {
  width: 11px;
  height: 11px;
  border-width: 1.5px;
}
@keyframes ctl-spin {
  to {
    transform: rotate(360deg);
  }
}

/* The inline notice inside a composer. */
.composer-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn);
  font: 400 13px/1.4 var(--ui);
}
.composer-notice b {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.composer-notice[data-tone='error'] {
  background: var(--danger-bg);
  color: var(--danger);
}
.composer-notice[data-tone='info'] {
  background: var(--surface-2);
  color: var(--muted);
}
.notice-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
.notice-action {
  flex: none;
  height: 28px;
  min-height: 28px;
  margin: 0 0 0 auto;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: var(--warn-bg);
  color: inherit;
  font: 600 13px/1 var(--ui);
  white-space: nowrap;
  cursor: pointer;
}

/* The prompt box. The textarea keeps focus, caret, selection and undo, with its own text transparent; the layer
   above it (which ignores the pointer) draws the text, with @Element and #camera tags as highlighted objects.
   Both use the same font, size, padding and border width, so the caret lines up with the text. */
#prompt-editor {
  position: relative;
  display: block;
  min-width: 0;
}
#prompt-highlight {
  position: absolute;
  inset: 0;
  z-index: 1;
  box-sizing: border-box;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  pointer-events: none;
}
#prompt-editor > #prompt {
  display: block;
  width: 100%;
  color: transparent;
  caret-color: var(--text);
  overflow-wrap: break-word;
  scrollbar-width: none;
}
#prompt-editor > #prompt::-webkit-scrollbar {
  display: none;
}
#prompt-editor > #prompt::selection {
  color: transparent;
  background: var(--accent-selection);
}
/* The quiet count under the prompt, shown from 18,000 characters. */
.prompt-count {
  justify-self: end;
  align-self: flex-end;
  font-variant-numeric: tabular-nums;
  line-height: 16px;
}
.prompt-count[hidden] {
  display: none;
}
#prompt-highlight mark {
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
/* The shadow pads the tag without moving any letters. */
#prompt-highlight :is(.prompt-element, .prompt-reference) {
  background: var(--element-bg);
  box-shadow: 0 0 0 3px var(--element-bg);
  color: var(--element);
}
#prompt-highlight .prompt-camera {
  background: var(--camera-bg);
  box-shadow: 0 0 0 3px var(--camera-bg);
  color: var(--camera);
}

@media (prefers-reduced-motion: reduce) {
  .chip,
  .pair-half,
  .stepper button,
  .menu,
  .menu-item,
  .gen {
    transition: none;
    animation: none;
  }
}

/* A native select shown as a chip (controls.js) keeps the chip's own width inside form labels. */
.select-chip {
  justify-self: start;
  align-self: start;
  width: auto;
  max-width: 100%;
}
