/* ================================================================
   AI Agent Chat — Styles
   Complete chat system with agent sidebar, conversation management,
   voice output, and enhanced message formatting.
   ================================================================ */

/* ── Chat Layout (Sidebar + Chat) ───────────────────────────── */
.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-lg);
  max-width: 1100px;
  margin: 0 auto;
  min-height: 70vh;
}

/* ── Agent Sidebar ──────────────────────────────────────────── */
.agent-sidebar {
  display: flex;
  flex-direction: column;
  background: rgba(13, 13, 26, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  position: sticky;
  top: 90px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  transition: all var(--transition-med);
}

.agent-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border-color);
}

.agent-sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.agent-sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: var(--space-xs);
  transition: color var(--transition-fast);
}

.agent-sidebar-toggle:hover { color: var(--color-lime); }

/* ── Sidebar Collapsed State ────────────────────────────────── */
.agent-sidebar.is-collapsed {
  width: 60px;
  min-width: 60px;
  padding: var(--space-sm);
  overflow: hidden;
}

.agent-sidebar.is-collapsed .agent-sidebar-title,
.agent-sidebar.is-collapsed .agent-info,
.agent-sidebar.is-collapsed .agent-active-dot,
.agent-sidebar.is-collapsed .agent-sidebar-actions,
.agent-sidebar.is-collapsed .budget-meter {
  display: none;
}

.agent-sidebar.is-collapsed .agent-card {
  justify-content: center;
  padding: var(--space-sm);
}

.agent-sidebar.is-collapsed .agent-emoji {
  width: auto;
}

.agent-sidebar.is-collapsed .agent-sidebar-toggle {
  transform: rotate(180deg);
}

/* Update grid when sidebar is collapsed */
.chat-layout:has(.agent-sidebar.is-collapsed) {
  grid-template-columns: 60px 1fr;
}

/* ── Agent Cards ────────────────────────────────────────────── */
.agent-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  flex: 1;
}

.agent-card {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
  font-family: var(--font-main);
  color: var(--text-secondary);
  position: relative;
}

.agent-card:hover {
  background: rgba(107, 63, 160, 0.1);
  border-color: rgba(107, 63, 160, 0.2);
  color: var(--text-primary);
}

.agent-card--active {
  background: rgba(107, 63, 160, 0.15);
  border-color: rgba(178, 212, 48, 0.3);
  color: var(--text-primary);
}

.agent-card--active .agent-name {
  color: var(--color-lime);
}

.agent-emoji {
  font-size: 1.5rem;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

.agent-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.agent-name {
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-role {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.agent-active-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-lime);
  box-shadow: 0 0 8px rgba(178, 212, 48, 0.6);
  margin-left: auto;
  flex-shrink: 0;
  animation: statusPulse 2s ease-in-out infinite;
}

/* ── Sidebar Actions ────────────────────────────────────────── */
.agent-sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-color);
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: rgba(107, 63, 160, 0.08);
  border: 1px solid rgba(107, 63, 160, 0.15);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sidebar-btn:hover {
  background: rgba(107, 63, 160, 0.18);
  color: var(--text-primary);
  border-color: rgba(107, 63, 160, 0.3);
}

/* ── Chat Container ─────────────────────────────────────────── */
.chat-container {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  margin-bottom: var(--space-md);
}

.chat-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.chat-header-controls {
  display: flex;
  gap: var(--space-xs);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: rgba(26, 10, 46, 0.7);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  border-color: var(--color-lime);
  background: rgba(107, 63, 160, 0.2);
}

.icon-btn.active {
  border-color: var(--color-lime);
  background: rgba(178, 212, 48, 0.15);
}

#btn-toggle-sidebar-mobile { display: none; }

/* ── AI Status Indicator ────────────────────────────────────── */
.ai-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: rgba(26, 10, 46, 0.7);
  border: 1px solid var(--border-color);
  border-radius: 100px;
  font-size: 0.8rem;
}

