/* ثيم مريح للعين — ألوان هادئة (مثل الصورة) */
:root {
  --bg-primary: #1a1b2e;
  --bg-secondary: #252636;
  --bg-card: rgba(44, 45, 58, 0.95);
  --bg-card-hover: rgba(52, 54, 70, 0.98);
  --accent: #6b8db4;
  --accent-soft: rgba(107, 141, 180, 0.2);
  --accent-glow: rgba(107, 141, 180, 0.25);
  --accent-hover: #7d9fc4;
  --gold: #c9a227;
  --gold-soft: rgba(201, 162, 39, 0.15);
  --text: #d8dce8;
  --text-muted: #9ca3b8;
  --success: #6b9b7a;
  --danger: #c75c5c;
  --border: rgba(255, 255, 255, 0.06);
  --shadow: 0 8px 28px rgba(0,0,0,0.25);
  --shadow-card: 0 4px 16px rgba(0,0,0,0.2);
  --radius: 12px;
  --radius-lg: 16px;
  --font-ar: "Tajawal", "Segoe UI", sans-serif;
  --font-heading: "Tajawal", var(--font-ar);
  --glass-bg: rgba(26, 27, 46, 0.9);
  --glass-blur: 24px;
  --line-height: 1.65;
  --gradient-primary: linear-gradient(135deg, #6b8db4 0%, #7d9fc4 40%, #8aadce 70%, #6b8db4 100%);
  --gradient-hero: linear-gradient(135deg, #d8dce8 0%, #a8b8d0 45%, #6b8db4 100%);
  --gradient-card-edge: linear-gradient(180deg, transparent 0%, rgba(107, 141, 180, 0.3) 50%, transparent 100%);
  --gradient-btn: linear-gradient(135deg, #6b8db4 0%, #7d9fc4 50%, #6b8db4 100%);
  --gradient-btn-hover: linear-gradient(135deg, #7d9fc4 0%, #8aadce 50%, #7d9fc4 100%);
  --gradient-icon-wrap: linear-gradient(145deg, rgba(107, 141, 180, 0.3) 0%, rgba(125, 159, 196, 0.18) 100%);
  --gradient-premium: linear-gradient(135deg, #c9a227 0%, #d4b03d 50%, #c9a227 100%);
}

[data-theme="light"] {
  --bg-primary: #f0f2f6;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.95);
  --bg-card-hover: #ffffff;
  --accent: #5a7a9a;
  --accent-soft: rgba(90, 122, 154, 0.12);
  --accent-glow: rgba(90, 122, 154, 0.15);
  --accent-hover: #6b8db4;
  --gold: #a68520;
  --gold-soft: rgba(166, 133, 32, 0.1);
  --text: #2d3142;
  --text-muted: #6b7280;
  --border: rgba(0, 0, 0, 0.07);
  --shadow: 0 8px 24px rgba(0,0,0,0.06);
  --shadow-card: 0 2px 12px rgba(0,0,0,0.04);
  --glass-bg: rgba(255, 255, 255, 0.92);
  --gradient-hero: linear-gradient(135deg, #2d3142 0%, #5a7a9a 50%, #6b8db4 100%);
  --gradient-btn: linear-gradient(135deg, #5a7a9a 0%, #6b8db4 100%);
  --gradient-btn-hover: linear-gradient(135deg, #6b8db4 0%, #7d9fc4 100%);
  --gradient-icon-wrap: linear-gradient(145deg, rgba(90, 122, 154, 0.2) 0%, rgba(107, 141, 180, 0.12) 100%);
  --gradient-premium: linear-gradient(135deg, #a68520 0%, #c9a227 100%);
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-ar);
  font-size: 1rem;
  line-height: var(--line-height);
  margin: 0;
  background: var(--bg-primary);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.4s ease;
}

/* خلفية هادئة بأسلوب أكاديمي — تدرج خفيف بدون حركة */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: 
    linear-gradient(165deg, var(--bg-primary) 0%, var(--bg-secondary) 45%, var(--bg-primary) 100%),
    radial-gradient(ellipse 80% 50% at 50% 0%, var(--accent-soft), transparent 55%);
  pointer-events: none;
  z-index: 0;
}
[data-theme="light"] body::before {
  background: 
    linear-gradient(165deg, var(--bg-primary) 0%, #fff 40%, #f0f4f8 100%),
    radial-gradient(ellipse 70% 40% at 50% 0%, var(--accent-soft), transparent 50%);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  z-index: 10;
}

.main-header {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
  padding-top: max(8px, env(safe-area-inset-top, 8px));
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}

@media (max-width: 600px) {
  .main-header { padding: 6px 0; padding-top: max(6px, env(safe-area-inset-top, 6px)); }
  .header-inner { padding: 0 10px; min-height: 44px; }
  .user-info { display: flex !important; align-items: flex-end; }
  .user-name { display: none; }
  .points-balance { margin-right: 0; }
  .brand-text { font-size: 1.25rem !important; }
  .action-buttons { gap: 8px; }
  .btn-icon-text { padding: 8px 10px; font-size: 0.85rem; }
  .btn-qr { padding: 8px 10px; min-width: auto; font-size: 0.85rem; }
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  font-size: 1.5rem;
  line-height: 1;
  opacity: 0.95;
}

.brand-and-plan {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.brand-text {
  font-size: 1.4rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.subscription-type-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.2;
}
.subscription-type-label.premium {
  color: var(--accent);
}
.subscription-type-label.free {
  color: var(--text-muted);
}
.subscription-type-label.support-link-wrap {
  font-size: 0.75rem;
  font-weight: 600;
}
.subscription-type-label.support-link {
  color: #25d366;
  text-decoration: none;
  border-bottom: 1px solid rgba(37, 211, 102, 0.4);
}
.subscription-type-label.support-link:hover {
  color: #20bd5a;
  border-bottom-color: #25d366;
}

.points-balance {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  margin-right: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.95rem;
}
/* أكثر من 25 نقطة — أخضر */
.points-balance.points-green {
  background: rgba(107, 155, 122, 0.25);
  color: var(--success);
}
/* هذا النمط لم يعد مستخدماً بعد توحيد الأرصدة الأقل من 25 إلى الأحمر */
.points-balance.points-yellow {
  background: rgba(201, 162, 39, 0.25);
  color: var(--gold);
}
/* 25 نقطة أو أقل — أحمر */
.points-balance.points-empty {
  background: rgba(199, 92, 92, 0.15);
  color: var(--danger);
}

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

.user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.user-name {
  font-size: 0.9rem;
  font-weight: 600;
}

#userBadge {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.points-last-tx {
  max-width: 240px;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--text-muted);
  text-align: right;
}

#userBadge.premium {
  background: var(--gradient-premium);
  color: #fff;
  box-shadow: 0 2px 8px rgba(184, 134, 11, 0.3);
}

.action-buttons {
  display: flex;
  gap: 10px;
}

.btn-icon-text, .btn-upgrade, .btn-icon-only {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: 0.2s;
  font-weight: 600;
}

.btn-qr {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(107, 141, 180, 0.28);
  background: rgba(107, 141, 180, 0.14);
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-qr:hover {
  background: rgba(107, 141, 180, 0.22);
  box-shadow: 0 4px 14px rgba(107, 141, 180, 0.18);
}

.btn-qr:active {
  transform: scale(0.985);
}

.inline-image-preview {
  margin-top: 12px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.inline-image-preview-title {
  margin-bottom: 10px;
  font-weight: 800;
  color: var(--text);
}

.inline-image-preview-empty {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.btn-upgrade,
a.btn-upgrade {
  background: linear-gradient(135deg, #0ea5e9 0%, #38bdf8 50%, #0ea5e9 100%);
  color: #fff !important;
  border: none;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.5);
  cursor: pointer;
  pointer-events: auto;
  text-decoration: none;
  display: inline-block;
}
.btn-upgrade:hover {
  background: linear-gradient(135deg, #0284c7 0%, #0ea5e9 50%, #0284c7 100%);
  opacity: 1;
  color: #fff !important;
  box-shadow: 0 6px 20px rgba(14, 165, 233, 0.6);
}

.btn-support {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid rgba(37, 211, 102, 0.4);
  background: rgba(37, 211, 102, 0.15);
  color: #25d366;
  text-decoration: none;
  margin-left: 8px;
}
.btn-support:hover {
  background: rgba(37, 211, 102, 0.25);
  color: #20bd5a;
  border-color: rgba(37, 211, 102, 0.6);
}

.subscription-dropdown-wrap {
  position: relative;
  display: inline-block;
  z-index: 150;
}
.subscription-dropdown-wrap .btn-upgrade {
  position: relative;
  z-index: 151;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}
.subscription-plan-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  min-width: 280px;
  z-index: 200;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.subscription-dropdown-wrap.open .subscription-plan-dropdown {
  display: flex;
  flex-direction: column;
}
.subscription-plan-option {
  background: linear-gradient(135deg, #0ea5e9 0%, #38bdf8 50%, #0ea5e9 100%);
  color: #fff !important;
  border: none;
  padding: 12px 14px;
  font-weight: 700;
  font-size: 0.9rem;
  text-align: right;
  cursor: pointer;
  transition: 0.2s;
  font-family: var(--font-ar);
  border-bottom: 1px solid rgba(255,255,255,0.2);
}
.subscription-plan-option:last-child {
  border-bottom: none;
}
.subscription-plan-option:hover {
  background: linear-gradient(135deg, #0284c7 0%, #0ea5e9 50%, #0284c7 100%);
  opacity: 1;
}

.btn-icon-text:hover, .btn-icon-only:hover {
  background: var(--bg-card-hover);
}
/* --- لوحة التحكم — تدرجات احترافية --- */
.dashboard-hero {
  text-align: center;
  margin-bottom: 48px;
  padding: 32px 16px 24px;
  position: relative;
}

.dashboard-hero h1 {
  font-size: 1.95rem;
  font-weight: 700;
  margin: 0 0 14px;
  letter-spacing: -0.02em;
  line-height: 1.35;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--text);
}

.dashboard-hero p {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin: 0 auto;
  max-width: 520px;
  line-height: 1.6;
}

.dashboard-hero::after {
  content: "";
  display: block;
  width: 80px;
  height: 4px;
  margin: 20px auto 0;
  border-radius: 2px;
  background: var(--gradient-btn);
  opacity: 0.9;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}
#cardsGrid {
  pointer-events: auto;
  cursor: default;
}
#cardsGrid .card {
  cursor: pointer;
  pointer-events: auto;
}

.card {
  position: relative;
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: inherit;
  text-align: right;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.25s ease, box-shadow 0.3s ease, transform 0.25s ease;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  color: inherit;
  margin: 0;
}
button.card,
a.card {
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  text-decoration: none;
  color: inherit;
  border: none;
  font: inherit;
  text-align: right;
}
a.card:hover { color: inherit; }
button.card:focus-visible,
a.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* شريط تدرج جانبي احترافي */
.card::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
  background: var(--gradient-primary);
  border-radius: 0 12px 12px 0;
  opacity: 0.95;
}

.card:hover {
  transform: translateY(-5px);
  background: var(--bg-card-hover);
  box-shadow: 0 12px 40px rgba(107, 141, 180, 0.2), 0 0 0 1px rgba(107, 141, 180, 0.12);
}

.card:active {
  transform: translateY(-1px) scale(0.995);
  background: var(--bg-card-hover);
  box-shadow: inset 0 1px 6px rgba(0, 0, 0, 0.14), 0 4px 12px rgba(107, 141, 180, 0.12);
}

.card:hover::before {
  opacity: 1;
  width: 5px;
  box-shadow: 0 0 20px rgba(107, 141, 180, 0.4);
}

.card:active::before {
  opacity: 1;
  width: 4px;
  box-shadow: 0 0 8px rgba(107, 141, 180, 0.2);
}

@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr; gap: 15px; }
  .card { padding: 24px !important; }
  .dashboard-hero h1 { font-size: 1.8rem !important; }
  .card-icon-wrap { font-size: 2.5rem !important; }
}
.card.locked { opacity: 0.8; filter: grayscale(0.4); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.card .card-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border-radius: 14px;
  background: var(--gradient-icon-wrap);
  border: 1px solid rgba(107, 141, 180, 0.3);
  margin-bottom: 18px;
  color: var(--accent);
  box-shadow: 0 4px 12px rgba(107, 141, 180, 0.2);
  transition: box-shadow 0.25s ease, transform 0.2s ease;
}

.card:hover .card-icon-wrap {
  box-shadow: 0 6px 20px rgba(107, 141, 180, 0.3);
  transform: scale(1.05);
}

.card:active .card-icon-wrap {
  transform: scale(0.995);
  box-shadow: 0 2px 8px rgba(107, 141, 180, 0.14);
}
.card .icon { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.card .title { font-weight: 700; font-size: 1.15rem; color: var(--text); margin-bottom: 8px; letter-spacing: -0.01em; }
.card .sub { font-size: 0.9rem; color: var(--text-muted); line-height: 1.6; }
.lock-badge { 
  display: inline-block;
  margin-top: 14px;
  padding: 5px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Smart Omnibox (Command Palette) */
.omnibox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  animation: fadeIn 0.2s ease;
}

.omnibox {
  background: var(--bg-card);
  width: 100%;
  max-width: 640px;
  border-radius: 20px;
  box-shadow: 0 30px 60px rgba(0,0,0,0.4), 0 0 0 1px var(--border);
  overflow: hidden;
  transform: translateY(0);
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDown {
  from { transform: translateY(-30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.omnibox-header {
  display: flex;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.omnibox-icon {
  font-size: 1.5rem;
  margin-left: 14px;
  color: var(--accent);
}

#omniboxInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
  font-family: inherit;
  outline: none;
}
#omniboxInput::placeholder { color: var(--text-muted); }

.omnibox-close {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.omnibox-close:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.omnibox-results {
  padding: 12px;
  max-height: 400px;
  overflow-y: auto;
}

.omnibox-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s;
}
.omnibox-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.omnibox-item .icon { font-size: 1.5rem; }
.omnibox-item .text { font-size: 1.1rem; font-weight: 600; }
.omnibox-item .query-text { color: var(--accent); }

/* Floating Copilot — زر بتدرج احترافي */
.floating-copilot {
  position: fixed;
  bottom: 30px;
  left: 30px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--gradient-btn);
  border: 2px solid rgba(255,255,255,0.15);
  box-shadow: 0 8px 24px rgba(107, 141, 180, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 900;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.floating-copilot:hover {
  background: var(--gradient-btn-hover);
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 12px 32px rgba(107, 141, 180, 0.4);
}

.floating-copilot .sparkle {
  font-size: 1.8rem;
  line-height: 1;
}


/* Theme Button Adaptation for Sidebar */
.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: right;
  width: 100%;
  transition: background 0.2s;
}
.theme-toggle:hover { background: var(--bg-card-hover); border-color: var(--accent); }

.btn-logout {
  background: rgba(244, 63, 94, 0.1);
  color: var(--danger);
  border: 1px solid rgba(244, 63, 94, 0.2);
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: right;
  width: 100%;
  transition: all 0.2s;
}
.btn-logout:hover { background: var(--danger); color: #fff; }

/* Responsive adjustments for Dashboard */
@media (max-width: 768px) {
  #appScreen { flex-direction: column; height: 100vh; height: 100dvh; }
  .sidebar {
    width: 100%;
    height: auto;
    border-left: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    background: var(--bg-card);
    position: relative;
    z-index: 100;
  }
  .sidebar-brand { margin-bottom: 12px; justify-content: center; transform: scale(0.9); }
  .sidebar-nav { flex-direction: row; flex-wrap: nowrap; justify-content: space-around; gap: 4px; overflow-x: auto; }
  .sidebar-nav .nav-item { 
    flex-direction: column; 
    padding: 10px 8px; 
    font-size: 0.75rem; 
    gap: 4px; 
    min-width: 70px;
  }
  .sidebar-nav .nav-item .text { display: none; } /* الغاء الكلمات من فوق كما طلب المستخدم */
  .sidebar-nav .nav-item .icon svg { width: 24px; height: 24px; }

  .sidebar-footer { display: none; } /* اخفاء الفوتر في الموبايل لتوفير مساحة */
  .search-trigger { width: 100%; margin: 10px 0; }
  
  .main-content { height: calc(100vh - 80px); height: calc(100dvh - 80px); }
}


/* فصل الشاشات: الدخول/التسجيل ثم الرئيسية — كل شاشة ملء النافذة */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  min-height: 100vh;
  overflow: auto;
  transition: opacity 0.28s ease;
}
.screen.active { display: block; }
.screen.screen-leave { opacity: 0; pointer-events: none; }
.screen.active.screen-enter { animation: screenEnter 0.32s ease forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes screenEnter { from { opacity: 0; } to { opacity: 1; } }

/* الشاشة الرئيسية: هيدر ثابت + محتوى قابل للتمرير */
#appScreen.screen {
  flex-direction: column;
  background: var(--bg-primary);
}
#appScreen.screen.active {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}
#appScreen.screen.active {
  pointer-events: auto;
}
#appScreen.screen.active main {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  pointer-events: auto;
}
#appScreen.screen.active #cardsGrid,
#appScreen.screen.active #viewDashboard {
  pointer-events: auto;
}
#appScreen.screen.active .main-header,
#appScreen.screen.active .action-buttons button,
#appScreen.screen.active .btn-icon-only,
#appScreen.screen.active .btn-icon-text,
#appScreen.screen.active .btn-upgrade {
  pointer-events: auto;
  cursor: pointer;
}

/* شاشة الدخول — مظهر أكاديمي هادئ */
#authScreen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  height: 100%;
  padding: 24px;
  box-sizing: border-box;
  background: var(--bg-primary);
  background-image: radial-gradient(ellipse 100% 60% at 50% 0%, var(--accent-soft), transparent 60%);
}
[data-theme="light"] #authScreen.active {
  background: var(--bg-primary);
  background-image: radial-gradient(ellipse 100% 50% at 50% 0%, var(--accent-soft), transparent 55%);
}
[data-theme="ios"] #authScreen.active {
  background: var(--bg-primary);
  background-image: radial-gradient(ellipse 100% 50% at 50% 0%, var(--accent-soft), transparent 55%);
}

.auth-box {
  position: relative;
  z-index: 11;
  margin: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
}
.auth-box .auth-tagline {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 6px 0 24px;
  font-weight: 500;
  text-align: center;
}
html[data-theme="ios"] .auth-box {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
}
.auth-box h2 { margin: 0; color: var(--text); text-align: center; font-weight: 700; font-size: 1.35rem; }
.auth-box input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--bg-primary);
  color: var(--text);
  transition: border-color 0.2s;
}
.auth-box input:focus { outline: none; border-color: var(--accent); }
.auth-box input::placeholder { color: var(--text-muted); }
.auth-box button[type="button"]:not(.auth-switch button) {
  width: 100%;
  padding: 14px;
  background: var(--gradient-btn);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(107, 141, 180, 0.3);
  transition: box-shadow 0.2s, transform 0.02s, opacity 0.2s;
}
.auth-box button[type="button"]:not(.auth-switch button):hover {
  opacity: 0.95;
  box-shadow: 0 6px 20px rgba(107, 141, 180, 0.4);
}
.auth-box button[type="button"]:not(.auth-switch button):active { transform: scale(0.99); }

.auth-switch { text-align: center; margin: 18px 0 0; }
.auth-switch button,
.auth-switch-btn {
  width: 100%;
  padding: 13px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text);
  transition: background 0.2s, border-color 0.2s;
  text-decoration: none;
  display: block;
  box-sizing: border-box;
}
.auth-switch button:hover,
.auth-switch-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  color: var(--accent);
}
[data-theme="light"] .auth-switch button,
[data-theme="light"] .auth-switch-btn { background: var(--bg-secondary); color: var(--text); }

