/* ==========================================================================
   هوشا چت (Hoosha AI) - Comprehensive Modern Design System
   Persian & English Bilingual AI Chatbot with Canvas & Code Runner
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@200;300;400;500;600;700;800;900&family=Fira+Code:wght@400;500;600&display=swap');

/* --- Root Design Tokens (Dark Mode Default) --- */
:root {
  --font-sans: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'Fira Code', 'Cascadia Code', Consolas, Monaco, monospace;

  /* Color Palette - Dark Mode (Obsidian / Neon Accent) */
  --bg-app: #090d16;
  --bg-sidebar: #0f1523;
  --bg-sidebar-card: #151d30;
  --bg-chat: #090d16;
  --bg-surface: #141b2d;
  --bg-surface-hover: #1c263e;
  --bg-surface-active: #23304e;
  --bg-glass: rgba(18, 25, 42, 0.75);
  --bg-glass-input: rgba(15, 21, 35, 0.85);
  --bg-bubble-user: linear-gradient(135deg, #4f46e5 0%, #6366f1 50%, #4338ca 100%);
  --bg-bubble-ai: #131b2e;
  --bg-code-header: #0d121f;
  --bg-code-block: #080c14;
  --bg-canvas: #0d121f;

  /* Accent & Gradients */
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.15);
  --accent-cyan: #06b6d4;
  --accent-purple: #a855f7;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --gradient-brand: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #06b6d4 100%);
  --gradient-glow: radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.25) 0%, transparent 70%);

  /* Text & Typography */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #090d16;
  --text-link: #38bdf8;

  /* Borders & Dividers */
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-medium: rgba(255, 255, 255, 0.14);
  --border-focus: rgba(99, 102, 241, 0.6);
  --border-glow: 0 0 15px rgba(99, 102, 241, 0.3);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 35px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.7);

  /* Dimensions */
  --sidebar-width: 290px;
  --canvas-width: 540px;
  --header-height: 64px;
  --border-radius-sm: 8px;
  --border-radius-md: 12px;
  --border-radius-lg: 18px;
  --border-radius-xl: 24px;
  --border-radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 350ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Light Mode Override --- */
[data-theme="light"] {
  --bg-app: #f8fafc;
  --bg-sidebar: #f1f5f9;
  --bg-sidebar-card: #e2e8f0;
  --bg-chat: #ffffff;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --bg-surface-active: #e2e8f0;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --bg-glass-input: rgba(255, 255, 255, 0.95);
  --bg-bubble-user: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  --bg-bubble-ai: #f8fafc;
  --bg-code-header: #f1f5f9;
  --bg-code-block: #0f172a;
  --bg-canvas: #ffffff;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;
  --text-link: #0284c7;

  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-medium: rgba(0, 0, 0, 0.15);
  --border-focus: rgba(99, 102, 241, 0.5);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.15);
}

/* --- Global Reset & Base Styles --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.25);
  border-radius: var(--border-radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.45);
}

/* App Container Layout */
#app-container {
  display: flex;
  width: 100%;
  max-width: 100%;
  height: 100%;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  background: var(--bg-app);
}

/* ==========================================================================
   Sidebar Styles
   ========================================================================== */
#sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: transform var(--transition-normal), width var(--transition-normal);
  flex-shrink: 0;
  user-select: none;
}

#sidebar.collapsed {
  transform: translateX(100%);
  margin-right: calc(-1 * var(--sidebar-width));
}

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

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-logo-img {
  width: 36px;
  height: 36px;
  border-radius: var(--border-radius-md);
  object-fit: cover;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 800;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.new-chat-btn-wrap {
  padding: 12px 16px 8px;
}

.btn-new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 16px;
  background: var(--gradient-brand);
  color: #ffffff;
  border: none;
  border-radius: var(--border-radius-md);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
  transition: all var(--transition-fast);
}

.btn-new-chat:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
  filter: brightness(1.08);
}

.btn-new-chat:active {
  transform: translateY(0);
}

.chat-search-wrap {
  padding: 6px 16px 10px;
}

.search-input-box {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  padding: 7px 12px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  transition: border-color var(--transition-fast);
}

.search-input-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.search-input-box input {
  background: transparent;
  border: none;
  outline: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  width: 100%;
}

.search-input-box input::placeholder {
  color: var(--text-muted);
}

/* Chat Sessions List */
.sidebar-sessions {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-group-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 10px 12px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  height: 34px;
  min-height: 34px;
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  border: 1px solid transparent;
  gap: 6px;
  margin-bottom: 2px;
}

.session-item:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.session-item.active {
  background: var(--bg-surface-active);
  color: var(--text-primary);
  font-weight: 600;
  border-color: rgba(99, 102, 241, 0.35);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.session-title-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.session-chat-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--text-muted);
}

.session-item.active .session-chat-icon {
  color: var(--primary);
}

.session-cat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 5px currentColor;
}

.session-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.83rem;
  flex: 1;
  min-width: 0;
  line-height: 1.2;
}

/* دکمه ۳ نقطه کباب تک‌آیکون */
.session-menu-trigger {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
  opacity: 0;
}

.session-item:hover .session-menu-trigger,
.session-item.active .session-menu-trigger,
.session-menu-trigger.active {
  opacity: 0.7;
}

.session-menu-trigger:hover,
.session-menu-trigger.active {
  opacity: 1 !important;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.12);
}

/* منوی شناور پاپ‌آپ برای هر گفتگو (Context Menu) */
.session-context-menu {
  position: fixed;
  z-index: 10000;
  background: var(--bg-surface-elevated, #1c202d);
  border: 1px solid var(--border-medium, rgba(255, 255, 255, 0.14));
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.25);
  padding: 5px;
  min-width: 145px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: sessionMenuFade 0.12s cubic-bezier(0.16, 1, 0.3, 1);
  direction: rtl;
  backdrop-filter: blur(8px);
}

@keyframes sessionMenuFade {
  from {
    opacity: 0;
    transform: scale(0.93) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.session-context-menu .menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  width: 100%;
  text-align: right;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.session-context-menu .menu-item:hover {
  background: var(--bg-surface-hover, rgba(255, 255, 255, 0.08));
  color: var(--text-primary);
}

.session-context-menu .menu-item.danger {
  color: #f87171;
}

.session-context-menu .menu-item.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-sidebar);
}

.sidebar-status-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg-surface);
  border-radius: var(--border-radius-sm);
  font-size: 0.78rem;
  border: 1px solid var(--border-subtle);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-amber);
  box-shadow: 0 0 6px var(--accent-amber);
}

.status-dot.connected {
  background: var(--accent-emerald);
  box-shadow: 0 0 6px var(--accent-emerald);
}

.status-dot.error {
  background: var(--accent-rose);
  box-shadow: 0 0 6px var(--accent-rose);
}

.sidebar-footer-buttons {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.footer-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.footer-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

/* ==========================================================================
   Main Content Area
   ========================================================================== */
#main-content {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-chat);
  overflow: hidden;
}

/* Chat Top Bar */
.chat-topbar {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-icon {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.chat-title-info {
  display: flex;
  flex-direction: column;
}

.current-chat-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-selector-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.model-selector-chip:hover {
  color: var(--primary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-topbar-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.83rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-topbar-action:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.btn-canvas-toggle {
  background: rgba(99, 102, 241, 0.12);
  color: var(--primary);
  border-color: rgba(99, 102, 241, 0.3);
}

.btn-canvas-toggle:hover {
  background: rgba(99, 102, 241, 0.22);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-canvas-toggle.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

/* ==========================================================================
   Chat Messages Container
   ========================================================================== */
#chat-messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scroll-behavior: smooth;
  width: 100%;
  box-sizing: border-box;
}

/* Empty State / Welcome Screen */
.empty-chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: auto;
  max-width: 720px;
  padding: 40px 20px;
  animation: fadeIn 0.4s ease-out;
}

.welcome-logo-glow {
  position: relative;
  margin-bottom: 24px;
}

.welcome-logo-glow::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 140px;
  height: 140px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.4) 0%, transparent 70%);
  filter: blur(25px);
  z-index: 0;
}

.welcome-avatar-img {
  width: 84px;
  height: 84px;
  border-radius: var(--border-radius-lg);
  object-fit: cover;
  position: relative;
  z-index: 1;
  box-shadow: var(--shadow-lg);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.welcome-heading {
  font-size: 1.85rem;
  font-weight: 800;
  margin-bottom: 10px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.welcome-desc {
  font-size: 0.98rem;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 28px;
}

.welcome-features {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 32px;
}

.feature-tag {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-full);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.prompt-suggestions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
}

@media (max-width: 680px) {
  .prompt-suggestions-grid {
    grid-template-columns: 1fr;
  }
}

.suggestion-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: right;
  gap: 6px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.suggestion-card:hover {
  background: var(--bg-surface-hover);
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.suggestion-icon-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-primary);
}

