/* Chat screen: top bar, conversation, bottom pill composer. */

.chat {
  background: var(--c-canvas);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
  min-height: calc(var(--phone-topbar) + var(--safe-top));
  padding: var(--safe-top) var(--space-2) 0;
  background: var(--c-canvas);
}

.tb-center {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.tb-title {
  margin: 0;
  overflow: hidden;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tb-sub {
  margin: 1px 0 0;
  overflow: hidden;
  color: var(--c-ink-muted);
  font-size: var(--text-2xs);
  line-height: var(--leading-tight);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tb-right {
  display: flex;
  justify-content: flex-end;
  min-width: var(--touch);
}

.badge-count {
  position: absolute;
  top: 6px;
  right: 4px;
  display: grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border: 2px solid var(--c-canvas);
  border-radius: var(--radius-pill);
  background: var(--c-inverse);
  color: var(--c-inverse-ink);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  line-height: 1;
}

.icon-btn[data-waiting="true"] .badge-count {
  background: var(--c-attention);
  color: var(--c-attention-ink);
}

.conn-banner {
  flex: none;
  margin: 0 var(--phone-gutter) var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--c-surface-sunken);
  color: var(--c-ink-soft);
  font-size: var(--text-xs);
  text-align: center;
  animation: fade var(--dur-base) var(--ease-out);
}

.conn-banner.rc {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  border-radius: var(--radius-lg);
  text-align: left;
  padding: var(--space-3) var(--space-4);
}
.conn-banner.rc[hidden] {
  display: none;
}
.rc-title {
  color: var(--c-ink);
  font-size: var(--text-sm);
  font-weight: 600;
}
.rc-meta {
  margin-top: 2px;
  color: var(--c-ink-soft);
  font-variant-numeric: tabular-nums;
}
.rc-part {
  white-space: nowrap;
}
.rc-route {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rc-hint {
  grid-column: 1 / -1;
  color: var(--c-ink-faint);
}
.rc-hint:empty {
  display: none;
}
.rc-retry {
  min-height: 36px;
  padding: 0 var(--space-4);
  border: 1px solid var(--c-line-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--c-ink);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 600;
}
.rc-retry[hidden] {
  display: none;
}
.conn-banner[data-state="flash"] .rc-title,
.conn-banner[data-state="revoked"] .rc-title {
  color: inherit;
}
.conn-banner[data-tone="error"],
.conn-banner[data-state="revoked"] {
  background: var(--c-danger-soft);
  color: var(--c-danger);
}

/* ── Conversation ───────────────────────────────────────────── */
.scroller {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-padding-bottom: var(--space-6);
}

.thread {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-3) var(--phone-gutter) var(--space-6);
}

.item[data-enter="true"] {
  animation: rise var(--dur-slow) var(--ease-out);
}

.item.user {
  display: flex;
  justify-content: flex-end;
  padding-left: 15%;
}

.bubble {
  max-width: 100%;
  padding: var(--space-2) var(--space-4);
  border-radius: 22px 22px 6px 22px;
  background: var(--c-user-bubble);
  font-size: var(--text-md);
  line-height: var(--leading-ui);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.item.assistant {
  font-size: var(--text-md);
  line-height: var(--leading-body);
  overflow-wrap: anywhere;
}

.item.assistant p,
.ws-text p {
  margin: 0 0 var(--space-3);
}

.item.assistant > :last-child,
.ws-text > :last-child {
  margin-bottom: 0;
}

.item.assistant ul,
.item.assistant ol {
  margin: 0 0 var(--space-3);
  padding-left: 1.3em;
}

.item.assistant pre {
  margin: 0 0 var(--space-3);
  padding: var(--space-3);
  overflow-x: auto;
  border-radius: var(--radius-sm);
  background: var(--c-surface-sunken);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
}

.item.assistant[data-streaming="true"] > :last-child::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--c-ink);
  vertical-align: 1px;
  animation: pulse 1s var(--ease-in-out) infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

.item.tool {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  margin: calc(var(--space-2) * -1) 0;
  color: var(--c-ink-muted);
  font-size: var(--text-xs);
}

.tool-dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-ink-faint);
}

[data-state="running"] > .tool-dot {
  animation: pulse 1s var(--ease-in-out) infinite;
}

[data-state="fail"] > .tool-dot {
  background: var(--c-danger);
}

