:root {
  --bg: #0e0f13;
  --bg-elevated: #16181d;
  --bg-input: #1c1f26;
  --border: #262a33;
  --text: #ececf1;
  --text-dim: #9a9da6;
  --accent: #7c5cff;
  --accent-hover: #8f72ff;
  --bot-bubble: #1c1f26;
  --user-bubble: #7c5cff;
  --danger: #ff5c6c;
  --success: #34d399;
  --radius: 14px;
  --sidebar-w: 264px;
}

[data-theme="light"] {
  --bg: #f7f7f8;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --border: #e5e5e8;
  --text: #1a1a1e;
  --text-dim: #6b6d76;
  --bot-bubble: #ffffff;
  --user-bubble: #7c5cff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Tahoma", "Cairo", system-ui, -apple-system, sans-serif;
  direction: rtl;
  font-size: 15px;
}

body { display: flex; overscroll-behavior: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

a { color: inherit; }
button { font-family: inherit; cursor: pointer; }

/* ───────── Layout ───────── */
.app {
  display: flex;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-right .25s ease;
}

.sidebar-header {
  padding: 14px;
  display: flex;
  gap: 8px;
}

.btn-new-chat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  transition: background .15s;
}
.btn-new-chat:hover { background: var(--bg-input); }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--bg-input); }

.search-box {
  margin: 0 14px 10px;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 2px;
  gap: 6px;
}
.conv-item:hover { background: var(--bg-input); }
.conv-item.active { background: var(--bg-input); color: var(--text); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-actions { display: none; gap: 4px; }
.conv-item:hover .conv-actions { display: flex; }
.conv-actions button {
  background: none; border: none; color: var(--text-dim); font-size: 13px; padding: 2px 4px; border-radius: 6px;
}
.conv-actions button:hover { color: var(--text); background: var(--border); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
}
.user-chip:hover { background: var(--bg-input); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #4fd1ff);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0;
}
.footer-links { display: flex; gap: 6px; flex-wrap: wrap; }
.footer-links a {
  font-size: 12.5px; color: var(--text-dim); text-decoration: none;
  padding: 6px 8px; border-radius: 8px;
}
.footer-links a:hover { background: var(--bg-input); color: var(--text); }

/* ───────── Chat main ───────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  background: var(--bg-elevated);
}
.topbar-identity { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.topbar-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  box-shadow: 0 0 0 2px var(--accent), 0 2px 8px rgba(124,92,255,.35);
}
.topbar-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.topbar-title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

.menu-toggle { display: none; }

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 8px;
  position: relative;
  background-image: linear-gradient(180deg, rgba(14,15,19,.35) 0%, rgba(14,15,19,.55) 55%, rgba(14,15,19,.85) 100%), var(--chat-bg-image, none);
  background-size: cover;
  background-position: top center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}
[data-theme="light"] .chat-scroll {
  background-image: linear-gradient(180deg, rgba(247,247,248,.55) 0%, rgba(247,247,248,.72) 55%, rgba(247,247,248,.92) 100%), var(--chat-bg-image, none);
}

.chat-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 18px;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 28px;
}
.empty-state h1 {
  font-size: 23px;
  color: var(--text);
  background: linear-gradient(135deg, var(--accent), #4fd1ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 560px;
}
.suggestion-chip {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: right;
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 13.5px;
}
.suggestion-chip:hover { background: var(--bg-input); color: var(--text); }

/* ── صفوف الرسائل — مثل انستا/مسنجر (ملتصقة ومضغوطة) ── */
.msg-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  animation: fadeUp .18s ease;
}
.msg-row + .msg-row.bot,
.msg-row + .msg-row.user { margin-top: 2px; }
.msg-row:last-child { margin-bottom: 10px; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-row.user { flex-direction: row-reverse; }

/* إخفاء الأفاتار عند الرسائل المتتالية من نفس الطرف */
.msg-row.user .msg-avatar { display: none; }

.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; overflow: hidden; align-self: flex-end;
}
.msg-avatar.bot { background: linear-gradient(135deg, var(--accent), #4fd1ff); }
.msg-avatar.user { background: var(--bg-input); border: 1px solid var(--border); }
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.msg-bubble-wrap { max-width: 75%; display: flex; flex-direction: column; gap: 2px; position: relative; }
.msg-row.user .msg-bubble-wrap { align-items: flex-end; }

/* فقاعة الرسالة — مضغوطة مثل انستغرام/مسنجر */
.msg-bubble {
  padding: 8px 13px;
  border-radius: 18px;
  line-height: 1.45;
  font-size: 14.5px;
  word-break: break-word;
  display: inline-block;
  max-width: 100%;
}

/* زوايا الفقاعة حسب الطرف — مثل مسنجر */
.msg-row.bot .msg-bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 18px;
}
.msg-row.user .msg-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 18px;
}