.suggestion-card p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Message Rows */
.chat-row {
  display: flex;
  gap: 14px;
  animation: slideUp 0.25s ease-out;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}

/* چت کاربر: کاملاً سمت راست (RTL) */
.chat-row.user-row {
  flex-direction: row; /* در چیدمان راست‌به‌چپ، آواتار سمت راست و حباب سمت چپ آواتار قرار می‌گیرد */
  justify-content: flex-start; /* در RTL، جهت شروع سمت راست است */
  align-self: flex-start; /* قفل شدن ردیف به سمت راست کانتینر */
  margin-left: auto;
  margin-right: 0;
  max-width: min(85%, 780px);
  width: auto;
}

.chat-row.user-row .message-body-wrap {
  align-items: flex-start; /* در RTL سمت راست قرار می‌گیرد */
  min-width: 0;
  box-sizing: border-box;
}

/* چت هوشا چت (هوش مصنوعی): کاملاً سمت چپ (LTR/RTL Reverse) با مهار کامل عرض و جلوگیری از بیرون‌زدگی */
.chat-row.ai-row {
  flex-direction: row-reverse; /* آواتار در دورترین نقطه سمت چپ، و حباب در سمت راست آواتار */
  justify-content: flex-start; /* در حالت معکوس، شروع از سمت چپ صفحه است */
  align-self: flex-start;
  margin-right: 0;
  margin-left: 0;
  max-width: min(92%, 920px);
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

.chat-row.ai-row .message-body-wrap {
  align-items: flex-start;
  flex: 1 1 0%;
  min-width: 0;
  max-width: calc(100% - 50px);
  width: calc(100% - 50px);
  box-sizing: border-box;
  overflow: hidden;
}

.chat-row.ai-row .message-meta-header {
  flex-direction: row-reverse;
  justify-content: flex-end;
}

.chat-row.ai-row .message-actions-toolbar {
  justify-content: flex-start;
}

/* آواتار پیام‌ها (محدودسازی ابعاد برای جلوگیری از به هم ریختگی تصویر لوگو) */
.message-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  max-width: 36px;
  max-height: 36px;
  border-radius: var(--border-radius-sm);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.88rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  align-self: flex-start;
  margin-top: 2px;
}

.user-avatar {
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  color: #ffffff;
}

.ai-avatar {
  background: #1e1b4b;
  border: 1px solid rgba(99, 102, 241, 0.4);
}

.ai-avatar-img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  display: block;
}

.message-meta-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sender-name {
  font-weight: 700;
  color: var(--text-secondary);
}

.message-time {
  font-size: 0.72rem;
}

/* User Message Bubble */
.user-bubble {
  background: var(--bg-bubble-user);
  color: #ffffff;
  padding: 13px 18px;
  border-radius: 18px 4px 18px 18px;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.25);
  font-size: 0.95rem;
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
  direction: auto;
  text-align: start;
  unicode-bidi: plaintext;
}

/* AI Message Bubble */
.ai-bubble {
  background: var(--bg-bubble-ai);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 18px 22px;
  border-radius: 4px 18px 18px 18px;
  box-shadow: var(--shadow-sm);
  font-size: 0.96rem;
  line-height: 1.8;
  word-break: break-word;
  overflow-wrap: break-word;
  position: relative;
  direction: auto;
  text-align: start;
  unicode-bidi: plaintext;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* Bi-directional Text Support */
.ai-bubble [dir="ltr"],
.ai-bubble .ltr-text,
.ai-bubble pre,
.ai-bubble code,
.ai-bubble .katex-display {
  direction: ltr;
  text-align: left;
}

/* Markdown Rendering in AI Messages with Smart Paragraph Bidi */
.ai-bubble p {
  margin-bottom: 12px;
  text-align: start;
  unicode-bidi: plaintext;
}
.ai-bubble p:last-child {
  margin-bottom: 0;
}

.ai-bubble h1, .ai-bubble h2, .ai-bubble h3, .ai-bubble h4 {
  margin-top: 20px;
  margin-bottom: 10px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.4;
  text-align: start;
  unicode-bidi: plaintext;
}

.ai-bubble h1 { font-size: 1.45rem; border-bottom: 1px solid var(--border-subtle); padding-bottom: 8px; }
.ai-bubble h2 { font-size: 1.25rem; }
.ai-bubble h3 { font-size: 1.1rem; }

.ai-bubble ul, .ai-bubble ol {
  padding-right: 24px;
  margin-bottom: 12px;
  text-align: start;
  unicode-bidi: plaintext;
}

.ai-bubble li {
  margin-bottom: 6px;
  text-align: start;
  unicode-bidi: plaintext;
}

.ai-bubble blockquote {
  border-right: 4px solid var(--primary);
  padding: 10px 16px;
  background: rgba(99, 102, 241, 0.08);
  border-radius: var(--border-radius-sm) 0 0 var(--border-radius-sm);
  margin: 14px 0;
  color: var(--text-secondary);
}

/* ==========================================================================
   Chat Tables & Horizontal Responsive Scrolling
   ========================================================================== */
.chat-table-wrapper {
  margin: 18px 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* عدم نمایش هدر اضافی راهنما برای جداول */
.chat-table-header {
  display: none !important;
}

/* اسکرول افقی درون کانتینر جدول در موبایل و دسکتاپ */
.chat-table-scroll-container {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(99, 102, 241, 0.4) transparent;
}

.chat-table-scroll-container::-webkit-scrollbar {
  height: 6px;
}

.chat-table-scroll-container::-webkit-scrollbar-track {
  background: transparent;
}

.chat-table-scroll-container::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.35);
  border-radius: 3px;
}

.chat-table-scroll-container::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* استایل جدول و سلول‌ها */
.chat-table-scroll-container table,
.ai-bubble table {
  width: auto !important;
  min-width: 100% !important;
  max-width: none !important;
  border-collapse: collapse;
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.65;
  table-layout: auto !important;
}

.chat-table-scroll-container th,
.chat-table-scroll-container td,
.ai-bubble th,
.ai-bubble td {
  border: 1px solid var(--border-medium);
  padding: 10px 14px;
  vertical-align: top;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  white-space: normal !important;
  unicode-bidi: plaintext;
  text-align: start;
  min-width: 100px;
  max-width: 380px; /* محدودیت هوشمند عرض سلول؛ در صورت طولانی بودن متن به سطر بعد می‌شکند */
}

/* ستون عناوین یا ویژگی‌ها (ستون اول): عرض استاندارد با قابلیت شکست خط در صورت طولانی بودن */
.chat-table-scroll-container th:first-child,
.chat-table-scroll-container td:first-child,
.ai-bubble th:first-child,
.ai-bubble td:first-child {
  min-width: 100px;
  max-width: 220px;
  font-weight: 700;
  background: rgba(99, 102, 241, 0.04);
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  white-space: normal !important;
}

[data-theme="light"] .chat-table-scroll-container th:first-child,
[data-theme="light"] .chat-table-scroll-container td:first-child,
[data-theme="light"] .ai-bubble th:first-child,
[data-theme="light"] .ai-bubble td:first-child {
  background: #f1f5f9;
}

.chat-table-scroll-container th,
.ai-bubble th {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  font-weight: 700;
  border-bottom: 2px solid rgba(99, 102, 241, 0.4);
  white-space: normal !important;
  min-width: 100px;
  max-width: 280px;
  word-break: break-word !important;
}

/* سلول‌های محتوا و توضیحات: کنترل هوشمند شکست خط */
.chat-table-scroll-container td:not(:first-child),
.ai-bubble td:not(:first-child) {
  min-width: 130px;
  max-width: 380px;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  white-space: normal !important;
}

@media (max-width: 768px) {
  .chat-table-scroll-container th,
  .chat-table-scroll-container td,
  .ai-bubble th,
  .ai-bubble td {
    min-width: 90px;
    max-width: 280px;
    padding: 8px 10px;
  }
  .chat-table-scroll-container td:not(:first-child),
  .ai-bubble td:not(:first-child) {
    max-width: 280px;
  }
}

/* کلاس‌های کمکی جهت سلول‌ها برای جلوگیری از اشتباه شدن جهت در متون انگلیسی/فارسی */
.table-cell-ltr {
  direction: ltr !important;
  text-align: left !important;
  unicode-bidi: isolate !important;
}

