/* ============================================ */
/* ULTRA FIXED THEME STABILITY - ZERO FLASHES */
/* ============================================ */

/* PERFECT KEYBOARD SOLUTION */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background-color: transparent;
}

body {
  height: 100dvh;
  transition: height 0.25s ease-out;
}

/* KILL ALL TRANSITIONS FOR PLACEHOLDERS */
.chat-textarea::placeholder {
  color: #999 !important;
  opacity: 1 !important;
  transition: none !important;
  animation: none !important;
  -webkit-transition: none !important;
  -webkit-animation: none !important;
}

body.light-theme .chat-textarea::placeholder {
  color: #999 !important;
  opacity: 1 !important;
  transition: none !important;
  animation: none !important;
  -webkit-transition: none !important;
  -webkit-animation: none !important;
}

body.dark-theme .chat-textarea::placeholder {
  color: #999 !important;
  opacity: 1 !important;
  transition: none !important;
  animation: none !important;
  -webkit-transition: none !important;
  -webkit-animation: none !important;
}

/* COMPLETELY DISABLE transitions until theme is loaded */
body:not(.theme-loaded) * {
  transition: none !important;
  animation: none !important;
  -webkit-transition: none !important;
  -webkit-animation: none !important;
}

/* Remove transitions from textarea completely */
.chat-textarea {
  transition: none !important;
  animation: none !important;
}

/* ============================================ */
/* REST OF YOUR EXISTING STYLES */
/* ============================================ */