/* محتوى داخل الفقاعة — بدون مسافات زائدة */
.msg-bubble p { margin: 2px 0; }
.msg-bubble p:first-child { margin-top: 0; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 4px 0; padding-inline-start: 18px; }
.msg-bubble li { margin: 1px 0; }
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 { margin: 4px 0 2px; font-size: 1em; font-weight: 700; }
.msg-bubble strong { font-weight: 700; }
.msg-bubble pre {
  background: #0a0b0e;
  border-radius: 10px;
  padding: 10px 12px;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  font-size: 12.5px;
  border: 1px solid var(--border);
  margin: 4px 0;
}
.msg-bubble code { font-family: "Consolas", monospace; }
.msg-bubble :not(pre) > code {
  background: rgba(124,92,255,.18);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 13px;
}
/* ── مرفقات الرسائل (صور/فيديو/صوت): قابلة للنقر للتكبير + زر تنزيل عند التمرير ── */
.msg-media-wrap { position: relative; display: inline-block; max-width: 100%; margin-top: 6px; }
.msg-media-wrap video, .msg-media-wrap audio { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; }
/* ملف قابل للتنزيل (ZIP وما شابه) */
.msg-file-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px;
  padding: 8px 12px;
  text-decoration: none;
  color: inherit;
  font-size: 13px;
  max-width: 260px;
  transition: background .15s;
  word-break: break-all;
}
.msg-file-bubble:hover { background: rgba(255,255,255,.14); }
.msg-file-icon { font-size: 22px; flex-shrink: 0; }
.msg-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file-dl { flex-shrink: 0; font-size: 14px; opacity: .7; }
.msg-media-audio { width: 100%; min-width: 220px; }
.msg-image-wrap img {
  max-width: 100%; max-height: 320px; border-radius: 10px; display: block;
  object-fit: contain; cursor: zoom-in; transition: filter .15s;
}
.msg-image-wrap:hover img { filter: brightness(.92); }
/* ── زر التنزيل ── */
.msg-download-btn {
  position: absolute;
  bottom: 10px;
  inset-inline-end: 10px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(10, 10, 20, .65);
  text-decoration: none;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transform: translateY(6px) scale(.85);
  transition: opacity .2s cubic-bezier(.34,1.56,.64,1),
              transform .2s cubic-bezier(.34,1.56,.64,1),
              background .15s, box-shadow .15s;
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  box-shadow: 0 2px 12px rgba(0,0,0,.45),
              inset 0 0 0 1px rgba(255,255,255,.14);
}
.msg-download-btn svg {
  width: 18px; height: 18px;
  display: block;
}
.msg-media-wrap:hover .msg-download-btn,
.msg-media-wrap:focus-within .msg-download-btn {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.msg-download-btn:hover {
  background: var(--accent);
  box-shadow: 0 4px 16px rgba(124,92,255,.5),
              inset 0 0 0 1px rgba(255,255,255,.2);
  transform: translateY(0) scale(1.1);
}
.msg-download-btn:active {
  transform: translateY(0) scale(.93);
  transition-duration: .08s;
}
/* الجوال: ظاهر دائماً */
@media (hover: none) {
  .msg-download-btn {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── نافذة العرض الكامل للصور (Lightbox) + تكبير/تصغير ── */
.lightbox-overlay {
  position: fixed; inset: 0; background: rgba(5, 3, 15, .93);
  display: none; align-items: center; justify-content: center;
  z-index: 900; padding: 60px 20px 80px;
  overflow: hidden;
}
.lightbox-overlay.open { display: flex; }

/* الصورة — transform يُطبَّق بالجافاسكريبت */
.lightbox-img {
  max-width: 92vw; max-height: 82vh;
  border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.6);
  transform-origin: center center;
  transition: transform .18s ease;
  will-change: transform;
  user-select: none; -webkit-user-drag: none;
}
.lightbox-img.lb-dragging { transition: none; cursor: grabbing; }
.lightbox-img.lb-zoomed   { cursor: grab; }

/* ── شريط الأزرار العلوي ── */
.lightbox-topbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px; padding: 6px 12px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}

/* أزرار مشتركة */
.lb-btn {
  background: none; border: none; color: #fff; cursor: pointer;
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; transition: background .15s, transform .1s;
  flex-shrink: 0;
}
.lb-btn:hover  { background: rgba(255,255,255,.18); }
.lb-btn:active { transform: scale(.88); }

/* مؤشر نسبة التكبير */
.lb-zoom-label {
  color: rgba(255,255,255,.75); font-size: 12.5px; font-weight: 600;
  min-width: 42px; text-align: center; letter-spacing: .3px;
  user-select: none;
}

/* فاصل عمودي */
.lb-sep {
  width: 1px; height: 20px; background: rgba(255,255,255,.18);
  flex-shrink: 0;
}

/* زر الإغلاق (الزاوية) */
.lightbox-close {
  position: absolute; top: 12px; inset-inline-end: 16px;
  background: rgba(255,255,255,.1); color: #fff; border: none;
  border-radius: 50%; width: 38px; height: 38px; padding: 0;
  font-size: 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lightbox-close:hover { background: var(--accent); }

/* زر التنزيل (الزاوية) */
.lightbox-download {
  position: absolute; top: 12px; inset-inline-start: 16px;
  background: rgba(255,255,255,.1); color: #fff; border: none;
  border-radius: 999px; padding: 8px 14px; font-size: 13px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s;
}
.lightbox-download:hover { background: var(--accent); }

/* تلميح الإيماءات — يظهر للحظة عند الفتح */
.lb-hint {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.55); color: rgba(255,255,255,.6);
  font-size: 12px; border-radius: 999px; padding: 5px 14px;
  pointer-events: none; white-space: nowrap;
  opacity: 1; transition: opacity .4s;
}
.lb-hint.hidden { opacity: 0; }

.msg-tools {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.msg-row:hover .msg-tools { opacity: 1; }
.msg-tools button {
  background: none; border: none; color: var(--text-dim); font-size: 12px;
  padding: 3px 6px; border-radius: 6px;
}
.msg-tools button:hover { background: var(--bg-input); color: var(--text); }

/* ───────── Reply / Quote ───────── */
.msg-quote {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 4px;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(124,92,255,.10);
  font-size: 12.5px;
  color: var(--text-dim);
  max-width: 100%;
}
.msg-quote-bar { width: 3px; border-radius: 3px; background: var(--accent); flex-shrink: 0; }
.msg-quote-text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reply-preview-bar {
  max-width: 780px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: 12px;
  padding: 8px 12px;
  animation: replySlideIn .18s ease;
}
@keyframes replySlideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.reply-preview-content { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.reply-preview-label { font-size: 11.5px; font-weight: 600; color: var(--accent); }
.reply-preview-text {
  font-size: 12.5px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reply-preview-close {
  background: none; border: none; color: var(--text-dim); font-size: 14px;
  padding: 4px 8px; border-radius: 8px; flex-shrink: 0; cursor: pointer;
}
.reply-preview-close:hover { background: var(--bg-input); color: var(--text); }

.typing-indicator {
  display: flex; gap: 4px; align-items: center; padding: 4px 0;
}
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .3; } 40% { opacity: 1; } }

/* ───────── Composer ───────── */
.composer-wrap {
  padding: 8px 16px 14px;
  position: relative;
  z-index: 2;
  background: var(--bg);
}
.composer {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 10px;
}
.composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  resize: none;
  font-size: 14px;
  line-height: 1.45;
  max-height: 140px;
  padding: 5px 4px;
  font-family: inherit;
}
.composer textarea:focus { outline: none; }
.attach-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 20px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.attach-btn:hover { background: var(--accent); color: #fff; transform: rotate(90deg); }
.image-preview-bar {
  max-width: 780px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: 12px;
  padding: 8px 12px;
  animation: replySlideIn .18s ease;
}
.image-preview-bar img {
  width: 42px; height: 42px; object-fit: cover; border-radius: 8px; flex-shrink: 0;
}
.image-preview-info { flex: 1; font-size: 12.5px; color: var(--text-dim); overflow: hidden; }
.image-preview-close {
  background: none; border: none; color: var(--text-dim); font-size: 14px;
  padding: 4px 8px; border-radius: 8px; flex-shrink: 0; cursor: pointer;
}
.image-preview-close:hover { background: var(--bg-input); color: var(--text); }

/* ───────── Reactions (Messenger/Instagram style) ───────── */
.msg-reaction-badge {
  position: absolute;
  bottom: -10px;
  font-size: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 5px;
  line-height: 1.4;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  animation: reactionPop .25s cubic-bezier(.34,1.56,.64,1);
}
.msg-row.bot .msg-reaction-badge { inset-inline-start: 46px; }
.msg-row.user .msg-reaction-badge { inset-inline-end: 4px; }
@keyframes reactionPop { from { transform: scale(0); } to { transform: scale(1); } }

.reaction-picker {
  position: fixed;
  z-index: 50;
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  animation: reactionPop .15s ease;
}
.reaction-picker button {
  background: none; border: none; font-size: 20px; cursor: pointer;
  padding: 2px 4px; border-radius: 50%; transition: transform .15s ease;
}
.reaction-picker button:hover { transform: scale(1.35); }

.send-btn {
  position: relative;
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #7c5cff 45%, #4fd1ff 100%);
  border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer;
  overflow: visible;
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1), box-shadow .25s ease, filter .2s ease;
  box-shadow: 0 3px 14px rgba(124,92,255,.5), 0 0 0 0 rgba(124,92,255,.5);
}
.send-btn-glow {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124,92,255,.55) 0%, rgba(124,92,255,0) 70%);
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
  z-index: -1;
}
.send-btn-icon {
  width: 19px; height: 19px;
  transform: translate(-1px, 0.5px);
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1);
}
.send-btn:hover {
  transform: scale(1.1) rotate(-6deg);
  filter: brightness(1.08);
  box-shadow: 0 6px 20px rgba(124,92,255,.65);
}
.send-btn:hover .send-btn-glow { opacity: 1; transform: scale(1.15); }
.send-btn:hover .send-btn-icon { transform: translate(1px, -1px) scale(1.05); }
.send-btn:active { transform: scale(.9) rotate(-2deg); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }
.send-btn:disabled .send-btn-glow { opacity: 0; }
.composer-hint {
  text-align: center; font-size: 11px; color: var(--text-dim); margin-top: 6px;
}

