:root {
  --bg-primary: #0f1116;
  --bg-secondary: #18191f;
  --bg-tertiary: #202123;
  --text-primary: #ececf1;
  --text-secondary: #9ca3af;
  --accent: #5a75e6;
  --accent-hover: #4a62d3;
  --user-msg: #434654;
  --assistant-msg: #343541;
  --border-color: #383942;
  --transition: all 0.3s ease;
  --glow: 0 0 15px rgba(90, 117, 230, 0.5);
  --glass-bg: rgba(25, 28, 39, 0.6);
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg-primary);
  font-family: 'Poppins', sans-serif;
  color: var(--text-primary);
  height: 100vh; /* Full viewport height */
  width: 100vw; /* Full viewport width */
  margin: 0;
  padding: 0;
  transition: var(--transition);
  position: relative;
  overflow: hidden; /* Prevent scrolling */
  overscroll-behavior: none; /* Prevent bounce effects */
}

body::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(125deg, #192339 0%, #0f0f17 40%, #1a1d29 70%, #151823 100%);
  z-index: -2;
}

body::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  right: -50%;
  bottom: -50%;
  background: radial-gradient(circle, rgba(90, 117, 230, 0.1) 0%, rgba(15, 17, 22, 0) 70%);
  z-index: -1;
  animation: pulse-glow 15s infinite alternate;
}

@keyframes pulse-glow {
  0% { transform: translate(20%, 20%); opacity: 0.5; }
  50% { transform: translate(-10%, -10%); opacity: 0.7; }
  100% { transform: translate(-30%, 10%); opacity: 0.5; }
}

#chat {
  flex: 1;
  overflow-y: auto; /* Allow scrolling only within the chat area */
  padding: 1.5rem;
  border: var(--glass-border);
  border-radius: 16px;
  background-color: var(--glass-bg);
  margin-bottom: 1rem;
  scroll-behavior: smooth;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--glass-shadow);
  position: relative;
  max-height: calc(100vh - 140px); /* Ensure chat area doesn't push content out of viewport */
}

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

#chat::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 8px;
}

#chat::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 8px;
}

/* Style all links inside the chat area */
#chat a {
  color: #2563eb;              /* Nice blue color */
}

/* Heading styles for proper markdown */
#chat h1, #chat .msg h1 {
  font-size: 2em;
  font-weight: 700;
  margin: 0.2em 0 0.1em; /* Further reduced margins */
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.1em; /* Also reduced padding slightly */
}

#chat h2, #chat .msg h2 {
  font-size: 1.75em;
  font-weight: 600;
  margin: 0.15em 0 0.05em; /* Further reduced margins */
  color: var(--text-primary);
}

#chat h3, #chat .msg h3 {
  font-size: 1.5em;
  font-weight: 600;
  margin: 0.15em 0 0.05em; /* Further reduced margins */
  color: var(--text-primary);
}

#chat h4, #chat .msg h4 {
  font-size: 1.25em;
  font-weight: 600;
  margin: 0.1em 0 0.05em; /* Further reduced margins */
  color: var(--text-primary);
}

#chat h5, #chat .msg h5 {
  font-size: 1.1em;
  font-weight: 600;
  margin: 0.1em 0 0.05em; /* Further reduced margins */
  color: var(--text-primary);
}

#chat h6, #chat .msg h6 {
  font-size: 1em;
  font-weight: 600;
  margin: 0.1em 0 0.05em; /* Further reduced margins */
  color: var(--text-primary);

  text-decoration: none;  /* Underline for clarity */
  font-weight: 500;            /* Slightly bolder */
  transition: color 0.2s;
  word-break: break-all;
  /* Prevent overflow for long URLs */
}

#chat a:hover {
  color: #254cce;              /* Darker blue on hover */
  text-decoration: underline;        /* Subtle background highlight on hover */
}

/* General styling for pre-formatted text and inline code within messages */
#chat .msg pre {
  background-color: var(--bg-tertiary); /* Match themed code blocks */
  color: var(--text-primary);
  padding: 1em;
  margin: 0.5em 0;
  border-radius: 8px;
  overflow-x: auto; /* For long lines */
  font-family: 'Fira Code', 'Consolas', 'Monaco', 'Andale Mono', 'Ubuntu Mono', monospace;
  font-size: 0.9em;
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* For inline code (e.g., `code`) not part of a pre.code-block */
#chat .msg code {
  background-color: var(--bg-secondary);
  color: var(--accent);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-family: 'Fira Code', 'Consolas', 'Monaco', 'Andale Mono', 'Ubuntu Mono', monospace;
  font-size: 0.85em;
}

