#chat-widget {
  --chat-primary: #6366f1;
  --chat-bg: #ffffff;
  --chat-text: #1f2937;
  --chat-border: #e5e7eb;
  --chat-user-bg: #6366f1;
  --chat-user-text: #ffffff;
  --chat-assistant-bg: #f3f4f6;

  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  #chat-widget {
    --chat-bg: #1f2937;
    --chat-text: #f3f4f6;
    --chat-border: #374151;
    --chat-assistant-bg: #374151;
  }
}

/* PaperMod dark mode class support */
.dark #chat-widget {
  --chat-bg: #1f2937;
  --chat-text: #f3f4f6;
  --chat-border: #374151;
  --chat-assistant-bg: #374151;
}

#chat-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--chat-primary);
  color: white;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s, box-shadow 0.2s;
}

#chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

#chat-toggle.hidden {
  display: none;
}

#chat-panel {
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 500px;
  max-height: calc(100vh - 100px);
  background: var(--chat-bg);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chat-panel.hidden {
  display: none;
}

#chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--chat-border);
  font-weight: 600;
  color: var(--chat-text);
}

#chat-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--chat-text);
  opacity: 0.6;
  line-height: 1;
  padding: 0;
  width: 28px;
  height: 28px;
}

#chat-close:hover {
  opacity: 1;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.5;
}

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

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

.message.loading {
  display: flex;
  gap: 4px;
  padding: 14px 18px;
}

.message.loading .dot {
  width: 8px;
  height: 8px;
  background: var(--chat-text);
  opacity: 0.4;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.message.loading .dot:nth-child(1) { animation-delay: -0.32s; }
.message.loading .dot:nth-child(2) { animation-delay: -0.16s; }

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

#chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
}

.suggestion {
  padding: 6px 12px;
  background: var(--chat-assistant-bg);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--chat-text);
  transition: background 0.2s;
}

.suggestion:hover {
  background: var(--chat-border);
}

#chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--chat-border);
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  outline: none;
  font-size: 14px;
  background: var(--chat-bg);
  color: var(--chat-text);
}

#chat-input:focus {
  border-color: var(--chat-primary);
}

#chat-send {
  width: 40px;
  height: 40px;
  background: var(--chat-primary);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

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

#chat-send:hover:not(:disabled) {
  opacity: 0.9;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  #chat-widget {
    bottom: 10px;
    right: 10px;
  }

  #chat-panel {
    width: calc(100vw - 20px);
    height: calc(100vh - 80px);
    border-radius: 12px;
  }

  #chat-toggle span {
    display: none;
  }

  #chat-toggle {
    padding: 14px;
    border-radius: 50%;
  }
}
