/* Loaded after chat.html's inline styles. Header rules are chat-only. */
.delegation-source-picker { margin-block: 10px; max-width: 100%; min-width: 0; }
.delegation-source-picker summary { cursor: pointer; padding: 10px 4px; }
.delegation-source-picker fieldset { min-width: 0; max-height: 280px; overflow: auto; }
.delegation-source-picker .delegation-source { display: flex; align-items: flex-start; gap: 8px; padding: 8px 0; }
.delegation-source-picker .delegation-source > span { min-width: 0; overflow-wrap: anywhere; }
.delegation-source-picker small { display: block; font-size: 0.85em; }
.delegation-source-picker input[type=checkbox] { min-width: 20px; min-height: 20px; }
.delegation-source-picker .delegation-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.delegation-source-picker button { min-height: 40px; white-space: normal; }
body > header.chat-header {
  flex: 0 0 auto;
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
  gap: 6px 8px;
}
body > header.chat-header > h1 {
  flex: 0 1 260px;
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}
body > header.chat-header > .sub {
  min-width: 0;
  max-width: 320px;
  flex: 0 1 auto;
  white-space: normal;
  overflow-wrap: anywhere;
}
body > header.chat-header > #live-user { max-width: 220px; }
body > header.chat-header > #dot { flex: 0 0 9px; }
body > header.chat-header > .spacer { min-width: 0; flex: 1 0 0; }
body > header.chat-header > :is(button, a, select) {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}
body > header.chat-header > :is(.icon-btn, .micro-btn) {
  width: 44px;
  height: 44px;
  padding: 0;
}
body > header.chat-header svg, .mobile-menu-body .header-nav-icon svg { flex-shrink: 0; }
body > header.chat-header > .header-nav-icon { text-decoration: none; }
body > header.chat-header > [hidden], .mobile-menu-body > [hidden], #inputbar #pwa-status[hidden],
#inputbar #pwa-actions button[hidden] { display: none; }

.mobile-panel-toolbar, #mobile-chats-close, #mobile-doc-close,
#mobile-overlay-backdrop { display: none; }

@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px) {
  html { height: 100%; }
  body {
    height: 100vh;
    height: var(--app-height, 100dvh);
    position: relative;
    top: var(--app-top, 0px);
    min-width: 0;
    overflow: hidden;
  }
  body.standalone-layout { height: 100%; }
  body > header.chat-header {
    flex: 0 0 auto;
    gap: 4px 6px;
    padding: calc(6px + env(safe-area-inset-top, 0px))
      calc(8px + env(safe-area-inset-right, 0px)) 6px
      calc(8px + env(safe-area-inset-left, 0px));
    max-height: 32%;
    overflow-y: auto;
    overflow-wrap: anywhere;
  }
  body > header.chat-header h1 { font-size: 14px; min-width: 0; flex: 1 1 170px; }
  main {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    position: relative;
    margin-left: env(safe-area-inset-left, 0px);
    margin-right: env(safe-area-inset-right, 0px);
  }
  #chatcol { min-width: 0; min-height: 0; }
  #chat { min-height: 0; padding: 10px 8px; overscroll-behavior: contain; }
  #inputbar {
    flex: 0 1 auto;
    min-height: 0;
    max-height: 60%;
    overflow-y: auto;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  #delegations-panel { max-height: min(34vh, 300px); padding: 6px 8px; }
  .delegations-head, .delegation-card > header, .delegation-actions { min-width: 0; flex-wrap: wrap; }
  .delegation-actions button { flex: 1 1 180px; }
  .delegation-preview pre, .delegation-result { max-height: 160px; }
  .delegation-source > span { min-width: 0; }
  #inputbar #composer-message-row { flex-wrap: nowrap; gap: 4px; min-width: 0; }
  #inputbar #ta {
    flex: 1 1 0%;
    width: 0;
    min-width: 0;
    min-height: 44px;
    max-height: min(160px, max(44px, calc(var(--app-height, 100dvh) / 5)));
    padding: 9px 10px;
  }
  #drop { padding: 4px 6px; font-size: 11px; line-height: 1.35; }
  body.keyboard-open #drop { display: none; }
  body.keyboard-open #inputbar { max-height: 62%; }
  #meta, #meta-tools { flex-wrap: wrap; gap: 4px 8px; min-width: 0; }
  #hint, #stats, #queuebar { overflow-wrap: anywhere; min-width: 0; }
  .msg, .msg.model, .doc-card { max-width: 100%; min-width: 0; }
  .doc-file .fname { max-width: 100%; overflow-wrap: anywhere; white-space: normal; }
  .doc-file .fstatus { white-space: normal; }

  /* Overlay order: backdrop, chat drawer, document. Dialog top layer wins. */
  #mobile-overlay-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 19;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: rgba(0, 0, 0, .5);
    touch-action: manipulation;
  }
  #mobile-overlay-backdrop[hidden] { display: none; }
  #chats-col {
    position: absolute; inset: 0 auto 0 0; z-index: 20;
    width: min(85vw, 320px); min-width: 0;
    max-width: 100%; min-height: 0; overflow: hidden;
    box-shadow: 8px 0 24px rgba(0, 0, 0, .35);
  }
  #chats-col .cc-head { flex-wrap: nowrap; gap: 4px; padding: 6px; }
  #chats-col #chat-search { min-width: 0; width: 0; padding-inline: 4px; }
  #chat-list { min-height: 0; overscroll-behavior: contain; }
  #docpane {
    position: absolute; inset: 0; z-index: 30;
    width: 100%; min-width: 0; flex-direction: column;
    background: var(--bg); min-height: 0; overflow: hidden;
  }
  .mobile-panel-toolbar {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
  }
  #mobile-chats-close, #mobile-doc-close { display: inline-flex; align-items: center; justify-content: center; }
  #docview-wrap { flex: 1 1 0; min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; }
  #annpanel { width: 100%; min-width: 0; overflow: auto; border-left: 0; border-top: 1px solid var(--border); flex: 0 1 auto; max-height: 40%; min-height: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  #docview { min-width: 0; }
  #docview .table-view { overflow-x: auto; max-width: 100%; }
  #docview .tv-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
  #docview .raster-view { max-width: 100%; }
  #annpanel .ann-nav, #annpanel .ann-filters, #annpanel .actions { flex-wrap: wrap; }
  .markdown-table, .markdown-body pre { max-width: 100%; overflow-x: auto; }
  .src-pop, #docview .tv-tooltip { max-width: calc(100vw - 24px); overflow-wrap: anywhere; }
}

