/* ── chat.css ── */
/* استایل‌های کامل چت با حس لطافت، آرامش و اعتماد (ChatGPT / DeepSeek) */

/* ============================================ */
/* هدر - تمیز و متعادل */
/* ============================================ */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-primary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  gap: 1rem;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-primary);
}

.header-title h1 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.version-badge {
  font-size: 0.65rem;
  font-weight: 500;
  background: var(--accent-color);
  color: #fff;
  padding: 0.15em 0.6em;
  border-radius: 2em;
  margin-left: 0.5rem;
  letter-spacing: 0.03em;
}

.header-title p {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.15rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.header-actions .btn-sm {
  padding: 0.5rem 1rem !important;
  font-size: 0.8rem !important;
  font-weight: 500 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 0.4rem !important;
  border-radius: 2em !important;
  border: none !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  white-space: nowrap !important;
  box-shadow: none !important;
  background: var(--bg-secondary) !important;
  color: var(--text-secondary) !important;
  border: 1px solid var(--border-color) !important;
}

.header-actions .btn-sm:hover {
  background: var(--bg-hover) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04) !important;
}

.header-actions .btn-sm[onclick*="openUpgradeModal"],
.header-actions .btn-sm[onclick*="openDonate"] {
  background: transparent !important;
  color: var(--text-secondary) !important;
  box-shadow: none !important;
}

.header-action-btn {
  background: transparent;
  border: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  position: relative;
}

.header-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: none;
  box-shadow: none;
}

.header-action-btn .tooltip {
  display: none;
  position: absolute;
  bottom: -2rem;
  right: 50%;
  transform: translateX(50%);
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 0.25rem 0.6rem;
  border-radius: 0.5rem;
  font-size: 0.7rem;
  white-space: nowrap;
  pointer-events: none;
}

.header-action-btn:hover .tooltip {
  display: block;
}

/* ============================================ */
/* صفحه Welcome - گرم و نرم */
/* ============================================ */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  text-align: center;
  padding: 3rem 1.5rem;
  position: relative;
}

.welcome-icon-wrapper {
  position: relative;
  width: 100px;
  height: 100px;
  margin-bottom: 2rem;
}

.welcome-icon-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 1.5px solid rgba(16, 163, 127, 0.15);
  animation: ringRotate 12s linear infinite;
}

.welcome-icon-ring::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-color);
  opacity: 0.8;
}

@keyframes ringRotate {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

.welcome-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 65px;
  height: 65px;
  background: linear-gradient(145deg, var(--accent-color), #0d8a6a);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(16, 163, 127, 0.2);
  animation: welcomePulse 3s ease-in-out infinite;
}

@keyframes welcomePulse {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
    box-shadow: 0 8px 24px rgba(16, 163, 127, 0.2);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.06);
    box-shadow: 0 12px 32px rgba(16, 163, 127, 0.3);
  }
}

.welcome-icon i {
  font-size: 1.8rem;
  color: #fff;
}

/* ذرات شناور */
.welcome-particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.particle {
  position: absolute;
  font-size: 0.8rem;
  animation: particleFloat 5s ease-in-out infinite;
  opacity: 0;
}

.p1 {
  top: 10%;
  left: 55%;
  animation-delay: 0s;
}
.p2 {
  top: 25%;
  right: 5%;
  animation-delay: 0.6s;
}
.p3 {
  bottom: 20%;
  right: 10%;
  animation-delay: 1.2s;
}
.p4 {
  bottom: 10%;
  left: 45%;
  animation-delay: 1.8s;
}
.p5 {
  top: 20%;
  left: 5%;
  animation-delay: 2.4s;
}
.p6 {
  top: 55%;
  left: 8%;
  animation-delay: 3s;
}

@keyframes particleFloat {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.6);
  }
  20% {
    opacity: 0.6;
    transform: translateY(-10px) scale(1);
  }
  80% {
    opacity: 0.3;
    transform: translateY(-5px) scale(0.8);
  }
  100% {
    opacity: 0;
    transform: translateY(0) scale(0.6);
  }
}

.welcome-screen h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.welcome-gradient {
  background: linear-gradient(135deg, var(--accent-color), #6366f1, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-screen p {
  color: var(--text-secondary);
  margin-bottom: 2.5rem;
  font-size: 1rem;
  max-width: 32rem;
  line-height: 1.7;
}

/* کارت‌های پیشنهادی */
.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  max-width: 800px;
  margin-top: 1.5rem;
}

.suggestion-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 1.5rem 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.suggestion-card:hover {
  background: var(--bg-hover);
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.04);
  transform: translateY(-2px);
}

.suggestion-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  background: rgba(16, 163, 127, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.75rem;
  color: var(--accent-color);
  font-size: 1.2rem;
  transition: all 0.2s ease;
}

