/* ============================================
   Enkaura — RTL + Mobile/Tablet Polish
   Loaded after base.css on every page.
   Goals:
   - Mirror layouts cleanly when [dir="rtl"]
   - Ensure 44px minimum touch targets
   - Prevent horizontal scroll on mobile
   - Smooth tablet breakpoints
   ============================================ */

/* ── Global no-overflow guard ── */
html, body { max-width: 100%; overflow-x: clip; }
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }
input, textarea, select, button { font-size: 16px; } /* prevents iOS auto-zoom */

/* ── Touch target minimums (WCAG 2.5.5 / Apple HIG) ── */
button, a.btn, .btn, .btn-primary, .btn-secondary,
.nav-cta, .lang-toggle, .theme-toggle, .search-toggle,
.footer-social-link, .scroll-top, [role="button"] {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

/* Safe-area aware containers (notched phones) */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ============================================
   RTL OVERRIDES
   ============================================ */
html[dir="rtl"] { text-align: right; }
html[dir="rtl"] body { font-family: 'Tajawal', 'Cairo', 'Inter', system-ui, sans-serif; }

/* General mirroring */
html[dir="rtl"] .nav-links,
html[dir="rtl"] .nav-actions,
html[dir="rtl"] .footer-grid,
html[dir="rtl"] .footer-bottom,
html[dir="rtl"] .footer-legal,
html[dir="rtl"] .err-actions {
  direction: rtl;
}

html[dir="rtl"] .nav-links { padding-right: 0; }

/* Margin/padding flips that commonly trip layouts */
html[dir="rtl"] .nav-cta,
html[dir="rtl"] .nav-actions > *,
html[dir="rtl"] .footer-social-link {
  margin-left: 0;
}

/* Inputs / forms — labels on the right */
html[dir="rtl"] input,
html[dir="rtl"] textarea,
html[dir="rtl"] select {
  text-align: right;
  direction: rtl;
}
/* Keep email / tel / url / number inputs LTR even in RTL pages */
html[dir="rtl"] input[type="email"],
html[dir="rtl"] input[type="url"],
html[dir="rtl"] input[type="tel"],
html[dir="rtl"] input[type="number"],
html[dir="rtl"] input[type="password"],
html[dir="rtl"] input[type="date"],
html[dir="rtl"] input[type="time"] {
  direction: ltr;
  text-align: right;
}

/* Mirror chevrons / arrows in dropdowns and CTAs */
html[dir="rtl"] .card-link svg,
html[dir="rtl"] .btn-primary svg,
html[dir="rtl"] .btn-secondary svg,
html[dir="rtl"] .nav-cta svg,
html[dir="rtl"] [class*="chevron"] svg,
html[dir="rtl"] [class*="arrow"] svg {
  transform: scaleX(-1);
}

/* Calendar / date pickers stay LTR for usability */
html[dir="rtl"] .calendar-grid,
html[dir="rtl"] .week-grid,
html[dir="rtl"] [data-keep-ltr] {
  direction: ltr;
  text-align: left;
}

/* Skip-to-content link */
html[dir="rtl"] .skip-to-content { left: auto; right: 1rem; }

/* Footer social icons keep visual order */
html[dir="rtl"] .footer-social {
  direction: ltr;
}

/* Scroll-top button position */
html[dir="rtl"] .scroll-top {
  right: auto;
  left: 1.5rem;
}

/* Loader stays centered (no change needed) */

/* ============================================
   MOBILE / TABLET REFINEMENTS
   ============================================ */

/* Tablet (≤1024px) — tighter container padding */
@media (max-width: 1024px) {
  .container { padding-left: 1.25rem; padding-right: 1.25rem; }
  .hero h1 { font-size: clamp(2rem, 6vw, 3.5rem); }
}

/* Phone (≤640px) — vertical stacking + full-width buttons */
@media (max-width: 640px) {
  .container { padding-left: 1rem; padding-right: 1rem; }

  /* Two-column nav actions stack */
  .footer-grid { grid-template-columns: 1fr !important; gap: 2rem; }
  .footer-legal { flex-direction: column; gap: 0.5rem; align-items: flex-start; }

  /* Form fields full width */
  .form-row, .form-grid { grid-template-columns: 1fr !important; }

  /* Buttons easier to tap */
  .btn, .btn-primary, .btn-secondary { padding: 0.9rem 1.4rem; font-size: 0.95rem; }

  /* Reduce massive headings */
  h1 { font-size: clamp(1.8rem, 7vw, 2.6rem) !important; line-height: 1.15; }
  h2 { font-size: clamp(1.4rem, 5.5vw, 2rem) !important; line-height: 1.2; }

  /* Tables become scrollable horizontally */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Very small phones (≤380px) */
@media (max-width: 380px) {
  .nav-cta { padding: 0.6rem 0.9rem; font-size: 0.8rem; }
  .lang-toggle, .theme-toggle, .search-toggle { padding: 0.5rem; }
}

/* ============================================
   ACCESSIBILITY — focus rings + reduced motion
   ============================================ */
:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Hide loader animations gracefully when user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
  .loader-bar { animation: none; background: linear-gradient(90deg,#6366f1,#a855f7); width: 100%; }
}

/* ============================================
   PRINT — clean output
   ============================================ */
@media print {
  .nav, .footer, .scroll-top, .chat-widget, .loader, .cookie-banner { display: none !important; }
  body { color: #000; background: #fff; }
  a { color: #000; text-decoration: underline; }
}

/* ============================================
   NAV — chevron arrow as separate toggle button
   The arrow MUST sit inline beside the title (right side),
   never below it. Works on desktop, tablet and mobile.
   ============================================ */
/* Make the dropdown <li> itself a flex row so the anchor and
   the new arrow button are siblings on the SAME line. */
.nav-links li.nav-dropdown {
  display: inline-flex;
  align-items: center;
  gap: 0;
  flex-wrap: nowrap;
}
/* The parent anchor was display:flex (block-level) which pushed
   the new button onto the next row. Force inline-flex. */
.nav-links li.nav-dropdown > a {
  display: inline-flex !important;
  align-items: center;
  gap: 0.35rem;
  flex: 0 1 auto;
}
.nav-dropdown > .dropdown-arrow-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  padding: 6px;
  margin-inline-start: -2px;
  cursor: pointer;
  color: inherit;
  border-radius: 6px;
  line-height: 0;
  vertical-align: middle;
  flex: 0 0 auto;
  align-self: center;
  transition: background 0.2s ease;
}
.nav-dropdown > .dropdown-arrow-btn:hover { background: rgba(255,255,255,0.06); }
.nav-dropdown > .dropdown-arrow-btn:focus-visible {
  outline: 2px solid var(--accent-3, #3ab4e9);
  outline-offset: 2px;
}
.nav-dropdown > .dropdown-arrow-btn > .dropdown-arrow {
  width: 12px; height: 12px; opacity: 0.5;
  transition: transform 0.4s var(--ease-spring, cubic-bezier(0.34,1.56,0.64,1));
}
.nav-dropdown:hover > .dropdown-arrow-btn > .dropdown-arrow,
.nav-dropdown.dropdown-open > .dropdown-arrow-btn > .dropdown-arrow,
.nav-dropdown.mobile-open > .dropdown-arrow-btn > .dropdown-arrow,
.nav-dropdown > .dropdown-arrow-btn[aria-expanded="true"] > .dropdown-arrow {
  transform: rotate(180deg);
  opacity: 1;
}

/* Inside the mobile drawer the <li> turns full-width column so we
   need the anchor to take remaining space and the arrow stays right. */
@media (max-width: 768px) {
  .nav-links li.nav-dropdown {
    display: flex;
    width: 100%;
    align-items: stretch;
  }
  .nav-links li.nav-dropdown > a {
    flex: 1 1 auto;
    min-width: 0;
  }
  .nav-dropdown > .dropdown-arrow-btn {
    padding: 0.75rem 0.9rem;
    margin: 0;
    border-radius: 8px;
  }
  .nav-dropdown > .dropdown-arrow-btn > .dropdown-arrow {
    width: 14px; height: 14px;
  }
}

/* ============================================
   HOMEPAGE — small pagination dots
   (quiz section + "What Leaders Say") on ALL screen sizes
   ============================================ */
.voices-dots {
  padding-left: 0 !important;
  padding-right: 0 !important;
  margin-top: 1rem;
  gap: 0.5rem;
  justify-content: center;
}
.voices-dot {
  width: 6px !important;
  height: 6px !important;
  border-width: 1px !important;
  box-shadow: none !important;
}
.voices-dot.active {
  width: 6px !important;
  height: 6px !important;
  transform: scale(1.5) !important;
  box-shadow: 0 0 6px rgba(58, 180, 233, 0.55) !important;
}
.voices-dot::after,
.voices-dot.active::after { display: none !important; }

/* Quiz progress dots */
.tq-dots { gap: 0.45rem !important; }
.tq-dot { width: 6px !important; height: 6px !important; border-width: 1px !important; }
.tq-dot--in-group {
  width: 7px !important; height: 7px !important;
  box-shadow: 0 0 0 2px rgba(58,180,233,0.08) !important;
}
.tq-dot--answered {
  width: 8px !important; height: 8px !important;
  box-shadow: 0 0 5px rgba(58,180,233,0.4) !important;
}
.tq-dot--answered.tq-dot--in-group {
  width: 9px !important; height: 9px !important;
  box-shadow: 0 0 8px rgba(58,180,233,0.55) !important;
}
.tq-dot--highlighted {
  transform: scale(1.45) !important;
  box-shadow: 0 0 10px rgba(58,180,233,0.7) !important;
}
.tq-dot--answered::after {
  width: 2px !important; height: 4px !important;
  border-width: 1.2px !important;
}

/* ============================================
   HEADER — tablet & mobile refinements
   ============================================ */
@media (max-width: 1024px) {
  .nav { padding-left: 1rem; padding-right: 1rem; }
  .nav-toggle-group { margin-left: 0.25rem; gap: 0; }
  .theme-toggle, .lang-toggle, .search-toggle { width: 36px; height: 36px; }
}
@media (max-width: 768px) {
  /* Slimmer header bar */
  .nav { padding: 0.65rem 1rem; }
  .nav-logo img, .nav-logo svg { max-height: 30px; }
  .nav-logo { font-size: 1rem; }
  /* Mobile drawer — better spacing & scroll */
  .nav-links {
    width: min(86vw, 340px) !important;
    padding: 5rem 1.25rem 2rem !important;
    gap: 0.35rem !important;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: max(2rem, env(safe-area-inset-bottom)) !important;
  }
  .nav-links a {
    font-size: 1rem !important;
    padding: 0.7rem 0.85rem !important;
    border-radius: 8px;
  }
  /* Toggle group lives at the right of the bar; tighten on phones */
  .nav-toggle-group { margin-left: auto; }
  .theme-toggle, .lang-toggle, .search-toggle { width: 38px; height: 38px; }
}
@media (max-width: 480px) {
  .nav { padding: 0.55rem 0.85rem; }
  .nav-logo img, .nav-logo svg { max-height: 26px; }
  .nav-logo span, .nav-logo-text { font-size: 0.95rem; }
  /* Hide search toggle on very small screens to save room */
  .search-toggle { display: none !important; }
}

/* ============================================
   FOOTER — tablet & mobile refinements
   ============================================ */
@media (max-width: 1024px) {
  .footer { padding: 3rem 1rem 1.5rem; margin-top: 3rem; }
  .footer-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 2rem !important;
  }
  .footer-brand { grid-column: 1 / -1; max-width: 100%; }
}
@media (max-width: 640px) {
  .footer { padding: 2.5rem 1rem 1.25rem; margin-top: 2rem; }
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 1.75rem !important;
    margin-bottom: 1.75rem !important;
    text-align: center;
  }
  .footer-brand { max-width: 100%; }
  .footer-brand .nav-logo { justify-content: center; }
  .footer-brand p { margin-left: auto; margin-right: auto; max-width: 320px; }
  .footer-col h4 { margin-bottom: 0.75rem; }
  .footer-col ul { display: flex; flex-direction: column; align-items: center; gap: 0.1rem; }
  .footer-social, .footer-socials, .social-links {
    justify-content: center !important;
    flex-wrap: wrap;
    gap: 0.65rem;
  }
  .footer-contact { text-align: center; }
  .footer-contact ul { align-items: center; }
  /* Footer bottom bar — stack on mobile */
  .footer-bottom {
    flex-direction: column;
    text-align: center;
    gap: 0.75rem;
    padding-top: 1.5rem;
  }
  .footer-legal {
    justify-content: center;
    gap: 0.4rem 0.5rem;
  }
  .footer-legal a { font-size: 0.78rem; }
  .footer-bottom p { font-size: 0.8rem; }
}

/* ============================================
   MOBILE-ONLY POLISH (≤640px)
   ============================================ */
@media (max-width: 640px) {
  section, .section { padding-left: 1rem; padding-right: 1rem; }
  .container { padding-left: 1rem; padding-right: 1rem; }

  .hero h1 { font-size: clamp(1.9rem, 8vw, 2.6rem) !important; line-height: 1.18; }
  .hero p, .hero-sub { font-size: 1rem; line-height: 1.6; }

  .tq-result-glow { width: 100% !important; max-width: 320px; height: 200px !important; filter: blur(60px); }
  .tq-result-card { padding: 1.5rem 1.1rem; }
  .tq-result-header { flex-direction: column; align-items: flex-start; gap: 0.85rem; }
  .tq-result-header-text { text-align: center; width: 100%; }
  .tq-result-badge { width: 88px; height: 88px; margin: 0 auto; }

  .tq-card::after { width: 70px; height: 70px; top: -30px; right: -20px; }
  .tq-section { padding: 3rem 0 2.5rem; }

  .trusted-voices { padding: 0 0.5rem; }
  .voice-text { font-size: 1rem !important; padding-left: 0 !important; padding-right: 0 !important; line-height: 1.7; }
  .voice-text::before { display: none; }
  .voice-quote-mark { display: none !important; }
  .voice-author { padding-left: 0 !important; padding-right: 0 !important; gap: 0.75rem; justify-content: flex-start; }
  .voice-company-logo { width: 40px; height: 40px; }
  .voice-name { font-size: 0.95rem; }
  .voice-role { font-size: 0.78rem; }

  .trusted-logo { padding: 0.45rem 0.9rem; font-size: 0.8rem; }
  .trusted-logo-img, .trusted-logo-placeholder { width: 26px; height: 26px; }

  .features-grid, .services-grid, .solutions-grid, .tier-cards,
  .pricing-grid, .gs-grid { grid-template-columns: 1fr !important; gap: 1rem; }
  .card, .feature-card, .service-card, .solution-card, .tier-card,
  .pricing-card, .glass-card, .gs-card { padding: 1.25rem !important; }

  .hero-cta, .hero-actions, .cta-row, .btn-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  .hero-cta .btn, .cta-row .btn, .btn-row .btn { width: 100%; justify-content: center; }

  .form-group { margin-bottom: 0.85rem; }
  .form-grid, .form-row, .auth-grid { grid-template-columns: 1fr !important; gap: 0.85rem; }
  .auth-input, .form-input, input[type="text"], input[type="email"], input[type="tel"],
  input[type="password"], input[type="number"], input[type="url"], textarea, select {
    width: 100%;
    box-sizing: border-box;
  }

  .modal, .quiz-modal, .auth-modal {
    width: 94% !important;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.25rem !important;
  }
  /* tier-modal is a full-screen overlay — do not constrain it */
  .tier-modal {
    width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  .profile-hero-chips { flex-wrap: wrap; gap: 0.4rem; }
  .profile-chip { font-size: 0.78rem; padding: 0.3rem 0.6rem; }
  .profile-edit-grid { grid-template-columns: 1fr !important; }

  .comm-toolbar { flex-wrap: wrap; gap: 0.5rem; }
  .comm-thread-header { flex-wrap: wrap; }
  .comm-thread-admin { width: 100%; justify-content: flex-end; }
  .comm-reply-form { flex-direction: column; align-items: stretch; }
  .comm-reply-form .btn { width: 100%; }

  table { display: block; overflow-x: auto; max-width: 100%; }
  code, pre, .mono { word-break: break-word; }
}

@media (max-width: 380px) {
  .hero h1 { font-size: clamp(1.7rem, 9vw, 2.2rem) !important; }
  .voices-nav { display: none !important; }
}

/* ============================================
   RTL — MOBILE / TABLET OVERRIDES
   Mirrors the English mobile layout for Arabic.
   All layout-flipping rules are scoped to [dir="rtl"].
   ============================================ */

/* ── Toggle group: swap border-radius for RTL (desktop, >1024px) ── */
html[dir="rtl"] .search-toggle { border-radius: 0 10px 10px 0; }
html[dir="rtl"] .lang-toggle   { border-radius: 10px 0 0 10px; }

/* ── Nav drawer: slide from LEFT in RTL (English slides from right) ── */
/* style.css uses  html .nav-links { right: -100% }  with specificity 0,0,1,1.
   html[dir="rtl"] raises that to 0,1,1,1 so it wins cleanly. */
@media (max-width: 1024px) {
  html[dir="rtl"] .nav-links {
    right: auto !important;
    left: -100% !important;
    transition: left var(--transition-med) !important;
  }
  html[dir="rtl"] .nav-links.open {
    left: 0 !important;
    right: auto !important;
  }
}

/* ── Footer accordion tabs: mirror heading alignment & chevron gap ── */
/* At ≤768px the footer becomes a 3-col accordion grid (style.css ~8571).
   LTR: col-2 left-aligns, col-4 right-aligns. RTL must mirror these. */
@media (max-width: 768px) {
  /* Col-2 (leftmost in LTR → rightmost in RTL grid): align right */
  html[dir="rtl"] .footer-col:nth-child(2) > h4 { justify-content: flex-end; }
  /* Col-3 stays centered — no change needed */
  /* Col-4 (rightmost in LTR → leftmost in RTL grid): align left */
  html[dir="rtl"] .footer-col:nth-child(4) > h4 { justify-content: flex-start; }

  /* Chevron pseudo-element: gap goes on the RIGHT side in RTL
     (chevron appears to the left of the label text in RTL flex row) */
  html[dir="rtl"] .footer-col h4::after {
    margin-left: 0;
    margin-right: 5px;
  }

  /* Link text alignment inside accordion panels */
  html[dir="rtl"] .footer-col:nth-child(2) > ul a {
    text-align: right !important;
    padding-right: 0.9rem;
    padding-left: 0;
  }
  /* Col-3 center stays center — no override needed */
  html[dir="rtl"] .footer-col:nth-child(4) > ul a {
    text-align: left !important;
    padding-left: 0.9rem;
    padding-right: 0;
  }

  /* Footer legal 2-col grid: anchor items from the right edge in RTL */
  html[dir="rtl"] .footer-legal { justify-items: end; }

  /* Hero button group (about/mission/vision/values/goals): align to right (reading start) */
  html[dir="rtl"] .about-btns {
    align-items: flex-end !important;
  }
}

/* ── Tier quiz card: override hard-coded text-align:left in home.css ── */
html[dir="rtl"] .tq-opt                { text-align: right; }
html[dir="rtl"] .tq-result-label       { text-align: right; }
html[dir="rtl"] .tq-result-name        { text-align: right; }
html[dir="rtl"] .tq-result-header-text { text-align: right; }
html[dir="rtl"] .tq-score-name         { text-align: right; }
/* On ≤640px the result card header is forced to center (existing rule) — no conflict. */

/* ── Tier package modal: hardware comparison table ── */
/* home.css forces text-align:left on th/td; in RTL flip to right */
html[dir="rtl"] .tm-hardware-table th,
html[dir="rtl"] .tm-hardware-table td { text-align: right; }
/* The LTR last-child is right-aligned as a "value" column; in RTL flip to left */
html[dir="rtl"] .tm-hardware-table td:last-child { text-align: left; }

/* ── Services upgrade flow: RTL scroll starts from right ── */
@media (max-width: 768px) {
  html[dir="rtl"] .services-upgrade-flow { direction: rtl; }
}

/* ── Very small phones (≤380px) RTL ── */
@media (max-width: 380px) {
  html[dir="rtl"] .nav-logo span,
  html[dir="rtl"] .nav-logo-text { font-size: 0.9rem; }
}
