/* agent-chat.css — Floating AI chat panel styles */

/* ============================================================
   FLOATING ACTION BUTTON (FAB)
   ============================================================ */
.agent-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent, #4f46e5);
  color: var(--text-on-accent, #ffffff);
  border: none;
  cursor: pointer;
  z-index: 9998;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.agent-chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.agent-chat-fab:active {
  transform: scale(0.95);
}

/* ============================================================
   CHAT PANEL
   ============================================================ */
.agent-chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  height: 600px;
  border-radius: 16px;
  box-shadow: var(--shadow-xl, 0 20px 25px -5px rgba(0, 0, 0, 0.08));
  display: flex;
  flex-direction: column;
  z-index: 9999;
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  overflow: hidden;
  transform-origin: bottom right;
  animation: agent-chat-open 0.2s ease forwards;
}

@keyframes agent-chat-open {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ============================================================
   HEADER
   ============================================================ */
.agent-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  background: var(--bg-elevated, #ffffff);
  flex-shrink: 0;
}

.agent-chat-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #0a0a0a);
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-chat-header-title svg {
  color: var(--accent, #4f46e5);
}

.agent-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.agent-chat-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-tertiary, #7a7a7a);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.agent-chat-header-btn:hover {
  background: var(--bg-hover, rgba(0, 0, 0, 0.04));
  color: var(--text-primary, #0a0a0a);
}

/* ============================================================
   CONVERSATION HISTORY DROPDOWN
   ============================================================ */
.agent-chat-history {
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  background: var(--bg-subtle, #f9f9f9);
  flex-shrink: 0;
  max-height: 200px;
  overflow-y: auto;
}

.agent-chat-history-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #4a4a4a);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease;
}

.agent-chat-history-toggle:hover {
  background: var(--bg-hover, rgba(0, 0, 0, 0.04));
}

.agent-chat-history-toggle svg {
  transition: transform 0.15s ease;
}

.agent-chat-history-toggle.open svg {
  transform: rotate(180deg);
}

.agent-chat-history-list {
  padding: 0 8px 8px;
}

.agent-chat-history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.agent-chat-history-item:hover {
  background: var(--bg-hover, rgba(0, 0, 0, 0.04));
}

.agent-chat-history-item.active {
  background: var(--accent-alpha, rgba(79, 70, 229, 0.12));
}

.agent-chat-history-item-info {
  flex: 1;
  min-width: 0;
}

.agent-chat-history-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary, #0a0a0a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-chat-history-item-date {
  font-size: 11px;
  color: var(--text-tertiary, #7a7a7a);
}

.agent-chat-history-delete {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-quaternary, #aaaaaa);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition:
    opacity 0.12s ease,
    color 0.12s ease,
    background 0.12s ease;
}

.agent-chat-history-item:hover .agent-chat-history-delete {
  opacity: 1;
}

.agent-chat-history-delete:hover {
  color: var(--danger, #dc2626);
  background: var(--danger-alpha, rgba(220, 38, 38, 0.12));
}

/* ============================================================
   MESSAGE LIST
   ============================================================ */
.agent-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

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

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

.agent-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-strong, rgba(0, 0, 0, 0.18));
  border-radius: 2px;
}

/* ============================================================
   MESSAGE BUBBLES
   ============================================================ */
.agent-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.agent-chat-msg.user {
  align-self: flex-end;
  background: var(--accent, #4f46e5);
  color: var(--text-on-accent, #ffffff);
  border-bottom-right-radius: 4px;
}

.agent-chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg-elevated, #f9f9f9);
  color: var(--text-primary, #0a0a0a);
  border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.05));
  border-bottom-left-radius: 4px;
}

/* Markdown rendered content */
.agent-chat-msg.assistant strong {
  font-weight: 600;
}

.agent-chat-msg.assistant em {
  font-style: italic;
}

.agent-chat-msg.assistant code {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  background: var(--bg-code, #f0f0f0);
  padding: 1px 5px;
  border-radius: 4px;
}

.agent-chat-msg.assistant pre {
  margin: 8px 0;
  padding: 10px 12px;
  background: var(--bg-code, #f0f0f0);
  border-radius: 8px;
  overflow-x: auto;
}

.agent-chat-msg.assistant pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  line-height: 1.5;
}

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

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

.agent-chat-msg.assistant a {
  color: var(--accent, #4f46e5);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.agent-chat-msg.assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}

.agent-chat-msg.assistant th,
.agent-chat-msg.assistant td {
  padding: 4px 8px;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  text-align: left;
}

.agent-chat-msg.assistant th {
  font-weight: 600;
  background: var(--bg-subtle, #f9f9f9);
}

/* ============================================================
   TOOL BADGES
   ============================================================ */
.agent-chat-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.agent-chat-tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent-alpha, rgba(79, 70, 229, 0.12));
  color: var(--accent, #4f46e5);
  font-size: 11px;
  font-family: "JetBrains Mono", monospace;
  font-weight: 500;
}

.agent-chat-tool-badge svg {
  width: 10px;
  height: 10px;
}

/* ============================================================
   CONFIRMATION CARD
   ============================================================ */
.agent-chat-confirm {
  align-self: flex-start;
  max-width: 90%;
  padding: 14px;
  border-radius: 12px;
  border: 1.5px solid var(--warning, #d97706);
  background: var(--warning-bg, #fffbeb);
}

.agent-chat-confirm-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--warning, #d97706);
  margin-bottom: 6px;
}

.agent-chat-confirm-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary, #0a0a0a);
  margin-bottom: 12px;
}

.agent-chat-confirm-actions {
  display: flex;
  gap: 8px;
}

.agent-chat-confirm-btn {
  padding: 6px 16px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.12s ease;
}

.agent-chat-confirm-btn:hover {
  opacity: 0.85;
}

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

.agent-chat-confirm-btn.confirm {
  background: var(--success, #16a34a);
  color: #ffffff;
}

.agent-chat-confirm-btn.cancel {
  background: var(--danger, #dc2626);
  color: #ffffff;
}

/* ============================================================
   TYPING INDICATOR
   ============================================================ */
.agent-chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--bg-elevated, #f9f9f9);
  border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.05));
  border-bottom-left-radius: 4px;
}

.agent-chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary, #7a7a7a);
  animation: agent-chat-bounce 1.4s infinite ease-in-out both;
}

.agent-chat-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.agent-chat-typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

.agent-chat-typing-dot:nth-child(3) {
  animation-delay: 0s;
}

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

/* ============================================================
   INPUT AREA
   ============================================================ */
.agent-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  background: var(--bg-surface, #ffffff);
  flex-shrink: 0;
}

.agent-chat-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: "Inter", sans-serif;
  line-height: 1.5;
  color: var(--text-primary, #0a0a0a);
  background: var(--bg-elevated, #ffffff);
  outline: none;
  min-height: 38px;
  max-height: 120px;
  transition: border-color 0.12s ease;
}

.agent-chat-textarea:focus {
  border-color: var(--accent, #4f46e5);
}

.agent-chat-textarea::placeholder {
  color: var(--text-quaternary, #aaaaaa);
}

.agent-chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--accent, #4f46e5);
  color: var(--text-on-accent, #ffffff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background 0.12s ease,
    opacity 0.12s ease;
}

.agent-chat-send-btn:hover:not(:disabled) {
  background: var(--accent-hover, #4338ca);
}

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

/* ============================================================
   EMPTY STATE
   ============================================================ */
.agent-chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  color: var(--text-tertiary, #7a7a7a);
}

.agent-chat-empty-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-alpha, rgba(79, 70, 229, 0.12));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent, #4f46e5);
}

.agent-chat-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary, #0a0a0a);
}

.agent-chat-empty-text {
  font-size: 13px;
  text-align: center;
  line-height: 1.5;
}

/* ============================================================
   KEYBOARD SHORTCUT HINT
   ============================================================ */
.agent-chat-shortcut {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 4px;
}

.agent-chat-shortcut kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 11px;
  font-family: "Inter", sans-serif;
  font-weight: 500;
  color: var(--text-tertiary, #7a7a7a);
  background: var(--bg-hover, rgba(0, 0, 0, 0.04));
  border: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  border-radius: 4px;
}

/* ============================================================
   DELETE CONFIRMATION OVERLAY
   ============================================================ */
.agent-chat-delete-confirm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--danger-bg, #fef2f2);
  border-radius: 8px;
  margin-top: 4px;
}

.agent-chat-delete-confirm span {
  font-size: 12px;
  color: var(--danger, #dc2626);
  font-weight: 500;
}

.agent-chat-delete-confirm button {
  padding: 3px 10px;
  border-radius: 6px;
  border: none;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

.agent-chat-delete-confirm .yes {
  background: var(--danger, #dc2626);
  color: #ffffff;
}

.agent-chat-delete-confirm .no {
  background: var(--bg-hover, rgba(0, 0, 0, 0.04));
  color: var(--text-secondary, #4a4a4a);
}

/* ============================================================
   VOICE — MICROPHONE BUTTON
   ============================================================ */
.chat-mic-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-tertiary, #7a7a7a);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    color 0.15s ease,
    background 0.15s ease;
}

.chat-mic-btn:hover {
  color: var(--text-primary, #0a0a0a);
  background: var(--bg-hover, rgba(0, 0, 0, 0.04));
}

.chat-mic-btn--active {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
  animation: chat-mic-pulse 1.5s ease-in-out infinite;
}

@keyframes chat-mic-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.3);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(220, 38, 38, 0);
  }
}

/* ============================================================
   VOICE — SPEAKER BUTTON (on assistant messages)
   ============================================================ */
.chat-speaker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-quaternary, #aaaaaa);
  cursor: pointer;
  margin-top: 4px;
  flex-shrink: 0;
  transition:
    color 0.12s ease,
    background 0.12s ease;
}

.chat-speaker-btn:hover {
  color: var(--accent, #4f46e5);
  background: var(--accent-alpha, rgba(79, 70, 229, 0.08));
}

.chat-speaker-btn--playing {
  color: var(--accent, #4f46e5);
  animation: chat-speaker-pulse 1.2s ease-in-out infinite;
}

@keyframes chat-speaker-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* ============================================================
   VOICE — SETTINGS PANEL
   ============================================================ */
.voice-settings-panel {
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  background: var(--bg-subtle, #f9f9f9);
  padding: 10px 16px;
  flex-shrink: 0;
}

.voice-settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary, #4a4a4a);
  cursor: pointer;
  padding: 4px 0;
}

.voice-settings-row input[type="checkbox"] {
  accent-color: var(--accent, #4f46e5);
  cursor: pointer;
}

.voice-settings-row input[type="range"] {
  flex: 1;
  max-width: 100px;
  height: 4px;
  accent-color: var(--accent, #4f46e5);
  cursor: pointer;
}

.voice-settings-rate {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  min-width: 28px;
  text-align: right;
}

/* Active state for header voice button */
.agent-chat-header-btn.active {
  color: var(--accent, #4f46e5);
  background: var(--accent-alpha, rgba(79, 70, 229, 0.12));
}

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
  .agent-chat-panel {
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }

  .agent-chat-fab {
    bottom: 16px;
    right: 16px;
  }
}

/* ============================================================
   AI screens markdown rendering (ai-fullscreen, ai-split)
   Mirrors the .agent-chat-msg.assistant rules so the new
   screens render headings/tables/code/lists with parity to
   the floating chatbot.
   ============================================================ */
.ai-fullscreen-message-bubble.assistant h1,
.ai-fullscreen-message-bubble.assistant h2,
.ai-fullscreen-message-bubble.assistant h3,
.ai-fullscreen-message-bubble.assistant h4,
.ai-fullscreen-message-bubble.assistant h5,
.ai-fullscreen-message-bubble.assistant h6 {
  margin: 12px 0 6px;
  font-weight: 600;
  line-height: 1.3;
}
.ai-fullscreen-message-bubble.assistant h1 { font-size: 18px; }
.ai-fullscreen-message-bubble.assistant h2 { font-size: 16px; }
.ai-fullscreen-message-bubble.assistant h3 { font-size: 15px; }
.ai-fullscreen-message-bubble.assistant h4,
.ai-fullscreen-message-bubble.assistant h5,
.ai-fullscreen-message-bubble.assistant h6 { font-size: 14px; }

.ai-fullscreen-message-bubble.assistant code {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  background: var(--bg-code, #f0f0f0);
  padding: 1px 5px;
  border-radius: 4px;
}
.ai-fullscreen-message-bubble.assistant pre {
  margin: 8px 0;
  padding: 10px 12px;
  background: var(--bg-code, #0f172a);
  color: #e2e8f0;
  border-radius: 8px;
  overflow-x: auto;
}
.ai-fullscreen-message-bubble.assistant pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
}

.ai-fullscreen-message-bubble.assistant ul,
.ai-fullscreen-message-bubble.assistant ol {
  margin: 6px 0;
  padding-left: 20px;
}
.ai-fullscreen-message-bubble.assistant li { margin: 2px 0; }

.ai-fullscreen-message-bubble.assistant a {
  color: var(--accent, #4f46e5);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-fullscreen-message-bubble.assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.ai-fullscreen-message-bubble.assistant th,
.ai-fullscreen-message-bubble.assistant td {
  padding: 6px 10px;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  text-align: left;
}
.ai-fullscreen-message-bubble.assistant th {
  font-weight: 600;
  background: var(--bg-subtle, #f9f9f9);
}

.ai-fullscreen-message-bubble.assistant hr {
  border: 0;
  border-top: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  margin: 12px 0;
}

/* Rich blocks share a common chrome — extend each block component's
   inline style with a consistent .dc-*-block selector for future
   theming. */
.dc-mermaid-block,
.dc-chart-block,
.dc-csv-block,
.dc-xlsx-block {
  font-size: 13px;
}
.dc-mermaid-block svg { max-width: 100%; height: auto; }
