/* --- Global Theme & Islamic Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&family=Tajawal:wght@400;500;700&display=swap');

:root {
  --primary-dark: #2a5336; /* Very deep Islamic green/black */
  --surface: #072a1e;      /* Rich emerald green */
  --surface-hover: #0a3d2c;
  --gold: #d4af37;         /* Classic gold */
  --gold-dim: rgba(212, 175, 55, 0.4);
  --text-main: #f8f9fa;
  --text-muted: #94a3b8;
}

body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: var(--primary-dark);
  /* Subtle Islamic Geometric Pattern 
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0l4.3 12.2 12.2 4.3-12.2 4.3L30 33l-4.3-12.2L13.5 16.5l12.2-4.3zM30 60l-4.3-12.2-12.2-4.3 12.2-4.3L30 27l4.3 12.2 12.2 4.3-12.2 4.3z' fill='%23072a1e' fill-opacity='0.5' fill-rule='evenodd'/%3E%3C/svg%3E");
  */
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  font-family: 'Tajawal', system-ui, -apple-system, sans-serif;
  transition: all 0.3s ease;
  color: var(--text-main);
}

/* --- Header --- */
#app-header {
  width: 100%;
  padding: 12px 10px;
  background-color: var(--primary-dark);
  color: var(--gold);
  font-family: 'Amiri', serif;
  font-size: 1.2rem;
  border-bottom: 2px solid var(--gold-dim);
  z-index: 10;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 15px rgba(0,0,0,0.6);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

.header-controls button {
  background: none;
  border: none;
  color: var(--gold);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}
.header-controls button:hover { color: #fff; }

.social-icon {
  color: var(--gold);
  display: flex;
  align-items: center;
  text-decoration: none;
  transition: opacity 0.2s;
}
.social-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.social-icon:hover { color: #fff; }

.header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-family: 'Tajawal', sans-serif;
}

#surah-select {
  background-color: var(--surface);
  color: var(--gold);
  border: 1px solid var(--gold);
  padding: 4px 8px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  outline: none;
  max-width: 120px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.hidden { display: none !important; }

/* --- Tafseer Tabs --- */
.mode-tabs {
  width: 100%;
  display: flex;
  background-color: var(--primary-dark);
  z-index: 9;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  max-height: 50px;
  opacity: 1;
  overflow: hidden;
  border-bottom: 1px solid var(--surface);
}

.mode-btn {
  flex: 1;
  padding: 12px 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  font-family: 'Amiri', serif;
  font-weight: bold;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.3s;
}

.mode-btn.active {
  color: var(--gold);
  border-bottom: 3px solid var(--gold);
  background-color: var(--surface);
}

/* --- Home Screen Grid --- */
#home-view {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
}

.home-header {
  width: 100%;
  padding: 30px 20px;
  color: var(--gold);
  text-align: center;
  font-family: 'Amiri', serif;
  font-size: 2.2rem;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  margin-bottom: 10px;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  padding: 10px 20px 50px;
  width: 100%;
  max-width: 500px;
  box-sizing: border-box;
}

.app-card {
  background: linear-gradient(145deg, var(--surface), var(--primary-dark));
  /* Mihrab Arch Shape */
  border-radius: 40px 40px 15px 15px; 
  border: 1px solid var(--gold-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 35px 15px 25px;
  color: var(--text-main);
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  cursor: pointer;
  font-family: 'Amiri', serif;
  font-size: 1.3rem;
  font-weight: bold;
  gap: 15px;
  position: relative;
}

/* Subtle inner glow for cards */
.app-card::before {
  content: "";
  position: absolute;
  top: 5px; left: 5px; right: 5px; bottom: 5px;
  border: 1px dashed var(--gold-dim);
  border-radius: 35px 35px 10px 10px;
  pointer-events: none;
}

.app-card:active {
  transform: scale(0.96);
  background: var(--surface-hover);
  border-color: var(--gold);
}

.app-card svg {
  width: 45px;
  height: 45px;
  fill: var(--gold);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

/* --- Reader View & Controls --- */
#reader-view {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#home-btn svg {
  fill: var(--gold);
  width: 24px;
  height: 24px;
}
#home-btn:hover svg { fill: #fff; }

#page-container {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 1500px;
  overflow: hidden;
  touch-action: pan-y;
  background-color: #000;
}

