/* الوضع الفاتح (الأساسي/الافتراضي) — أبيض صافٍ مع الأزرق الكحلي الهادئ.
 *
 * كانت اللوحة كريمية دافئة (#f7f3ec). الحين الأسطح كلها أبيض خالص،
 * والفصل بينها يجي من الحدود مو من اختلاف الخلفيات.
 *
 * الرماديات هنا مايلة ميلًا خفيفًا جدًا للأزرق (مو رمادي محايد ميت) عشان
 * تنسجم مع لون العلامة وتبان مختارة لا افتراضية. */
:root {
  --bg-dark: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-input: #f4f5f7;
  /* فقاعة المستخدم: لمسة من لون العلامة عشان تنفصل عن الأبيض بوضوح */
  --bg-bubble-user: #eceff4;
  --bg-card: #ffffff;
  --bg-hover: #f1f3f6;
  --text-main: #1f2429;
  --text-muted: #6b7480;
  --accent: #4a6a87;
  --accent-soft: #4a6a871a;
  --accent-hover: #3f5a73;
  /* لون النص فوق اللون المميّز: أبيض على الأزرق الغامق في الوضع الفاتح،
     وداكن على الأزرق الفاتح في الوضع الداكن — الأبيض عليه ما يُقرأ */
  --on-accent: #ffffff;
  --border-color: #e5e8ec;
  --border-hover: #ccd2da;
  --danger: #b5544a;
  --danger-soft: rgba(181, 84, 74, 0.1);
  --danger-text: #8f342b;
  --overlay-soft: rgba(31, 36, 41, 0.05);
  --avatar-user-bg: #e2e7ee;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-soft: 0 2px 12px rgba(31, 36, 41, 0.07);
  --font-main: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  --font-heading: "El Messiri", var(--font-main);
}

/* الوضع الداكن — نفس الطابع الكلاسيكي الدافئ، بخلفية بنّية غامقة بدل الأزرق الداكن */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-dark: #2a221a;
    --bg-sidebar: #221b15;
    --bg-input: #362c21;
    --bg-bubble-user: #3e3226;
    --bg-card: #2f2720;
    --bg-hover: #372d22;
    --text-main: #f1e9df;
    --text-muted: #b3a48f;
    --accent: #9abad7;
    --accent-soft: #9abad724;
    --accent-hover: #b1c9e0;
    --on-accent: #1f2a33;
    --border-color: #423527;
    --border-hover: #56452f;
    --danger: #d9756a;
    --danger-soft: rgba(217, 117, 106, 0.14);
    --danger-text: #ffb3a8;
    --overlay-soft: rgba(255, 255, 255, 0.05);
    --avatar-user-bg: #453829;
    --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

[data-theme="dark"] {
  --bg-dark: #2a221a;
  --bg-sidebar: #221b15;
  --bg-input: #362c21;
  --bg-bubble-user: #3e3226;
  --bg-card: #2f2720;
  --bg-hover: #372d22;
  --text-main: #f1e9df;
  --text-muted: #b3a48f;
  --accent: #9abad7;
  --accent-soft: #9abad724;
  --accent-hover: #b1c9e0;
  --on-accent: #1f2a33;
  --border-color: #423527;
  --border-hover: #56452f;
  --danger: #d9756a;
  --danger-soft: rgba(217, 117, 106, 0.14);
  --danger-text: #ffb3a8;
  --overlay-soft: rgba(255, 255, 255, 0.05);
  --avatar-user-bg: #453829;
  --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-main);
  background: var(--bg-dark);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
  /* حماية عامة من أي عنصر يفيض بعرضه عن الشاشة بالغلط (زي مشكلة شبكة
     الأدوات وجدول لوحة التحكم بالجوال) - ما يمنع أي تمرير أفقي مقصود
     داخل عنصر عنده overflow-x:auto خاص فيه */
  overflow-x: hidden;
}

/* ---------- شريط التمرير (نحيف وهادي بدل الشريط العريض الافتراضي) ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-hover) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 8px;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.hidden {
  display: none !important;
}

.theme-toggle {
  position: fixed;
  top: 16px;
  inset-inline-start: 16px;
  z-index: 100;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

.theme-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

::selection {
  background: var(--accent-soft);
}

/* ---------- شاشة تسجيل الدخول ---------- */
.auth-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  padding: 20px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 44px 36px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  animation: fadeInUp 0.4s ease;
}

