/* Design System Variables */
* {
  -webkit-tap-highlight-color: transparent;
}

*:focus {
  outline: none;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-message-user: #e0f2fe;
  --bg-message-assistant: transparent;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-color: #3b82f6;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);
  
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  
  --error-color: #ef4444;
  --success-color: #22c55e;
  --warning-color: #eab308;
  
  --sidebar-width: 280px;
  --header-height: 64px;
  
  --font-sans: 'Inter', sans-serif;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'Fira Code', monospace;
  
  --shadow-lg: 0 10px 30px -10px rgba(15, 23, 42, 0.08), 0 4px 12px -5px rgba(15, 23, 42, 0.05);
  --glass-bg: rgba(255, 255, 255, 0.95);
  --glass-blur: none;
}

/* Base Resets */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  height: calc(var(--vh, 1vh) * 100);
  width: 100vw;
  overflow: hidden;
  line-height: 1.6;
  animation: fadeInPage 0.25s ease-out forwards;
}

input, button, select, textarea {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Helper Classes */
.hidden {
  display: none !important;
}

.glassmorphism {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
}

.gradient-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.btn-glow:hover {
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.btn-icon:hover {
  background-color: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

/* Mobile menu button - hidden on desktop */
.btn-mobile-menu {
  display: none;
}

/* App Container Layout */
.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  height: calc(var(--vh, 1vh) * 100);
  width: 100vw;
  overflow: hidden;
}

/* Sidebar Styling */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  transition: width 0.3s ease, transform 0.3s ease;
  z-index: 100;
  overflow: hidden;
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}


/* Sidebar backdrop for mobile */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  pointer-events: none;
}

.sidebar-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
  flex-shrink: 0;
  margin-left: 0.1rem;
}

.logo:hover {
  opacity: 0.85;
}

.logo:active {
  transform: scale(0.97);
}

.logo-icon-small {
  font-size: 1.25rem;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  transform: translateY(-0.04em);
}

.logo-text {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.2px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
  line-height: 1;
}

.btn-new-chat {
  margin: 16px;
  background-color: rgba(0, 0, 0, 0.02);
  border: 1px dashed rgba(0, 0, 0, 0.12);
  color: var(--text-primary);
  justify-content: flex-start;
  padding: 12px 16px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}

.btn-new-chat:hover {
  background-color: rgba(0, 0, 0, 0.04);
  border-color: var(--accent-color);
}

.sidebar-section {
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--border-color);
}

/* Admin Section in Sidebar */
.admin-section {
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.admin-section .section-label {
  margin-bottom: 8px;
}

.admin-select-wrapper {
  position: relative;
  width: 100%;
}

.admin-select-wrapper::after {
  content: "▾";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.admin-select {
  width: 100%;
  padding: 10px 30px 10px 12px;
  border-radius: 8px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: all 0.3s;
  color: var(--text-primary);
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.admin-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 10px var(--accent-glow);
}

.sidebar.collapsed .admin-section {
  display: none !important;
}

.section-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}

/* Custom Styled Select */
.custom-select-wrapper {
  position: relative;
  width: 100%;
}

.custom-select {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: all 0.3s;
}

.custom-select:focus {
  outline: none;
  border-color: var(--border-focus);
}

.custom-select-wrapper::after {
  content: "▾";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* Chats List */
.chats-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  overflow: hidden;
}

.chats-section .section-label {
  padding: 0 20px;
  margin-bottom: 12px;
}

.chats-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: all 0.2s;
  position: relative;
  text-decoration: none;
  color: inherit;
}

.chat-item:hover {
  background-color: rgba(0, 0, 0, 0.035);
}

.chat-item.active {
  background-color: rgba(59, 130, 246, 0.08);
}

.chat-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background-color: var(--accent-color);
  border-radius: 8px 0 0 8px;
}

.chat-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.chat-item-title {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
}

.chat-item.active .chat-item-title {
  color: var(--text-primary);
}

.chat-item-actions {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.2s;
  padding-left: 32px;
  padding-right: 12px;
  align-items: center;
  border-radius: 0 8px 8px 0;
  pointer-events: none;
}

.chat-item-actions button {
  pointer-events: auto;
}

.chat-item:hover .chat-item-actions {
  opacity: 1;
  background: linear-gradient(90deg, rgba(239, 241, 243, 0) 0%, rgba(239, 241, 243, 1) 35%);
}