/* All touch devices get usable controls, including tablet desktop layouts. */
@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px), (pointer: coarse) {
  body :is(#chat, #inputbar, #chats-col, #docpane, header, dialog) button,
  body :is(#chat, #chats-col, #annpanel) summary,
  body :is(#chat, #chats-col) :is(.finding, .chat-item, .sr-item, .src-chip),
  body #docview .tv-tab,
  body header a {
    min-width: 44px;
    min-height: 44px;
    height: auto;
    touch-action: manipulation;
  }
  body :is(#inputbar, #chats-col, #docpane, header, dialog) :is(.micro-btn, .icon-btn) {
    width: auto;
    min-width: 44px;
    min-height: 44px;
    height: auto;
  }
  body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea, select),
  body #ta, body #chat-search, body #input-dlg-value, body #mem-add input,
  body :is(#docpane, #inputbar, #chats-col, dialog) :is(textarea, select, input:not([type="checkbox"]):not([type="radio"]):not([type="range"])) {
    font-size: 16px;
    min-width: 0;
    max-width: 100%;
  }
  /* Keep queue actions compact even under the general touch-button rules. */
  #queuebar .qerror { max-width: 1.3em; text-overflow: clip; }
  #queuebar .qa button {
    flex: 0 0 20px;
    width: 20px;
    min-width: 20px;
    height: 24px;
    min-height: 24px;
  }
  body select { min-height: 44px; }
  body dialog {
    position: fixed;
    top: calc(12px + var(--app-top, 0px) + env(safe-area-inset-top, 0px));
    bottom: auto;
    margin: 0 auto;
    min-width: 0;
    width: min(620px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    max-height: calc(var(--app-height, 100dvh) - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow: auto;
    overscroll-behavior: contain;
    padding: 12px;
    overflow-wrap: anywhere;
  }
  body :is(#data-dlg, #execution-dlg, #mem-dlg, #input-dlg, #auth-dlg) {
    min-width: 0;
    max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    max-height: calc(var(--app-height, 100dvh) - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  dialog .actions, #data-search-row, #mem-add, .execution-head { flex-wrap: wrap; }
  body :is(#data-search-row, #mem-add) :is(input, select) { flex: 1 1 180px; min-width: 0; }
  dialog .field, .data-doc, .execution-resource-head, .execution-work-row { min-width: 0; }
  .data-doc { flex-wrap: wrap; }
  .data-doc .nm, .data-doc .st { min-width: 0; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  .execution-head h2 { min-width: 0; flex-basis: 100%; }
  .execution-resource-head .meta { min-width: 0; }
  #mem-add select { max-width: 100%; }
}

@media (max-width: 1000px) and (max-height: 450px) {
  body > header.chat-header { max-height: 25%; }
  #inputbar { max-height: 66%; }
  body.keyboard-open #inputbar { max-height: 70%; }
  #inputbar #ta { max-height: 60px; }
}

/* The same controls move to the mobile menu; handlers and IDs are preserved. */
.mobile-menu-body { display: grid; grid-template-columns: minmax(0, 1fr); align-items: stretch; gap: 8px; margin-bottom: 16px; }
.mobile-menu-body .spacer { display: none; }
.mobile-menu-body a { padding: 12px; }
.mobile-menu-body button[aria-label]::after { content: attr(aria-label); margin-left: 6px; }
.mobile-menu-body a.header-nav-icon[aria-label]::after { content: attr(aria-label); }
.mobile-menu-body :is(.header-nav-icon, button[aria-label]) {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px;
  width: 100%; height: auto; min-width: 0; min-height: 48px; padding: 10px 12px;
  max-width: 100%; white-space: normal; overflow-wrap: anywhere; text-align: left;
  border: 1px solid var(--border); border-radius: var(--r-md); text-decoration: none;
  font-size: var(--fs-base); line-height: 1.4;
}
.mobile-menu-body :is(button, a)[aria-label]::after { margin-left: 0; min-width: 0; }
.mobile-menu-body > :is(#model, #live-user):empty { display: none; }
.mobile-menu-body > :is(#model, #live-user) { padding: 4px 12px; }
.mobile-menu-body > :is(#meta-tools, #pwa-actions, #pwa-status, #attachment-help) { min-width: 0; max-width: 100%; }
.mobile-menu-body :is(#live-user, #model) { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
#pwa-status { color: var(--dim); font-size: var(--fs-small); padding: 6px 0; }
#pwa-actions { display: flex; flex-wrap: wrap; gap: 6px; }
#pwa-actions:has(button:not([hidden])) { margin: 6px 0; }
#inputbar #pwa-status { min-width: 0; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
#inputbar #pwa-actions button { min-width: 0; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px) {
  body > header.chat-header { flex-wrap: nowrap; }
  body > header.chat-header h1 { flex: 1 1 0; }
  #mobile-more { flex: 0 0 auto; }
  #pwa-actions button { min-height: 44px; }
}
/* Personal-memory controls remain readable in the mobile dialog. */
.mem-settings { display: grid; gap: 10px; margin: 12px 0; min-width: 0; }
.mem-settings label { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-width: 0; }
.mem-settings label:has(input[type="checkbox"]) { grid-template-columns: 20px minmax(0, 1fr); align-items: start; }
#mem-dlg .mem-settings input[type="checkbox"] { width: 18px; height: 18px; min-width: 18px; margin: 3px 0 0; padding: 0; }
.mem-settings :is(input[type="number"], select) { width: 100%; max-width: 100%; min-width: 0; }
#mem-dlg :is(.mem-cat, .mem-settings, .mem-fact, .mem-graph-row, .memory-decision) { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
#mem-dlg .mem-fact { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
#mem-dlg .mem-fact > :is(.c, .d, details, textarea, .mem-save) { grid-column: 1 / -1; min-width: 0; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
#mem-dlg .mem-fact > .c { line-height: 1.5; }
#mem-dlg .mem-fact > .d { font-size: var(--fs-small); color: var(--dim); }
#mem-dlg .memory-decision > * { grid-column: 1 / -1; min-width: 0; }
#mem-dlg .mem-fact > button { min-height: 44px; white-space: normal; justify-self: start; }
#mem-dlg .mem-fact > .x { visibility: visible; width: 44px; display: inline-flex; align-items: center; justify-content: center; justify-self: end; }
#mem-dlg .mem-fact > textarea { width: 100%; min-height: 96px; resize: vertical; font: inherit; color: var(--text); background: var(--panel2); padding: 8px; border: 1px solid var(--border); border-radius: var(--r-sm); }
#mem-dlg .mem-fact summary { min-height: 36px; padding: 6px 0; cursor: pointer; }
#mem-dlg .mem-settings button { min-height: 44px; white-space: normal; }
.mem-graph-row { padding: 10px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.mem-graph-row button, .mem-fact button { min-height: 36px; }
.mem-fact details { flex-basis: 100%; min-width: 0; overflow-wrap: anywhere; }
.tool-call summary, .agent-tool summary, .agent-job summary { overflow-wrap: anywhere; }
#chat-follow {
  position: absolute;
  z-index: 2;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  min-width: 44px; min-height: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
}
#chat-follow > span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--panel2);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
}
#chat-follow[hidden] { display: none; }
#attachment-help { display: none; }

/* Document actions keep their original handlers and use readable chip labels. */
#chat .document-actions { flex-basis: 100%; min-width: 0; margin: 2px 0; white-space: normal; }
#chat .document-actions:has(> .tools[hidden]), #chat .document-actions:has(> .gtools[hidden]) { display: none; }
#chat .document-actions > summary { min-height: 32px; padding: 6px 2px; font-size: var(--fs-small); line-height: 20px; color: var(--text); cursor: pointer; }
#chat .document-actions > summary:hover { color: var(--accent2); }
#chat .document-actions[open] > :is(.tools, .gtools) { margin: 2px 0 4px; }
#chat :is(.doc-file, .doc-card, .doc-group) :is(.tools, .gtools) { gap: 4px; white-space: normal; }
#chat button.document-chip {
  display: inline-flex; align-items: center; gap: 5px; min-height: 30px; height: auto;
  padding: 5px 9px; border-radius: 14px; font-size: var(--fs-small); line-height: 1.3;
  color: var(--text); background: var(--panel); border: 1px solid var(--border);
}
#chat button.document-chip:hover, #chat button.document-chip:focus-visible {
  border-color: var(--accent2); background: var(--hover-bg); outline: 2px solid var(--accent); outline-offset: 1px;
}
#chat button.document-chip:disabled { opacity: .55; cursor: not-allowed; }
.document-chip-icon { font-size: 16px; line-height: 1; }
.document-chip-help { flex-basis: 100%; color: var(--dim); white-space: normal; font-size: var(--fs-small); }
#chat .document-chip-help > summary { cursor: pointer; min-height: 28px; padding: 4px 0; }
.document-chip-help dl { padding: 6px 10px; background: var(--panel); border-left: 2px solid var(--accent); }
.document-chip-help dt { color: var(--text); font-weight: 600; margin-top: 6px; }
.document-chip-help dd { margin: 2px 0 8px; }
.document-chip-tooltip { position: fixed; z-index: 100; max-width: min(280px, calc(100vw - 16px)); padding: 8px 12px; border: 1px solid var(--accent2); border-radius: 8px; background: var(--panel2); color: var(--text); box-shadow: 0 3px 14px #0005; pointer-events: none; font-size: var(--fs-small); line-height: 1.5; overflow-wrap: anywhere; white-space: normal; }
.document-chip-tooltip[hidden] { display: none; }
@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px), (pointer: coarse) {
  #chat button.document-chip { min-height: 44px; }
  #chat .document-actions > summary { min-height: 44px; padding: 12px 2px; }
  #chat .document-chip-help > summary { min-height: 36px; padding: 8px 0; }
}

/* Compact process rows: preserve whitespace in content, not structural markup. */
#chat {
  --process-font-size: calc(var(--fs-base) * 0.8);
  --process-surface: linear-gradient(105deg,
    color-mix(in srgb, var(--text) 7%, transparent),
    color-mix(in srgb, var(--text) 2%, transparent));
}
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group, details.think) {
  font-size: var(--process-font-size);
}
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group, details.think) > summary,
#chat :is(.tool-result, .agent-tool-body),
#chat :is(.tool-call, .agent-tool) > summary .meta { font-size: var(--process-font-size); }
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group, details.think) {
  white-space: normal;
  margin-top: 0;
  margin-bottom: 0;
}
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group) {
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--process-surface);
  overflow: hidden;
}
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group) > summary {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: 28px;
  min-height: 28px;
  max-height: 28px;
  min-width: 0;
  padding: 3px 4px;
  line-height: 20px;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--r-sm);
  list-style: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#chat details.think > summary {
  min-height: 28px;
  padding: 4px 6px;
  line-height: 20px;
  box-sizing: border-box;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--r-sm);
  overflow-wrap: anywhere;
}
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group) > summary::-webkit-details-marker { display: none; }
#chat .tool-icon-chip {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  color: var(--dim);
  background: var(--panel);
  border: 0;
  border-radius: 3px;
}
#chat .tool-icon-chip > svg { width: 12px; height: 12px; }
#chat .tool-icon-fallback { font-size: 12px; line-height: 1; }
#chat :is(.tool-summary-label, .tool-group-label) { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chat .tool-disclosure-chip {
  box-sizing: border-box;
  display: none;
  align-items: center;
  justify-content: center;
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  color: var(--dim);
  background: var(--panel);
  border: 0;
  border-radius: 3px;
}
#chat .tool-disclosure-chip > span { display: block; font-size: 12px; line-height: 1; transition: transform 150ms ease; }
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group)[open] > summary .tool-disclosure-chip > span { transform: rotate(90deg); }
#chat :is(.tool-call, .agent-tool)[open] > summary .tool-icon-chip,
#chat :is(.tool-call, .agent-tool) > summary:focus-visible .tool-icon-chip {
  color: var(--accent2);
  background: var(--hover-bg);
}
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group, details.think) > summary:hover { background: var(--panel2); }
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group) > summary:hover .tool-disclosure-chip,
#chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group) > summary:focus-visible .tool-disclosure-chip {
  color: var(--accent2);
  background: var(--hover-bg);
}
#chat summary:focus-visible { outline: 2px solid var(--accent2); outline-offset: -2px; }
#chat details:not(.tool-call):not(.agent-tool):not(.tool-group):not(.agent-orphan-tools) > summary { list-style: none; }
#chat details:not(.tool-call):not(.agent-tool):not(.tool-group):not(.agent-orphan-tools) > summary::-webkit-details-marker { display: none; }
#chat details:not(.tool-call):not(.agent-tool):not(.tool-group):not(.agent-orphan-tools):not(.swallow-card) > summary::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  margin-right: 5px;
  vertical-align: -1px;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m9 5 7 7-7 7' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m9 5 7 7-7 7' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform 150ms ease;
}
#chat details:not(.tool-call):not(.agent-tool):not(.tool-group):not(.agent-orphan-tools)[open] > summary::before { transform: rotate(90deg); }
/* Status/time/action chips are themselves the disclosure control. */
#chat details:not(.tool-call):not(.agent-tool):not(.tool-group):not(.agent-orphan-tools) > summary.run-microchips::before { content: none; display: none; }
@media (prefers-reduced-motion: reduce) {
  #chat details:not(.tool-call):not(.agent-tool):not(.tool-group):not(.agent-orphan-tools) > summary::before,
  #chat .tool-disclosure-chip > span,
  #chat .timeline-entry-head::before { transition: none; }
}
#chat :is(.tool-pending, .tool-unresolved) {
  box-sizing: border-box;
  height: 28px;
  min-height: 28px;
  max-height: 28px;
  min-width: 0;
  padding: 3px 4px;
  color: var(--text);
  border: 0;
  background: var(--process-surface);
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  white-space: nowrap;
}
#chat .tool-pending .tp-dots { flex: 0 0 auto; }
#chat .tool-unresolved .meta {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#chat [data-executing="true"] {
  color: var(--executing);
  border-color: var(--executing);
}
#chat .linear-timeline {
  gap: 4px;
  margin: 4px 0;
  white-space: normal;
}
#chat .linear-timeline :is(.timeline-segment, .timeline-tools) { white-space: normal; }
#chat .linear-timeline .timeline-tools { gap: 4px; }
#chat .timeline-entry {
  min-width: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--process-surface);
  overflow: hidden;
}
#chat .timeline-entry-head {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 28px;
  padding: 4px 7px;
  display: block;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: var(--process-font-size);
  line-height: 20px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