.auth-logo {
  width: 54px;
  height: 54px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

/* ---------- شعار الموقع (لوقو) ----------
   لو حطيتِ ملف اسمه logo.png داخل مجلد public/ بيظهر تلقائيًا مكان حرف "د"
   في شاشة الدخول وفي الشريط الجانبي. لو الملف مو موجود يرجع الحرف عادي. */
.logo-slot {
  position: relative;
  overflow: hidden;
}

.logo-slot .logo-img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.logo-slot.has-logo {
  border-color: transparent;
}

.logo-slot.has-logo .logo-img {
  display: block;
}

.logo-slot.has-logo .logo-letter {
  display: none;
}

.auth-title {
  margin: 0 0 4px;
  font-family: var(--font-heading);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.auth-subtitle {
  margin: 0 0 28px;
  color: var(--text-muted);
  font-size: 14px;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  background: var(--bg-input);
  border-radius: 12px;
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  transition: 0.2s;
}

.auth-tab.active {
  background: var(--accent);
  color: var(--on-accent);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form input {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: 0.2s;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.gender-select {
  display: flex;
  gap: 8px;
}

.gender-option {
  flex: 1;
  padding: 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: 0.2s;
}

.gender-option:hover {
  border-color: var(--accent);
}

.gender-option.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-primary {
  padding: 13px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: 0.2s;
  margin-top: 4px;
}

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

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

.auth-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 4px 0 0;
}

.password-hint {
  color: var(--text-muted);
  font-size: 12px;
  margin: -6px 0 2px;
  text-align: start;
  transition: color 0.15s;
}

.password-hint.valid {
  color: #5a9e6f;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  margin-top: 6px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-btn:hover {
  color: var(--accent-hover);
}

.auth-note {
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.6;
  margin: 0 0 4px;
  text-align: start;
}

.credit-footer {
  margin-top: 22px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

/* اسم المطوّرة صار رابط واتساب — نخلّيه يبان قابلًا للضغط */
.credit-footer .credit-name,
.sidebar-credit .credit-name {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: 0.18s;
}

.credit-footer .credit-name:hover,
.sidebar-credit .credit-name:hover,
.credit-footer .credit-name:focus-visible,
.sidebar-credit .credit-name:focus-visible {
  color: var(--accent-hover);
  border-bottom-color: currentColor;
}

.credit-footer .credit-year {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  opacity: 0.8;
}

.sidebar-credit {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  padding-top: 10px;
  opacity: 0.85;
}

.sidebar-credit .credit-year {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  opacity: 0.8;
}

/* ---------- تطبيق الدردشة ---------- */
.app-screen {
  height: 100vh;
  display: flex;
}

.sidebar {
  width: 268px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  padding: 14px;
  border-inline-end: 1px solid var(--border-color);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
  /* زر تبديل المظهر ثابت بزاوية الشاشة وكان يغطي أيقونة/شعار الموقع،
     فنزيح صف الاسم شوي عن الحافة عشان الشعار يبان كامل */
  padding-inline-start: 50px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 18px;
}

.sidebar-collapse-btn {
  margin-inline-start: auto;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  color: var(--text-main);
  border-color: var(--border-hover);
}

.sidebar-collapse-btn svg {
  width: 15px;
  height: 15px;
  transform: scaleX(-1);
}

[dir="rtl"] .sidebar-collapse-btn svg {
  transform: none;
}

.sidebar-expand-btn {
  position: fixed;
  top: 64px;
  inset-inline-start: 16px;
  z-index: 20;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  display: flex;
}

.sidebar-expand-btn.hidden {
  display: none;
}

.sidebar-expand-btn svg {
  width: 15px;
  height: 15px;
  transform: scaleX(-1);
}

[dir="rtl"] .sidebar-expand-btn svg {
  transform: none;
}

@media (min-width: 701px) {
  .app-screen.sidebar-collapsed .sidebar {
    display: none;
  }
}

@media (max-width: 700px) {
  .sidebar-collapse-btn,
  .sidebar-expand-btn {
    display: none !important;
  }
}

.sidebar-brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.3px solid var(--accent);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  margin-bottom: 14px;
  transition: 0.2s;
}

.new-chat-btn span {
  font-size: 16px;
  color: var(--accent);
}

.new-chat-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.new-chat-btn:active {
  transform: scale(0.97);
}

.sidebar-search {
  position: relative;
  margin-bottom: 10px;
}

.sidebar-search svg {
  position: absolute;
  top: 50%;
  inset-inline-start: 11px;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.sidebar-search input {
  width: 100%;
  padding: 9px 12px 9px 12px;
  padding-inline-start: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: 0.2s;
}

.sidebar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.conversation-list-hint {
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 10px 12px;
  text-align: center;
}

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  gap: 8px;
  transition: 0.15s;
}

.conversation-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.conversation-item.active {
  background: var(--accent-soft);
  color: var(--text-main);
}

.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conversation-item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: 0.15s;
}

.conversation-item:hover .conversation-item-actions {
  opacity: 1;
}

.conv-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 3px;
  border-radius: 5px;
}

.conv-action-btn:hover {
  background: var(--overlay-soft);
  color: var(--text-main);
}

.conv-action-btn.share-conv-btn.active {
  color: var(--accent);
}

.conv-action-btn:hover.delete-conv-btn,
.delete-conv-btn:hover {
  color: var(--danger);
}

.delete-conv-btn svg,
.share-conv-btn svg,
.attachment-chip .remove-chip svg {
  width: 12px;
  height: 12px;
}

/* ---------- بطاقات الأدوات الجاهزة (تظهر مع الشاشة الفارغة) ---------- */
.tool-shortcuts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  max-width: 560px;
  margin: 24px auto 0;
  text-align: start;
}

.tool-shortcut-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  font-family: inherit;
  text-align: start;
  transition: 0.2s;
}

.tool-shortcut-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tool-shortcut-card:active {
  transform: scale(0.98);
}

.tool-shortcut-card svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.tool-shortcut-card .tool-shortcut-title {
  font-weight: 700;
  font-size: 13.5px;
}

.tool-shortcut-card .tool-shortcut-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.conversation-item:hover .delete-conv-btn {
  opacity: 1;
}

.delete-conv-btn:hover {
  color: var(--danger);
}

.sidebar-tools {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
  margin-top: 4px;
}

.tool-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: 0.2s;
}