/* المودال */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: auto;
}
.modal.show { display: flex; animation: fadeIn 0.25s ease; }
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow), 0 0 0 1px var(--border);
  box-sizing: border-box;
}
.modal-box h3 { margin: 0 0 18px; color: var(--text); font-weight: 700; font-size: 1.2rem; }
.modal-box textarea {
  width: 100%;
  min-height: 120px;
  max-height: 35vh;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  resize: vertical;
  background: var(--bg-primary);
  color: var(--text);
}
@media (max-width: 768px) {
  .modal-box textarea { min-height: 100px; font-size: 16px; }
}
.modal-box textarea:focus { outline: none; border-color: var(--accent); }
.modal-box .result {
  margin-top: 18px;
  padding: 18px;
  background: var(--bg-primary);
  border-radius: 12px;
  white-space: pre-wrap;
  text-align: right;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}
.modal-box .actions { margin-top: 18px; display: flex; gap: 10px; justify-content: flex-end; }
.modal-box button { padding: 12px 22px; border-radius: 10px; border: none; cursor: pointer; font-weight: 600; font-family: inherit; }
.modal-box .btn-primary {
  background: var(--gradient-btn);
  color: #fff;
  box-shadow: 0 4px 14px rgba(107, 141, 180, 0.25);
  transition: opacity 0.2s, box-shadow 0.2s;
}
.modal-box .btn-primary:hover { opacity: 0.95; box-shadow: 0 6px 18px rgba(107, 141, 180, 0.35); }
.modal-box .btn-primary:disabled { opacity: 0.6; cursor: not-allowed; box-shadow: none; }
.modal-box .btn-secondary { background: var(--bg-primary); color: var(--text); border: 1px solid var(--border); }
.modal-box .btn-close-red,
.actions .btn-close-red { color: #dc2626 !important; border-color: #dc2626 !important; }
.modal-box .btn-close-red:hover,
.actions .btn-close-red:hover { background: rgba(220, 38, 38, 0.1) !important; }

/* التوست */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 16px 24px;
  border-radius: 12px;
  display: none;
  z-index: 10002;
  box-shadow: var(--shadow);
  font-weight: 500;
}
.outline-inline-error {
  width: 100%;
  margin-bottom: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 500;
}
/* تمييز حقل المجال/الموضوع عند ترك الحقل فارغاً عند إنشاء الهيكلية */
.research-field-error,
.research-field-error input {
  background: rgba(239, 68, 68, 0.15) !important;
  border-color: rgba(239, 68, 68, 0.5);
}
label.research-field-error { border-radius: 8px; padding: 2px 4px; }
.toast.show { display: block; animation: slideIn 0.35s ease; }
.toast.err { border-color: var(--danger); background: rgba(244, 63, 94, 0.18); color: #fff; }
.toast.ok { border-color: var(--success); background: rgba(45, 212, 191, 0.15); color: var(--text); }
.toast .toast-icon { margin-left: 8px; font-size: 1.1em; }

/* شريط التقدم للعمليات الطويلة */
.progress-wrap {
  width: 100%;
  height: 6px;
  background: var(--bg-primary);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
}
.progress-bar {
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 999px;
  animation: progressIndeterminate 1.8s ease-in-out infinite;
}
@keyframes progressIndeterminate {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(280%); }
  100% { transform: translateX(-100%); }
}
.progress-text { margin: 0; color: var(--text-muted); font-size: 0.95rem; }

