/* ============================================================
   LampOn — Responsive & RTL Patch
   Fixes:
   1. Excessive margins/padding on small devices (EN + AR)
   2. Mobile nav scroll when menu is open
   3. RTL layout corrections for mobile
   4. Container padding on very small screens
   ============================================================ */

/* ============================================================
   1. ROOT OVERRIDES — Tighten spacing tokens at small sizes
   ============================================================ */
@media (max-width: 480px) {
  :root {
    --space-3xl: 56px;   /* was 96px */
    --space-2xl: 40px;   /* was 64px */
    --space-xl:  28px;   /* was 40px */
  }
}

@media (max-width: 360px) {
  :root {
    --space-3xl: 44px;
    --space-2xl: 32px;
    --space-xl:  22px;
  }
}

/* ============================================================
   2. CONTAINER — Tighter horizontal padding on small screens
   ============================================================ */
@media (max-width: 480px) {
  .container {
    padding: 0 var(--space-md); /* 16px sides */
  }
}

@media (max-width: 360px) {
  .container {
    padding: 0 12px;
  }
}

/* ============================================================
   3. SECTION PADDING — Reduce vertical breathing room
   ============================================================ */
@media (max-width: 768px) {
  .section {
    padding: var(--space-2xl) 0;
  }
}

@media (max-width: 480px) {
  .section {
    padding: var(--space-xl) 0;
  }
}

/* ============================================================
   4. NAVBAR — Tighter on mobile, RTL slide direction
   ============================================================ */
/* ── LTR fix: on mobile, group navbar-actions + hamburger on the right ── */
/* When desktop nav is hidden (≤768px), space-between leaves the search   */
/* icon isolated in the middle. Switch to flex-start + margin-left:auto.  */
@media (max-width: 768px) {
  .navbar-inner {
    justify-content: flex-start;
  }

  .navbar-actions {
    margin-left: auto;
  }

  [dir="rtl"] .navbar-inner {
    justify-content: flex-end;
  }

  [dir="rtl"] .navbar-actions {
    margin-left: 0;
    margin-right: auto;
  }
}

@media (max-width: 480px) {
  .navbar-inner {
    padding: 12px var(--space-md);
  }

  .logo-text {
    font-size: 1.1rem;
  }

  .logo-ar {
    display: none; /* avoid cramping on tiny screens */
  }
}

/* RTL: nav actions order — items within actions bar reverse, but not the whole navbar */
[dir="rtl"] .navbar-actions {
  flex-direction: row-reverse;
}

/* ============================================================
   5. MOBILE NAV — Scroll fix + RTL slide direction
   ============================================================ */

/* ── Enable scroll inside open nav ── */
.mobile-nav {
  overflow-y: auto;          /* scroll if items exceed viewport */
  overscroll-behavior: contain; /* prevent scroll propagation to page */
  -webkit-overflow-scrolling: touch; /* smooth iOS momentum scroll */
  display: flex;
  flex-direction: column;
}

.mobile-nav ul {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: var(--space-2xl); /* breathing room at bottom */
}

/* ── Prevent body scroll when nav is open (position:fixed — preserves scroll on iOS) ── */
body.nav-open {
  position: fixed;
  overflow-y: scroll; /* keep scrollbar width to avoid layout shift */
  width: 100%;
  /* top is set dynamically by JS: document.body.style.top = -scrollY + px */
}

/* ── RTL: nav slides from LEFT not right ── */
[dir="rtl"] .mobile-nav {
  right: auto;
  left: -100%;
  border-left: none;
  border-right: 1px solid var(--border);
  transition: left 0.3s var(--ease);
}

[dir="rtl"] .mobile-nav.open {
  left: 0;
  right: auto;
}

/* Nav close button — always visible at top */
.mobile-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
  flex-shrink: 0; /* never compress */
}

[dir="rtl"] .mobile-nav-header {
  flex-direction: row-reverse;
}

/* Full-width on very small screens */
@media (max-width: 360px) {
  .mobile-nav {
    max-width: 100%;
    padding: var(--space-xl) var(--space-md);
  }
}

/* ============================================================
   6. HERO SECTION — Compact on mobile
   ============================================================ */
@media (max-width: 768px) {
  .hero {
    padding-top: 70px;
    min-height: 92vh;
    align-items: flex-start;
    padding-bottom: var(--space-2xl);
  }

  .hero-content {
    padding-top: var(--space-xl);
  }

  .hero-lead {
    font-size: 1.05rem;
    margin-bottom: var(--space-lg);
  }
}