#page-container.zoomed {
  display: block; 
  overflow: auto;
  touch-action: auto;
  text-align: right;
}

#quran-image-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
  transform-style: preserve-3d;
}

#page-container.zoomed #quran-image-wrapper {
  display: inline-block;
  width: auto;
  height: auto;
  min-width: 100%;
  text-align: right;
}

#quran-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background-color: #fdf6e3; /* Paper-like background for the image if transparent */
  transition: width 0.2s ease, height 0.2s ease;

  -webkit-touch-callout: none; /* Disables iOS Safari share/save popup */
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: pan-y pinch-zoom;
}

#page-container.zoomed #quran-image {
  max-width: none;
  max-height: none;
  object-fit: cover;
}

.controls {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background-color: var(--primary-dark);
  border-top: 1px solid var(--gold-dim);
  box-sizing: border-box;
  z-index: 10;
  transition: padding 0.3s;
}

button.nav-btn {
  padding: 8px 18px;
  font-size: 1rem;
  border: 1px solid var(--gold-dim);
  background-color: var(--surface);
  color: var(--gold);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  font-weight: bold;
  transition: all 0.2s;
}
button.nav-btn:hover { background-color: var(--surface-hover); border-color: var(--gold); color: #fff;}
button.nav-btn:disabled { background-color: var(--primary-dark); color: var(--text-muted); border-color: transparent; cursor: not-allowed; }
.btn-icon { display: none; font-size: 1.2rem; }

.zoom-group {
  display: flex;
  align-items: center;
  background-color: var(--surface);
  border: 1px solid var(--gold-dim);
  border-radius: 8px;
  overflow: hidden;
}
.zoom-group button {
  background: none;
  border: none;
  color: var(--gold);
  font-size: 1.4rem;
  padding: 4px 15px;
  cursor: pointer;
  font-weight: bold;
}
.zoom-group button:active { background-color: var(--surface-hover); color: #fff;}
#zoom-display {
  color: var(--text-main); font-size: 0.9rem; min-width: 45px; text-align: center; direction: ltr; user-select: none; font-weight: bold;
}

/* Zoom Mode UI Optimization */
body.zoom-mode #app-header { padding: 6px 10px; }
body.zoom-mode .mode-tabs { max-height: 0; opacity: 0; border: none; }
body.zoom-mode .controls { padding: 6px 20px; }
body.zoom-mode .btn-text { display: none; }
body.zoom-mode .btn-icon { display: inline; }
body.zoom-mode button.nav-btn { padding: 6px 12px; }

/* Update Notification Toast */
#update-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px);
  background-color: var(--gold); color: var(--primary-dark);
  padding: 12px 20px; border-radius: 30px; box-shadow: 0 4px 15px rgba(0,0,0,0.6);
  display: flex; align-items: center; gap: 15px; z-index: 9999;
  opacity: 0; pointer-events: none; transition: opacity 0.3s, transform 0.3s ease-out;
  white-space: nowrap; font-family: 'Tajawal', sans-serif; font-weight: bold;
}
#update-toast.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
#update-toast button {
  background: var(--primary-dark); color: var(--gold); border: none;
  padding: 6px 12px; border-radius: 15px; font-weight: bold; font-family: inherit; cursor: pointer;
}

/* --- Modal (Tafseer Popup) --- */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(3px);
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--primary-dark);
  border: 1px solid var(--gold);
  border-radius: 20px;
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0,0,0,0.8);
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
  transform: translateY(0);
}

