*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1f2933 0, #020617 45%, #000 100%);
  color: #e5e7eb;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 1rem;
}

.app {
  width: 100%;
  max-width: 900px;
  background: rgba(15, 23, 42, 0.96);
  border-radius: 1.25rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.5rem;
}

.app-header {
  text-align: center;
  margin-bottom: 0.75rem;
}

.app-header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
}

.app-header .subtitle {
  margin-top: 0.35rem;
  color: #9ca3af;
  font-size: 0.88rem;
}

/* كارت الأوث */
.auth-card {
  background: rgba(15, 23, 42, 0.9);
  border-radius: 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.45);
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.65rem;
}

.auth-card h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.auth-text {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #9ca3af;
}

.auth-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.auth-row input {
  flex: 1;
  min-width: 180px;
  padding: 0.35rem 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid #4b5563;
  background: #020617;
  color: inherit;
}

.auth-row input:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.7);
}

.auth-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.auth-buttons button {
  border-radius: 999px;
  border: none;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.auth-buttons button.secondary {
  background: #020617;
  color: #e5e7eb;
  border: 1px solid #4b5563;
}

.auth-buttons button:not(.secondary) {
  background: linear-gradient(135deg, #22c55e, #0ea5e9);
  color: #0b1120;
  font-weight: 600;
}

.auth-buttons button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-note {
  margin: 0;
  font-size: 0.8rem;
  color: #9ca3af;
}

/* شريط الحالة */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  margin-bottom: 0.6rem;
  border-radius: 0.75rem;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.status-left {
  font-size: 0.85rem;
}

.status-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.status-right button {
  border-radius: 999px;
  border: 1px solid #4b5563;
  background: #020617;
  color: #e5e7eb;
  padding: 0.25rem 0.8rem;
  cursor: pointer;
}

.status-right button:hover {
  border-color: #f97316;
}

/* اختيار الموديل */
.chat-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-height: 0;
}

.model-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: rgba(15, 23, 42, 0.85);
  border-radius: 0.75rem;
}

.model-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.model-group label {
  font-size: 0.8rem;
  color: #9ca3af;
}

.model-group select {
  min-width: 160px;
  padding: 0.3rem 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid #4b5563;
  background: #020617;
  color: inherit;
}

/* الرسائل */
.messages {
  flex: 1;
  min-height: 0;
  margin-top: 0.5rem;
  padding: 0.5rem 0.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.message {
  display: flex;
  width: 100%;
}

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

.message.bot {
  justify-content: flex-start;
}

.bubble {
  max-width: 80%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.9rem;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  color: white;
  border-bottom-right-radius: 0.2rem;
}

.message.bot .bubble {
  background: #020617;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-bottom-left-radius: 0.2rem;
}

/* فقاعة الكتابة */
.typing {
  font-size: 0.8rem;
  color: #9ca3af;
}

/* فورم الشات */
.chat-form {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(31, 41, 55, 0.9);
}

.chat-input-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.attach-button {
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 999px;
  border: 1px solid #4b5563;
  background: #020617;
  color: #e5e7eb;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.attach-button:hover {
  border-color: #38bdf8;
}

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

.chat-form input {
  flex: 1;
  border-radius: 999px;
  border: 1px solid #4b5563;
  padding: 0.45rem 0.75rem;
  background: #020617;
  color: inherit;
}

.attachments-info {
  font-size: 0.75rem;
  color: #9ca3af;
}

.attachments-info span {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.9);
}


.context-options {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: #9ca3af;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.context-options input[type="checkbox"] {
  accent-color: #f97316;
}

.chat-form input:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.7);
}

.chat-form button {
  border-radius: 999px;
  border: none;
  padding: 0.45rem 1rem;
  background: linear-gradient(135deg, #22c55e, #0ea5e9);
  color: #0b1120;
  font-weight: 600;
  cursor: pointer;
}

.chat-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.app-footer {
  margin-top: 0.35rem;
  text-align: center;
  font-size: 0.75rem;
  color: #6b7280;
}

.app-footer code {
  background: #020617;
  padding: 0.1rem 0.25rem;
  border-radius: 0.3rem;
}

.hidden {
  display: none !important;
}


/* === قائمة المحادثات المحلية =========================================== */

.conversations-toggle {
  position: fixed;
  inset-inline-start: 1rem;
  bottom: 1.25rem;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: radial-gradient(circle at top, #0f172a, #020617);
  color: #e5e7eb;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.8);
  z-index: 40;
}

.conversations-toggle:hover {
  border-color: #f97316;
  transform: translateY(-1px);
}

.conversations-panel {
  position: fixed;
  inset-block: 4.25rem 1rem;
  inset-inline-start: 1rem;
  width: min(280px, 80vw);
  background: rgba(15, 23, 42, 0.98);
  border-radius: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.4);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.9);
  padding: 0.75rem 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 50;
}

