/* AI course assistant widget styling */
:root {
  --ait-primary: #1e40af;
  --ait-primary-light: #3b82f6;
  --ait-primary-dark: #1e3a8a;
  --ait-secondary: #f59e0b;
  --ait-success: #10b981;
  --ait-danger: #ef4444;
  --ait-gray-50: #f9fafb;
  --ait-gray-100: #f3f4f6;
  --ait-gray-200: #e5e7eb;
  --ait-gray-300: #d1d5db;
  --ait-gray-400: #9ca3af;
  --ait-gray-500: #6b7280;
  --ait-gray-600: #4b5563;
  --ait-gray-700: #374151;
  --ait-gray-800: #1f2937;
  --ait-gray-900: #111827;
  --ait-text-primary: #111827;
  --ait-text-secondary: #6b7280;
  --ait-border: #e5e7eb;
  --ait-bg: #ffffff;
  --ait-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --ait-primary: #3b82f6;
    --ait-primary-light: #60a5fa;
    --ait-primary-dark: #1e40af;
    --ait-secondary: #fbbf24;
    --ait-gray-50: #0f172a;
    --ait-gray-100: #1e293b;
    --ait-gray-200: #334155;
    --ait-gray-300: #475569;
    --ait-gray-400: #64748b;
    --ait-gray-500: #94a3b8;
    --ait-gray-600: #cbd5e1;
    --ait-gray-700: #e2e8f0;
    --ait-gray-800: #f1f5f9;
    --ait-gray-900: #ffffff;
    --ait-text-primary: #f1f5f9;
    --ait-text-secondary: #94a3b8;
    --ait-border: #334155;
    --ait-bg: #1e293b;
    --ait-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  }
}

#ait-ai-widget {
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
    'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  position: fixed;
  bottom: 20px;
  left: 20px;
  font-family: var(--font-family);
  z-index: 999999;
  user-select: none;
}

/* Chat Toggle Button — a labelled pill, so it reads as the program assistant
   rather than as generic support chat */
.ait-chat-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 52px;
  padding: 0 20px 0 14px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--ait-primary), var(--ait-primary-light));
  color: white;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(30, 64, 175, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ait-toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
}

.ait-toggle-label {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.1px;
}

.ait-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(30, 64, 175, 0.45);
}

.ait-chat-toggle:active {
  transform: translateY(0);
}

/* The panel replaces the launcher rather than sitting on top of it. */
#ait-ai-widget.is-open .ait-chat-toggle {
  display: none;
}

/* Chat Window */
.ait-chat-window {
  position: absolute;
  bottom: 80px;
  left: 0;
  width: 420px;
  max-width: calc(100vw - 40px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--ait-bg);
  border-radius: 12px;
  box-shadow: var(--ait-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 1px solid var(--ait-border);
}

.ait-chat-window.hidden {
  display: none;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

/* Chat Header */
.ait-chat-header {
  background: linear-gradient(135deg, var(--ait-primary), var(--ait-primary-light));
  color: white;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.ait-bot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
}

.ait-chat-title {
  flex: 1;
  min-width: 0;
}

.ait-chat-title h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}

.ait-chat-title p {
  margin: 4px 0 0 0;
  font-size: 12px;
  opacity: 0.9;
  line-height: 1.3;
}

.ait-chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
  flex-shrink: 0;
  margin-left: 12px;
}

.ait-chat-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Messages Container */
.ait-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--ait-gray-50);
}

.ait-message {
  display: flex;
  animation: slideIn 0.3s ease;
}

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

.ait-message-user {
  justify-content: flex-end;
}

.ait-message-assistant {
  justify-content: flex-start;
}

.ait-message-content {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
  word-wrap: break-word;
  font-size: 14px;
  /* The model answers in short emoji-prefixed lines. Without this every newline
     collapses and the reply arrives as one unreadable block of prose. */
  white-space: pre-line;
}

.ait-message-content strong {
  font-weight: 700;
}

.ait-message-user .ait-message-content {
  background: var(--ait-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.ait-message-assistant .ait-message-content {
  background: white;
  color: var(--ait-text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--ait-border);
}

.ait-message-content ul {
  margin: 0;
  padding-left: 20px;
}

.ait-message-content li {
  margin: 4px 0;
}

/* "Finding your answer…" placeholder shown while the model is working */
.ait-message-content.ait-thinking {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ait-text-secondary);
  font-style: italic;
}

.ait-thinking-dots {
  display: inline-flex;
  gap: 3px;
}

.ait-thinking-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ait-primary);
  opacity: 0.35;
  animation: ait-blink 1.3s infinite ease-in-out;
}

.ait-thinking-dots i:nth-child(2) { animation-delay: 0.18s; }
.ait-thinking-dots i:nth-child(3) { animation-delay: 0.36s; }

@keyframes ait-blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .ait-thinking-dots i {
    animation: none;
    opacity: 0.6;
  }
}