/* Ensure code tags inside our styled 'pre' don't get double styling */
#chat .msg pre > code {
  background-color: transparent;
  color: inherit; /* Inherit color from the parent 'pre' */
  padding: 0;
  border-radius: 0;
  font-size: inherit; /* Inherit font size from the parent 'pre' */
}

.msg {
  margin-bottom: 1.25rem;
  padding: 1.25rem;
  border-radius: 18px;
  white-space: pre-wrap;
  animation: fadeIn 0.5s ease;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.msg-image {
  max-width: 60%; /* Changed from 100% to 60% to make images smaller in chat */
  max-height: 300px; /* Added max-height to limit very tall images */
  border-radius: 12px;
  margin: 8px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;
  object-fit: contain; /* Ensures image maintains aspect ratio */
}

.msg-image:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.image-container {
  position: relative;
  display: inline-block;
  margin: 8px 0;
}

.image-loading {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 12px;
  color: white;
  font-size: 0.9rem;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}


.msg:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

/* Code blocks styling */
.code-block {
  background-color: #f6f8fa;
  border-radius: 6px;
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  line-height: 1.45;
  border: 1px solid #ddd;
  color: #333;
  width: 100%;
}

code {
  background-color: #f1f1f1;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9em;
  color: #333;
}

/* Citation and source links styling */
.citation-link {
  display: block;
  margin-top: 8px;
  padding: 6px 10px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  border-left: 3px solid var(--accent);
}

.citation-link a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.citation-link a:hover {
  text-decoration: underline;
}

/* Download button styling */
.download-button {
  display: inline-block;
  margin: 8px 0;
  padding: 8px 12px;
  background-color: #4CAF50;
  color: white;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 500;
  transition: background-color 0.3s;
}

.download-button:hover {
  background-color: #45a049;
  text-decoration: none;
}

/* Animated cursor for typing effect */
.typing-animation::after {
  content: '|';
  display: inline-block;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Text-to-speech button styling */
.speech-button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  opacity: 0.7;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

.speech-button:hover {
  opacity: 1;
  transform: scale(1.1);
  box-shadow: var(--glow);
}

.speech-button.speaking {
  animation: speech-pulse 1.5s infinite;
  opacity: 1;
}

@keyframes speech-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.msg.user {
  background-color: var(--user-msg);
  color: var(--text-primary);
  align-self: flex-end;
  margin-left: auto;
  border-radius: 18px;
  border-bottom-right-radius: 0;
  position: relative;
  max-width: 80%;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  padding-top: 40px;
}

.user::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 4px;
  background: linear-gradient(to bottom, var(--accent), transparent);
  opacity: 0.8;
}

.user::after {
  content: 'User';
  position: absolute;
  top: 10px;
  left: 15px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background-color: rgba(90, 117, 230, 0.1);
  padding: 3px 10px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 5;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(90, 117, 230, 0.2);
}

.msg.assistant {
  background-color: transparent;
  color: var(--text-primary);
  align-self: stretch;
  width: calc(100% - 10px);
  max-width: calc(100% - 10px);
  margin-left: 5px;
  margin-right: 5px;
  position: relative;
  box-shadow: none;
  padding: 10px 15px;
  overflow-wrap: break-word;
  word-wrap: break-word;
  line-height: 1.4;
}

.msg.assistant p {
  margin-bottom: 0.8em;
  margin-top: 0.8em;
}

.msg.assistant p:first-child {
  margin-top: 0;
}

/* Style for the 'Response stopped by user' message */
.msg.assistant .response-stopped {
    color: #e74c3c;
    font-style: italic;
    font-weight: 500;
    border-left: 3px solid #e74c3c;
    padding-left: 10px;
    background-color: rgba(231, 76, 60, 0.05);
    padding: 8px 12px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 5px;
}

.assistant {
  align-self: stretch;
  width: calc(100% - 10px);
  max-width: calc(100% - 10px);
  margin-left: 5px;
  margin-right: 5px;
  padding: 40px 15px 15px 15px;
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 0;
  overflow-wrap: break-word;
  word-wrap: break-word;
  line-height: 1.3;
}

.assistant::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 4px;
  background: linear-gradient(to bottom, var(--accent), transparent);
  opacity: 0.8;
}