.chat-item.active:hover .chat-item-actions {
  opacity: 1;
  background: linear-gradient(90deg, rgba(233, 240, 252, 0) 0%, rgba(233, 240, 252, 1) 35%);
}

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

.chat-action-btn:hover {
  color: var(--text-primary);
  background-color: rgba(0, 0, 0, 0.05);
}

.chat-action-btn.delete:hover {
  color: var(--error-color);
  background-color: rgba(239, 68, 68, 0.1);
}

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

/* Skeletons */
.skeleton-list {
  padding: 0 10px;
}

.skeleton-item {
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.03) 25%, rgba(0, 0, 0, 0.08) 50%, rgba(0, 0, 0, 0.03) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  margin-bottom: 8px;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-color);
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: row;
  align-items: center;
  min-width: 0;
  margin-right: 4px;
  gap: 4px;
}

.user-profile .username {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: translateY(1.5px);
  flex: 1;
  min-width: 0;
}

.user-info .status {
  font-size: 0.7rem;
  color: var(--success-color);
}

/* Main Content Area Styling */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  min-width: 0;
}

/* Top Nav Bar */
.top-nav {
  height: var(--header-height);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 50;
  min-width: 0;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.nav-right {
  display: flex;
  align-items: center;
}

/* Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 40px 24px 20px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
}

.welcome-screen {
  margin: auto;
  max-width: 800px;
  width: 100%;
  animation: fadeIn 0.6s ease-out;
}

.welcome-content {
  text-align: center;
  padding: 20px 0;
}

.welcome-content h1 {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 3rem;
  letter-spacing: -0.5px;
  margin-bottom: 18px;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.welcome-content h1:hover {
  opacity: 0.85;
}

.welcome-content h1:active {
  transform: scale(0.97);
}

.welcome-title-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  left: -0.02em;
}

.welcome-title-wrapper .brand-hand {
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-52%);
  margin-right: 0.25em;
}

.welcome-title-wrapper::after {
  display: none;
}

.welcome-subtitle {
  color: var(--text-secondary);
  font-size: 1.2rem;
  margin-bottom: 40px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}


/* Message Bubbles */
.message-wrapper {
  width: 100%;
  max-width: 800px;
  margin: 0 auto 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  animation: fadeIn 0.3s ease-out;
  min-width: 0;
}

.message-wrapper.user {
  justify-content: flex-end;
}

.message-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message-wrapper.assistant .message-avatar {
  background: var(--accent-gradient);
  color: #fff;
}

.message-wrapper.assistant .message-avatar .brand-hand {
  background: linear-gradient(135deg, #ffeb3b 0%, #fbc02d 100%);
  position: relative;
  left: 0.02em;
}

.message-bubble {
  padding: 14px 20px;
  border-radius: 18px;
  max-width: calc(100% - 3.5rem);
  position: relative;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: break-word;
}

.message-wrapper.user .message-bubble {
  background-color: var(--bg-message-user);
  color: var(--text-primary);
  border-radius: 1.25rem;
  min-height: 2.5rem;
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 1.1rem;
}

.message-wrapper.assistant .message-bubble {
  background-color: var(--bg-message-assistant);
  color: var(--text-primary);
  width: 100%;
  padding-top: 0.51rem;
  padding-left: 0;
  padding-bottom: 14px;
}

/* Message Markdown Content Styling */

.message-bubble p {
  margin-bottom: 12px;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble ul, .message-bubble ol {
  margin-left: 20px;
  margin-bottom: 12px;
}

.message-bubble li {
  margin-bottom: 4px;
}

.message-bubble h1, .message-bubble h2, .message-bubble h3, .message-bubble h4 {
  font-family: var(--font-display);
  margin-top: 18px;
  margin-bottom: 8px;
  font-weight: 600;
}

.message-bubble h1 { font-size: 1.4rem; }
.message-bubble h2 { font-size: 1.25rem; }
.message-bubble h3 { font-size: 1.1rem; }

.message-bubble code {
  font-family: var(--font-mono);
  background-color: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9rem;
}

.message-bubble pre {
  margin: 16px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.message-bubble pre code {
  display: block;
  padding: 16px;
  overflow-x: auto;
  background-color: #121824 !important;
  font-size: 0.88rem;
  line-height: 1.5;
  touch-action: pan-x pan-y;
}

/* Pre / Code Wrapper Header */
.code-container {
  margin: 16px 0;
  border-radius: 10px;
  overflow: hidden;
  background-color: #121824;
}

.message-bubble .code-container pre {
  margin: 0;
  border-radius: 0;
  border: none;
}

.code-header {
  background-color: #121824;
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.code-lang {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
  font-family: var(--font-mono);
}

.btn-copy-code {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.2s;
}

.btn-copy-code:hover {
  color: var(--text-primary);
}

.btn-copy-code svg {
  width: 14px;
  height: 14px;
}

/* Blockquotes & Tables */
.message-bubble blockquote {
  border-left: 4px solid var(--accent-color);
  padding-left: 16px;
  margin: 16px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message-bubble .table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-color) var(--bg-tertiary);
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
}

.message-bubble .table-wrapper::-webkit-scrollbar {
  height: 8px;
  display: block;
}

.message-bubble .table-wrapper::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.message-bubble .table-wrapper::-webkit-scrollbar-thumb {
  background: var(--accent-color);
  border-radius: 4px;
}

.message-bubble .table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--accent-hover);
}

.message-bubble table {
  border-collapse: collapse;
  font-size: 0.9rem;
  white-space: nowrap;
}

.message-bubble .table-wrapper table {
  margin: 0;
}

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

.message-bubble th {
  background-color: rgba(0, 0, 0, 0.03);
  font-weight: 600;
}

.message-bubble img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* Streaming Typing Cursor */
.streaming-indicator {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  margin-top: 4px;
}

.streaming-indicator span {
  width: 8px;
  height: 8px;
  background-color: var(--accent-color);
  border-radius: 50%;
  display: inline-block;
  animation: bounce 1.4s infinite ease-in-out both;
}

.streaming-indicator span:nth-child(1) { animation-delay: -0.32s; }
.streaming-indicator span:nth-child(2) { animation-delay: -0.16s; }

/* Input Bar Footer */
.chat-footer {
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-width: 0;
}

.input-container {
  width: 100%;
  max-width: 800px;
  border-radius: 16px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  transition: border-color 0.3s, box-shadow 0.3s;
  min-width: 0;
}

.input-container:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.15);
}