/* IMMEDIATE THEME APPLICATION - NO TRANSITIONS INITIALLY */
:root {
  --bg-color: #121212;
  --text-color: #f5f5f5;
  --secondary-bg: #1e1e1e;
  --border-color: #333333;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --hover-bg: #2a2a2a;
  --message-bg: #1e1e1e;
  --sidebar-bg: #181818;
  --user-message-bg: #2a2a2a;
  --toast-bg: #f3f4f6;
  --toast-text: #1f2937;
  --text-secondary: #a0a0a0;
  --text-primary: #f5f5f5;
  --app-bg: #121212;
  --default-btn-bg: #1e1e1e;
  --primary-color: linear-gradient(45deg, #ff6b35, #8b5cf6);
  --caret-color: #ff6b35;
}

/* Apply dark theme IMMEDIATELY without any transition */
html.dark-theme,
html {
  background-color: #121212 !important;
  height: 100%;
  transition: none !important;
}

body.dark-theme,
body {
  background-color: #121212 !important;
  color: #f5f5f5 !important;
  margin: 0;
  padding: 0;
  transition: none !important;
  min-height: 100%;
  font-family: 'Poppins', sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Light mode variables */
body.light-theme {
  --bg-color: #ffffff;
  --text-color: #000000;
  --secondary-bg: #f8f9fa;
  --border-color: #e2e8f0;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --hover-bg: #f1f5f9;
  --message-bg: #ffffff;
  --sidebar-bg: #f8fafc;
  --user-message-bg: #f1f5f9;
  --toast-bg: #1f2937;
  --toast-text: #ffffff;
  --text-secondary: #666666;
  --text-primary: #000000;
  --app-bg: #ffffff;
  --default-btn-bg: var(--secondary-bg);
}

/* Apply light theme */
body.light-theme {
  background-color: #ffffff !important;
  color: #000000 !important;
}

/* Hide everything until theme is fully applied */
body:not(.theme-loaded) .main-content,
body:not(.theme-loaded) .header,
body:not(.theme-loaded) .side-page {
  opacity: 0;
}

body.theme-loaded .main-content,
body.theme-loaded .header,
body.theme-loaded .side-page {
  opacity: 1;
  transition: opacity 0.15s ease;
}

/* Prevent FOUC */
.hidden {
  display: none !important;
}

/* FIXED: Keyboard detachment flash prevention */
.chat-input-bar {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  perspective: 1000;
  -webkit-perspective: 1000;
  will-change: transform;
}

/* Enable smooth transitions only after theme is loaded */
body.theme-loaded {
  transition: background-color 0.3s ease, color 0.3s ease !important;
}

body.theme-loaded * {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}

/* ADDED: Completely exclude textarea and placeholder from ALL transitions */
body.theme-loaded .chat-textarea,
body.theme-loaded .chat-textarea::placeholder {
  transition: none !important;
  animation: none !important;
}

/* ============================================ */
/* UPDATED FEEDBACK SYSTEM STYLES - TEMPORARY GRADIENT */
/* ============================================ */

.feedback-container {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

.feedback-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.feedback-btn:hover {
  background: var(--hover-bg);
  color: var(--text-color);
  transform: scale(1.05);
}

.feedback-btn.active {
  background: linear-gradient(135deg, #ff6b35, #8b5cf6);
  color: white;
  border-color: transparent;
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

.feedback-btn i {
  width: 16px;
  height: 16px;
  transition: all 0.3s ease;
}

/* ============================================ */
/* FIXED FEEDBACK TOAST - SAME AS OTHER TOASTS */
/* ============================================ */

#feedbackToast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 12px 20px;
  border-radius: 12px;
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem;
  box-shadow: 0 4px 12px var(--shadow-color);
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: auto;
  max-width: 300px;
  text-align: center;
  z-index: 3000;
}

#feedbackToast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Remove the old feedback toast styles that were conflicting */
.feedback-toast {
  display: none !important;
}

/* ============================================ */
/* FILE PREVIEW LOADING SPINNERS - ADDED */
/* ============================================ */
.file-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  z-index: 10;
}

.file-loading-overlay.hidden {
  display: none;
}

.file-loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid transparent;
  border-top: 2px solid #ff6b35;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.file-type-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

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

/* ============================================ */
/* REST OF YOUR STYLES */
/* ============================================ */

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100dvh;
  font-family: 'Poppins', sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-overflow-scrolling: touch;
}

/* ============================================ */
/* FIXED BLUE HIGHLIGHTS - COMPLETE OVERRIDE */
/* ============================================ */
*:focus, *:active, *:focus-visible, 
button:focus, button:active, button:focus-visible, 
input:focus, input:active, input:focus-visible,
textarea:focus, textarea:active, textarea:focus-visible,
div:focus, div:active, div:focus-visible, 
span:focus, span:active, span:focus-visible,
a:focus, a:active, a:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  -webkit-tap-highlight-color: transparent !important;
  -webkit-focus-ring-color: transparent !important;
  -moz-outline: none !important;
  -webkit-appearance: none !important;
}

/* Remove blue highlights on mobile Safari */
input, textarea, button, select, a {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

/* ============================================ */
/* FIXED LAUREL WREATH ANIMATION - BETTER POSITIONING & CIRCULAR SHAPE */
/* ============================================ */
.hidden { 
  display: none !important; 
}

/* FIXED: Laurel wreath positioning - MOVED UP SIGNIFICANTLY */
.typing-indicator {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 2px 0 2px 0; /* FURTHER REDUCED padding to move up */
  margin: 0;
  width: 100%;
  margin-left: -5px;
  margin-top: -30px; /* INCREASED: Move the entire indicator up more */
  margin-bottom: 10px; /* ADDED: Add some bottom margin for spacing */
}

/* FIXED: Perfect circular loading spinner - PROPER LOADING STYLE */
.typing-indicator .laurel { 
  width: 28px; /* Slightly smaller for better proportions */
  height: 28px;
  border: 3px solid transparent;
  border-top: 3px solid #ff6b35;
  border-right: 3px solid #8b5cf6;
  border-radius: 50% !important; /* FORCE circular */
  background: transparent;
  flex-shrink: 0;
  animation: spin 1s linear infinite;
  box-shadow: none !important;
}

/* FIXED: "Just a sec" text on same line - MOVED UP */
.wait-text { 
  color: var(--text-secondary); 
  font-size: 14px; 
  font-style: italic;
  white-space: nowrap; /* ADDED: Prevent text wrapping */
  display: inline-block; /* ADDED: Keep on same line */
  margin-top: -2px; /* ADDED: Fine-tune vertical alignment */
}

/* Make sure it's positioned where AI response starts */
.message.ai .typing-indicator {
  margin-left: -5px;
  padding-left: 0;
  padding-top: 2px; /* FURTHER REDUCED padding */
  padding-bottom: 2px; /* FURTHER REDUCED padding */
  margin-top: -8px; /* INCREASED: Move up more */
}

/* spinner animation class */
.loading { 
  animation: spin 1s linear infinite !important; 
}

@keyframes spin { 
  from { transform: rotate(0); } 
  to { transform: rotate(360deg); } 
}

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

/* FIXED: Stamp appended under ai message - FULL CIRCULAR LOADING SPINNER */
.ai-message .stamp,
.message.ai .stamp {
  display: block;
  margin: 8px 0 0 0;
  width: 22px; /* Slightly smaller for better proportions */
  height: 22px;
  border: 2px solid;
  border-color: #ff6b35 #8b5cf6 #8b5cf6 #ff6b35; /* Full circle with gradient colors */
  border-radius: 50% !important; /* FORCE circular */
  opacity: 0.7;
  background: transparent;
  animation: spin 1.2s linear infinite; /* Slower spin for subtle effect */
  box-shadow: none !important;
}

@keyframes stampAppear {
  0% { transform: scale(0.8); opacity: 0; }
  70% { transform: scale(1.1); opacity: 0.8; }
  100% { transform: scale(1); opacity: 0.7; }
}

/* ============================================ */
/* FIXED BOTTOM SHEET INPUT STYLES - NO WHITE FLASH */
/* ============================================ */
.chat-input-bar{
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--border-color);
  border-radius: 25px 25px 0 0 !important;
  padding: 8px 12px;
  background: var(--secondary-bg);
  width: 100% !important;
  margin: 0 !important;
  max-width: 100% !important;
  box-shadow: 0 -1px 3px var(--shadow-color);
  gap: 8px;
  position: fixed;
  bottom: 0 !important;
  left: 0 !important;
  transform: none !important;
  z-index: 100;
  border-bottom: none !important;
  -webkit-backface-visibility: hidden;
  -webkit-perspective: 1000;
  transform: translateZ(0);
  transition: transform 0.2s ease, background-color 0.3s ease;
}

/* Fix for keyboard detachment transition */
.chat-input-bar.keyboard-detaching {
  transition: transform 0.2s ease, background-color 0.3s ease !important;
}

/* ============================================ */
/* FIXED TEXTAREA - NO FLASH ON KEYBOARD DETACHMENT */
/* ============================================ */
.textarea-container{
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: calc(100% - 100px);
}

.chat-textarea {
  resize: none !important;
  overflow-y: auto !important;
  min-height: 24px !important;
  max-height: 150px !important;
  flex-grow: 1 !important;
  margin: 0 !important;
  padding: 8px 12px !important;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  font-size: 1rem !important;
  font-weight: 400 !important;
  line-height: 1.5 !important;
  color: var(--text-color) !important;
  font-family: 'Poppins', sans-serif !important;
  width: 100% !important;
  caret-color: var(--caret-color) !important;
  caret-width: 3px !important;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
  -webkit-appearance: none !important;
  transition: none !important; /* ADDED: Remove all transitions */
}

.chat-textarea::-webkit-scrollbar {
  display: none !important;
}

/* ============================================ */
/* FIXED IMAGE RESPONSE STYLES */
/* ============================================ */
.image-response-container {
  margin: 1rem 0;
  text-align: center;
}

.image-response-container img {
  max-width: 100%;
  max-height: 400px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  background: var(--secondary-bg);
  border: 1px solid var(--border-color);
}

/* Worker-provided image styles */
.related-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin: 0.5rem 0;
}

