:root {
  --bg-color: #121212;
  --text-color: #eee;
  --chat-bg: #1e1e1e;
  --ai-bg: #2a2a2a;
  --ai-color: #eee;
  --header-controls: #1e1e1e;
  --file-tag-bg: #333;
  --file-tag-text: #eee;
  --remove-btn-color: #ff4d4d;
  --back-btn-color: #eee;
  --back-btn-bg: transparent;
  --back-btn-border: none;
  --prompt-bg: #222;
  --accent-color: #4CAF50;
}

body.light-mode {
  --bg-color: #f5f5f5;
  --text-color: #121212;
  --chat-bg: #e0e0e0;
  --ai-bg: #eee;
  --ai-color: #2a2a2a;
  --header-controls: #e1e1e1;
  --file-tag-bg: #e0e0e0;
  --file-tag-text: #121212;
  --remove-btn-color: #d32f2f;
  --back-btn-color: #121212;
  --back-btn-bg: transparent;
  --back-btn-border: none;
  --prompt-bg: white;
  --accent-color: #2E7D32;
}

/* ---------- Base Styles ---------- */
body {
  font-family: Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  position: relative;
}

/* Scrollbar */
body::-webkit-scrollbar {
  width: 10px;
}
body::-webkit-scrollbar-track {
  background: #2e2e2e;
  border-radius: 10px;
}
body::-webkit-scrollbar-thumb {
  background-color: #555;
  border-radius: 10px;
  border: 2px solid #2e2e2e;
}
body::-webkit-scrollbar-thumb:hover {
  background-color: #777;
}

/* ---------- Header Controls ---------- */
.header-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  width: 100%;
  padding: 10px 20px;
  background-color: var(--header-controls);
  position: sticky;
  top: 0;
  z-index: 10;
  box-sizing: border-box;
}

.right-controls {
  display: flex;
  gap: 10px;
}

/* Theme toggle wrapper (right aligned) */
.theme-toggle-wrapper {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  padding: 8px 20px;
  box-sizing: border-box;
}

/* ---------- Button Styles ---------- */
.theme-btn,
.danger-btn,
.logout-btn,
.primary-btn,
.icon-btn {
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  border: none;
  border-radius: 5px;
  color: white;
  transition: background-color 0.3s ease;
}

.theme-btn {
  background-color: #444;
}
.theme-btn:hover {
  background-color: #666;
}

.danger-btn {
  background-color: #e74c3c;
}
.danger-btn:hover {
  background-color: #b71c1c;
}

.logout-btn {
  background-color: #3498db;
}
.logout-btn:hover {
  background-color: #217dbb;
}

.primary-btn {
  background-color: #2979ff;
}
.primary-btn:hover {
  background-color: #005ce6;
}

.icon-btn {
  background-color: #555;
}
.icon-btn:hover {
  background-color: #777;
}

/* ---------- Chat Container ---------- */
.chat-container {
  width: 90vw;
  max-width: 90vw;
  height: 55vh;
  background-color: var(--chat-bg);
  border-radius: 8px;
  overflow-y: auto;
  padding: 15px;
  margin: 15px 0;
  margin-top: 10vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  box-sizing: border-box;
}

/* Scroll inside chat */
.chat-container::-webkit-scrollbar {
  width: 10px;
}
.chat-container::-webkit-scrollbar-track {
  background: #2e2e2e;
  border-radius: 10px;
}
.chat-container::-webkit-scrollbar-thumb {
  background-color: #555;
  border-radius: 10px;
  border: 2px solid #2e2e2e;
}
.chat-container::-webkit-scrollbar-thumb:hover {
  background-color: #777;
}

/* ---------- Chat Messages ---------- */
.chat-message {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 1.05rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  display: inline-block;
  position: relative;
}

.chat-message.user {
  background-color: #2979ff;
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  margin-left: auto;
}

.chat-message.ai {
  background-color: var(--ai-bg);
  color: var(--ai-color);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  margin-right: auto;
}

.chat-message.ai.thinking {
  font-style: italic;
  opacity: 0.7;
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: "Thinking"; }
  40% { content: "Thinking."; }
  60% { content: "Thinking.."; }
  80%, 100% { content: "Thinking..."; }
}

/* Markdown code styling */
.chat-message pre {
  background: #1e1e1e;
  color: #e0e0e0;
  padding: 1em;
  border-radius: 8px;
  overflow-x: auto;
  font-family: Consolas, monospace;
  white-space: pre-wrap;
  margin: 0.5em 0;
}

.chat-message strong {
  font-weight: bold;
  color: #ffaa00;
}

/* System messages */
.system-chat-box {
  background-color: #444;
  color: #eee;
  align-self: center;
  font-size: 0.9em;
  padding: 8px 12px;
  border-radius: 12px;
  max-width: 80%;
}

/* ---------- Chat Input Area ---------- */
.chat-input-area {
  width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

#prompt {
  width: 100%;
  min-height: 60px;
  padding: 10px;
  font-size: 1rem;
  border-radius: 5px;
  border: none;
  outline: none;
  resize: none;
  background-color: var(--prompt-bg);
  color: var(--text-color);
  box-sizing: border-box;
}

.buttons {
  display: flex;
  gap: 10px;
  width: 100%;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .header-controls {
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
  }

  .chat-message.user,
  .chat-message.ai {
    max-width: 85vw;
    font-size: 1rem;
  }

  .chat-input-area,
  .buttons {
    width: 100%;
  }
}