.suggestion-card:hover .suggestion-icon {
  background: var(--accent-color);
  color: #fff;
}

.suggestion-card span {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* ============================================ */
/* پیام‌ها - خوانایی و آرامش */
/* ============================================ */
.messages-container {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.messages-list {
  max-width: 48rem;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
  width: 100%;
}

.message {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  animation: fadeIn 0.3s ease;
}

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

.message-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.95rem;
}

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

.message.assistant .message-avatar {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.message-content {
  flex: 1;
  line-height: 1.75;
  font-size: 0.95rem;
  color: var(--text-primary);
  min-width: 0;
  word-break: break-word;
}

.message.user .message-content {
  padding: 0.8rem 1rem;
  background: var(--user-message-bg);
  border-radius: 1.25rem 1.25rem 0.25rem 1.25rem;
  max-width: 85%;
}

.message.assistant .message-content {
  padding: 0.5rem 0;
  max-width: 100%;
}

.message-content p {
  margin: 0 0 0.8rem;
}

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

.message-content pre {
  background: var(--bg-sidebar);
  border-radius: 0.75rem;
  padding: 1rem;
  margin: 0.8rem 0;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  direction: ltr;
  text-align: left;
  font-size: 0.85rem;
}

.message-content code {
  font-size: 0.85rem;
}

/* تایپینگ */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.8rem 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  30% {
    transform: translateY(-5px);
    opacity: 0.8;
  }
}

/* ============================================ */
/* چت‌بار (input) - مدرن و نرم */
/* ============================================ */
.input-container {
  border-top: 1px solid var(--border-color);
  padding: 0.75rem 1.25rem 1rem;
  background: var(--bg-primary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.input-wrapper {
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 1.75rem;
  padding: 0.35rem 0.5rem 0.35rem 1.25rem;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
textarea {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0.6rem 0.5rem 0.6rem 0;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  resize: none;
  outline: none;
  max-height: 10rem;
  line-height: 1.6;
}

textarea:focus,
textarea:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

textarea::placeholder {
  color: var(--text-tertiary);
  text-align: right;
  padding-right: 0.25rem;
  opacity: 0.8;
}

.send-btn {
  width: 2.25rem;
  height: 2.25rem;
  min-width: 2.25rem;
  border-radius: 50%;
  background: var(--accent-color);
  border: none;
  cursor: pointer;
  color: #fff;
  transition: all 0.2s ease;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  box-shadow: 0 2px 8px rgba(16, 163, 127, 0.25);
  margin-left: auto;
  margin-right: 0.2rem;
  margin-bottom: 0.15rem;
}

.send-btn:hover {
  background: #059669;
  transform: scale(1.04);
  box-shadow: 0 4px 14px rgba(16, 163, 127, 0.35);
}

.send-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
  box-shadow: none;
}

.upload-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

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

.input-info {
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.input-info a {
  color: var(--text-tertiary);
  text-decoration: none;
}

.input-info a:hover {
  color: var(--accent-color);
}

/* فایل Indicator */
#fileIndicator {
  max-width: 48rem !important;
  margin: 0.5rem auto 0 !important;
  border-radius: 0.75rem !important;
  font-size: 0.8rem !important;
  padding: 0.6rem 1rem !important;
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border-color) !important;
  color: var(--text-primary) !important;
}

/* ============================================ */
/* دکمه‌های حالت (Exam, Consultant, Planner) */
/* ============================================ */
.chat-actions {
  max-width: 48rem;
  margin: 0 auto 0.5rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.9rem;
  border-radius: 2em;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

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

.action-btn.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16, 163, 127, 0.25);
}

/* ============================================ */
/* کد بلاک‌ها - تمیز و حرفه‌ای */
/* ============================================ */
.code-block-wrapper {
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #1e1e2e;
  margin: 1rem 0;
  direction: ltr;
  text-align: left;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.8rem;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.7rem;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.code-block-copy {
  background: transparent;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: color 0.2s;
}

.code-block-copy:hover {
  color: #fff;
}

.code-block-wrapper pre {
  margin: 0 !important;
  padding: 1rem !important;
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  overflow-x: auto;
  direction: ltr !important;
  text-align: left !important;
  white-space: pre;
}

.code-block-wrapper code {
  color: #e0e0e0 !important;
  font-size: 0.85rem !important;
  line-height: 1.6 !important;
  direction: ltr !important;
  text-align: left !important;
  unicode-bidi: embed !important;
  white-space: pre;
}

/* ============================================ */
/* جدول‌ها - شفاف و خوانا */
/* ============================================ */
.markdown-table-wrapper {
  overflow-x: auto;
  margin: 1rem 0;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
}

.markdown-table-wrapper table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.markdown-table-wrapper thead {
  background: var(--bg-sidebar);
}

.markdown-table-wrapper th,
.markdown-table-wrapper td {
  padding: 0.6rem 0.8rem;
  text-align: right;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
}

.markdown-table-wrapper th {
  font-weight: 600;
  color: var(--text-primary);
}

.markdown-table-wrapper tbody tr:hover {
  background: rgba(16, 163, 127, 0.03);
}

.markdown-table-wrapper tbody tr:last-child td {
  border-bottom: none;
}

/* ============================================ */
/* منابع (Search) */
/* ============================================ */
.sources-section {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  background: var(--bg-secondary);
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
}

.sources-section .sources-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sources-section .sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.sources-section .source-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.7rem;
  background: var(--bg-hover);
  border-radius: 0.4rem;
  font-size: 0.75rem;
  color: var(--accent-color);
  text-decoration: none;
  transition: background 0.2s;
}

.sources-section .source-link:hover {
  background: var(--accent-color);
  color: #fff;
}

/* ============================================ */
/* تفکر (DeepThink) */
/* ============================================ */
.thinking-section {
  margin-bottom: 1rem;
  padding: 0.8rem 1rem;
  background: rgba(245, 158, 11, 0.04);
  border-radius: 0.5rem;
  border: 1px solid rgba(245, 158, 11, 0.12);
  cursor: pointer;
}

.thinking-section .thinking-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #f59e0b;
}