@media (max-width: 480px) {
  .hero {
    min-height: 85vh;
    padding-top: 64px;
  }

  .hero-title {
    font-size: clamp(2rem, 9vw, 2.8rem);
    margin-bottom: var(--space-md);
    line-height: 1.1;
  }

  [dir="rtl"] .hero-title {
    font-size: clamp(1.8rem, 8vw, 2.6rem);
  }

  .hero-lead {
    font-size: 1rem;
    line-height: 1.7;
  }

  .hero-kicker {
    margin-bottom: var(--space-md);
  }

  .hero-actions {
    gap: var(--space-sm);
  }

  .hero-actions .btn {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .hero-scroll {
    display: none; /* hide scroll indicator on mobile — too little space */
  }
}

@media (max-width: 360px) {
  .hero-title {
    font-size: clamp(1.75rem, 8vw, 2.4rem);
  }
}

/* ============================================================
   7. ARTICLE HERO — Too much top padding on mobile
   ============================================================ */
@media (max-width: 768px) {
  .article-hero {
    padding: calc(64px + var(--space-xl)) 0 var(--space-xl);
  }
}

@media (max-width: 480px) {
  .article-hero {
    padding: calc(60px + var(--space-md)) 0 var(--space-lg);
  }

  .article-content {
    padding: 0;
  }

  .article-body {
    font-size: 1.05rem;
    line-height: 1.85;
  }
}

/* ============================================================
   8. ARTICLE GRID & CARDS
   ============================================================ */
@media (max-width: 480px) {
  .article-card {
    border-radius: 0; /* full bleed on mobile */
  }

  .articles-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-sm);
  }
}

/* ============================================================
   8b. FILTER TABS — Wrap on mobile so they don't push navbar off-screen
   ============================================================ */
@media (max-width: 768px) {
  .filter-tabs {
    flex-wrap: wrap;    /* allow buttons to wrap to a second row */
    flex-shrink: 1 !important; /* override inline flex-shrink:0 */
    max-width: 100%;    /* never wider than the viewport */
    overflow: visible;  /* undo the overflow:hidden that clips wrapped rows */
    background: transparent;
    gap: 6px;
    border-radius: 0;
  }

  .filter-tab {
    flex: 0 0 auto;     /* don't stretch; size to content */
    border: 1px solid var(--border);
    border-radius: 2px;
    background: var(--surface);
  }

  .filter-tab.active {
    border-color: var(--gold);
  }
}

/* ============================================================
   9. FACES / CATEGORIES GRID
   ============================================================ */
@media (max-width: 480px) {
  .face-card {
    padding: var(--space-lg) var(--space-md);
  }

  .faces-grid {
    margin-top: var(--space-lg);
  }
}

/* ============================================================
   10. NEWSLETTER SECTION
   ============================================================ */
@media (max-width: 480px) {
  .newsletter-inner {
    padding: 0 var(--space-sm);
  }

  .newsletter-form {
    flex-direction: column;
    background: transparent;
    gap: var(--space-sm);
  }

  .newsletter-input {
    border: 1px solid var(--border);
    border-radius: 2px;
    width: 100%;
  }

  .newsletter-btn {
    width: 100%;
    padding: 14px;
    border-radius: 2px;
  }
}

/* ============================================================
   11. FOOTER — Stack cleanly on mobile
   ============================================================ */
@media (max-width: 480px) {
  .footer {
    padding: var(--space-xl) 0 var(--space-lg);
  }

  .footer-inner {
    gap: var(--space-xl);
    margin-bottom: var(--space-lg);
  }

  .footer-brand p {
    max-width: 100%;
  }

  .footer-bottom {
    flex-direction: column;
    gap: var(--space-sm);
    text-align: center;
  }

  [dir="rtl"] .footer-bottom {
    text-align: center;
  }
}

/* ============================================================
   12. RTL — General direction fixes
   ============================================================ */

/* Flex row reversal for RTL two-col layouts */
[dir="rtl"] .flex-between {
  flex-direction: row-reverse;
}

/* Article meta row */
[dir="rtl"] .article-meta {
  flex-direction: row-reverse;
}

/* Quote card indent direction */
[dir="rtl"] .quote-card {
  border-left: none;
  border-right: 3px solid var(--gold-dim);
  padding-left: 0;
  padding-right: var(--space-lg);
}

/* Newsletter form direction */
[dir="rtl"] .newsletter-form {
  flex-direction: row-reverse;
}

@media (max-width: 480px) {
  [dir="rtl"] .newsletter-form {
    flex-direction: column;
  }
}

/* Search box position */
[dir="rtl"] .nav-search-box {
  right: auto;
  left: 0;
}

/* Breadcrumb direction */
[dir="rtl"] .breadcrumb {
  flex-direction: row-reverse;
}

/* Pagination direction */
[dir="rtl"] .pagination {
  flex-direction: row-reverse;
}

