/* ============================================
   Modern Chat Widget Design
   ============================================ */

/* Floating Action Button */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  background: none;
  border: none;
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: visible;
  filter: drop-shadow(0 4px 12px rgba(0, 206, 209, 0.4));
}

.chat-fab:hover {
  transform: scale(1.1);
  filter: drop-shadow(0 6px 16px rgba(0, 206, 209, 0.5));
}

.chat-fab:active {
  transform: scale(0.95);
}

.chat-fab-avatar {
  width: 82px;
  height: 82px;
  object-fit: contain;
  transition: transform 0.3s ease;
  pointer-events: none;
}

.chat-fab:hover .chat-fab-avatar {
  transform: scale(1.1);
}

.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff4444;
  color: white;
  font-size: 11px;
  font-weight: 600;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* Chat Widget Container */
.chat-widget {
  position: fixed;
  bottom: 30px;
  right: 24px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 70px);
  background: white;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  display: none;
  flex-direction: column;
  z-index: 9999;
  overflow: hidden;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(0, 206, 209, 0.2);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Chat Header */
.chat-header {
  background: linear-gradient(135deg, #00CED1 0%, #20B2AA 100%);
  color: white;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-header-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.chat-header-text {
  flex: 1;
  min-width: 0;
}

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

.chat-subtitle {
  font-size: 12px;
  margin: 2px 0 0 0;
  opacity: 0.9;
  line-height: 1.2;
}

.chat-close-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

/* Chat Body */
.chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f8f9fa;
}

.chat-welcome {
  padding: 24px 20px;
  text-align: center;
  background: white;
  border-bottom: 1px solid #e9ecef;
}

.welcome-avatar {
  width: 56px;
  height: 56px;
  margin: 0 auto 10px;
  animation: welcomeBounce 2s ease-in-out infinite;
}

.welcome-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 206, 209, 0.3));
}

@keyframes welcomeBounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.welcome-message {
  text-align: left;
}

.welcome-text {
  font-size: 15px;
  font-weight: 600;
  color: #212529;
  margin: 0 0 8px 0;
}

.welcome-desc {
  font-size: 13px;
  color: #6c757d;
  margin: 0;
  line-height: 1.5;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: #dee2e6;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}

/* Bot Message Avatar */
.bot-avatar {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  margin-top: 4px;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.1));
}

/* Message Bubbles */
.chat-message {
  display: flex;
  gap: 8px;
  animation: fadeIn 0.3s ease;
  max-width: 85%;
}

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

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

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

.message-bubble-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
}

.chat-message.user .message-bubble {
  background: linear-gradient(135deg, #00CED1 0%, #20B2AA 100%);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 206, 209, 0.3);
}

.chat-message.bot .message-bubble {
  background: white;
  color: #212529;
  border: 1px solid #e9ecef;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.message-time {
  font-size: 10px;
  color: #6c757d;
  margin-top: 4px;
  opacity: 0.7;
}

.chat-message.user .message-time {
  text-align: right;
  color: rgba(255, 255, 255, 0.8);
}

/* Typing Indicator */
.chat-typing {
  padding: 0 20px 12px;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: white;
  border-radius: 18px;
  border: 1px solid #e9ecef;
  width: fit-content;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00CED1;
  animation: typing 1.4s infinite;
}

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

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

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

/* Chat Input */
.chat-input {
  padding: 16px 20px;
  background: white;
  border-top: 1px solid #e9ecef;
}

.chat-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #f8f9fa;
  border-radius: 24px;
  padding: 4px;
  border: 1px solid #e9ecef;
  transition: all 0.2s ease;
}

.chat-input-wrapper:focus-within {
  border-color: #00CED1;
  box-shadow: 0 0 0 3px rgba(0, 206, 209, 0.15);
}

#chat-text {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 16px;
  font-size: 16px;
  color: #212529;
  outline: none;
}

#chat-text::placeholder {
  color: #adb5bd;
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00CED1 0%, #20B2AA 100%);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 206, 209, 0.4);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* === Bot Markdown Content === */
.bot-content {
  font-size: 14px;
  line-height: 1.6;
}

.bot-content p {
  margin: 0 0 8px 0;
}

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

