/* Chat: agents on the left, one conversation on the right, a message bar with attach, voice and send.
   Colors come from tokens in styles.css, so dark and light themes both work. */

.chat-page {
  height: calc(100vh - var(--topbar)); min-height: 480px;
  display: grid; grid-template-columns: 300px minmax(0, 1fr);
}

/* Threads */
.threads { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--cream-tint); }
.threads-head { padding: 16px 14px 10px; display: flex; flex-direction: column; gap: 8px; }
.thread-search { width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--field); font-size: 14px; }
.thread-list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; }
.thread {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; text-align: left; padding: 10px 12px; min-height: 56px;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer; color: var(--charcoal);
}
.thread:hover { background: var(--white); }
.thread[aria-current="true"] { background: var(--white); box-shadow: inset 3px 0 0 var(--oxblood); }
.thread-name { font-family: var(--font-mono); font-size: 14px; font-weight: 500; display: flex; align-items: baseline; min-width: 0; }
.thread-name .tn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.thread-name .dup-id { flex: none; }
.thread-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); white-space: nowrap; }
.thread-preview { grid-column: 1 / -1; font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-agent { margin: 10px 14px 14px; }
.thread-empty { padding: 12px; }

/* Conversation */
.convo { position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--cream); }
.convo-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.back-to-list { display: none !important; font-size: 20px; }
.convo-who { min-width: 0; flex: 1 1 auto; }
.convo-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.convo-title h2 { font-size: 18px; font-weight: 600; }
.convo-title h2:focus { outline: none; }
.convo-title h2:focus-visible { outline: 2px solid var(--oxblood); outline-offset: 2px; }
.convo-sample { font-size: 11px; }
.convo-meta { font-size: 13px; color: var(--text-3); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.convo-meta .mono { font-size: 12px; }
.convo-actions { display: flex; gap: 8px; flex: none; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.pause-sm { background: var(--pause-bg); color: var(--pause-text); border-color: var(--pause-line); }
.pause-sm:hover { filter: brightness(1.15); color: var(--pause-text); }
.pause-sm.resume { background: var(--ok-fill); color: var(--on-primary); }
.pause-sm[aria-disabled="true"] { opacity: 0.6; cursor: progress; }

.logs { flex: 1 1 auto; min-height: 0; position: relative; }
.chat-log { position: absolute; inset: 0; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.chat-log > :first-child { margin-top: auto; }
.chat-empty { align-self: center; color: var(--text-3); font-size: 14px; text-align: center; max-width: 360px; }
.chat-log .loading { align-self: center; }
.chat-log .error-card { align-self: stretch; }
.chat-error { padding: 32px 24px; grid-column: 1 / -1; }
.msg { max-width: min(720px, 80%); display: flex; flex-direction: column; gap: 6px; }
.msg-me { align-self: flex-end; align-items: flex-end; }
.msg-agent { align-self: flex-start; }
.bubble { padding: 11px 15px; border-radius: 16px; font-size: 15px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-me .bubble { background: var(--me-bubble); color: var(--me-bubble-text); border-bottom-right-radius: 4px; }
.msg-agent .bubble { background: var(--white); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-foot { display: flex; align-items: center; gap: 8px; padding: 0 4px; min-height: 24px; }
.msg-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }
.speak { border: 0; background: transparent; color: var(--text-3); cursor: pointer; padding: 4px; border-radius: 6px; display: inline-flex; min-width: 32px; min-height: 32px; align-items: center; justify-content: center; }
.speak:hover, .speak[aria-pressed="true"] { color: var(--oxblood); background: var(--cream-tint); }
.files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: bob 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.stream-caret { display: inline-block; width: 7px; height: 1em; margin-left: 2px; vertical-align: text-bottom; background: var(--oxblood); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Ask first card, right in the conversation */
.ask-card { align-self: flex-start; width: min(560px, 92%); border: 1px solid var(--ask-card-line); background: var(--ask-card-bg); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.ask-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.ask-top strong { font-size: 15px; }
.ask-raw { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-2); background: var(--field); border: 1px solid var(--ask-card-line); border-radius: 10px; padding: 8px 10px; overflow-wrap: anywhere; }
.ask-why { font-size: 14px; color: var(--text-2); }
.ask-btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ask-btns .btn { min-height: 40px; padding: 8px 16px; font-size: 14px; }
.ask-result { font-size: 14px; font-weight: 600; }
.ask-result.ok { color: var(--ok); }
.ask-result.no { color: var(--never); }

.drop-hint {
  position: absolute; inset: 70px 16px 16px; z-index: 5; display: grid; place-items: center; border-radius: 16px;
  border: 2px dashed var(--oxblood); background: color-mix(in srgb, var(--cream) 88%, transparent); font-weight: 600; color: var(--oxblood);
}

.suggest { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 24px 10px; }
.suggest button { min-height: 36px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--white); font-size: 13px; cursor: pointer; color: var(--text-2); }
.suggest button:hover { border-color: var(--oxblood); color: var(--charcoal); }

/* Message bar: + attach, text, microphone, send */
.composer { margin: 0 24px; border: 1px solid var(--line-strong); border-radius: 18px; background: var(--field); padding: 6px; }
.composer:focus-within { border-color: var(--oxblood); box-shadow: 0 0 0 1px var(--oxblood); }
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; max-height: 200px; min-height: 40px; padding: 9px 6px; border: 0; background: transparent;
  font-size: 15px; line-height: 1.45; outline: none;
}
.composer textarea:disabled { cursor: not-allowed; }
.tool-btn, .send-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: transparent; color: var(--text-2);
}
.tool-btn:hover { background: var(--cream-tint); color: var(--charcoal); }
.tool-btn[aria-pressed="true"] { background: var(--never-bg); color: var(--never); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--never) 20%, transparent); } }
.send-btn { background: var(--primary-bg); color: var(--on-primary); }
.send-btn:hover { background: var(--primary-bg-hover); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.send-btn.stop { background: var(--charcoal); color: var(--cream); }
.tool-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 4px 6px; }
.attachments:empty { display: none; }
.file-chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 260px; padding: 6px 6px 6px 10px; border-radius: 10px;
  background: var(--cream-tint); border: 1px solid var(--line); font-size: 13px;
}
.file-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .size { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); flex: none; }
.file-chip button { border: 0; background: transparent; color: var(--text-3); cursor: pointer; width: 28px; height: 28px; border-radius: 6px; font-size: 16px; line-height: 1; }
.file-chip button:hover { background: var(--line); color: var(--charcoal); }
.msg-me .file-chip { background: var(--white); }
.composer-help { padding: 6px 28px 12px; }

@media (max-width: 900px) {
  .chat-page { grid-template-columns: 1fr; height: calc(100dvh - var(--topbar)); min-height: 0; }
  .chat-page:not(.show-convo) .convo { display: none; }
  .chat-page.show-convo .threads { display: none; }
  .back-to-list { display: inline-flex !important; }
  .convo-head { padding: 10px 12px; gap: 6px; }
  .convo-actions { gap: 6px; }
  .convo-actions .btn-sm { padding: 6px 10px; min-height: 44px; }
  .chat-log { padding: 14px; }
  .msg { max-width: 92%; }
  .suggest { padding: 0 12px 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .suggest button { flex: none; }
  .composer { margin: 0 10px; }
  .composer-help { display: none; }
  .composer { margin-bottom: 10px; }
  .composer textarea, .thread-search { font-size: 16px; } /* 16px or more stops phones zooming in on focus */
  .suggest button, .ask-btns .btn { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .typing i, .stream-caret, .tool-btn[aria-pressed="true"] { animation: none; }
}
