/* ── Left — Chat panel ── */
.chat-panel {
  width: 38%;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 92%;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.msg.error { align-self: flex-start; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}
.msg.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}
.msg.assistant .msg-bubble {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-bottom-left-radius: var(--radius-sm);
}
.msg.error .msg-bubble {
  background: rgba(248, 81, 73, .12);
  border: 1px solid rgba(248, 81, 73, .3);
  color: var(--red);
}
.msg-meta { font-size: 11px; color: var(--text-dim); }

/* Message model/agent meta footer */
.msg-model-meta {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 2px;
  flex-wrap: wrap;
}
.msg-agent-tag {
  font-size: 10px;
  color: var(--accent);
  background: rgba(var(--accent-rgb, 99, 102, 241), .10);
  border: 1px solid rgba(var(--accent-rgb, 99, 102, 241), .20);
  border-radius: 20px;
  padding: 1px 7px;
  font-weight: 500;
  cursor: default;
  user-select: none;
  white-space: nowrap;
}
.msg-model-tag {
  font-size: 10px;
  color: var(--text-dim);
  font-family: "SFMono-Regular", Consolas, monospace;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  padding: 1px 7px;
  cursor: default;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* Cached-response badge */
.cache-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  background: rgba(var(--accent-rgb, 99, 102, 241), .12);
  color: var(--accent, #6366f1);
  border: 1px solid rgba(var(--accent-rgb, 99, 102, 241), .25);
  cursor: default;
  user-select: none;
}

/* Rendered markdown inside chat bubbles */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  color: inherit; font-weight: 600; margin: .7em 0 .3em;
  font-size: 13px;
}
.msg-bubble p { margin: .35em 0; }
.msg-bubble code {
  background: rgba(0,0,0,.25); border-radius: 3px;
  padding: 1px 4px; font-size: 11.5px;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.msg.user .msg-bubble code { background: rgba(255,255,255,.15); }
.msg-bubble pre {
  background: rgba(0,0,0,.3); border-radius: 6px;
  padding: 10px 12px; overflow-x: auto; margin: .5em 0;
}
.msg-bubble pre code { background: none; padding: 0; font-size: 11.5px; }
.msg-bubble ul, .msg-bubble ol { padding-left: 1.3em; margin: .35em 0; }
.msg-bubble li { margin: .15em 0; }
.msg-bubble strong { font-weight: 600; }

/* Tables in chat bubbles */
.msg-bubble table {
  border-collapse: collapse; width: 100%;
  margin: .5em 0; font-size: 12px;
}
.msg-bubble th, .msg-bubble td {
  border: 1px solid var(--border); padding: 4px 8px;
  text-align: left; vertical-align: top;
}
.msg-bubble th {
  background: rgba(0,0,0,.25); font-weight: 600;
  color: var(--text-muted);
}
.msg-bubble tr:nth-child(even) td { background: rgba(0,0,0,.15); }

/* Token chip in chat */
.msg-bubble .token-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(188,140,255,.15);
  border: 1px solid rgba(188,140,255,.3);
  border-radius: 20px; padding: 0px 6px;
  font-size: 11px; color: var(--purple);
  font-family: "SFMono-Regular", Consolas, monospace;
  vertical-align: middle;
}
.msg.user .msg-bubble .token-chip {
  background: rgba(255,255,255,.15);
  border-color: rgba(255,255,255,.3);
  color: #fff;
}