.thinking-section .thinking-content {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.8;
  display: none;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(245, 158, 11, 0.15);
}

.thinking-section.expanded .thinking-content {
  display: block;
}

/* ============================================ */
/* منوی کشویی انتخاب مدل */
/* ============================================ */
.model-selector {
  position: relative;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.5rem;
  transition: background 0.2s;
}

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

.model-selector .model-arrow {
  font-size: 0.65rem;
  margin-right: 0.25rem;
  color: var(--text-tertiary);
  vertical-align: middle;
}

.model-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 260px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
  z-index: 300;
  padding: 0.4rem;
  animation: fadeInUp 0.2s ease;
}

.model-dropdown.show {
  display: block;
}

.model-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s;
}

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

.model-option.active {
  background: rgba(16, 163, 127, 0.06);
  border: 1px solid rgba(16, 163, 127, 0.2);
}

.model-option.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.model-option-icon {
  font-size: 1.5rem;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border-radius: 0.6rem;
  flex-shrink: 0;
}

.model-option-info {
  flex: 1;
}

.model-option-name {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.15rem;
}

.model-option-desc {
  display: block;
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.model-option .lock-icon {
  font-size: 0.9rem;
  color: var(--text-tertiary);
  margin-left: auto;
}

/* اورلی */
.model-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 299;
}

.model-overlay.show {
  display: block;
}

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

/* ============================================ */
/* واکنش‌گرایی (Mobile) */
/* ============================================ */
@media (max-width: 768px) {
  .chat-header {
    padding: 0.5rem 1rem;
  }

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

  .header-actions .btn-sm span {
    display: none;
  }

  .header-actions .btn-sm {
    padding: 0.5rem !important;
    font-size: 1rem !important;
  }

  .welcome-screen h2 {
    font-size: 1.5rem;
  }

  .suggestions-grid {
    grid-template-columns: 1fr;
  }

  .messages-list {
    padding: 1rem;
  }

  .input-wrapper {
    margin: 0 0.5rem;
  }

  .model-dropdown {
    right: 0;
    left: auto;
    min-width: 220px;
    z-index: 9999 !important;
    background: var(--bg-primary) !important;
  }
}

/* ============================================ */
/* فرمول‌های ریاضی (KaTeX) - چپ‌چین */
/* ============================================ */
.katex,
.katex-display,
.katex-html,
.katex .katex-mathml,
.katex .katex-html {
  direction: ltr !important;
  text-align: left !important;
  unicode-bidi: embed !important;
}

.katex-display {
  direction: ltr !important;
  text-align: left !important;
  overflow-x: auto;
  max-width: 100%;
}

.katex-display > .katex {
  direction: ltr !important;
  text-align: left !important;
  overflow-x: visible;
  max-width: none;
}

/* ============================================ */
/* قلاب‌های ظریف */
/* ============================================ */
@keyframes heartbeat {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}
.header-btn-upgrade {
  background: rgba(99, 102, 241, 0.1) !important;
  color: #6366f1 !important;
  border: 1px solid rgba(99, 102, 241, 0.2) !important;
}

.header-btn-upgrade:hover {
  background: rgba(99, 102, 241, 0.2) !important;
  color: #4f46e5 !important;
}

.header-btn-donate {
  background: rgba(229, 62, 62, 0.1) !important;
  color: #e53e3e !important;
  border: 1px solid rgba(229, 62, 62, 0.2) !important;
}

.header-btn-donate:hover {
  background: rgba(229, 62, 62, 0.2) !important;
  color: #c53030 !important;
}
