@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");

:root {
  --font-family: "Poppins", sans-serif;

  --light-bg: #f4f7f9;
  --light-chat-bg: #ffffff;
  --light-header-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --light-user-msg-bg: #dcf8c6;
  --light-ai-msg-bg: #eceff1;
  --light-input-bg: #f0f0f0;
  --light-text-color: #333;
  --light-header-text: #ffffff;
  --light-button-color: #5e60ce;
  --light-button-hover: #4d4fb8;
  --light-border-color: #e0e0e0;
  --light-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);

  --dark-bg: #1a1a2e;
  --dark-chat-bg: #16213e;
  --dark-header-bg: linear-gradient(135deg, #2c3e50 0%, #1f2b38 100%);
  --dark-user-msg-bg: #0f3460;
  --dark-ai-msg-bg: #27374d;
  --dark-input-bg: #0f3460;
  --dark-text-color: #e0e0e0;
  --dark-header-text: #e0e0e0;
  --dark-button-color: #50fa7b;
  --dark-button-hover: #42d969;
  --dark-border-color: #3a3a5a;
  --dark-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);

  /* Default to light theme */
  --current-bg: var(--light-bg);
  --current-chat-bg: var(--light-chat-bg);
  --current-header-bg: var(--light-header-bg);
  --current-user-msg-bg: var(--light-user-msg-bg);
  --current-ai-msg-bg: var(--light-ai-msg-bg);
  --current-input-bg: var(--light-input-bg);
  --current-text-color: var(--light-text-color);
  --current-header-text: var(--light-header-text);
  --current-button-color: var(--light-button-color);
  --current-button-hover: var(--light-button-hover);
  --current-border-color: var(--light-border-color);
  --current-shadow: var(--light-shadow);
}

body {
  font-family: var(--font-family);
  margin: 0;
  background-color: var(--current-bg);
  color: var(--current-text-color);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 10px;
  box-sizing: border-box;
  transition: background-color 0.3s, color 0.3s;
}

.chat-container {
  width: 100%;
  max-width: 750px;
  height: 90vh;
  max-height: 800px;
  background-color: var(--current-chat-bg);
  border-radius: 15px;
  box-shadow: var(--current-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color 0.3s, box-shadow 0.3s;
}

.chat-header {
  background: var(--current-header-bg);
  color: var(--current-header-text);
  padding: 15px 20px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: space-between; /* Para el botón de tema */
  border-bottom: 1px solid var(--current-border-color);
  transition: background 0.3s, color 0.3s, border-bottom-color 0.3s;
}

.chat-header .logo {
  border-radius: 10%;
  background-color: rgba(255, 255, 255, 0);
}

.chat-header .fa-graduation-cap {
  font-size: 1.8em;
  margin-right: 10px;
}

.chat-header h1 {
  font-size: 1.4em;
  font-weight: 600;
  margin: 0;
  flex-grow: 1;
  text-align: center;
}

.theme-toggle-button {
  background: none;
  border: none;
  color: var(--current-header-text);
  font-size: 1.5em;
  cursor: pointer;
  padding: 5px;
  transition: color 0.3s;
}
.theme-toggle-button:hover {
  opacity: 0.8;
}

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

.message {
  display: flex;
  align-items: flex-end; /* Alinea avatar e icono de copia con la parte inferior del mensaje */
  max-width: 80%;
  word-wrap: break-word;
  position: relative; /* Para el botón de copiar */
}

.message .avatar {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3em;
  color: white;
  flex-shrink: 0;
}

.message .text-content {
  padding: 12px 18px;
  border-radius: 20px;
  line-height: 1.5;
  margin: 0 10px;
  position: relative; /* Para el botón de copiar */
}
.message .text-content pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  background-color: rgba(0, 0, 0, 0.05);
  padding: 10px;
  border-radius: 5px;
  margin: 10px 0;
  font-family: "Courier New", Courier, monospace;
  overflow-x: auto;
}
.message .text-content code:not(pre code) {
  background-color: rgba(0, 0, 0, 0.07);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: "Courier New", Courier, monospace;
}

.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.user-message .avatar {
  background-color: var(--current-button-color);
}
.user-message .text-content {
  background-color: #B7C1F9;
  color: var(--current-text-color);
  border-bottom-right-radius: 5px;
}

.ai-message {
  align-self: flex-start;
}
.ai-message .avatar {
  background-color: #888; /* Un color neutro para el avatar IA */
}
.ai-message .text-content {
  background-color: var(--current-ai-msg-bg);
  color: var(--current-text-color);
  border-bottom-left-radius: 5px;
}

.copy-button {
  background: none;
  border: none;
  color: var(--current-text-color);
  opacity: 0.7;
  cursor: pointer;
  font-size: 0.9em;
  padding: 5px;
  transition: opacity 0.2s;
  color: #5665b2 !important;
}

.speak-button {
  color: #5665b2 !important;
  border: 2px solid #5665b2;
  border-radius: 8px;
  font-size: 0.9em;
  opacity: 0.7;
  background: none;
  cursor: pointer;
  margin-left: 5px;
  color: var(--text-color);
}

.message:hover .copy-button {
  visibility: visible; /* Visible al pasar el ratón sobre el mensaje */
}
.copy-button:hover {
  opacity: 1;
}
.copy-button.copied {
  color: var(--current-button-color); /* O un color verde */
}

.typing-indicator .text-content {
  padding: 12px 18px;
}
.typing-indicator span {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin: 0 2px;
  background-color: var(--current-text-color);
  opacity: 0.7;
  border-radius: 50%;
  animation: typing 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}
.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  50% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.chat-input-area {
  display: flex;
  padding: 15px;
  border-top: 1px solid var(--current-border-color);
  background-color: var(--current-chat-bg); /* Fondo consistente con el chat */
  transition: border-top-color 0.3s, background-color 0.3s;
}
.chat-input-area form {
  display: flex;
  width: 100%;
  gap: 10px;
}
.chat-input-area input[type="text"] {
  flex-grow: 1;
  padding: 12px 18px;
  border: 1px solid var(--current-border-color);
  border-radius: 25px;
  font-size: 1em;
  outline: none;
  background-color: var(--current-input-bg);
  color: var(--current-text-color);
  transition: border-color 0.3s, background-color 0.3s, color 0.3s;
}
.chat-input-area input[type="text"]:focus {
  border-color: var(--current-button-color);
}
.chat-input-area button {
  background-color: var(--current-button-color);
  color: white;
  border: none;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  font-size: 1.2em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s;
  flex-shrink: 0;
}
.chat-input-area button:hover {
  background-color: var(--current-button-hover);
}
.chat-input-area button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.mic-button.recording {
  color: red;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(255, 82, 82, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 82, 82, 0);
  }
}

/* Scrollbar styling */
.chat-box::-webkit-scrollbar {
  width: 8px;
}
.chat-box::-webkit-scrollbar-track {
  background: var(--current-input-bg);
  border-radius: 10px;
}
.chat-box::-webkit-scrollbar-thumb {
  background: var(--current-button-color);
  border-radius: 10px;
}
.chat-box::-webkit-scrollbar-thumb:hover {
  background: var(--current-button-hover);
}

@media (max-width: 700px) {
  body {
    padding: 0;
  }
  .chat-container {
    border-radius: 0;
    height: 100vh;
    max-height: none;
  }
  .chat-header h1 {
    font-size: 1.2em;
  }
  .message {
    max-width: 90%;
  }
  .chat-input-area {
    padding: 10px;
  }
  .chat-input-area input[type="text"] {
    padding: 10px 15px;
  }
  .chat-input-area button {
    width: 45px;
    height: 45px;
  }
}