.tool-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

#bg-reset-btn svg {
  width: 13px;
  height: 13px;
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-hover);
}

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

.tool-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.tool-group-label {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 2px;
  margin-top: 2px;
}

.collapsible-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.2s;
}

.collapsible-toggle:hover {
  color: var(--text-main);
}

.collapsible-toggle .chevron-icon {
  width: 14px;
  height: 14px;
  transition: transform 0.2s;
}

.collapsible-toggle.open .chevron-icon {
  transform: rotate(180deg);
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-group.hidden {
  display: none;
}

#bg-reset-btn {
  flex: 0 0 auto;
  min-width: 0;
  width: 34px;
}

.sidebar-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 12px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.current-username {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: 0.15s;
}

.logout-btn:hover {
  color: var(--danger);
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  /* dvh يتعامل صح مع شريط متصفح الجوال اللي يظهر ويختفي (والآيفون خصوصًا) */
  height: 100dvh;
  background: var(--bg-dark);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  min-width: 0;
}

/* طبقة تعتيم فوق الخلفية المخصصة: تعتيم أقوى + ضباب خفيف، عشان الكلام
   والبطاقات تبقى مقروءة مهما كانت الصورة مزدحمة بالتفاصيل */
.chat-main.has-custom-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg-dark);
  opacity: 0.82;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  pointer-events: none;
  z-index: 0;
}

.chat-main.has-custom-bg > * {
  position: relative;
  z-index: 1;
}

/* فوق خلفية مخصصة نخلي البطاقات ومربع الكتابة معتمين تمامًا (مو شفافين)
   عشان ما تتداخل تفاصيل الصورة مع النص */
.chat-main.has-custom-bg .tool-shortcut-card,
.chat-main.has-custom-bg .message-form {
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
}

.chat-main.has-custom-bg .empty-state h2,
.chat-main.has-custom-bg .empty-state p {
  color: var(--text-main);
}

/* منطقة الرسائل: المحتوى يظل بعرض 820 بكسل بالنص، لكن الحاوية نفسها
   بعرض الصفحة كامل - عشان شريط التمرير يطلع على حافة الصفحة بدل ما
   يطفو بنص الشاشة (كان قبل max-width + margin auto فيبان الشريط داخلي) */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px max(24px, calc((100% - 820px) / 2));
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 100%;
}

.messages-loading {
  margin: auto;
  color: var(--text-muted);
  font-size: 13.5px;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.empty-state-icon svg {
  width: 22px;
  height: 22px;
}

.empty-state h2 {
  color: var(--text-main);
  font-family: var(--font-heading);
  font-size: 21px;
  font-weight: 700;
  margin: 0 0 6px;
}

.message-row {
  display: flex;
  gap: 12px;
  max-width: 100%;
  min-width: 0;
  animation: fadeInUp 0.25s ease;
}

.message-row.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.avatar svg {
  width: 16px;
  height: 16px;
}

.avatar.user {
  background: var(--avatar-user-bg);
  color: var(--text-muted);
}

.avatar.assistant {
  background: var(--accent);
}

.avatar-mark {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

.bubble {
  padding: 13px 17px;
  border-radius: var(--radius-md);
  line-height: 1.75;
  font-size: 15px;
  white-space: pre-wrap;
  unicode-bidi: plaintext;

  /* الفقاعة عنصر داخل flex، وقيمته الافتراضية min-width:auto تمنعه من
     الانكماش تحت عرض أطول كلمة فيه. فلو لصقت المستخدمة رابطًا طويلًا
     بدون مسافات، يتمدّد الكلام خارج الفقاعة وخارج الشاشة.
     min-width:0 يسمح بالانكماش، و overflow-wrap:anywhere يكسر الرابط. */
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* الروابط والأكواد داخل الردود: تنكسر بدل ما تمدّ الصفحة */
.bubble a {
  overflow-wrap: anywhere;
}

.bubble pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
}

.bubble :not(pre) > code {
  overflow-wrap: anywhere;
}

/* ---------- ردود المساعد المنسّقة (Markdown + معادلات) ----------
   الفقاعة نفسها pre-wrap عشان رسائل المستخدم تحفظ أسطرها. الرد المنسّق
   يبني فقراته وأسطره بنفسه، فلو خلّينا pre-wrap عليه تتضاعف المسافات. */
.md {
  white-space: normal;
}

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }

/* كل فقرة تحدّد اتجاهها من أول حرف فيها — فقرة إنجليزية بنص رد عربي
   تنعرض من اليسار، بدون ما نكتشف اللغة يدويًا */
.md p,
.md li,
.md h1,
.md h2,
.md h3,
.md h4 {
  unicode-bidi: plaintext;
}

.md p { margin: 0 0 0.7em; }

.md h1,
.md h2,
.md h3,
.md h4 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.45;
  margin: 1.1em 0 0.45em;
  color: var(--text-main);
}
.md h1 { font-size: 1.3em; }
.md h2 { font-size: 1.18em; }
.md h3 { font-size: 1.07em; }
.md h4 { font-size: 1em; }

.md ul,
.md ol {
  margin: 0 0 0.7em;
  padding-inline-start: 1.4em;
}
.md li { margin: 0.22em 0; }
.md li > p { margin: 0; }
.md li::marker { color: var(--text-muted); }

.md hr {
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 1.1em 0;
}

