/* ─── AI Chat Engine — CyberStackHub ───────────────────────────────────────── */

.ai-chat-wrapper {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 24px rgba(0,0,0,0.07);
  overflow: hidden;
  margin: 0 auto 2rem;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  min-height: 520px;
}

/* Header */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #fff;
  gap: 0.75rem;
}

.ai-chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ai-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.ai-chat-header-info h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #f1f5f9;
}

.ai-chat-header-info p {
  margin: 0;
  font-size: 0.75rem;
  color: #94a3b8;
}

.ai-chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  margin-right: 4px;
  animation: ai-pulse 2s infinite;
}

@keyframes ai-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.ai-chat-switch-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #94a3b8;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.ai-chat-switch-btn:hover {
  background: rgba(255,255,255,0.14);
  color: #e2e8f0;
}

/* Messages area */
.ai-chat-messages {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 360px;
  max-height: 420px;
  background: #f8fafc;
}

/* Scrollbar */
.ai-chat-messages::-webkit-scrollbar {
  width: 4px;
}
.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 2px;
}

/* Message bubbles */
.ai-chat-msg {
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
  animation: ai-msg-in 0.2s ease;
}

@keyframes ai-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-chat-msg.ai {
  align-self: flex-start;
  max-width: 85%;
}

.ai-chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
  max-width: 75%;
}

.ai-chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.ai-chat-msg.ai .ai-chat-msg-avatar {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
}

.ai-chat-msg.user .ai-chat-msg-avatar {
  background: #e2e8f0;
  color: #64748b;
}

.ai-chat-bubble {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.55;
  word-break: break-word;
}

.ai-chat-msg.ai .ai-chat-bubble {
  background: #fff;
  color: #1e293b;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.ai-chat-msg.user .ai-chat-bubble {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.ai-chat-typing {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  align-self: flex-start;
  animation: ai-msg-in 0.2s ease;
}

.ai-chat-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  background: #fff;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.ai-chat-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: ai-typing 1.2s infinite;
}

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

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

/* Extraction card */
.ai-chat-extraction {
  background: #fff;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.125rem;
  align-self: flex-start;
  max-width: 90%;
  animation: ai-msg-in 0.25s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.ai-chat-extraction-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.875rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #1e293b;
}

.ai-chat-extraction-header .check-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.ai-chat-extraction-fields {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}

.ai-chat-field-row {
  display: flex;
  gap: 0.5rem;
  font-size: 0.8rem;
  line-height: 1.4;
}

.ai-chat-field-key {
  color: #64748b;
  min-width: 140px;
  font-weight: 500;
  flex-shrink: 0;
}

.ai-chat-field-val {
  color: #1e293b;
}

.ai-chat-extraction-actions {
  display: flex;
  gap: 0.625rem;
  flex-wrap: wrap;
}

.ai-chat-confirm-btn {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  border: none;
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.ai-chat-confirm-btn:hover {
  opacity: 0.9;
}

.ai-chat-confirm-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ai-chat-edit-btn {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
  padding: 0.625rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.ai-chat-edit-btn:hover {
  background: #e2e8f0;
}

/* Input area */
.ai-chat-input-area {
  padding: 1rem 1.25rem;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
}

.ai-chat-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  color: #1e293b;
  resize: none;
  outline: none;
  font-family: inherit;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.15s ease;
  background: #f8fafc;
  line-height: 1.5;
}

.ai-chat-input:focus {
  border-color: #3b82f6;
  background: #fff;
}

.ai-chat-input::placeholder {
  color: #94a3b8;
}

.ai-chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.ai-chat-send-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: scale(1.04);
}

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

.ai-chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Form toggle section */
.ai-chat-form-toggle {
  text-align: center;
  padding: 0.75rem 0 0.25rem;
}

.ai-chat-form-toggle-link {
  font-size: 0.8rem;
  color: #64748b;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}

.ai-chat-form-toggle-link:hover {
  color: #3b82f6;
}

/* Error message */
.ai-chat-error-msg {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  border-radius: 8px;
  padding: 0.625rem 0.875rem;
  font-size: 0.82rem;
  align-self: flex-start;
  max-width: 85%;
  animation: ai-msg-in 0.2s ease;
}

/* Generating state */
.ai-chat-generating {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  background: linear-gradient(135deg, #eff6ff, #f0fdf4);
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  font-size: 0.85rem;
  color: #1d4ed8;
  align-self: stretch;
  animation: ai-msg-in 0.2s ease;
}

.ai-chat-generating-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #bfdbfe;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: ai-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes ai-spin {
  to { transform: rotate(360deg); }
}

/* Disabled input overlay */
.ai-chat-input-area.disabled .ai-chat-input {
  opacity: 0.5;
  pointer-events: none;
}
.ai-chat-input-area.disabled .ai-chat-send-btn {
  opacity: 0.35;
  pointer-events: none;
}

/* Quick reply chips */
.ai-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0 1.25rem 0.75rem;
}

.ai-chat-chip {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  padding: 0.3rem 0.75rem;
  border-radius: 100px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.ai-chat-chip:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

/* Mobile responsive */
@media (max-width: 640px) {
  .ai-chat-wrapper {
    border-radius: 12px;
    min-height: 440px;
  }

  .ai-chat-messages {
    max-height: 340px;
    padding: 1rem;
  }

  .ai-chat-field-key {
    min-width: 110px;
  }

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

  .ai-chat-msg.ai {
    max-width: 92%;
  }

  .ai-chat-switch-btn {
    display: none;
  }
}