/* Bot label for assistant messages */
.assistant::after {
  position: absolute;
  top: 8px;
  left: 15px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background-color: rgba(90, 117, 230, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  z-index: 5;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Pulsing dot to indicate it's an AI response */
.bot-indicator {
  display: inline-flex;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--accent);
  background-color: rgba(90, 117, 230, 0.1);
  padding: 4px 10px;
  border-radius: 12px;
  align-self: flex-start;
  font-size: 13px;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.bot-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: var(--accent);
  border-radius: 50%;
  margin-right: 6px;
  animation: pulse 1.5s infinite;
}

/* Message content container */
.message-content {
  width: 100%;
}

@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.5; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.8); opacity: 0.5; }
}

.code-container {
  position: relative;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  border-radius: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: rgba(30, 30, 40, 0.6);
  border-bottom: 1px solid var(--border-color);
  font-family: 'Poppins', sans-serif;
  font-size: 0.85rem;
}

.code-language {
  color: var(--accent);
  font-weight: 600;
}

.copy-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: var(--transition);
}

.copy-btn:hover {
  color: var(--accent);
  background: rgba(255, 255, 255, 0.05);
}

.copy-btn i {
  font-size: 1rem;
}

.copy-success {
  color: #50fa7b !important;
}

.code {
  background: var(--bg-primary);
  color: #ffffff;
  padding: 1rem;
  overflow-x: auto;
  white-space: pre;
  font-family: 'Fira Code', monospace;
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.code-explanation {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: rgba(90, 117, 230, 0.1);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-style: italic;
}

#form {
  padding: 0.75rem 1rem;
  background: var(--glass-bg);
  border-radius: 1rem;
  border: var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--glass-shadow);
  position: relative;
  z-index: 10;
  margin-top: auto;
}

.input-container {
  position: relative;
  width: 100%;
  display: flex;
}

#input {
  flex: 1;
  padding: 1rem 5rem 1rem 1.25rem; /* Changed right padding from 2.75rem to 5rem to make space for thumbnail and buttons */
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  outline: none;
  transition: var(--transition);
  font-size: 1rem;
  font-family: 'Poppins', sans-serif;
  letter-spacing: 0.2px;
  height: 120px;
  resize: none;
  column-count: 3;
  column-gap: 15px;
  column-rule: 1px solid var(--border-color);
  overflow-y: auto;
  line-height: 1.5;
  box-sizing: border-box;
  width: 100%;
}

.image-thumbnail-container {
  position: absolute;
  top: 10px;
  right: 60px; /* Changed from left: 10px to right: 60px to position it on the right side */
  width: 50px; /* Reduced from 60px to 50px */
  height: 50px; /* Reduced from 60px to 50px */
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  z-index: 3;
  background-color: var(--bg-secondary);
}

.image-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: all 0.2s ease;
}

.image-thumbnail-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  opacity: 0.8;
  transition: all 0.2s ease;
}

.image-thumbnail-remove:hover {
  opacity: 1;
  background-color: rgba(231, 76, 60, 0.8);
}

#input:focus {
  border-color: var(--accent);
  box-shadow: var(--glow);
}

.input-submit-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background-color: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 2;
  padding: 0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.input-submit-btn:hover {
  background-color: var(--accent-hover);
  transform: scale(1.05);
  box-shadow: var(--glow);
}

.input-submit-btn:active {
  transform: scale(0.95);
}

.input-submit-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  transition: all 0.3s ease;
}

.image-upload-btn {
  position: absolute;
  right: 12px;
  bottom: 58px;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 2;
  padding: 0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.image-upload-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.05);
  box-shadow: var(--glow);
}

.image-upload-btn:active {
  transform: scale(0.95);
}

.image-upload-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  transition: all 0.3s ease;
}

/* Stop button styling */
.input-submit-btn.stop-button {
  background-color: #e74c3c;
  animation: pulse 1.5s infinite;
}

.input-submit-btn.stop-button:hover {
  background-color: #c0392b;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.input-submit-btn.stop-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(231, 76, 60, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0);
  }
}


/* Submit button styles for the new inline button */

.thinking {
  color: var(--text-secondary);
  font-style: italic;
  margin: 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: pulse 1.5s infinite;
  padding: 1rem 1.25rem;
  border-radius: 18px;
  max-width: 50%;
  background-color: var(--assistant-msg);
  position: relative;
}

