/* Chat window styles */
#chat-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background-color: var(--chat-primary);
  color: var(--chat-bg);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  font-size: 24px;
  box-shadow: 0 2px 10px var(--chat-shadow);
  transition: background-color 0.3s ease;
  z-index: 1000;
}

#chat-button:hover {
  background-color: var(--chat-primary-hover);
}

#chat-window {
  position: fixed;
  bottom: 20px;
  right: 20px;
  transform: none;
  width: 400px;
  height: 600px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  border: 1px solid var(--chat-border);
  background-color: var(--chat-bg);
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px var(--chat-shadow);
  z-index: 999;
  /* If --chat-bg is not defined or is transparent, use a fallback color */
  background-color: var(--bg, #2b2b2b);
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  background-color: var(--bg);
  border-bottom: 1px solid var(--sidebar-bg);
}

.chat-title {
  font-size: 16px;
  font-weight: bold;
  color: var(--fg);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

#connection-status {
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 10px;
}

#connection-status.connected {
  background-color: rgba(76, 175, 80, 0.2);
  color: #4caf50;
}

#connection-status.disconnected {
  background-color: rgba(244, 67, 54, 0.2);
  color: #f44336;
}

#clear-history {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  color: var(--fg);
  opacity: 0.7;
  transition: opacity 0.3s, transform 0.1s;
}

#clear-history:hover {
  opacity: 1;
}

#clear-history:active {
  transform: scale(0.9);
}

#clear-history svg {
  vertical-align: middle;
}

#close-chat {
  font-size: 20px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--fg);
  opacity: 0.7;
  transition: opacity 0.3s;
}

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

.chat-controls {
  display: flex;
  align-items: center;
}

.icon-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  margin-left: 10px;
  color: var(--fg);
  opacity: 0.7;
  transition: opacity 0.3s;
}

.icon-button:hover {
  opacity: 1;
}

#chat-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 20px;
  background-color: var(--chat-bg);
}

#chat-input {
  display: flex;
  padding: 15px;
  background-color: var(--chat-input-bg, var(--bg));
  border-top: 1px solid var(--chat-border);
  height: 60px; /* Fixed height for the input area */
}

#message-input {
  flex-grow: 1;
  margin-right: 10px;
  padding: 10px;
  border: 1px solid var(--chat-border);
  border-radius: 4px;
  background-color: var(--chat-input-bg, var(--bg));
  color: var(--chat-text);
  font-size: 16px;
}

#send-message {
  background-color: var(--links);
  color: var(--bg);
  border: none;
}

#send-message:hover {
  opacity: 0.9;
}

.message {
  margin-bottom: 15px;
  padding: 12px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1.5;
  max-width: 80%;
  box-shadow: 0 1px 2px var(--chat-shadow, rgba(0, 0, 0, 0.1));
}

.message.user {
  background-color: var(--chat-user-msg-bg, #4a86e8);
  color: var(--chat-user-msg-text, white);
  align-self: flex-end;
  margin-left: auto;
}

.message.ai {
  background-color: var(--chat-ai-msg-bg, #424242);
  color: var(--chat-ai-msg-text, white);
  align-self: flex-start;
}

.message .content {
  white-space: pre-wrap;
  word-break: break-word;
}

.message .content pre {
  background-color: #2b2b2b;
  border-radius: 4px;
  padding: 1em;
  overflow-x: auto;
}

.message .content code {
  font-family: "Courier New", Courier, monospace;
}

.message.loading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.loading-dots {
  display: flex;
  gap: 4px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: currentColor;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

/* Add different delays for each dot */
.loading-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

/* Add the bounce animation */
@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* Code block styles */
.message .content pre {
  background-color: var(--chat-code-bg);
  border-radius: 4px;
  padding: 1em;
  overflow-x: auto;
}

.message .content code {
  font-family: "Courier New", Courier, monospace;
}

/* Link styles */
.message .content a {
  color: var(--chat-primary);
  text-decoration: none;
}

.message .content a:hover {
  text-decoration: underline;
}

/* Scrollbar styles */
#chat-messages {
  scrollbar-width: thin;
  scrollbar-color: var(--chat-scrollbar) var(--chat-bg);
}

#chat-messages::-webkit-scrollbar {
  width: 8px;
}

#chat-messages::-webkit-scrollbar-track {
  background: var(--chat-bg);
}

#chat-messages::-webkit-scrollbar-thumb {
  background-color: var(--chat-scrollbar);
  border-radius: 4px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
  background-color: var(--chat-scrollbar-hover);
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 20px;
  border-radius: 5px;
  color: white;
  opacity: 0.9;
  z-index: 1001;
}

.toast.error {
  background-color: var(--chat-toast-error);
}
.toast.success {
  background-color: var(--chat-toast-success);
}
.toast.warning {
  background-color: var(--chat-toast-warning);
}

/* Prevent background scrolling when chat is open */
body.chat-open {
  overflow: hidden;
}

/* Responsive design */
@media (max-width: 768px) {
  #chat-window {
    width: 90%;
    height: 90vh;
  }

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

@media (max-width: 480px) {
  #chat-window {
    width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }
}
