/* ============================================
   Unified AI Chat Component Styles
   Consistent styling across all pages
   ============================================ */

/* ============================================
   Main Container
   ============================================ */

.ai-chat-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg, 1.5rem);
  height: 100%;
  background: var(--color-bg-elevated, #ffffff) !important;
  border-radius: var(--radius-xl, 12px);
  padding: var(--space-xl, 2rem);
  border: 1px solid var(--color-border, #e5e7eb);
  color: var(--color-text, #1f2937) !important;
}

/* ============================================
   Example Prompts Section
   ============================================ */

.ai-example-prompts {
  margin-bottom: var(--space-md, 1rem);
}

.ai-example-prompts h4 {
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: var(--font-weight-semibold, 600);
  color: var(--color-text-secondary, #6b7280) !important;
  margin-bottom: var(--space-sm, 0.75rem);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ai-prompt-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm, 0.75rem);
}

.ai-prompt-btn {
  padding: var(--space-sm, 0.75rem) var(--space-md, 1rem);
  background: linear-gradient(
    135deg,
    rgba(102, 126, 234, 0.1) 0%,
    rgba(118, 75, 162, 0.1) 100%
  );
  border: 1px solid rgba(102, 126, 234, 0.3);
  border-radius: var(--radius-lg, 8px);
  color: var(--color-text, #1f2937) !important;
  font-size: var(--font-size-sm, 0.875rem);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.ai-prompt-btn:hover {
  background: linear-gradient(
    135deg,
    rgba(102, 126, 234, 0.15) 0%,
    rgba(118, 75, 162, 0.15) 100%
  );
  border-color: rgba(102, 126, 234, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.ai-prompt-btn:active {
  transform: translateY(0);
}

/* ============================================
   Question Counter - Brand Purple Theme (WCAG AA Compliant)
   ============================================ */

.ai-question-counter {
  padding: var(--space-md, 1rem) var(--space-lg, 1.5rem);
  background: linear-gradient(135deg, #4c1d95 0%, #5b21b6 100%);
  border: 1px solid rgba(91, 33, 182, 0.6);
  border-radius: var(--radius-lg, 8px);
  margin-bottom: var(--space-md, 1rem);
  transition: all 0.3s ease;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(76, 29, 149, 0.35);
}

.ai-question-counter .counter-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm, 0.75rem);
}

.ai-question-counter .counter-icon {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
  color: #ffffff !important;
}

.ai-question-counter .counter-text {
  color: #ffffff !important;
  font-size: var(--font-size-sm, 0.875rem);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-question-counter .counter-text strong {
  color: #ffffff !important;
  font-weight: var(--font-weight-bold, 700);
}

/* Warning state - 1 question remaining (dark amber for contrast) */
.ai-question-counter.warning {
  background: linear-gradient(135deg, #92400e 0%, #b45309 100%);
  border-color: rgba(146, 64, 14, 0.7);
  box-shadow: 0 4px 12px rgba(180, 83, 9, 0.4);
  animation: pulse-warning 2s ease-in-out infinite;
}

.ai-question-counter.warning .counter-icon,
.ai-question-counter.warning .counter-text,
.ai-question-counter.warning .counter-text strong {
  color: #ffffff !important;
}

/* Danger state - no questions remaining (dark red for contrast) */
.ai-question-counter.danger {
  background: linear-gradient(135deg, #991b1b 0%, #b91c1c 100%);
  border-color: rgba(153, 27, 27, 0.7);
  box-shadow: 0 4px 12px rgba(185, 28, 28, 0.4);
}

.ai-question-counter.danger .counter-icon,
.ai-question-counter.danger .counter-text,
.ai-question-counter.danger .counter-text strong {
  color: #ffffff !important;
}

@keyframes pulse-warning {
  0%,
  100% {
    box-shadow: 0 4px 12px rgba(180, 83, 9, 0.4);
  }
  50% {
    box-shadow: 0 4px 16px rgba(180, 83, 9, 0.7), 0 0 0 4px rgba(180, 83, 9, 0.25);
  }
}

/* ============================================
   Messages Container
   ============================================ */

.ai-chat-messages-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-bg, #f9fafb) !important;
  border-radius: var(--radius-lg, 8px);
  border: 1px solid var(--color-border, #e5e7eb);
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg, 1.5rem);
  display: flex;
  flex-direction: column;
  gap: var(--space-md, 1rem);
  scroll-behavior: smooth;
}

/* Custom scrollbar */
.ai-chat-messages::-webkit-scrollbar {
  width: 8px;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.3);
  border-radius: 4px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.5);
}

/* ============================================
   Individual Messages
   ============================================ */

.ai-chat-message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: messageSlideIn 0.3s ease;
}

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

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

.ai-chat-message.assistant {
  align-self: flex-start;
}

.ai-message-content {
  padding: var(--space-md, 1rem) var(--space-lg, 1.5rem);
  border-radius: var(--radius-lg, 8px);
  font-size: var(--font-size-base, 1rem);
  line-height: var(--line-height-relaxed, 1.6);
}

.ai-chat-message.user .ai-message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-chat-message.assistant .ai-message-content {
  background: var(--color-bg-elevated, #ffffff);
  color: var(--color-text, #1f2937);
  border: 1px solid var(--color-border, #e5e7eb);
  border-bottom-left-radius: 4px;
}

.ai-chat-message.error .ai-message-content {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #dc2626;
}

.ai-message-content p {
  margin: 0;
  word-wrap: break-word;
}

.ai-message-time {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--color-text-tertiary, #9ca3af);
  margin-top: var(--space-xs, 0.5rem);
  padding: 0 var(--space-sm, 0.75rem);
}

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

/* ============================================
   Loading Indicator
   ============================================ */

.ai-chat-loading {
  padding: var(--space-lg, 1.5rem);
  display: flex;
  align-items: center;
  gap: var(--space-md, 1rem);
  background: var(--color-bg-elevated, #ffffff);
  border-top: 1px solid var(--color-border, #e5e7eb);
}

.ai-typing-indicator {
  display: flex;
  gap: 4px;
}

.ai-typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  animation: typingDot 1.4s ease-in-out infinite;
}

.ai-typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

.ai-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingDot {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.7;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

.ai-chat-loading p {
  margin: 0;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--color-text-secondary, #6b7280);
}

/* ============================================
   Input Form
   ============================================ */

.ai-chat-input-form {
  margin-top: var(--space-md, 1rem);
}

.ai-chat-input-group {
  display: flex;
  gap: var(--space-sm, 0.75rem);
  align-items: stretch;
}

.ai-chat-input {
  flex: 1;
  padding: var(--space-md, 1rem) var(--space-lg, 1.5rem);
  border: 2px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-lg, 8px);
  font-size: var(--font-size-base, 1rem);
  font-family: inherit;
  color: var(--color-text, #1f2937);
  background: var(--color-bg-elevated, #ffffff);
  transition: all 0.2s ease;
}

.ai-chat-input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.ai-chat-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--color-bg, #f9fafb);
}

.ai-chat-input::placeholder {
  color: var(--color-text-tertiary, #9ca3af);
}

.ai-chat-submit {
  padding: var(--space-md, 1rem) var(--space-lg, 1.5rem);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: var(--radius-lg, 8px);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
}

.ai-chat-submit:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(102, 126, 234, 0.3);
}

.ai-chat-submit:active:not(:disabled) {
  transform: translateY(0);
}

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

.ai-chat-submit svg {
  width: 20px;
  height: 20px;
}

/* ============================================
   Empty State
   ============================================ */

.ai-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-3xl, 3rem);
  text-align: center;
  color: var(--color-text-secondary, #6b7280);
}

.ai-chat-empty svg {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-lg, 1.5rem);
  opacity: 0.5;
}

.ai-chat-empty h3 {
  font-size: var(--font-size-lg, 1.125rem);
  margin-bottom: var(--space-sm, 0.75rem);
  color: var(--color-text, #1f2937);
}

.ai-chat-empty p {
  font-size: var(--font-size-base, 1rem);
  max-width: 400px;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
  .ai-chat-wrapper {
    padding: var(--space-lg, 1.5rem);
  }

  .ai-chat-message {
    max-width: 90%;
  }

  .ai-prompt-buttons {
    flex-direction: column;
  }

  .ai-prompt-btn {
    width: 100%;
  }

  .ai-chat-input-group {
    flex-direction: row;
  }

  .ai-chat-input {
    font-size: var(--font-size-sm, 0.875rem);
    padding: var(--space-sm, 0.75rem) var(--space-md, 1rem);
  }

  .ai-chat-submit {
    min-width: 48px;
    padding: var(--space-sm, 0.75rem);
  }
}

@media (max-width: 480px) {
  .ai-chat-wrapper {
    padding: var(--space-md, 1rem);
  }

  .ai-chat-messages {
    padding: var(--space-md, 1rem);
  }

  .ai-example-prompts h4 {
    font-size: var(--font-size-xs, 0.75rem);
  }

  .ai-message-content {
    font-size: var(--font-size-sm, 0.875rem);
    padding: var(--space-sm, 0.75rem) var(--space-md, 1rem);
  }
}

/* ============================================
   Dark Mode Support (using data-theme attribute)
   ============================================ */

/* Dark mode using data-theme attribute for manual toggle */
[data-theme="dark"] .ai-chat-wrapper {
  background: #1f2937 !important;
  border-color: #374151 !important;
  color: #f9fafb !important;
}

[data-theme="dark"] .ai-chat-messages-wrapper {
  background: #111827 !important;
  border-color: #374151 !important;
}

[data-theme="dark"] .ai-example-prompts h4 {
  color: #9ca3af !important;
}

[data-theme="dark"] .ai-prompt-btn {
  color: #f9fafb !important;
  background: linear-gradient(
    135deg,
    rgba(102, 126, 234, 0.2) 0%,
    rgba(118, 75, 162, 0.2) 100%
  );
  border-color: rgba(102, 126, 234, 0.4);
}

[data-theme="dark"] .ai-chat-message.assistant .ai-message-content {
  background: #1f2937 !important;
  border-color: #374151 !important;
  color: #f9fafb !important;
}

[data-theme="dark"] .ai-chat-input {
  background: #1f2937 !important;
  border-color: #374151 !important;
  color: #f9fafb !important;
}

[data-theme="dark"] .ai-chat-input::placeholder {
  color: #6b7280 !important;
}

[data-theme="dark"] .ai-chat-input:focus {
  border-color: #667eea !important;
}

[data-theme="dark"] .ai-chat-loading {
  background: #1f2937 !important;
  border-color: #374151 !important;
}

[data-theme="dark"] .ai-chat-loading p {
  color: #9ca3af !important;
}

[data-theme="dark"] .ai-chat-empty h3 {
  color: #f9fafb !important;
}

[data-theme="dark"] .ai-chat-empty p {
  color: #9ca3af !important;
}

/* AI Question Counter - Dark mode (slightly lighter purple for dark backgrounds, still WCAG compliant) */
[data-theme="dark"] .ai-question-counter {
  background: linear-gradient(135deg, #5b21b6 0%, #6d28d9 100%) !important;
  border-color: rgba(109, 40, 217, 0.7) !important;
  box-shadow: 0 4px 16px rgba(91, 33, 182, 0.5) !important;
}

[data-theme="dark"] .ai-question-counter .counter-content,
[data-theme="dark"] .ai-question-counter .counter-icon,
[data-theme="dark"] .ai-question-counter .counter-text,
[data-theme="dark"] .ai-question-counter .counter-text strong {
  color: #ffffff !important;
}

[data-theme="dark"] .ai-question-counter.warning {
  background: linear-gradient(135deg, #b45309 0%, #d97706 100%) !important;
  border-color: rgba(180, 83, 9, 0.7) !important;
  box-shadow: 0 4px 16px rgba(217, 119, 6, 0.5) !important;
}

[data-theme="dark"] .ai-question-counter.warning .counter-icon,
[data-theme="dark"] .ai-question-counter.warning .counter-text,
[data-theme="dark"] .ai-question-counter.warning .counter-text strong {
  color: #ffffff !important;
}

[data-theme="dark"] .ai-question-counter.danger {
  background: linear-gradient(135deg, #b91c1c 0%, #dc2626 100%) !important;
  border-color: rgba(185, 28, 28, 0.7) !important;
  box-shadow: 0 4px 16px rgba(220, 38, 38, 0.5) !important;
}

[data-theme="dark"] .ai-question-counter.danger .counter-icon,
[data-theme="dark"] .ai-question-counter.danger .counter-text,
[data-theme="dark"] .ai-question-counter.danger .counter-text strong {
  color: #ffffff !important;
}

/* Also support prefers-color-scheme for system preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ai-chat-wrapper {
    background: #1f2937;
    border-color: #374151;
  }

  :root:not([data-theme="light"]) .ai-chat-messages-wrapper {
    background: #111827;
    border-color: #374151;
  }

  :root:not([data-theme="light"]) .ai-chat-message.assistant .ai-message-content {
    background: #1f2937;
    border-color: #374151;
    color: #f9fafb;
  }

  :root:not([data-theme="light"]) .ai-chat-input {
    background: #1f2937;
    border-color: #374151;
    color: #f9fafb;
  }

  :root:not([data-theme="light"]) .ai-question-counter {
    background: linear-gradient(135deg, #5b21b6 0%, #6d28d9 100%);
    box-shadow: 0 4px 16px rgba(91, 33, 182, 0.5);
  }

  :root:not([data-theme="light"]) .ai-question-counter .counter-content,
  :root:not([data-theme="light"]) .ai-question-counter .counter-icon,
  :root:not([data-theme="light"]) .ai-question-counter .counter-text,
  :root:not([data-theme="light"]) .ai-question-counter .counter-text strong {
    color: #ffffff !important;
  }
}

/* ============================================
   Accessibility
   ============================================ */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus visible for keyboard navigation */
.ai-prompt-btn:focus-visible,
.ai-chat-input:focus-visible,
.ai-chat-submit:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .ai-chat-message,
  .ai-prompt-btn,
  .ai-chat-submit,
  .ai-typing-indicator span {
    animation: none;
    transition: none;
  }
}
