/* ═══════════════════════════════════════
   CHAT PANEL — AI Agent slide-out panel
   ═══════════════════════════════════════ */

/* ── Floating action button ── */
.chat-fab {
  display: none; /* shown via body.authenticated */
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
  z-index: 1000;
  transition: transform 0.15s, box-shadow 0.15s;
}

body.authenticated .chat-fab {
  display: flex;
}

.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(59, 130, 246, 0.5);
}

.chat-fab.active {
  background: var(--surface-hover);
  color: var(--text-dim);
  box-shadow: 0 2px 8px var(--shadow-heavy);
}

/* ── Panel container ── */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 440px;
  max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 999;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.chat-panel.open {
  transform: translateX(0);
}

/* ── Header ── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-bright);
  letter-spacing: 0.02em;
}

.chat-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
}

.chat-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ── Messages area ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Welcome state ── */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  gap: 12px;
  flex: 1;
}

.chat-welcome-icon {
  width: 40px;
  height: 40px;
  color: var(--accent-blue);
  opacity: 0.6;
}

.chat-welcome h3 {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-bright);
  margin: 0;
}

.chat-welcome p {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
  max-width: 280px;
  line-height: 1.5;
}

/* ── Message bubbles ── */
.chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: chatFadeIn 0.2s ease;
}

@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--accent-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* ── Markdown rendering in assistant messages ── */
.chat-msg-assistant strong {
  color: var(--text-bright);
  font-weight: 600;
}

.chat-msg-assistant code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--accent-teal);
}

.chat-msg-assistant pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.chat-msg-assistant pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 11px;
  line-height: 1.5;
}

.chat-msg-assistant ul, .chat-msg-assistant ol {
  margin: 6px 0;
  padding-left: 20px;
}

.chat-msg-assistant li {
  margin: 2px 0;
}

/* ── Tool call indicators ── */
.chat-tool {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0;
}

.chat-tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.1s;
}

.chat-tool-pill:hover {
  background: var(--surface-hover);
}

.chat-tool-pill svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.chat-tool-pill .tool-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-tool-pill .tool-status.running {
  background: var(--accent-amber);
  animation: toolPulse 1s ease-in-out infinite;
}

.chat-tool-pill .tool-status.done {
  background: var(--accent-teal);
}

.chat-tool-pill .tool-status.error {
  background: var(--accent-rose);
}

@keyframes toolPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.chat-tool-detail {
  display: none;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.chat-tool-detail.expanded {
  display: block;
}

/* ── Input area ── */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.4;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 20px;
  transition: border-color 0.15s;
}

.chat-input:focus {
  border-color: var(--accent-blue);
}

.chat-input::placeholder {
  color: var(--text-dim);
}

.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent-blue);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.chat-send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.chat-send:not(:disabled):hover {
  opacity: 0.85;
}

/* ── Streaming indicator ── */
.chat-streaming-dot {
  display: inline-block;
  width: 4px;
  height: 4px;
  background: var(--accent-blue);
  border-radius: 50%;
  margin-left: 2px;
  animation: streamBlink 0.8s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes streamBlink {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}

/* ── Error messages ── */
.chat-error {
  align-self: center;
  padding: 8px 14px;
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.25);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-rose);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .chat-panel {
    width: 100vw;
  }

  .chat-fab {
    bottom: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
  }
}