.table-cell-rtl {
  direction: rtl !important;
  text-align: right !important;
  unicode-bidi: isolate !important;
}

.chat-table-scroll-container td code,
.ai-bubble table td code {
  unicode-bidi: isolate;
  display: inline-block;
  direction: ltr;
}

.chat-table-scroll-container tr:nth-child(even),
.ai-bubble tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .chat-table-scroll-container tr:nth-child(even),
[data-theme="light"] .ai-bubble tr:nth-child(even) {
  background: #f8fafc;
}

.chat-table-scroll-container tr:hover,
.ai-bubble tr:hover {
  background: rgba(99, 102, 241, 0.05);
}

[data-theme="light"] .chat-table-scroll-container tr:hover,
[data-theme="light"] .ai-bubble tr:hover {
  background: #ede9fe;
}

/* Links & Hyperlinks in AI Bubble */
.ai-bubble a {
  color: var(--text-link);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1.5px;
  font-weight: 600;
  transition: all 0.2s ease;
  word-break: break-all;
}

.ai-bubble a:hover {
  color: #818cf8;
  text-decoration-color: #818cf8;
  filter: brightness(1.15);
}

[data-theme="light"] .ai-bubble a {
  color: #2563eb;
}

[data-theme="light"] .ai-bubble a:hover {
  color: #1d4ed8;
}

.inline-ext-icon {
  display: inline-block;
  vertical-align: middle;
  margin-right: 2px;
  opacity: 0.8;
}

/* Inline Code - Dark Mode */
.ai-bubble :not(pre) > code,
code:not(pre code) {
  font-family: var(--font-mono);
  background: rgba(99, 102, 241, 0.16);
  color: #c7d2fe;
  border: 1px solid rgba(129, 140, 248, 0.28);
  padding: 2.5px 8px;
  border-radius: 6px;
  font-size: 0.89em;
  font-weight: 600;
  direction: ltr;
  display: inline-block;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Inline Code - Light Mode (بنفش پررنگ، خوانا و با کنتراست بالا مطابق درخواست کاربر) */
[data-theme="light"] .ai-bubble :not(pre) > code,
[data-theme="light"] .ai-bubble code:not(pre code),
[data-theme="light"] code:not(pre code) {
  background: #ede9fe !important; /* زمینه ملایم یاسی/بنفش روشن */
  color: #4338ca !important;      /* متن بنفش/نیلی پررنگ و کاملاً خوانا با کنتراست عالی */
  border: 1px solid #c4b5fd !important;
  font-weight: 700 !important;
  font-size: 0.9em !important;
  padding: 2.5px 8px !important;
  border-radius: 6px !important;
  box-shadow: 0 1px 3px rgba(99, 102, 241, 0.12) !important;
}

/* Citation Badges (منبع ۱، منبع ۲، ...) */
.citation-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(99, 102, 241, 0.16);
  color: #a5b4fc;
  border: 1px solid rgba(129, 140, 248, 0.35);
  padding: 1px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none !important;
  vertical-align: middle;
  margin: 0 3px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  white-space: nowrap;
}

.citation-badge:hover {
  background: rgba(99, 102, 241, 0.32);
  border-color: #6366f1;
  color: #e0e7ff;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.citation-badge.generic {
  cursor: default;
  opacity: 0.85;
}

.citation-arrow {
  opacity: 0.8;
  margin-right: 1px;
}

[data-theme="light"] .citation-badge {
  background: #ede9fe;
  color: #4338ca;
  border-color: #c4b5fd;
}

[data-theme="light"] .citation-badge:hover {
  background: #ddd6fe;
  color: #3730a3;
  border-color: #8b5cf6;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.2);
}

/* Web Sources Section at bottom of AI Message */
.web-sources-container {
  margin: 12px 0 6px 0;
  padding: 12px 14px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(99, 102, 241, 0.22);
  border-radius: var(--border-radius-md);
  font-size: 0.85rem;
  width: 100%;
  box-sizing: border-box;
}

[data-theme="light"] .web-sources-container {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.web-sources-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.web-sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
}

.web-source-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  text-decoration: none !important;
  color: var(--text-primary);
  transition: all 0.2s ease;
  min-width: 0;
}

.web-source-card:hover {
  border-color: var(--primary);
  background: var(--bg-surface-hover);
  transform: translateY(-1.5px);
  box-shadow: var(--shadow-sm);
}

.web-source-card .source-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
  font-size: 0.72rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

[data-theme="light"] .web-source-card .source-num {
  background: #ede9fe;
  color: #4338ca;
}

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

.web-source-card .source-title {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.web-source-card .source-domain {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.web-source-card .source-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.web-source-card:hover .source-arrow {
  color: var(--primary);
  transform: translateX(-2px);
}

/* Code Blocks with Canvas Action Bar */
.code-block-wrapper {
  margin: 18px 0;
  background: var(--bg-code-block);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-md);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  direction: ltr;
  text-align: left;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-code-header);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.8rem;
}

.code-lang-tag {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.code-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-code-action {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.76rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-code-action:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.btn-code-action.btn-inline-preview {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
  font-weight: 600;
}

.btn-code-action.btn-inline-preview:hover {
  background: #10b981;
  color: #ffffff;
}

.btn-code-action.btn-inline-preview.active {
  background: rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  border-color: rgba(99, 102, 241, 0.6);
}

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

/* In-place switch: Hide source view and code header when preview mode is active */
.code-block-wrapper.in-preview-mode .code-block-header {
  display: none !important;
}

.code-block-wrapper.in-preview-mode .code-source-view {
  display: none !important;
}

/* Inline Code Preview Container (In-place Replacement) */
.inline-code-preview-box {
  display: flex;
  flex-direction: column;
  background: #0f172a;
  border: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  direction: rtl;
  text-align: right;
  width: 100%;
  box-sizing: border-box;
}

.inline-code-preview-box.hidden {
  display: none !important;
}

.inline-preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(15, 23, 42, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.8rem;
  direction: rtl;
  gap: 8px;
  box-sizing: border-box;
  flex-shrink: 0;
}

.preview-toolbar-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  color: #f1f5f9;
}

.preview-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 10px #10b981;
  animation: pulse-dot 2s infinite ease-in-out;
  display: inline-block;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.preview-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.preview-toolbar-actions button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--border-radius-sm, 6px);
  color: #cbd5e1;
  font-family: var(--font-sans);
  font-size: 0.76rem;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.preview-toolbar-actions button:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.btn-preview-refresh:hover {
  color: #38bdf8 !important;
  border-color: rgba(56, 189, 248, 0.4) !important;
}

.btn-preview-fullscreen:hover {
  color: #818cf8 !important;
  border-color: rgba(129, 140, 248, 0.4) !important;
}

.btn-preview-fullscreen.active {
  background: rgba(99, 102, 241, 0.3) !important;
  color: #a5b4fc !important;
  border-color: rgba(99, 102, 241, 0.6) !important;
}

.btn-preview-copy:hover {
  color: #34d399 !important;
  border-color: rgba(52, 211, 153, 0.4) !important;
}

.btn-preview-close {
  background: rgba(239, 68, 68, 0.16) !important;
  color: #fca5a5 !important;
  border-color: rgba(239, 68, 68, 0.35) !important;
  font-weight: 500;
}

.btn-preview-close:hover {
  background: rgba(239, 68, 68, 0.32) !important;
  color: #ffffff !important;
}

.inline-preview-content {
  position: relative;
  width: 100%;
  height: 420px;
  min-height: 250px;
  max-height: 75vh;
  resize: vertical;
  overflow: hidden;
  background: #ffffff;
  box-sizing: border-box;
}

.inline-preview-iframe {
  width: 100% !important;
  height: 100% !important;
  min-height: 100% !important;
  border: none !important;
  display: block !important;
  background: #ffffff;
  box-sizing: border-box;
}

.mermaid-inline-render,
.svg-inline-render {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
  background: #0f172a;
  box-sizing: border-box;
}

.mermaid-inline-render svg,
.svg-inline-render svg {
  max-width: 100%;
  max-height: 100%;
  height: auto;
}

.preview-error {
  padding: 20px;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  font-family: var(--font-mono, monospace);
  font-size: 0.85rem;
  direction: ltr;
  text-align: left;
}

/* ==============================================================
   FULLSCREEN STYLING FOR INLINE CODE PREVIEW
   Fixes the bug where fullscreen only showed the normal-mode slice
   ============================================================== */
