/*----------------------------------------
  0. Biến màu (CSS Variables)
-----------------------------------------*/
:root {
  /* Light theme */
  --primary-color: #e67e22;       /* Cam chủ đạo */
  --primary-dark: #c55a00;        /* Cam đậm cho hover/focus */
  --primary-light: #f39c12;       /* Cam nhạt cho hover */
  --background-light: #f8f9fa;    /* Nền sáng tổng thể */
  --text-color: #333333;          /* Màu chữ chính */
  --muted-color: #6c757d;         /* Màu chữ phụ, timestamp */
  --error-color: #dc3545;         /* Màu cảnh báo/lỗi */
  --user-msg-bg: #fff3bf;         /* Nền user-message */
  --bot-msg-bg: #fdf2e9;          /* Nền bot-message */
  --input-border: #e67e22;        /* Viền input */
  --input-focus: #f39c12;         /* Viền input khi focus */
  --scrollbar-thumb: #e67e22;     /* Thumb scrollbar */
  --scrollbar-thumb-hover: #c55a00;
  --card-bg: #ffffff;
  --header-bg: linear-gradient(90deg, #e67e22 0%, #eb8c2c 100%);
  --shadow-color: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
  --primary-color: #f39c12;
  --primary-dark: #e67e22;
  --primary-light: #f1c40f;
  --background-light: #1a1a1a;
  --text-color: #ffffff;
  --muted-color: #a0a0a0;
  --error-color: #ff6b6b;
  --user-msg-bg: #2c2c2c;
  --bot-msg-bg: #3d3d3d;
  --input-border: #4a4a4a;
  --input-focus: #f39c12;
  --scrollbar-thumb: #4a4a4a;
  --scrollbar-thumb-hover: #5a5a5a;
  --card-bg: #2c2c2c;
  --header-bg: linear-gradient(90deg, #2c2c2c 0%, #3d3d3d 100%);
  --shadow-color: rgba(0, 0, 0, 0.3);
}

/*----------------------------------------
  1. Reset & Base Styles
-----------------------------------------*/
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  transition: background-color 0.3s, color 0.3s;
}

/* Accessibility: hidden cho screen reader */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/*----------------------------------------
  2. Body & Container
-----------------------------------------*/
body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background-color: var(--background-light);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  position: relative;
}

/* Theme Toggle Button */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--card-bg);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color);
  box-shadow: 0 2px 10px var(--shadow-color);
  z-index: 1000;
  transition: transform 0.3s ease;
}

.theme-toggle:hover {
  transform: scale(1.1);
}

/*----------------------------------------
  3. Header Styles
-----------------------------------------*/
.header {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--header-bg);
  padding: 16px 24px;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 4px 12px var(--shadow-color);
  color: #ffffff;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-container {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.library-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header-texts {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.header-title {
  font-size: 1.5rem;
  margin: 0;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-subtitle {
  font-size: 0.9rem;
  margin: 4px 0 0 0;
  opacity: 0.9;
}

/* Responsive Header cho mobile ≤ 600px */
@media (max-width: 600px) {
  .header {
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
  }
  .logo-container {
    width: 40px;
    height: 40px;
  }
  .header-title {
    font-size: 1.2rem;
    text-align: center;
  }
  .header-subtitle {
    font-size: 0.75rem;
    text-align: center;
  }
}

/*----------------------------------------
  4. Chat Container
-----------------------------------------*/
#chat-container {
  max-width: 800px;
  width: 100%;
  margin: 20px auto;
  background: var(--card-bg);
  padding: 24px;
  border-radius: 16px;
  box-shadow: 0 4px 20px var(--shadow-color);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/*----------------------------------------
  5. Welcome Message
-----------------------------------------*/
.welcome-message {
  background: var(--header-bg);
  color: white;
  padding: 24px;
  border-radius: 12px;
  animation: fadeIn 0.5s ease-out;
}

.welcome-content {
  margin-bottom: 20px;
}