/* هيكل التحميل (Skeleton) */
.skeleton-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
.skeleton-card .skeleton-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(90deg, var(--bg-card-hover) 25%, var(--border) 50%, var(--bg-card-hover) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.2s ease-in-out infinite;
  margin: 0 auto 12px;
}
.skeleton-card .skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--bg-card-hover) 25%, var(--border) 50%, var(--bg-card-hover) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.2s ease-in-out infinite;
  margin: 8px auto;
  max-width: 80%;
}
.skeleton-card .skeleton-line.short { max-width: 50%; }
@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* صندوق تنبيه للرسائل */
.alert-box {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--danger);
  background: rgba(244, 63, 94, 0.1);
  color: var(--text);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-box .alert-icon { color: var(--danger); font-size: 1.2rem; }
.alert-box.ok { border-color: var(--success); background: rgba(45, 212, 191, 0.12); }
.alert-box.ok .alert-icon { color: var(--success); }

/* منبثق إضافة للشاشة الرئيسية */
.pwa-prompt {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 190;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pwa-prompt-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.pwa-prompt-icon {
  text-align: center;
  margin-bottom: 16px;
}
.pwa-prompt-icon img {
  width: 72px;
  height: 72px;
  border-radius: 16px;
}
.pwa-prompt-title {
  margin: 0 0 10px;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  text-align: center;
}
.pwa-prompt-desc {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.55;
  font-size: 0.95rem;
}
.pwa-prompt-how { margin: 0 0 20px; padding: 14px; background: var(--bg-primary); border-radius: 12px; border: 1px solid var(--border); }
.pwa-prompt-how-title { margin: 0 0 10px; font-size: 0.9rem; font-weight: 700; color: var(--text); }
.pwa-prompt-steps { margin: 0 0 12px; }
.pwa-prompt-steps:last-child { margin-bottom: 0; }
.pwa-prompt-steps strong { display: block; margin-bottom: 6px; font-size: 0.85rem; color: var(--accent); }
.pwa-prompt-steps ol { margin: 0; padding-right: 20px; color: var(--text); font-size: 0.9rem; line-height: 1.6; }
.pwa-prompt-actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.pwa-prompt-actions button {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  font-size: 1rem;
}
#pwaPromptOk { background: var(--accent); color: #fff; }
#pwaPromptLater { background: var(--bg-primary); color: var(--text); border: 1px solid var(--border); }

/* عارض PDF كامل داخل التطبيق (من الصفحة الأولى إلى الأخيرة) */
.pdf-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 12px;
}
.pdf-viewer-box {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 960px;
  max-height: 98vh;
  overflow: hidden;
}
.pdf-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pdf-viewer-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text);
  font-weight: 700;
}
.pdf-viewer-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.pdf-viewer-close:hover {
  background: var(--accent);
  color: #fff;
}
.pdf-viewer-frame-wrap {
  flex: 1;
  min-height: 0;
  padding: 12px;
}
.pdf-viewer-frame {
  width: 100%;
  height: 100%;
  min-height: 70vh;
  border: none;
  border-radius: 10px;
  background: #525659;
}

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

.loading { opacity: 0.7; pointer-events: none; }