.inline-code-preview-box:fullscreen,
.inline-code-preview-box:-webkit-full-screen,
.inline-code-preview-box.is-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  background: #090d16 !important;
  z-index: 999999 !important;
  display: flex !important;
  flex-direction: column !important;
  box-shadow: none !important;
}

.inline-code-preview-box:fullscreen .inline-preview-toolbar,
.inline-code-preview-box:-webkit-full-screen .inline-preview-toolbar,
.inline-code-preview-box.is-fullscreen .inline-preview-toolbar {
  height: 48px !important;
  min-height: 48px !important;
  max-height: 48px !important;
  width: 100vw !important;
  max-width: 100vw !important;
  padding: 0 20px !important;
  background: rgba(15, 23, 42, 0.98) !important;
  backdrop-filter: blur(16px) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14) !important;
  border-radius: 0 !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
}

.inline-code-preview-box:fullscreen .inline-preview-content,
.inline-code-preview-box:-webkit-full-screen .inline-preview-content,
.inline-code-preview-box.is-fullscreen .inline-preview-content {
  flex: 1 1 auto !important;
  width: 100vw !important;
  max-width: 100vw !important;
  height: calc(100vh - 48px) !important;
  max-height: calc(100vh - 48px) !important;
  min-height: calc(100vh - 48px) !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  resize: none !important;
  overflow: hidden !important;
  background: #ffffff !important;
  box-sizing: border-box !important;
}

.inline-code-preview-box:fullscreen .inline-preview-iframe,
.inline-code-preview-box:-webkit-full-screen .inline-preview-iframe,
.inline-code-preview-box.is-fullscreen .inline-preview-iframe {
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100% !important;
  min-height: 100% !important;
  max-height: 100% !important;
  border: none !important;
  display: block !important;
  box-sizing: border-box !important;
}

.inline-code-preview-box:fullscreen .mermaid-inline-render,
.inline-code-preview-box:-webkit-full-screen .mermaid-inline-render,
.inline-code-preview-box.is-fullscreen .mermaid-inline-render,
.inline-code-preview-box:fullscreen .svg-inline-render,
.inline-code-preview-box:-webkit-full-screen .svg-inline-render,
.inline-code-preview-box.is-fullscreen .svg-inline-render {
  width: 100vw !important;
  max-width: 100vw !important;
  height: calc(100vh - 48px) !important;
  min-height: calc(100vh - 48px) !important;
  max-height: calc(100vh - 48px) !important;
  background: #090d16 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 30px !important;
  overflow: auto !important;
  box-sizing: border-box !important;
}

.inline-code-preview-box:fullscreen .mermaid-inline-render svg,
.inline-code-preview-box:-webkit-full-screen .mermaid-inline-render svg,
.inline-code-preview-box.is-fullscreen .mermaid-inline-render svg,
.inline-code-preview-box:fullscreen .svg-inline-render svg,
.inline-code-preview-box:-webkit-full-screen .svg-inline-render svg,
.inline-code-preview-box.is-fullscreen .svg-inline-render svg {
  max-width: 95vw !important;
  max-height: calc(90vh - 48px) !important;
  width: auto !important;
  height: auto !important;
}

.code-block-wrapper pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
}

.code-block-wrapper code {
  font-family: inherit;
}

/* Attached Media Previews in Messages */
.message-attached-media {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.msg-image-thumb {
  max-width: 220px;
  max-height: 180px;
  border-radius: var(--border-radius-sm);
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

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

.msg-file-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--border-radius-sm);
  font-size: 0.82rem;
}

/* Message Bottom Action Toolbar */
.message-actions-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  opacity: 0.85;
  transition: opacity var(--transition-fast);
}

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

.msg-tool-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.76rem;
  font-family: var(--font-sans);
  transition: all var(--transition-fast);
}

.msg-tool-btn:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

/* Streaming Typing Indicator */
.streaming-cursor {
  display: inline-block;
  width: 7px;
  height: 16px;
  background: var(--primary);
  margin-right: 4px;
  vertical-align: middle;
  border-radius: 2px;
  animation: blink 0.9s infinite;
}

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

.typing-indicator-row {
  display: flex;
  gap: 16px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.typing-indicator-bubble {
  padding: 14px 18px;
  background: var(--bg-bubble-ai);
  border-radius: 4px 18px 18px 18px;
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 6px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   Input Section & File Attachments
   ========================================================================== */
#chat-input-section {
  padding: 12px 20px 20px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  z-index: 25;
}

.input-box-wrapper {
  background: var(--bg-glass-input);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-xl);
  box-shadow: var(--shadow-md);
  padding: 12px 16px 10px;
  display: flex;
  flex-direction: column;
  transition: all var(--transition-fast);
}

.input-box-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light), 0 8px 30px rgba(0, 0, 0, 0.35);
}

/* Attached Files Tray inside input */
.input-attachments-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 8px;
}

.input-attachments-tray:empty {
  display: none;
}

.attachment-preview-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-sm);
  font-size: 0.8rem;
  color: var(--text-primary);
  position: relative;
  animation: popIn 0.2s ease-out;
}

.attachment-thumb {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
}

.attachment-info {
  display: flex;
  flex-direction: column;
  max-width: 150px;
}

.attachment-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.attachment-size {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.btn-remove-attachment {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-remove-attachment:hover {
  background: rgba(244, 63, 94, 0.2);
  color: var(--accent-rose);
}

/* Main Textarea */
.input-textarea {
  width: 100%;
  max-height: 200px;
  min-height: 48px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.98rem;
  line-height: 1.6;
  resize: none;
  direction: auto;
  text-align: right;
}

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

/* Input Bottom Toolbar */
.input-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 6px;
}

.input-actions-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-attach {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-full);
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-attach:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.input-actions-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--gradient-brand);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.btn-send:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.btn-send:active {
  transform: scale(0.96);
}

.btn-stop-generating {
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.4);
  border-radius: var(--border-radius-full);
  padding: 7px 14px;
  color: var(--accent-rose);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-stop-generating:hover {
  background: var(--accent-rose);
  color: #ffffff;
}

.btn-stop-generating.active {
  display: flex;
}

.input-hint-text {
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Drag and Drop Fullscreen Overlay */
#drag-drop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 3px dashed var(--primary);
  pointer-events: none;
}

#drag-drop-overlay.active {
  display: flex;
}

.drag-drop-icon {
  width: 64px;
  height: 64px;
  color: var(--primary);
  margin-bottom: 16px;
  animation: float 2s infinite ease-in-out;
}

.drag-drop-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: #ffffff;
}

/* ==========================================================================
   Canvas / Artifacts Panel (Split View & Live Code Runner)
   ========================================================================== */
#canvas-panel {
  width: var(--canvas-width);
  height: 100%;
  background: var(--bg-canvas);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: width var(--transition-normal), transform var(--transition-normal);
  flex-shrink: 0;
  position: relative;
}

#canvas-panel.closed {
  display: none;
}

#canvas-panel.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 200;
}

.canvas-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.canvas-title-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.canvas-badge-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-title-text {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* Canvas Mode Switcher Tabs */
.canvas-tabs {
  display: flex;
  align-items: center;
  background: var(--bg-code-header);
  padding: 3px;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-subtle);
}

.canvas-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 5px 12px;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.canvas-tab-btn.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.canvas-header-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Canvas Content Body */
.canvas-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: #080c14;
}

/* Sandboxed Iframe Preview */
#canvas-iframe-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.canvas-preview-toolbar {
  padding: 6px 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.device-viewport-toggles {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-viewport {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: all var(--transition-fast);
}

.btn-viewport.active,
.btn-viewport:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.iframe-sandbox-wrapper {
  flex: 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #181f2f;
  overflow: auto;
  transition: all var(--transition-normal);
}

#canvas-sandbox-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
  transition: width var(--transition-fast);
}

/* Viewport sizes */
.iframe-sandbox-wrapper.tablet #canvas-sandbox-iframe {
  width: 768px;
  height: 95%;
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-xl);
}

.iframe-sandbox-wrapper.mobile #canvas-sandbox-iframe {
  width: 375px;
  height: 90%;
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-xl);
}

/* SVG / Mermaid Preview Area */
#canvas-render-container {
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  background: var(--bg-canvas);
}

/* Code Editor Tab */
#canvas-code-container {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
}

.code-editor-toolbar {
  padding: 8px 14px;
  background: var(--bg-code-header);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.code-editor-textarea {
  flex: 1;
  width: 100%;
  height: 100%;
  background: #080c14;
  color: #e2e8f0;
  border: none;
  outline: none;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  resize: none;
  direction: ltr;
  text-align: left;
  tab-size: 2;
}

.btn-update-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--primary);
  border: none;
  border-radius: var(--border-radius-sm);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-update-preview:hover {
  background: var(--primary-hover);
}