.fetched-image {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  margin: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease;
  background: var(--secondary-bg);
  border: 1px solid var(--border-color);
}

.fetched-image:hover {
  transform: scale(1.02);
}

/* ============================================ */
/* FIXED FILE UPLOAD PREVIEW STYLES */
/* ============================================ */
.file-preview-container{
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 8px;
  max-height: 100px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px;
  scrollbar-width: thin;
}

.file-preview {
  position: relative;
  width: 70px;
  height: 70px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--secondary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.file-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block !important;
}

/* FIXED: BIGGER close button styling */
.remove-file-btn {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 28px !important;
  height: 28px !important;
  border-radius: 50%;
  background: var(--secondary-bg) !important;
  border: 2px solid var(--border-color) !important;
  color: var(--text-color) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  font-size: 18px !important;
  font-weight: bold !important;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2) !important;
  padding: 0 !important;
  line-height: 1 !important;
}

.remove-file-btn:hover {
  background: var(--hover-bg) !important;
  transform: scale(1.15) !important;
  border-color: #ff4444 !important;
  color: #ff4444 !important;
}

.remove-file-btn:active {
  transform: scale(0.95) !important;
}

/* ============================================ */
/* SOURCES STYLES */
/* ============================================ */
.sources-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: 'Poppins', sans-serif;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
  white-space: nowrap;
  margin-left: auto;
}