/* ── Suggested Prompts ──────────────────────────────────────── */
.suggested-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.prompt-chip {
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-family: var(--font-main);
  background: rgba(107, 63, 160, 0.1);
  border: 1px solid rgba(107, 63, 160, 0.25);
  border-radius: 100px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.prompt-chip:hover {
  background: rgba(107, 63, 160, 0.2);
  border-color: var(--color-lime);
  color: var(--color-lime);
  transform: translateY(-1px);
}

/* ── Chat Messages Area ─────────────────────────────────────── */
.chat-messages {
  flex: 1;
  min-height: 300px;
  max-height: 50vh;
  overflow-y: auto;
  padding: var(--space-md);
  background: rgba(13, 13, 26, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  scroll-behavior: smooth;
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(107, 63, 160, 0.4); border-radius: 3px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(107, 63, 160, 0.7); }

/* ── Chat Message ───────────────────────────────────────────── */
.chat-msg {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.3s ease;
}

.chat-msg:last-child { margin-bottom: 0; }
.chat-msg--user { flex-direction: row-reverse; }

.chat-msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  background: rgba(107, 63, 160, 0.3);
  border: 1px solid var(--border-color);
}

.chat-msg--user .chat-msg-avatar {
  background: rgba(178, 212, 48, 0.15);
  border-color: rgba(178, 212, 48, 0.3);
}

.chat-msg-content {
  max-width: 80%;
  min-width: 0;
}

.chat-msg--user .chat-msg-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.chat-msg-bubble {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  line-height: 1.6;
  font-size: 0.9rem;
  position: relative;
}

.chat-msg--assistant .chat-msg-bubble {
  background: rgba(26, 10, 46, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.chat-msg--user .chat-msg-bubble {
  background: rgba(107, 63, 160, 0.25);
  border: 1px solid rgba(107, 63, 160, 0.4);
  color: var(--text-primary);
}

.chat-msg-bubble p { margin: 0 0 var(--space-sm) 0; }
.chat-msg-bubble p:last-child { margin-bottom: 0; }

.welcome-list {
  margin: 0.5rem 0 0.5rem 1.2rem;
  list-style: disc;
}

/* Code blocks inside chat */
.chat-msg-bubble pre {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(107, 63, 160, 0.3);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  overflow-x: auto;
  margin: var(--space-sm) 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.5;
  position: relative;
}

.chat-msg-bubble code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(107, 63, 160, 0.15);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

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

/* Message actions (voice, copy) */
.chat-msg-actions {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.chat-msg:hover .chat-msg-actions { opacity: 1; }

.msg-action-btn {
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
  background: rgba(107, 63, 160, 0.1);
  border: 1px solid rgba(107, 63, 160, 0.2);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.msg-action-btn:hover {
  color: var(--color-lime);
  border-color: rgba(178, 212, 48, 0.3);
  background: rgba(178, 212, 48, 0.1);
}

.chat-msg-time {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
  padding: 0 var(--space-sm);
}

/* ── Typing Indicator ───────────────────────────────────────── */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: var(--space-md) var(--space-lg);
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-purple);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Chat Input Area ────────────────────────────────────────── */
.chat-input-area {
  margin-top: auto;
}

.chat-input-wrapper {
  display: flex;
  gap: var(--space-sm);
  background: rgba(13, 13, 26, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-input-wrapper:focus-within {
  border-color: var(--color-lime);
  box-shadow: 0 0 0 2px rgba(178, 212, 48, 0.15);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.9rem;
  padding: var(--space-sm) var(--space-md);
  resize: none;
  line-height: 1.5;
  max-height: 150px;
  overflow-y: auto;
}

.chat-input:focus { outline: none; }
.chat-input::placeholder { color: var(--text-muted); }

.chat-send-btn {
  align-self: flex-end;
  width: 42px;
  height: 42px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

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

/* ── Chat Input Meta ────────────────────────────────────────── */
.chat-input-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-char-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

.chat-meta-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.agent-indicator {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  background: rgba(107, 63, 160, 0.1);
  border-radius: 100px;
  color: var(--color-lime);
}

.chat-clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.75rem;
  cursor: pointer;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.chat-clear-btn:hover {
  color: var(--color-red);
  background: rgba(230, 57, 70, 0.1);
}

/* ── Error Message ──────────────────────────────────────────── */
.chat-msg--error .chat-msg-bubble {
  background: rgba(230, 57, 70, 0.1);
  border-color: rgba(230, 57, 70, 0.4);
  color: var(--color-red);
}

/* ── Local Dev Notice ───────────────────────────────────────── */
.chat-msg--local .chat-msg-bubble {
  background: rgba(247, 147, 30, 0.1);
  border-color: rgba(247, 147, 30, 0.3);
}

/* ── Active Nav Link ────────────────────────────────────────── */
.nav-link--active { color: var(--color-lime) !important; }

/* .logo-link moved to style.css */

/* ── Saved Conversations List (Load Modal) ──────────────────── */
.saved-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  max-height: 300px;
  overflow-y: auto;
  padding: var(--space-sm);
}

.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background: rgba(107, 63, 160, 0.08);
  border: 1px solid rgba(107, 63, 160, 0.15);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.saved-item:hover {
  background: rgba(107, 63, 160, 0.18);
  border-color: rgba(178, 212, 48, 0.3);
}

.saved-item-info {
  display: flex;
  flex-direction: column;
}

.saved-item-title {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 600;
}

.saved-item-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.saved-item-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem;
  transition: color var(--transition-fast);
}

.saved-item-delete:hover { color: var(--color-red); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .agent-sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100vh;
    z-index: 500;
    border-radius: 0;
    border-left: none;
    border-right: 1px solid var(--border-color);
    background: rgba(13, 13, 26, 0.98);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    transition: left var(--transition-med);
  }

  .agent-sidebar.is-open {
    left: 0;
  }

  #btn-toggle-sidebar-mobile { display: flex; }
}

@media (max-width: 768px) {
  .chat-messages {
    max-height: 40vh;
  }

  .chat-msg-content {
    max-width: 85%;
  }

  .chat-msg-bubble {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.85rem;
  }

  .suggested-prompts {
    gap: 4px;
  }

  .prompt-chip {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }
}

/* ══ Torch-in-the-Dark — Chat-specific glow effects ══════════ */
.agent-card:hover {
  box-shadow: 0 0 15px rgba(107, 63, 160, 0.2);
  text-shadow: 0 0 6px rgba(178, 212, 48, 0.2);
}
.agent-card--active {
  box-shadow: 0 0 12px rgba(178, 212, 48, 0.15);
}
.prompt-chip:hover {
  box-shadow: 0 0 12px rgba(107, 63, 160, 0.3);
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.3);
}
.chat-send-btn:not(:disabled):hover {
  box-shadow: 0 0 18px rgba(178, 212, 48, 0.4);
  text-shadow: 0 0 6px rgba(178, 212, 48, 0.6);
}
.msg-action-btn:hover {
  box-shadow: 0 0 8px rgba(107, 63, 160, 0.3);
}