/* Follow-up links the assistant ends each answer with */
.ait-quick-links {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  margin: -4px 0 4px 4px;
}

.ait-quick-link {
  background: none;
  border: none;
  padding: 5px 0;
  color: var(--ait-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.ait-quick-link:hover {
  text-decoration: underline;
}

/* Starter chips under the greeting */
.ait-quick-start {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 4px 4px;
}

.ait-quick-start-btn {
  background: var(--ait-bg);
  border: 1px solid var(--ait-border);
  border-radius: 999px;
  padding: 7px 13px;
  color: var(--ait-text-primary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ait-quick-start-btn:hover {
  border-color: var(--ait-primary);
  color: var(--ait-primary);
  transform: translateY(-1px);
}

/* Suggested Actions */
.ait-suggested-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.ait-action-btn {
  background: var(--ait-gray-100);
  border: 1px solid var(--ait-border);
  color: var(--ait-text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.ait-action-btn:hover {
  background: var(--ait-primary-light);
  color: white;
  border-color: var(--ait-primary);
}

/* Input Area */
.ait-chat-input-area {
  padding: 12px;
  background: var(--ait-gray-50);
  border-top: 1px solid var(--ait-border);
  flex-shrink: 0;
}

.ait-chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ait-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--ait-border);
  border-radius: 6px;
  background: var(--ait-bg);
  color: var(--ait-text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.ait-chat-input:focus {
  outline: none;
  border-color: var(--ait-primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.ait-chat-input::placeholder {
  color: var(--ait-text-secondary);
}

.ait-chat-send {
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--ait-primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.ait-chat-send:hover:not(:disabled) {
  background: var(--ait-primary-dark);
  transform: scale(1.05);
}

.ait-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Lead Capture Section — two fields, sits under the input without swallowing the reply */
.ait-lead-section {
  padding: 12px;
  border-top: 1px solid var(--ait-border);
  background: var(--ait-gray-50);
  flex-shrink: 0;
}

.ait-lead-section.hidden {
  display: none;
}

.ait-lead-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.ait-lead-head p {
  flex: 1;
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ait-text-secondary);
}

.ait-lead-dismiss {
  background: none;
  border: none;
  padding: 2px;
  color: var(--ait-text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  border-radius: 4px;
}

.ait-lead-dismiss:hover {
  color: var(--ait-text-primary);
  background: var(--ait-gray-200);
}

.ait-lead-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ait-lead-form input {
  flex: 1 1 140px;
  min-width: 0;
}

.ait-lead-form .ait-lead-submit {
  flex: 0 0 auto;
}

.ait-lead-form input,
.ait-lead-form textarea {
  padding: 10px;
  border: 1px solid var(--ait-border);
  border-radius: 6px;
  background: var(--ait-bg);
  color: var(--ait-text-primary);
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.ait-lead-form input:focus,
.ait-lead-form textarea:focus {
  outline: none;
  border-color: var(--ait-primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.ait-lead-form input::placeholder,
.ait-lead-form textarea::placeholder {
  color: var(--ait-text-secondary);
}

.ait-lead-submit {
  padding: 10px 18px;
  background: var(--ait-primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.ait-lead-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ait-lead-submit:hover {
  background: var(--ait-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}

.ait-lead-submit:active {
  transform: translateY(0);
}

/* Responsive Design */
@media (max-width: 480px) {
  #ait-ai-widget {
    bottom: 0;
    right: 0;
    left: 0;
  }

  .ait-chat-window {
    width: 100%;
    max-width: none;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    bottom: 0;
  }

  .ait-chat-toggle {
    height: 46px;
    padding: 0 16px 0 11px;
    /* Clears the site's own fixed mobile bottom nav bar (~71px) so the two
       don't overlap. Margin, not a shifted container bottom, so the fullscreen
       chat window (below) still reaches the true edge of the viewport. */
    margin-bottom: 78px;
  }

  .ait-toggle-icon {
    width: 28px;
    height: 28px;
  }

  .ait-toggle-label {
    font-size: 13px;
  }

  .ait-message-content {
    max-width: 90%;
  }
}

/* Scrollbar Styling */
.ait-chat-messages::-webkit-scrollbar,
.ait-lead-section::-webkit-scrollbar {
  width: 6px;
}

.ait-chat-messages::-webkit-scrollbar-track,
.ait-lead-section::-webkit-scrollbar-track {
  background: transparent;
}

.ait-chat-messages::-webkit-scrollbar-thumb,
.ait-lead-section::-webkit-scrollbar-thumb {
  background: var(--ait-gray-300);
  border-radius: 3px;
}

.ait-chat-messages::-webkit-scrollbar-thumb:hover,
.ait-lead-section::-webkit-scrollbar-thumb:hover {
  background: var(--ait-gray-400);
}

/* Print Styles */
@media print {
  #ait-ai-widget {
    display: none !important;
  }
}
