/* Conversation layout only. The visual language lives in ui.css. */
.chat-page { overflow: hidden; }
.chat-page [hidden] { display: none !important; }
.chat-page .solid { fill: currentColor; stroke: none; }
.chat-app { height: min(100dvh, var(--visible-height, 100dvh)); transform: translateY(var(--visible-top, 0px)); display: flex; flex-direction: column; }
.chat-page .topbar { position: relative; }
.chat-menu { display: none; margin-left: auto; }
.chat-tools-slot { display: none; }
.chat-layout { flex: 1; display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 0; transition: grid-template-columns var(--t2) var(--e); }
/* A plain list of titles, like every chat app: the newest picture is already
   on screen, and a thumbnail per row only made the column noisy. */
.chat-sidebar { background: var(--chrome); border-right: 1px solid var(--line); padding: var(--sp-3) var(--sp-2); display: flex; flex-direction: column; gap: var(--sp-3); min-height: 0; overflow: hidden; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.sidebar-close { display: none; }
.conversation-list { flex: 1; overflow: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 1px; }
.conversation-group { margin: 14px 10px 4px; font-size: var(--fz-2xs); font-weight: var(--fw-medium); color: var(--fg-4); }
.conversation-group:first-child { margin-top: 2px; }
.conversation-item {
  position: relative; flex: none;
  display: flex; align-items: center; height: 36px;
  color: var(--fg-2); border-radius: var(--r2);
  /* A long press opens our menu; iOS must not also offer to copy the title. */
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
  transition: color var(--t1) var(--e), background var(--t1) var(--e);
}
.conversation-item:hover { color: var(--fg); background: var(--raised); }
.conversation-item[data-current] { color: var(--fg); background: var(--a-dim); }
/* The row a menu belongs to stays lit while the menu is open. */
.conversation-item:has(.conversation-more[aria-expanded="true"]):not([data-current]) { color: var(--fg); background: var(--raised); }
.conversation-open {
  flex: 1; min-width: 0; align-self: stretch; padding: 0 10px;
  font-size: var(--fz-sm); text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-radius: inherit;
}
.conversation-open:focus-visible { outline: 2px solid var(--a); outline-offset: -2px; }
.conversation-busy { flex: none; width: 6px; height: 6px; margin: 0 10px 0 4px; border-radius: 50%; background: var(--a); animation: conversationBusy 1.4s var(--e) infinite; }
@keyframes conversationBusy { 50% { opacity: .35; } }
/* Kept in the tab order while invisible, so keyboard users still reach it;
   it takes no width until shown so idle titles get the whole row. */
.conversation-more { width: 0; margin-right: 0; overflow: hidden; opacity: 0; }
.conversation-more:hover { background: var(--hover); }
.conversation-item:is(:hover, :focus-within, [data-current]) .conversation-more,
.conversation-more[aria-expanded="true"] { width: 28px; margin-right: 4px; opacity: 1; }
.conversation-rename { flex: 1; min-width: 0; height: 28px; margin: 0 4px; padding: 0 6px; font-size: var(--fz-sm); -webkit-user-select: text; user-select: text; }
.conversation-item[data-renaming] { background: transparent; }
.conversation-item[data-renaming] .conversation-more { display: none; }
/* Collapsed to a rail: just the two actions, stacked. The list leaves the
   tab order with it. */
@media (min-width: 861px) {
  .chat-page[data-rail="collapsed"] .chat-layout { grid-template-columns: 52px minmax(0, 1fr); }
  .chat-page[data-rail="collapsed"] .chat-sidebar { padding-inline: 0; }
  .chat-page[data-rail="collapsed"] .sidebar-heading { flex-direction: column; }
  .chat-page[data-rail="collapsed"] .conversation-list { display: none; }
}
/* The conversation menu: a manual popover in the top layer, placed by script
   beside the ⋯ button, the pointer, or the long-pressed row. */
.conv-menu {
  inset: auto; margin: 0; padding: 4px; min-width: 176px;
  color: var(--fg);
  background: color-mix(in srgb, var(--raised) 97%, transparent);
  border: 1px solid var(--line-2); border-radius: var(--r3);
  box-shadow: var(--sh-3), var(--sh-lip);
  backdrop-filter: blur(16px);
}
.conv-menu:popover-open { display: grid; gap: 1px; animation: convMenuIn var(--t1) var(--e-out); }
@keyframes convMenuIn { from { opacity: 0; transform: translateY(3px) scale(.99); } }
.conv-menu button {
  display: flex; align-items: center; gap: 10px; min-height: 32px; padding: 0 10px;
  font-size: var(--fz-sm); color: var(--fg-2); text-align: left;
  border-radius: var(--r1);
  transition: color var(--t1) var(--e), background var(--t1) var(--e);
}
.conv-menu button .ico { width: 16px; height: 16px; color: var(--fg-3); }
.conv-menu button:is(:hover, :focus-visible) { color: var(--fg); background: var(--hover); outline: none; }
.conv-menu button:is(:hover, :focus-visible) .ico { color: currentColor; }
.conv-menu button[aria-disabled="true"] { opacity: .45; cursor: default; }
.conv-menu button[aria-disabled="true"]:hover { color: var(--fg-2); background: none; }
.conv-menu .danger, .conv-menu .danger .ico { color: var(--err); }
.conv-menu .danger:is(:hover, :focus-visible) { color: var(--err); background: var(--err-dim); }
.conv-menu hr { margin: 4px 6px; border: 0; border-top: 1px solid var(--line); }
@media (prefers-reduced-motion: reduce) {
  .conversation-busy { animation: none; }
  .chat-layout { transition: none; }
}
.chat-workspace { display: flex; flex-direction: column; min-height: 0; position: relative; background: var(--canvas); }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scroll-padding: 24px; }
.chat-empty { min-height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: var(--sp-3); padding: var(--sp-5); text-align: center; color: var(--fg-3); }
.chat-empty .ico { color: var(--fg-3); margin-bottom: 4px; }
.chat-empty h1 { color: var(--fg-2); font-size: var(--fz-lg); font-weight: var(--fw-medium); }
/* The stream: what you asked on the right, the model's pictures on the left.
   Messages and composer share one column so the exchange reads as one line
   of conversation instead of a gallery with a text box under it. */
