* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  overflow-x: hidden;
}

/* CSS Custom Properties for theming */
:root {
  --bg-page: #f5f5f5;
  --bg-container: white;
  --bg-messages: #fafafa;
  --bg-assistant: white;
  --bg-input: white;
  --bg-loading: #f0f0f0;
  --text-primary: #2d2d2d;
  --text-secondary: #666;
  --text-muted: #888;
  --border-color: #e0e0e0;
  --border-light: #e8e8e8;
  --border-input: #ddd;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --prompt-bg: white;
  --feedback-bg: transparent;
  --user-avatar-bg: #e0e0e0;
}

[data-theme="dark"] {
  --bg-page: #1a1a2e;
  --bg-container: #16213e;
  --bg-messages: #1a1a2e;
  --bg-assistant: #0f3460;
  --bg-input: #16213e;
  --bg-loading: #0f3460;
  --text-primary: #e8e8e8;
  --text-secondary: #b0b0b0;
  --text-muted: #888;
  --border-color: #2a2a4a;
  --border-light: #2a2a4a;
  --border-input: #3a3a5a;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --prompt-bg: #0f3460;
  --feedback-bg: #0f3460;
  --user-avatar-bg: #3a3a5a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-page);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  transition: background 0.3s;
}

.chat-container {
  width: 100%;
  max-width: 600px;
  height: 90vh;
  max-height: 800px;
  background: var(--bg-container);
  border-radius: 12px;
  box-shadow: 0 4px 20px var(--shadow-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.3s, box-shadow 0.3s;
}

.chat-header {
  background: linear-gradient(135deg, #4d1979 0%, #6b2a9e 100%);
  color: white;
  padding: 0.875rem 1.25rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.header-logo {
  height: 36px;
  width: auto;
  max-width: 60%;
  opacity: 0.95;
}

.header-actions {
  display: flex;
  gap: 0.375rem;
  align-items: center;
  flex-shrink: 0;
}

.header-info h1 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.header-info p {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-top: 0.125rem;
}

#clear-btn {
  padding: 0.4rem 1rem;
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
}

#clear-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

#theme-toggle {
  width: 36px;
  height: 28px;
  padding: 0;
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#theme-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

#theme-toggle .sun-icon {
  display: block;
}

#theme-toggle .moon-icon {
  display: none;
}

[data-theme="dark"] #theme-toggle .sun-icon {
  display: none;
}

[data-theme="dark"] #theme-toggle .moon-icon {
  display: block;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--bg-messages);
  transition: background 0.3s;
}

.message {
  max-width: 85%;
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
  min-width: 0;
}