.searching {
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
  padding: 1rem 1.25rem;
  border-radius: 18px;
  max-width: 50%;
  background-color: var(--assistant-msg);
  position: relative;
  border-left: 4px solid var(--accent);
}

.searching i {
  color: var(--accent);
  animation: spin 1.5s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.thinking::after {
  content: '';
  height: 20px;
  width: 20px;
  background: radial-gradient(circle, var(--accent) 3px, transparent 0),
             radial-gradient(circle, var(--accent) 3px, transparent 0),
             radial-gradient(circle, var(--accent) 3px, transparent 0);
  background-position: 0px center, 10px center, 20px center;
  background-size: 20px 20px;
  background-repeat: no-repeat;
  opacity: 0.8;
  animation: dots 1.5s infinite steps(1);
  margin-left: 5px;
}

@keyframes dots {
  0% { background-position: 0px center, 10px center, 20px center; }
  25% { background-position: 10px center, 20px center, 0px center; }
  50% { background-position: 20px center, 0px center, 10px center; }
  75% { background-position: 0px center, 20px center, 10px center; }
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

h5 {
  margin-left: 20px;
  color: var(--text-secondary);
  margin-top: 3%;
}

/* Mobile elements are hidden by default on desktop */
.mobile-only {
  display: none;
}

/* Disclaimer message styling */
.disclaimer {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.6rem;
  margin-top: 0.5rem;
  padding: 0.25rem 0.5rem;
 
  border-radius: 0.5rem;
  font-style: italic;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(90, 117, 230, 0.2);
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}

/* Desktop Sidebar Toggle Button */
.desktop-only-flex {
  display: none; /* Hidden by default, shown via media query */
}

#desktop-sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  margin-right: 1rem; /* Space from other header items */
  transition: color 0.2s ease;
}

#desktop-sidebar-toggle:hover {
  color: var(--accent);
}

/* Sidebar and Main Content Transitions */
.sidebar {
  transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1),
              width 0.4s cubic-bezier(0.25, 0.8, 0.25, 1),
              padding 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.main-content {
  transition: margin-left 0.4s cubic-bezier(0.25, 0.8, 0.25, 1),
              width 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Collapsed State - applied to .app-container */
.app-container.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  width: 0;
  padding: 0;
  overflow: hidden;
  border-right: none; /* Hide border when collapsed */
}

.app-container.sidebar-collapsed .main-content {
  margin-left: 0;
  width: 100%; /* Take full width when sidebar is closed */
}

/* Responsive Media Queries */
@media (min-width: 1024px) { /* Desktop and larger screens */
  .desktop-only-flex {
    display: flex; /* Show the desktop toggle button */
    align-items: center;
  }
  .mobile-only {
    display: none !important; /* Ensure mobile toggles are hidden on desktop */
  }
}

@media (max-width: 1023px) { /* Tablets and below - adjust as needed */
  #desktop-sidebar-toggle {
    display: none; /* Hide desktop toggle on smaller screens */
  }

  /*
    Default state for sidebar on mobile/tablet:
    - It should be positioned off-screen.
    - It must have its defined width (e.g., 280px), not width:0 from desktop's collapsed state.
    - It must have its border and overflow properties correctly set, overriding desktop's collapsed state.
  */
  .app-container .sidebar {
    transform: translateX(-100%); /* Position off-screen */
    width: 280px;                 /* Ensure it has width (overrides desktop collapse width:0) */
    padding: initial;             /* Reset padding if desktop collapse set it to 0 */
    border-right: var(--glass-border); /* Ensure border is visible (overrides desktop collapse border:none) */
    overflow-y: auto;             /* Allow vertical scrolling (overrides desktop collapse overflow:hidden) */
    overflow-x: hidden;           /* Prevent horizontal scrolling */
  }

  /*
    When mobile menu opens (.sidebar-open is on .app-container):
    - Slide sidebar into view.
    - Ensure its width, padding, border, and overflow are correctly set for an open, functional mobile sidebar.
  */
  .app-container.sidebar-open .sidebar {
    transform: translateX(0);     /* Slide into view */
    /* Width, padding, border, overflow are primarily defined by the rule above for mobile.
       This rule mainly handles the transform. We can re-affirm if there are specificity concerns. */
    width: 280px;                 /* Re-affirm width */
    padding: initial;             /* Re-affirm padding reset */
    border-right: var(--glass-border); /* Re-affirm border */
    overflow-y: auto;             /* Re-affirm scrolling */
    overflow-x: hidden;
  }

  /*
    If desktop's .sidebar-collapsed class is present on .app-container during mobile view:
    - Its effects on .main-content (margin-left, width) are generally fine for mobile as main content takes full width.
    - Its effects on .sidebar (transform, width, padding, border, overflow) are handled/overridden by the mobile-specific rules above.
  */
  .app-container.sidebar-collapsed .main-content {
    margin-left: 0; /* Mobile main content is already at margin-left: 0 */
    width: 100%;    /* Mobile main content is already at width: 100% */
  }
}

