.chat-view {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  height: clamp(470px, calc(100dvh - 137px), 870px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, #1a2b44 0%, #132033 100%);
  box-shadow: var(--shadow);
}

.content-research .topbar h1 {
  font: 650 1.17rem/1.2 Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  letter-spacing: -.02em;
}

.chat-refresh.button {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border-color: transparent;
  background: linear-gradient(180deg, #4784f2, #1d4ed8);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset, 0 6px 16px -8px rgba(37,99,235,.65);
}
.chat-refresh.button:hover {
  background: linear-gradient(180deg, #6ea4ff, #2563eb);
  color: #fff;
  border-color: transparent;
}

.chat-thread {
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scroll-padding: 15px;
}

.chat-thread:focus-visible { outline-offset: -4px; }

.chat-empty,
.chat-log {
  width: min(100%, 800px);
  margin-inline: auto;
  padding: 20px clamp(14px, 3vw, 31px);
}

.chat-empty,
.chat-log:not(:empty) {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
}

.chat-empty { gap: 14px; }
.chat-log:not(:empty) { gap: 20px; }
.chat-log:empty { padding: 0; }

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chat-suggestions .prompt {
  width: auto;
  min-height: 34px;
  max-width: 100%;
  padding: 7px 14px;
  border-radius: 999px;
  white-space: normal;
  text-align: left;
  background: rgba(59,130,246,.12);
  border-color: rgba(59,130,246,.3);
  color: var(--acc-hi);
  box-shadow: 0 1px 0 rgba(255,255,255,.05) inset;
}

.chat-suggestions .prompt:hover { background: var(--accent-soft); }

.chat-turn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.chat-outgoing,
.chat-reply {
  width: fit-content;
  padding: 10px 14px;
  color: var(--text);
  font-size: .99rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.chat-outgoing {
  align-self: flex-end;
  max-width: min(89%, 535px);
  border-radius: 18px 18px 6px 18px;
  background: linear-gradient(180deg, #4784f2, #1d4ed8);
  color: #fff;
  white-space: pre-wrap;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset;
}

.chat-incoming {
  width: fit-content;
  min-width: 0;
  max-width: min(93%, 690px);
}

.chat-reply {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px 18px 18px 6px;
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(12,21,38,.35));
}

.chat-reply-text { white-space: pre-wrap; }
.chat-key-point { margin-top: 6px; color: var(--accent); }
.chat-reply > .chat-key-point:only-child { margin-top: 0; }

.chat-market-details {
  margin: 3px 0 0 8px;
  color: var(--text);
}

.chat-market-details summary {
  width: fit-content;
  min-height: 35px;
  padding: 8px 0;
  color: var(--muted);
  font-size: .83rem;
  font-weight: 750;
  cursor: pointer;
}

.chat-market-details summary:hover { color: var(--accent); }

.chat-market-content {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--dark);
  color: var(--text);
  font-size: .91rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.chat-market-content > :first-child { margin-top: 0; }
.chat-market-content p + p { margin-top: 7px; }

.chat-reply-points {
  display: grid;
  gap: 7px;
  margin: 9px 0 0;
  padding-left: 20px;
}

.chat-reply-points li::marker { color: var(--accent); }

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 11px;
}

.chat-actions .button {
  justify-content: flex-start;
  max-width: 100%;
  line-height: 1.3;
  text-align: left;
}

.chat-primary-action { margin: 2px 0 0 7px; }
.chat-primary-action .button { text-align: left; line-height: 1.35; }

.chat-source {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.4;
}

.chat-typing {
  position: relative;
  display: grid;
  width: fit-content;
  min-height: 36px;
  margin-top: 6px;
  padding: 0 12px;
  place-items: center;
  border-radius: 18px 18px 18px 6px;
  background: var(--surface-raised);
}

.chat-typing:first-child { margin-top: 0; }

.chat-dots { display: flex; gap: 4px; }

.chat-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

@media (prefers-reduced-motion: no-preference) {
  .chat-dots i { animation: chat-pulse 1.45s ease-in-out infinite; }
  .chat-dots i:nth-child(2) { animation-delay: .18s; }
  .chat-dots i:nth-child(3) { animation-delay: .36s; }
  @keyframes chat-pulse {
    0%, 60%, 100% { opacity: .55; }
    30% { opacity: 1; }
  }
}

.chat-composer {
  padding: 8px clamp(12px, 2.4vw, 23px) 12px;
  background: var(--surface);
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-width: 0;
  max-width: 800px;
  margin-inline: auto;
  padding: 4px 4px 4px 16px;
  border: 1px solid rgba(125,211,252,.2);
  border-radius: 999px;
  background: var(--inset);
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset;
}

.chat-input-row:focus-within {
  border-color: rgba(125,211,252,.45);
  box-shadow: 0 0 0 4px rgba(59,130,246,.16);
}

.chat-input-row textarea {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  max-height: 116px;
  padding: 10px 3px;
  resize: none;
  field-sizing: content;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}

.chat-input-row textarea:focus-visible { outline: 0; }
.chat-input-row textarea::placeholder { color: var(--muted); }

.chat-send.button {
  flex: none;
  width: 44px;
  height: 44px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
}

.chat-send .icon { width: 19px; height: 19px; }
.chat-send.button:disabled { opacity: .52; }

.chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 850px) {
  .chat-view { height: clamp(430px, calc(100dvh - 113px), 820px); }
}

@media (max-width: 560px) {
  .chat-view {
    height: calc(100dvh - 128px - env(safe-area-inset-bottom));
    min-height: 325px;
    border-radius: 20px;
  }
  .chat-empty, .chat-log { padding: 16px 12px; }
  .chat-log:not(:empty) { gap: 17px; }
  .chat-composer { padding: 7px 8px 9px; }
  .chat-outgoing, .chat-reply { padding: 9px 12px; }
}

@media (max-width: 560px) and (max-height: 520px) {
  .chat-view:has(.chat-input-row:focus-within) {
    height: max(205px, calc(100dvh - 128px - env(safe-area-inset-bottom)));
    min-height: 0;
  }
}
