/* Main App Styles - Modular CSS Architecture */

/* Import all modular CSS files */

/* CSS Variables and Root Styles */

:root {
  --bg: #0d0d0d;
  --panel: #141414;
  --panel-2: #1a1a1a;
  --border: #2a2a2a;
  --text: #ececec;
  --muted: #9aa0a6;
  --accent: #A6C4F7;
  --accent-2: #7BA8E8;
  --danger: #ff6b6b;
  --radius: 12px;

  /* Additional semantic colors */
  --text-primary: #ececec;
  --text-secondary: #9aa0a6;
  --hover-bg: rgba(255, 255, 255, 0.05);
  --border-color: #2a2a2a;
  --accent-color: #A6C4F7;

  /* Typography - with Arabic support */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Noto Sans Arabic", "Helvetica Neue", Arial, "Tahoma", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: -0.01em;
}

/* Scrollbar */

::-webkit-scrollbar { width: 8px; height: 8px; }

::-webkit-scrollbar-track { background: transparent; }

::-webkit-scrollbar-thumb { background: #333; border-radius: 6px; }

::-webkit-scrollbar-thumb:hover { background: #3b3b3b; }

/* App Layout, Sidebar, and Chat Container */

.app-layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  overflow: visible; /* Allow page scroll */
}

/* Sidebar */

.sidebar {
  width: 260px;
  background: #141414; /* Slightly lighter than chat area (#0d0d0d) for subtle separation */
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar.closed {
  transform: translateX(-100%);
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar-header {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.sidebar-logo {
  height: 50px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-header-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* New chat button - improved design */

.new-chat-button {
  margin: 12px 12px 8px 12px;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s ease;
  width: calc(100% - 24px);
}

.new-chat-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.03);
  border-color: #3a3a3a;
}

.new-chat-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.new-chat-button .plus-icon {
  color: #0ea5e9; /* Blue accent color */
  flex-shrink: 0;
}

/* Recents header */

.recents-header {
  padding: 12px 16px 8px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.new-chat-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.new-chat-btn:hover {
  background: #242424;
  border-color: #3a3a3a;
}

.toggle-sidebar-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.toggle-sidebar-btn:hover {
  background: #242424;
}

.floating-toggle-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 20;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.floating-toggle-btn:hover {
  background: #242424;
  border-color: #3a3a3a;
}

.conversations-list { 
  flex: 1; 
  overflow-y: auto; 
  padding: 8px; 
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
}

.conversation-item:hover { 
  background: #232323; 
}

.conversation-item.active { 
  background: #202020; 
  border-left: 3px solid var(--accent); 
  padding-left: 9px; 
}

.conv-title { 
  flex: 1; 
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  color: var(--text); 
  opacity: 0.9; 
}

.delete-conv-btn { 
  background: transparent; 
  border: none; 
  color: var(--muted); 
  cursor: pointer; 
  display: none; 
}

.conversation-item:hover .delete-conv-btn { 
  display: block; 
}

.delete-conv-btn:hover {
  color: var(--danger);
}

/* Guest Mode Message in Sidebar */

.guest-mode-message {
  padding: 24px 16px;
  text-align: center;
  color: var(--text);
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
}

.guest-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.guest-mode-message h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.guest-mode-message p {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
}

.guest-features {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0;
}

.guest-feature {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: left;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.guest-cta {
  font-size: 14px;
  font-weight: 600;
  color: #A6C4F7;
  margin-top: 8px;
}

/* Sidebar footer */

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-1);
}

.user-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #000000;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.logout-btn:hover {
  background: #242424;
  border-color: #3a3a3a;
  color: var(--danger);
}

/* Sign In Button in Sidebar (for guests) */

.signin-btn {
  width: 100%;
  padding: 12px 16px;
  background: #1a1a1a;
  color: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.signin-btn:hover {
  background: #242424;
  border-color: #3a3a3a;
}

.signin-btn:active {
  background: #141414;
}

/* Main chat column */

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel-2);
  margin-left: 260px; /* Make room for fixed sidebar when open */
  min-height: 100vh;
  overflow: visible; /* Allow page scroll */
  transition: margin-left 0.3s ease; /* Smooth transition when sidebar toggles */
}

/* Full width when sidebar is closed on desktop */

.sidebar.closed ~ .chat-container {
  margin-left: 0;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
}

.chat-header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

/* Mobile chat header - hidden on desktop */

.mobile-chat-header {
  display: none;
}

/* Guest Sign In Button - Bottom Left */

.guest-signin-btn {
  position: fixed;
  bottom: 20px;
  left: 20px;
  padding: 12px 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.guest-signin-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.guest-signin-btn:active {
  transform: translateY(0);
}

/* Scroll to bottom button */

.scroll-to-bottom-btn {
  position: fixed;
  bottom: 120px; /* Above input area */
  right: 50%;
  transform: translateX(50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
}

.scroll-to-bottom-btn:hover {
  background: rgba(40, 40, 40, 0.95);
  transform: translateX(50%) scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.scroll-to-bottom-btn:active {
  transform: translateX(50%) scale(0.95);
}

.messages-container {
  flex: 1;
  overflow-y: visible; /* Use page scroll instead */
  overflow-x: hidden; /* Prevent horizontal scrolling */
  padding: 24px 16px 95px 16px; /* Even tighter bottom padding like Claude */
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 720px; /* Narrower like Claude for better readability */
  margin: 0 auto; /* Center on desktop */
}

/* Welcome */

.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  gap: 20px;
  padding: 40px 20px;
  max-width: 800px;
  margin: 0 auto;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.welcome-avatar {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

.welcome-title {
  font-size: 48px;
  font-weight: 700;
  margin: 0;
  background: linear-gradient(135deg, #A6C4F7, #7BA8E8);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 2px;
}

.welcome-tagline {
  font-size: 24px;
  font-weight: 600;
  margin: 8px 0;
  color: var(--text);
}

.welcome-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin: 0 0 32px 0;
  max-width: 500px;
}

/* Starter Prompts */

.starter-prompts {
  width: 100%;
  max-width: 700px;
  margin-top: 20px;
}

.prompts-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: left;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.prompts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  width: 100%;
}

.prompt-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 70px;
}

.prompt-card:hover {
  background: var(--hover);
  border-color: #A6C4F7;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(166, 196, 247, 0.15);
}

.prompt-card:active {
  transform: translateY(0);
}

.prompt-icon {
  flex-shrink: 0;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.prompt-card:hover .prompt-icon {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.1);
}

.prompt-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  flex: 1;
}

/* Mobile overlay */

.mobile-overlay {
  display: none;
}

/* Search banner - compact style under user message (legacy) */

.search-banner {
  background: rgba(166, 196, 247, 0.05);
  border: 1px solid rgba(166, 196, 247, 0.15);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0 16px 0;
  max-width: fit-content;
  animation: slideDown 0.2s ease-out;
}

.search-banner-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-text {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.search-text strong {
  color: var(--accent);
  font-weight: 500;
}

.search-query {
  color: var(--muted);
  font-style: italic;
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tool Status Banner - fixed position above input area */

.tool-status-banner {
  background: rgba(166, 196, 247, 0.1);
  border: 1px solid rgba(166, 196, 247, 0.25);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 0 16px 12px 16px;
  animation: slideUp 0.3s ease-out;
}

.tool-status-banner.pdf-banner {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
}

.tool-status-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tool-status-text {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.tool-status-text strong {
  color: var(--accent);
  font-weight: 600;
}

.tool-status-banner.pdf-banner .tool-status-text strong {
  color: #ef4444;
}

.tool-status-query {
  color: var(--muted);
  font-style: italic;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.search-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(166, 196, 247, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

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

/* PDF generation banner variant */

.pdf-banner {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.2);
}

.pdf-banner .search-spinner {
  border-color: rgba(59, 130, 246, 0.2);
  border-top-color: #3b82f6;
}

.pdf-banner .search-text strong {
  color: #3b82f6;
}

/* Message Styles, Markdown, and Avatars */

/* Messages */

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 24px; /* Comfortable spacing */
  will-change: contents; /* Hint browser that content will change during streaming */
  transform: translateZ(0); /* Force GPU acceleration */
}

.message.assistant {
  padding-left: 0;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 4px;
}

.message.assistant .message-avatar {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.assistant-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none !important;
  color: white;
}

.message.user .message-avatar {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.avatar-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

.message-content {
  display: flex;
  flex-direction: column;
}

/* Assistant messages take full width */

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

/* User messages size to content */

.message.user .message-content {
  max-width: fit-content;
}

.message-text {
  line-height: 1.65;
  color: var(--text);
  word-wrap: break-word;
  word-break: break-word; /* Better word breaking for all languages */
  overflow-wrap: break-word; /* Modern standard for word wrapping */
  font-family: var(--font-sans);
  font-size: 15px;
  letter-spacing: -0.005em;
  min-height: 20px; /* Prevent layout shift during streaming */
  contain: layout; /* Optimize rendering performance */
  /* Ensure proper text rendering for Arabic and other complex scripts */
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Ensure visibility in PWA standalone mode */
  visibility: visible !important;
  opacity: 1 !important;
  display: block !important;
}

/* User messages have darker background and size to content */

.message.user .message-text {
  background: #242424;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  max-width: fit-content; /* Size based on content like Claude */
}

/* Assistant messages have no background - just plain text like Claude */

.message.assistant .message-text {
  background: transparent;
  border: none;
  padding: 0;
  line-height: 1.7; /* Slightly more line height for readability */
  /* Ensure visibility in PWA standalone mode */
  visibility: visible !important;
  opacity: 1 !important;
  display: block !important;
}

.user-message {
  white-space: pre-wrap;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.user-message.editing {
  background: transparent;
  padding: 0;
  width: 100%;
  max-width: 100%;
}

/* When editing, expand the message content to full width */

.message.user:has(.user-message.editing) {
  justify-content: flex-start;
}

.message.user:has(.user-message.editing) .message-content {
  max-width: 100%;
  width: 100%;
}

.message.user:has(.user-message.editing) .message-text {
  max-width: 100%;
  width: 100%;
  background: transparent;
  border: none;
  padding: 0;
}

.user-message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #52525B; /* Neutral gray like Claude */
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

/* Message header and copy button */

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.message-role {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.2s ease;
  opacity: 0; /* Hidden by default */
}

.message:hover .copy-btn {
  opacity: 1; /* Show on hover */
}

.copy-btn:hover {
  background: var(--panel);
  border-color: var(--accent);
  color: var(--accent);
}

.copy-btn span {
  font-weight: 500;
}

/* Message action buttons - Claude style */

.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  padding-top: 8px;
  opacity: 0; /* Hidden by default - show on hover */
  transition: opacity 0.2s ease;
  justify-content: space-between; /* Space between icon and buttons */
  align-items: center;
}

/* Show actions on hover for older messages */

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

/* Always show actions for the last message */

.message-actions.always-visible {
  opacity: 1;
}

/* Luxra icon - appears below message, spins while loading */

.luxra-icon {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-top: 12px;
  padding-top: 8px;
}

/* When inside message-actions, align with buttons */

.message-actions .luxra-icon {
  margin-top: 0;
  padding-top: 0;
  margin-right: auto; /* Push to the left */
}

.luxra-icon img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

/* Spinning animation when loading */

.luxra-icon.spinning img {
  animation: spin 1s linear infinite;
}

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

/* Spacer to maintain layout when icon is not shown */

.luxra-icon-spacer {
  margin-right: auto; /* Keep buttons on the right */
}

.action-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border);
  color: var(--text);
}

.action-btn.active {
  background: rgba(14, 165, 233, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

/* Message disclaimer - Claude style */

.message-disclaimer {
  text-align: right;
  font-size: 11px;
  color: #6b6b6b;
  margin-top: 2px;
  margin-bottom: 0;
  line-height: 1.4;
}

/* Markdown typography - polished like Claude */

.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
  margin: 20px 0 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

.message-text h1 {
  font-size: 1.5rem;
  margin-top: 24px;
}

.message-text h2 {
  font-size: 1.3rem;
  margin-top: 20px;
}

.message-text h3 {
  font-size: 1.15rem;
}

.message-text h4 {
  font-size: 1.05rem;
}

.message-text h5,
.message-text h6 {
  font-size: 1rem;
}

/* First heading has no top margin */

.message-text h1:first-child,
.message-text h2:first-child,
.message-text h3:first-child,
.message-text h4:first-child {
  margin-top: 0;
}

.message-text p {
  margin: 0 0 12px;
  line-height: 1.7;
}

.message-text p:last-child {
  margin-bottom: 0;
}

/* Strong and emphasis */

.message-text strong,
.message-text b {
  font-weight: 600;
  color: var(--text);
}

.message-text em,
.message-text i {
  font-style: italic;
  color: var(--text);
}

/* Inline code */

.message-text code {
  background: #2a2a2a;
  padding: 2px 6px;
  border-radius: 4px;
  color: #e8e8e8;
  font-family: var(--font-mono);
  font-size: 0.9em;
  font-weight: 400;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Code blocks */

.message-text pre {
  background: #1a1a1a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
  line-height: 1.5;
}

.message-text pre code {
  background: transparent;
  padding: 0;
  border: none;
  color: #e8e8e8;
  font-size: 14px;
  font-weight: 400;
}

/* Blockquotes */

.message-text blockquote {
  border-left: 3px solid rgba(255, 255, 255, 0.2);
  margin: 16px 0;
  padding: 8px 0 8px 16px;
  color: rgba(255, 255, 255, 0.7);
  font-style: italic;
}

.message-text blockquote p {
  margin: 4px 0;
}

/* Horizontal rules */

.message-text hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* Links */

.message-text a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.message-text a:hover {
  border-bottom-color: var(--accent);
}

/* Tables */

.message-text table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
  font-size: 14px;
}

.message-text table th,
.message-text table td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
}

.message-text table th {
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
  color: var(--text);
}

.message-text table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Task lists */

.message-text input[type="checkbox"] {
  margin-right: 8px;
  cursor: pointer;
}

.message-text li:has(input[type="checkbox"]) {
  list-style: none;
  margin-left: -24px;
}

/* List styling - polished like Claude */

.message-text ul,
.message-text ol {
  margin: 12px 0;
  padding-left: 24px;
}

.message-text ul {
  list-style-type: disc;
}

.message-text ol {
  list-style-type: decimal;
}

.message-text li {
  margin: 6px 0;
  padding-left: 8px;
  line-height: 1.7;
}

/* Nested lists */

.message-text ul ul,
.message-text ol ul {
  list-style-type: circle;
  margin: 4px 0;
}

.message-text ul ul ul,
.message-text ol ul ul,
.message-text ol ol ul {
  list-style-type: square;
}

.message-text ol ol {
  list-style-type: lower-alpha;
}

.message-text ol ol ol {
  list-style-type: lower-roman;
}

/* Better spacing for list items with paragraphs */

.message-text li > p {
  margin: 4px 0;
}

/* Strong/bold text in lists */

.message-text li strong,
.message-text li b {
  font-weight: 600;
  color: var(--text);
}

/* Message file attachments */

.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.file-item {
  position: relative;
}

.file-thumbnail {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.file-thumbnail:hover {
  transform: scale(1.02);
  border-color: var(--primary);
}

.file-item .file-icon {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Loading indicators */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  margin-left: 0; /* No avatar, so no left margin needed */
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

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

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

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

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

/* Typing Indicator (shown before first chunk arrives) */

.message-loading {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 8px 0;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

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

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

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

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

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

/* Skeleton loader lines */

.skeleton-lines {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.skeleton-line {
  height: 16px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  border-radius: 4px;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-line.short {
  width: 60%;
}

@keyframes skeleton-pulse {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* PDF Preview Container */

.pdf-preview-container {
  margin: 16px 0;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-secondary, #f9fafb);
  max-width: 600px;
}

.pdf-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #141414;
  border-bottom: 1px solid #2a2a2a;
}

.pdf-preview-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: #e5e5e5;
}

.pdf-preview-icon {
  width: 20px;
  height: 20px;
  color: #3b82f6;
  flex-shrink: 0;
}

.pdf-preview-title span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.pdf-preview-actions {
  display: flex;
  gap: 8px;
}

.pdf-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.1);
  color: #f1f5f9;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s ease;
  cursor: pointer;
}

.pdf-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.pdf-action-btn svg {
  width: 16px;
  height: 16px;
}

.pdf-download-btn {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

.pdf-download-btn:hover {
  background: #2563eb;
  border-color: #2563eb;
  color: white;
}

.pdf-preview-frame {
  position: relative;
  background: #525659;
  height: 400px;
}

.pdf-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #525659;
}

/* Dark mode adjustments */

[data-theme="dark"] .pdf-preview-container {
  background: var(--bg-secondary, #1f2937);
  border-color: var(--border-color, #374151);
}

[data-theme="dark"] .pdf-preview-header {
  background: var(--bg-tertiary, #111827);
  border-color: var(--border-color, #374151);
}

[data-theme="dark"] .pdf-action-btn {
  background: var(--bg-secondary, #1f2937);
  border-color: var(--border-color, #4b5563);
  color: var(--text-primary, #f9fafb);
}

[data-theme="dark"] .pdf-action-btn:hover {
  background: var(--bg-tertiary, #374151);
}

[data-theme="dark"] .pdf-download-btn {
  background: #2563eb;
  border-color: #2563eb;
  color: white;
}

[data-theme="dark"] .pdf-download-btn:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

/* Mobile responsive */

@media (max-width: 768px) {
  .pdf-preview-container {
    max-width: 100%;
  }

  .pdf-preview-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .pdf-preview-title span {
    max-width: 180px;
  }

  .pdf-preview-frame {
    height: 300px;
  }
}

/* ===== Edit Message Styles ===== */

.edit-message-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 300px;
  width: 100%;
}

.edit-message-input {
  width: 100%;
  min-height: 100px;
  max-height: 300px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  box-sizing: border-box;
}

.edit-message-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

.edit-message-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
}

.edit-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

.edit-action-btn svg {
  width: 14px;
  height: 14px;
}

.edit-action-btn.save-btn {
  background: var(--accent);
  color: white;
}

.edit-action-btn.save-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.edit-action-btn.cancel-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.edit-action-btn.cancel-btn:hover {
  background: var(--panel);
  color: var(--text);
}

/* User message edit button - appears on hover */

.user-message {
  position: relative;
}

.user-message-edit-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, transform 0.15s ease;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.user-message:hover .user-message-edit-btn {
  opacity: 1;
}

.user-message-edit-btn:hover {
  background: var(--panel-2);
  color: var(--text);
}

/* ===== Regenerate Button Styles ===== */

.action-btn.regenerate-btn {
  color: var(--text-secondary);
}

.action-btn.regenerate-btn:hover {
  color: var(--accent);
  background: rgba(var(--accent-rgb), 0.1);
}

/* ===== Responsive Edit Styles ===== */

/* Large desktops (1400px+) */

@media (min-width: 1400px) {
  .edit-message-input {
    font-size: 16px;
    min-height: 120px;
  }
}

/* Tablets and small laptops (768px - 1024px) */

@media (max-width: 1024px) {
  .edit-message-input {
    min-height: 70px;
  }
}

/* Tablets and Mobile */

@media (max-width: 768px) {
  .user-message-edit-btn {
    /* Position at bottom-right edge of message on mobile */
    top: auto;
    bottom: -14px;
    right: 8px;
    width: 28px;
    height: 28px;
    opacity: 0.9;
    background: var(--panel-2);
  }

  .user-message:hover .user-message-edit-btn {
    opacity: 1;
  }

  .edit-message-container {
    width: 100%;
  }

  .edit-message-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
    min-height: 80px;
    padding: 14px 16px;
  }

  .edit-message-actions {
    flex-direction: row;
    gap: 10px;
  }

  .edit-action-btn {
    flex: 1;
    justify-content: center;
    padding: 12px 16px;
    font-size: 14px;
  }
}

/* Small phones (max-width: 480px) */

@media (max-width: 480px) {
  .user-message-edit-btn {
    bottom: -12px;
    right: 4px;
    width: 26px;
    height: 26px;
  }

  .edit-message-input {
    min-height: 100px;
    border-radius: 10px;
  }

  .edit-message-actions {
    gap: 8px;
  }

  .edit-action-btn {
    padding: 10px 12px;
    font-size: 13px;
    border-radius: 8px;
  }

  .edit-action-btn svg {
    width: 12px;
    height: 12px;
  }
}

/* Handle notch/safe areas on modern phones */

@supports (padding: max(0px)) {
  @media (max-width: 768px) {
    .edit-message-container {
      padding-left: max(0px, env(safe-area-inset-left));
      padding-right: max(0px, env(safe-area-inset-right));
    }
  }
}

/* Regenerate button responsive */

@media (max-width: 768px) {
  .action-btn.regenerate-btn {
    padding: 8px;
  }

  .action-btn.regenerate-btn svg {
    width: 16px;
    height: 16px;
  }
}

/* ===== Voice Output Button Styles ===== */

.voice-output-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s ease;
}

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

.voice-output-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.voice-output-btn.playing {
  color: var(--accent);
  background: rgba(14, 165, 233, 0.1);
  border-color: var(--accent);
}

.voice-output-btn.loading {
  color: var(--muted);
}

.voice-output-btn .loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Voice output responsive */

@media (max-width: 768px) {
  .voice-output-btn {
    padding: 8px;
  }

  .voice-output-btn svg {
    width: 16px;
    height: 16px;
  }
}

/* Input Area, File Upload, and Buttons */

/* Input */

.input-area {
  position: fixed;
  bottom: 0;
  left: 260px; /* Account for sidebar when open */
  right: 0;
  padding: 16px;
  border-top: none; /* Remove border to match Claude's clean look */
  background: var(--panel-2); /* Match chat container background */
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 100; /* Higher z-index to stay on top */
  transition: left 0.3s ease; /* Smooth transition when sidebar toggles */
  /* Ensure touch events work in PWA */
  touch-action: manipulation;
  pointer-events: auto;
}

/* Full width when sidebar is closed on desktop */

.chat-container .input-area {
  left: 260px; /* Default with sidebar open */
}

.sidebar.closed ~ .chat-container .input-area {
  left: 0; /* Full width when sidebar closed */
}

/* File upload preview */

.uploaded-files-preview {
  max-width: 720px;
  margin: 0 auto 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.file-preview-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-icon {
  font-size: 18px;
}

.file-preview-image {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.file-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-name {
  color: var(--text);
  font-weight: 500;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  color: var(--muted);
  font-size: 11px;
}

.remove-file-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.remove-file-btn:hover {
  background: var(--border);
  color: var(--danger);
}

.input-form {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #1b1b1b;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 12px 16px;
  /* Ensure touch events work in PWA */
  touch-action: manipulation;
  pointer-events: auto;
}

.attach-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.attach-btn:hover {
  color: var(--accent);
}

.attach-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-sans);
  line-height: 1.5;
  letter-spacing: -0.005em;
  outline: none;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
  /* Ensure touch events work in PWA */
  touch-action: manipulation;
  pointer-events: auto;
  -webkit-user-select: text;
  user-select: text;
}

.send-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn:hover { 
  background: var(--accent-2); 
}

.send-btn:disabled {
  opacity: 1; /* Keep full opacity when loading so spinner is visible */
  cursor: not-allowed;
}

.send-btn.loading {
  background: var(--accent); /* Keep accent color when loading */
  opacity: 1;
  animation: pulse-button 2s ease-in-out infinite; /* Subtle pulse effect */
}

.loading-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.25);
  border-top: 2.5px solid white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes pulse-button {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.9;
  }
}

/* Stop button styling */

.send-btn.stop-btn {
  background: #ef4444;
  animation: none;
}

.send-btn.stop-btn:hover {
  background: #dc2626;
}

.send-btn.stop-btn svg {
  fill: white;
}

/* Stop button responsive */

@media (max-width: 768px) {
  .send-btn.stop-btn {
    width: 44px;
    height: 44px;
  }

  .send-btn.stop-btn svg {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 480px) {
  .send-btn.stop-btn {
    width: 40px;
    height: 40px;
  }
}

/* Voice Input Styles */

.voice-input-container {
  display: flex;
  align-items: center;
  position: relative;
}

.voice-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: color 0.2s, background-color 0.2s;
  border-radius: 50%;
  width: 32px;
  height: 32px;
}

.voice-btn:hover {
  color: var(--accent);
}

.voice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.voice-btn.recording {
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.1);
  animation: pulse-recording 1.5s ease-in-out infinite;
}

.voice-btn.processing {
  color: var(--accent);
}

@keyframes pulse-recording {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
  }
}

.recording-time {
  font-size: 11px;
  font-weight: 500;
  color: #ef4444;
  min-width: 32px;
}

.processing-indicator {
  font-size: 12px;
  animation: blink 1s infinite;
}

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

.voice-error {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  margin-bottom: 4px;
  z-index: 10;
}

/* Animations and Keyframes */

.streaming-cursor { 
  display: inline-block; 
  margin-left: 4px; 
  color: var(--accent); 
  animation: blink 1.2s infinite; 
  font-weight: bold;
  font-size: 16px;
}

/* Removed blinking border-left on streaming messages */

/* Rotate Luxra avatar while assistant is streaming/thinking */

.message.assistant.streaming .avatar-image {
  animation: rotate360 1.2s linear infinite;
}

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

@keyframes pulse {
  0%, 100% { border-left-color: var(--accent); }
  50% { border-left-color: transparent; }
}

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

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

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Mobile-Specific Styles and Media Queries */

/* Mobile-first responsive design */

@media (max-width: 768px) {
  /* On mobile, hide action buttons by default for older messages */
  .message-actions {
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  /* Always show for last message */
  .message-actions.always-visible {
    opacity: 1 !important;
  }

  /* Show when message is in viewport (added via JS) */
  .message.in-viewport .message-actions {
    opacity: 1;
  }

  .mobile-overlay {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 25;
    backdrop-filter: blur(2px);
  }
  
  .app-layout {
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    min-height: 100svh; /* Small viewport height (iOS keyboard safe) */
    overflow: visible;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 150; /* Higher than input area (100) and mobile header (100) */
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Add safe area padding to sidebar header on mobile */
  .sidebar-header {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
  }



  .chat-container {
    width: 100%;
    max-width: 100vw;
    margin-left: 0;
    overflow-x: hidden;
    overflow-y: visible; /* Use page scroll, not container scroll */
    box-sizing: border-box;
  }

  /* Ensure body doesn't overflow */
  body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  .input-area {
    left: 0; /* Full width on mobile */
    position: fixed; /* Ensure it stays fixed on mobile */
    z-index: 100;
  }

  /* Hide floating toggle button on mobile - we have mobile-menu-btn in sticky header */
  .floating-toggle-btn {
    display: none;
  }

  .chat-header {
    display: none; /* Hide desktop header on mobile */
  }

  /* Mobile sticky header - Claude style */
  .mobile-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    /* Add safe area padding for notch/status bar */
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--panel-2);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease;
  }

  /* Hide mobile header when sidebar is open */
  .mobile-chat-header.hidden {
    transform: translateY(-100%);
  }

  /* Add padding to messages container to account for fixed header */
  .chat-container {
    /* Base header height (56px) + safe area inset for notch/status bar */
    padding-top: calc(56px + env(safe-area-inset-top));
  }

  .mobile-menu-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
    flex-shrink: 0;
  }

  .mobile-menu-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
  }

  .mobile-chat-title {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: #a0a0a0; /* Light silver/gray like Claude */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
  }

  .mobile-action-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
    flex-shrink: 0;
  }

  .mobile-action-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
  }

  .messages-container {
    padding: 16px 20px; /* Extra left/right padding to prevent list cutoff */
    max-width: 100%;
    width: 100%;
    margin: 0; /* Remove auto margin to use full width */
    padding-bottom: 95px; /* Normal padding for browser */
    overflow-x: hidden; /* Prevent horizontal scroll */
    overflow-y: visible; /* Use page scroll, not container scroll */
    box-sizing: border-box;
  }

  .message {
    gap: 10px;
    margin-bottom: 20px;
    max-width: 100%;
    overflow-x: hidden;
  }

  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  /* Assistant messages use full width on mobile */
  .message.assistant .message-content {
    flex: 1;
    max-width: 100%;
    min-width: 0; /* Allow flex items to shrink below content size */
    overflow-x: hidden;
    padding-left: 4px; /* Small padding to prevent list cutoff */
  }

  /* User messages still size to content */
  .message.user .message-content {
    max-width: 85%;
    min-width: 0;
    overflow-x: hidden;
  }

  .message-text {
    font-size: 15px;
    line-height: 1.6;
  }

  /* User messages keep their bubble style */
  .message.user .message-text {
    padding: 12px 16px;
    border-radius: 18px;
  }

  /* Assistant messages remain plain text, no background */
  .message.assistant .message-text {
    padding: 0;
    background: transparent;
    border: none;
    overflow-x: hidden; /* Prevent horizontal overflow */
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* Fix code blocks overflow on mobile */
  .message-text pre {
    overflow-x: auto;
    max-width: 100%;
    font-size: 13px;
    padding: 12px;
    margin: 8px 0;
    /* Enable horizontal scrolling for code */
    -webkit-overflow-scrolling: touch;
  }

  .message-text pre code {
    font-size: 13px;
    word-break: break-all;
    white-space: pre-wrap;
  }

  .message-text code {
    font-size: 13px;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* Ensure tables don't overflow */
  .message-text table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  /* Break long words and URLs */
  .message-text {
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: none; /* Don't hyphenate words - just wrap them */
  }

  .message-text a {
    word-break: break-all;
  }

  /* List spacing on mobile - ensure bullets/numbers are visible */
  .message-text ul,
  .message-text ol {
    padding-left: 28px; /* Enough space for bullets/numbers to show */
    margin: 8px 0;
    list-style-position: outside; /* Ensure markers are outside the content */
  }

  .message-text li {
    margin: 4px 0; /* Comfortable vertical spacing */
    padding-left: 8px; /* Extra padding for readability */
  }

  /* Nested lists */
  .message-text ul ul,
  .message-text ol ul,
  .message-text ol ol {
    margin: 4px 0;
    padding-left: 24px; /* Enough space for nested markers */
  }

  .input-area {
    padding: 12px 16px; /* Comfortable padding like Claude mobile */
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    position: fixed; /* Fixed to stay at bottom on scroll */
    bottom: 0;
    left: 0 !important; /* Full width on mobile - override desktop sidebar offset */
    right: 0;
    width: 100%; /* Ensure full width */
    box-sizing: border-box; /* Include padding in width calculation */
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px)); /* Respect notch on left */
    padding-right: max(16px, env(safe-area-inset-right, 0px)); /* Respect notch on right */
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    /* Critical: Ensure touch events work in PWA */
    touch-action: manipulation !important;
    pointer-events: auto !important;
    /* Fix for in-app browsers (Instagram, Facebook) - use transform instead of fixed positioning */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }
  
  /* But allow text selection inside the textarea */
  .input-area textarea {
    -webkit-user-select: text !important;
    user-select: text !important;
  }

  .input-form {
    width: 100%; /* Full width */
    max-width: 100%; /* No max-width constraint on mobile */
    margin: 0; /* Remove auto margin for full width */
    gap: 8px;
    box-sizing: border-box; /* Include padding in width */
  }

  .uploaded-files-preview {
    width: 100%;
    max-width: 100%;
    margin: 0 0 12px 0; /* Remove auto margin for full width */
    box-sizing: border-box;
  }

  .input-wrapper {
    width: 100%; /* Full width */
    padding: 12px 16px;
    border-radius: 24px;
    min-height: 48px;
    box-sizing: border-box; /* Include padding in width */
    /* Critical: Ensure touch events work in PWA */
    touch-action: manipulation !important;
    pointer-events: auto !important;
    /* Ensure children can receive touch events */
    position: relative;
    z-index: 1;
  }

  .input-wrapper textarea {
    width: 100%; /* Full width */
    font-size: 16px; /* Prevents zoom on iOS */
    line-height: 1.5;
    max-height: 120px; /* Limit height on mobile */
    box-sizing: border-box; /* Include padding in width */
    /* Critical: Ensure keyboard opens on tap in PWA */
    touch-action: manipulation !important;
    pointer-events: auto !important;
    -webkit-user-select: text !important;
    user-select: text !important;
    -webkit-tap-highlight-color: transparent;
    /* iOS PWA specific fixes */
    -webkit-appearance: none !important;
    appearance: none !important;
    /* Ensure it's focusable */
    position: relative;
    z-index: 1;
  }

  .send-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
  }

  .attach-btn {
    width: 36px;
    height: 36px;
  }

  .welcome-message {
    padding: 20px;
    gap: 16px;
  }

  .welcome-title {
    font-size: 36px !important;
  }

  .welcome-tagline {
    font-size: 20px !important;
  }

  .welcome-subtitle {
    font-size: 14px !important;
  }

  .welcome-message h2 {
    font-size: 28px;
  }

  .welcome-icon {
    font-size: 48px;
    width: 64px !important;
    height: 64px !important;
  }

  .prompts-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .prompt-card {
    min-height: 60px !important;
    padding: 14px !important;
  }

  .prompt-icon {
    width: 28px !important;
    height: 28px !important;
  }

  .prompt-icon svg {
    width: 20px !important;
    height: 20px !important;
  }

  .prompt-text {
    font-size: 13px !important;
  }

  /* Touch-friendly conversation items */
  .conversation-item {
    padding: 14px 12px;
    margin-bottom: 2px;
    border-radius: 12px;
    min-height: 48px;
  }

  .sidebar-header {
    padding: 16px;
    min-height: 64px;
  }

  .new-chat-btn, .toggle-sidebar-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  /* Hide scrollbars on mobile but keep functionality */
  *::-webkit-scrollbar {
    display: none;
  }

  /* Also hide for Firefox */
  * {
    scrollbar-width: none;
  }

  /* Ensure smooth scrolling on mobile */
  html {
    -webkit-overflow-scrolling: touch;
  }

  /* Search banner on mobile */
  .search-banner {
    max-width: 100%;
    margin: 8px 0 16px 0;
  }

  .search-query {
    max-width: 200px;
  }

  .search-text {
    font-size: 12px;
  }

  /* Scroll to bottom button - mobile positioning */
  .scroll-to-bottom-btn {
    bottom: 110px; /* Above input area in browser */
    width: 40px;
    height: 40px;
  }
}

/* PWA Standalone Mode - Extra padding to prevent overlap */

@media (max-width: 768px) and (display-mode: standalone) {
  .messages-container {
    padding-bottom: 140px !important; /* Extra padding for PWA mode */
  }

  .scroll-to-bottom-btn {
    bottom: 140px !important; /* Higher position in PWA mode */
  }

  /* Ensure input area fits properly in PWA */
  .input-area {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .input-form {
    width: 100% !important;
    max-width: 100% !important;
  }

  .input-wrapper {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* iPhone 12 Pro Max and larger screens - specific fixes */

@media (min-width: 428px) and (max-width: 500px) {
  /* Ensure input area is properly positioned on larger iPhone screens */
  .input-area {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  
  .input-wrapper textarea {
    /* Extra aggressive fixes for iPhone 12 Pro Max */
    font-size: 16px !important;
    -webkit-user-select: text !important;
    user-select: text !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    /* Force focusability */
    position: relative;
    z-index: 999 !important;
  }
  
  /* Ensure messages are visible */
  .message-text {
    visibility: visible !important;
    opacity: 1 !important;
    display: block !important;
  }
  
  .message.assistant .message-text {
    visibility: visible !important;
    opacity: 1 !important;
    display: block !important;
  }
}

/* Extra small phones */

@media (max-width: 375px) {
  .messages-container {
    padding: 12px 12px;
    padding-bottom: 95px; /* Normal padding for browser */
  }

  .input-area {
    padding: 10px 12px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .message-avatar {
    width: 26px;
    height: 26px;
    font-size: 11px;
  }
}

/* PWA Standalone Mode - Extra small phones */

@media (max-width: 375px) and (display-mode: standalone) {
  .messages-container {
    padding-bottom: 140px !important; /* Extra padding for PWA mode */
  }

  .input-area {
    width: 100% !important;
    max-width: 100% !important;
  }

  .input-form {
    width: 100% !important;
    max-width: 100% !important;
  }

  .input-wrapper {
    width: 100% !important;
    max-width: 100% !important;
  }

  .message.user .message-content {
    max-width: 90%;
  }

  /* Even smaller code blocks on tiny screens */
  .message-text pre {
    font-size: 12px;
    padding: 10px;
  }

  .message-text pre code,
  .message-text code {
    font-size: 12px;
  }
}

/* Tablet adjustments */

@media (min-width: 769px) and (max-width: 1024px) {
  .messages-container, .input-form {
    max-width: 720px;
  }
  
  .sidebar {
    width: 280px;
  }
}

/* Large screens */

@media (min-width: 1025px) {
  .sidebar.closed {
    transform: translateX(-100%);
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 10;
  }
  
  .floating-toggle-btn {
    display: block;
  }

  .chat-container {
    transition: margin-left 0.3s ease;
  }

  /* Guest Sign In Button - Mobile */
  .guest-signin-btn {
    bottom: 80px; /* Above input area */
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    font-size: 13px;
  }

  .guest-signin-btn:hover {
    transform: translateX(-50%) translateY(-2px);
  }

  .guest-signin-btn:active {
    transform: translateX(-50%) translateY(0);
  }

  /* Edit message styles for mobile */
  .message.user .user-message.editing {
    max-width: 100%;
    background: transparent;
    padding: 0;
  }

  .message.user .user-message.editing .message-text {
    background: transparent;
    padding: 0;
  }

  /* Make sure edit container fills the message area on mobile */
  .user-message.editing .edit-message-container {
    width: 100%;
  }
}

/* Model Picker - Claude-style model selector */

.model-picker {
  position: relative;
  display: flex;
  align-items: center;
  margin-right: 8px;
}

.model-picker-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.model-picker-trigger:hover:not(:disabled) {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.model-picker-trigger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.model-picker-trigger .model-name {
  font-size: 13px;
}

.model-picker-trigger .chevron {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
  color: var(--text-secondary);
}

.model-picker-trigger .chevron.open {
  transform: rotate(180deg);
}

/* Dropdown */
.model-picker-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 280px;
  background: var(--panel-2);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  padding: 6px;
  z-index: 1000;
  animation: slideUp 0.15s ease-out;
}

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

/* Model option */
.model-option {
  width: 100%;
  padding: 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  text-align: left;
}

.model-option:hover {
  background: var(--hover-bg);
}

.model-option.selected {
  background: var(--hover-bg);
}

.model-option-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.model-option-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-option-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.checkmark {
  color: var(--accent-color);
  flex-shrink: 0;
}

.model-option-description {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.4;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .model-picker-dropdown {
    min-width: 260px;
  }

  .model-picker-trigger .model-name {
    font-size: 12px;
  }

  .model-option-name {
    font-size: 13px;
  }

  .model-option-description {
    font-size: 11px;
  }
}

pre code.hljs {
  display: block;
  overflow-x: auto;
  padding: 1em
}
code.hljs {
  padding: 3px 5px
}
/*!
  Theme: GitHub Dark
  Description: Dark theme as seen on github.com
  Author: github.com
  Maintainer: @Hirse
  Updated: 2021-05-15

  Outdated base version: https://github.com/primer/github-syntax-dark
  Current colors taken from GitHub's CSS
*/
.hljs {
  color: #c9d1d9;
  background: #0d1117
}
.hljs-doctag,
.hljs-keyword,
.hljs-meta .hljs-keyword,
.hljs-template-tag,
.hljs-template-variable,
.hljs-type,
.hljs-variable.language_ {
  /* prettylights-syntax-keyword */
  color: #ff7b72
}
.hljs-title,
.hljs-title.class_,
.hljs-title.class_.inherited__,
.hljs-title.function_ {
  /* prettylights-syntax-entity */
  color: #d2a8ff
}
.hljs-attr,
.hljs-attribute,
.hljs-literal,
.hljs-meta,
.hljs-number,
.hljs-operator,
.hljs-variable,
.hljs-selector-attr,
.hljs-selector-class,
.hljs-selector-id {
  /* prettylights-syntax-constant */
  color: #79c0ff
}
.hljs-regexp,
.hljs-string,
.hljs-meta .hljs-string {
  /* prettylights-syntax-string */
  color: #a5d6ff
}
.hljs-built_in,
.hljs-symbol {
  /* prettylights-syntax-variable */
  color: #ffa657
}
.hljs-comment,
.hljs-code,
.hljs-formula {
  /* prettylights-syntax-comment */
  color: #8b949e
}
.hljs-name,
.hljs-quote,
.hljs-selector-tag,
.hljs-selector-pseudo {
  /* prettylights-syntax-entity-tag */
  color: #7ee787
}
.hljs-subst {
  /* prettylights-syntax-storage-modifier-import */
  color: #c9d1d9
}
.hljs-section {
  /* prettylights-syntax-markup-heading */
  color: #1f6feb;
  font-weight: bold
}
.hljs-bullet {
  /* prettylights-syntax-markup-list */
  color: #f2cc60
}
.hljs-emphasis {
  /* prettylights-syntax-markup-italic */
  color: #c9d1d9;
  font-style: italic
}
.hljs-strong {
  /* prettylights-syntax-markup-bold */
  color: #c9d1d9;
  font-weight: bold
}
.hljs-addition {
  /* prettylights-syntax-markup-inserted */
  color: #aff5b4;
  background-color: #033a16
}
.hljs-deletion {
  /* prettylights-syntax-markup-deleted */
  color: #ffdcd7;
  background-color: #67060c
}
.hljs-char.escape_,
.hljs-link,
.hljs-params,
.hljs-property,
.hljs-punctuation,
.hljs-tag {
  /* purposely ignored */
  
}/**
 * Modal Styles
 * Styles for confirmation modals and dialogs
 */

/* Backdrop overlay */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Modal container */
.modal-container {
  background: var(--panel-2);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-width: 450px;
  width: 90%;
  animation: slideUp 0.3s ease-out;
  overflow: hidden;
}

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

/* Modal header */
.modal-header {
  padding: 24px 24px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: var(--panel-1);
  color: var(--text-primary);
}

/* Modal body */
.modal-body {
  padding: 24px;
}

.modal-body p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.6;
}

/* Modal footer */
.modal-footer {
  padding: 16px 24px 24px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Modal buttons */
.modal-btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  outline: none;
}

.modal-btn-cancel {
  background: var(--panel-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.modal-btn-cancel:hover {
  background: var(--panel-3);
  border-color: var(--text-secondary);
}

.modal-btn-confirm {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.modal-btn-confirm:hover {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
  transform: translateY(-1px);
}

.modal-btn-confirm:active {
  transform: translateY(0);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .modal-container {
    max-width: 90%;
    margin: 20px;
  }

  .modal-header {
    padding: 20px 20px 12px;
  }

  .modal-header h2 {
    font-size: 18px;
  }

  .modal-body {
    padding: 20px;
  }

  .modal-body p {
    font-size: 14px;
  }

  .modal-footer {
    padding: 12px 20px 20px;
    flex-direction: column-reverse;
  }

  .modal-btn {
    width: 100%;
    padding: 12px;
  }
}

/**
 * Login Modal styles - Dark theme matching Luxra branding
 */

/* Modal backdrop */
.login-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease-out;
  padding: 20px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Modal container */
.login-modal-container {
  background: var(--panel);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease-out;
  position: relative;
}

.login-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
}

.login-modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
}

.login-modal-content {
  position: relative;
}

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

.login-header {
  background: linear-gradient(135deg, rgba(166, 196, 247, 0.1) 0%, rgba(123, 168, 232, 0.1) 100%);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 40px 30px 30px;
  text-align: center;
  position: relative;
}

.login-logo {
  width: auto;
  height: 60px;
  margin-bottom: 20px;
  transition: transform 0.3s ease;
  object-fit: contain;
}

.login-logo:hover {
  transform: scale(1.05);
}

.login-header h1 {
  margin: 0 0 8px 0;
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
}

.login-header p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  font-weight: 400;
}

.login-content {
  padding: 30px 40px;
}

.login-content h2 {
  margin: 0 0 12px 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.login-subtitle {
  margin: 0 0 30px 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  text-align: center;
}

.google-login-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
  padding: 20px;
  background: rgba(166, 196, 247, 0.05);
  border-radius: 12px;
  border: 1px solid var(--border);
  transition: all 0.3s ease;
}

.google-login-wrapper:hover {
  background: rgba(166, 196, 247, 0.08);
  border-color: rgba(166, 196, 247, 0.3);
}

.login-features {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.feature {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.feature svg {
  color: var(--accent);
  flex-shrink: 0;
}

.login-footer {
  background: rgba(166, 196, 247, 0.03);
  border-top: 1px solid var(--border);
  padding: 16px 30px;
  text-align: center;
}

.login-footer p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* Mobile responsive */
@media (max-width: 600px) {
  .login-modal-backdrop {
    padding: 10px;
  }

  .login-modal-container {
    max-height: 95vh;
    border-radius: 12px;
  }

  .login-header {
    padding: 30px 20px 24px;
  }

  .login-logo {
    height: 50px;
    width: auto;
  }

  .login-header h1 {
    font-size: 24px;
  }

  .login-header p {
    font-size: 13px;
  }

  .login-content {
    padding: 24px 20px;
  }

  .login-content h2 {
    font-size: 20px;
  }

  .login-footer {
    padding: 12px 20px;
  }
}

/**
 * Guest Banner Styles
 * Shows usage stats and upgrade prompt for guest users
 */

.guest-banner {
  position: fixed;
  bottom: 90px; /* Position above the fixed input area (input is ~80px + padding) */
  left: 260px; /* Account for sidebar when open */
  right: 16px; /* Match input area padding */
  z-index: 99; /* Below input area (z-index 100) but above messages */
  background: var(--panel);
  border: 1px solid #000000;
  border-radius: 8px;
  padding: 12px 16px;
  max-width: 720px;
  margin: 0 auto;
  color: var(--text);
  animation: slideUp 0.3s ease-out;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.3);
  transition: left 0.3s ease, right 0.3s ease; /* Smooth transition when sidebar toggles */
}

/* Full width when sidebar is closed on desktop */
.sidebar.closed ~ .chat-container .guest-banner {
  left: 16px; /* Just padding when sidebar closed */
}

.guest-banner.warning {
  background: var(--panel);
  border-color: #000000;
}

.guest-banner.error {
  background: var(--panel);
  border-color: #000000;
}

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

.guest-banner-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.guest-banner-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.guest-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.guest-text strong {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.guest-subtext {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.guest-banner-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.guest-close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  transition: all 0.2s ease;
  width: 24px;
  height: 24px;
}

.guest-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.guest-progress {
  width: 100px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.guest-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.guest-banner.warning .guest-progress-bar {
  background: var(--accent);
  opacity: 0.8;
}

.guest-banner.error .guest-progress-bar {
  background: var(--accent);
  opacity: 0.9;
}

.guest-signup-btn {
  padding: 6px 14px;
  background: rgba(166, 196, 247, 0.1);
  color: var(--accent);
  border: 1px solid rgba(166, 196, 247, 0.2);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.guest-signup-btn:hover {
  background: rgba(166, 196, 247, 0.15);
  border-color: rgba(166, 196, 247, 0.3);
}

.guest-signup-btn:active {
  transform: scale(0.98);
}

.guest-banner.warning .guest-signup-btn {
  background: rgba(166, 196, 247, 0.1);
  color: var(--accent);
  border-color: rgba(166, 196, 247, 0.2);
}

.guest-banner.warning .guest-signup-btn:hover {
  background: rgba(166, 196, 247, 0.15);
  border-color: rgba(166, 196, 247, 0.3);
}

.guest-banner.error .guest-signup-btn {
  background: rgba(166, 196, 247, 0.1);
  color: var(--accent);
  border-color: rgba(166, 196, 247, 0.2);
}

.guest-banner.error .guest-signup-btn:hover {
  background: rgba(166, 196, 247, 0.15);
  border-color: rgba(166, 196, 247, 0.3);
}

/* Mobile styles */
@media (max-width: 768px) {
  .guest-banner {
    padding: 12px 16px;
    bottom: 80px; /* Position above mobile input area */
    left: 0 !important;
    right: 0 !important;
    margin: 0 12px; /* Side margins on mobile */
    max-width: calc(100% - 24px); /* Account for margins */
    border-radius: 12px;
  }

  .sidebar.closed ~ .chat-container .guest-banner {
    left: 0 !important;
    right: 0 !important;
  }

  .guest-banner-content {
    gap: 10px;
  }

  .guest-banner-info {
    flex: 1;
    min-width: 0; /* Allow text to shrink */
  }

  .guest-banner-actions {
    gap: 10px;
    flex-shrink: 0;
  }

  .guest-progress {
    width: 80px; /* Smaller on mobile */
  }

  .guest-text {
    min-width: 0; /* Allow text to shrink */
  }

  .guest-text strong {
    font-size: 13px;
    line-height: 1.3;
  }

  .guest-subtext {
    font-size: 11px;
    line-height: 1.3;
  }

  .guest-signup-btn {
    padding: 6px 12px;
    font-size: 12px;
    white-space: nowrap;
  }

  .guest-close-btn {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
  }
}

/* Small mobile devices (iPhone SE, small Androids) */
@media (max-width: 375px) {
  .guest-banner {
    padding: 10px 12px;
    bottom: 75px;
    margin: 0 8px;
    max-width: calc(100% - 16px);
  }

  .guest-banner-content {
    gap: 8px;
  }

  .guest-text strong {
    font-size: 12px;
  }

  .guest-subtext {
    font-size: 10px;
  }

  .guest-progress {
    width: 60px;
  }

  .guest-signup-btn {
    padding: 5px 10px;
    font-size: 11px;
  }

  .guest-close-btn {
    width: 24px;
    height: 24px;
  }
}

/* PWA mode - adjust for safe areas */
@media (display-mode: standalone) {
  .guest-banner {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    left: env(safe-area-inset-left, 0px) !important;
    right: env(safe-area-inset-right, 0px) !important;
    margin-left: max(12px, env(safe-area-inset-left, 0px));
    margin-right: max(12px, env(safe-area-inset-right, 0px));
  }
}

/* Small PWA mode */
@media (max-width: 375px) and (display-mode: standalone) {
  .guest-banner {
    bottom: calc(75px + env(safe-area-inset-bottom, 0px));
    margin-left: max(8px, env(safe-area-inset-left, 0px));
    margin-right: max(8px, env(safe-area-inset-right, 0px));
  }
}

/* Very small screens - stack vertically */
@media (max-width: 320px) {
  .guest-banner-content {
    flex-direction: column;
    align-items: stretch;
  }

  .guest-banner-info {
    justify-content: center;
  }

  .guest-text {
    text-align: center;
  }

  .guest-banner-actions {
    justify-content: space-between;
    width: 100%;
  }

  .guest-progress {
    flex: 1;
    width: auto;
  }
}

/* PWA Install Prompt Styles */

.pwa-install-prompt {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  max-width: 420px;
  width: calc(100% - 32px);
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.pwa-prompt-content {
  background: linear-gradient(135deg, #1a1a1a 0%, #0d0d0d 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 
    0 10px 40px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 16px;
  backdrop-filter: blur(20px);
}

.pwa-prompt-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.pwa-prompt-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pwa-prompt-text {
  flex: 1;
  min-width: 0;
}

.pwa-prompt-text h3 {
  margin: 0 0 4px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.pwa-prompt-text p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ios-share-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #007AFF;
  margin: 0 2px;
}

.pwa-prompt-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.pwa-install-btn,
.pwa-dismiss-btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  white-space: nowrap;
}

.pwa-install-btn {
  background: linear-gradient(135deg, #A6C4F7 0%, #7BA8E8 100%);
  color: #0d0d0d;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(166, 196, 247, 0.3);
}

.pwa-install-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(166, 196, 247, 0.4);
  background: linear-gradient(135deg, #b8d1f9 0%, #8db9ed 100%);
}

.pwa-install-btn:active {
  transform: translateY(0);
}

.pwa-dismiss-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.pwa-dismiss-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .pwa-install-prompt {
    bottom: 90px; /* Above input area */
    max-width: calc(100% - 24px);
  }

  .pwa-prompt-content {
    padding: 14px 16px;
    gap: 12px;
  }

  .pwa-prompt-icon {
    width: 40px;
    height: 40px;
  }

  .pwa-prompt-text h3 {
    font-size: 14px;
  }

  .pwa-prompt-text p {
    font-size: 12px;
  }

  .pwa-install-btn,
  .pwa-dismiss-btn {
    padding: 7px 12px;
    font-size: 12px;
  }
}

/* Extra small phones */
@media (max-width: 375px) {
  .pwa-prompt-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .pwa-prompt-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .pwa-install-prompt {
    bottom: 10px;
  }

  .pwa-prompt-content {
    padding: 10px 14px;
  }

  .pwa-prompt-icon {
    width: 36px;
    height: 36px;
  }
}