.sources-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
}

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

.sources-btn.hidden {
  display: none !important;
}

/* Sources Modal */
.sources-modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-color);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 20px var(--shadow-color);
  z-index: 3500;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.sources-modal.open {
  transform: translateY(0);
}

.sources-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sources-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-color);
}

.sources-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-color);
}

.close-sources-btn {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

.close-sources-btn:hover {
  background: var(--secondary-bg);
}

.sources-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  max-height: calc(80vh - 100px);
}

.sources-list {
  flex: 1;
  overflow-y: auto;
}

/* Source Items */
.source-item {
  display: flex;
  gap: 16px;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--secondary-bg);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.source-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.source-number {
  width: 32px;
  height: 32px;
  background: var(--primary-color);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.source-content {
  flex: 1;
  min-width: 0;
}

.source-content h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-color);
  line-height: 1.3;
}

.source-content p {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--text-color);
  opacity: 0.8;
  line-height: 1.4;
}

.source-text {
  background: var(--bg-color);
  padding: 12px;
  border-radius: 8px;
  border-left: 3px solid var(--primary-color);
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 12px !important;
}

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary-color);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 12px;
  border: 1px solid var(--primary-color);
  border-radius: 6px;
  transition: all 0.2s ease;
}

.source-link:hover {
  background: var(--primary-color);
  color: white;
  transform: translateY(-1px);
}

/* No Sources State */
.no-sources {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-color);
  opacity: 0.6;
}

.no-sources i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.no-sources p {
  margin: 0;
  font-size: 16px;
}

/* ============================================ */
/* REST OF YOUR STYLES */
/* ============================================ */

/* Header */
.header{
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: var(--bg-color);
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
}

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

.nav-button:hover {
  background: var(--hover-bg);
  transform: scale(1.05);
}

.nav-button:active {
  transform: scale(0.95);
}

/* FIXED: Navbar title - prevent truncation on all screens */
.title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-color);
  flex: 1;
  text-align: center;
  margin: 0 1rem;
  white-space: nowrap;
  overflow: visible !important; /* FIXED: Prevent truncation */
  text-overflow: clip !important; /* FIXED: Don't show ellipsis */
  min-width: max-content; /* FIXED: Allow title to take needed space */
}

.main-content{
  margin-top: 60px;
  height: calc(100dvh - 60px);
  display: flex;
  flex-direction: column;
  max-width: 768px;
  margin-left: auto;
  margin-right: auto;
  background: var(--bg-color);
  position: relative;
  transition: none;
}

.welcome-screen{
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  z-index: 1;
}

.welcome-content {
  max-width: 400px;
}

.welcome-text {
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-color);
  text-align: center;
  opacity: 0.8;
}

.chat-container{
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  scroll-behavior: smooth;
  position: relative;
  padding-bottom: 160px !important;
  -webkit-overflow-scrolling: touch;
}

.messages-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding-bottom: 2rem;
  min-height: 100%;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 100%;
  position: relative;
}

.message.user {
  align-items: flex-end;
}

.message.ai {
  align-items: flex-start;
  width: 100%;
}

