/* ============================================
   Structural Optimism Chatbot Styles
   ============================================ */

/* Chat Toggle Button
   ============================================ */
.chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--md-primary-fg-color);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.chat-toggle:focus {
  outline: 3px solid var(--md-accent-fg-color);
  outline-offset: 2px;
}

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

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

.chat-toggle.active .chat-icon {
  display: none;
}

.chat-toggle.active .close-icon {
  display: block;
}

/* Chat Container
   ============================================ */
.chat-container {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 500px;
  max-height: calc(100vh - 140px);
  background: var(--md-default-bg-color);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
  border: 1px solid var(--md-default-fg-color--lightest);
}

.chat-container.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Chat Header
   ============================================ */
.chat-header {
  padding: 16px 20px;
  background: var(--md-primary-fg-color);
  color: white;
  border-radius: 16px 16px 0 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-icon {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-header-icon svg {
  width: 18px;
  height: 18px;
  fill: white;
}

.chat-header-text h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.chat-header-text p {
  margin: 0;
  font-size: 0.75rem;
  opacity: 0.85;
}

/* Guide Notice */
.guide-notice {
  padding: 12px 16px;
  font-size: 0.8rem;
  color: var(--md-default-fg-color--light);
  text-align: center;
  border-bottom: 1px solid var(--md-default-fg-color--lightest);
}

/* Guide Content */
.guide-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.guide-text {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--md-typeset-color);
  margin: 0;
}

.guide-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.guide-choice {
  padding: 12px 16px;
  font-size: 0.9rem;
  background: var(--md-code-bg-color);
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 8px;
  cursor: pointer;
  color: var(--md-typeset-color);
  text-align: left;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}

.guide-choice:hover {
  background: var(--md-primary-fg-color);
  border-color: var(--md-primary-fg-color);
  color: white;
  transform: translateX(4px);
}

.guide-choice:focus {
  outline: 2px solid var(--md-accent-fg-color);
  outline-offset: 2px;
}

/* Chat Messages Area
   ============================================ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  animation: messageSlide 0.3s ease;
}

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

.chat-message.bot {
  background: var(--md-code-bg-color);
  color: var(--md-typeset-color);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-message.user {
  background: var(--md-primary-fg-color);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-message a {
  color: inherit;
  text-decoration: underline;
}

.chat-message.bot a {
  color: var(--md-primary-fg-color);
}

/* Typing Indicator
   ============================================ */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--md-code-bg-color);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  max-width: 60px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--md-default-fg-color--light);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

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

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-4px);
  }
}

/* Quick Actions
   ============================================ */
.chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--md-default-fg-color--lightest);
}

.quick-action-btn {
  padding: 6px 12px;
  font-size: 0.8rem;
  background: var(--md-code-bg-color);
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 16px;
  cursor: pointer;
  color: var(--md-typeset-color);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.quick-action-btn:hover {
  background: var(--md-primary-fg-color--light);
  border-color: var(--md-primary-fg-color);
  color: var(--md-primary-fg-color);
}

.quick-action-btn:focus {
  outline: 2px solid var(--md-accent-fg-color);
  outline-offset: 1px;
}

/* Chat Input Area
   ============================================ */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--md-default-fg-color--lightest);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 20px;
  background: var(--md-default-bg-color);
  color: var(--md-typeset-color);
  font-size: 0.9rem;
  resize: none;
  max-height: 100px;
  font-family: inherit;
}

.chat-input:focus {
  outline: none;
  border-color: var(--md-primary-fg-color);
}

.chat-input::placeholder {
  color: var(--md-default-fg-color--light);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--md-primary-fg-color);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: var(--md-primary-fg-color--dark);
  transform: scale(1.05);
}

.chat-send-btn:focus {
  outline: 2px solid var(--md-accent-fg-color);
  outline-offset: 2px;
}

.chat-send-btn:disabled {
  background: var(--md-default-fg-color--light);
  cursor: not-allowed;
  transform: none;
}

.chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Suggested Links in Messages
   ============================================ */
.chat-links {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--md-primary-fg-color);
  transition: background 0.2s ease;
}

.chat-link:hover {
  background: rgba(0, 0, 0, 0.1);
}

[data-md-color-scheme="slate"] .chat-link {
  background: rgba(255, 255, 255, 0.1);
}

[data-md-color-scheme="slate"] .chat-link:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Mobile Responsive
   ============================================ */
@media screen and (max-width: 480px) {
  .chat-container {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
    border-radius: 16px 16px 0 0;
  }
  
  .chat-toggle {
    bottom: 16px;
    right: 16px;
  }
  
  .chat-container.open + .chat-toggle {
    bottom: calc(100vh - 44px);
  }
}

/* Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .chat-container {
    transition: opacity 0.1s ease, visibility 0.1s ease;
    transform: none;
  }
  
  .chat-container.open {
    transform: none;
  }
  
  .chat-message {
    animation: none;
  }
  
  .typing-indicator span {
    animation: none;
  }
  
  .chat-toggle:hover {
    transform: none;
  }
}

/* High Contrast Mode
   ============================================ */
@media (prefers-contrast: high) {
  .chat-container {
    border-width: 2px;
  }
  
  .chat-message {
    border: 1px solid currentColor;
  }
  
  .chat-input {
    border-width: 2px;
  }
}

/* Print - Hide Chatbot
   ============================================ */
@media print {
  .chat-toggle,
  .chat-container {
    display: none !important;
  }
}