.input-container textarea {
  flex: 1;
  resize: none;
  background: none;
  border: none;
  font-size: 0.98rem;
  line-height: 1.5;
  height: 24px;
  color: var(--text-primary);
  max-height: 200px;
  outline: none;
  padding: 0;
}

.input-container textarea::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background-color: rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.btn-send:not(.disabled) {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

.btn-send:not(.disabled):hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.btn-send.disabled {
  cursor: not-allowed;
}

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



.footer-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 10px;
  text-align: center;
}

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

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

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

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

@keyframes pulseGlow {
  0%, 100% { opacity: 0.8; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); text-shadow: 0 0 15px rgba(139, 92, 246, 0.5); }
}



.brand-hand {
  display: inline-block;
  width: 1em;
  height: 1em;
  background: var(--accent-gradient);
  -webkit-background-clip: border-box;
  background-clip: border-box;
  -webkit-text-fill-color: initial;
  -webkit-mask: url("/brand-hand.png") no-repeat center / contain;
  mask: url("/brand-hand.png") no-repeat center / contain;
}

/* Responsive Breakpoints */

/* Sidebar collapsed state (desktop) */
.sidebar.collapsed {
  width: 64px;
}

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

.sidebar.collapsed .logo .logo-text,
.sidebar.collapsed .section-label,
.sidebar.collapsed .chats-list,
.sidebar.collapsed .btn-new-chat span,
.sidebar.collapsed .username,
.sidebar.collapsed .user-actions {
  display: none;
}



.sidebar.collapsed #btn-toggle-sidebar {
  display: none;
}

.sidebar.collapsed .btn-new-chat {
  margin: 16px 8px;
  padding: 12px;
  justify-content: center;
}

.sidebar.collapsed .sidebar-footer {
  justify-content: center;
  padding: 16px 8px;
}

.sidebar.collapsed .user-profile {
  justify-content: center;
}

.sidebar.collapsed .icon-collapse {
  display: none;
}

