/* AgentChat — unified global chat panel styles
 *
 * Drop-in alongside chat-agent.js. Reuses starcontrol's CSS variables
 * (--bg, --bg2, --fg, --brand, --border, --good) and .chat-msg patterns.
 */

.agent-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg, #1a1a2e);
  color: var(--fg, #e0e0e0);
  font-family: inherit;
}

/* --- Header --- */

.agent-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border, #2a2a4a);
  flex-shrink: 0;
}

.agent-chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Backend toggle (Starbot / Claude) --- */

.backend-toggle {
  display: flex;
  background: var(--bg2, #16213e);
  border: 1px solid var(--border, #2a2a4a);
  border-radius: 6px;
  overflow: hidden;
}

.toggle-btn {
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: rgba(224, 224, 224, 0.5);
  cursor: pointer;
  transition: all 0.15s ease;
}

.toggle-btn:hover {
  color: var(--fg, #e0e0e0);
}

.toggle-btn.active[data-backend="starbot"] {
  background: #f97316;
  color: #fff;
}

.toggle-btn.active[data-backend="claude"] {
  background: var(--brand, #4a6cf7);
  color: #fff;
}

.agent-chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.agent-chat-actions .cp-btn-icon {
  padding: 4px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.agent-chat-actions .cp-btn-icon:hover { color: var(--text); }

.agent-filter {
  font-size: 11px;
  padding: 3px 6px;
  background: var(--bg2, #16213e);
  color: var(--fg, #e0e0e0);
  border: 1px solid var(--border, #2a2a4a);
  border-radius: 4px;
  max-width: 120px;
}

/* --- Messages --- */

.agent-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 95%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--brand, #4a6cf7);
  color: #1a1a2e;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg2, #16213e);
  border: 1px solid var(--border, #2a2a4a);
  color: var(--fg, #e0e0e0);
}

.chat-msg.progress {
  opacity: 0.7;
  border-style: dashed;
}

.chat-msg-content {
  white-space: pre-wrap;
}

/* --- App badge on user messages --- */

.app-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  color: #fff;
  margin-bottom: 4px;
  letter-spacing: 0.3px;
}

/* --- Tool badges --- */

.tool-badges {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tool-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(53, 196, 111, 0.15);
  color: var(--good, #35c46f);
  border: 1px solid rgba(53, 196, 111, 0.25);
}

.tool-badge-fail {
  background: rgba(255, 107, 107, 0.15);
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.25);
}

/* --- Code --- */

.chat-msg pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 10px;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 12px;
  margin: 6px 0;
}

.chat-msg code {
  font-size: 12px;
  background: rgba(0, 0, 0, 0.2);
  padding: 1px 4px;
  border-radius: 3px;
}

.chat-msg pre code {
  background: none;
  padding: 0;
}

/* --- Thinking indicator --- */

.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg, #e0e0e0);
  opacity: 0.4;
  animation: thinking-bounce 1.2s infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { opacity: 0.4; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.2); }
}

/* --- Input area --- */

.agent-chat-input {
  padding: 10px 14px;
  border-top: 1px solid var(--border, #2a2a4a);
  flex-shrink: 0;
}

.agent-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.agent-app-select {
  font-size: 11px;
  padding: 6px 4px;
  background: var(--bg2, #16213e);
  color: var(--fg, #e0e0e0);
  border: 1px solid var(--border, #2a2a4a);
  border-radius: 4px;
  max-width: 110px;
  flex-shrink: 0;
}

#agent-input {
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
  background: var(--bg2, #16213e);
  color: var(--fg, #e0e0e0);
  border: 1px solid var(--border, #2a2a4a);
  border-radius: 6px;
  outline: none;
}

#agent-input:focus {
  border-color: var(--brand, #4a6cf7);
}

#agent-input::placeholder {
  color: rgba(224, 224, 224, 0.3);
}

.agent-send-btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  background: var(--brand, #4a6cf7);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.agent-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.agent-send-btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

/* --- Backend badge on assistant messages --- */

.backend-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 8px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.backend-starbot {
  background: rgba(249, 115, 22, 0.2);
  color: #f97316;
  border: 1px solid rgba(249, 115, 22, 0.3);
}

.backend-claude {
  background: rgba(74, 108, 247, 0.2);
  color: var(--brand, #4a6cf7);
  border: 1px solid rgba(74, 108, 247, 0.3);
}

/* --- Status bar --- */

.agent-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 10px;
  color: rgba(224, 224, 224, 0.4);
}

.agent-backend-label {
  font-weight: 500;
}

/* --- WS status indicator --- */

.agent-ws-status {
  font-size: 10px;
  color: rgba(224, 224, 224, 0.4);
  display: flex;
  align-items: center;
  gap: 4px;
}

.ws-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.ws-connected {
  background: var(--good, #35c46f);
}

.ws-disconnected {
  background: #6b7280;
}

.ws-starbot {
  background: #f97316;
}

/* --- Scrollbar --- */

.agent-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.agent-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.agent-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(224, 224, 224, 0.15);
  border-radius: 3px;
}

/* --- Responsive --- */

@media (max-width: 768px) {
  .agent-chat-header {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .agent-chat-actions {
    flex-wrap: wrap;
  }
  .agent-app-select {
    max-width: 80px;
  }
  .agent-chat-input {
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .agent-input-row {
    gap: 6px;
  }
  #agent-input {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 10px 12px;
    min-height: 44px;
  }
  .agent-send-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 12px;
  }
  .chat-msg {
    max-width: 90%;
    font-size: 14px;
  }
}