.message-bubble {
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  max-width: 80%;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.message.user .message-bubble {
  background: var(--user-message-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

.message.ai .message-bubble {
  background: transparent !important;
  color: var(--text-color);
  border: none !important;
  padding: 0.75rem 0 !important;
  border-radius: 0 !important;
  max-width: 100% !important;
}

.message-image {
  max-width: 100%;
  max-height: 300px;
  border-radius: 12px;
  margin: 0.5rem 0;
  display: block !important;
  object-fit: cover;
  box-shadow: 0 2px 8px var(--shadow-color);
  background: var(--secondary-bg);
  border: 1px solid var(--border-color);
}

.message-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--secondary-bg);
  border-radius: 8px;
  margin: 0.5rem 0;
  max-width: 250px;
}

.message.ai .message-actions {
  opacity: 1 !important;
  margin-top: 0.75rem;
  margin-left: 0;
}

.message-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.message:hover .message-actions {
  opacity: 1;
}

/* ============================================ */
/* FIXED INPUT ACTIONS ROW - NO CUTOFF BUTTONS */
/* ============================================ */
.input-actions-row{
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
  flex-wrap: nowrap;
  overflow-x: visible !important; /* FIXED: Allow buttons to be fully visible */
  overflow-y: hidden;
  padding: 4px 0; /* FIXED: Added padding to prevent cutoff */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.input-actions-row::-webkit-scrollbar {
  display: none;
}

.input-actions-row .action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  height: auto;
  width: auto;
  font-size: 0.75rem;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  color: var(--text-color);
  transition: all 0.2s ease;
  min-height: 40px;
  flex-shrink: 0;
  min-width: max-content;
  position: relative; /* FIXED: Ensure proper positioning */
  z-index: 1; /* FIXED: Ensure buttons are above other elements */
}

.input-actions-row .action-btn.active {
  background: linear-gradient(45deg, rgba(255, 107, 53, 0.8), rgba(139, 92, 246, 0.8));
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  color: white;
  box-shadow: 0 4px 20px rgba(255, 107, 53, 0.3);
}

.input-actions-row .action-btn i {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.input-actions-row .action-btn span {
  font-size: 0.7rem;
  white-space: nowrap;
}

/* Send button */
.send-btn {
  width: 36px !important;
  height: 36px !important;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  position: relative;
  flex-shrink: 0;
  background: #000000 !important;
  color: white !important;
  margin-left: 8px;
}

.send-btn:hover {
  background: #333333 !important;
  transform: scale(1.05);
}

.send-btn.has-text {
  background: var(--primary-color) !important;
  color: white !important;
}

.send-btn.has-text:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.send-btn.generating {
  background: var(--bg-color) !important;
  border: 2px solid var(--text-color) !important;
  color: var(--text-color) !important;
}

.send-btn.generating:hover {
  background: var(--hover-bg) !important;
  transform: scale(1.05);
}

#sendIcon {
  width: 20px;
  height: 20px;
  color: white;
}

.send-btn.generating #sendIcon {
  color: var(--text-color) !important;
}

.chat-icons{
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.icon-btn{
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-color);
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--primary-color);
  color: white;
  transform: scale(1.05);
}

.scroll-to-bottom{
  position: fixed;
  bottom: 160px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow-color);
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  color: var(--text-color);
}

.scroll-to-bottom.visible {
  opacity: 1;
  visibility: visible;
}

.scroll-to-bottom:hover {
  background: var(--primary-color);
  color: white;
  transform: translateY(-2px);
}

.side-page{
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  height: 100dvh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  touch-action: pan-y;
}

.side-page.open {
  transform: translateX(0);
}

.side-page.dragging {
  transition: none;
}

.side-top-bar{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--sidebar-bg);
}

.nav-icon, .sidebar-new-chat, .nav-item, .chat-item {
  transition: all 0.2s ease;
  cursor: pointer;
  user-select: none;
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-color);
}

.nav-icon:hover {
  background: var(--primary-color);
  color: white;
  transform: scale(1.05);
}

.nav-icon:active {
  transform: scale(0.97);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--secondary-bg);
  color: var(--text-color);
  font-size: 0.875rem;
  font-weight: 600;
}

.user-avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px var(--shadow-color);
}

.search-bar{
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 72px;
  z-index: 9;
  background: var(--sidebar-bg);
}