.conversations-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.conversations-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.conversations-icon-button {
  border-radius: 999px;
  border: 1px solid #4b5563;
  background: #020617;
  color: #e5e7eb;
  width: 1.8rem;
  height: 1.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.conversations-icon-button:hover {
  border-color: #f97316;
}

.conversations-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.conversations-actions button {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  border: 1px solid #4b5563;
  background: #020617;
  color: #e5e7eb;
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}

.conversations-actions button:hover {
  border-color: #38bdf8;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0.1rem 0.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.conversation-item {
  border-radius: 0.75rem;
  border: 1px solid rgba(75, 85, 99, 0.9);
  background: rgba(15, 23, 42, 0.95);
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.conversation-item.active {
  border-color: #f97316;
  box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.5);
}

.conversation-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-meta {
  font-size: 0.7rem;
  color: #9ca3af;
}

/* على الشاشات الصغيرة نرفع الزر والقائمة قليلاً */
@media (max-width: 640px) {
  .conversations-toggle {
    bottom: 0.9rem;
  }

  .conversations-panel {
    inset-block: 4rem 0.75rem;
    inset-inline-start: 0.75rem;
    width: min(260px, 78vw);
  }
}

@media (max-width: 640px) {
  .app {
    padding: 0.9rem;
    border-radius: 1rem;
  }

  .bubble {
    max-width: 100%;
  }

  .model-picker {
    flex-direction: column;
  }

  .chat-form {
    flex-direction: column;
  }

  .chat-form button {
    width: 100%;
  }
}

.image-button {
  border-radius: 999px;
  border: 1px solid #4b5563;
  background: radial-gradient(circle at top, #0f172a, #020617);
  color: #e5e7eb;
  width: 2.4rem;
  height: 2.4rem;
  margin-inline-start: 0.25rem;
  margin-inline-end: 0.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.image-button:hover {
  border-color: #f97316;
  transform: translateY(-1px);
}

.message-image {
  max-width: 100%;
  border-radius: 0.75rem;
  display: block;
}

.message-image-caption {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: #9ca3af;
}


/* === عرض أكواد البرمجة في الردود مع زر نسخ ============================ */
.code-block {
  margin: 0.6rem 0;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: #020617;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  background: radial-gradient(circle at top, #020617, #020617);
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
}

.code-block-lang {
  text-transform: lowercase;
  opacity: 0.8;
  color: #9ca3af;
}

.copy-code-btn {
  border: none;
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.copy-code-btn:hover {
  background: rgba(37, 99, 235, 0.9);
}

.copy-code-btn.copied {
  background: rgba(34, 197, 94, 0.95);
}

.code-block pre {
  margin: 0;
  padding: 0.6rem 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre;
}


/* === شاشة التحميل (Splash Screen) ====================================== */
.splash-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #020617 0, #000 55%, #000 100%);
  z-index: 9999;
}

.splash-inner {
  text-align: center;
  padding: 2.5rem 2rem;
  border-radius: 1.75rem;
  background: radial-gradient(circle at top, rgba(15,23,42,0.98), rgba(15,23,42,0.98));
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
  border: 1px solid rgba(148,163,184,0.35);
  max-width: 320px;
  width: 90%;
}

.splash-logo-wrap {
  width: 140px;
  height: 140px;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  border: 3px solid rgba(250,204,21,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #020617 0, #000 60%);
  overflow: hidden;
}

.splash-logo {
  max-width: 90%;
  max-height: 90%;
  display: block;
}

.splash-title {
  margin: 0 0 0.3rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.splash-status {
  margin: 0 0 1.4rem;
  font-size: 0.85rem;
  color: #9ca3af;
}

.splash-loader {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border-radius: 999px;
  border: 3px solid rgba(148,163,184,0.25);
  border-top-color: #22c55e;
  animation: splash-spin 0.9s linear infinite;
}

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

/* === شعار MAY في أعلى الصفحة =========================================== */
.app-header-inner {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 1rem;
}

.app-logo-fixed {
  flex-shrink: 0;
  margin-inline-start: 0.25rem;
}

.app-logo-small {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: 2px solid rgba(250,204,21,0.9);
  background: radial-gradient(circle at top, #020617 0, #000 60%);
  display: block;
}


/* === صفحة تسجيل الدخول المستقلة ======================================== */
.auth-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem 1rem 2.5rem;
}

.auth-header {
  margin-bottom: 1.5rem;
}

.auth-header-top {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.auth-logo-fixed {
  flex-shrink: 0;
  margin-inline-start: 0.25rem;
}

.auth-logo-small {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: 2px solid rgba(250,204,21,0.9);
  background: radial-gradient(circle at top, #020617 0, #000 60%);
  display: block;
}

.auth-header-text h1 {
  margin: 0;
  font-size: 1.6rem;
}

.auth-subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: #9ca3af;
}

.auth-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-card-standalone {
  margin-top: 0.5rem;
}