/* المحادثة الاحترافية المتقدمة */
.chat-container-advanced {
  display: flex;
  gap: 16px;
  height: 600px;
  max-height: 70vh;
}

.chat-sidebar {
  width: 220px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  padding: 14px;
  flex-shrink: 0;
}

.new-chat-btn {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  font-weight: 700;
  margin-bottom: 14px;
  background: linear-gradient(145deg, var(--accent) 0%, rgba(180, 45, 65, 0.95) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
}

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

.chat-history-item {
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid transparent;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-history-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-soft);
}
.chat-history-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.chat-history-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  font-size: 1rem;
}
.chat-history-delete:hover { color: var(--danger); }

.chat-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 14px;
  position: relative;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-msg {
  padding: 14px 18px;
  border-radius: 14px;
  max-width: 85%;
  line-height: 1.6;
  font-size: 0.95rem;
  word-break: break-word;
}
.chat-msg.user { 
  align-self: flex-start; /* Because of RTL, flex-start is right */
  background: linear-gradient(135deg, var(--accent), #4f46e5); 
  color: #fff; 
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
  align-self: flex-end; /* Left side */
  background: var(--bg-card-hover); 
  color: var(--text); 
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* markdown styles inside chat */
.chat-msg.assistant table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.chat-msg.assistant th, .chat-msg.assistant td { border: 1px solid var(--border); padding: 8px; }
.chat-msg.assistant pre { background: var(--bg-primary); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 10px 0;}
.chat-msg.assistant code { font-family: monospace; color: var(--gold); }

.chat-input-wrapper {
  display: flex;
  gap: 10px;
  padding: 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  position: relative;
}

.voice-btn {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s;
}
.voice-btn:hover { background: var(--bg-card-hover); color: var(--accent); }
.voice-btn.recording {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  border-color: var(--danger);
  animation: pulseGlow 1.5s infinite;
}

.chat-input-wrapper input {
  flex: 1;
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 1rem;
  background: var(--bg-primary);
  color: var(--text);
  transition: border-color 0.2s;
}
.chat-input-wrapper input:focus { outline: none; border-color: var(--accent); }

.chat-send-btn { 
  padding: 0 24px; 
  background: var(--accent); 
  color: #fff; 
  border: none; 
  border-radius: 24px; 
  font-weight: 700; 
  cursor: pointer; 
  transition: opacity 0.2s;
}
.chat-send-btn:hover { opacity: 0.9; }

.chat-typing-indicator {
  position: absolute;
  bottom: 85px;
  right: 20px;
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  backdrop-filter: blur(4px);
}

.modal-box.chat-box { max-width: 900px; width: 95vw; padding: 20px; }

@media (max-width: 768px) {
  .chat-container-advanced { flex-direction: column; height: 80vh; }
  .chat-sidebar { width: 100%; height: 120px; flex-direction: row; align-items: center; gap: 10px; overflow-x: auto; padding: 10px; }
  .new-chat-btn { width: auto; margin: 0; white-space: nowrap; }
  .chat-history-list { flex-direction: row; gap: 6px; }
  .chat-history-item { white-space: nowrap; max-width: 150px; }
}


/* —— Word: محرر مستندات احترافي (شكل Word) —— */
.modal-box.editor-modal {
  max-width: 920px;
  max-height: 95vh;
  overflow: auto;
  padding: 16px;
}
.word-online-wrap {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 420px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
.word-online-ribbon {
  background: linear-gradient(180deg, #2b579a 0%, #1e3a5f 100%);
  border: none;
  border-radius: 0;
  overflow: hidden;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
}
.word-ribbon-brand {
  display: flex;
  align-items: center;
  padding: 0 20px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  font-family: 'Segoe UI', var(--font-ar), sans-serif;
  border-right: 1px solid rgba(255,255,255,0.15);
  direction: ltr;
}
.word-online-tabs {
  display: flex;
  gap: 0;
  padding: 0 8px;
  background: transparent;
  border-bottom: none;
}
.word-online-tab {
  padding: 12px 18px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.9);
  font-weight: 600;
  font-size: 14px;
  font-family: var(--font-ar), sans-serif;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: 0;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.word-online-tab:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
}
.word-online-tab.active {
  color: #fff;
  background: rgba(255,255,255,0.15);
  border-bottom-color: #fff;
}
.word-online-toolbar {
  width: 100%;
  padding: 12px 16px;
  border-radius: 0;
  border: none;
  border-top: 1px solid rgba(255,255,255,0.08);
  min-height: 52px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}
.word-ribbon-panel {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.word-ribbon-panel.active {
  display: flex;
}
.word-online-doc-area {
  background: #d1d5db;
  margin-top: 0;
  padding: 28px;
  border: none;
  border-top: 1px solid #e5e7eb;
  border-radius: 0;
  min-height: 360px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.word-online-page {
  background: #fff;
  width: 100%;
  max-width: 21cm;
  margin: 0 auto;
  padding: 28px 40px;
  border-radius: 0;
  box-shadow: 0 4px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.08);
  border: 1px solid #e2e8f0;
  min-height: 420px;
}
.word-page {
  background: var(--bg-primary);
  margin-top: 14px;
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.modal-box.editor-modal .word-online-page .editor-area-label {
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 6px;
}
.modal-box.editor-modal .word-online-page .word-editor-content,
.modal-box.editor-modal .word-online-page #wordEditorContent {
  border: none;
  border-radius: 0;
  box-shadow: none;
  min-height: 380px;
  height: 420px;
}
.modal-box.editor-modal .word-online-page #wordEditorContent:focus {
  box-shadow: none;
  outline: none;
  border: none;
}
.editor-area-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 10px;
  direction: rtl;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.editor-area-label:hover { color: #475569; }

/* شريط أدوات احترافي */
.word-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #f8f9fa 0%, #f1f3f5 100%);
  border: 1px solid #dee2e6;
  border-radius: 10px 10px 0 0;
  min-height: 50px;
  border-bottom: 2px solid #ced4da;
}
.word-tb-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  border-left: 1px solid #dee2e6;
}
.word-tb-group:first-child { border-left: none; padding-left: 0; }
.word-tb-btn {
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-ar), 'Tajawal', sans-serif;
  background: #fff;
  color: #495057;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.word-tb-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.word-tb-select {
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font-ar), sans-serif;
  background: #fff;
  color: #212529;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  cursor: pointer;
  min-width: 95px;
}
.word-tb-color {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  cursor: pointer;
  background: #fff;
}
.word-tb-label { font-size: 11px; color: #6c757d; margin-right: 2px; }

/* صفحة الكتابة — تبدأ من الأعلى مثل Word، مظهر ورقة احترافية */
.word-editor-content,
#wordEditorContent {
  display: block;
  width: 100%;
  min-height: 420px;
  height: 480px;
  overflow-y: auto;
  padding: 32px 36px;
  font-family: var(--font-ar), 'Tajawal', sans-serif;
  font-size: 18px;
  line-height: 1.95;
  direction: rtl;
  text-align: right;
  background: #fff !important;
  color: #212529 !important;
  border: 1px solid #ced4da;
  border-top: none;
  border-radius: 0 0 10px 10px;
  outline: none;
  cursor: text;
  box-sizing: border-box;
  position: relative;
  z-index: 0;
  -webkit-user-select: text;
  user-select: text;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04), 0 4px 14px rgba(0,0,0,0.08);
  vertical-align: top;
}
#wordEditorContent:empty::before {
  content: attr(data-placeholder);
  color: #adb5bd;
}
#wordEditorContent br { display: inline; }
#wordEditorContent p {
  margin: 0 0 0.75em 0;
  min-height: 1.2em;
  text-align: inherit;
}
#wordEditorContent p:first-child { margin-top: 0; }
#wordEditorContent:focus {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04), 0 0 0 3px rgba(233,69,96,0.2);
}
.word-page .ql-editor table.word-table td { background: #fff; }
.word-page .ql-editor table.word-table td:focus { outline: 2px solid rgba(233,69,96,0.35); }

/* فواصل الصفحات + ترقيم داخل المحرر — خلف النص حتى لا يخفى ما يكتب */
.page-overlay{
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}
.page-break-line{
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px dashed rgba(0,0,0,0.10);
}
.page-num-chip{
  position: absolute;
  left: 16px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(0,0,0,0.06);
  color: rgba(0,0,0,0.65);
}

.page-header-chip{
  position: absolute;
  right: 20px;
  left: 20px;
  font-size: 12px;
  color: rgba(0,0,0,0.55);
  text-align: right;
  direction: rtl;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-footer-chip{
  position: absolute;
  right: 20px;
  left: 20px;
  font-size: 12px;
  color: rgba(0,0,0,0.55);
  text-align: right;
  direction: rtl;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#wordEditorContent img { max-width: 100%; height: auto; display: block; margin: 10px auto; }
#wordEditorContent table,
.word-page .ql-editor table.word-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
#wordEditorContent table td,
#wordEditorContent table th,
.word-page .ql-editor table.word-table td, 
.word-page .ql-editor table.word-table th { border: 1px solid #cbd5e1; padding: 10px; vertical-align: top; }
#wordEditorContent table td { min-width: 70px; }
.word-page mark { background: rgba(240,180,41,0.25); }

/* —— Ruler + draggable margins —— */
.ruler-wrap{ margin-top: 12px; }
.ruler-head{ display:flex; justify-content:space-between; align-items:center; gap:10px; flex-wrap:wrap; color: var(--text-muted); font-weight:800; font-size:0.85rem; }
.ruler{
  position: relative;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background:
    linear-gradient(to right, rgba(0,0,0,0.08) 1px, transparent 1px) 0 0 / calc(100%/21) 100%,
    linear-gradient(to right, rgba(0,0,0,0.14) 1px, transparent 1px) 0 0 / calc(100%/7) 100%;
  background-color: var(--bg-primary);
  overflow: hidden;
}
.ruler .tick-label{
  position:absolute;
  top: 8px;
  font-size: 11px;
  color: rgba(0,0,0,0.45);
  user-select:none;
}
.ruler .marker{
  position:absolute;
  top: 0;
  width: 18px;
  height: 100%;
  cursor: ew-resize;
  user-select:none;
  display:flex;
  align-items:flex-start;
  justify-content:center;
}
.ruler .marker::before{
  content:'';
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 12px solid var(--accent);
  margin-top: 2px;
}
.ruler .marker span{
  position:absolute;
  bottom: 6px;
  font-size: 11px;
  font-weight: 800;
  color: rgba(0,0,0,0.65);
}
.ruler .shade{
  position:absolute;
  top:0; bottom:0;
  background: rgba(233,69,96,0.08);
  pointer-events:none;
}
.word-bar {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* —— Diff preview (Track changes lite) —— */
.diff-box{
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  line-height: 1.9;
  white-space: pre-wrap;
  max-height: 320px;
  overflow: auto;
}
.diff-ins{ background: rgba(45, 212, 191, 0.22); padding: 0 2px; border-radius: 4px; text-decoration: none; }
.diff-del{ background: rgba(244, 63, 94, 0.20); padding: 0 2px; border-radius: 4px; text-decoration: line-through; }
.diff-eq{ color: inherit; }

/* صف مقفل في خطة الأقسام */
tr.plan-row-locked { background: rgba(148, 163, 184, 0.08); opacity: 0.92; }

/* تقرير فحص الانتحال */
.plag-report { max-height: 70vh; overflow-y: auto; }
.plag-gauge-wrap { padding: 10px 0; }
.plag-source-card { transition: border-color 0.2s, background 0.2s; }
.plag-source-card:hover { border-color: var(--accent); background: rgba(233, 69, 96, 0.06); }
.plag-source-card a { text-decoration: none; }
.plag-source-card a:hover { text-decoration: underline; }

/* هيكل النماذج داخل المودال */
.modal-box label { display: block; margin-bottom: 12px; color: var(--text-muted); font-size: 0.9rem; }
.modal-box label input,
.modal-box label select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text);
}
.modal-box label select { cursor: pointer; }

/* —— انشاء بحث كامل: تخطيط عمودين — اليمين خيارات إضافية —— */
.research-form-layout {
  display: flex;
  flex-direction: row;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.research-main-fields {
  flex: 1;
  min-width: 280px;
}
.research-main-fields label { display: block; margin-bottom: 14px; }
.research-main-fields label input[type="text"],
.research-main-fields label input[type="url"],
.research-main-fields label select,
.research-main-fields label textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text);
  font-size: 0.95rem;
}
.research-main-fields label textarea { min-height: 72px; resize: vertical; }
.research-options-sidebar {
  width: 260px;
  flex-shrink: 0;
}
.research-options-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
.research-options-title {
  margin: 0 0 16px;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.research-option-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  font-size: 0.9rem;
}
.research-option-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
}
.research-option-row span { flex: 1; }
.research-option-pipeline { color: var(--text-muted); }
.research-cover-fields {
  display: none;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.research-cover-fields label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.research-cover-fields input {
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.9rem;
}
@media (max-width: 640px) {
  .research-form-layout { flex-direction: column; }
  .research-options-sidebar { width: 100%; max-width: 320px; }
}

/* سبينر التحميل */
.spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-left: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* —— بطاقات المصادر (جلب المصادر) —— */
.sources-result { padding: 0; background: transparent; border: none; }
.sources-header { margin-bottom: 16px; padding: 12px 16px; background: var(--bg-primary); border-radius: var(--radius); border: 1px solid var(--border); font-weight: 700; color: var(--text-muted); }
.sources-list { display: flex; flex-direction: column; gap: 16px; max-height: 70vh; overflow: auto; }
.source-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: right;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.source-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.source-thumb {
  width: 64px;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  float: right;
  margin-left: 14px;
  margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.source-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  margin-left: 8px;
  margin-bottom: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}
.source-kind-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 6px;
  margin-left: 6px;
  margin-bottom: 8px;
  background: var(--bg-primary);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.source-card .source-title { margin: 0 0 8px; font-size: 1rem; font-weight: 700; line-height: 1.4; }
.source-card .source-title a { color: var(--accent); text-decoration: none; }
.source-card .source-title a:hover { text-decoration: underline; }
.source-meta { margin: 0 0 10px; font-size: 0.85rem; color: var(--text-muted); }
.source-abstract { margin: 0 0 14px; font-size: 0.9rem; line-height: 1.5; color: var(--text); max-height: 4.5em; overflow: hidden; text-overflow: ellipsis; }
.source-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.source-actions button, .source-actions .source-link {
  padding: 8px 14px;
  font-size: 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s;
}
.source-actions button:hover, .source-actions .source-link:hover { border-color: var(--accent); background: var(--accent-soft); }
.source-actions button.copied { border-color: var(--success); background: rgba(45, 212, 191, 0.2); color: var(--success); }
.modal-box.sources-modal { max-width: 720px; }

/* نصوص مطابقة من PDF */
.passages { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.passage { background: var(--bg-primary); border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-top: 10px; }
.passage .p-head { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; font-weight: 700; }
.passage .p-text { font-size: 0.9rem; line-height: 1.6; color: var(--text); white-space: pre-wrap; }

/* لوحة المدير — احترافية */
.admin-panel {
  padding: 12px 4px 20px;
  max-width: 740px;
  margin: 0 auto;
}
.admin-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--border);
  flex-wrap: wrap;
}
.admin-tabs button {
  padding: 12px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: 10px 10px 0 0;
  transition: color 0.2s, background 0.2s;
}
.admin-tabs button:hover { color: var(--text); background: var(--bg-primary); }
.admin-tabs button.active { color: var(--accent); background: var(--bg-primary); border-bottom: 2px solid var(--accent); margin-bottom: -2px; }
.admin-tab-content { display: none; padding: 8px 0; }
.admin-tab-content.active { display: block; }
.admin-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 18px;
}
.admin-card h4 { margin: 0 0 10px 0; font-size: 1.05rem; color: var(--accent); }
.admin-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0 0 14px 0;
  line-height: 1.55;
}
.admin-card-lock {
  border-color: var(--gold);
  background: linear-gradient(135deg, var(--bg-primary) 0%, rgba(240, 180, 41, 0.06) 100%);
}
.admin-card-lock h4 { color: var(--gold); }
.admin-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--bg-secondary);
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}
.admin-toggle input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; }
.admin-toggle:hover { border-color: var(--accent); }
.admin-form-row { margin-bottom: 14px; }
.admin-form-row label { display: block; margin-bottom: 6px; font-weight: 600; color: var(--text-muted); font-size: 0.9rem; }
.admin-form-row input, .admin-form-row select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}
.admin-form-row input:focus, .admin-form-row select:focus { outline: none; border-color: var(--accent); }
.admin-btn-save { padding: 10px 20px; background: var(--accent); color: #fff; border: none; border-radius: 10px; font-weight: 700; cursor: pointer; margin-top: 8px; }
.admin-btn-save:hover { opacity: 0.9; }
.admin-table-wrap {
  overflow-x: auto;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}
.admin-users-table {
  width: 100%;
  min-width: 320px;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.admin-users-table th, .admin-users-table td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); }