.sidebar.collapsed .icon-expand {
  display: block !important;
}

.sidebar:not(.collapsed) .icon-expand {
  display: none !important;
}

.sidebar.collapsed .logo {
  cursor: pointer;
  position: relative;
}

.sidebar.collapsed .logo .logo-icon-small {
  transition: opacity 0.2s;
}

.sidebar.collapsed .logo:hover .logo-icon-small {
  opacity: 0;
}

.sidebar.collapsed .logo::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%233b82f6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.sidebar.collapsed .logo:hover::after {
  opacity: 1;
}

.sidebar:not(.collapsed) #btn-toggle-sidebar {
  display: flex;
}

@media (max-width: 768px) {
  body {
    height: 100dvh;
    height: calc(var(--vh, 1vh) * 100);
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 100;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }

  .chat-item.active .chat-item-actions {
    opacity: 1;
    background: linear-gradient(90deg, rgba(233, 240, 252, 0) 0%, rgba(233, 240, 252, 1) 35%);
  }

  
  .top-nav {
    padding: 0 12px;
  }

  .nav-left {
    gap: 8px;
  }
  
  .chat-footer {
    padding: 0 12px calc(12px + env(safe-area-inset-bottom, 8px));
  }

  .input-container {
    padding: 10px 12px;
    border-radius: 14px;
  }

  .btn-mobile-menu {
    display: flex;
  }

  #btn-toggle-sidebar {
    display: none;
  }

  .chat-messages {
    padding: 20px 12px 12px;
  }

  .welcome-content h1 {
    font-size: 2.2rem;
  }

  .welcome-subtitle {
    font-size: 0.88rem;
    margin-bottom: 28px;
  }

}

/* Tablet (landscape) safe area adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
  .chat-footer {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 24px));
  }
}



/* Hide sidebar-section if not used */
.sidebar-section {
  display: none;
}

.btn-action-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  padding: 0;
}

.btn-action-icon svg {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
}

.btn-action-icon:hover {
  background-color: var(--bg-tertiary) !important;
  color: var(--accent-color) !important;
}

.btn-action-icon:hover svg {
  transform: scale(1.1);
}

#btn-logout:hover {
  background-color: rgba(239, 68, 68, 0.08) !important;
  color: var(--error-color) !important;
}

/* Custom Thought / Reasoning Block styling */
.thought-container {
  margin-bottom: 12px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
}

.thought-details {
  width: 100%;
}

.thought-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  background-color: var(--bg-tertiary);
  transition: background-color 0.2s;
}

.thought-summary:hover {
  background-color: var(--border-color);
}

.thought-summary::-webkit-details-marker {
  display: none;
}

.thought-summary::after {
  content: '▼';
  font-size: 0.65rem;
  margin-left: auto;
  transition: transform 0.2s;
  opacity: 0.6;
}

.thought-details[open] .thought-summary::after {
  transform: rotate(-180deg);
}

.thought-body {
  padding: 12px 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-color);
  line-height: 1.5;
  font-style: italic;
}

.answer-body {
  font-size: 0.92rem;
  line-height: 1.6;
}

.typing-indicator {
  color: var(--text-muted) !important;
  font-size: 0.88rem !important;
  font-style: italic !important;
  user-select: none !important;
  display: block !important;
  width: auto !important;
  height: auto !important;
  background: none !important;
  border-radius: 0 !important;
  margin-top: 1.5px !important;
  line-height: 1.6 !important;
}

.typing-dot {
  font-style: normal !important;
  display: inline-block;
  opacity: 0.2;
  animation: typingDotFade 1.4s infinite;
  margin-left: 1px;
}

.typing-dot:nth-of-type(1) {
  animation-delay: 0s;
}

.typing-dot:nth-of-type(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-of-type(3) {
  animation-delay: 0.4s;
}

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

/* Search Sources Styling */
.message-sources {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-color);
  width: 100%;
}

.sources-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sources-title svg {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
}

.sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary) !important;
  font-size: 0.82rem;
  text-decoration: none !important;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.source-item:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--border-focus);
  color: var(--accent-color) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.source-index {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 700;
  transition: all 0.2s;
}

.source-item:hover .source-index {
  background-color: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
}

