/* ========================================================================== */
/* AI Chat Agent Drawer & Widget Styles - Trader to Trader                      */
/* High-End Dark Terminal & Glassmorphism Aesthetic                          */
/* ========================================================================== */

.ai-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.ai-chat-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.ai-chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 95vw;
  background: #090d16;
  border-left: 1px solid rgba(56, 189, 248, 0.25);
  box-shadow: -10px 0 35px rgba(0, 0, 0, 0.85);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: var(--font-mono, ui-monospace, monospace);
  color: #f1f5f9;
}

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

/* Header */
.ai-chat-header {
  padding: 14px 18px;
  background: rgba(15, 23, 42, 0.85);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ai-chat-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.ai-chat-title-wrap {
  display: flex;
  flex-direction: column;
}

.ai-chat-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-chat-status {
  font-size: 10px;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

.ai-chat-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  animation: aiPulse 2s infinite;
}

@keyframes aiPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.ai-chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chat-btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-chat-btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #f1f5f9;
  border-color: rgba(255, 255, 255, 0.2);
}

.ai-chat-btn-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s;
}

.ai-chat-btn-close:hover {
  color: #ef4444;
}

/* Quick Prompt Suggestions */
.ai-chat-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  background: rgba(10, 15, 29, 0.6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.ai-chat-chips::-webkit-scrollbar {
  display: none;
}

.ai-chip {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: #bae6fd;
  font-size: 10px;
  padding: 4px 9px;
  border-radius: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ai-chip:hover {
  background: rgba(56, 189, 248, 0.2);
  border-color: #38bdf8;
  color: #fff;
  transform: translateY(-1px);
}

/* Message Scroll Area */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 90%;
  animation: aiMsgIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.ai-msg.user {
  align-self: flex-end;
}

.ai-msg.user .ai-msg-bubble {
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.3), rgba(14, 165, 233, 0.2));
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #f0f9ff;
  border-bottom-right-radius: 2px;
}

.ai-msg.assistant {
  align-self: flex-start;
  max-width: 96%;
}

.ai-msg.assistant .ai-msg-bubble {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  border-bottom-left-radius: 2px;
}

.ai-msg-bubble {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 11.5px;
  line-height: 1.55;
  word-break: break-word;
}

.ai-msg-time {
  font-size: 8.5px;
  color: #64748b;
  margin-top: 3px;
  padding: 0 4px;
}

.ai-msg.user .ai-msg-time {
  text-align: right;
}

/* Markdown formatting inside assistant bubble */
.ai-msg-bubble h3 {
  font-size: 12px;
  font-weight: 800;
  color: #38bdf8;
  margin: 10px 0 4px 0;
  border-bottom: 1px solid rgba(56, 189, 248, 0.2);
  padding-bottom: 2px;
}

.ai-msg-bubble h3:first-child {
  margin-top: 0;
}

.ai-msg-bubble p {
  margin: 4px 0;
}

.ai-msg-bubble strong {
  color: #fff;
  font-weight: 700;
}

.ai-msg-bubble ul {
  margin: 4px 0 6px 16px;
  padding: 0;
}

.ai-msg-bubble li {
  margin-bottom: 3px;
}

.ai-msg-bubble hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin: 8px 0;
}

/* Thinking Indicator */
.ai-thinking {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #38bdf8;
  font-size: 11px;
}

.ai-dot-bounce {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #38bdf8;
  animation: aiDotBounce 1.2s infinite ease-in-out both;
}

.ai-dot-bounce:nth-child(1) { animation-delay: -0.32s; }
.ai-dot-bounce:nth-child(2) { animation-delay: -0.16s; }
.ai-dot-bounce:nth-child(3) { animation-delay: 0s; }

@keyframes aiDotBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

/* Footer / Input Area */
.ai-chat-footer {
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.9);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.ai-chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: rgba(10, 15, 29, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 8px;
  padding: 6px 10px;
  transition: border-color 0.15s;
}

.ai-chat-input-bar:focus-within {
  border-color: #38bdf8;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.2);
}

.ai-chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.4;
  resize: none;
  max-height: 100px;
  min-height: 24px;
}

.ai-chat-input::placeholder {
  color: #64748b;
}

.ai-chat-send-btn {
  background: #0284c7;
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.ai-chat-send-btn:hover {
  background: #38bdf8;
  transform: scale(1.04);
}

.ai-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.ai-chat-hint {
  font-size: 9px;
  color: #64748b;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2px;
}

/* Light Theme Overrides */
body.theme-light .ai-chat-drawer {
  background: #f8fafc;
  color: #0f172a;
  border-left-color: #cbd5e1;
}

body.theme-light .ai-chat-header {
  background: #ffffff;
  border-bottom-color: #e2e8f0;
}

body.theme-light .ai-chat-title {
  color: #0f172a;
}

body.theme-light .ai-chat-chips {
  background: #f1f5f9;
  border-bottom-color: #e2e8f0;
}

body.theme-light .ai-chip {
  background: rgba(2, 132, 199, 0.1);
  color: #0369a1;
  border-color: rgba(2, 132, 199, 0.25);
}

body.theme-light .ai-msg.assistant .ai-msg-bubble {
  background: #ffffff;
  border-color: #e2e8f0;
  color: #1e293b;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

body.theme-light .ai-msg.user .ai-msg-bubble {
  background: #0284c7;
  color: #ffffff;
}

body.theme-light .ai-chat-footer {
  background: #ffffff;
  border-top-color: #e2e8f0;
}

body.theme-light .ai-chat-input-bar {
  background: #f8fafc;
  border-color: #cbd5e1;
}

body.theme-light .ai-chat-input {
  color: #0f172a;
}