/* Tags/pills spacing in RTL */
[dir="rtl"] .tag,
[dir="rtl"] .badge,
[dir="rtl"] .pill {
  direction: rtl;
}

/* ============================================================
   13. MODAL — Full screen on small devices
   ============================================================ */
@media (max-width: 480px) {
  .modal-box {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    margin: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    transform: none !important;
  }

  .modal {
    align-items: flex-end;
    padding: 0;
  }
}

/* ============================================================
   14. READING PROGRESS — keep above navbar on mobile
   ============================================================ */
@media (max-width: 768px) {
  .reading-progress {
    top: 0;
    z-index: 101;
  }
}

/* ============================================================
   15. REALM MEGA MENU — Prevent overflow on mid screens
   ============================================================ */
@media (max-width: 768px) {
  .realms-mega {
    display: none !important; /* use mobile nav on tablet/mobile */
  }
}

/* ============================================================
   16. USER DASHBOARD — Stack on mobile
   ============================================================ */
@media (max-width: 768px) {
  .dashboard-grid,
  .dashboard-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .dashboard-stats {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
  }

  .stat-card {
    padding: var(--space-md);
  }
}

/* ============================================================
   17. ASSESSMENT / QUIZ — Full width on mobile
   ============================================================ */
@media (max-width: 480px) {
  .assessment-card,
  .question-card {
    padding: var(--space-lg) var(--space-md);
  }

  .options-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   18. CATEGORY SIDEBAR — Horizontal scroll on mobile
   ============================================================ */
@media (max-width: 768px) {
  .category-type-sidebar {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0;
  }

  .category-type-sidebar::-webkit-scrollbar {
    display: none;
  }
}

/* ============================================================
   19. TABLE OVERFLOW — Prevent horizontal blowout
   ============================================================ */
@media (max-width: 768px) {
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
}

/* ============================================================
   20. LANG TOGGLE — Tighter on mobile
   ============================================================ */
@media (max-width: 480px) {
  .lang-toggle {
    padding: 4px 8px;
    font-size: 0.7rem;
  }

  .lang-dropdown {
    right: 0;
    min-width: 120px;
  }

  [dir="rtl"] .lang-dropdown {
    right: auto;
    left: 0;
  }
}

/* ============================================================
   21. SEARCH BAR — Prevent overflow on very small screens
   ============================================================ */
@media (max-width: 480px) {
  .nav-search-box {
    /* On small screens anchor to the right edge of the viewport
       and cap width so it never bleeds off the left edge        */
    position: fixed;
    top: 60px;           /* just below the navbar */
    right: 8px;
    left: 8px;
    width: auto;         /* stretch between the 8px gutters */
    max-width: calc(100vw - 16px);
    box-sizing: border-box;
    z-index: 500;
  }

  [dir="rtl"] .nav-search-box {
    right: 8px;
    left: 8px;
  }
}

/* ============================================================
   22. EMAIL-VERIFY BANNER — Full-width, wrapping on mobile
   ============================================================ */
#email-verify-banner {
  box-sizing: border-box;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

@media (max-width: 600px) {
  #email-verify-banner {
    padding: 10px 36px 10px 12px !important; /* room for ✕ button on the right */
    gap: 8px !important;
    font-size: 0.75rem !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    text-align: left !important;
  }

  [dir="rtl"] #email-verify-banner {
    padding: 10px 12px 10px 36px !important;
    text-align: right !important;
    align-items: flex-end !important;
  }

  /* Keep the dismiss ✕ pinned to the top-right corner even in column layout */
  #email-verify-banner button:last-child {
    position: absolute !important;
    right: 8px !important;
    top: 8px !important;
    transform: none !important;
  }

  [dir="rtl"] #email-verify-banner button:last-child {
    right: auto !important;
    left: 8px !important;
  }

  #verify-banner-resend {
    align-self: flex-start;
  }
}

/* ============================================================
   23. NOTIFICATION DROPDOWN — Full-width on mobile
   ============================================================ */
@media (max-width: 600px) {
  .nav-notif-dropdown {
    /* Detach from the bell and anchor to the viewport edges */
    position: fixed;
    top: 60px;          /* just below the navbar */
    left: 8px;
    right: 8px;
    width: auto;        /* stretch between the 8px gutters */
    max-width: calc(100vw - 16px);
    max-height: 70vh;   /* don't eat the whole screen */
    box-sizing: border-box;
    z-index: 500;
    border-radius: 4px;
  }

  /* RTL: same treatment — position:fixed ignores direction anyway */
  [dir="rtl"] .nav-notif-dropdown {
    right: 8px;
    left: 8px;
  }

  /* Make notification list scrollable inside fixed height */
  .nav-notif-list {
    max-height: calc(70vh - 48px); /* subtract header height */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}