.source-name {
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Clickable Citation Links */
.citation-link {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-color);
  text-decoration: none !important;
  vertical-align: super;
  line-height: 0;
  margin: 0 2px;
  display: inline-block;
  transition: all 0.2s ease;
  opacity: 0.85;
}

.citation-link:hover {
  color: var(--accent-color);
  opacity: 1;
  text-shadow: 0 0 8px var(--accent-glow);
  transform: scale(1.15) translateY(-1px);
}

/* Animations for streaming search sources */
.message-sources.animate-in {
  border-top: 1px dashed var(--border-color);
}

.message-sources.animate-in .sources-title {
  opacity: 0;
  animation: instantShow 0.01s forwards;
  animation-delay: 0.1s;
}

.message-sources.animate-in .source-item {
  opacity: 0;
  animation: instantShow 0.01s forwards;
}

.message-sources.animate-in .source-item:nth-child(1) { animation-delay: 0.2s; }
.message-sources.animate-in .source-item:nth-child(2) { animation-delay: 0.3s; }
.message-sources.animate-in .source-item:nth-child(3) { animation-delay: 0.4s; }
.message-sources.animate-in .source-item:nth-child(4) { animation-delay: 0.5s; }
.message-sources.animate-in .source-item:nth-child(5) { animation-delay: 0.6s; }
.message-sources.animate-in .source-item:nth-child(6) { animation-delay: 0.7s; }
.message-sources.animate-in .source-item:nth-child(7) { animation-delay: 0.8s; }
.message-sources.animate-in .source-item:nth-child(8) { animation-delay: 0.9s; }
.message-sources.animate-in .source-item:nth-child(9) { animation-delay: 1.0s; }
.message-sources.animate-in .source-item:nth-child(10) { animation-delay: 1.1s; }

@keyframes instantShow {
  to {
    opacity: 1;
  }
}

/* Header Premium Button */
.btn-upgrade-premium {
  display: none !important;
  font-size: 0.85rem;
  padding: 6px 14px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent-gradient);
  color: white;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  height: 34px;
  white-space: nowrap;
}

.btn-upgrade-premium:disabled {
  opacity: 1;
  cursor: default;
}

@media (max-width: 600px) {
  .btn-upgrade-premium .btn-text-desktop {
    display: none;
  }
  .btn-upgrade-premium {
    padding: 6px 10px;
    font-size: 0.8rem;
  }
}

/* Modal Overlay & Card */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  overscroll-behavior: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  max-width: 550px;
  width: 100%;
  padding: 24px;
  position: relative;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: none;
  transform: translateY(20px);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.modal-close-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.premium-modal-header {
  text-align: center;
  margin-bottom: 16px;
}

.premium-crown-icon {
  font-size: 2.4rem;
  margin-bottom: 6px;
  line-height: 1;
  display: inline-block;
  animation: float 3s ease-in-out infinite;
}

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

.premium-modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

/* Feature Ribbon */
.premium-features-row {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--bg-secondary);
  border: 1px dashed var(--border-color);
  border-radius: 12px;
  padding: 10px 14px;
}

.premium-feature-tag {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* Plans Grid */
.premium-plans {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.plan-card {
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-secondary);
}

.plan-card:hover {
  transform: translateY(-2px);
  border-color: #f59e0b;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.1);
}

.plan-card.selected {
  border-color: #f59e0b;
  background-color: rgba(245, 158, 11, 0.05);
  box-shadow: 0 4px 20px rgba(245, 158, 11, 0.15);
}

.plan-card.selected::after {
  content: '✓';
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: #f59e0b;
  color: white;
  border-radius: 50%;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.plan-card .plan-badge {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.2);
}

.plan-card.featured {
  border-color: var(--border-color);
}

.plan-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.plan-price {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.plan-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-pay {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  border: none;
  color: white;
  transition: all 0.3s;
}

.btn-pay:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.btn-pay:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--text-muted);
}

.modal-footer-notice {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 16px;
  line-height: 1.4;
}

/* Warning Banner for Disabled Search */
.warning-banner {
  background-color: rgba(234, 179, 8, 0.1);
  border: 1px solid rgba(234, 179, 8, 0.2);
  color: #a16207;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  animation: fadeIn 0.3s forwards;
}

/* Mobile responsive fixes */
@media (max-width: 576px) {
  .premium-plans {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .modal-card {
    padding: 24px 16px;
  }
}