.message .avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.assistant-avatar {
  background: linear-gradient(135deg, #4d1979 0%, #6b2a9e 100%);
  background-image: url('images/addran-wordmark.svg');
  background-size: 80%;
  background-position: center;
  background-repeat: no-repeat;
}

.user-avatar {
  background-color: var(--user-avatar-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23666'%3E%3Cpath d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E");
  background-size: 60%;
  background-position: center;
  background-repeat: no-repeat;
}

[data-theme="dark"] .user-avatar {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23aaa'%3E%3Cpath d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E");
}

.message-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.message-content {
  padding: 0.875rem 1.125rem;
  border-radius: 18px;
  line-height: 1.6;
  font-size: 0.9375rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
}

.message-timestamp {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  padding: 0 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.message:hover .message-timestamp {
  opacity: 1;
}

.message.user .message-timestamp {
  text-align: right;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.user .message-content {
  background: linear-gradient(135deg, #4d1979 0%, #6b2a9e 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
  background: var(--bg-assistant);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-light);
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}

.message.loading .message-content {
  color: var(--text-muted);
  background: var(--bg-loading);
  border: none;
}

/* Typing animation */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Suggested prompts */
.suggested-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.prompt-chip {
  background: var(--prompt-bg);
  border: 1px solid #4d1979;
  color: #4d1979;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s;
}

[data-theme="dark"] .prompt-chip {
  border-color: #9b59b6;
  color: #d4a5ff;
}

.prompt-chip:hover {
  background: #4d1979;
  color: white;
}

[data-theme="dark"] .prompt-chip:hover {
  background: #9b59b6;
}

.message-content a {
  color: #4d1979;
  text-decoration: underline;
  text-underline-offset: 2px;
}

[data-theme="dark"] .message.assistant .message-content a {
  color: #d4a5ff;
}

.message.user .message-content a {
  color: #e0d0f0;
}

.message-content p {
  margin-bottom: 0.75rem;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content ul {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.message-content li {
  margin-bottom: 0.4rem;
}

.message-content strong {
  font-weight: 600;
}

#export-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4rem 0.75rem;
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

#export-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

#export-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.disclaimer {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.5rem 1rem 0;
  line-height: 1.3;
}

.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: #d32f2f;
  color: white;
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  font-size: 0.875rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.chat-input {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-input);
  transition: background 0.3s, border-color 0.3s;
}

.chat-input input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-input);
  border-radius: 24px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, background 0.3s, color 0.3s;
  background: var(--bg-container);
  color: var(--text-primary);
}

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

.chat-input input:focus {
  border-color: #4d1979;
}

[data-theme="dark"] .chat-input input:focus {
  border-color: #9b59b6;
}

.chat-input button {
  width: 44px;
  height: 44px;
  padding: 0;
  background: #4d1979;
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input button:hover {
  background: #3a1259;
  transform: scale(1.05);
}

.chat-input button:disabled {
  background: #999;
  cursor: not-allowed;
  transform: none;
}

/* Feedback buttons */
.feedback-buttons {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.feedback-btn {
  background: var(--feedback-bg);
  border: 1px solid var(--border-input);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.feedback-btn:hover:not(:disabled) {
  border-color: #4d1979;
  color: #4d1979;
}

[data-theme="dark"] .feedback-btn:hover:not(:disabled) {
  border-color: #9b59b6;
  color: #d4a5ff;
}

.feedback-btn:disabled {
  cursor: default;
  opacity: 0.6;
}

.feedback-btn.selected[data-rating="positive"] {
  background: #e8f5e9;
  border-color: #4caf50;
  color: #4caf50;
}

.feedback-btn.selected[data-rating="negative"] {
  background: #ffebee;
  border-color: #f44336;
  color: #f44336;
}

.feedback-buttons.submitted {
  opacity: 0.7;
}

/* Program cards */
.program-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.program-card {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-container);
  transition: box-shadow 0.2s, border-color 0.2s;
}

.program-card:hover {
  border-color: #4d1979;
  box-shadow: 0 2px 8px var(--shadow-color);
}

[data-theme="dark"] .program-card:hover {
  border-color: #9b59b6;
}

.program-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.program-card-title {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.program-card-title strong {
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.program-card-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.program-card-chevron {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.25s ease;
}

.program-card.expanded .program-card-chevron {
  transform: rotate(180deg);
}

.program-card-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  padding: 0 1rem;
}

.program-card.expanded .program-card-body {
  max-height: 600px;
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border-light);
}

.program-card-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0.75rem 0;
}

.program-card-section {
  margin-top: 0.75rem;
}

.program-card-section h4 {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.program-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.program-card-tag {
  font-size: 0.75rem;
  padding: 0.2rem 0.625rem;
  border-radius: 12px;
  background: var(--bg-messages);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

.program-card-body ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.program-card-body li {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  padding: 0.25rem 0;
}

.program-card-body li a {
  color: #4d1979;
  text-decoration: none;
}

.program-card-body li a:hover {
  text-decoration: underline;
}

[data-theme="dark"] .program-card-body li a {
  color: #d4a5ff;
}

.program-card-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #4d1979;
  text-decoration: none;
}

.program-card-link:hover {
  text-decoration: underline;
}

[data-theme="dark"] .program-card-link {
  color: #d4a5ff;
}

@media (max-width: 480px) {
  body {
    padding: 0;
  }

  .chat-container {
    height: 100vh;
    max-height: none;
    border-radius: 0;
    width: 100vw;
    max-width: 100vw;
  }

  .chat-header {
    padding: 0.75rem 1rem;
  }

  .header-logo {
    height: 30px;
  }

  .header-info h1 {
    font-size: 1rem;
  }

  .header-info p {
    font-size: 0.6875rem;
  }

  .chat-messages {
    padding: 1rem;
  }

  .message {
    max-width: 90%;
  }

  .message-content {
    padding: 0.75rem 1rem;
  }

  .chat-input {
    padding: 0.75rem;
  }

  .chat-input input {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  #export-btn .export-label {
    display: none;
  }

  #export-btn {
    padding: 0.4rem 0.5rem;
  }

  .suggested-prompts {
    gap: 0.375rem;
  }

  .prompt-chip {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
  }

  .program-card-header {
    padding: 0.625rem 0.75rem;
  }

  .program-card.expanded .program-card-body {
    padding: 0 0.75rem 0.75rem;
  }

  .program-card-tags {
    gap: 0.25rem;
  }

  .program-card-tag {
    font-size: 0.6875rem;
    padding: 0.15rem 0.5rem;
  }
}

/* Embed mode — when loaded inside a wizard iframe */
body.embed-mode {
  padding: 0;
  background: var(--bg-container);
  align-items: stretch;
}

body.embed-mode .chat-container {
  max-width: 100%;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  box-shadow: none;
}

body.embed-mode .chat-header {
  display: none;
}

body.embed-mode .disclaimer {
  display: none;
}