.md blockquote {
  margin: 0 0 0.7em;
  padding: 0.15em 1em;
  border-inline-start: 3px solid var(--border-color);
  color: var(--text-muted);
}

.md strong { font-weight: 700; }

.md a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* الكود دايمًا من اليسار لليمين، حتى داخل فقرة عربية */
.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--bg-input);
  padding: 0.12em 0.38em;
  border-radius: 5px;
  direction: ltr;
  unicode-bidi: isolate;
}

.md pre {
  background: var(--bg-input);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin: 0 0 0.8em;
  direction: ltr;
  text-align: left;
}

.md pre code {
  background: none;
  padding: 0;
  font-size: 0.86em;
}

.md-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 0 0 0.8em;
}

.md table {
  border-collapse: collapse;
  font-size: 0.94em;
}

.md th,
.md td {
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  text-align: start;
  vertical-align: top;
}

.md th {
  background: var(--bg-input);
  font-weight: 700;
}

/* المعادلات: معزولة الاتجاه — بدون العزل، المتصفح داخل فقرة عربية يقلب
   «2 × 3» إلى «3 × 2» ويبعثر الرموز، وهذا اللي كان يطلع بالردود */
.math-inline {
  direction: ltr;
  unicode-bidi: isolate;
}

.math-display {
  direction: ltr;
  text-align: center;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0.6em 0 0.9em;
  padding: 4px 0;
}

/* الفقاعة تكسر الكلمات الطويلة عشان الروابط — بس لو ورّثنا هذا للمعادلة
   تنكسر المصفوفة من نصّها */
.bubble .katex {
  font-size: 1.08em;
  overflow-wrap: normal;
  word-break: normal;
}

.stopped-note {
  margin-top: 0.6em;
  font-size: 0.88em;
  color: var(--text-muted);
}

.message-row.user .bubble {
  background: var(--bg-bubble-user);
}

.message-row.assistant .bubble {
  background: transparent;
  padding-right: 0;
  padding-left: 0;
}

.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: 0.15s;
}

.message-row:hover .msg-actions {
  opacity: 1;
}

.msg-action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 12px;
  font-family: inherit;
  transition: 0.15s;
}

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

.msg-action-btn svg {
  width: 12px;
  height: 12px;
}

.msg-action-btn.favorite-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}

.msg-action-btn.favorite-btn.active svg {
  fill: var(--accent);
}

.export-wrap {
  position: relative;
}

.msg-actions:has(.export-menu:not(.hidden)) {
  opacity: 1;
}

.export-menu {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-end: 0;
  z-index: 20;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-soft);
  padding: 4px;
  display: flex;
  flex-direction: column;
  min-width: 130px;
}

.export-menu a {
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text-main);
  text-decoration: none;
  white-space: nowrap;
}

.export-menu a:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.thinking-status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.thinking-status .typing-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-inline-end: 3px;
  background: var(--accent);
  border-radius: 50%;
  animation: blink 1.4s infinite both;
}

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

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

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

.message-form {
  display: flex;
  gap: 10px;
  /* المساحة الآمنة تحت: عشان مربع الكتابة ما يختفي وراء شريط الآيفون السفلي */
  padding: 14px 24px calc(22px + env(safe-area-inset-bottom, 0px));
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- شريط "ما فيه إنترنت" ---------- */
.offline-banner {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  inset-inline: 16px;
  z-index: 30;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger-text);
  border: 1px solid var(--danger);
  font-size: 12.5px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}

/* ---------- تعديلات تخص تطبيق الجوال الأصلي فقط ----------
   html.is-native-app تنضاف من native.js لما يكون التطبيق مفتوح من الآيفون */
.is-native-app .theme-toggle {
  top: calc(16px + env(safe-area-inset-top, 0px));
}

.is-native-app .sidebar {
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
}

.is-native-app .messages {
  padding-top: calc(28px + env(safe-area-inset-top, 0px));
}

/* بالتطبيق الأصلي ما فيه فائدة من تلميح "اضغطي أيقونة الإرفاق" لأن فيه زر
   كاميرا واضح، فنخلي المساحة للمحتوى */
.is-native-app .input-hint {
  display: none;
}

.message-form textarea {
  flex: 1;
  resize: none;
  max-height: 200px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: 0.2s;
}

.message-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.attach-btn {
  width: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  cursor: pointer;
  transition: 0.2s;
}

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

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

/* وضع الصوت: الزر يبان مفعّل بوضوح عشان تعرف إنه شغّال */
.attach-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.attach-btn .tool-icon {
  display: flex;
}

.attach-btn .tool-icon svg {
  width: 18px;
  height: 18px;
}

/* شريط فوق مربع الكتابة يقول إن الوضع شغّال وكيف توقفينه */
.voice-mode-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 24px 8px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 12.5px;
  line-height: 1.6;
}

.voice-mode-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.voice-mode-bar.is-speaking .voice-mode-dot {
  animation: voiceDot 1.1s ease-in-out infinite;
}

@keyframes voiceDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.6); opacity: 0.45; }
}

#voice-mode-text {
  flex: 1;
  min-width: 0;
}

.voice-mode-off {
  flex: 0 0 auto;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: 0.2s;
}

.voice-mode-off:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-card);
}

@media (max-width: 560px) {
  .voice-mode-bar {
    margin: 0 14px 8px;
  }
}

#mic-btn.listening {
  color: var(--danger);
  border-color: var(--danger);
  animation: micPulse 1.4s infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--danger-soft); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