.admin-users-table th { background: var(--bg-primary); color: var(--text-muted); font-weight: 700; }
.admin-users-table tr:hover { background: var(--bg-primary); }
.admin-badge-premium { background: var(--gold); color: #000; padding: 2px 8px; border-radius: 6px; font-size: 0.8rem; font-weight: 700; }
.admin-badge-free { background: var(--border); color: var(--text-muted); padding: 2px 8px; border-radius: 6px; font-size: 0.8rem; }
.admin-subscription-card {
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
}
.admin-subscription-card .price-display { font-size: 1.5rem; font-weight: 800; color: var(--accent); }
.admin-ai-card { background: var(--bg-primary); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 14px; }
.admin-ai-card h4 { margin: 0 0 12px 0; font-size: 0.95rem; color: var(--text); }

/* ========== مواءمة الموبايل ========== */
@media (max-width: 768px) {
  :root {
    --radius: 12px;
    --radius-lg: 16px;
  }

  body {
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .container {
    max-width: 100%;
    padding: 12px 14px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .header {
    padding: 14px 16px;
    margin-bottom: 20px;
    gap: 10px;
    border-radius: var(--radius);
  }
  .header h1 {
    font-size: 1.1rem;
    line-height: 1.35;
    width: 100%;
    order: -1;
    margin-bottom: 4px;
  }
  .header > div {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }
  .header .user {
    font-size: 0.8rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .header button,
  .theme-toggle {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 0.85rem;
  }
  .header .premium,
  .header .free {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .card {
    padding: 16px 12px;
    border-radius: var(--radius);
  }
  .card .icon {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 8px;
    color: var(--accent); /* This allows standard SVGs to use 'currentColor' */
  }
  .card .icon svg {
    width: 2rem;
    height: 2rem;
  }
  .card .title {
    font-size: 0.95rem;
  }
  .card .sub {
    font-size: 0.8rem;
  }
  .card:hover {
    transform: translateY(-3px);
  }

  .auth-box {
    margin: 24px 14px;
    padding: 28px 20px;
    max-width: 100%;
    border-radius: var(--radius-lg);
  }
  .auth-box h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
  }
  .auth-box input {
    padding: 14px 16px;
    margin-bottom: 14px;
    font-size: 16px; /* يقلل zoom على iOS */
  }
  .auth-box button {
    padding: 14px;
    min-height: 48px;
  }
  .auth-switch button {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .modal {
    padding: 10px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    align-items: flex-end;
  }
  /* إنشاء بحث: شاشة عادية من الأعلى مثل صفحة عادية بدون زوم */
  .modal.research-open {
    align-items: flex-start;
    padding-top: max(12px, env(safe-area-inset-top));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal.research-open .modal-box {
    max-height: none;
    min-height: auto;
    border-radius: var(--radius-lg);
    margin-bottom: max(20px, env(safe-area-bottom));
  }
  .modal-box {
    max-width: 100%;
    width: 100%;
    max-height: 88vh;
    max-height: 88dvh;
    padding: 20px 16px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .modal-box h3 {
    font-size: 1.1rem;
    margin-bottom: 14px;
  }
  .modal-box .result {
    max-height: 240px;
    padding: 14px;
    font-size: 0.9rem;
  }
  .modal-box .actions {
    margin-top: 14px;
  }
  .modal-box button {
    min-height: 44px;
    padding: 12px 18px;
  }

/* --- Advanced Premium Chat Interface --- */
  .modal-box.chat-box {
    max-width: 100vw !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    background: var(--bg-primary);
  }

  .chat-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
  }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
  }

  /* Chat Message Bubbles */
  .chat-msg {
    max-width: 85%;
    padding: 16px 20px;
    border-radius: 20px;
    font-size: 1.05rem;
    line-height: 1.6;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease-out;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  }

  .chat-msg.user {
    align-self: flex-start;
    background: linear-gradient(135deg, var(--accent), #d1304d);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 16px rgba(233, 69, 96, 0.2);
  }

  .chat-msg.assistant {
    align-self: flex-end;
    background: var(--bg-secondary);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
  }

  /* Chat Input Area */
  .chat-row {
    display: flex;
    gap: 12px;
    padding: 20px 32px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    align-items: center;
  }

  .chat-row input {
    flex: 1;
    padding: 16px 24px;
    font-size: 1.1rem;
    border-radius: 30px;
    border: 2px solid var(--border);
    background: var(--bg-primary);
    color: var(--text);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .chat-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(233, 69, 96, 0.1);
  }

  .chat-row button {
    min-height: 54px;
    min-width: 120px;
    padding: 0 24px;
    border-radius: 30px;
    background: linear-gradient(135deg, var(--accent), #b42d41);
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 8px 16px rgba(233, 69, 96, 0.3);
  }

  .chat-row button:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(233, 69, 96, 0.5);
  }

  .chat-row button:active {
    transform: translateY(1px);
  }

  /* --- Advanced Premium Editor Interface --- */
  .modal-box.editor-modal {
    max-width: 1200px !important;
    width: 98vw !important;
    height: 95vh !important;
    max-height: 98vh !important;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    background: var(--bg-primary);
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 24px 64px rgba(0,0,0,0.4);
  }

  .word-online-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-secondary);
  }

  .word-online-ribbon {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.02);
  }

  .word-ribbon-brand {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }

  .word-online-tabs {
    display: flex;
    gap: 8px;
    padding: 0;
  }

  .word-online-tab {
    padding: 10px 20px;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
  }

  .word-online-tab.active, .word-online-tab:hover {
    background: var(--bg-primary);
    color: var(--accent);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  }

  .word-online-doc-area {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    background: var(--bg-secondary);
  }

  .word-online-page {
    width: 100%;
    max-width: 900px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 60px 80px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.08);
  }

  .word-toolbar {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 20px;
    margin-top: 12px;
    display: flex;
    gap: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    flex-wrap: wrap;
    justify-content: center;
  }

  .word-tb-btn,
  .word-tb-select {
    padding: 10px 14px;
    font-size: 1rem;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
  }

  .word-tb-btn:hover,
  .word-tb-select:hover {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(233, 69, 96, 0.2);
  }

  .word-editor-content,
  #wordEditorContent {
    min-height: 600px;
    font-size: 1.2rem;
    line-height: 1.8;
    color: var(--text);
    outline: none;
  }
  .word-online-tabs {
    padding: 0 8px;
  }
  .word-online-tab {
    padding: 10px 14px;
    font-size: 13px;
  }
  .word-online-doc-area {
    padding: 12px;
    min-height: 280px;
  }
  .word-online-page {
    padding: 16px 20px;
  }
  .word-toolbar {
    padding: 10px 12px;
    gap: 6px;
  }
  .word-tb-btn,
  .word-tb-select {
    padding: 8px 10px;
    font-size: 11px;
  }
  .word-editor-content,
  #wordEditorContent {
    min-height: 280px;
    height: 320px;
    padding: 20px 24px;
    font-size: 16px;
  }

  .toast {
    left: 14px;
    right: 14px;
    bottom: max(20px, env(safe-area-inset-bottom));
    padding: 14px 18px;
    font-size: 0.9rem;
  }

  .admin-panel {
    padding: 8px 0 16px;
  }
  .admin-tabs {
    gap: 2px;
    margin-bottom: 14px;
  }
  .admin-tabs button {
    padding: 10px 14px;
    font-size: 0.85rem;
  }
  .admin-card,
  .admin-ai-card,
  .admin-subscription-card {
    padding: 16px;
  }
  .admin-hint {
    font-size: 0.8rem;
    margin-bottom: 12px;
  }
  .admin-toggle {
    padding: 10px 12px;
    font-size: 0.9rem;
  }
  .admin-users-table {
    font-size: 0.8rem;
  }
  .admin-users-table th,
  .admin-users-table td {
    padding: 8px 6px;
  }
  .admin-table-wrap {
    margin-left: -4px;
    margin-right: -4px;
  }

  .sources-list {
    max-height: 60vh;
  }
  .source-card {
    padding: 14px;
  }
  .source-thumb {
    width: 52px;
    height: 72px;
    margin-left: 10px;
  }
  .source-actions button,
  .source-actions .source-link {
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  /* إنشاء بحث — شاشة عادية: حجم خط طبيعي، نصوص كاملة، بدون إحساس زوم */
  .modal-box.research-feature {
    padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    font-size: 15px;
    overflow-wrap: break-word;
    word-wrap: break-word;
  }
  .modal-box.research-feature h3 {
    margin-bottom: 16px;
    padding-top: 0;
    font-size: 1.05rem;
  }
  .modal-box.research-feature label {
    margin-bottom: 14px;
    font-size: 0.9rem;
  }
  .modal-box.research-feature label input,
  .modal-box.research-feature label select {
    font-size: 16px;
  }
  .modal-box.research-feature .research-outline-block {
    margin-top: 18px;
    padding: 18px;
    border-radius: var(--radius);
  }
  .modal-box.research-feature .research-outline-title {
    margin: 0 0 10px;
    font-size: 1rem;
  }
  .modal-box.research-feature .research-outline-desc {
    margin: 0 0 16px;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-muted);
    white-space: normal;
    overflow-wrap: break-word;
  }
  .modal-box.research-feature .research-outline-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 16px;
  }
  .modal-box.research-feature .research-outline-actions .btn-secondary {
    width: 100%;
    min-height: 44px;
    padding: 12px 16px;
    font-size: 0.95rem;
  }
  .modal-box.research-feature .research-outline-use {
    min-width: 0;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
  }
  .modal-box.research-feature .research-outline-use span {
    min-width: 0;
    flex: 1;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.5;
    font-size: 0.9rem;
  }
  .modal-box.research-feature .outline-result-wrap {
    margin-top: 14px;
    padding: 18px;
    gap: 18px;
  }
  .modal-box.research-feature .outline-field {
    margin-bottom: 0;
  }
  .modal-box.research-feature .outline-field-label {
    margin-bottom: 6px;
    font-size: 0.9rem;
  }
  .modal-box.research-feature .outline-input {
    font-size: 0.9rem;
  }
  .modal-box.research-feature .outline-textarea {
/* --- Sidebar Layout Architecture --- */
.main-wrapper {
    display: flex;
    flex-direction: row-reverse; /* RTL: Sidebar on the right */
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
/* --- Sidebar Layout Architecture --- */
.main-wrapper {
    display: flex;
    flex-direction: row-reverse; /* RTL: Sidebar on the right */
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--border);
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
    padding: 0 24px 32px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand .brand-logo { color: var(--accent); }
.sidebar-brand .brand-text { font-size: 1.4rem; font-weight: 800; color: var(--text); }
.sidebar-brand .brand-text small { font-size: 0.7rem; background: var(--accent); color: #fff; padding: 2px 6px; border-radius: 4px; margin-right: 4px; }

.sidebar-nav {
    flex: 1;
    padding: 0 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    text-align: right;
    transition: all 0.2s;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.nav-item.active { background: rgba(233, 69, 96, 0.1); color: var(--accent); }
.nav-icon { font-size: 1.2rem; }

.sidebar-footer {
    padding: 20px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.user-profile { display: flex; align-items: center; gap: 12px; padding: 8px; }
.user-avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--bg-secondary); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--accent); }
.user-details { flex: 1; overflow: hidden; }
.user-name { font-size: 0.85rem; font-weight: 700; color: var(--text); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.user-status { font-size: 0.7rem; }

.btn-upgrade-sidebar {
    background: var(--accent);
    color: #fff; border: none; padding: 10px; border-radius: var(--radius); font-weight: 600; font-size: 0.85rem; cursor: pointer;
}
.btn-upgrade-sidebar:hover { background: var(--accent-hover); }

.btn-logout-sidebar {
    display: flex; align-items: center; justify-content: space-between; background: rgba(233, 69, 96, 0.05); border: 1px solid rgba(233, 69, 96, 0.1); color: var(--accent); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 0.85rem; cursor: pointer;
}

.main-content {
    flex: 1;
    margin-right: 260px;
    padding: 40px;
    transition: all 0.3s ease;
}

.dashboard-hero { margin-bottom: 40px; }
.dashboard-hero h1 { font-size: 1.95rem; font-weight: 700; margin-bottom: 8px; }
.dashboard-hero p { font-size: 1.05rem; color: var(--text-muted); }

/* --- Responsive Adjustments --- */
@media (max-width: 992px) {
    .sidebar { width: 80px; }
    .sidebar .nav-text, .sidebar .user-details, .sidebar .brand-text, .sidebar .btn-upgrade-sidebar, .sidebar .btn-logout-sidebar span { display: none; }
    .sidebar-brand, .sidebar-footer { justify-content: center; padding: 20px 0; }
    .main-content { margin-right: 80px; }
}

@media (max-width: 600px) {
    .main-wrapper { flex-direction: column; }
    .sidebar {
        width: 100%; height: auto; position: fixed; bottom: 0; top: auto; flex-direction: row; padding: 5px 10px; border-left: none; border-top: 1px solid var(--border); justify-content: space-around; background: rgba(18, 18, 18, 0.95);
    }
    .sidebar-brand, .sidebar-footer, .sidebar-nav .nav-text { display: none; }
    .sidebar-nav { flex-direction: row; width: 100%; justify-content: space-around; padding: 0; }
    .nav-item { flex-direction: column; gap: 2px; padding: 8px; font-size: 0.6rem; }
    .nav-icon { font-size: 1.4rem; }
    .main-content { margin-right: 0; margin-bottom: 70px; padding: 20px; }
}

/* Skeleton Loading Animation */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton-card {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 20px;
    height: 140px;
    border: 1px solid var(--border);
}
.skeleton-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-secondary);
    margin-bottom: 12px;
}
.skeleton-line {
    height: 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    margin-bottom: 8px;
    width: 80%;
}
.skeleton-line.short {
    width: 50%;
}

.plagiarism-modal-box {
    max-width: 800px !important;
    width: 95vw !important;
}
#inpPlag {
    width: 100%;
    background: var(--bg-primary);
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    font-size: 16px;
    line-height: 1.6;
    resize: vertical;
    box-sizing: border-box;
}

