/* Chat uses the shared app shell and toolbar; only the conversation is distinct. */
.chat-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  flex: 1;
  background: var(--paper);
}
.chat-toolbar {
  position: sticky;
  top: 0;
  z-index: 3;
  background: transparent;
  pointer-events: none;
  min-height: 52px;
  padding: 8px 24px;
  border: 0;
  gap: 12px;
}
.chat-identity {
  flex: 1;
  min-width: 0;
}
.chat-notifications[aria-pressed="true"] {
  color: var(--accent);
}
.chat-identity h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}
.chat-provider {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.846154rem;
  white-space: nowrap;
}
.chat-provider[hidden] { display: none; }
.chatgpt-mark {
  display: block;
  width: 15px;
  height: 15px;
  flex: none;
}
.chat-connection {
  font-size: 0.846154rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-connection:before {
  content: "";
  width: 5px;
  height: 5px;
  background: var(--faint);
  border-radius: 50%;
}
.chat-connection.online:before {
  background: var(--success);
}
.chat-activities {
  display: grid;
  gap: 6px;
  align-self: flex-start;
  max-width: min(92%, 820px);
  margin: 2px 0 3px;
}
.chat-activity {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.923077rem;
  line-height: 1.45;
}
.chat-activity-failed { color: var(--danger); }
.chat-earlier-activity { color: var(--muted); font-size: .929rem; }
.chat-earlier-activity > summary { cursor: pointer; padding-block: 8px; }
.chat-activity-indicator {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  animation: chat-activity-pulse 1.25s ease-in-out infinite;
}
@keyframes chat-activity-pulse {
  50% { opacity: .35; transform: scale(.78); }
}
.chat-transcript {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.chat-messages {
  flex: 1 0 auto;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 24px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.chat-day {
  text-align: center;
  color: var(--muted);
  font-size: 0.846154rem;
  padding: 6px 0 2px;
}
.chat-history-note {
  text-align: center;
  font-size: 0.846154rem;
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}
.chat-message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 92%;
  min-width: 0;
}
.chat-message.from-user {
  flex-direction: row;
  gap: 8px;
  align-self: flex-end;
  align-items: center;
  justify-content: flex-end;
  max-width: 82%;
}
.chat-message-source {
  display: inline-flex;
  color: var(--muted);
  margin: 0;
  flex: none;
}
.chat-message.from-user:has(.chat-receipt) { flex-wrap: wrap; }
.chat-message.from-user .chat-receipt { flex-basis: 100%; text-align: right; }
.chat-goal-link {
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.846154rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.chat-goal-link:hover {
  color: var(--ink);
  text-decoration: underline;
}
.chat-bubble {
  max-width: 100%;
  overflow-wrap: anywhere;
}
.from-user .chat-bubble {
  background: var(--selected);
  color: var(--ink);
  border-radius: 18px;
  padding: 10px 14px;
}
.chat-bubble .markdown-body,
.chat-user-text {
  font-size: var(--reading-font-size);
  line-height: var(--reading-line-height);
}
.chat-bubble .markdown-body { color: var(--ink); }
.chat-bubble .markdown-body > :last-child {
  margin-bottom: 0;
}
.chat-bubble .markdown-body h1 { font-size: 1.846154rem; }
.chat-bubble .markdown-body h2 {
  font-size: 1.538462rem;
  margin-top: 16px;
}
.chat-bubble .markdown-body h3 { font-size: 1.384615rem; }
.chat-bubble .markdown-body h4 { font-size: var(--reading-font-size); }
.chat-content { display: grid; gap: 14px; min-width: 0; }
.chat-content > .markdown-body > :first-child { margin-top: 0; }
.chat-image { margin: 0; position: relative; max-width: 560px; }
.chat-image-open { display: block; width: 100%; padding: 0; border: 0; background: transparent; overflow: hidden; border-radius: var(--shape-lg); cursor: zoom-in; }
.chat-image-open img { display: block; width: 100%; max-height: 420px; object-fit: contain; }
.chat-image-status, .chat-content-unavailable { color: var(--muted); font-size: 0.923077rem; }
.chat-image-status { display: block; padding: 10px 0; }
.chat-image [hidden] { display: none; }
.chat-file { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--shape-md); color: var(--ink); text-decoration: none; width: fit-content; max-width: 100%; }
.chat-file:hover { background: var(--hover); }
.chat-file .ui-icon { flex: none; width: 18px; height: 18px; }
.chat-citation { color: var(--muted); font-size: 0.923077rem; text-underline-offset: 3px; width: fit-content; }
.chat-citation:hover { color: var(--ink); }
.chat-image-viewer { width: min(960px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 48px 12px 12px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--shape-lg); }
.chat-image-viewer::backdrop { background: #000b; }
.chat-image-viewer > img { display: block; max-width: 100%; max-height: calc(100dvh - 110px); margin: auto; object-fit: contain; }
.chat-image-close { position: absolute; right: 6px; top: 6px; min-width: 36px; min-height: 36px; }
@media (max-width: 650px), (pointer: coarse) {
  .chat-image-close { min-width: 44px; min-height: 44px; }
  .chat-image-viewer { padding-top: 56px; }
}
.chat-user-text {
  white-space: pre-wrap;
  margin: 0;
}
.chat-receipt {
  font-size: 0.769231rem;
  color: var(--muted);
  margin: 3px 3px 0;
}
/* Queued messages share a card tucked behind the top of the input. */
.chat-queue {
  pointer-events: auto;
  position: relative;
  margin: 0 18px -22px;
  padding: 4px 6px 26px;
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  background: var(--paper);
}
.chat-compose-row { position: relative; z-index: 1; }
.chat-queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.chat-queue-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 4px 0 12px;
}
.chat-queue-text {
  flex: 1;
  min-width: 0;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 650px) {
  .chat-queue { margin-inline: 10px; }
}
/* The WebGL swarm draws over these slots; ink matches the iOS loader. */
.quine-swarm-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  color: rgb(46, 64, 92);
}
:root[data-theme="dark"] .quine-swarm-canvas { color: rgb(199, 219, 255); }
.chat-swarm { flex: none; }
.chat-swarm-empty {
  width: 192px;
  height: 168px;
  margin: auto;
}
/* 64×56 like iOS; the drawn field is inset about 7px from its box. */
.chat-swarm-loader {
  width: 64px;
  height: 56px;
  margin: -10px 0 -10px -7px;
}
.chat-replying {
  font-size: 0.923077rem;
  color: var(--muted);
  padding: 4px 0;
}
.chat-composer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  pointer-events: none;
  border: 0;
  padding: 12px max(20px, calc((100% - 772px) / 2)) 20px;
  background: transparent;
  flex: none;
}
.chat-compose-row {
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--glass-refract-fill, var(--field));
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.chat-compose-row:focus-within {
  border-color: var(--line-strong);
  box-shadow: var(--glass-refract-rim, 0 0 #0000), 0 0 0 3px color-mix(in srgb, var(--focus) 8%, transparent);
}
.chat-input {
  font-size: var(--reading-font-size);
  line-height: 1.5;
  min-height: 44px;
  min-width: 0;
  max-height: 140px;
  padding: 11.5px 12px; /* 21px line + 23px padding = 44px, matching .chat-send */
  resize: none;
  border-radius: 22px;
  border: 0;
  outline: 0;
  background: transparent;
  box-shadow: none;
  flex: 1;
}
.chat-input:focus {
  background: transparent;
}
.chat-send {
  width: 44px;
  height: 44px;
  min-height: 44px;
  border-radius: 50%;
  font-size: 1.538462rem;
  line-height: 1;
  padding: 0;
  margin: 0;
  flex: none;
}

.chat-send .ui-icon { width: 20px; height: 20px; }
.chat-status {
  font-size: 0.846154rem;
  line-height: 1.5;
  color: var(--muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.chat-status:not(:empty) {
  pointer-events: auto;
  width: fit-content;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--paper);
  margin: 0 8px 8px;
}
.chat-status button {
  font-size: 0.846154rem;
}
.chat-delivery-check {
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 4px;
  flex: none;
}
.chat-delivery-check .ui-icon {
  width: 14px;
  height: 14px;
}
.chat-failure-resend {
  min-height: 26px;
  padding: 2px 9px;
}
@media (max-width: 650px) {
  .chat-toolbar {
    min-height: 44px;
    padding: 6px 12px;
  }
  .chat-messages {
    padding: 20px 16px;
    gap: 22px;
  }
  .chat-message {
    max-width: 95%;
  }
  .chat-message.from-user {
    max-width: 94%;
  }
  .chat-composer {
    padding: 8px 16px 12px;
  }
  .chat-connection {
    font-size: 0.769231rem;
  }
  .chat-provider { font-size: 0.769231rem; }
  .chat-provider .chatgpt-mark { width: 14px; height: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-activity-indicator { animation: none !important; }
}

.chat-menu { margin-left: auto; pointer-events: auto; }
.chat-menu > summary { background: var(--paper); border-radius: 999px; }
.chat-menu .chat-provider { font-size: 0.923077rem; }
.chat-menu summary .chat-connection.online { font-size: 0; gap: 0; }
.chat-menu summary .chat-connection.online::before { width: 5px; height: 5px; }
@media (max-width: 650px) {
  .chat-menu { position: relative; top: auto; right: auto; z-index: 10; }
  .shell:has(.chat-panel) .workspace-name { display: none; }
}

.chat-message-links { display: flex; align-items: center; gap: 6px; min-width: 0; }

.chat-view-switch{display:flex;gap:2px;pointer-events:auto;flex:none}
.chat-view-switch button[aria-pressed="true"]{background:var(--selected);color:var(--ink)}
.chat-canvas[hidden]{display:none}
.chat-canvas{min-height:0;min-width:0;flex:1;overflow:auto;padding:0 24px 16px;overscroll-behavior:contain}
.chat-canvas-mode .chat-transcript{overflow:hidden}
.chat-canvas-mode .chat-toolbar{flex:none}
.chat-canvas-mode .chat-messages{flex:0 1 auto;max-height:24vh;overflow:auto;gap:2px;padding-top:8px;padding-bottom:4px}
.chat-canvas-mode .chat-messages>.empty{padding:8px}
@media(max-width:650px){.chat-canvas{padding-inline:12px}.chat-view-switch{gap:0}.chat-view-switch button{padding-inline:8px}}

.chat-canvas-excerpt{display:flex;flex-direction:column;align-items:flex-start;max-width:100%;width:100%;min-height:36px!important;padding:6px 10px!important;border:0!important;box-shadow:none!important;background:transparent!important;text-align:left!important;line-height:1.5}
.chat-canvas-excerpt>span:first-child{display:block;max-width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.chat-canvas-excerpt.from-user{align-self:flex-end;width:auto;max-width:85%;background:var(--surface-raised)!important;border-radius:var(--shape-lg)}
.chat-canvas-excerpt:hover{background:var(--surface)!important}
.chat-canvas-excerpt:focus-visible{outline:1px solid var(--focus);outline-offset:-1px}

/* Pulse default: shares the connected-chat menu and saved account order. */
.chat-menu > summary { border-radius: var(--shape-md); min-height: 44px; }
.chat-connection:has(.chat-default-name)::before { display:none; }
.chat-default-name { display:block; max-width: 240px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-menu .chat-connection:not(.online) { display:grid; gap:2px; font-size: 12px; }
.chat-default-environment { display:flex; align-items:center; gap:5px; color:var(--muted); font-size:11px; }
.chat-default-environment svg,.chat-default-account svg { width:13px; height:13px; flex:none; }
.chat-menu .chat-default-panel { width:340px; max-width:calc(100vw - 32px); padding:8px; }
.chat-default-title { padding:6px 8px 10px; font-weight:500; }
.chat-default-choices { display:grid; gap:3px; max-height:360px; overflow-y:auto; }
.chat-default-panel .chat-default-choice { display:flex; align-items:center; gap:11px; padding:10px; min-height:58px; width:100%; text-align:left; white-space:normal; }
.chat-default-choice[aria-checked=true] { background:var(--selected); }
.chat-default-choice > svg { width:18px; height:18px; flex:none; }
.chat-default-copy { display:grid; gap:3px; flex:1; min-width:0; }
.chat-default-choice-title { display:flex; align-items:center; gap:9px; flex-wrap:wrap; }
.chat-default-account { display:inline-flex; align-items:center; gap:4px; font-size:12px; color:var(--muted); overflow-wrap:anywhere; }
.chat-default-unavailable { margin-left:auto; font-size:11px; }
.chat-default-current { border-bottom:1px solid var(--line); margin-bottom:6px; padding:6px 8px 10px; font-size:12px; color:var(--muted); }
.chat-default-current > div { display:flex; align-items:center; gap:7px; }
.chat-default-current svg { width:15px; height:15px; flex:none; }
.chat-default-scope,.chat-default-empty { padding:6px 8px; font-size:12px; color:var(--muted); margin:0; }
.chat-default-tools { display:flex; justify-content:flex-end; border-top:1px solid var(--line); margin-top:5px; padding-top:5px; }
.chat-default-panel .chat-default-tools > button { width:36px; height:36px; min-height:36px; padding:8px; }
.chat-default-tools > button > span { display:none; }
.chat-default-tools > button > svg { margin:0; }
.chat-view-switch button { width:36px; height:36px; padding:8px; }
@media(max-width:650px) { .chat-default-name { max-width:180px; } .chat-default-panel .chat-default-tools > button { width:44px; height:44px; } }

.chat-activity-with-swarm { display: flex; align-items: center; gap: 8px; }

/* One work summary and compact delegated-agent rows, shared with Storybook. */
.chat-work { width: 100%; max-width: 820px; container-type: inline-size; font-size: 1rem; margin: 2px 0; }
.chat-work-header { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.chat-work-header > :first-child { flex-shrink: 1; min-width: 0; white-space: normal; text-align: left; }
.chat-work-children { margin-left: 18px; padding-left: 10px; border-left: 1px solid var(--line); }
.chat-work-child summary { display: flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; list-style: none; }
.chat-work-child summary::-webkit-details-marker { display: none; }
.chat-work-child summary:hover { background: var(--hover); }
.chat-work-child summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.chat-work-mark { flex: none; width: 16px; height: 16px; }
.chat-work-child[data-status="result_ready"] .chat-work-mark { color: var(--success); }
.chat-work-child:is([data-status="waiting"],[data-status="stalled"],[data-status="unconfirmed"]) .chat-work-mark { color: var(--warning); }
.chat-work-child:is([data-status="failed"],[data-status="needs_attention"]) .chat-work-mark { color: var(--danger); }
.chat-work-agent { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.chat-work-task, .chat-work-action, .chat-work-age { font-weight: 400; color: var(--muted); }
.chat-work-action { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-work-child:is([data-status="waiting"],[data-status="failed"],[data-status="needs_attention"],[data-status="stalled"],[data-status="unconfirmed"]) .chat-work-action { white-space: normal; overflow: visible; overflow-wrap: anywhere; }
.chat-work-age { flex: none; font-size: .857rem; font-variant-numeric: tabular-nums; }
.chat-work-chevron { flex: none; width: 12px; height: 12px; color: var(--muted); }
.chat-work-child[open] .chat-work-chevron { transform: rotate(90deg); }
.chat-work-detail { padding: 2px 20px 10px 24px; font-size: .929rem; line-height: 1.5; overflow-wrap: anywhere; }
.chat-work-detail strong { font-weight: 500; }
.chat-work-detail p { margin: 4px 0 0; color: var(--muted); white-space: pre-wrap; }
.chat-work-history { font-size: .929rem; color: var(--muted); margin: 8px 0 0 18px; padding-left: 20px; line-height: 1.7; overflow-wrap: anywhere; }
.chat-work-incomplete { color: var(--warning); font-size: .929rem; margin: 4px 0; }
.chat-activity-with-swarm { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-activity-with-swarm .chat-activity-label { color: var(--muted); font-size: .929rem; }
@container (max-width: 460px) {
  .chat-work-child summary { flex-wrap: wrap; gap: 3px 7px; padding: 6px 0; }
  .chat-work-agent { flex: 1; max-width: none; }
  .chat-work-action { order: 1; flex-basis: calc(100% - 24px); margin-left: 23px; }
}
@media (pointer: coarse) { .chat-work-child summary { min-height: 44px; } }