.tool-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.item.report {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}

.report-dot {
  flex: none;
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--c-ink-muted);
}

.item.report[data-status="needs_review"] .report-dot {
  background: var(--c-attention);
}

.report-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.report-body b {
  font-weight: var(--weight-semibold);
}

.report-body span {
  color: var(--c-ink-muted);
  overflow-wrap: anywhere;
}

.report-open {
  flex: none;
  align-self: center;
  min-height: var(--touch);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--c-ink);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.thinking {
  display: flex;
  gap: 5px;
  padding: var(--space-2) 0;
}

.thinking i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c-ink-muted);
  animation: pulse 1.2s var(--ease-in-out) infinite;
}

.thinking i:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking i:nth-child(3) {
  animation-delay: 0.3s;
}

/* ── Empty state ────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 100%;
  padding: var(--space-8) var(--phone-gutter) var(--space-4);
}

.empty .wordmark {
  margin-bottom: var(--space-3);
}

.empty-sub {
  margin: 0 0 var(--space-8);
  word-break: keep-all;
  overflow-wrap: anywhere;
  max-width: 26em;
  color: var(--c-ink-muted);
  font-size: var(--text-md);
  line-height: var(--leading-body);
}

.suggestions {
  display: flex;
  gap: var(--space-2);
  margin: 0 calc(var(--phone-gutter) * -1);
  padding: 0 var(--phone-gutter) var(--space-1);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  /* Snap to the gutter, not the screen edge: the first card lines up with the text above. */
  scroll-padding-inline: var(--phone-gutter);
  scrollbar-width: none;
}

.suggestions::-webkit-scrollbar {
  display: none;
}

.suggestion {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 2px;
  width: 46%;
  min-height: 72px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--c-line-strong);
  border-radius: var(--radius-lg);
  background: var(--c-surface-raised);
  text-align: left;
  scroll-snap-align: start;
  transition: transform var(--dur-fast) var(--ease-out);
}

.suggestion:active {
  transform: scale(0.97);
}

.sg-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.sg-hint {
  color: var(--c-ink-muted);
  font-size: var(--text-xs);
}

/* ── Dock: waiting pill + composer ──────────────────────────── */
.dock {
  position: relative;
  flex: none;
  padding: var(--space-2) var(--space-3) calc(var(--space-2) + max(var(--safe-bottom), var(--space-2)));
  margin-bottom: var(--kb, 0px);
  background: linear-gradient(to bottom, transparent, var(--c-canvas) 18px);
  transition: margin-bottom var(--dur-fast) var(--ease-out);
}

.wait-pill {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch);
  margin: 0 auto var(--space-2);
  padding: 0 var(--space-3) 0 var(--space-4);
  border: 1px solid var(--c-attention);
  border-radius: var(--radius-pill);
  background: var(--c-attention-soft);
  color: var(--c-attention);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  animation: rise var(--dur-slow) var(--ease-spring);
}

.wait-pill .dot {
  background: var(--c-attention);
  animation: pulse 1.4s var(--ease-in-out) infinite;
}

.wait-pill[data-tone="danger"] {
  border-color: var(--c-danger-line);
  background: var(--c-danger-soft);
  color: var(--c-danger);
}

.wait-pill[data-tone="danger"] .dot {
  background: var(--c-danger);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  min-height: 56px;
  padding: 6px 6px 6px var(--space-5);
  border: 1px solid var(--c-line-strong);
  border-radius: 28px;
  background: var(--c-composer);
  box-shadow: var(--shadow-composer);
  transition: border-color var(--dur-base) var(--ease-out);
}

.composer:focus-within {
  border-color: var(--c-focus);
}

.composer-input {
  flex: 1;
  min-width: 0;
  max-height: 132px;
  margin: 0;
  padding: 10px 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: var(--text-md);
  line-height: 1.5;
  resize: none;
}

.composer-input::placeholder {
  color: var(--c-ink-faint);
}

.send-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--touch);
  height: var(--touch);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--c-inverse);
  color: var(--c-inverse-ink);
  transition:
    transform var(--dur-fast) var(--ease-out),
    opacity var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out);
}

.send-btn:disabled {
  background: var(--c-active);
  color: var(--c-ink-faint);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.9);
}

.send-btn[data-mode="stop"] .icon {
  fill: currentColor;
}
