.research-app { padding-block: clamp(2rem, 5vw, 4.5rem); }
.research-head { padding-bottom: clamp(1.25rem, 2.4vw, 2rem); border-bottom: 1px solid var(--ink); }
.research-id { display: flex; align-items: center; gap: clamp(.75rem, 1.7vw, 1.3rem); }
.research-face { display: block; flex: none; width: clamp(3.5rem, 6vw, 5rem); aspect-ratio: 1; border-radius: 50%; overflow: hidden; border: 1px solid var(--line); }
.research-face img, .chat-speaker img { width: 100%; height: 100%; object-fit: cover; }
.research-face img { transform: scale(1.4); transform-origin: 53% 27%; }
.research-head h1 { margin: 0; font: 600 clamp(3.1rem, 6.5vw, 6rem)/1.04 var(--head); letter-spacing: -.046em; }
.research-head > p { margin: .65rem 0 0; max-width: 52ch; color: var(--muted); font: 400 clamp(1.18rem, 1.55vw, 1.4rem)/1.45 var(--ui); }
.research-layout { display: grid; grid-template-columns: minmax(0,1fr); padding-block: clamp(1.4rem,3.1vw,2.75rem); }
.research-main { min-width: 0; }
.research-starters { border-top: 1px solid var(--line); }
.research-starters button { display: block; width: 100%; min-height: 46px; padding: .65rem 0; border: 0; border-bottom: 1px solid var(--line); background: white; color: var(--ink); text-align: left; font: 480 1.15rem/1.37 var(--ui); }
.research-starters button:hover, .research-starters button:focus-visible { text-decoration: underline; text-underline-offset: .18em; }