.chat-page { --column: 832px; --img-w: 600px; --img-h: min(62dvh, 640px); }
.message-list { max-width: calc(var(--column) + 48px); margin: 0 auto; padding: var(--sp-6) var(--sp-5) var(--sp-5); display: grid; gap: 40px; }
.message-list:empty { display: none; }
.chat-turn { min-width: 0; display: grid; gap: var(--sp-4); }
.msg { min-width: 0; }
.msg-user { position: relative; justify-self: end; max-width: min(78%, 600px); display: grid; justify-items: end; gap: 6px; }
.msg-bubble { padding: 10px 16px; background: var(--raised); border: 1px solid var(--line); border-radius: 18px 18px 6px 18px; color: var(--fg); font-size: var(--fz-md); line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; outline: none; }
.turn-references { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.turn-references button { width: 64px; height: 64px; overflow: hidden; border-radius: var(--r3); background: var(--well); box-shadow: 0 0 0 1px var(--line-2); }
/* The init image: the one picture this turn actually edited. */
.turn-references button[data-slot="base"] { box-shadow: 0 0 0 2px rgba(179, 161, 255, .62); }
.turn-references img { display: block; width: 100%; height: 100%; object-fit: cover; }
/* Beside the bubble rather than under it, so hidden tools hold no space. */
.msg-tools { position: absolute; right: 100%; bottom: 0; display: flex; gap: 2px; padding-right: 6px; opacity: 0; transition: opacity var(--t1) var(--e); }
.msg-user:hover .msg-tools, .msg-user:focus-within .msg-tools { opacity: 1; }
.msg-tools .ibtn { width: 28px; height: 28px; --ico: 15px; }
.msg-model { display: grid; gap: 10px; }
.msg-head { display: flex; align-items: center; gap: 8px; min-height: 28px; color: var(--fg-2); font-size: var(--fz-sm); }
.msg-avatar { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: var(--fg-2); background: var(--raised); box-shadow: 0 0 0 1px var(--line-2); }
.msg-avatar .ico { width: 14px; height: 14px; }
.msg-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--fw-medium); }
.msg-phase { flex: none; display: inline-flex; gap: 6px; color: var(--a); font-size: var(--fz-xs); }
.msg-elapsed { color: var(--fg-3); font-size: var(--fz-2xs); }
.version-pager { flex: none; display: inline-flex; align-items: center; margin-left: 2px; color: var(--fg-3); }
.version-pager .ibtn { width: 24px; height: 24px; --ico: 14px; }
.version-pager .ibtn:disabled { opacity: .35; pointer-events: none; }
.version-prev .ico { transform: rotate(180deg); }
.version-count { min-width: 30px; text-align: center; font-size: var(--fz-2xs); font-variant-numeric: tabular-nums; }
/* Indented under the name, so the avatar column stays a clean left edge. */
.msg-body { min-width: 0; display: grid; justify-items: start; gap: var(--sp-3); padding-left: 34px; }
.msg-body[data-images] { display: flex; flex-wrap: wrap; align-items: flex-start; }
.msg-body[data-images] .msg-text { flex-basis: 100%; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fz-md); line-height: 1.75; color: var(--fg); }
.chat-result { width: min(100%, var(--image-width), var(--img-w), calc(var(--img-h) * var(--image-ratio))); display: grid; gap: 6px; }
.msg-body[data-images] .chat-result { width: min(calc(50% - 6px), var(--image-width), calc(var(--img-w) / 2), calc(var(--img-h) * var(--image-ratio) / 2)); }
.chat-page .chat-print { width: 100%; max-width: 100%; animation: none; transition: box-shadow var(--t2) var(--e); }
.chat-page .chat-print[data-new="true"] { animation: printIn var(--t3) var(--e-out); }
.chat-page .chat-print img { width: 100%; height: auto; max-width: 100%; max-height: var(--img-h); object-fit: contain; }
/* Marks the picture the next turn will edit, which used to be visible only
   inside the context panel. */