/* Loading */
.loading-bubble {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex; gap: 8px; align-items: center;
}
.loading-dots {
  display: flex; gap: 5px; align-items: center; flex-shrink: 0;
}
.loading-status {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  animation: bounce .9s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* Thinking block */
.thinking-block {
  align-self: flex-start;
  max-width: 92%;
  margin-bottom: 2px;
}
.thinking-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text-muted);
  background: none; border: none; cursor: pointer;
  padding: 3px 0; line-height: 1.4;
  transition: color .15s;
}
.thinking-toggle:hover { color: var(--text); }
.thinking-toggle-icon {
  font-size: 10px;
  transition: transform .2s ease;
  display: inline-block;
}
.thinking-block.expanded .thinking-toggle-icon { transform: rotate(90deg); }
.thinking-steps {
  margin-top: 6px;
  border-left: 2px solid var(--border);
  padding-left: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.thinking-block:not(.expanded) .thinking-steps { display: none; }
.thinking-block.expanded .thinking-steps { display: flex; }
.thinking-step {
  font-size: 11.5px; line-height: 1.5; color: var(--text-muted);
}
.thinking-step-tool {
  display: inline-flex; align-items: center; gap: 5px;
}
.thinking-step-tool-name {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px; color: var(--purple);
  background: rgba(188,140,255,.1);
  border: 1px solid rgba(188,140,255,.2);
  border-radius: 3px; padding: 1px 5px;
}
.thinking-step-reasoning {
  font-style: italic;
  color: var(--text-dim);
  white-space: pre-wrap;
  max-height: 120px;
  overflow-y: auto;
  font-size: 11px;
}

/* ── Live activity trace ────────────────────────────────────────────────── */
/* Rows grow inside the loading bubble as SSE events arrive, then the whole  */
/* .trace-live div is moved into a .thinking-block collapsible on "done".    */
.trace-live {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
}

/* Individual trace row */
.trace-item {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 5px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  transition: background .12s;
}
.trace-item:hover { background: rgba(255,255,255,.04); }

/* Agent-routed row */
.trace-routed { color: var(--text); }
.trace-icon-route { color: var(--accent); font-size: 12px; }
.trace-agent-name {
  font-weight: 600; font-size: 11.5px;
  color: var(--accent);
}
.trace-reason {
  font-size: 10.5px; color: var(--text-dim);
  font-style: italic;
}
.trace-model-hint {
  font-size: 10px;
  color: var(--text-dim);
  font-family: "SFMono-Regular", Consolas, monospace;
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: 3px;
  padding: 0 5px;
  user-select: none;
}

/* Tool-call row */
.trace-icon { color: var(--text-dim); font-size: 11px; }
.trace-tool-name {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px; color: var(--purple);
  background: rgba(188,140,255,.1);
  border: 1px solid rgba(188,140,255,.2);
  border-radius: 3px; padding: 1px 5px;
}
.trace-arg-hint {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10.5px; color: var(--text-dim);
}
.trace-result-badge {
  font-size: 10px; color: #3fb950;
  background: rgba(63,185,80,.1);
  border: 1px solid rgba(63,185,80,.2);
  border-radius: 3px; padding: 1px 5px;
  font-family: "SFMono-Regular", Consolas, monospace;
}

/* Expandable args/result detail */
.trace-detail { display: none; width: 100%; margin-top: 4px; }
.trace-item.trace-expanded .trace-detail { display: block; }
.trace-detail-section {
  display: flex; flex-direction: column; gap: 2px;
  margin-bottom: 4px;
}
.trace-detail-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .4px; color: var(--text-dim);
}
.trace-detail-code {
  background: rgba(0,0,0,.3); border: 1px solid var(--border-soft);
  border-radius: 4px; padding: 6px 8px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10.5px; color: var(--text-muted);
  white-space: pre-wrap; word-break: break-all;
  max-height: 200px; overflow-y: auto;
  margin: 0;
}

/* Finalized trace inside thinking-block — remove the live hover cursor */
.trace-finalized .trace-item { cursor: pointer; }

/* ── Reasoning rows ─────────────────────────────────────────────────────── */
.trace-reasoning-row { cursor: pointer; }
.trace-icon-think { color: var(--text-dim); font-size: 12px; }
.trace-reasoning-preview {
  color: var(--text-dim);
  font-style: italic;
  font-size: 11px;
  flex: 1;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: break-word;
  max-height: 80px;
  overflow-y: hidden;
}
.trace-reasoning-full {
  font-style: italic;
  color: var(--text-dim);
  max-height: 260px;
  overflow-y: auto;
}

/* Live agent feedback while waiting */
.agent-live-feedback {
  margin-top: 8px;
  border: 1px solid var(--border-soft);
  background: rgba(255,255,255,.02);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.agent-live-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .45px;
  color: var(--text-dim);
  font-weight: 600;
}
.agent-live-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
  align-items: start;
}
.agent-live-key {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .35px;
}
.agent-live-val {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}
/* ──────────────────────────────────────────────────────────────────────── */

/* Chips */
.chips-section {
  padding: 8px 12px 6px;
  flex-shrink: 0;
  border-top: 1px solid var(--border-soft);
}
.chips-label {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: none; border: none; padding: 0; cursor: pointer;
  font-size: 10px; font-weight: 600; letter-spacing: .4px;
  color: var(--text-dim); text-transform: uppercase; margin-bottom: 6px;
}
.chips-label:hover { color: var(--text-muted); }
.chips-toggle-icon {
  font-size: 12px; line-height: 1; transition: transform .2s;
}
.chips-section.collapsed .chips-toggle-icon { transform: rotate(-90deg); }
.chips {
  display: flex; flex-wrap: wrap; gap: 5px;
}
.chips-section.collapsed .chips { display: none; }
.chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11.5px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(47,129,247,.08);
}

/* Input area */
.input-area {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
  align-items: flex-end;
}
textarea {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 12px;
  resize: none;
  min-height: 38px;
  max-height: 120px;
  transition: border-color .15s;
}
textarea:focus { border-color: var(--accent); }
textarea::placeholder { color: var(--text-dim); }

button.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .15s;
  height: 38px;
}
button.send-btn:hover:not(:disabled) { opacity: .85; }
button.send-btn:disabled { opacity: .4; cursor: not-allowed; }