/* ==========================================================================
   Modals & Settings Dialogs
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: zoomIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-card.modal-lg {
  max-width: 780px;
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--bg-surface);
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
}

/* Modal Tabs Header Bar (ثابت در بالای مودال تا با اسکرول بدنه هرگز مخفی یا قطع نشود) */
.modal-tabs-header {
  padding: 12px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.settings-tabs-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--bg-chat);
  border: 1px solid var(--border-subtle);
  padding: 5px;
  border-radius: var(--border-radius-md);
  width: 100%;
  box-sizing: border-box;
}

.tab-btn {
  padding: 9px 8px;
  background: transparent;
  border: none;
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  user-select: none;
}

.tab-btn span {
  pointer-events: none;
}

.tab-btn .tab-icon {
  font-size: 0.95rem;
  line-height: 1;
  flex-shrink: 0;
}

.tab-btn .tab-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.4);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

/* Tab Content Visibility */
.tab-content {
  display: none;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: tabFadeIn 0.2s ease-out;
}

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

/* Provider Info & Action Cards */
.provider-box-card {
  background: var(--bg-chat);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.provider-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.provider-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  padding: 3px 8px;
  border-radius: var(--border-radius-full);
  background: rgba(16, 185, 129, 0.12);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.btn-fetch-models {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  color: #ffffff;
  border: none;
  border-radius: var(--border-radius-sm);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.35);
}

.btn-fetch-models:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.5);
}

.btn-fetch-models:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Model Chips and Active Models Manager */
.active-models-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  min-height: 44px;
  max-height: 140px;
  overflow-y: auto;
}

.model-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: var(--border-radius-full);
  color: #a5b4fc;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  user-select: none;
}

.model-tag-chip.default-model {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  font-weight: 600;
}

.model-tag-chip .btn-remove-tag {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 2px;
  border-radius: 50%;
  transition: transform 0.15s;
}

.model-tag-chip .btn-remove-tag:hover {
  transform: scale(1.3);
  color: #f87171;
}

/* Model Selection Sheet Box (Fetched from API) */
.model-picker-sheet {
  background: var(--bg-surface);
  border: 1px solid var(--primary);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.25);
  border-radius: var(--border-radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.model-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.model-picker-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-picker-search {
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-chat);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  direction: ltr;
}

.model-picker-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-chat);
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-subtle);
}

.model-select-card {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.model-select-card:hover {
  border-color: var(--primary);
  color: var(--text-primary);
}

.model-select-card.selected {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--primary);
  color: #818cf8;
  font-weight: 600;
}

.model-picker-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

/* Settings Form Groups */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-chat);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}

.form-input[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

.form-input[dir="ltr"],
.form-input.ltr-input,
.form-input[type="password"],
.form-input[type="url"],
#custom-url-input,
#custom-key-input,
#gemini-dedicated-key,
#gemini-tts-dedicated-key,
#api-key-input,
#setting-tavily-key,
#admin-new-username,
#auth-username,
#auth-password,
#pass-current,
#pass-new,
#gemini-manual-model-input,
#custom-manual-model-input {
  direction: ltr;
  text-align: left;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.form-input-with-button {
  display: flex;
  gap: 8px;
}

.preset-pills-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.preset-pill {
  padding: 4px 10px;
  background: var(--bg-chat);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-full);
  font-size: 0.76rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.preset-pill:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 14px;
}

.form-range {
  flex: 1;
  accent-color: var(--primary);
  cursor: pointer;
}

.slider-val-badge {
  padding: 3px 8px;
  background: var(--bg-chat);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  border: 1px solid var(--border-subtle);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-surface);
}

.btn-modal-secondary {
  padding: 9px 18px;
  background: transparent;
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.btn-modal-primary {
  padding: 9px 22px;
  background: var(--gradient-brand);
  border: none;
  border-radius: var(--border-radius-sm);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

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

/* Image Fullscreen Preview Modal */
.image-lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.image-lightbox.open {
  display: flex;
}

.image-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-xl);
}

/* Toast Notifications */
/* ==========================================================================
   Toast Notifications (اعلان‌های شیشه‌ای زیر نوار بالا)
   ========================================================================== */
#toast-container {
  position: fixed;
  top: calc(var(--header-height) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  max-width: min(480px, 92vw);
  width: 100%;
}

.app-toast {
  padding: 10px 20px;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25), 0 0 0 0.5px rgba(255, 255, 255, 0.06);
  color: #f1f5f9;
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  animation: toastSlideDown 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.3s ease, transform 0.3s ease;
  direction: rtl;
  text-align: right;
  max-width: 100%;
  line-height: 1.5;
}

[data-theme="light"] .app-toast {
  background: rgba(255, 255, 255, 0.88);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  color: #0f172a;
}

.toast-icon {
  font-size: 1rem;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
}

.toast-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

/* رنگ‌های مختلف توست */
.toast-info .toast-icon { color: #60a5fa; }
.toast-success .toast-icon { color: #34d399; }
.toast-error .toast-icon { color: #fb7185; }
.toast-warning .toast-icon { color: #fbbf24; }

.toast-info { border-right: 3px solid #3b82f6; }
.toast-success { border-right: 3px solid #10b981; }
.toast-error { border-right: 3px solid #f43f5e; }
.toast-warning { border-right: 3px solid #f59e0b; }

[data-theme="light"] .toast-info .toast-icon { color: #2563eb; }
[data-theme="light"] .toast-success .toast-icon { color: #059669; }
[data-theme="light"] .toast-error .toast-icon { color: #e11d48; }
[data-theme="light"] .toast-warning .toast-icon { color: #d97706; }

@keyframes toastSlideDown {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

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

@keyframes zoomIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

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

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 1024px) {
  #canvas-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100%;
    z-index: 150;
    box-shadow: var(--shadow-xl);
  }
}

@media (max-width: 960px) {
  #sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    width: 290px;
    max-width: 86vw;
    z-index: 500;
    box-shadow: -5px 0 35px rgba(0, 0, 0, 0.65);
    transform: translateX(100%);
    margin-right: 0 !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  #sidebar:not(.collapsed) {
    transform: translateX(0);
  }

  #sidebar.collapsed {
    transform: translateX(100%);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 490;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .sidebar-backdrop.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  #main-content {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  #chat-messages-container {
    padding: 16px 12px;
  }

  #chat-input-section {
    padding: 8px 12px 14px;
  }

  .user-bubble, .ai-bubble {
    padding: 12px 14px;
    font-size: 0.92rem;
  }
}

/* ==========================================================================
   Thinking / Reasoning Accordion Styles (DeepSeek R1 / o1 / Gemini)
   ========================================================================== */
.thinking-accordion {
  margin-bottom: 14px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--border-radius-md);
  overflow: hidden;
  transition: all var(--transition-fast);
}

.thinking-accordion.open {
  border-color: rgba(99, 102, 241, 0.45);
  background: rgba(15, 23, 42, 0.85);
}

.thinking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  cursor: pointer;
  user-select: none;
  background: rgba(99, 102, 241, 0.08);
}

.thinking-header:hover {
  background: rgba(99, 102, 241, 0.15);
}

.thinking-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #c7d2fe;
}

.thinking-icon.pulse {
  animation: brainPulse 1.2s infinite alternate ease-in-out;
}

@keyframes brainPulse {
  0% { transform: scale(1); filter: drop-shadow(0 0 2px #a855f7); }
  100% { transform: scale(1.25); filter: drop-shadow(0 0 8px #a855f7); }
}

.thinking-toggle-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--border-radius-full);
  color: var(--text-muted);
}

.thinking-content {
  display: none;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.6;
  color: #94a3b8;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  direction: ltr;
  text-align: left;
}

.thinking-accordion.open .thinking-content {
  display: block;
}

/* ==========================================================================
   Voice Input & Web Search Action Buttons
   ========================================================================== */
.btn-mic {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-full);
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-mic:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.btn-mic.listening {
  background: rgba(244, 63, 94, 0.2);
  border-color: var(--accent-rose);
  color: #ff4d6d;
  animation: micPulse 1.5s infinite;
}

@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.6); }
  70% { box-shadow: 0 0 0 10px rgba(244, 63, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0); }
}

.btn-web-search {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-full);
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-web-search:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.btn-web-search.active {
  background: rgba(6, 182, 212, 0.18);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.3);
}

/* ==================== Custom Modern Glassmorphic Topbar Dropdowns ==================== */
.topbar-selectors {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.custom-select-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.hidden-select {
  display: none !important;
}

.custom-select-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  user-select: none;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.custom-select-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(99, 102, 241, 0.45);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.22);
  transform: translateY(-1px);
}

.custom-select-btn:active,
.custom-select-btn[aria-expanded="true"] {
  background: rgba(99, 102, 241, 0.18);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.35);
}

.custom-select-icon {
  font-size: 0.88rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.custom-select-text {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.custom-select-arrow {
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
  opacity: 0.7;
}

.custom-select-btn[aria-expanded="true"] .custom-select-arrow {
  transform: rotate(180deg);
  opacity: 1;
  color: var(--primary);
}

/* حالت روشن برای دکمه سلکتور سفارشی */
[data-theme="light"] .custom-select-btn {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .custom-select-btn:hover {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.15);
}

[data-theme="light"] .custom-select-btn:active,
[data-theme="light"] .custom-select-btn[aria-expanded="true"] {
  background: rgba(99, 102, 241, 0.12);
  border-color: var(--primary);
  color: #1e1b4b;
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.2);
}

/* Floating Dropdown Menu Card */
.custom-select-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 230px;
  max-width: 310px;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  padding: 8px;
  z-index: 1000;
  display: none;
  flex-direction: column;
  gap: 4px;
  animation: selectDropdownFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* حالت روشن برای دراپ‌داون سلکتور سفارشی */
[data-theme="light"] .custom-select-dropdown {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(99, 102, 241, 0.25);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .custom-select-dropdown-header {
  color: var(--text-secondary);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .custom-models-count {
  background: rgba(99, 102, 241, 0.12);
  color: #4f46e5;
}

[data-theme="light"] .custom-select-search-wrap {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .custom-select-item:hover {
  background: rgba(99, 102, 241, 0.1);
  color: #1e1b4b;
}

[data-theme="light"] .custom-select-item.selected {
  background: rgba(99, 102, 241, 0.15);
  color: #4338ca;
  border-color: rgba(99, 102, 241, 0.3);
}

[data-theme="light"] .custom-item-badge {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-secondary);
}

[data-theme="light"] .custom-item-check {
  color: #4f46e5;
}

.custom-select-dropdown.open {
  display: flex !important;
}

@keyframes selectDropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.custom-select-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 4px;
  letter-spacing: 0.2px;
}

.custom-models-count {
  font-size: 0.7rem;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: normal;
}

.custom-select-search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  margin-bottom: 6px;
}

.custom-select-search {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  width: 100%;
  outline: none;
  direction: ltr;
  text-align: right;
}

.custom-select-search::placeholder {
  color: var(--text-muted);
  font-size: 0.74rem;
}

.custom-select-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 2px;
}

.custom-select-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text-primary);
  user-select: none;
}