.search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 1.5rem;
  background: var(--secondary-bg);
  color: var(--text-color);
  font-family: 'Poppins', sans-serif;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.search-input:focus {
  border-color: var(--caret-color);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.side-nav-vertical{
  padding: 1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  border-radius: 0.75rem;
  cursor: pointer;
  color: var(--text-color);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: all 0.2s ease;
  font-family: 'Poppins', sans-serif;
}

.nav-item:hover {
  background: rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

.nav-item:active {
  transform: scale(0.97);
}

.nav-item[data-action="explore"].active {
  background: linear-gradient(45deg, #ff6b35, #8b5cf6) !important;
  color: white !important;
  font-weight: 600;
}

.sidebar-new-chat{
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--secondary-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: 'Poppins', sans-serif;
  margin: 0.5rem 1rem;
  width: calc(100% - 2rem);
}

.sidebar-new-chat:hover {
  background: linear-gradient(45deg, #ff6b35, #8b5cf6);
  color: white;
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

.sidebar-new-chat:active {
  transform: scale(0.97);
}

.sidebar-section{
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text-color);
  font-size: 0.875rem;
  font-weight: 600;
}

.sidebar-header i {
  width: 18px;
  height: 18px;
}

.chat-list-container{
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
  max-height: calc(100dvh - 300px);
  scrollbar-width: thin;
}

.chat-list-container::-webkit-scrollbar {
  width: 4px;
}

.chat-list-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.chat-list {
  list-style: none;
  padding-bottom: 80px;
}

.chat-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-item:hover {
  background: rgba(0, 0, 0, 0.05);
  transform: translateX(4px);
}

.chat-item:active {
  transform: scale(0.97);
  background: rgba(0, 0, 0, 0.1);
}

.chat-item-content {
  flex: 1;
  min-width: 0;
}

.chat-item h3 {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-color);
  margin-bottom: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item p {
  font-size: 0.75rem;
  color: #666;
  margin-bottom: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-time {
  font-size: 0.6875rem;
  color: #999;
}

.chat-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 1;
  transition: opacity 0.15s ease;
}

.chat-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px !important;
  height: 24px !important;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #999;
  transition: all 0.2s ease;
  font-size: 14px !important;
  padding: 0 !important;
}

.chat-action-btn:hover {
  color: var(--text-color);
  background: var(--hover-bg);
  transform: scale(1.1);
}

.chat-action-btn:active {
  transform: scale(0.9);
}

.chat-action-btn.delete:hover {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.1);
}

.action-btn, .speak-btn, .feedback-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-color);
  transition: all 0.2s ease;
}

.action-btn:hover, .speak-btn:hover, .feedback-btn:hover {
  background: var(--primary-color);
  color: white;
  transform: scale(1.1);
}

.action-btn:active, .speak-btn:active, .feedback-btn:active {
  transform: scale(0.95);
}

.upload-options{
  position: absolute;
  bottom: 70px;
  left: 20px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--shadow-color);
  z-index: 1000;
  display: none;
  flex-direction: column;
  padding: 8px;
  gap: 4px;
  min-width: 150px;
}

.upload-options.visible {
  display: flex;
}

.upload-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-color);
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem;
  transition: all 0.2s ease;
  text-align: left;
  width: 100%;
}

.upload-option:hover {
  background: var(--primary-color);
  color: white;
  transform: translateY(-1px);
}

.upload-option:active {
  transform: scale(0.97);
}

.toast-container{
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 12px 20px;
  border-radius: 12px;
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem;
  box-shadow: 0 4px 12px var(--shadow-color);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
  pointer-events: auto;
  max-width: 300px;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  background: var(--toast-bg);
  color: var(--toast-text);
}

.toast.error {
  background: rgba(239, 68, 68, 0.9);
  color: white;
}

.toast.info {
  background: var(--toast-bg);
  color: var(--toast-text);
}

.modal{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 16px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-color);
}

.modal-body {
  padding: 16px 0;
}

.modal-body p {
  color: var(--text-color);
  margin-bottom: 16px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.modal-btn:hover {
  transform: translateY(-1px);
}

.modal-btn:active {
  transform: scale(0.97);
}

.cancel-btn {
  background: var(--secondary-bg);
  color: var(--text-color);
}

.cancel-btn:hover {
  background: var(--hover-bg);
}

.confirm-btn {
  background: var(--primary-color);
  color: white;
  border: none;
}

.confirm-btn:hover {
  opacity: 0.9;
}

.delete-btn {
  background: #dc2626;
  color: white;
  border-color: #dc2626;
}

.delete-btn:hover {
  background: #b91c1c;
}

.message-context-menu{
  position: fixed;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow-color);
  z-index: 2500;
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 2px;
  min-width: 180px;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-color);
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem;
  transition: all 0.2s ease;
  text-align: left;
  width: 100%;
}

