/* Conversation area, messages, markdown, code, composer */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.chat-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }
.thread { max-width: 820px; margin: 0 auto; padding: var(--s6) var(--s5) var(--s6); }
@media (max-width: 640px) { .thread { padding: var(--s4) var(--s4); } }

/* ---------- empty state ---------- */
.welcome { max-width: 760px; margin: 0 auto; padding: clamp(24px, 9vh, 96px) var(--s5) var(--s5); }
.welcome .hello { font-family: var(--font-head); font-size: clamp(26px, 3.4vw, 36px); font-weight: 600; letter-spacing: -.02em; line-height: 1.12; margin: 0 0 var(--s3); }
.welcome .mode-line { display: flex; align-items: flex-start; gap: 12px; color: var(--text-2); max-width: 62ch; }
.welcome .mode-line .glyph { width: 34px; height: 34px; border-radius: 9px; background: var(--navy); color: #fff; display: grid; place-items: center; font-family: var(--font-mono); font-size: 15px; flex: none; }
.welcome .mode-line b { color: var(--text); font-weight: 600; display: block; font-family: var(--font-head); }
.examples { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s2); margin-top: var(--s6); }
.example {
  all: unset; box-sizing: border-box; cursor: pointer; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); font-size: var(--fs-md); line-height: 1.4; color: var(--text); display: flex; gap: 10px; align-items: flex-start;
}
.example .icon { color: var(--primary-text); margin-top: 1px; width: 16px; height: 16px; }
.example:hover { border-color: var(--primary); background: var(--primary-weak); }
.example:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.input-hints { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.input-hint { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); padding: 5px 10px; border-radius: 999px; border: 1px dashed var(--border-strong); background: transparent; cursor: pointer; }
.input-hint:hover { border-color: var(--primary); color: var(--primary-text); }
.tools-hint { margin-top: var(--s5); font-size: var(--fs-sm); color: var(--text-3); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- messages ---------- */
.msg { margin-bottom: var(--s6); }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble {
  max-width: min(640px, 88%); background: var(--surface-3); color: var(--text); padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-base);
}
.msg.user .atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; max-width: 88%; }
.msg.assistant { position: relative; padding-left: 18px; }
/* signature: provenance rail — teal when the answer is backed by tools or citations */
.msg.assistant::before { content: ""; position: absolute; left: 0; top: 4px; bottom: 4px; width: 3px; border-radius: 3px; background: var(--border-strong); }
.msg.assistant.grounded::before { background: linear-gradient(var(--signal), color-mix(in srgb, var(--signal) 35%, transparent)); }
.msg.assistant.streaming::before { background: linear-gradient(var(--primary), transparent); animation: rail 1.4s ease-in-out infinite; }
@keyframes rail { 50% { opacity: .45; } }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--text-3); margin-bottom: 6px; flex-wrap: wrap; }
.msg-head .who { font-family: var(--font-head); font-weight: 600; color: var(--text); font-size: var(--fs-sm); }
.msg-head .ver { font-family: var(--font-mono); }
.msg-actions { display: flex; gap: 2px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.msg.user .msg-actions { opacity: 0; transition: opacity .12s; }
.msg.user:hover .msg-actions, .msg.user:focus-within .msg-actions { opacity: 1; }
@media (hover: none) { .msg.user .msg-actions { opacity: 1; } }
.msg-actions .icon-btn { width: 30px; height: 30px; }
.msg-actions .icon-btn .icon { width: 16px; height: 16px; }
.msg-actions .usage { font-size: var(--fs-xs); color: var(--text-3); margin-left: 6px; font-variant-numeric: tabular-nums; }
.edit-box { width: min(640px, 100%); }
.edit-box textarea { width: 100%; min-height: 80px; }
.edit-box .row { margin-top: 8px; }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.stopped-note { font-size: var(--fs-xs); color: var(--text-3); margin-top: 4px; font-style: italic; }
.msg-error { margin-top: 8px; }

/* ---------- notices / citations / artifacts ---------- */
.notices { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.notice { display: flex; gap: 8px; align-items: flex-start; font-size: var(--fs-sm); padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.notice .icon { width: 16px; height: 16px; margin-top: 1px; color: var(--primary-text); }
.notice.warning { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.notice.warning .icon { color: var(--warn-text); }
.cites { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 10px; }
.cites h4 { font-size: var(--fs-xs); font-family: var(--font-body); font-weight: 600; color: var(--text-2); margin: 0 0 6px; display: flex; align-items: center; gap: 6px; }
.cites ol { margin: 0; padding-left: 20px; font-size: var(--fs-sm); color: var(--text-2); }
.cites li { margin: 2px 0; }
.cites li .src { color: var(--text); font-weight: 500; overflow-wrap: anywhere; }
.cites li .snip { display: block; color: var(--text-3); font-size: var(--fs-xs); }
.artifacts { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.artifact { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.artifact-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; }
.artifact .kind { width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; font-family: var(--font-mono); font-size: 11px; font-weight: 500; flex: none; background: var(--primary-weak); color: var(--primary-text); text-transform: uppercase; }
.artifact .kind.xlsx, .artifact .kind.csv { background: var(--signal-weak); color: var(--signal-text); }
.artifact .kind.pdf { background: var(--danger-weak); color: var(--danger-text); }
.artifact .info { flex: 1; min-width: 0; }
.artifact .fn { font-weight: 500; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.artifact .sub { font-size: var(--fs-xs); color: var(--text-3); }
.artifact .preview { border-top: 1px solid var(--border); background: #fff; padding: 8px; display: flex; justify-content: center; }
.artifact .preview svg, .artifact .preview img { max-height: 360px; width: auto; max-width: 100%; height: auto; display: block; }
.att-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; height: 30px; padding: 0 4px 0 10px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--surface); font-size: var(--fs-sm); position: relative; overflow: hidden; }
.att-chip .fn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.att-chip .sz { color: var(--text-3); font-size: 11px; flex: none; }
.att-chip .prog { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--primary); transition: width .2s; }
.att-chip.err { border-color: var(--danger); color: var(--danger-text); }
.att-chip .icon-btn { width: 24px; height: 24px; }
.att-chip > .icon { width: 14px; height: 14px; color: var(--text-3); }
.att-chip.static { padding-right: 10px; }

/* ---------- markdown ---------- */
.md { font-size: var(--fs-base); line-height: 1.65; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md .md-table, .md .code-block, .md .katex-display { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; } .md h4 { font-size: 15px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 3px 0; }
.md li > p { margin: 0 0 4px; }
.md blockquote { border-left: 3px solid var(--border-strong); padding: 2px 0 2px 12px; color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.md a { color: var(--primary-text); text-underline-offset: 2px; }
.md :not(pre) > code { font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); }
.md img { border-radius: var(--r-sm); }
.md-table { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-sm); max-width: 100%; }
.md-table:focus-visible { outline: 2px solid var(--focus); }
.md table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.md th, .md td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }
.md td[align="right"], .md th[align="right"] { text-align: right; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.md .katex { font-size: 1.06em; }

/* code blocks */
.code-block { border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 4px 12px; background: var(--code-head); border-bottom: 1px solid var(--border); }
.code-lang { font-family: var(--font-mono); font-size: 12px; color: var(--text-2); font-weight: 500; }
.code-actions { display: flex; gap: 2px; }
.code-btn { border: 0; background: transparent; color: var(--text-2); font-size: 12px; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-family: var(--font-body); }
.code-btn:hover { background: var(--surface); color: var(--text); }
.code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.55; tab-size: 2; }
.code-block pre:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.code-block code { font-family: var(--font-mono); background: none; border: 0; padding: 0; white-space: pre; color: var(--text); }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in.hljs-keyword, .hljs-literal { color: var(--hl-kw); font-weight: 500; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute { color: var(--hl-str); }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--hl-num); }
.hljs-comment, .hljs-quote { color: var(--hl-com); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--hl-fn); }
.hljs-title.class_, .hljs-type, .hljs-built_in { color: var(--hl-type); }
.hljs-meta, .hljs-variable, .hljs-template-variable, .hljs-punctuation { color: var(--hl-meta); }
.hljs-deletion { color: var(--danger-text); }

/* ---------- composer ---------- */
.composer-wrap { flex: none; padding: 0 var(--s5) var(--s4); }
@media (max-width: 640px) { .composer-wrap { padding: 0 var(--s3) var(--s3); } }
.composer {
  max-width: 820px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px;
  box-shadow: var(--shadow-1); transition: border-color .12s, box-shadow .12s; position: relative;
}
.composer:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.composer.dragging { border-style: dashed; border-color: var(--primary); background: var(--primary-weak); }
.composer .drop-hint { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; font-weight: 600; color: var(--primary-text); border-radius: inherit; pointer-events: none; }
.composer.dragging .drop-hint { display: flex; }
.composer.dragging > :not(.drop-hint) { visibility: hidden; }
.composer .chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 0; }
.composer textarea {
  display: block; width: 100%; border: 0; background: transparent; resize: none; padding: 12px 14px 4px; font-size: var(--fs-base); line-height: 1.5;
  min-height: 48px; max-height: 40vh; overflow-y: auto; color: var(--text);
}
.composer textarea:focus-visible { outline: none; }
.composer textarea::placeholder { color: var(--text-3); }
.composer-bar { display: flex; align-items: center; gap: 4px; padding: 4px 8px 8px; }
.composer-bar .tok { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; margin-left: 4px; white-space: nowrap; }
.composer-bar .tok.over { color: var(--danger-text); }
.send-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--primary); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.send-btn:hover:not(:disabled) { background: var(--primary-hover); }
.send-btn:disabled { background: var(--surface-3); color: var(--text-3); cursor: not-allowed; }
.send-btn.stop { background: var(--text); color: var(--surface); }
.send-btn .icon { width: 18px; height: 18px; stroke-width: 2.2; }
.send-btn.stop .icon { fill: currentColor; }
.composer-foot { max-width: 820px; margin: 6px auto 0; font-size: 11.5px; color: var(--text-3); text-align: center; }
.composer-foot kbd { font-size: 10px; }
.jump-latest { position: absolute; left: 50%; transform: translateX(-50%); bottom: 8px; z-index: 5; box-shadow: var(--shadow-2); border-radius: 999px; }