.bot-content ul,
.bot-content ol {
  margin: 4px 0 8px 0;
  padding-left: 20px;
}

.bot-content li {
  margin-bottom: 2px;
}

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

.bot-content a {
  color: #0d9488;
  text-decoration: underline;
}

.bot-content a:hover {
  color: #00CED1;
}

.bot-content code {
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
}

/* === Suggestion Chips === */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  animation: fadeIn 0.3s ease;
}

.suggestion-chip {
  background: white;
  border: 1px solid #00CED1;
  color: #0d9488;
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-chip:hover {
  background: #00CED1;
  color: white;
}

/* === Feedback Buttons === */
.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.chat-message.bot:hover .message-actions {
  opacity: 1;
}

/* Keep buttons visible after feedback is given */
.message-actions.feedback-given {
  opacity: 1;
}

.feedback-btn {
  background: none;
  border: 1px solid transparent;
  color: #9ca3af;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.feedback-btn:not(:disabled):hover {
  color: #00CED1;
  border-color: #e5e7eb;
}

.feedback-btn.feedback-active {
  color: #00CED1;
  border-color: #00CED1;
  background: rgba(0, 206, 209, 0.08);
}

.feedback-btn.feedback-active[data-feedback="down"] {
  color: #ef4444;
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
}

.feedback-btn:disabled:not(.feedback-active) {
  opacity: 0.35;
  cursor: default;
}

.feedback-btn:disabled.feedback-active {
  cursor: default;
}

/* === Streaming Cursor === */
.streaming-content::after {
  content: "\25CA";
  animation: blink 1s infinite;
  color: #00CED1;
  margin-left: 2px;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .chat-widget {
    width: 100%;
    height: 100%;
    max-height: none;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
    transform: none !important;
  }

  .chat-fab {
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
  }

  .chat-fab-avatar {
    width: 66px;
    height: 66px;
  }

  .chat-header {
    border-radius: 0;
    padding: 16px;
    padding-top: env(safe-area-inset-top, 16px);
  }

  .welcome-avatar {
    width: 48px;
    height: 48px;
  }

  .chat-welcome {
    padding: 16px;
  }

  .chat-messages {
    padding: 16px;
  }

  .chat-input {
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }

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

  .suggestion-chip {
    white-space: normal;
    font-size: 12px;
    padding: 5px 12px;
  }

  .message-actions {
    opacity: 1;
  }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
  .chat-widget {
    background: #1a1a1a;
    border-color: rgba(255, 255, 255, 0.1);
  }

  .chat-body {
    background: #1a1a1a;
  }

  .chat-welcome {
    background: #2a2a2a;
    border-color: rgba(255, 255, 255, 0.1);
  }

  .welcome-text {
    color: #ffffff;
  }

  .welcome-desc {
    color: #adb5bd;
  }

  .chat-message.bot .message-bubble {
    background: #2a2a2a;
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.1);
  }

  .chat-input {
    background: #2a2a2a;
    border-color: rgba(255, 255, 255, 0.1);
  }

  .chat-input-wrapper {
    background: #1a1a1a;
    border-color: rgba(255, 255, 255, 0.1);
  }

  #chat-text {
    color: #ffffff;
  }

  .typing-indicator {
    background: #2a2a2a;
    border-color: rgba(255, 255, 255, 0.1);
  }

  /* Dark mode: suggestion chips */
  .suggestion-chip {
    background: #2a2a2a;
    border-color: #00CED1;
    color: #00CED1;
  }

  .suggestion-chip:hover {
    background: #00CED1;
    color: #1a1a1a;
  }

  /* Dark mode: feedback */
  .feedback-btn {
    color: #6b7280;
  }

  .feedback-btn:not(:disabled):hover,
  .feedback-btn.feedback-active {
    color: #00CED1;
  }

  .feedback-btn.feedback-active[data-feedback="down"] {
    color: #ef4444;
  }

  .feedback-btn:disabled:not(.feedback-active) {
    opacity: 0.35;
  }

  /* Dark mode: FAB */
  .chat-fab {
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
  }

  /* Dark mode: markdown content */
  .bot-content code {
    background: #374151;
    color: #e5e7eb;
  }

  .bot-content a {
    color: #5eead4;
  }
}
