/*
 * Naming: BEM-ish — block-element pattern (no __ or -- delimiters).
 * Examples: block-header, block-title, agent-card, agent-dot, task-item, task-meta.
 * State variants use dot-chained classes: .agent-status.ready, .block-status--processing.
 * Tokens: spacing uses --space-*, typography uses --text-*, colors use named vars.
 */

/* ── Chat Container ── */
.chat-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.messages::-webkit-scrollbar {
  width: 4px;
}
.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── Chat Empty State ── */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-muted);
  gap: var(--space-4);
}
.chat-empty-icon { font-size: 32px; opacity: 0.5; }
.chat-empty-title { font-size: var(--text-md); font-weight: 600; }
.chat-empty-body { font-size: var(--text-sm); }
.chat-empty-body a { color: var(--blue); }

/* ── Messages ── */
.msg {
  max-width: 85%;
  padding: var(--space-4) var(--space-5);
  border-radius: 10px;
  font-size: var(--text-base);
  line-height: 1.5;
  animation: fadeIn 0.2s ease;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border-bottom-left-radius: 3px;
}
.msg.msg-error {
  color: var(--red);
}
.msg .msg-agent {
  font-size: var(--text-xs);
  font-weight: 600;
  margin-bottom: var(--space-1);
}
.msg .msg-time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
  text-align: right;
}

/* ── Streaming ── */
.msg.assistant .stream-text p {
  margin: 0 0 var(--space-3);
}
.msg.assistant .stream-text p:last-child {
  margin: 0;
}
.msg.assistant .stream-text pre {
  background: rgba(0, 0, 0, 0.3);
  padding: var(--space-3) var(--space-4);
  border-radius: 4px;
  overflow-x: auto;
  font-size: var(--text-sm);
  margin: var(--space-2) 0;
}
.msg.assistant .stream-text code {
  background: rgba(0, 0, 0, 0.2);
  padding: 1px var(--space-2);
  border-radius: 3px;
  font-size: var(--text-sm);
}
.msg.assistant .stream-text pre code {
  background: none;
  padding: 0;
}
.msg.assistant .stream-text ul,
.msg.assistant .stream-text ol {
  margin: var(--space-2) 0;
  padding-left: var(--space-6);
}

/* ── Typing Indicator ── */
.typing-dots {
  display: inline-flex;
  gap: var(--space-1);
  padding: var(--space-2) 0;
}
.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 0.6s infinite;
}
.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

/* ── Status Strip ── */
/* Compact agent/task dots above the input, replacing what would otherwise
   be permanent Agents/Tasks panels. Hidden entirely (display:none, set in
   JS) when there's nothing to show. */
.status-strip {
  display: none;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-5);
}
.status-dot {
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.status-dot:hover {
  background: var(--bg-hover);
}
.status-dot-mark {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot-mark.pulse {
  animation: pulse 2s infinite;
}
.status-dot--tasks {
  border-radius: var(--radius);
}
.status-dot-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  min-width: 14px;
  text-align: center;
}
.status-dot-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: var(--space-2);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--space-3) var(--space-4);
  min-width: 160px;
  max-width: 260px;
  z-index: 60;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  text-align: left;
  cursor: default;
}
.status-dot-dropdown-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-2);
}
.status-dot-dropdown-line {
  font-size: var(--text-sm);
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 0;
}
.status-dot-dropdown-more {
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding-top: var(--space-1);
}

/* ── Input ── */
.input-area {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-3);
  position: relative;
}
.input-area textarea {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: var(--space-4);
  font-family: var(--font);
  font-size: var(--text-base);
  resize: none;
  outline: none;
  min-height: 36px;
  max-height: 100px;
}
.input-area textarea:focus {
  border-color: var(--accent);
}
.input-area .send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: var(--radius);
  padding: 0 var(--space-5);
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: 500;
}
.input-area .send-btn:hover {
  opacity: 0.85;
}
.input-area .send-btn:active {
  background: var(--bg-active);
}
.input-area .send-btn:focus-visible {
  box-shadow: var(--focus-ring);
}

/* ── Tool Blocks ── */
.tool-block {
  background: var(--glass);
  border: 1px solid var(--glass-b);
  border-radius: 10px;
  padding: var(--space-5) var(--space-6);
  margin: var(--space-4) 0;
}
.tool-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.tool-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}
.tool-status.running {
  background: var(--text);
  animation: pulse 1.5s infinite;
}
.tool-status.error {
  background: var(--red);
}
.tool-name {
  font-family: "SF Mono", monospace;
  font-size: var(--text-sm);
  color: var(--text-dim);
}
.tool-input {
  font-family: "SF Mono", monospace;
  font-size: var(--text-xs);
  background: rgba(0, 0, 0, 0.3);
  padding: var(--space-4);
  border-radius: 6px;
  margin-top: var(--space-4);
  overflow-x: auto;
  white-space: pre-wrap;
  color: var(--text-muted);
}