/* نافذة منبثقة احترافية لعرض نتيجة البحث — مربع واضح وكبير */
.research-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}
.research-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}
.research-modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: min(1100px, 96vw);
  height: 90vh;
  max-height: 90vh;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: default;
}
[data-theme="light"] .research-modal-card {
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--border);
}
.research-modal-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
  border-bottom: 2px solid var(--border);
  background: var(--bg-card-hover);
}
.research-modal-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
}
.research-modal-close {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.5);
  border-radius: 12px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.research-modal-close:hover {
  color: #fff;
  background: #dc2626;
  border-color: #dc2626;
}
.research-modal-body {
  flex: 1;
  overflow: auto;
  padding: 24px;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-primary);
}
/* منطقة عرض نص البحث — مربع واضح واحترافي، خط أكبر وواضح */
#researchFullScreenContent .diff-box {
  max-height: none !important;
  min-height: 50vh;
  padding: 28px 32px;
  font-size: 1.1rem;
  line-height: 2;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--bg-card);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}
[data-theme="light"] #researchFullScreenContent .diff-box {
  background: #fff;
  border-color: var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
#researchFullScreenContent .diff-box h1 { font-size: 1.75rem; margin: 0 0 16px; }
#researchFullScreenContent .diff-box h2 { font-size: 1.35rem; margin: 24px 0 12px; }
#researchFullScreenContent .diff-box p { margin: 0 0 1em; }
#researchFullScreenContent .diff-box ol, #researchFullScreenContent .diff-box ul { padding-right: 1.5em; margin: 0 0 1em; }