.custom-select-item:hover {
  background: rgba(99, 102, 241, 0.15);
  color: #ffffff;
  transform: translateX(-2px);
}

.custom-select-item.selected {
  background: rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
  font-weight: 600;
  border: 1px solid rgba(99, 102, 241, 0.35);
}

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

.custom-item-icon {
  font-size: 0.95rem;
  flex-shrink: 0;
}

.custom-item-text {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: ltr;
  text-align: left;
}

.custom-item-text.rtl-text {
  direction: rtl;
  text-align: right;
}

.custom-item-check {
  font-size: 0.85rem;
  color: #818cf8;
  font-weight: bold;
  flex-shrink: 0;
}

.custom-item-badge {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Fallback legacy selector units */
.selector-unit {
  display: flex;
  align-items: center;
  gap: 5px;
}

.selector-unit-label {
  font-size: 0.74rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 500;
}

.topbar-select {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  padding: 5px 8px;
  border-radius: var(--border-radius-sm);
  outline: none;
  cursor: pointer;
  max-width: 155px;
  text-overflow: ellipsis;
  transition: border-color var(--transition-fast);
}

.topbar-select:hover, .topbar-select:focus {
  border-color: var(--primary);
  color: var(--text-primary);
}

/* User Menu in Topbar */
.user-menu-wrapper {
  position: relative;
}

.btn-user-badge-top {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-full);
  cursor: pointer;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  transition: all var(--transition-fast);
}

.btn-user-badge-top:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

.user-badge-letter {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

/* Generic Hidden Utility */
.hidden {
  display: none !important;
}

.user-menu-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.user-dropdown-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  background: #181d2a;
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-md);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65);
  min-width: 230px;
  z-index: 1000;
  padding: 6px;
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.15s ease-out;
}

.user-dropdown-menu.hidden {
  display: none !important;
}

.dropdown-header {
  padding: 8px 10px;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0;
}

.dropdown-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  cursor: pointer;
  text-align: right;
  transition: all var(--transition-fast);
}

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

.dropdown-item.text-danger {
  color: #ef4444;
}

.dropdown-item.text-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
}

/* Sidebar Sessions & Category Row Groups */
.sidebar-sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
}

.sessions-header-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-add-cat-sm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 4px;
  color: #818cf8;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  padding: 2px 7px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-add-cat-sm:hover {
  background: #6366f1;
  color: #ffffff;
  border-color: #6366f1;
}

/* Category Folder Accordion Row */
.category-group-section {
  margin-bottom: 8px;
}

.category-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  margin: 2px 4px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.category-group-header:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-subtle);
}

.cat-header-left {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  flex: 1;
}

.cat-chevron {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  width: 12px;
  text-align: center;
}

.category-group-section.collapsed .cat-chevron {
  transform: rotate(90deg);
}

.category-group-section.collapsed .category-group-items {
  display: none;
}

.cat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cat-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat-badge-count {
  font-size: 0.68rem;
  padding: 1px 6px;
  background: var(--bg-surface);
  border-radius: 10px;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.cat-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  opacity: 0.85;
  transition: opacity var(--transition-fast);
}

.category-group-header:hover .cat-actions {
  opacity: 1;
}

.cat-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: var(--border-radius-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.cat-action-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.cat-action-btn.cat-edit-btn:hover {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.15);
}

.cat-action-btn.cat-del-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

.category-group-items {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 8px;
  margin-top: 3px;
  border-right: 2px solid var(--border-subtle);
  margin-right: 12px;
}

/* Chat Item Category Pill */
.session-cat-pill {
  font-size: 0.66rem;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 600;
}

/* Assign Category Modal Options */
.assign-cat-options-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 250px;
  overflow-y: auto;
}

.assign-cat-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.84rem;
}

.assign-cat-opt:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

.assign-cat-opt.selected {
  background: rgba(99, 102, 241, 0.18);
  border-color: var(--primary);
  color: #818cf8;
  font-weight: 600;
}

.assign-cat-opt.uncategorized-opt {
  color: #f87171;
  border-style: dashed;
}

.assign-cat-opt.uncategorized-opt:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: #ef4444;
}

.btn-icon-xs {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-icon-xs:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* Sidebar User Info Card */
.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-md);
  margin-bottom: 8px;
}

.user-avatar-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gradient-brand);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.user-info-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.user-display-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-badge {
  font-size: 0.68rem;
  color: var(--primary);
  font-weight: 500;
}

/* Inline Code Visual Preview */
.btn-inline-preview {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #818cf8;
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-inline-preview:hover {
  background: rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
}

.btn-inline-preview.active {
  background: #6366f1;
  color: #ffffff;
  border-color: #6366f1;
}

.inline-code-preview-box {
  margin-top: 10px;
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-md);
  overflow: hidden;
  background: #090d16;
}

.inline-preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.preview-toolbar-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.preview-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.preview-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-preview-refresh, .btn-preview-fullscreen, .btn-preview-close {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

.btn-preview-refresh:hover, .btn-preview-fullscreen:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.btn-preview-close:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.inline-preview-content {
  min-height: 200px;
  max-height: 500px;
  overflow: auto;
  position: relative;
  background: #ffffff;
  color: #111827;
}

.inline-preview-iframe {
  width: 100%;
  height: 320px;
  border: none;
  display: block;
  background: #ffffff;
}

.mermaid-inline-render {
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: auto;
  background: #0f1523;
  color: #f8fafc;
}

.svg-inline-render {
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #0f1523;
}

/* Authentication Fullscreen Overlay */
.auth-fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(9, 13, 22, 0.95);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.auth-fullscreen-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-xl);
  padding: 32px 28px;
  box-shadow: var(--shadow-xl);
  animation: modalScaleIn 0.3s ease-out;
}

.auth-header {
  text-align: center;
  margin-bottom: 22px;
}