/* ── Markdown ── */
.markdown-content {
  padding: var(--space-2) var(--space-4);
}
.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
  margin: var(--space-7) 0 var(--space-4);
  font-weight: 600;
}
.markdown-content h1 {
  font-size: var(--text-lg);
}
.markdown-content h2 {
  font-size: var(--text-lg);
}
.markdown-content h3 {
  font-size: var(--text-md);
}
.markdown-content code {
  background: rgba(255, 255, 255, 0.06);
  padding: var(--space-1) var(--space-3);
  border-radius: 4px;
  font-family: "SF Mono", monospace;
  font-size: var(--text-base);
}
.markdown-content pre {
  background: rgba(0, 0, 0, 0.4);
  padding: var(--space-5);
  border-radius: 8px;
  overflow-x: auto;
  margin: var(--space-5) 0;
}
.markdown-content pre code {
  background: none;
  padding: 0;
}
.markdown-content a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── Mobile chat ── */
@media (max-width: 768px) {
  .input-area {
    position: sticky;
    bottom: 0;
    padding: var(--space-4);
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
  }
  .input-area textarea,
  .input-area input {
    font-size: 16px;
    min-height: 44px;
  }
  .msg {
    max-width: 95%;
    font-size: var(--text-md);
  }
  .messages {
    padding: var(--space-4);
    -webkit-overflow-scrolling: touch;
  }
}

/* ── Markdown Viewer Widget ── */
.md-viewer {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.md-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.md-toolbar button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-4);
  cursor: pointer;
  font-size: var(--text-sm);
}
.md-toolbar button:disabled {
  opacity: 0.3;
  cursor: default;
}
.md-content {
  flex: 1;
  overflow: auto;
}
.md-source {
  font-family: "SF Mono", monospace;
  font-size: var(--text-base);
  white-space: pre-wrap;
  padding: var(--space-5);
  color: var(--text);
}
.md-title {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Attach Button + Menu ── */
.attach-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.attach-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.attach-btn:active {
  background: var(--bg-active);
}
.attach-btn:focus-visible {
  box-shadow: var(--focus-ring);
}
.attach-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: var(--space-2);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.attach-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-3) var(--space-5);
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: var(--text-base);
  white-space: nowrap;
}
.attach-menu button:hover {
  background: var(--glass);
}

/* ── Text Snippet / @Prompts / Commands panels ── */
.snippet-panel,
.prompts-panel,
.commands-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: var(--space-2);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  max-width: 360px;
}
.snippet-input {
  width: 100%;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: var(--space-2);
  font-family: inherit;
  font-size: var(--text-sm);
}
.snippet-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.snippet-actions button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
}
.snippet-insert {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}
.prompts-search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: var(--space-2);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}
.prompts-list,
.commands-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.prompt-item,
.command-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: var(--radius);
  padding: var(--space-2);
  cursor: pointer;
  color: var(--text);
}
.prompt-item:hover,
.command-item:hover {
  background: var(--glass);
}
.prompt-title {
  font-size: var(--text-sm);
  font-weight: 600;
}
.prompt-text,
.command-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.prompts-empty {
  color: var(--text-muted);
  font-size: var(--text-sm);
  padding: var(--space-3);
  text-align: center;
}

/* ── Attachment Preview ── */
.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0 var(--space-5);
}
.attachment-preview:empty {
  display: none;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
}
.attach-thumb {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 3px;
}
.attach-name {
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-xs);
  padding: 0 var(--space-1);
}
.attach-remove:hover {
  color: var(--red);
}

/* ── Message Attachments ── */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.msg-thumb {
  max-width: 120px;
  max-height: 80px;
  border-radius: 4px;
}
.msg-file {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ── Mic Button (Voice Input) ── */
.mic-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.mic-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.mic-btn:focus-visible {
  box-shadow: var(--focus-ring);
}
.mic-btn.recording {
  color: var(--red);
  border-color: var(--red);
  animation: pulse 1.5s infinite;
}

/* ── Voice Interim Indicator ── */
.voice-interim {
  display: none;
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-style: italic;
  padding: 0 var(--space-5);
  max-height: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.voice-interim:not(:empty) {
  display: block;
}