/* نتيجة البحث مباشرة في الصفحة — مربع واضح واحترافي (بدون منبثق) */
.research-result-box {
  margin-top: 20px;
  padding: 24px 28px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255,255,255,0.04);
  max-width: 100%;
  box-sizing: border-box;
}
[data-theme="light"] .research-result-box {
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--border);
}
.research-result-box .diff-box {
  max-height: none !important;
  min-height: 360px;
  padding: 28px 32px;
  font-size: 1.1rem;
  line-height: 2;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--bg-primary);
  margin-top: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}
[data-theme="light"] .research-result-box .diff-box {
  background: #fff;
  border-color: var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.research-result-box .diff-box h1 { font-size: 1.75rem; margin: 0 0 16px; }
.research-result-box .diff-box h2 { font-size: 1.35rem; margin: 24px 0 12px; }
.research-result-box .diff-box p { margin: 0 0 1em; }
.research-result-box .diff-box ol,
.research-result-box .diff-box ul { padding-right: 1.5em; margin: 0 0 1em; }

/* مكانholders المخطط/الجدول/الخريطة/الشكل في البحث */
.research-visual-placeholder {
  display: inline-block;
  vertical-align: middle;
  min-width: 140px;
  padding: 12px 16px;
  margin: 8px 12px 8px 0;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  text-align: center;
}
.research-visual-icon {
  display: block;
  font-size: 1.8rem;
  margin-bottom: 6px;
}
.research-visual-label {
  display: block;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--text);
}
.research-visual-desc {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* قسم إضافة صور/خرائط/مخططات — فوق عملية التنفيذ */
.research-visuals-block {
  background: linear-gradient(145deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
  border: 1px solid var(--border);
  border-right: 4px solid #0ea5e9;
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.research-visuals-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}
.research-visuals-desc {
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.research-visuals-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.research-visuals-options label { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 700; }
.research-visuals-input { flex: 1; min-width: 180px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-primary); color: var(--text); }
.result-image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.result-image-card {
  margin: 0;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
}
.result-image-card img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  border-radius: 10px;
}
.result-image-card figcaption {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

.qr-modal-card {
  text-align: center;
  padding: 8px 0 4px;
}
.qr-modal-desc {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 0.92rem;
}
.qr-code-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}
.qr-link-preview {
  margin: 12px 0 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-all;
}
.qr-actions-row {
  margin: 0;
}
.qr-download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.3);
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}
.qr-download-link:hover {
  background: rgba(14, 165, 233, 0.18);
}