#chat .timeline-entry-head::before { content: none; display: none; }
#chat :is(.run-cancel-details, .agent-cancel-details) > summary .run-microchip {
  background: var(--process-surface);
}
/* One surface per row, including expanded and grouped tool calls. */
#chat :is(.timeline-entry, .agent-orphan-tools, .tool-group)
  :is(.tool-call, .agent-tool, .tool-group, .tool-pending, .tool-unresolved, .timeline-tool-pending) {
  background: transparent;
}
#chat .timeline-entry-viewport { min-width: 0; padding: 0 7px 6px; }
#chat .timeline-entry-viewport[hidden] { display: none; }
#chat .timeline-entry-content { min-width: 0; overflow-wrap: anywhere; overflow-anchor: none; }
#chat .timeline-entry[data-disclosure="preview"] .timeline-entry-content {
  max-height: calc(5 * var(--timeline-preview-line-height, 20px));
  overflow: hidden;
}
#chat .timeline-entry[data-disclosure="preview"][data-preview-overflow="true"] .timeline-entry-content {
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 14px);
  mask-image: linear-gradient(to bottom, transparent, #000 14px);
}
#chat .timeline-entry[data-disclosure="full"] .timeline-entry-content { max-height: none; overflow: visible; }
#chat .timeline-entry[data-disclosure="full"] :is(.tool-result, .agent-tool-body, .tool-group-body) { max-height: none; overflow: visible; }
#chat .timeline-entry-content > details.think { margin: 0; padding: 0; background: transparent; }
#chat .timeline-entry-content > details.think > summary,
#chat .timeline-entry-content .reasoning-current { display: none; }
#chat .timeline-entry-content .reasoning-viewport { max-height: none !important; overflow: visible !important; mask-image: none !important; -webkit-mask-image: none !important; }
#chat [data-timeline-expand] {
  min-height: 28px;
  margin-top: 3px;
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: var(--accent2);
  font: inherit;
  font-size: var(--process-font-size);
  cursor: pointer;
}
#chat [data-timeline-expand][hidden] { display: none; }
#chat .timeline-entry-head:focus-visible,
#chat [data-timeline-expand]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#chat .timeline-tool-pending {
  box-sizing: border-box;
  height: 28px;
  min-height: 28px;
  max-height: 28px;
  min-width: 0;
  padding: 3px 4px;
  display: flex;
  align-items: center;
  color: var(--dim);
  border: 0;
  border-radius: var(--r-sm);
  background: var(--process-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#chat :is(.tool-result, .agent-tool-body, .tool-group-body) { box-sizing: border-box; max-height: min(45vh, 360px); overflow: auto; }
#chat :is(.tool-result, .agent-tool-body) { margin: 0 6px 6px; padding: 4px 8px; border-left: 0; }
#chat .tool-group-body { padding: 3px; }
#chat details.think {
  padding: 6px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--process-surface);
  color: var(--dim);
}
#chat details.think > summary { font-size: var(--process-font-size); }
#chat details.think > :not(summary) { white-space: pre-wrap; }
#chat details.think > .markdown-body { white-space: normal; }
#chat details.think.reasoning-compact > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
}
#chat details.think.reasoning-compact > summary::-webkit-details-marker { display: none; }
#chat details.think.reasoning-compact:not(.tool-call):not(.agent-tool):not(.tool-group):not(.agent-orphan-tools) > summary::before { display: none; }
#chat .reasoning-toggle { flex-shrink: 0; color: var(--dim); font-size: .95em; }
#chat .reasoning-viewport {
  line-height: 1.6;
  white-space: normal;
  overflow-wrap: anywhere;
  overflow-anchor: none;
}
#chat .reasoning-compact:not(.reasoning-expanded) > .reasoning-viewport {
  max-height: calc(5 * var(--reasoning-line-height, 17px));
  overflow: hidden;
}
#chat .reasoning-compact.reasoning-overflow:not(.reasoning-expanded) > .reasoning-viewport {
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 14px);
  mask-image: linear-gradient(to bottom, transparent, #000 14px);
}
#chat .reasoning-expanded > .reasoning-viewport { max-height: none; overflow: visible; }
#chat .reasoning-current {
  border: 0;
  background: transparent;
  color: var(--accent2);
  padding: 6px 0 0;
  font: inherit;
  cursor: pointer;
}
#chat .reasoning-current[hidden] { display: none; }
#chat .reasoning-compact > summary:focus-visible,
#chat .reasoning-current:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#chat { scroll-padding-bottom: 64px; }
#chat-viewport:has(#chat-follow:not([hidden])) #chat > :last-child { margin-bottom: 52px; }
@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px) {
  #chat-viewport:has(#chat-follow:not([hidden])) #chat > :last-child { margin-bottom: 30px; }
}
#filelist:empty, #pwa-actions:not(:has(button:not([hidden]))), #meta:not(:has(#meta-tools)):not(:has(#composer-tools)):has(#hint:empty) { display: none; }