.buttons {
  display: flex;
  width: 100%;
  gap: 10px;
  justify-content: space-between;
}

.buttons button {
  flex: 1;
  padding: 10px;
  font-size: 1rem;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-weight: bold;
  background-color: #2979ff;
  color: white;
  transition: background-color 0.3s ease;
}

.buttons button:hover {
  background-color: #005ce6;
}

.chat-message {
  white-space: pre-wrap;
  line-height: 1.6;
}

/* Make all chat input buttons equal width */
.chat-input-area .buttons {
  display: flex;
  gap: 10px;
}

.chat-input-area .buttons > * {
  flex: 1; /* Equal width for all buttons */
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#EchoAI{
  position: absolute;
  left: 0;
  margin-left: 10px;
  font-size: 1.5em;
  display: inline-block;
  font-weight: 900;
}

#AIInEchoAI{
  color: var(--accent-color);
}

.file-preview {
  margin-top: 5px;
  color: #ccc;
}

.file-tag {
  background: var(--file-tag-bg);
  display: inline-block;
  padding: 5px 10px;
  border-radius: 20px;
  margin-top: 5px;
}

.remove-file-btn {
  background: var(--remove-btn-color);
  color: white;
  border: none;
  border-radius: 50%;
  margin-left: 8px;
  cursor: pointer;
}

.theme-btn {
  position: fixed;
  top: 80px;
  right: 20px;
  font-size: 1.5em;
  padding: 10px;
  border: none;
  background-color: var(--text-color, #eee);
  color: var(--bg-color, #121212);
  border-radius: 5px;
  cursor: pointer;
  z-index: 1000;
}

.theme-btn {
  background-color: var(--text-color);
}
.theme-btn:hover {
  background-color: var(--text-color);
}

.prompt-box {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1.4;
  overflow-y: auto;
  white-space: pre-wrap;
}
.prompt-box:empty:before {
  content: attr(placeholder);
  color: #999;
}
.file-tag {
  display: inline-block;
  background: #e0e0e0;
  border-radius: 6px;
  padding: 4px 8px;
  margin: 4px 2px;
  font-size: 14px;
}
.remove-file-btn {
  cursor: pointer;
  margin-left: 8px;
  color: red;
  font-weight: bold;
}

#backBtn{
  position: absolute;
  left: 0;
  margin-left: 2vw;
  cursor: pointer;
  font-size: 1.5em;
  border-radius: 12.5%;
}

.file-tag {
  background: var(--file-tag-bg);
  color: var(--file-tag-text);
  border-radius: 16px;
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  margin: 4px;
}

.remove-file-btn {
  margin-left: 8px;
  background: transparent;
  color: var(--remove-btn-color);
  border: none;
  font-size: 16px;
  cursor: pointer;
}

.file-tag:hover {
  background-color: #555;
  transition: background 0.2s ease;
}
.remove-file-btn:hover {
  color: #ff0000;
}

#filePreviewContainer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.file-preview-card {
  display: inline-flex;
  align-items: center;
  background-color: #eee;
  color: #333;
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.9rem;
  user-select: none;
}

.dark-mode .file-preview-card {
  background-color: #2e2e2e;
  color: #fff;
}

.file-icon {
  margin-right: 6px;
}

.file-name {
  margin-right: 8px;
  font-weight: 500;
}

.remove-file-btn {
  background: transparent;
  border: none;
  color: red;
  font-size: 1rem;
  cursor: pointer;
}

.file-tag {
  display: inline-block;
  background-color: #ddd;
  color: #222;
  border-radius: 16px;
  padding: 2px 8px;
  margin: 2px 4px;
  font-size: 0.85rem;
  user-select: none;
}

.dark-mode .file-tag {
  background-color: #333;
  color: #eee;
}

.remove-file-btn {
  margin-left: 6px;
  color: red;
  cursor: pointer;
  font-weight: bold;
}

.file-tag {
  display: inline-block;
  background-color: #ddd;
  color: #000;
  padding: 3px 8px;
  border-radius: 16px;
  margin: 2px 4px;
  user-select: none;
  pointer-events: auto;
}

.remove-file-btn {
  margin-left: 6px;
  color: red;
  font-weight: bold;
  cursor: pointer;
}

.dark-mode .file-tag {
  background-color: #333;
  color: #fff;
}

.file-tag {
  background-color: #e0e0e0;
  border-radius: 4px;
  padding: 4px 8px;
  margin: 2px;
  display: inline-block;
  user-select: none;
  pointer-events: auto;
}

.file-tag[contenteditable="false"] {
  cursor: default;
}

.file-tag {
  background: #eee;
  border-radius: 8px;
  padding: 4px 8px;
  margin: 4px;
  display: inline-block;
}

.remove-file-btn {
  margin-left: 6px;
  cursor: pointer;
  color: red;
}

.buttons button,
.primary-btn,
.icon-btn {
  height: 42px; /* fixed height */
  font-size: 14px;
  flex: 1;
  min-width: 110px;
  border-radius: 5px;
  border: none;
  color: white;
  background-color: #2979ff;
  cursor: pointer;
  transition: background-color 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.disabled {
  opacity: 0.6;
  pointer-events: none;
}