.welcome-message h3 {
  font-size: 1.3rem;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.welcome-list {
  list-style: none;
  margin: 16px 0;
}

.welcome-list li {
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.suggested-questions {
  display: flex;
  overflow-x: auto;
  gap: 12px;
  padding: 8px 0;
  scrollbar-width: thin;
}

.suggested-question {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  padding: 10px 16px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.suggested-question:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

/*----------------------------------------
  6. Chat Box
-----------------------------------------*/
.chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--background-light);
  border-radius: 12px;
  max-height: calc(100vh - 400px);
  min-height: 300px;
}

.message-container {
  margin-bottom: 16px;
  animation: slideIn 0.3s ease-out;
}

.message {
  padding: 12px 16px;
  border-radius: 12px;
  max-width: 80%;
  position: relative;
  box-shadow: 0 2px 8px var(--shadow-color);
}

.user-message {
  background: var(--user-msg-bg);
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.bot-message {
  background: var(--bot-msg-bg);
  margin-right: auto;
  border-bottom-left-radius: 4px;
  white-space: pre-line;
  line-height: 1.5;
}

.bot-message br {
  margin-bottom: 0.5em;
}

.bot-message p {
  margin: 0.5em 0;
}

.bot-message ol,
.bot-message ul {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.bot-message li {
  margin: 0.3em 0;
}

.timestamp {
  font-size: 0.75rem;
  color: var(--muted-color);
  margin-top: 4px;
  text-align: right;
}

/*----------------------------------------
  7. Input Area
-----------------------------------------*/
.input-wrapper {
  position: relative;
  margin-top: auto;
}

.input-container {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--card-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  transition: border-color 0.2s;
}

.input-container:focus-within {
  border-color: var(--primary-color);
}

#user-input {
  flex: 1;
  border: 2px solid var(--input-border);
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  background: var(--card-bg);
  color: var(--text-color);
  transition: all 0.3s ease;
}

#user-input:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(243, 156, 18, 0.2);
}

.char-counter {
  position: absolute;
  right: 60px;
  bottom: 8px;
  font-size: 12px;
  color: var(--muted-color);
  pointer-events: none;
}

.send-button {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.send-button:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/*----------------------------------------
  8. Animations
-----------------------------------------*/
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/*----------------------------------------
  9. Error Notice + Retry Button
-----------------------------------------*/
.error-message {
  color: var(--error-color);
  background-color: #ffe5e5;
  padding: 8px 12px;
  border-radius: 8px;
  text-align: center;
  margin-top: 8px;
  font-size: 14px;
  transition: background-color 0.3s, color 0.3s;
}
.error-message.hidden {
  display: none;
}

/*----------------------------------------
  10. Feedback Box (👍👎)
-----------------------------------------*/
.feedback-box {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 10px;
}
.feedback-box.hidden {
  display: none;
}
.feedback-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  transition: transform 0.2s;
}
.feedback-btn:hover,
.feedback-btn:focus {
  transform: scale(1.2);
  outline: none;
}

/*----------------------------------------
  11. Responsive Design
-----------------------------------------*/
@media (max-width: 768px) {
  .header {
    padding: 12px 16px;
    border-radius: 0 0 12px 12px;
  }

  .logo-container {
    width: 40px;
    height: 40px;
  }

  .header-title {
    font-size: 1.2rem;
  }

  .header-subtitle {
    font-size: 0.8rem;
  }

  #chat-container {
    margin: 12px;
    padding: 16px;
    border-radius: 12px;
  }

  .welcome-message {
    padding: 16px;
  }

  .message {
    max-width: 90%;
  }

  .input-container {
    padding: 8px;
  }

  #user-input {
    padding: 8px;
  }
}

@media (max-width: 480px) {
  .theme-toggle {
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
  }

  .header {
    padding: 8px 12px;
  }

  .header-left {
    gap: 8px;
  }

  .logo-container {
    width: 32px;
    height: 32px;
  }

  .header-title {
    font-size: 1rem;
  }

  .header-subtitle {
    font-size: 0.7rem;
  }

  .welcome-message h3 {
    font-size: 1.1rem;
  }

  .suggested-question {
    padding: 8px 12px;
    font-size: 0.9rem;
  }
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary-color);
  background-color: var(--bg-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease;
}

.avatar:hover {
  transform: scale(1.05);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  margin: 8px 0;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.typing-indicator.hidden {
  display: none;
  opacity: 0;
}

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

.typing-indicator .dots span {
  width: 8px;
  height: 8px;
  background: var(--primary-color);
  border-radius: 50%;
  animation: typingAnimation 1.4s infinite ease-in-out;
}

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

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

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

@keyframes typingAnimation {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.6;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}
  