@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px), (pointer: coarse) {
  #chat :is(details.think, .minion-card) > summary { min-height: 36px; padding: 8px 6px; }
}
@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px) {
  #chat .src-chips:not(details), #chat .src-chip-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px) {
  .header-description { display: none; }
  #inputbar #drop { display: none; }
  #inputbar .wrap { gap: 4px; }
  #inputbar #send { margin-left: auto; }
  #inputbar .micro-btn { color: var(--text); }
  #inputbar #ta::placeholder { color: var(--dim); opacity: 1; }
  #filelist { margin-bottom: 0; }
  #mobile-controls :is(#meta-tools, #pwa-actions) { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; }
  #mobile-controls #pwa-actions:not(:has(button:not([hidden]))) { display: none; }
  #mobile-controls #attachment-help { display: block; color: var(--text); font-size: var(--fs-small); line-height: 1.5; }
  #mobile-controls #pwa-status[hidden], #mobile-controls #pwa-actions button[hidden] { display: none; }
  #mem-add { display: grid; grid-template-columns: minmax(0, 1fr); }
  #mem-add :is(input, select, button) { width: 100%; min-width: 0; min-height: 44px; }
  #mem-dlg :is(input:not([type="checkbox"]), textarea, select) { font-size: 16px; }
}

/* Metadata-scale icon controls override the general touch target rules. */
body #chat button.message-copy-chip,
body #chat button.delegation-refresh-chip,
body #delegations-panel button.delegation-refresh-chip {
  box-sizing: border-box;
  flex: 0 0 20px;
  width: 20px;
  min-width: 20px;
  max-width: 20px;
  height: 20px;
  min-height: 20px;
  max-height: 20px;
  padding: 0;
  touch-action: manipulation;
}
body #chat button.notification-open-chat,
body #chat button.document-open-chip,
body #execution-dlg button.execution-open-chat {
  box-sizing: border-box;
  flex: 0 0 1em;
  width: 1em;
  min-width: 1em;
  max-width: 1em;
  height: 1em;
  min-height: 1em;
  max-height: 1em;
  padding: 0;
  border: 0;
  background: none;
  touch-action: manipulation;
}
body #chat button.src-chip {
  min-width: 0;
  height: 20px;
  min-height: 20px;
  max-height: 20px;
  padding-block: 0;
}
body #chat .src-chip-cell > button.src-chip:not(:first-child) {
  flex-basis: 20px;
  width: 20px;
  min-width: 20px;
  max-width: 20px;
}
body #chat details.src-chips > summary {
  height: 20px;
  min-height: 20px;
  max-height: 20px;
  padding-block: 0;
}