.helena-thread, .chat-turn, .chat-assistant, .chat-body { min-width: 0; }
.helena-thread[hidden], .research-answer[hidden], [data-chat-empty][hidden], [data-chat-clear][hidden] { display: none; }
.helena-thread { display: grid; gap: clamp(1.35rem, 2.6vw, 2.15rem); margin: 0; }
.chat-turn { display: grid; align-items: start; }
.chat-user-by { margin: 0 0 .25rem auto; color: var(--muted); font: 600 1rem/1.35 var(--ui); }
.chat-user { max-width: min(90%, 41rem); justify-self: end; padding: .58rem .95rem .62rem; border-radius: 1rem 1rem .25rem 1rem; background: #f1f1ef; color: var(--ink); font: 450 clamp(1.09rem, 1.25vw, 1.23rem)/1.45 var(--ui); white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-assistant { margin-top: 1.05rem; }
.chat-speaker { display: flex; align-items: center; gap: .55rem; width: fit-content; margin: 0 0 .45rem; color: var(--ink); font: 650 1.08rem/1.3 var(--ui); }
.chat-speaker img { width: 33px; height: 33px; border-radius: 50%; border: 1px solid #cdcec9; }
.chat-body { max-width: 66ch; font: 400 clamp(1.18rem, 1.42vw, 1.38rem)/1.5 var(--ui); color: var(--ink); overflow-wrap: anywhere; }
.chat-body > :first-child { margin-top: 0; }
.chat-body h2,.chat-body h3,.chat-assistant > h2 { margin: 0 0 .4rem; font: 600 clamp(1.45rem, 2.1vw, 1.95rem)/1.16 var(--head); letter-spacing: -.02em; text-wrap: pretty; }
.chat-body h2:focus-visible,.chat-assistant:focus-visible,.chat-speaker:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.chat-body p + p,.research-report + .research-report,.research-contract + .research-contract { margin-top: .7rem; }
.research-report time,.research-period { display: block; margin: .22rem 0; color: var(--muted); font: 550 1rem/1.4 var(--ui); }
.research-contract { padding: .45rem 0; }
.research-contract strong { font-weight: 600; }
.research-value { display: block; margin-top: .2rem; font: 500 1rem/1.5 monospace; overflow-wrap: anywhere; }
.research-basis { color: var(--muted); }
.research-directory { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0 1.3rem; padding: 0; margin: .5rem 0; list-style: none; }
.research-directory li { display: flex; flex-direction: column; min-width: 0; padding: .35rem 0 .5rem; border-bottom: 1px solid var(--line); }
.research-directory li > span { color: var(--muted); font: 400 1rem/1.4 var(--ui); }
.research-table { margin: .65rem 0; width: 100%; border-collapse: collapse; color: var(--ink); font: 500 clamp(1.03rem, 1.25vw, 1.18rem)/1.35 var(--ui); font-variant-numeric: tabular-nums; }
.research-table td,.research-table th { border-bottom: 1px solid var(--line); padding: .4rem .35rem .4rem 0; text-align: left; overflow-wrap: anywhere; }
.research-table th:last-child,.research-table td:last-child { text-align: right; }
.research-sources { display: flex; align-items: baseline; flex-wrap: wrap; gap: .12rem 1rem; padding: 0; margin: .35rem 0 0; list-style: none; }
.research-sources li { min-width: 0; }
.research-ref { display: inline-flex; align-items: center; gap: .3rem; min-height: 44px; max-width: 100%; color: var(--muted); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .22em; text-decoration-color: #93968e; font: 550 1.05rem/1.35 var(--ui); overflow-wrap: anywhere; }
.research-ref:hover { color: var(--ink); text-decoration-color: currentColor; }
.research-followups { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .5rem; margin-top: .65rem; }
.research-followups h3 { flex-basis: 100%; margin: 0; font: 550 1rem/1.35 var(--ui); color: var(--muted); }
.research-followups button { max-width: 100%; min-height: 44px; padding: .42rem .74rem; border: 1px solid #c7c8c2; border-radius: .4rem; background: white; color: var(--ink); font: 500 1.04rem/1.35 var(--ui); text-align: left; overflow-wrap: anywhere; }
.research-followups button:hover { border-color: var(--ink); background: #f6f6f4; }
[data-chat-clear] { min-height: 44px; padding: .4rem 0; border: 0; background: transparent; color: var(--muted); font: 550 1rem/1.35 var(--ui); text-decoration: underline; text-underline-offset: .2em; }
[data-chat-clear]:hover { color: var(--ink); }
.research-form { display: grid; grid-template-columns: minmax(0,1fr) auto; column-gap: .8rem; }
.research-form label { grid-column: 1/-1; margin: 0 0 .4rem; font: 600 1.07rem/1.4 var(--ui); }
.research-form textarea { display: block; grid-column: 1/-1; width: 100%; min-width: 0; resize: vertical; min-height: 5.25rem; padding: .72rem .88rem; border: 1px solid #878982; border-radius: .4rem; background: white; color: var(--ink); font: 400 clamp(1.1rem, 1.35vw, 1.22rem)/1.4 var(--ui); }
.research-form textarea::placeholder { color: #60625d; opacity: 1; }
.research-form textarea:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.research-form:focus-within label { color: var(--ink); }
.research-actions { display: flex; grid-column: 1/-1; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: .4rem .8rem; margin-top: .65rem; }
.research-actions button { min-height: 46px; padding: .55rem 1.15rem; border: 1px solid var(--ink); border-radius: .34rem; color: white; background: var(--ink); font: 600 1.12rem/1.35 var(--ui); }
.research-actions button:hover { background: #363834; }
.research-actions p { flex: 1 1 11rem; order: -1; font: 500 1.05rem/1.4 var(--ui); }
.research-actions p:empty { display: none; }
.research-main .helena-thread:not([hidden]) + .research-form,
[data-chat-active] .research-main .research-form { margin-top: 1.2rem; padding-top: .85rem; border-top: 1px solid var(--line); }

@media(max-width:510px) {
  .research-id h1 { font-size: clamp(2.65rem,10vw,3.6rem); }
  .research-directory { grid-template-columns: minmax(0,1fr); }
  .research-actions button { padding-inline: 1rem; }
  .chat-user { max-width: 91%; }
}

/* The conversation has the same reading measure as Helena's notes. */
.research-app.wrap { --desk-width: 55rem; }
.research-chat-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .4rem 1rem; }
.research-welcome { margin: 0 0 1.3rem; padding: 0; }
.research-welcome > p { max-width: 48ch; color: var(--ink); font: 400 clamp(1.25rem,1.8vw,1.55rem)/1.45 var(--ui); text-wrap: pretty; }
.research-welcome .research-starters { display: flex; flex-wrap: wrap; gap: .4rem .5rem; margin-top: .85rem; border: 0; }
.research-welcome .research-starters button { width: auto; max-width: 100%; min-height: 44px; padding: .4rem .8rem; border: 1px solid #c7c8c2; border-radius: .4rem; font: 500 1.05rem/1.35 var(--ui); }
.research-welcome .research-starters button:hover { border-color: var(--ink); background: #f6f6f4; }
@media(max-width:510px) {
  .research-chat-head { align-items: baseline; }
  .research-chat-head [data-chat-clear] { font-size: 1rem; }
  .research-welcome .research-starters { gap:.35rem; }
}

.helena-thread:not([hidden]) { max-height: min(58vh, 40rem); max-height: min(58svh, 40rem); overflow: auto; padding: .2rem .65rem .45rem .2rem; scrollbar-width: thin; scrollbar-color: #858780 transparent; scroll-padding: .45rem; }
.helena-thread:focus-visible, .chat-more-sources > summary:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.chat-more-sources { margin-top: .15rem; }
.chat-more-sources > summary { width: fit-content; min-height: 44px; padding: .5rem .15rem .5rem 0; color: var(--muted); font: 550 1.05rem/1.35 var(--ui); }
.chat-assistant[aria-busy=true] .chat-body { font-style: italic; color: var(--muted); }
@media(max-height:560px) {
  .helena-thread:not([hidden]) { max-height: min(55svh, 17rem); }
}

.research-form { scroll-margin-block: .85rem calc(6.25rem + env(safe-area-inset-bottom,0px)); }

.chat-thinking {
  display: inline-flex;
  align-items: baseline;
  gap: .4em;
  max-width: 100%;
  color: var(--muted);
  font-style: normal;
}
.chat-thinking-label { min-width: 0; }
.chat-thinking-dots {
  display: inline-flex;
  flex: none;
  gap: .16em;
  align-self: center;
}
.chat-thinking-dots i {
  width: .21em;
  height: .21em;
  border-radius: 50%;
  background: currentColor;
}
@media (prefers-reduced-motion: no-preference) {
  .chat-thinking-dots i { animation: helena-thinking-ink 1.5s ease-in-out infinite; }
  .chat-thinking-dots i:nth-child(2) { animation-delay: .16s; }
  .chat-thinking-dots i:nth-child(3) { animation-delay: .32s; }
}
@keyframes helena-thinking-ink {
  0%, 60%, 100% { opacity: .32; }
  28% { opacity: 1; }
}

.chat-body .research-attribution { margin-top: .45rem; color: var(--muted); font: 400 1rem/1.4 var(--ui); }
.research-attribution .research-ref { font: inherit; }