.auth-logo-glow {
  width: 68px;
  height: 68px;
  margin: 0 auto 12px;
  position: relative;
  border-radius: 18px;
  box-shadow: 0 0 25px rgba(99, 102, 241, 0.45);
}

.auth-logo-img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.auth-title {
  font-size: 1.35rem;
  font-weight: 800;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}

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

.auth-remember-row {
  margin: 10px 0;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.btn-auth-primary {
  width: 100%;
  padding: 12px;
  background: var(--gradient-brand);
  color: #ffffff;
  border: none;
  border-radius: var(--border-radius-md);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 12px;
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.4);
  transition: all var(--transition-fast);
}

.btn-auth-primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 22px rgba(99, 102, 241, 0.55);
}

.auth-notice-box {
  margin-top: 16px;
  padding: 10px 12px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--border-radius-sm);
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-error-banner {
  padding: 10px 12px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: var(--border-radius-sm);
  color: #f87171;
  font-size: 0.84rem;
  margin-bottom: 12px;
  line-height: 1.5;
}

.auth-warning-banner {
  margin-top: 14px;
  margin-bottom: 8px;
  padding: 12px 14px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--border-radius-md);
  color: #fbbf24;
  font-size: 0.82rem;
  line-height: 1.6;
}

.auth-warning-banner.hidden {
  display: none !important;
}

.auth-warning-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #f59e0b;
}

.auth-warning-desc {
  margin: 0 0 10px 0;
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.5;
}

.auth-warning-desc strong {
  color: var(--text-primary);
}

.btn-auth-guest {
  width: 100%;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.btn-auth-guest:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--brand-primary);
  color: #ffffff;
}

/* Admin Users Management Table */
.admin-create-user-box {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-md);
  padding: 14px;
}

.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.admin-users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
  text-align: right;
}

.admin-users-table th {
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border-medium);
  color: var(--text-muted);
  font-weight: 600;
}

.admin-users-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.user-badge-role {
  padding: 2px 7px;
  border-radius: var(--border-radius-full);
  font-size: 0.72rem;
  font-weight: 600;
}

.user-badge-role.admin {
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.user-badge-role.user {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
}

/* Color Dots for Category Picker */
.color-picker-row {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform var(--transition-fast);
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.active {
  border-color: #ffffff;
  transform: scale(1.15);
}

/* Custom Providers List */
.custom-providers-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.custom-provider-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
}

/* Responsive Overhaul for Mobile & Split Windows */
@media (max-width: 960px) {
  .chat-topbar {
    padding: 0 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  
  .topbar-selectors {
    gap: 6px;
  }

  .current-chat-title {
    max-width: 160px;
    font-size: 0.88rem;
  }

  .user-dropdown-menu {
    left: 4px;
    right: auto;
    max-width: calc(100vw - 16px);
  }

  .hide-on-mobile {
    display: none !important;
  }

  /* در صفحات کمتر از ۹۶۰ دکمه‌های حجیم خروجی و پاکسازی در منوی کاربر قرار می‌گیرند */
  .btn-topbar-action {
    display: none !important;
  }

  .modal-card {
    width: 95%;
    max-width: calc(100vw - 20px);
    max-height: 92vh;
  }
}

@media (max-width: 640px) {
  /* ==================== تب‌های افقی روان و مدرن تنظیمات در موبایل ==================== */
  .modal-tabs-header {
    padding: 8px 10px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    background: rgba(15, 23, 42, 0.7) !important;
    border-bottom: 1px solid var(--border-subtle) !important;
  }

  .modal-tabs-header::-webkit-scrollbar {
    display: none !important;
  }

  .settings-tabs-row {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    width: max-content !important;
    min-width: 100% !important;
  }

  .tab-btn {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
    padding: 7px 14px !important;
    font-size: 0.78rem !important;
    border-radius: 20px !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid var(--border-subtle) !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    color: var(--text-secondary) !important;
    transition: all 0.2s ease !important;
  }

  .tab-btn.active {
    background: var(--primary) !important;
    color: #ffffff !important;
    border-color: var(--primary) !important;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.4) !important;
  }

  /* کادربندی بهینه پنجره‌های پاپ‌آپ و مودال در موبایل */
  .modal-card {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    margin: 8px auto !important;
    border-radius: 16px !important;
    max-height: calc(100dvh - 20px) !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .modal-header {
    padding: 12px 14px !important;
  }

  .modal-title {
    font-size: 0.92rem !important;
  }

  .modal-body {
    padding: 12px 10px !important;
    max-height: calc(100dvh - 125px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  .modal-footer {
    padding: 10px 14px !important;
  }

  .provider-box-card {
    padding: 12px 10px !important;
    border-radius: 12px !important;
    margin-bottom: 12px !important;
  }

  .provider-header-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }

  /* نوار بالای چت در موبایل */
  .chat-topbar {
    padding: 0 6px !important;
    height: 48px !important;
    gap: 4px !important;
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .topbar-left {
    flex-shrink: 0;
    gap: 4px;
  }

  .btn-icon {
    width: 32px !important;
    height: 32px !important;
  }

  .current-chat-title {
    display: none !important;
  }

  .topbar-selectors {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px !important;
    margin: 0;
  }

  .custom-select-wrapper {
    flex: 1;
    min-width: 0;
    max-width: 130px;
    position: relative;
  }

  .custom-select-btn {
    width: 100% !important;
    max-width: 100% !important;
    height: 29px !important;
    padding: 0 6px !important;
    font-size: 0.72rem !important;
    gap: 3px !important;
    border-radius: 14px !important;
    box-shadow: none !important;
  }

  .custom-select-icon {
    font-size: 0.78rem !important;
  }

  .custom-select-text {
    max-width: 62px !important;
    font-size: 0.72rem !important;
  }

  .custom-select-dropdown {
    position: fixed !important;
    top: 50px !important;
    right: 8px !important;
    left: auto !important;
    max-width: calc(100vw - 16px) !important;
    width: 280px !important;
    max-height: 60vh !important;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.75) !important;
    z-index: 9999 !important;
  }

  .selector-unit {
    flex: 1;
    min-width: 0;
    max-width: 135px;
  }

  .selector-unit-label {
    display: none !important;
  }

  .hide-on-narrow {
    display: none !important;
  }

  .topbar-right {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 3px !important;
  }

  .btn-topbar-action {
    display: none !important;
  }

  .btn-user-badge-top {
    padding: 2px 5px !important;
    gap: 2px !important;
    height: 30px !important;
  }

  .user-badge-letter {
    width: 24px !important;
    height: 24px !important;
    font-size: 0.75rem !important;
  }

  /* کادربندی جمع‌وجور پیام‌ها و حباب‌های گفتگو در موبایل */
  #chat-messages-container {
    padding: 10px 8px !important;
    gap: 12px !important;
    overflow-x: hidden !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .chat-row {
    gap: 8px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    min-width: 0 !important;
  }

  .chat-row.user-row {
    max-width: 95% !important;
    align-self: flex-start !important;
  }

  .chat-row.user-row .message-body-wrap {
    max-width: calc(100% - 36px) !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  .chat-row.ai-row {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    align-self: stretch !important;
  }

  .chat-row.ai-row .message-body-wrap {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    max-width: calc(100% - 36px) !important;
    width: calc(100% - 36px) !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .user-bubble {
    padding: 9px 13px !important;
    font-size: 0.88rem !important;
    border-radius: 14px 4px 14px 14px !important;
    line-height: 1.6 !important;
    box-sizing: border-box !important;
  }

  .ai-bubble {
    padding: 11px 13px !important;
    font-size: 0.88rem !important;
    border-radius: 4px 14px 14px 14px !important;
    line-height: 1.65 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
  }

  .message-avatar {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    max-width: 28px !important;
    max-height: 28px !important;
    font-size: 0.74rem !important;
    border-radius: 6px !important;
  }

  /* کادربندی بهینه‌تر و فشرده‌تر صفحه خوش‌آمدگویی در موبایل */
  .empty-chat-welcome {
    padding: 16px 8px 8px !important;
    max-width: 100% !important;
  }

  .welcome-logo-glow {
    margin-bottom: 12px;
  }

  .welcome-logo-img {
    width: 48px;
    height: 48px;
  }

  .welcome-title {
    font-size: 1.25rem !important;
  }

  .welcome-subtitle {
    font-size: 0.8rem !important;
    margin-bottom: 12px !important;
  }

  .welcome-features {
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 12px;
    justify-content: center;
  }

  .feature-pill {
    font-size: 0.68rem;
    padding: 3px 8px;
    border-radius: 14px;
  }

  .suggestions-grid {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    width: 100%;
  }

  .suggestion-card {
    padding: 8px 12px;
    border-radius: 10px;
  }

  .suggestion-card h4 {
    font-size: 0.82rem;
    margin-bottom: 2px;
  }

  .suggestion-card p {
    font-size: 0.72rem;
    line-height: 1.35;
  }

  /* کادربندی جمع‌وجور و بدون فضای هدر رفته ورودی پیام در موبایل */
  #chat-input-section {
    padding: 4px 8px 10px !important;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .input-box-wrapper {
    padding: 8px 10px 6px !important;
    border-radius: 14px !important;
  }

  .input-textarea {
    font-size: 0.88rem !important;
    padding: 2px 0 4px !important;
    line-height: 1.45;
  }

  .input-actions-bar {
    padding-top: 4px;
    gap: 4px;
  }

  .btn-label-text {
    display: none;
  }

  .input-actions-left {
    gap: 4px;
  }

  .btn-attach, .btn-web-search, .btn-mic {
    padding: 4px 6px;
    font-size: 0.72rem;
    border-radius: 6px;
  }

  .btn-send {
    width: 32px;
    height: 32px;
  }

  .input-hint-text {
    font-size: 0.65rem;
    margin-top: 3px;
  }
}

/* ==================== استایل‌های مدرن مدیریت ارائه‌دهندگان و چیپ‌های مدل‌ها ==================== */
.active-models-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-md);
  min-height: 48px;
  align-items: center;
}

.active-model-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-primary);
  direction: ltr;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.active-model-chip:hover {
  border-color: var(--brand-primary);
  background: rgba(99, 102, 241, 0.08);
}

.active-model-chip.is-default {
  background: rgba(99, 102, 241, 0.18);
  border-color: var(--brand-primary);
  color: #a5b4fc;
  font-weight: 600;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.25);
}

.active-model-chip .chip-star {
  color: #fbbf24;
  font-size: 0.82rem;
  margin-right: 2px;
}

.active-model-chip .chip-del {
  color: var(--text-muted);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  transition: all var(--transition-fast);
  margin-left: 2px;
}

.active-model-chip .chip-del:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

/* شیت پنجره انتخاب مدل‌های دریافت شده */
.model-picker-sheet {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-md);
  padding: 14px;
  margin: 10px 0;
  box-shadow: var(--shadow-lg);
  animation: modalScaleIn 0.2s ease-out;
}