/* ───────── Auth pages ───────── */
.auth-page {
  width: 100%; min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, rgba(124,92,255,.15), transparent 60%), var(--bg);
  padding: 20px 0;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 18px; padding: 32px 28px;
}

/* السماح بالتمرير في صفحات تسجيل الدخول والتسجيل */
body:has(.auth-page) {
  overflow-y: auto !important;
  height: auto !important;
}
html:has(.auth-page) {
  overflow-y: auto !important;
  height: auto !important;
}
.auth-avatar { display: block; width: 64px; height: 64px; border-radius: 50%; object-fit: cover; margin: 0 auto 10px; box-shadow: 0 0 0 3px var(--accent), 0 4px 18px rgba(124,92,255,.35); }
.auth-logo { text-align: center; font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.auth-logo span { color: var(--accent); }
.auth-subtitle { text-align: center; color: var(--text-dim); font-size: 13.5px; margin-bottom: 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text-dim); }
.field input {
  width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-input); color: var(--text); font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.btn-primary {
  width: 100%; padding: 12px; border-radius: 10px; border: none;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14.5px; margin-top: 6px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.auth-error {
  background: rgba(255,92,108,.12); color: var(--danger); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; margin-bottom: 14px; display: none;
}
.auth-success {
  background: rgba(52,211,153,.12); color: var(--success); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; margin-bottom: 14px; text-align: center;
}
.auth-tabs {
  display: flex; gap: 0; margin-bottom: 22px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border);
}
.auth-tab {
  flex: 1; padding: 10px; background: transparent; border: none;
  color: var(--text-dim); font-size: 14px; font-family: inherit; cursor: pointer;
  transition: all .2s; font-weight: 600;
}
.auth-tab.active { background: var(--accent); color: #fff; }
.field-hint { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13.5px; color: var(--text-dim); }
.auth-switch a { color: var(--accent); font-weight: 600; text-decoration: none; }
/* صور الرسائل */
.msg-bubble img { max-width: 100%; max-height: 320px; border-radius: 10px; margin-top: 8px; display: block; object-fit: contain; }

/* ───────── Settings / Profile / Admin (shared page shell) ───────── */
.page-shell { width: 100%; height: 100vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page-topbar {
  height: 56px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  justify-content: space-between; padding: 0 20px; position: sticky; top: 0; background: var(--bg);
  z-index: 5;
}
.page-body { max-width: 820px; margin: 0 auto; padding: 28px 20px; }
.back-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 600; }

.settings-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
}
.settings-card h3 { margin-top: 0; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 0;
  border-top: 1px solid var(--border);
}
.setting-row:first-of-type { border-top: none; }
.theme-options, .accent-options { display: flex; gap: 8px; }
.theme-btn, .accent-dot {
  border: 1px solid var(--border); background: var(--bg-input); color: var(--text);
  padding: 8px 14px; border-radius: 10px; font-size: 13px;
}
.theme-btn.active { border-color: var(--accent); color: var(--accent); }
.accent-dot { width: 30px; height: 30px; border-radius: 50%; padding: 0; }
.accent-dot.active { outline: 2px solid var(--text); outline-offset: 2px; }
.settings-link-btn {
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: rgba(124,92,255,.1); border: 1px solid rgba(124,92,255,.25);
  padding: 6px 14px; border-radius: 9px; text-decoration: none;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.settings-link-btn:hover { background: rgba(124,92,255,.18); border-color: rgba(124,92,255,.5); }
.settings-logout-btn {
  font-size: 13px; font-weight: 600; color: #f87171;
  background: rgba(248,113,113,.08); border: 1px solid rgba(248,113,113,.22);
  padding: 6px 14px; border-radius: 9px; cursor: pointer; font-family: inherit;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.settings-logout-btn:hover { background: rgba(248,113,113,.16); border-color: rgba(248,113,113,.5); }
.settings-logout-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Stat cards for admin */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.stat-card .num { font-size: 24px; font-weight: 800; color: var(--accent); }
.stat-card .label { font-size: 12.5px; color: var(--text-dim); margin-top: 4px; }

table.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.admin-table th, table.admin-table td {
  padding: 10px; text-align: right; border-bottom: 1px solid var(--border);
}
table.admin-table th { color: var(--text-dim); font-weight: 600; }
.badge { padding: 3px 8px; border-radius: 20px; font-size: 11.5px; }
.badge.admin { background: rgba(124,92,255,.18); color: var(--accent); }
.badge.user { background: rgba(154,157,166,.15); color: var(--text-dim); }
.btn-danger { background: none; border: 1px solid var(--danger); color: var(--danger); border-radius: 8px; padding: 5px 10px; font-size: 12.5px; }

.loading-screen {
  position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; z-index: 999;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 13.5px; z-index: 1000;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}

/* ───────── نظام الإشعارات ───────── */
.notif-wrap {
  position: relative;
}

.notif-btn {
  position: relative;
  font-size: 20px;
}

.notif-badge {
  position: absolute;
  top: -2px;
  left: -2px;
  min-width: 16px;
  height: 16px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  pointer-events: none;
}

@keyframes notif-ring {
  0%   { transform: rotate(0deg); }
  15%  { transform: rotate(18deg); }
  30%  { transform: rotate(-16deg); }
  45%  { transform: rotate(12deg); }
  60%  { transform: rotate(-8deg); }
  75%  { transform: rotate(5deg); }
  100% { transform: rotate(0deg); }
}

.notif-btn.notif-ring {
  animation: notif-ring 0.9s ease;
  transform-origin: top center;
}

.notif-panel {
  position: fixed;
  top: 58px;
  left: 14px;
  width: min(300px, calc(100vw - 28px));
  max-height: min(400px, calc(100vh - 80px));
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  z-index: 300;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}

.notif-clear-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 8px;
  transition: background .15s;
}
.notif-clear-btn:hover { background: var(--border); color: var(--text); }

.notif-list {
  overflow-y: auto;
  flex: 1;
}

.notif-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 30px 16px;
}