.context-menu-item:hover {
  background: var(--primary-color);
  color: white;
  transform: translateY(-1px);
}

.context-menu-item:active {
  transform: scale(0.97);
}

.overlay{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 1500;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
}

.hidden{
  display: none !important;
}

.visible {
  display: flex !important;
}

.no-scroll {
  overflow: hidden;
}

.empty-state{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  color: #999;
}

.empty-state i {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  color: #ccc;
}

.empty-state p {
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

/* ============================================ */
/* RESPONSIVE DESIGN */
/* ============================================ */
@media (max-width: 768px) {
  .chat-input-bar {
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
    width: 100% !important;
    padding: 8px 12px !important; /* FIXED: Ensure proper padding */
  }
  
  .sources-btn {
    padding: 6px 12px;
    font-size: 0.7rem;
  }
  
  .sources-modal {
    max-height: 85vh;
  }
  
  .sources-header {
    padding: 16px 20px 12px;
  }
  
  .sources-body {
    padding: 16px 20px;
  }
  
  .source-item {
    padding: 12px;
    gap: 12px;
  }
  
  .main-content {
    height: calc(100dvh - 60px);
  }
  
  /* FIXED: Ensure buttons are fully visible on mobile */
  .input-actions-row {
    flex-wrap: nowrap !important;
    overflow-x: visible !important; /* FIXED: No cutoff */
    padding: 4px 0 !important; /* FIXED: Added padding */
    gap: 6px !important; /* FIXED: Slightly smaller gap on mobile */
  }
  
  .input-actions-row .action-btn {
    flex-shrink: 0 !important;
    min-width: max-content !important;
    padding: 6px 10px !important; /* FIXED: Slightly smaller padding on mobile */
    font-size: 0.7rem !important; /* FIXED: Slightly smaller font on mobile */
  }
  
  /* FIXED: Adjust textarea container to accommodate buttons */
  .textarea-container {
    max-width: calc(100% - 90px) !important; /* FIXED: Give more space for buttons */
  }
}

/* ============================================ */
/* FIXED RATE LIMIT MODAL STYLES */
/* ============================================ */
#rateLimitModal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000;
  padding: 20px;
}

#rateLimitModal.hidden {
  display: none;
}

#rateLimitModal .modal-content {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  position: relative;
}

#rateLimitModal .modal-header {
  position: relative;
  padding: 0 0 16px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#rateLimitModal .modal-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
}

#closeRateLimitBtn {
  position: absolute !important;
  top: -15px !important;
  right: -15px !important;
  width: 32px !important;
  height: 32px !important;
  border-radius: 50% !important;
  background: var(--secondary-bg) !important;
  border: 1px solid var(--border-color) !important;
  color: var(--text-color) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  font-size: 18px !important;
  font-weight: bold !important;
  padding: 0 !important;
  z-index: 10;
}

#closeRateLimitBtn:hover {
  background: var(--hover-bg) !important;
  transform: scale(1.1) !important;
}

#closeRateLimitBtn:active {
  transform: scale(0.95) !important;
}

#rateLimitModal .modal-body {
  padding: 16px 0;
  text-align: center;
}

#rateLimitModal .modal-body p {
  color: var(--text-color);
  margin-bottom: 12px;
  line-height: 1.5;
  font-size: 0.95rem;
}

.modal-actions-centered {
  display: flex !important;
  justify-content: center !important;
  padding-top: 16px !important;
  width: 100%;
}

#upgradeBtn {
  background: linear-gradient(45deg, #ff6b35, #8b5cf6) !important;
  color: white !important;
  border: none !important;
  border-radius: 25px !important;
  padding: 12px 32px !important;
  font-size: 1rem !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  transition: all 0.3s ease !important;
  box-shadow: 0 4px 15px rgba(255, 107, 53, 0.3) !important;
  min-width: 160px;
}

#upgradeBtn:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 6px 20px rgba(255, 107, 53, 0.4) !important;
}

#upgradeBtn:active {
  transform: translateY(0) !important;
}

#rateLimitTimer {
  font-weight: 600;
  color: #ff6b35;
  margin-top: 1rem;
  text-align: center;
  font-size: 0.9rem;
}

#resetTimeInfo {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  text-align: center;
}