.attachment-preview {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  max-width: 260px;
}

.attachment-chip img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 6px;
}

.attachment-chip .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip .remove-chip {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
}

.attachment-chip .remove-chip:hover {
  color: var(--danger);
}

.message-attachment-image {
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--radius-md);
  display: block;
  margin-bottom: 8px;
}

.message-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--overlay-soft);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  margin-bottom: 8px;
}

.generated-image {
  max-width: 100%;
  max-height: 420px;
  border-radius: var(--radius-md);
  display: block;
  box-shadow: var(--shadow-soft);
}

.image-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 13px;
  text-decoration: none;
  transition: 0.2s;
}

.image-download-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.image-download-btn svg {
  width: 13px;
  height: 13px;
}

.attachment-chip svg,
.message-attachment-file svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.message-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.send-btn {
  width: 50px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.send-btn:hover {
  background: var(--accent-hover);
}

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

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}

.send-btn.stop-mode {
  background: var(--danger);
}

.send-btn.stop-mode:hover {
  filter: brightness(1.1);
}

.stop-icon {
  width: 13px;
  height: 13px;
  background: white;
  border-radius: 3px;
  display: inline-block;
}

.error-banner {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger-text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  max-width: 820px;
  margin: 0 auto;
}

.input-hint {
  max-width: 820px;
  width: 100%;
  margin: -8px auto 0;
  padding: 0 24px 14px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

.input-hint code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
}

.sidebar-toggle-btn {
  display: none;
  position: fixed;
  top: 14px;
  inset-inline-end: 16px;
  z-index: 60;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle-btn svg {
  width: 17px;
  height: 17px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9;
}

.sidebar-overlay:not(.hidden) {
  display: block;
}

@media (max-width: 700px) {
  .sidebar-toggle-btn {
    display: flex;
  }
  .theme-toggle.hidden-by-sidebar {
    display: none;
  }
  .sidebar {
    position: fixed;
    z-index: 10;
    top: 0;
    bottom: 0;
    height: 100vh;
    transform: translateX(100%);
    transition: 0.2s;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.3);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .messages {
    padding: 24px 14px 16px;
  }
  .tool-shortcuts {
    /* auto-fit مع minmax(150px..) كان يفيض عن عرض شاشة الجوال (يسوي ٣
       أعمدة بعرض ١٥٠px كل وحد حتى لو الشاشة أضيق من ذلك) - نثبتها عمودين
       متساويين يتماشيان مع أي عرض شاشة */
    grid-template-columns: 1fr 1fr;
  }
  .message-form {
    padding: 12px 14px 18px;
    gap: 8px;
  }
  .attachment-preview,
  .input-hint {
    padding-left: 14px;
    padding-right: 14px;
  }
  .send-btn,
  .attach-btn {
    width: 42px;
  }
  .auth-card {
    padding: 32px 22px;
  }
  .theme-toggle {
    top: 12px;
    width: 34px;
    height: 34px;
    font-size: 13px;
  }
  .modal-card {
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 100px);
  }
}

/* ---------- نوافذ منبثقة (المفضلة، رابط المشاركة) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 22px;
  width: 100%;
  max-width: 480px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}

.modal-card-sm {
  max-width: 420px;
}

.modal-card-preview {
  max-width: 900px;
  width: 100%;
  height: 80vh;
  max-height: 80vh;
}

/* ---------- زر فتح الإعدادات + نافذة الإعدادات ---------- */
.settings-entry-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: 0.2s;
}

.settings-entry-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-hover);
}

.settings-entry-btn svg {
  width: 17px;
  height: 17px;
}

.modal-card-settings {
  max-width: 460px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.settings-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.settings-section-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.settings-full-btn {
  display: flex;
  width: 100%;
  margin-top: 6px;
}

.current-plan-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text-main);
  font-size: 13px;
}

.current-plan-box strong {
  color: var(--accent);
}

.current-plan-expiry {
  color: var(--text-muted);
  font-size: 12px;
}

.settings-whatsapp-btn {
  color: #25b263;
  border-color: #25b26355;
  text-decoration: none;
}

.settings-whatsapp-btn:hover {
  background: #25b26314;
  border-color: #25b263;
  color: #25b263;
}

.settings-whatsapp-btn svg {
  width: 17px;
  height: 17px;
}

#settings-admin-section:has(.hidden) {
  display: none;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.website-preview-frame {
  flex: 1;
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #fff;
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  padding: 4px;
  border-radius: 6px;
}

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

.modal-close-btn svg {
  width: 14px;
  height: 14px;
}

/* ---------- لوحة أداة مخصصة (تفتح لمّا نضغطين بطاقة أداة بالشاشة الفارغة) ---------- */
.tool-panel-desc {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  margin: -6px 0 14px;
}

.tool-panel-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.tool-panel-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-panel-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
}

.tool-panel-field input,
.tool-panel-field textarea,
.tool-panel-field select {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: 0.2s;
  resize: vertical;
}

.tool-panel-field textarea {
  min-height: 80px;
}

.tool-panel-field input:focus,
.tool-panel-field textarea:focus,
.tool-panel-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.tool-panel-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tool-panel-file-btn {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.2s;
}

.tool-panel-file-btn:hover {
  border-color: var(--accent);
}

.tool-panel-file-name {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.favorites-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.favorite-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  transition: 0.15s;
}