.chat-page .chat-print[data-base] { box-shadow: 0 0 0 2px rgba(179, 161, 255, .62), 0 14px 36px -12px rgba(0,0,0,.6); }
/* While a fresh result opens out of the wave, the picture is the canvas's
   until it has fully merged; the frame and the base mark arrive with the crest. */
.chat-page .chat-print[data-reveal] img { opacity: 0; }
.chat-page .chat-print[data-wave] { transition: box-shadow 1.2s var(--e); }
.chat-page .chat-print[data-wave="rest"] { box-shadow: var(--print-shadow-off); }
.chat-page .chat-pending { width: min(100%, var(--img-w), calc(var(--img-h) * var(--image-ratio, 1))); height: auto; aspect-ratio: var(--image-ratio, 1); }
.turn-error { max-width: 520px; padding: 12px 14px; border: 1px solid var(--line-2); border-radius: var(--r3); background: var(--chrome); display: grid; gap: 10px; justify-items: start; overflow-wrap: anywhere; }
.turn-error p { display: flex; gap: 8px; color: var(--fg-2); line-height: 1.6; }
.turn-error p .ico { width: 16px; height: 16px; margin-top: 3px; color: var(--fg-3); }
.msg-model[data-status="error"] .turn-error p { color: var(--err); }
.msg-model[data-status="error"] .turn-error p .ico { color: var(--err); }
.chat-meta { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.chat-meta .result-actions { display: flex; gap: 2px; margin-left: -6px; transition: opacity var(--t1) var(--e); }
.chat-meta .result-actions .ibtn { background: transparent; border-color: transparent; box-shadow: none; }
.chat-meta .result-actions .ibtn:hover { background: var(--raised); }
.chat-meta .result-actions .ibtn-accent, .chat-meta .result-actions .ibtn-accent:hover { color: var(--a); }
.chat-meta-info { margin-left: auto; display: flex; gap: 10px; flex: none; color: var(--fg-3); font-size: var(--fz-2xs); }
/* Older answers keep their tools out of the way until pointed at; the newest
   one, the usual next step, always shows them. */
@media (hover: hover) {
  .chat-turn:not(:last-child) .result-actions { opacity: 0; }
  .chat-turn:hover .result-actions, .chat-result:focus-within .result-actions { opacity: 1; }
}
/* Touch has no hover: the newest prompt shows its tools under the bubble, and
   older ones show theirs once the bubble is tapped. */
@media (hover: none) {
  .msg-tools { position: static; padding: 0; margin-right: -6px; opacity: 1; }
  .chat-turn:last-child .msg-tools { display: flex; }
  .chat-turn:not(:last-child) .msg-tools { display: none; }
  .chat-turn:not(:last-child) .msg-user:focus-within .msg-tools { display: flex; }
}
/* The composer: attachments, the text, then one toolbar — upload and context
   on the left; model, any credit cost and send on the right. */
.chat-composer { position: relative; flex: none; width: calc(100% - 48px); max-width: var(--column); align-self: center; margin: 0 24px 20px; padding: 8px 10px 10px; background: var(--chrome); border: 1px solid var(--line-2); border-radius: var(--r4); box-shadow: var(--sh-lip), 0 8px 28px -16px rgba(0,0,0,.55); transition: border-color var(--t1) var(--e), background var(--t1) var(--e); }
.chat-page #chatPrompt { display: block; resize: none; min-height: 44px; max-height: 26dvh; background: transparent; border-color: transparent; box-shadow: none; padding: 10px 6px; font-size: var(--fz-md); line-height: 1.6; }
.chat-page #chatPrompt::placeholder { color: var(--fg-3); }
.chat-composer-bottom { display: flex; align-items: center; gap: 4px; }
.context-button { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; color: var(--fg-3); font: var(--fw-medium) var(--fz-xs)/1 var(--mono); border-radius: var(--r2); transition: color var(--t1) var(--e), background var(--t1) var(--e); }
.context-button .ico { width: 14px; height: 14px; }
.context-divider { width: 1px; height: 10px; background: var(--line-2); margin-inline: 2px; }
.context-button:hover { color: var(--fg); background: var(--raised); }
/* Parameters, then the model: two quiet chips, each opening its own panel.
   The parameter chip is just its icon until something leaves the default. */
.param-button, .model-chip { display: inline-flex; align-items: center; gap: 6px; min-width: 0; height: 32px; font-size: var(--fz-sm); white-space: nowrap; border-radius: 999px; transition: color var(--t1) var(--e), background var(--t1) var(--e); }
.param-button { position: relative; justify-content: center; flex: 0 1 auto; min-width: 32px; margin-left: auto; padding: 0 8px; color: var(--fg-3); }
.param-button[data-changed] { padding-inline: 9px 11px; color: var(--fg-2); }
.param-button .ico { width: 16px; height: 16px; }
.param-summary { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.param-summary:empty { display: none; }
.param-button[hidden] + .model-chip { margin-left: auto; }
.model-chip { flex: 0 1 auto; padding: 0 8px 0 10px; color: var(--fg-2); }
.param-button:hover, .param-button[aria-expanded="true"], .model-chip:hover, .model-chip[aria-expanded="true"] { color: var(--fg); background: var(--raised); }
.param-button:focus-visible, .model-chip:focus-visible { outline: 2px solid var(--a); outline-offset: 1px; }
.model-chip-icon { flex: none; width: 15px; height: 15px; }
.model-chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.model-chip-caret { flex: none; width: 12px; height: 12px; color: var(--fg-3); transform: rotate(90deg); transition: transform var(--t1) var(--e); }
.model-chip[aria-expanded="true"] .model-chip-caret { transform: rotate(-90deg); }
.quote-cost { flex: none; padding: 0 4px; font-size: var(--fz-xs); color: var(--warn); }
/* Send and stop stack in one cell: send shrinks away as stop grows in. */
.send-slot { display: grid; flex: none; margin-left: 4px; }
.send-slot > .btn { grid-area: 1 / 1; width: 40px; height: 40px; padding: 0;
  transition: opacity var(--t2) var(--e), transform var(--t2) var(--e-out), visibility 0s,
    color var(--t2) var(--e), background-color var(--t2) var(--e), border-color var(--t1) var(--e), box-shadow var(--t2) var(--e); }
.send-slot > .btn[hidden] { display: inline-flex; visibility: hidden; pointer-events: none; opacity: 0; transform: scale(.72);
  transition: opacity var(--t1) var(--e), transform var(--t1) var(--e), visibility 0s linear var(--t1); }
.chat-send .ico { width: 20px; height: 20px; stroke-width: 2; }
/* Stop: a ring that turns while the turn runs, around the square that ends
   it. Neutral at rest; the error hue only on hover, when it means "cancel". */
.chat-stop { position: relative; color: var(--fg); background: var(--raised); border: 1px solid var(--line-2); border-radius: var(--r3); box-shadow: var(--sh-lip); }
.chat-stop .ico { width: 20px; height: 20px; fill: currentColor; stroke: none; }
.chat-stop::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; border: 2px solid var(--a-dim); border-top-color: var(--a); animation: goSpin .9s linear infinite; pointer-events: none; }
/* Only where a pointer can actually hover: a tap leaves :hover stuck on
   touch screens, and the stop that just appeared under the finger would sit
   there red. */
@media (hover: hover) {
  .chat-stop:hover { color: var(--err); background: rgba(232,135,135,.1); border-color: rgba(232,135,135,.38); }
  .chat-stop:hover::before { border-color: rgba(232,135,135,.16); border-top-color: var(--err); }
}
.chat-inline-error { color: var(--err); font-size: var(--fz-xs); overflow-wrap: anywhere; }
.chat-inline-error:not(:empty) { margin: 0 6px 6px; }
.chat-attachments { display: flex; gap: 8px; overflow-x: auto; overscroll-behavior: contain; }
.chat-attachments:not(:empty) { padding: 2px 2px 4px; }
.attachment { position: relative; flex: none; width: 56px; height: 56px; border: 1px solid var(--line-2); background: var(--well); border-radius: var(--r3); }
.attachment-preview { display: block; width: 100%; height: 100%; border-radius: inherit; overflow: hidden; }
.attachment img { display: block; width: 100%; height: 100%; object-fit: cover; }
.attachment-loading { overflow: hidden; border-color: var(--line); }
.chat-page .attachment-remove { position: absolute; top: -2px; right: -2px; width: 28px; height: 28px; border: 0; border-radius: 50%; color: var(--canvas); background: transparent; }
.attachment-remove::before { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: var(--fg); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.attachment-remove .ico { position: relative; width: 10px; height: 10px; stroke-width: 2.2; }
.attachment-remove:hover::before { background: #fff; }
/* Files dragged anywhere over the page land here; say so while they hover. */
.chat-composer[data-drop] { border-color: var(--a); border-style: dashed; }
.chat-composer[data-drop]::after { content: "松开添加图片"; position: absolute; inset: 0; display: grid; place-items: center; border-radius: inherit; color: var(--a); font-size: var(--fz-sm); font-weight: var(--fw-medium); background: color-mix(in srgb, var(--chrome) 92%, var(--a)); pointer-events: none; }
/* The two panels, built on the editor's popover (.editor-pop): models as a
   short checked menu grouped by provider; settings as rows of chips. Each is
   as wide as its content needs. */
.chat-pop { width: max-content; max-width: calc(100vw - 16px); }
.model-panel { min-width: 200px; }
.model-panel .editor-pop-item { min-height: 30px; font-size: var(--fz-sm); }
.model-panel .editor-pop-group p.model-group-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px 3px; }
.model-group-head .ico { width: 12px; height: 12px; }
.model-panel-foot { padding-top: 3px; border-top: 1px solid var(--line); }
.model-panel .model-manage { width: 100%; gap: 6px; color: var(--fg-3); }
.model-manage .ico { width: 12px; height: 12px; }
/* The radio covers its whole label, so the label is the click target and the
   radio still takes keyboard focus and arrow keys natively. */
.chat-pop input[type="radio"] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.param-panel { max-width: min(400px, 100vw - 16px); }
.param-rows { display: grid; gap: 8px; padding: 6px 6px 4px; }
.param-row { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: start; gap: 8px; }
.param-name { padding-top: 6px; font-size: var(--fz-2xs); color: var(--fg-4); }
.param-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.param-chip { position: relative; display: inline-flex; align-items: center; min-height: 28px; padding: 0 9px; font-size: var(--fz-xs); color: var(--fg-3); background: var(--well); border-radius: var(--r1); transition: color var(--t1) var(--e), background var(--t1) var(--e); }
.param-chip:hover { color: var(--fg); }
.param-chip:has(input:checked) { color: var(--fg); background: var(--a-dim); box-shadow: inset 0 0 0 1px var(--a-line); }
.param-chip:has(input:focus-visible) { outline: 2px solid var(--a); outline-offset: 1px; }
/* ── Context panel: what the next turn sends ──
   On desktop a third column that narrows the chat rather than covering it,
   so results can be picked and the turn sent while it is open; a bottom
   sheet on phones. */
.chat-page { --context-w: 340px; }
.context-panel { position: static; width: auto; max-width: none; height: auto; max-height: none; margin: 0; padding: 0; color: var(--fg); background: var(--chrome); border: 0; border-left: 1px solid var(--line); }
.context-panel[open] { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
@media (min-width: 861px) {
  .chat-page[data-context="open"] .chat-layout { grid-template-columns: 248px minmax(0, 1fr) var(--context-w); }
  .chat-page[data-context="open"][data-rail="collapsed"] .chat-layout { grid-template-columns: 52px minmax(0, 1fr) var(--context-w); }
}
@media (max-width: 1199px) { .chat-page { --context-w: 300px; } }
.context-button[aria-expanded="true"] { color: var(--fg); background: var(--raised); }
.context-head { flex: none; display: flex; align-items: center; gap: 2px; height: 52px; padding: 0 8px 0 16px; }
.context-head h2 { flex: 1; margin: 0; font-size: var(--fz-md); font-weight: var(--fw-semibold); }
/* One column width for every picture in the panel; the base takes two. */
.context-body { --cols: 4; --gap: 8px; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 16px 24px; }
.context-section + .context-section { margin-top: 20px; border-top: 1px solid var(--line); }
.context-section-head { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.context-section-head h3 { margin: 0; font-size: var(--fz-xs); font-weight: var(--fw-semibold); color: var(--fg-2); }
/* Capacity is a count against the model's cap, not a sentence. */
.context-count { margin-left: auto; font-size: var(--fz-xs); color: var(--fg-4); font-variant-numeric: tabular-nums; }
.context-count[data-state="over"], .context-over { color: var(--warn); }
.context-over { font-size: var(--fz-xs); }
.context-group { margin-top: 16px; }
.context-sub { margin: 0 0 8px; font-size: var(--fz-xs); color: var(--fg-4); }
.context-grid, .context-base { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: var(--gap); }
/* The base is the picture being edited: the largest tile, its label and the
   follow switch beside it in the remaining columns. */
.context-base > .context-tile { grid-column: span 2; }
.context-base-meta { grid-column: 3 / -1; display: flex; flex-direction: column; justify-content: space-between; min-width: 0; padding-block: 2px; }
.context-base-label { display: grid; gap: 2px; margin: 0; font-size: var(--fz-xs); color: var(--fg-3); }
.context-base-label b { font-size: var(--fz-sm); font-weight: var(--fw-semibold); color: var(--fg); }
.context-follow { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 28px; font-size: var(--fz-xs); color: var(--fg-2); cursor: pointer; }
.context-follow input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch { position: relative; flex: none; width: 28px; height: 16px; border-radius: 999px; background: var(--line-2); transition: background var(--t1) var(--e); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--fg-2); transition: transform var(--t1) var(--e-out), background var(--t1) var(--e); }
.context-follow input:checked + .switch { background: var(--a); }
.context-follow input:checked + .switch::after { transform: translateX(12px); background: #fff; }
.context-follow input:focus-visible + .switch { outline: 2px solid var(--a); outline-offset: 2px; }
.context-tile { position: relative; display: block; width: 100%; aspect-ratio: 1; padding: 0; overflow: hidden; background: var(--well); border: 1px solid var(--line-2); border-radius: var(--r2); cursor: pointer; transition: border-color var(--t1) var(--e), opacity var(--t1) var(--e); }
.context-base > .context-tile { border-radius: var(--r3); }
.context-tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
.context-tile:hover { border-color: var(--fg-4); }
.context-tile:focus-visible { outline: 2px solid var(--a); outline-offset: 2px; }
.context-tile[data-dragging] { opacity: .35; }
.context-tile[data-dropped] { border-style: dashed; }
.context-tile[data-dropped] img { opacity: .4; filter: grayscale(1); }
.context-tile-empty { display: grid; place-items: center; color: var(--fg-4); border-style: dashed; cursor: default; }
.context-tile-empty:hover { border-color: var(--line-2); }
/* Order number top-left, provenance bottom-right: both legible on any picture. */
.context-tile-no, .context-tile-origin { position: absolute; display: inline-flex; align-items: center; justify-content: center; height: 16px; padding: 0 4px; font: var(--fw-medium) 10px/1 var(--mono); color: #fff; background: rgba(0,0,0,.6); }
.context-tile-no { top: 4px; left: 4px; min-width: 16px; border-radius: 999px; }
.context-tile-origin { right: 4px; bottom: 4px; border-radius: 4px; }
.context-tile-origin .ico { width: 10px; height: 10px; }
.context-pool .context-tile img { opacity: .6; }
.context-pool .context-tile:is(:hover, :focus-visible) img { opacity: 1; }
.context-tile-add { position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; color: #fff; background: var(--a); }
.context-tile-add .ico { width: 10px; height: 10px; stroke-width: 2.4; }
/* Where a dragged picture will land. */
.context-base[data-over] > .context-tile, .context-grid[data-over], .context-tile[data-over] { outline: 2px dashed var(--a); outline-offset: 3px; }
/* Text rows share three columns — box, turn number, text — and their hover
   wash bleeds into the gutter so the content keeps the panel's left edge. */
.context-turns { display: grid; gap: 2px; margin-inline: -8px; }
.context-turn, .check.context-turn { display: grid; grid-template-columns: 16px 28px minmax(0, 1fr); column-gap: 8px; align-items: start; padding: 6px 8px; font-size: var(--fz-sm); line-height: 20px; color: var(--fg-2); border-radius: var(--r2); }
.check.context-turn:hover { background: var(--hover); }
.check.context-turn > span:first-of-type { margin-top: 2px; }
.context-turn-no { font-size: var(--fz-2xs); color: var(--fg-4); }
.context-turn-text { min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.context-turn:has(input:not(:checked)) .context-turn-text { color: var(--fg-4); text-decoration: line-through; }
.context-now-mark { display: grid; place-items: center; height: 20px; }
.context-now-mark::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--a); }
.context-now .context-turn-no { font-size: var(--fz-xs); color: var(--a); }
.context-now [data-empty] { color: var(--fg-4); }
.context-raw { margin: 2px -8px 0; }
.context-raw summary { display: grid; grid-template-columns: 16px minmax(0, 1fr); column-gap: 8px; align-items: center; padding: 6px 8px; list-style: none; font-size: var(--fz-xs); line-height: 20px; color: var(--fg-3); cursor: pointer; border-radius: var(--r2); }
.context-raw summary::-webkit-details-marker { display: none; }
.context-raw summary:hover { color: var(--fg); background: var(--hover); }
.context-raw summary:focus-visible { outline: 2px solid var(--a); outline-offset: -2px; }
.context-raw summary .ico { justify-self: center; width: 14px; height: 14px; transition: transform var(--t1) var(--e); }
.context-raw[open] summary .ico { transform: rotate(90deg); }
.context-raw pre { margin: 4px 8px 0; padding: 10px 12px; max-height: 260px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: var(--fz-xs)/1.7 var(--sans); color: var(--fg-2); background: var(--well); border-radius: var(--r2); }
.attachment[data-dropped="true"] { border-style: dashed; }
.attachment[data-dropped="true"] img { opacity: .4; filter: grayscale(1); }
/* The overflow count rides the entry point, since the panel is usually closed.
   Inline rather than a corner badge: the composer row is 22px tall and a
   floating dot would clip against the neighbouring status text. */
#contextButton.has-overflow { color: var(--warn); }
#contextButton.has-overflow::after { content: "−" attr(data-overflow); padding: 1px 5px; border-radius: 999px; font-size: 10px; font-weight: var(--fw-semibold); color: var(--warn); background: rgba(224,171,104,.14); }
.chat-lightbox::backdrop { background: rgba(8,8,10,.8); backdrop-filter: blur(4px); }
.dialog-note, .dialog-note:empty { color: var(--fg-3); font-size: var(--fz-xs); }
.dialog-note { margin-top: 16px; }
.quota-row { display: flex; justify-content: space-between; gap: 16px; padding-block: 8px; color: var(--fg-2); }
.chat-lightbox { padding: 12px; border: 0; background: transparent; max-width: 100vw; max-height: 100dvh; overflow: auto; }
.chat-lightbox img { display: block; max-width: calc(100vw - 24px); max-height: calc(100dvh - 64px); object-fit: contain; }
.chat-lightbox .ibtn { display: grid; margin-left: auto; margin-bottom: 8px; background: var(--raised); }
.latest-button { position: absolute; bottom: calc(var(--composer-height, 180px) + 32px); left: 50%; transform: translateX(-50%); z-index: 2; border-radius: 50%; background: var(--raised); border: 1px solid var(--line-2); box-shadow: var(--sh-1); }
.latest-button:active { transform: translateX(-50%) scale(.94); }
/* A new conversation: greeting and composer sit together mid-screen, as the
   start of a conversation rather than an empty page with a bar at the bottom. */
@media (min-width: 861px) {
  .chat-workspace[data-empty="true"] { justify-content: center; padding-bottom: 10vh; }
  .chat-workspace[data-empty="true"] .chat-scroll { flex: none; overflow: visible; }
  .chat-workspace[data-empty="true"] .chat-empty { min-height: 0; padding-bottom: 28px; }
}
@media (max-width: 860px) {
  .chat-page { --bar-h: 54px; }
  .chat-page .topbar { padding: 0 12px; gap: 8px; }
  .chat-page .brand { gap: 7px; }
  .chat-page .brand-mark { --m: 28px; }
  .chat-page .brand-title { font-size: 18px; }
  .chat-page .brand-subtitle { font-size: 9px; }
  .chat-page .brand-wordmark { gap: 6px; }
  /* Balances right-aligned beside the menu button, as on the NAI page. */
  .chat-app > .topbar .topbar-account { margin-left: auto; }
  .chat-app > .topbar .topbar-menu { order: 1; margin-left: 0; }
  .chat-app > .topbar .topbar-sep { display: none; }
  .chat-menu { display: grid; }
  .chat-tools-slot { display: block; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
  .chat-tools-slot .topbar-end { gap: 8px; }
  .chat-tools-slot [data-tip]::after { display: none; }
  .chat-layout { grid-template-columns: minmax(0,1fr); }
  .chat-sidebar { position: absolute; inset: var(--bar-h) auto 0 0; width: min(280px, 85vw); z-index: var(--z-pop); visibility: hidden; transform: translateX(-100%); transition: transform var(--t2) var(--e), visibility var(--t2); }
  .chat-page[data-sidebar="open"] .chat-sidebar { visibility: visible; transform: none; }
  .chat-sidebar-backdrop { position: absolute; inset: var(--bar-h) 0 0; z-index: calc(var(--z-pop) - 1); background: rgba(0,0,0,.55); }
  .sidebar-close { display: grid; }
  .rail-toggle { display: none; }
  /* Touch has no hover, so ⋯ shows on the open conversation; the rest long-press. */
  .conversation-item { height: 44px; }
  /* Under 16px iOS zooms the page to edit the name. */
  .conversation-rename { height: 34px; font-size: 16px; }
  .conversation-item:is(:hover, :focus-within, [data-current]) .conversation-more,
  .conversation-more[aria-expanded="true"] { width: 36px; height: 36px; }
  .conv-menu button { min-height: 44px; font-size: var(--fz-md); }
  .chat-page { --img-w: 100%; --img-h: 66dvh; }
  .message-list { padding: 20px 12px; gap: 32px; }
  .msg-user { max-width: 88%; }
  /* No room beside a near-full-width bubble: tools drop under it instead. */
  .msg-tools { position: static; display: none; padding: 0; margin-right: -6px; opacity: 1; }
  .msg-user:hover .msg-tools, .msg-user:focus-within .msg-tools { display: flex; }
  .msg-body { padding-left: 0; }
  .chat-page .msg-tools .ibtn { width: 40px; height: 40px; }
  .chat-page .version-pager .ibtn { width: 36px; height: 36px; }
  .chat-composer { width: 100%; margin: 0; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-radius: 0; border-inline: 0; border-bottom: 0; }
  .chat-page #chatPrompt { font-size: 16px; min-height: 40px; max-height: 22dvh; padding: 8px 4px; }
  .chat-composer-bottom { gap: 2px; }
  .param-button { flex: none; width: 44px; height: 44px; padding: 0; }
  .param-button[data-changed] { padding: 0; }
  .param-summary { display: none; }
  /* No room for the summary, so a dot says "not the defaults". */
  .param-button[data-changed]::after { content: ""; position: absolute; top: 10px; right: 9px; width: 6px; height: 6px; border-radius: 50%; background: var(--a); }
  .model-chip { height: 44px; padding-inline: 10px 8px; }
  .send-slot > .btn { width: 44px; height: 44px; }
  /* Both panels become bottom sheets, sized for thumbs. */
  /* Doubled class: editor.css loads after this file and resets inset. */
  .editor-pop.chat-pop { inset: auto 0 0 0; width: 100%; min-width: 0; max-width: none; max-height: 80dvh; padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); border-bottom: 0; border-radius: var(--r4) var(--r4) 0 0; }
  .chat-pop::backdrop { background: rgba(0,0,0,.45); }
  .model-panel .editor-pop-item { min-height: 44px; font-size: var(--fz-md); }
  .model-panel .editor-pop-group p.model-group-head { padding: 8px 8px 4px; font-size: var(--fz-xs); }
  .param-row { grid-template-columns: 48px minmax(0, 1fr); }
  .param-name { padding-top: 12px; font-size: var(--fz-xs); }
  .param-chip { min-height: 40px; padding: 0 14px; font-size: var(--fz-sm); }
  .chat-page .ibtn, .chat-meta .result-actions .ibtn { width: 44px; height: 44px; }
  .chat-page .chat-menu { width: 36px; height: 44px; }
  .attachment { width: 64px; height: 64px; }
  .chat-page .attachment-remove { width: 44px; height: 44px; top: -8px; right: -8px; }
  .attachment-remove::before { width: 22px; height: 22px; }
  .context-button { height: 44px; padding-inline: 8px; }
  /* The context panel as a bottom sheet, its rows sized for thumbs. */
  .context-panel:modal { position: fixed; inset: auto 0 0 0; width: 100%; max-height: 85dvh; padding-bottom: env(safe-area-inset-bottom); border-left: 0; border-top: 1px solid var(--line-2); border-radius: var(--r4) var(--r4) 0 0; }
  .context-panel::backdrop { background: rgba(0,0,0,.45); }
  .context-body { --cols: 5; }
  .context-follow { min-height: 44px; font-size: var(--fz-sm); }
  .context-turn, .check.context-turn { padding-block: 12px; font-size: var(--fz-md); }
  .context-raw summary { padding-block: 12px; font-size: var(--fz-sm); }
  .latest-button { bottom: calc(var(--composer-height, 180px) + 12px); }
}
/* Small phones: the model name needs the room more than its provider mark. */
@media (max-width: 400px) {
  .chat-composer { padding-inline: 8px; }
  .model-chip-icon { display: none; }
  .context-button { gap: 4px; padding-inline: 4px; }
}
@media (max-width: 360px) {
  .chat-page .topbar { padding-inline: 6px; gap: 4px; }
}
@media (prefers-reduced-motion: reduce) { .chat-stop::before { animation-duration: 2.4s; } }