.modal-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--gold-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  color: var(--gold);
  font-family: 'Amiri', serif;
  font-size: 1.4rem;
}

.close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}
.close-modal:hover { color: #fff; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.modal-body select {
  background-color: var(--surface);
  color: var(--text-main);
  border: 1px solid var(--gold-dim);
  padding: 10px;
  border-radius: 8px;
  font-family: 'Tajawal', sans-serif;
  font-size: 1rem;
  outline: none;
}

.fetch-btn {
  background: var(--gold);
  color: var(--primary-dark);
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: bold;
  font-size: 1.1rem;
  cursor: pointer;
  font-family: 'Amiri', serif;
}
.fetch-btn:active { background: #b5952f; }

#tafseer00-result00 {
  background: var(--surface);
  padding: 15px;
  border-radius: 8px;
  border: 1px dashed var(--gold-dim);
  font-family: 'Amiri', serif;
  font-size: 1.2rem;
  line-height: 1.8;
  color: var(--text-main);
  min-height: 100px;
}
#tafseer-result {
  background: var(--surface);
  padding: 15px;
  border-radius: 8px;
  border: 1px dashed var(--gold-dim);
  font-family: 'Amiri', serif;
  font-size: 1.2rem;
  line-height: 1.8;
  color: var(--text-main);
  min-height: 100px;
  
  /* --- الخصائص الجديدة لحل مشكلة النص الطويل --- */
  height: auto; /* يجبر الصندوق على أخذ ارتفاع النص بالكامل */
  flex-shrink: 0; /* يمنع الصندوق من الانكماش داخل النافذة المنبثقة */
  word-wrap: break-word; /* يضمن كسر الكلمات الطويلة جداً حتى لا تخرج من الجوانب */
  overflow-wrap: break-word;
  white-space: pre-wrap; /* يحترم المسافات والأسطر الجديدة (Enter) القادمة من قاعدة البيانات */
}

/* --- وضع القراءة بملء الشاشة (Auto-Hide UI) --- */
#app-header, .controls, #tafseer-tabs {
  overflow: hidden;
  /* انتقال ناعم لجميع الخصائص لكي تتمدد الصفحة بسلاسة */
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
              padding 0.4s ease, 
              opacity 0.4s ease, 
              border-width 0.4s ease, 
              margin 0.4s ease;
}

#app-header { max-height: 120px; }
.controls { max-height: 100px; }

/* عند تفعيل وضع القراءة (reading-mode)، يتم تقليص القوائم بالكامل */
body.reading-mode #app-header,
body.reading-mode .controls {
  max-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  margin: 0 !important;
  opacity: 0 !important;
  border-width: 0 !important;
  pointer-events: none;
}

body.reading-mode #tafseer-tabs {
  max-height: 0 !important;
  padding: 0 !important;
  opacity: 0 !important;
  border-width: 0 !important;
  pointer-events: none;
}

/* --- وضع الهاتف العرضي (Landscape Mode) للهواتف فقط --- */
/* الشرط هنا: يجب أن تكون الشاشة بالعرض + وأن يكون ارتفاعها أقل من 600 بكسل (لضمان استبعاد الكمبيوتر والتابلت) */
@media (orientation: landscape) and (max-height: 600px) {
  
  /* تغيير حاوية الصفحة لتسمح بالتمرير العمودي (Scroll) بدلاً من التوسيط */
  #page-container:not(.zoomed) {
    display: block; 
    overflow-y: auto;
    overflow-x: hidden;
  }
  
  /* جعل الغلاف يأخذ العرض بالكامل */
  #page-container:not(.zoomed) #quran-image-wrapper {
    display: block;
    width: 100%;
    height: auto;
    padding-bottom: 30px; /* مسافة بسيطة في الأسفل لراحة العين */
  }

  /* إجبار صورة القرآن على التمدد بعرض الشاشة والسماح للطول بالتمدد بحرية */
  #page-container:not(.zoomed) #quran-image {
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: none;
    object-fit: contain;
  }
}