.favorite-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.favorite-item .favorite-snippet {
  font-size: 13.5px;
  color: var(--text-main);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.favorites-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
  padding: 30px 10px;
}

.share-link-row {
  display: flex;
  gap: 8px;
  margin: 14px 0 10px;
}

.share-link-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 13px;
  font-family: inherit;
}

.share-link-row .btn-primary {
  width: auto;
  padding: 10px 16px;
  margin-top: 0;
}

/* ---------- حجم الخط (لكبار السن وضعاف البصر) ----------
   المستخدمة تختار الحجم من الإعدادات، ونحفظه بمتصفحها. نكبّر النصوص اللي
   تُقرأ فعلًا (الردود، مربع الكتابة، القوائم) ونترك الأيقونات والأزرار
   الصغيرة على حالها عشان التصميم ما ينهار. */
:root {
  --text-scale: 1;
}

html[data-fontsize='large'] {
  --text-scale: 1.15;
}

html[data-fontsize='xlarge'] {
  --text-scale: 1.35;
}

html[data-fontsize='xxlarge'] {
  --text-scale: 1.6;
}

.bubble {
  font-size: calc(15px * var(--text-scale));
}

.message-form textarea {
  font-size: calc(15px * var(--text-scale));
  /* لازم يكبر ارتفاع المربع مع الخط، وإلا انقص النص المكتوب فيه */
  min-height: calc(50px * var(--text-scale));
}

.input-hint {
  font-size: calc(12px * var(--text-scale));
}

/* بالأحجام الكبيرة الأزرار الأربعة تخنق مربع الكتابة على شاشة الجوال، فننقل
   المربع لسطر كامل لحاله والأزرار تحته - بدل ما ينقص النص */
html[data-fontsize='xlarge'] .message-form,
html[data-fontsize='xxlarge'] .message-form {
  flex-wrap: wrap;
}

html[data-fontsize='xlarge'] .message-form textarea,
html[data-fontsize='xxlarge'] .message-form textarea {
  flex: 1 1 100%;
  order: -1;
}

.conversation-item {
  font-size: calc(14px * var(--text-scale));
}

.empty-state h2 {
  font-size: calc(21px * var(--text-scale));
}

.tool-shortcut-card .tool-shortcut-title {
  font-size: calc(13.5px * var(--text-scale));
}

.tool-shortcut-card .tool-shortcut-desc {
  font-size: calc(12px * var(--text-scale));
}

.tool-btn,
.settings-entry-btn {
  font-size: calc(13px * var(--text-scale));
}

.current-plan-box {
  font-size: calc(13px * var(--text-scale));
}

/* صفوف اختيار حجم الخط داخل الإعدادات */
.fontsize-row {
  display: flex;
  gap: 8px;
}

.fontsize-btn {
  flex: 1;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s;
  line-height: 1.2;
}

.fontsize-btn:hover {
  border-color: var(--border-hover);
}

.fontsize-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* حرف "أ" بأحجام متدرجة يوضّح كل خيار بالنظر بدون قراءة */
.fontsize-btn .fontsize-sample {
  display: block;
  font-family: var(--font-heading);
}

.fontsize-btn[data-size='normal'] .fontsize-sample {
  font-size: 15px;
}

.fontsize-btn[data-size='large'] .fontsize-sample {
  font-size: 19px;
}

.fontsize-btn[data-size='xlarge'] .fontsize-sample {
  font-size: 23px;
}

.fontsize-btn[data-size='xxlarge'] .fontsize-sample {
  font-size: 27px;
}

.fontsize-btn .fontsize-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2px;
}

.fontsize-btn.active .fontsize-label {
  color: var(--accent);
}

/* ---------- رسالة تنبيه صغيرة تحت مربع الكتابة (أخطاء المايك مثلًا) ---------- */
.inline-notice {
  margin: 0 24px 10px;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger-text);
  border: 1px solid var(--danger);
  font-size: 12.5px;
  line-height: 1.6;
  text-align: center;
}

/* ---------- عدّاد الرسائل المتبقية اليوم ---------- */
.usage-meter {
  margin: 0 24px 8px;
  font-size: calc(12px * var(--text-scale));
  color: var(--text-muted);
  text-align: center;
}

.usage-meter.is-low {
  color: var(--danger-text);
  font-weight: 500;
}

.usage-meter a {
  color: var(--accent);
  font-weight: 500;
}

/* ---------- خانة إدخال رمز التحقق ---------- */
.code-input {
  text-align: center;
  letter-spacing: 0.5em;
  font-size: 22px !important;
  font-weight: 700;
  direction: ltr;
  padding-inline-start: 0.5em !important;
}

/* ---------- نافذة التأكيد ---------- */
.confirm-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.confirm-actions .tool-btn,
.confirm-actions .btn-danger {
  flex: 1;
  justify-content: center;
}

.btn-danger {
  padding: 11px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--danger);
  color: #fff;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s;
}

.btn-danger:hover {
  filter: brightness(0.93);
}

/* ---------- صف البريد الإلكتروني بالإعدادات ---------- */
.email-row {
  display: flex;
  gap: 8px;
}

.email-row input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-family: inherit;
  font-size: calc(13px * var(--text-scale));
  outline: none;
}

.email-row input:focus {
  border-color: var(--accent);
}

.email-row .btn-primary {
  margin-top: 0;
  padding: 11px 18px;
  font-size: 13.5px;
  flex-shrink: 0;
}