@media (max-width: 768px) {
  body {
    padding: 0; /* Remove padding on mobile */
    height: 100%; /* Use % instead of vh units */
    position: fixed; /* Fix the body to prevent scroll */
    width: 100%;
  }

  .disclaimer {
    display: none;
    display: flex;
    margin-bottom: 10px;
    position: relative;
}

.message.right {
    justify-content: flex-end;
}

.message.system {
    text-overflow: ellipsis;
    max-width: 150px;
  }
  
  /* Show mobile elements on mobile screens */
  .mobile-only {
    display: block;
  }
  /* Ensure desktop toggle is definitely hidden on mobile */
  .desktop-only-flex {
    display: none !important;
  }

  /* Mobile sidebar styles */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    transform: translateX(-100%);
    width: 250px;
    height: 100%; /* Use % instead of vh */
    max-height: 100%; /* Ensure it doesn't exceed container */
    background-color: var(--bg-tertiary);
    overflow-y: auto; /* Allow scrolling within sidebar if needed */
  }
  
  .sidebar-open {
    transform: translateX(0);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
  }
  
  
  
  #mobile-menu {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    
    min-width: 40px;
    height: 40px;
  }
  
  #mobile-close {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    margin-left: auto;
  }
  
  #chat-container {
    padding: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent container scrolling */
    height: 100%;
    background: transparent;
    border: none;
    box-shadow: none;
    margin: 0;
  }
  
  #chat {
    border: none;
    border-radius: 0;
    background-color: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
    max-height: none;
    height: 100%;
  }
  
  header {
    background: transparent;
    border-bottom: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
    margin-bottom: 0;
  }
  
  .msg.user {
    margin-right: 10px;
    margin-left: auto;
    max-width: 80%;
    width: auto;
    align-self: flex-end;
  }
  
  .msg.assistant, .assistant {
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    background-color: transparent;
  }
  
  #form {
    width: 100%;
    max-width: 100%;
  }
}

/* App container */
.app-container {
  display: flex;
  height: 100%; /* Use 100% instead of 100vh to respect parent constraints */
  width: 100%;
  max-height: 100vh; /* Ensure it doesn't exceed viewport height */
  overflow: hidden; /* Prevent container scrolling */
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-tertiary);
  border-right: var(--glass-border);
  display: flex;
  flex-direction: column;
  height: 100%;
  transform: translateX(0); /* Explicit open state */
  /* Transition will be handled by the rule below */
}

.sidebar-header {
  display: flex;
  align-items: center;
  padding: 1rem;
  border-bottom: var(--glass-border);
}

.logo-small {
  font-size: 1.5rem;
  margin-right: 0.5rem;
  color: var(--accent);
}

.sidebar-header h2 {
  font-size: 1.2rem;
  font-weight: 500;
}

/* Sidebar theme toggle */
.sidebar-theme-toggle {
  display: flex;
  justify-content: left;
  margin: 0.5rem 0;
  margin-left: 10px;
  padding: 0.5rem;
  border-bottom: var(--glass-border);
}

.sidebar .theme-toggle {
  background: var(--accent);
  color: white;
}

.new-chat-btn {
  margin: 1rem;
  padding: 0.75rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 80%;
  font-weight: 500;
  transition: var(--transition);
}

.new-chat-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: var(--glow);
}

.history-label {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-bottom: var(--glass-border);
  margin-top: 0.5rem;
}

.chat-history {
  overflow-y: auto;
  flex-grow: 1;
  padding: 0.5rem;
}

.chat-item {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass-bg);
  border: var(--glass-border);
  overflow: hidden;
  position: relative;
}

/* Chat item content */
.chat-item-content {
  flex-grow: 1;
  overflow: hidden;
  cursor: pointer;
  max-width: 80%;
}