/* Compact account disclosure, shared by desktop and mobile. */
body > header.chat-header { flex-wrap: nowrap; justify-content: space-between; overflow: visible; padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right, 0px)) 0 max(8px, env(safe-area-inset-left, 0px)); background: transparent; border: 0; box-shadow: none; }
#user-menu { position: relative; min-width: 0; max-width: calc(100% - 52px); margin-left: auto; }
#user-menu-toggle { display: flex; align-items: center; justify-content: center; width: 44px; min-height: 44px; padding: 0; }
#user-menu-toggle .user-menu-avatar { flex: 0 0 18px; }
#user-menu-toggle #live-user { display: none; }
#user-menu-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 100; width: min(340px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))); max-height: max(0px, calc(var(--app-height, 100dvh) - 60px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px))); overflow: auto; overscroll-behavior: contain; padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); box-shadow: 0 12px 32px #0004; }
#user-menu-panel[hidden], #user-menu-panel [hidden] { display: none; }
.user-menu-info { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.user-menu-info h1 { font-size: 14px; margin: 0; }
.user-menu-info #model { overflow-wrap: anywhere; min-width: 0; }
.user-menu-actions { display: grid; gap: 2px; }
.user-menu-actions + .user-menu-actions { margin-top: 6px; border-top: 1px solid var(--border); }
.user-menu-actions > h2 { margin: 0; padding: 10px 10px 3px; font-size: var(--fs-meta); font-weight: 600; color: var(--dim); }
.user-menu-actions > :is(button, a) { display: flex; align-items: center; justify-content: flex-start; gap: 12px; width: 100%; height: auto; min-height: 44px; padding: 10px; text-align: left; white-space: normal; text-decoration: none; color: var(--text); border: 0; background: transparent; box-shadow: none; }
.user-menu-actions > :is(button, a)[aria-label]::after { content: attr(aria-label); }
.user-menu-actions > :is(#announcements-open, #mobile-more)::after { content: none; }
.user-menu-actions > .danger { color: var(--danger, #e66); }
.user-menu-actions svg { flex-shrink: 0; }
#user-menu-toggle:focus-visible, .user-menu-actions > :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.user-menu-actions > :is(button, a):hover { background: var(--panel2); }

/* Only the two persistent header controls: keep generous hit targets. */
body > header.chat-header :is(#chats-toggle, #user-menu-toggle) { width: 44px; height: 44px; min-width: 44px; min-height: 44px; border: 0; background: transparent; box-shadow: none; }
body > header.chat-header :is(#chats-toggle, #user-menu-toggle):hover { background: var(--panel2); }
body > header.chat-header :is(#chats-toggle, #user-menu-toggle):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* List rows must scroll, not shrink below their touch controls and preview. */
#chat-list > * { flex-shrink: 0; }
@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px), (pointer: coarse) {
  #chat-list .chat-item .row1 { align-items: center; min-height: 44px; }
  #chats-col #chat-list .chat-row-actions > .del { min-width: 26px; width: 26px; min-height: 44px; }
  #chat-list .chat-item .del { visibility: visible; }
}
@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px) {
  #chats-col > .mobile-panel-toolbar { justify-content: flex-end; }
  body > header.chat-header { max-height: none; }
}

/* Match the existing left inset of timeline tool calls on both sides. */
#chat .agent-tool { margin-inline: 21px; }
/* PWA and reminder controls remain in the account menu on every viewport. */
#user-menu-panel #pwa-actions { display: flex; flex-direction: column; gap: 2px; margin: 0; }
#user-menu-panel #pwa-actions button { width: 100%; min-height: 44px; padding: 10px; text-align: left; white-space: normal; overflow-wrap: anywhere; border: 0; background: transparent; box-shadow: none; }
#user-menu-panel #pwa-actions button:hover { background: var(--panel2); }
#user-menu-panel #pwa-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#user-menu-panel #pwa-status { padding: 8px 10px; white-space: normal; overflow-wrap: anywhere; }

#chat .next-step-row { box-sizing: border-box; width: 100%; min-width: 0; padding: 4px 7px; border-radius: var(--r-sm); color: var(--dim); font-size: var(--process-font-size); line-height: 20px; }

/* The delegated job shares the same collapsed row as the surrounding timeline. */
#chat .swallow-card {
  width: 100%;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: var(--process-surface);
  font-size: var(--process-font-size);
}
#chat .swallow-card > summary {
  box-sizing: border-box;
  align-items: center;
  min-height: 28px;
  padding: 4px 7px;
  line-height: 20px;
  color: var(--dim);
}
#chat .swallow-card:not([open]) > summary { white-space: nowrap; }
#chat .swallow-card .swallow-title { flex: 1 1 auto; }
#chat .swallow-card .swallow-progress {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: inherit;
}
#chat .swallow-card[open] .swallow-progress { overflow-wrap: anywhere; }
#chat details.swallow-card > summary::before { display: none; }
#chat .swallow-body { padding: 4px 7px 6px; font-size: var(--fs-small); }
/* Keep closed activity rows compact; expanded content keeps its own spacing. */
@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px) {
  #chat details.think:not([open]) { padding-block: 0; }
  #chat .timeline-entry-head[aria-expanded="false"],
  #chat :is(details.think, .tool-call, .agent-tool, .agent-orphan-tools, .tool-group, .minion-card, .swallow-card):not([open]) > summary,
  #chat :is(.tool-pending, .tool-unresolved, .timeline-tool-pending),
  #chat .next-step-row {
    box-sizing: border-box;
    height: auto;
    min-height: 19px;
    max-height: none;
    padding-block: 1px;
    line-height: 1.35;
  }
  #chat :is(.tool-call, .agent-tool, .agent-orphan-tools, .tool-group):not([open]) > summary .tool-icon-chip {
    width: 16px;
    height: 16px;
    flex-basis: 16px;
  }
}