/* --- فرض الوضع العرضي يدوياً بالضغط على الزر (Manual Landscape Mode) --- */
body.force-landscape #page-container:not(.zoomed) {
  display: block; 
  overflow-y: auto;
  overflow-x: hidden;
}

body.force-landscape #page-container:not(.zoomed) #quran-image-wrapper {
  display: block;
  width: 100%;
  height: auto;
  padding-bottom: 30px;
}

body.force-landscape #page-container:not(.zoomed) #quran-image {
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: none;
  object-fit: contain;
}

/* --- Slide-Out Menu Drawer --- */
.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 1100;
}

.menu-backdrop.open {
  opacity: 1;
  visibility: visible;
}


.side-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  max-width: 82vw;
  height: 100vh;
  height: 100dvh; /* Accounts for mobile browser toolbars */
  max-height: 100dvh;
  background: var(--primary-dark, #02140d);
  border-left: 1px solid var(--gold-dim, #8a6d3b);
  box-shadow: -5px 0 20px rgba(0, 0, 0, 0.6);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Keeps header fixed while items scroll */
}

.side-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(212, 175, 55, 0.25);
  color: var(--gold, #d4af37);
  flex-shrink: 0; /* Never compress header */
}

.drawer-items {
  flex: 1 1 auto;
  min-height: 0; /* Critical for flex child scrolling */
  display: flex;
  flex-direction: column;
  padding: 12px 12px calc(32px + env(safe-area-inset-bottom, 16px)) 12px;
  gap: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.drawer-nav-group {
  flex-shrink: 0;
}

.drawer-item {
  flex-shrink: 0; /* Prevents buttons from squishing instead of scrolling */
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 13px 16px;
  background: var(--surface, #0a291c);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: 10px;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.96rem;
  cursor: pointer;
  text-align: right;
  transition: background 0.2s, border-color 0.2s;
}

.drawer-header h3 {
  margin: 0;
  font-size: 1.1rem;
}





.drawer-item:hover,
.drawer-item:active {
  background: rgba(212, 175, 55, 0.15);
  border-color: var(--gold, #d4af37);
}

.drawer-item svg {
  width: 22px;
  height: 22px;
  fill: var(--gold, #d4af37);
  flex-shrink: 0;
}

.drawer-item.hidden {
  display: none;
}

/* --- Drawer Navigation Selectors (Surah & Page Lists) --- */
.drawer-nav-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(212, 175, 55, 0.2);
}

.drawer-select-box {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.drawer-select-box.hidden {
  display: none;
}

.drawer-select-box label {
  font-size: 0.85rem;
  color: var(--gold, #d4af37);
  padding-right: 4px;
}

.drawer-select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--gold-dim, #8a6d3b);
  background: var(--surface, #0a291c);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  cursor: pointer;
}

.drawer-select:focus {
  border-color: var(--gold, #d4af37);
}


/* --- Ayah Highlight Layer & Boxes --- */
#quran-image-wrapper {
  position: relative;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: fit-content;
  margin: 0 auto;
}

.ayah-highlight-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 5;
}

.ayah-highlight-box {
  position: absolute;
  background-color: rgba(212, 175, 55, 0.35);
  border-bottom: 2px solid rgba(212, 175, 55, 0.85);
  border-radius: 4px;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.chat-badge {
  margin-right: auto;
  background: #e53935;
  color: #fff;
  font-size: 0.75rem;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 999px;
}
.chat-badge.hidden {
  display: none;
}

/* ==========================================
   Enhanced Chat Modal & Auth Forms
   ========================================== */
.modal-content.chat-content {
  width: 94%;
  max-width: 460px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--primary-dark, #031a11);
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.75);
  overflow: hidden;
  padding: 0;
}

.chat-content .modal-header {
  padding: 18px 22px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(212, 175, 55, 0.2);
}

.chat-body-section {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}

.chat-body-section.hidden,
.auth-form.hidden,
.admin-select-bar.hidden {
  display: none !important;
}

/* Auth Forms (Login & Register) */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 15px; /* Generous vertical spacing between fields */
}

.auth-subtitle {
  margin: 0 0 4px 0;
  font-size: 0.92rem;
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chat-input {
  width: 100%;
  box-sizing: border-box;
  padding: 14px 16px; /* Taller, comfortable touch target */
  font-size: 1rem;
  font-family: inherit;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(212, 175, 55, 0.28);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.chat-input:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--gold, #d4af37);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15);
}

select.chat-input option {
  background: #062317;
  color: #ffffff;
}

.chat-primary-btn {
  margin-top: 6px;
  padding: 14px;
  font-size: 1.02rem;
  font-weight: bold;
  border-radius: 12px;
  cursor: pointer;
}

.auth-switch-btn {
  background: transparent;
  border: none;
  color: var(--gold, #d4af37);
  font-family: inherit;
  font-size: 0.93rem;
  padding: 8px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.auth-error {
  color: #ff7b7b;
  font-size: 0.9rem;
  margin-top: 14px;
  text-align: center;
  min-height: 20px;
}

/* Active Chat View Layout */
.chat-active-layout {
  display: flex;
  flex-direction: column;
  height: 72vh;
  max-height: 600px;
  padding: 16px 18px;
  gap: 14px;
}

.admin-select-bar {
  padding-bottom: 4px;
}

/* Messages Scroll Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(212, 175, 55, 0.15);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px; /* Clear separation between message bubbles */
}

.chat-messages .msg {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 0.96rem;
  line-height: 1.55;
  word-wrap: break-word;
}

.chat-messages .msg.me {
  align-self: flex-start; /* Right side in RTL */
  background: linear-gradient(135deg, #1b5e3a, #124228);
  color: #ffffff;
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-bottom-right-radius: 4px;
}

.chat-messages .msg.them {
  align-self: flex-end; /* Left side in RTL */
  background: rgba(255, 255, 255, 0.1);
  color: #f1f5f3;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom-left-radius: 4px;
}

/* Chat Input Bar & Footer */
.chat-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-input-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-input-area .chat-input {
  flex: 1;
  border-radius: 999px;
  padding: 13px 18px;
}

.chat-send-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--gold, #d4af37);
  color: #02140d;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

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

.logout-btn {
  align-self: center;
  background: transparent;
  border: none;
  color: rgba(255, 130, 130, 0.85);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 4px 10px;
  cursor: pointer;
}

/* ==========================================
   Video Generator & Share Modal
   ========================================== */
.video-modal-content {
  width: 94%;
  max-width: 460px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--primary-dark, #031a11);
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 18px;
  padding: 0;
  overflow: hidden;
}

.video-modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.vid-scope-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: rgba(0, 0, 0, 0.3);
  padding: 5px;
  border-radius: 12px;
}

.vid-scope-btn {
  padding: 10px 6px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.vid-scope-btn.active {
  background: var(--gold, #d4af37);
  color: #02140d;
  font-weight: bold;
}

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

.vid-field label {
  font-size: 0.86rem;
  color: var(--gold, #d4af37);
}

.vid-ayah-selectors {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.vid-progress-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.vid-status-text {
  font-size: 0.92rem;
  color: #fff;
}

.vid-progress-bar {
  width: 100%;
  height: 10px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  overflow: hidden;
}

.vid-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #b8860b, #f3d266);
  transition: width 0.25s ease;
}

.vid-recording-actions,
.vid-result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.vid-secondary-btn {
  padding: 11px 16px;
  border-radius: 10px;
  border: 1px solid var(--gold, #d4af37);
  background: rgba(212, 175, 55, 0.12);
  color: var(--gold, #d4af37);
  font-family: inherit;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
}

.vid-result-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.vid-preview-player {
  width: 100%;
  max-height: 280px;
  background: #000;
  border-radius: 12px;
  border: 1px solid rgba(212, 175, 55, 0.3);
}

/* --- Custom Video Background & Motion Panel --- */
.vid-custom-panel {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.vid-custom-panel.hidden,
.vid-guest-notice.hidden,
.vid-user-bg-controls.hidden,
.vid-bg-thumb.hidden {
  display: none !important;
}

.vid-guest-notice {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.9rem;
  color: #f3d266;
}

.vid-user-bg-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.vid-bg-preview-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.vid-bg-thumb {
  width: 64px;
  height: 92px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--gold, #d4af37);
  flex-shrink: 0;
}

.vid-bg-upload-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.vid-color-picker {
  width: 100%;
  height: 44px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid rgba(212, 175, 55, 0.35);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

/* --- Approval Status Banner & Admin Moderation --- */
.vid-approval-banner {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  text-align: center;
  font-weight: bold;
}
.vid-approval-banner.hidden { display: none !important; }
.vid-approval-banner.pending {
  background: rgba(255, 193, 7, 0.16);
  border: 1px solid rgba(255, 193, 7, 0.5);
  color: #ffd54f;
}
.vid-approval-banner.approved {
  background: rgba(76, 175, 80, 0.16);
  border: 1px solid rgba(76, 175, 80, 0.5);
  color: #81c784;
}
.vid-approval-banner.rejected {
  background: rgba(244, 67, 54, 0.16);
  border: 1px solid rgba(244, 67, 54, 0.5);
  color: #e57373;
}

.admin-mod-box {
  background: rgba(212, 175, 55, 0.08);
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
}
.admin-mod-box.hidden { display: none !important; }
.admin-mod-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  color: var(--gold, #d4af37);
  font-weight: bold;
}
.admin-pending-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.admin-pending-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.35);
  padding: 8px;
  border-radius: 8px;
}
.admin-pending-thumb {
  width: 48px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.admin-pending-info {
  flex: 1;
  font-size: 0.85rem;
}
.admin-pending-actions {
  display: flex;
  gap: 6px;
}
.btn-approve {
  background: #2e7d32;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.82rem;
}
.btn-reject {
  background: #c62828;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.82rem;
}

/* Update Toast */
.update-toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(150%);
  background: var(--surface);
  border: 1px solid var(--gold);
  padding: 12px 18px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 2000;
  transition: transform 0.3s ease;
}

.update-toast.show {
  transform: translateX(-50%) translateY(0);
}

/* --- Prepared Backgrounds Gallery --- */
.vid-prepared-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px;
  border-radius: 10px;
}

.vid-prep-tab {
  padding: 8px 6px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.vid-prep-tab.active {
  background: var(--gold, #d4af37);
  color: #02140d;
  font-weight: bold;
}

.vid-prepared-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 210px;
  overflow-y: auto;
  padding: 2px;
}

.vid-prep-item {
  position: relative;
  aspect-ratio: 9 / 14;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.14);
  background: #000;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.vid-prep-item.selected {
  border-color: var(--gold, #d4af37);
  box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.45);
}

.vid-prep-item img,
.vid-prep-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.vid-prep-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 6px;
}

.search-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.search-results-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 56vh;
  overflow-y: auto;
  padding-left: 4px;
}

.search-result-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(212, 175, 55, 0.24);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  text-align: right;
  color: #ffffff;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform 0.12s ease;
}

.search-result-card:hover,
.search-result-card:active {
  background: rgba(212, 175, 55, 0.14);
  border-color: var(--gold);
  transform: translateY(-1px);
}

.search-result-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--gold-light);
  font-weight: 700;
}

.search-result-text {
  font-size: 1.08rem;
  line-height: 1.85;
  color: #ffffff;
}