.settings-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 8px 0 0;
  line-height: 1.6;
}

.settings-hint.is-ok { color: var(--accent); }
.settings-hint.is-error { color: var(--danger-text); }

/* ملاحظة صغيرة تحت نموذج التسجيل */
.auth-note-sm {
  font-size: 12px;
  margin-top: 4px;
  margin-bottom: 0;
}

/* رابط باهت لخيارات نادرة الاستخدام (دخول الطوارئ) */
.link-btn-faint {
  opacity: 0.55;
  font-size: 12px;
}

.link-btn-faint:hover {
  opacity: 1;
}

/* ==========================================================================
   روابط الصفحات القانونية داخل التطبيق
   (نستخدم em بدل px عشان تكبر تلقائيًا مع إعداد "حجم الخط" بالإعدادات)
   ========================================================================== */

.auth-legal-links {
  margin: 14px 0 0;
  font-size: 0.8em;
  line-height: 1.8;
  color: var(--text-muted);
  text-align: center;
}

.auth-legal-links a {
  color: var(--accent);
  text-decoration: none;
}

.auth-legal-links a:hover {
  text-decoration: underline;
}

.legal-links-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.legal-links-row a {
  font-size: 0.88em;
  color: var(--text-muted);
  text-decoration: none;
  padding: 2px 0;
}

.legal-links-row a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ==========================================================================
   شريط "ضيفي سم Ai لشاشتك" (PWA)
   ========================================================================== */

.pwa-bar {
  position: fixed;
  z-index: 9000;
  inset-inline: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  transform: translateY(140%);
  opacity: 0;
  transition: transform 0.32s ease, opacity 0.32s ease;
}

.pwa-bar.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.pwa-bar-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  overflow: hidden;
  flex-shrink: 0;
}

.pwa-bar-icon img {
  width: 100%;
  height: 100%;
  display: block;
}

.pwa-bar-text {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.55;
}

.pwa-bar-text strong {
  display: block;
  font-size: 0.94em;
  font-weight: 700;
  color: var(--text-main);
}

.pwa-bar-text span {
  display: block;
  font-size: 0.8em;
  color: var(--text-muted);
}

.pwa-share-icon {
  display: inline-block;
  color: var(--accent);
  font-weight: 700;
}

.pwa-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pwa-bar-btn {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-family: inherit;
  font-size: 0.86em;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.pwa-bar-btn:hover { background: var(--accent-hover); }

.pwa-bar-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1em;
  line-height: 1;
  padding: 7px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.pwa-bar-close:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

@media (max-width: 400px) {
  .pwa-bar { gap: 9px; padding: 10px 11px; }
  .pwa-bar-icon { width: 36px; height: 36px; }
  .pwa-bar-btn { padding: 8px 12px; }
}

/* ==========================================================================
   شريط تنبيه قرب انتهاء الباقة
   (em بدل px عشان يكبر مع إعداد "حجم الخط" بالإعدادات)
   ========================================================================== */

.plan-banner {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  inset-inline: 16px;
  z-index: 29;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text-main);
  border: 1px solid var(--accent);
  box-shadow: var(--shadow-soft);
}

.plan-banner-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.85em;
  line-height: 1.6;
}

.plan-banner-btn {
  flex-shrink: 0;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.8em;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.plan-banner-btn:hover { background: var(--accent-hover); }

.plan-banner-close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.85em;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.plan-banner-close:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

/* آخر يومين: نرفع درجة الإلحاح بصريًا */
.plan-banner.is-urgent {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger-text);
}

.plan-banner.is-urgent .plan-banner-btn {
  background: var(--danger);
}

.plan-banner.is-urgent .plan-banner-close {
  color: var(--danger-text);
}

@media (max-width: 460px) {
  .plan-banner { gap: 7px; padding: 8px 10px; }
  .plan-banner-btn { padding: 6px 10px; }
}

/* ---------- سلسلة الأيام المتتالية (الاستريك) ----------
   تظهر تحت زر "محادثة جديدة". لها ثلاث حالات:
   عادية (كلّمه اليوم)، ومهدّدة (ما كلّمه اليوم بعد)، ولحظة الزيادة. */
/* هادئة عن قصد: بلا خلفية ولا إطار ولا لون صارخ. سطر صغير يشبه
   بقية عناصر الشريط الجانبي، لا شارة ملوّنة تصرخ في وجه المستخدم. */
.streak-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 12px 2px 2px;
  padding: 2px 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

/* اللهب مرسوم بخط رفيع بنفس لون النص، مثل باقي أيقونات الشريط */
.streak-flame {
  width: 17px;
  height: 17px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linejoin: round;
}

.streak-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.streak-text b {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text-main);
}