/* Apply the same surface to the visible row carrying each live status. */
#chat :is(.timeline-entry:has(> .timeline-entry-head[data-process-active]), details[data-process-active] > summary,
          .tool-pending[data-executing="true"] > summary, summary[data-executing="true"],
          .delegation-card-summary:has(> [data-executing="true"]),
          .delegation-minion > summary:has(> [data-executing="true"]),
          .agent-orphan-tools:has(.agent-tool[data-process-active]) > summary, .minion-card[data-status="awaiting"] > summary,
          .stream-technical > summary, .minion-reading-progress, [data-agent-model-activity],
          .agent-step-title:has(.agent-step-state.in_progress),
          .task-context-progress:is([data-stage="running"], [data-stage="paging"]),
          .pipeline-state[data-state="running"], [data-process-state="running"],
          .doc-file:has(.pipeline-state[data-state="running"], [data-process-state="running"]) > summary) {
  background-color: color-mix(in srgb, var(--accent) 9%, transparent);
  background-image: var(--process-reflection, none);
  background-size: 160% 100%;
  background-repeat: repeat-x;
  animation: var(--process-motion, none);
}
@media (prefers-reduced-motion: no-preference) {
  #chat {
    --process-reflection: linear-gradient(110deg, transparent 18%,
      color-mix(in srgb, var(--accent) 16%, transparent) 34%,
      color-mix(in srgb, var(--accent) 38%, transparent) 46%,
      color-mix(in srgb, var(--text) 22%, transparent) 51%, transparent 76%);
    --process-motion: process-row-shimmer 2.2s linear infinite;
  }
}
@keyframes process-row-shimmer {
  from { background-position: 0% 0; }
  to { background-position: -266.6667% 0; }
}

/* Sidebar buttons only; chat selection and search input keep their borders. */
#chats-col button { border: 0; background: transparent; box-shadow: none; }
#chats-col button:hover:not(:disabled) { background: var(--panel2); }
#chats-col button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
