/* ============================================
   IAIS Chat Widget
   Brand: dark-green #2e4e42, yellow #ffd800,
          sage #D1E4DD, gray #6c757d, green-gray #484f4c
   Font: inherited from brand.css (Atkinson Hyperlegible)
   ============================================ */

.iais-chat-container {
  font-family: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: #484f4c;
}

/* Floating Toggle Button */
.iais-chat-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2e4e42 0%, #3a6355 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(46, 78, 66, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 10000;
}

.iais-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(46, 78, 66, 0.45);
}

.iais-chat-toggle:focus-visible {
  outline: 3px solid #ffd800;
  outline-offset: 3px;
}

.iais-chat-toggle svg {
  width: 28px;
  height: 28px;
  fill: white;
}

.iais-chat-toggle.open svg.icon-chat {
  display: none;
}

.iais-chat-toggle svg.icon-close {
  display: none;
}

.iais-chat-toggle.open svg.icon-close {
  display: block;
}

/* Chat Window */
.iais-chat-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 400px;
  height: 580px;
  max-height: calc(100vh - 110px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.14);
  display: none;
  flex-direction: column;
  z-index: 10000;
  overflow: hidden;
}

.iais-chat-window.active {
  display: flex;
}

/* Header */
.iais-chat-header {
  background: linear-gradient(135deg, #2e4e42 0%, #3a6355 100%);
  color: #fff;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.iais-chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.iais-chat-header-info h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #ffd800;
}

.iais-chat-header-info p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #fff;
  opacity: 0.85;
}

/* Messages Area */
.iais-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #edf3f0;
  scroll-behavior: smooth;
}

.iais-msg {
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
  animation: iaisFadeIn 0.3s ease;
}

.iais-msg.user {
  flex-direction: row-reverse;
}

@media (prefers-reduced-motion: reduce) {
  .iais-msg {
    animation: none;
  }
  .iais-typing-dot {
    animation: none !important;
    opacity: 0.6;
  }
}

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

.iais-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #2e4e42;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.iais-msg.user .iais-msg-avatar {
  background: #c8d5cf;
  color: #484f4c;
}

.iais-msg-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
}

.iais-msg.bot .iais-msg-bubble {
  background: #fff;
  color: #484f4c;
  border-bottom-left-radius: 4px;
}

.iais-msg.user .iais-msg-bubble {
  background: #2e4e42;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Option Buttons */
.iais-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 20px 16px 48px;
}

/* Screen reader only */
.iais-chat-container .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.iais-options.disabled {
  pointer-events: none;
  opacity: 0.5;
}

.iais-opt-btn {
  padding: 9px 16px;
  border: 1.5px solid #2e4e42;
  background: #fff;
  color: #2e4e42;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.iais-opt-btn:hover {
  background: #2e4e42;
  color: #fff;
}

.iais-opt-btn:focus-visible {
  outline: 3px solid #2e4e42;
  outline-offset: 2px;
}

.iais-opt-btn:active {
  transform: scale(0.97);
}

/* CTA Buttons (inside messages) */
.iais-cta-group {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.iais-cta-btn {
  padding: 11px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 700;
  transition: background 0.15s ease, transform 0.1s ease;
  border: none;
  text-align: center;
  min-height: 44px;
  text-decoration: none;
  display: block;
}

.iais-cta-btn.primary {
  background: #2e4e42;
  color: #fff;
}

.iais-cta-btn.primary:hover {
  background: #243f35;
}

.iais-cta-btn.secondary {
  background: transparent;
  color: #2e4e42;
  border: 1.5px solid #2e4e42;
}

.iais-cta-btn.secondary:hover {
  background: rgba(46, 78, 66, 0.08);
}

.iais-cta-btn.accent {
  background: #ffd800;
  color: #2e4e42;
}

.iais-cta-btn.accent:hover {
  background: #e6c300;
}

.iais-cta-btn:focus-visible {
  outline: 3px solid #2e4e42;
  outline-offset: 2px;
}

/* External link indicator */
.iais-cta-btn .ext-icon,
.iais-opt-btn .ext-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 6px;
  vertical-align: middle;
}

/* Typing Indicator */
.iais-typing {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.iais-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: #fff;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.iais-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6c757d;
  animation: iaisTyping 1.2s infinite;
}

.iais-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.iais-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes iaisTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-6px); }
}

/* Start Over Footer */
.iais-chat-footer {
  padding: 10px 20px;
  background: #fff;
  border-top: 1px solid #dce5e0;
  text-align: center;
  flex-shrink: 0;
}

.iais-start-over {
  background: none;
  border: none;
  color: #2e4e42;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  padding: 6px 12px;
  min-height: 44px;
}

.iais-start-over:hover {
  text-decoration: underline;
}

.iais-start-over:focus-visible {
  outline: 3px solid #2e4e42;
  outline-offset: 2px;
}

/* Site logo in bot/header avatars (replaces IAIS text) */
.iais-msg.bot .iais-msg-avatar,
.iais-typing .iais-msg-avatar {
  background-color: #fff;
  background-image: url('/images/cropped-IAS-Logosm-1.webp');
  background-size: 80%;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
  font-size: 0;
}

.iais-chat-header-avatar {
  background-color: rgba(255, 255, 255, 0.9);
  background-image: url('/images/cropped-IAS-Logosm-1.webp');
  background-size: 75%;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
  font-size: 0;
}

/* Mobile */
@media (max-width: 480px) {
  .iais-chat-window {
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
    max-height: 100vh;
  }

  .iais-chat-toggle {
    bottom: 16px;
    right: 16px;
  }

  .iais-msg-bubble {
    max-width: 82%;
  }

  .iais-options {
    padding-left: 20px;
    padding-right: 10px;
  }
}