.streak-note {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* على وشك الانقطاع: اللهب وحده يدفأ لونه. تنبيه بلا إزعاج. */
.streak-chip.at-risk {
  color: #a86a45;
}

[data-theme="dark"] .streak-chip.at-risk,
:root:not([data-theme="light"]) .streak-chip.at-risk {
  color: #c08a62;
}

/* لحظة زيادة السلسلة: نبضة قصيرة وحدة */
.streak-chip.just-grew {
  animation: streakPop 0.55s ease;
}

.streak-chip.just-grew .streak-flame {
  animation: streakFlame 0.55s ease;
}

@keyframes streakPop {
  0%   { opacity: 1; }
  40%  { opacity: 0.45; }
  100% { opacity: 1; }
}

@keyframes streakFlame {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .streak-chip.just-grew,
  .streak-chip.just-grew .streak-flame {
    animation: none;
  }
}

/* ---------- بطاقة السلسلة اليومية (بنص الشاشة) ----------
   تطلع مرة وحدة في اليوم بعد أول رسالة، وفيها جملة تحفيز مولّدة لليوم.
   لما يسكّرها المستخدم تنكمش نحو الشعلة في الشريط الجانبي عشان يعرف
   وين مكانها الدائم — بدل ما تختفي فجأة. */
.streak-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(31, 36, 41, 0.32);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: streakVeil 0.25s ease;
}

[data-theme="dark"] .streak-modal,
:root:not([data-theme="light"]) .streak-modal {
  background: rgba(0, 0, 0, 0.45);
}

.streak-modal-card {
  width: 100%;
  max-width: 340px;
  padding: 30px 26px 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  box-shadow: 0 18px 50px rgba(31, 36, 41, 0.18);
  text-align: center;
  transform-origin: center;
  animation: streakCardIn 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.streak-modal-flame {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.5;
  stroke-linejoin: round;
  margin-bottom: 14px;
  animation: streakFlame 0.7s 0.15s ease both;
}

/* ---------- الشعار ببطاقة السلسلة ----------
   الشعار بالنص وكبير، والشعلة صارت شارة صغيرة على طرفه. */
.streak-modal-hero {
  position: relative;
  width: 88px;
  height: 88px;
  margin: 0 auto 16px;
}

.streak-modal-logo {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 8px 24px rgba(31, 36, 41, 0.18);
  animation: streakLogoIn 0.6s 0.05s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.streak-modal-badge {
  position: absolute;
  bottom: -2px;
  inset-inline-end: -4px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-card);
  box-shadow: 0 2px 8px rgba(31, 36, 41, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* الشعلة داخل الشارة: أصغر، بلون العلامة، وبلا الهامش السفلي القديم */
.streak-modal-badge .streak-modal-flame {
  width: 19px;
  height: 19px;
  margin: 0;
  stroke: var(--accent);
}

/* انقطعت السلسلة: الشعار يبهت للرمادي — نفس الشعار، بس «مطفي» */
.streak-modal-card.is-lost .streak-modal-logo {
  filter: grayscale(1);
  opacity: 0.55;
  animation: none;
}

@keyframes streakLogoIn {
  from { opacity: 0; transform: scale(0.86); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .streak-modal-logo { animation: none; }
}

/* حالة الانقطاع: نفس البطاقة بشعلة خامدة — لون أفتح، خط أرق،
   وبلا حركة الاشتعال. الفرق بصري بحت، بلا أي نبرة عتاب. */
.streak-modal-card.is-lost .streak-modal-flame {
  stroke: var(--border-color);
  stroke-width: 1.2;
  opacity: 0.75;
  animation: none;
}

.streak-modal-card.is-lost .streak-modal-count {
  color: var(--text-muted);
  font-size: 20px;
}

.streak-modal-count {
  margin: 0 0 10px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 23px;
  color: var(--text-main);
}

.streak-modal-msg {
  margin: 0 0 22px;
  font-size: 14.5px;
  line-height: 1.85;
  color: var(--text-muted);
  text-wrap: balance;
}

.streak-modal-btn {
  width: 100%;
  margin: 0;
}

/* الانكماش نحو الشعلة: الإزاحة تُحسب بالجافاسكربت وتُحقن كمتغيّرات */
.streak-modal.is-closing {
  animation: streakVeilOut 0.42s ease forwards;
  pointer-events: none;
}

.streak-modal.is-closing .streak-modal-card {
  animation: streakCardToChip 0.42s cubic-bezier(0.5, 0, 0.75, 0.3) forwards;
}

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

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

@keyframes streakCardIn {
  from { opacity: 0; transform: scale(0.88) translateY(14px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes streakCardToChip {
  from { opacity: 1; transform: translate(0, 0) scale(1); }
  to {
    opacity: 0;
    transform: translate(var(--streak-dx, 0px), var(--streak-dy, 0px)) scale(0.18);
  }
}

@media (prefers-reduced-motion: reduce) {
  .streak-modal,
  .streak-modal-card,
  .streak-modal-flame,
  .streak-modal.is-closing,
  .streak-modal.is-closing .streak-modal-card {
    animation: none;
  }
  .streak-modal.is-closing { opacity: 0; }
}

@media (max-width: 480px) {
  .streak-modal-card { padding: 26px 20px 20px; }
  .streak-modal-count { font-size: 21px; }
}

/* ---------- طبقة سحب الملفات ----------
   تغطي الشاشة كلها عشان ترمين الملف بأي مكان، مو بمربّع صغير. */
.drop-zone {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay-soft);
  backdrop-filter: blur(2px);
  /* ما تستقبل أحداث الفأرة — وإلا صارت هي هدف الإفلات وما وصل الحدث للنافذة */
  pointer-events: none;
}

.drop-zone.hidden { display: none; }

.drop-zone-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 36px 52px;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--accent);
  background: var(--bg-card);
  box-shadow: 0 18px 50px rgba(31, 36, 41, 0.18);
  color: var(--accent);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 17px;
}

.drop-zone-card svg { width: 34px; height: 34px; }