/* هيكلية البحث (الخطة) */
.research-outline-block {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-right: 4px solid #8b5cf6;
}
.research-outline-title { margin: 0 0 8px; font-size: 1.05rem; font-weight: 800; color: var(--text); }
.research-outline-desc { margin: 0 0 12px; font-size: 0.9rem; color: var(--text-muted); line-height: 1.5; }
.research-outline-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.research-outline-use { display: flex; align-items: center; gap: 8px; font-weight: 700; }
/* منطقة هيكلية البحث — انسيابية واحترافية، مناسبة للموبايل (لون نص عادي غير أحمر) */
.outline-result-wrap {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.outline-result-wrap .outline-field-label,
.outline-result-wrap .outline-input,
.outline-result-wrap .outline-textarea,
.outline-result-wrap .outline-section-title-preview { color: var(--text); }
.outline-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.outline-field-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}
.outline-input,
.outline-textarea {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  font-size: 1rem;
  line-height: 1.5;
  font-family: var(--font-ar);
  color: var(--text);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}
.outline-input::placeholder,
.outline-textarea::placeholder { color: var(--text-muted); opacity: 0.9; }
.outline-textarea { resize: vertical; min-height: 100px; font-size: 0.875rem; }
.outline-section-body input.outline-notes,
.outline-section-body input.outline-heading { font-size: 0.875rem; }
/* قائمة الأقسام — واحدة تحت الأخرى، قابلة للطي والفتح */
.outline-plan-wrap { margin-top: 6px; min-width: 0; }
.outline-plan-title {
  font-weight: 800;
  font-size: 0.95rem;
  margin: 0 0 14px;
  color: var(--text);
}
.outline-plan-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.outline-section-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-secondary);
  overflow: hidden;
  min-width: 0;
}
.outline-section-card--sub {
  margin-right: 16px;
  border-right: 3px solid var(--gold);
}
.outline-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  border-bottom: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s;
}
.outline-section-card.is-open .outline-section-header {
  border-bottom-color: var(--border);
}
.outline-section-header:hover {
  background: rgba(255, 255, 255, 0.04);
}
.outline-section-toggle {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.outline-section-card.is-open .outline-section-toggle {
  transform: rotate(180deg);
}
.outline-section-toggle::before {
  content: "▼";
}
.outline-section-title-preview {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* أزرار الهيكلية — إضافة (أخضر) وحذف (أحمر) فقط */
.outline-section-card .outline-section-add,
.outline-section-card .outline-section-delete,
button.outline-section-add,
button.outline-section-delete {
  pointer-events: auto !important;
  position: relative;
  z-index: 5;
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer !important;
  border-radius: 8px;
  font-family: var(--font-ar);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.outline-section-header {
  pointer-events: auto;
}
.outline-section-card .outline-section-add,
button.outline-section-add {
  border: 1px solid #16a34a !important;
  background: rgba(34, 197, 94, 0.3) !important;
  color: #22c55e !important;
}
.outline-section-card .outline-section-add:hover,
button.outline-section-add:hover {
  background: rgba(34, 197, 94, 0.45) !important;
  color: #4ade80 !important;
}
.outline-section-card .outline-section-delete,
button.outline-section-delete {
  border: 1px solid #dc2626 !important;
  background: rgba(239, 68, 68, 0.25) !important;
  color: #ef4444 !important;
}
.outline-section-card .outline-section-delete:hover,
button.outline-section-delete:hover {
  background: rgba(239, 68, 68, 0.4) !important;
  color: #f87171 !important;
}
.outline-section-body {
  display: none;
  padding: 14px 16px;
  background: var(--bg-primary);
}
.outline-section-card.is-open .outline-section-body {
  display: block;
}
.outline-section-body .outline-field {
  margin-bottom: 14px;
}
.outline-section-body .outline-field:last-child {
  margin-bottom: 0;
}
.outline-section-body .outline-input,
.outline-section-body input.outline-heading,
.outline-section-body input.outline-words,
.outline-section-body input.outline-notes {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: var(--font-ar);
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-sizing: border-box;
}
.outline-add-row-btn { font-size: 0.95rem; margin-top: 14px; padding: 12px 18px; }

@media (max-width: 640px) {
  .outline-result-wrap { padding: 14px 12px; gap: 16px; }
  .research-modal-body { padding: 16px 14px; }
  .outline-input, .outline-textarea { padding: 14px 16px; font-size: 16px; }
  .outline-section-header { padding: 14px 16px; }
  .outline-section-body { padding: 16px; }
  .outline-section-body input { font-size: 16px !important; padding: 14px 16px !important; }
}

/* شاشة كاملة لتحرير قسم الهيكلية — مثل الشاشة الرئيسية، بدون زوم أو قرب */
.outline-section-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: var(--bg-primary);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  box-sizing: border-box;
}
.outline-section-overlay[aria-hidden="false"],
.outline-section-overlay.show {
  display: block !important;
}
.outline-section-screen {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
}
.outline-section-screen-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.outline-section-screen-back {
  flex-shrink: 0;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-ar);
  color: var(--accent);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.outline-section-screen-back:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.outline-section-screen-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-wrap: break-word;
  line-height: 1.4;
}
.outline-section-screen-body {
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.outline-section-screen-body .outline-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.outline-section-screen-body .outline-field-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}
.outline-section-screen-body .outline-input {
  width: 100%;
  min-width: 0;
  padding: 14px 18px;
  font-size: 0.875rem;
  line-height: 1.5;
  font-family: var(--font-ar);
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-sizing: border-box;
}
.outline-section-screen-body .outline-input::placeholder {
  color: var(--text-muted);
}

/* التزام أكاديمي أعلى نموذج البحث */
.research-academic-commitment {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
  border: 1px solid var(--border);
  border-right: 4px solid var(--gold, #eab308);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.55;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.research-academic-commitment strong { color: var(--gold, #eab308); }
.research-result-note {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 10px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border-right: 3px solid var(--ok, #22c55e);
}

/* غلاف بحث احترافي مع إطار */
.research-cover-pro {
  margin-bottom: 32px;
}
.research-cover-frame {
  border: 3px double var(--border);
  border-radius: 4px;
  padding: 8px;
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow);
}
.research-cover-inner {
  text-align: center;
  padding: 36px 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-primary);
}
.research-cover-academic .research-cover-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
  text-align: right;
}
.research-cover-org {
  flex: 1;
  min-width: 200px;
}
.research-cover-university {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 6px;
  color: var(--text);
}
.research-cover-logo {
  flex-shrink: 0;
}
.research-cover-logo img {
  max-height: 88px;
  max-width: 220px;
  object-fit: contain;
  margin-bottom: 16px;
}
.research-cover-thesis-stmt {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin: 12px 0 20px;
  line-height: 1.5;
}
.research-cover-year {
  font-size: 0.95rem;
  margin: 10px 0 4px;
  color: var(--text);
}
.research-cover-pagenum {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 24px;
  margin-bottom: 0;
}
.research-cover-college {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 8px 0 4px;
  color: var(--text);
  letter-spacing: 0.02em;
}
.research-cover-dept {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 20px;
  color: var(--text-muted);
}
.research-cover-type {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin: 0 0 16px;
  letter-spacing: 0.05em;
}
.research-cover-title {
  font-size: 1.35rem;
  font-weight: 800;
  margin: 12px 0 20px;
  line-height: 1.4;
  color: var(--text);
}
.research-cover-meta {
  font-size: 0.95rem;
  margin: 6px 0;
  color: var(--text);
}

/* صور إضافية في البحث */
.research-extra-images {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 20px 0;
  justify-content: center;
}
.research-extra-images .research-fig {
  margin: 0;
  max-width: 280px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
}
.research-extra-images .research-fig img {
  width: 100%;
  height: auto;
  display: block;
}
.research-extra-images figcaption {
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

/* خيارات شعار الغلاف: رفع أو رابط */
.cover-logo-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
}
.cover-logo-upload input[type="file"] {
  display: none;
}
.cover-logo-or {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* مخططات بيانية وأشكال وجداول مولّدة في البحث */
.research-chart-fig,
.research-shape-fig,
.research-table-fig {
  margin: 16px 0;
  text-align: center;
  max-width: 100%;
  display: block;
}
.research-chart-fig img,
.research-shape-fig img,
.research-table-fig img {
  max-width: 100%;
  width: auto;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  display: block;
  margin: 0 auto;
}
.research-chart-fig figcaption,
.research-shape-fig figcaption,
.research-table-fig figcaption {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
  direction: rtl;
  text-align: right;
}

/* صور الأشكال المدمجة في البحث [شكل 1] [شكل 2] */
.research-visual-fig {
  display: inline-block;
  max-width: 320px;
  margin: 12px 16px 12px 0;
  vertical-align: top;
}
.research-visual-fig img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* تحميل الصفحة — إزالة الوامض */
body.loading-ui {
  opacity: 0.99;
}