/* Ellipsis menu */
.chat-item-actions {
  position: relative;
  z-index: 10;
}

.ellipsis-menu {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.7;
  transition: var(--transition);
  border-radius: 50%;
}

.ellipsis-menu:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

/* Dropdown menu */
.dropdown-menu {
  position: fixed; /* Changed from absolute to fixed */
  width: 150px;
  background: rgba(30, 30, 45, 0.95);
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: none;
  overflow: hidden;
  transform-origin: top right;
  /* These values will be set via JavaScript */
}

.dropdown-menu.show {
  display: block;
  animation: dropdownFadeIn 0.3s ease-out forwards;
}

@keyframes dropdownFadeIn {
  from { 
    opacity: 0; 
    transform: translateY(-10px) scale(0.95); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0) scale(1); 
  }
}

.dropdown-item {
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
}

.dropdown-item:hover {
  background: var(--user-msg);
  color: var(--text-primary);
}

.dropdown-item.rename i {
  color: var(--accent);
}

.dropdown-item.delete i {
  color: #ff4757;
}

.dropdown-item.delete:hover {
  color: #ff4757;
  background: rgba(255, 71, 87, 0.1);
}

/* Animation for dropdown */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Modal styles */
.rename-modal,
.delete-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: modalFadeIn 0.3s ease-out;
}

.rename-modal-content,
.delete-modal-content {
  width: 90%;
  max-width: 400px;
  background: var(--glass-bg);
  border-radius: 1rem;
  border: var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--glass-shadow);
  padding: 1.5rem;
  animation: modalContentSlideIn 0.3s ease-out;
}

/* Modal animations */
@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalContentSlideIn {
  from { transform: translateY(-30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Modal headings */
.rename-modal-content h3,
.delete-modal-content h3 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
  font-size: 1.4rem;
  font-weight: 500;
}

.delete-modal-content p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

/* Modal input */
#rename-input {
  width: 100%;
  padding: 0.75rem;
  border-radius: 0.5rem;
  border: var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  font-family: 'Poppins', sans-serif;
  transition: var(--transition);
}

#rename-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(90, 117, 230, 0.3);
}

/* Modal buttons */
.rename-modal-buttons,
.delete-modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.rename-modal-buttons button,
.delete-modal-buttons button {
  padding: 0.75rem 1.25rem;
  border-radius: 0.5rem;
  font-family: 'Poppins', sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: none;
}

#rename-cancel,
#delete-cancel {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
}

#rename-cancel:hover,
#delete-cancel:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

#rename-save {
  background: var(--accent);
  color: white;
}

#rename-save:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: var(--glow);
}

#delete-confirm {
  background: #ff4757;
  color: white;
}

#delete-confirm:hover {
  background: #ff3748;
  transform: translateY(-2px);
  box-shadow: 0 0 15px rgba(255, 71, 87, 0.5);
}

.chat-item:hover {
  background: var(--user-msg);
}

.chat-item.active {
  background: var(--accent);
  color: white;
}

.chat-item-content {
  flex-grow: 1;
  overflow: hidden;
}

.chat-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.chat-item-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Main content area */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

header {
  display: flex;
  padding: 0.75rem 1.25rem;
  margin-bottom: 0.5rem;
  position: relative;
  background: var(--glass-bg);
  border: var(--glass-border);
  box-shadow: var(--glass-shadow);
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: transparent;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

#chat-container {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 160px);
}

.logo {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.75rem;
  text-align: center;
}

.logo-icon {
  font-size: 1.75rem;
  color: var(--accent);
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.logo h1 {
  font-size: 1.2rem;
  font-weight: 600;
  background: linear-gradient(90deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0;
}

nav {
  display: flex;
  gap: 1rem;
}

.nav-item {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  transition: var(--transition);
  font-size: 0.9rem;
}

.nav-item:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.theme-toggle {
  background: var(--glass-bg);
  border: var(--glass-border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
  font-size: 1.1rem;
  padding: 0;
}

.theme-toggle:hover {
  color: var(--accent);
  background: rgba(255, 255, 255, 0.05);
  transform: rotate(30deg);
}

header h1 {
  color: var(--accent);
  font-size: 1.8rem;
  margin: 0;
}

header nav ul {
  list-style: none;
  display: flex;
  gap: 1.5rem;
}

header nav ul li a {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

header nav ul li a:hover {
  color: var(--accent);
}