.model-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.model-picker-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.model-picker-search {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  margin-bottom: 8px;
}

.model-picker-list {
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
  padding: 4px;
  margin: 8px 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  background: var(--bg-base);
}

.model-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  direction: ltr;
  text-align: left;
  font-size: 0.78rem;
  transition: all var(--transition-fast);
}

.model-picker-item:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

.model-picker-item input[type="checkbox"] {
  cursor: pointer;
}

.model-picker-actions {
  margin-top: 10px;
}

/* کارت‌های لیست ارائه‌دهندگان سفارشی */
.custom-providers-cards-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.custom-prov-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all var(--transition-fast);
  position: relative;
}

.custom-prov-card:hover {
  border-color: var(--brand-primary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.custom-prov-card.is-active {
  border-color: var(--brand-primary);
  background: rgba(99, 102, 241, 0.05);
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.2);
}

.custom-prov-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.custom-prov-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.custom-prov-badge {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 12px;
  font-weight: 600;
}

.custom-prov-badge.active-badge {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.custom-prov-badge.inactive-badge {
  background: var(--bg-surface-hover);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.custom-prov-url {
  font-size: 0.76rem;
  color: var(--text-muted);
  direction: ltr;
  text-align: left;
  word-break: break-all;
}

.custom-prov-default-model {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  direction: ltr;
}

.custom-prov-models-count {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.custom-prov-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.btn-card-action {
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-card-activate {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border-color: rgba(99, 102, 241, 0.3);
}

.btn-card-activate:hover {
  background: #6366f1;
  color: #ffffff;
}

.btn-card-edit {
  background: var(--bg-surface-hover);
  color: var(--text-secondary);
  border-color: var(--border-medium);
}

.btn-card-edit:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.btn-card-delete {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.25);
  margin-right: auto;
}

.btn-card-delete:hover {
  background: #ef4444;
  color: #ffffff;
}

/* ==========================================================================
   Token Usage Badge in AI Response Meta Header
   ========================================================================== */
.message-tokens-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.73rem;
  font-weight: 500;
  color: #10b981;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.28);
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 6px;
  cursor: default;
  transition: all 0.2s ease;
  user-select: none;
}

[data-theme="light"] .message-tokens-badge {
  color: #047857;
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(5, 150, 105, 0.35);
  font-weight: 600;
}

.message-tokens-badge:hover {
  background: rgba(16, 185, 129, 0.2);
}

/* ==========================================================================
   User Message Bubble Wrap & Copy/Edit Actions
   ========================================================================== */
.user-bubble-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 100%;
  position: relative;
}

.user-message-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  opacity: 0.85;
  transition: opacity 0.2s ease;
}

.chat-row.user-row:hover .user-message-actions,
.chat-row.user-row:focus-within .user-message-actions {
  opacity: 1;
}

.btn-copy-user-msg,
.btn-edit-user-msg {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  padding: 3px 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-copy-user-msg:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

.btn-edit-user-msg:hover {
  color: var(--primary);
  background: var(--bg-surface-hover);
  border-color: rgba(99, 102, 241, 0.4);
}

/* Inline Edit Box for User Message */
.user-message-edit-box {
  width: 100%;
  min-width: 280px;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--primary);
  border-radius: var(--border-radius-md);
  padding: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  margin-top: 4px;
  animation: fadeIn 0.2s ease-out;
}

.user-edit-textarea {
  width: 100%;
  min-height: 80px;
  max-height: 260px;
  background: var(--bg-chat);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  line-height: 1.6;
  padding: 10px 12px;
  resize: vertical;
  direction: auto;
  box-sizing: border-box;
}

.user-edit-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.user-edit-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.btn-save-edit-user {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--gradient-brand);
  color: #ffffff;
  border: none;
  border-radius: var(--border-radius-sm);
  padding: 7px 16px;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
}

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

.btn-cancel-edit-user {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--border-radius-sm);
  padding: 7px 14px;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-cancel-edit-user:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* ==========================================================================
   Smart Scroll-to-Bottom Floating Button (طبق درخواست کاربر کاملاً حذف شد)
   ========================================================================== */
.btn-scroll-bottom {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

/* ==========================================================================
   Memory Tab (Cross-Chat Long-Term Memory)
   ========================================================================== */
.empty-memories-notice {
  text-align: center;
  padding: 28px 16px;
  background: var(--bg-surface);
  border: 1px dashed var(--border-medium);
  border-radius: var(--border-radius-sm);
}

.memories-list-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  padding-right: 4px;
}

.memory-item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-sm);
  transition: border-color 0.2s, background 0.2s;
}

.memory-item-card:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

.memory-item-text {
  font-size: 0.85rem;
  color: var(--text-primary);
  line-height: 1.5;
  word-break: break-word;
  flex: 1;
}

.memory-item-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.memory-item-date {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.btn-delete-memory {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #ef4444;
  border-radius: 4px;
  padding: 4px 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-delete-memory:hover {
  background: #ef4444;
  color: #fff;
}

/* ==========================================================================
   AI Generated & Markdown Images in Chat Bubbles
   ========================================================================== */
.ai-rendered-image,
.ai-bubble img:not(.msg-image-thumb):not(.ai-avatar-img):not(.welcome-avatar-img) {
  max-width: 100%;
  max-height: 480px;
  object-fit: cover;
  border-radius: var(--border-radius-md);
  margin: 10px 0 4px 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-medium);
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  display: block;
}

.ai-rendered-image:hover,
.ai-bubble img:not(.msg-image-thumb):not(.ai-avatar-img):not(.welcome-avatar-img):hover {
  transform: scale(1.015);
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.35);
}

.ai-image-container {
  display: inline-block;
  max-width: 100%;
  margin: 12px 0;
  position: relative;
  border-radius: var(--border-radius-md);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-medium);
}

.ai-image-container .ai-rendered-image {
  margin: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.ai-image-caption-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-muted);
  user-select: none;
}

.ai-image-caption-bar .btn-download-img {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  background: var(--primary-light);
  padding: 3px 10px;
  border-radius: var(--border-radius-sm);
  transition: all 0.2s ease;
}

.ai-image-caption-bar .btn-download-img:hover {
  background: var(--primary);
  color: #ffffff;
}

[data-theme="light"] .ai-image-caption-bar {
  background: #f1f5f9;
}