.notif-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: rgba(255,255,255,.04); }

.notif-item-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.notif-item-body {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 5px;
  word-break: break-word;
}

.notif-item-time {
  font-size: 11px;
  color: var(--text-dim);
}

/* ───────── Responsive ───────── */
@media (max-width: 860px) {
  :root { --sidebar-w: 260px; }
  .sidebar {
    position: fixed; right: 0; top: 0; bottom: 0; z-index: 50;
    margin-right: calc(-1 * var(--sidebar-w));
    box-shadow: -10px 0 30px rgba(0,0,0,.3);
  }
  .sidebar.open { margin-right: 0; }
  .menu-toggle { display: flex; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .suggestions { grid-template-columns: 1fr; }
  .msg-bubble-wrap { max-width: 88%; }
}

/* ───────── Account Switcher — Settings Page ───────── */
.accsw-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  transition: background .14s, border-color .14s;
}
.accsw-item:hover { background: rgba(124,92,255,.06); border-color: rgba(124,92,255,.25); }
.accsw-item.active { background: rgba(124,92,255,.1); border-color: rgba(124,92,255,.35); }
.accsw-avatar {
  width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #4fd1ff);
  color: #fff; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.22);
}
.accsw-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 14px; }
.accsw-info { flex: 1; min-width: 0; }
.accsw-name { font-size: 14px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.accsw-username { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.accsw-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.accsw-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; color: var(--accent);
  background: rgba(124,92,255,.15); border-radius: 20px; padding: 3px 10px;
}
.accsw-switch-btn {
  font-size: 12.5px; font-weight: 600; font-family: inherit;
  color: var(--accent); background: rgba(124,92,255,.12);
  border: 1px solid rgba(124,92,255,.25); border-radius: 10px;
  padding: 5px 13px; cursor: pointer; transition: background .13s;
}
.accsw-switch-btn:hover { background: rgba(124,92,255,.22); }
.accsw-switch-btn:disabled { opacity: .5; cursor: not-allowed; }
.accsw-remove-btn {
  width: 30px; height: 30px; border-radius: 9px; border: none; flex-shrink: 0;
  background: transparent; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .13s, color .13s;
}
.accsw-remove-btn:hover { background: rgba(239,68,68,.12); color: #ef4444; }
.accsw-add-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px 14px; margin-top: 4px;
  border-radius: 12px; border: 1px dashed rgba(124,92,255,.35);
  background: rgba(124,92,255,.06); color: var(--accent);
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.accsw-add-btn:hover { background: rgba(124,92,255,.13); border-color: rgba(124,92,255,.55); }
