/* ==========================================================================
   NEXORA — Header / navigation / tooltips  (single source of truth)
   --------------------------------------------------------------------------
   Replaces the stacked, conflicting navigation patches that used to live in
   style.css, nexora-extra.css and nexora-ui-enhancements.css.

   Layout model (logical properties only → identical in RTL and LTR):
     ≥ 1280px   brand | links (centred) | actions
     < 1280px   brand | actions (+ menu button); links open in a dropdown panel
   The same rules cover desktop, phones, and phone "Desktop site" mode (~980px).
   ========================================================================== */

/* ---------- Header shell ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--hero-bg-op);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.topbar .nav {
  width: min(1240px, calc(100% - 32px));
  margin-inline: auto;
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  position: relative;
}

/* ---------- Brand (header + footer) ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  flex: 0 1 auto;
  color: var(--text);
}
.brand img {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 50%;
  box-shadow: 0 0 14px rgba(41, 182, 255, .45);
}
.brand-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: .6px;
  line-height: 1.2;
}
.brand-name strong { font-weight: 800; letter-spacing: .14em; font-size: 1.05rem; }
.brand-name small,
.brand-name .brand-sub {
  display: block;
  margin: 2px 0 0;
  font-size: .66rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.35;
  color: var(--muted);
  white-space: nowrap;
}
/* Footer brand keeps a simple inline look */
.footer .brand-name { display: block; font-size: 1rem; }
.footer .brand-name small { display: block; white-space: normal; }

/* ---------- Desktop links ---------- */
.navlinks {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px 20px;
  flex: 1 1 auto;
  min-width: 0;
}
.navlinks a {
  position: relative;
  padding: 8px 2px;
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text);
  transition: color .2s ease;
}
.navlinks a::after {
  content: '';
  position: absolute;
  inset-inline: 2px;
  bottom: 2px;
  height: 2px;
  border-radius: 2px;
  background: var(--cyan);
  transform: scaleX(0);
  transition: transform .2s ease;
}
.navlinks a:hover,
.navlinks a:focus-visible,
.navlinks a.active { color: var(--cyan); }
.navlinks a.active::after,
.navlinks a:hover::after { transform: scaleX(1); }
.navlinks .nav-cta-mobile { display: none; }

/* ---------- Actions ---------- */
.nav-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
}
.action-icon-btn,
.lang-btn,
.menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: .86rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color .2s ease, background-color .2s ease, border-color .2s ease, transform .15s ease;
}
.action-icon-btn:hover,
.lang-btn:hover,
.menu-btn:hover,
.action-icon-btn:focus-visible,
.lang-btn:focus-visible,
.menu-btn:focus-visible {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(41, 182, 255, .1);
}
.action-icon-btn:active,
.lang-btn:active,
.menu-btn:active { transform: scale(.95); }
.nav-actions .nav-cta { white-space: nowrap; margin-inline-start: 2px; }

/* Hamburger icon (pure CSS: no font dependency) */
.menu-btn { display: none; }
.menu-bars { position: relative; display: block; width: 18px; height: 14px; }
.menu-bars i {
  position: absolute;
  inset-inline: 0;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform .22s ease, opacity .18s ease, top .22s ease;
}
.menu-bars i:nth-child(1) { top: 0; }
.menu-bars i:nth-child(2) { top: 6px; }
.menu-bars i:nth-child(3) { top: 12px; }
.menu-btn.is-open .menu-bars i:nth-child(1) { top: 6px; transform: rotate(45deg); }
.menu-btn.is-open .menu-bars i:nth-child(2) { opacity: 0; }
.menu-btn.is-open .menu-bars i:nth-child(3) { top: 6px; transform: rotate(-45deg); }

/* ---------- Tooltip (floating, positioned by main.js) ---------- */
.nx-tip {
  position: fixed;
  z-index: 3000;
  left: 0;
  top: 0;
  width: max-content;
  padding: 8px 12px;
  border: 1px solid rgba(41, 182, 255, .45);
  border-radius: 10px;
  background: #0B1830;
  color: #F1F6FF;
  font-size: .76rem;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity .16s ease, transform .16s ease, visibility .16s;
}
.nx-tip.is-visible { opacity: 1; visibility: visible; transform: none; }
.nx-tip::before {
  content: '';
  position: absolute;
  left: var(--arrow-x, 50%);
  top: -6px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background: #0B1830;
  border-left: 1px solid rgba(41, 182, 255, .45);
  border-top: 1px solid rgba(41, 182, 255, .45);
  transform: rotate(45deg);
}
.nx-tip.is-above::before { top: auto; bottom: -6px; transform: rotate(225deg); }
:root[data-theme="light"] .nx-tip,
:root[data-theme="light"] .nx-tip::before { background: #0F172A; }

/* ---------- Light theme header ---------- */
:root[data-theme="light"] .topbar { background: rgba(255, 255, 255, .9); border-bottom-color: rgba(15, 23, 42, .16); }
:root[data-theme="light"] .brand-name small,
:root[data-theme="light"] .brand-name .brand-sub { color: #334155; }
:root[data-theme="light"] .navlinks a { color: #0F172A; }
:root[data-theme="light"] .navlinks a:hover,
:root[data-theme="light"] .navlinks a.active { color: #0369A1; }
:root[data-theme="light"] .action-icon-btn,
:root[data-theme="light"] .lang-btn,
:root[data-theme="light"] .menu-btn { background: #fff; border-color: #94A3B8; color: #0F172A; }

/* ==========================================================================
   Compact layout (< 1280px): tablets, phones and phone "Desktop site" mode
   ========================================================================== */
@media (max-width: 1279px) {
  .topbar .nav { min-height: 68px; }
  .nav-actions .nav-cta { display: none; }
  .menu-btn { display: inline-flex; }

  .navlinks {
    position: absolute;
    inset-inline: 0;
    top: calc(100% + 8px);
    z-index: 70;
    display: none;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card);
    box-shadow: var(--shadow);
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }
  .navlinks.open { display: flex; }
  .navlinks a {
    padding: 13px 12px;
    font-size: 1rem;
    border-radius: 10px;
    border-bottom: 1px solid var(--line);
  }
  .navlinks a:last-of-type { border-bottom: 0; }
  .navlinks a::after { display: none; }
  .navlinks a.active { background: rgba(41, 182, 255, .1); }
  .navlinks .nav-cta-mobile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    padding: 13px 16px;
    border-bottom: 0;
    color: #04101b;
    text-align: center;
  }
  .navlinks .nav-cta-mobile:hover { color: #04101b; }
}

@media (max-width: 560px) {
  .topbar .nav { width: calc(100% - 20px); gap: 8px; min-height: 62px; }
  .brand { gap: 8px; }
  .brand img { width: 46px; height: 46px; }
  .brand-name strong { font-size: .95rem; letter-spacing: .12em; }
  .brand-name .brand-sub {
    font-size: .54rem;
    white-space: normal;
    max-width: 112px;
    line-height: 1.3;
  }
  .nav-actions { gap: 5px; }
  .action-icon-btn,
  .lang-btn,
  .menu-btn { min-width: 34px; height: 34px; padding: 0 6px; border-radius: 10px; font-size: .78rem; }
}

/* Very narrow phones: logo + wordmark only; the full company name stays in the hero. */
@media (max-width: 380px) {
  .brand-name .brand-sub { display: none; }
  .nav-actions { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .nx-tip, .menu-bars i, .navlinks a::after { transition: none; }
}

/* ---------- Primary buttons in light mode: readable text on the whole gradient ---------- */
:root[data-theme="light"] .btn-primary {
  color: #fff;
  background: linear-gradient(110deg, #0369A1, #0284C7 55%, #0EA5E9);
  box-shadow: 0 8px 22px rgba(3, 105, 161, .25);
}
:root[data-theme="light"] .navlinks .nav-cta-mobile,
:root[data-theme="light"] .navlinks .nav-cta-mobile:hover { color: #fff; }
/* ---------- Floating controls (same place in Arabic/English, phone/tablet/desktop) ----------
   Left column : sound button (bottom) with the recitation prompt stacked directly above it.
   Right column: back-to-top button.
   --nxc-h is set by nexora-consent.js while the cookie banner is open, so nothing hides behind it. */
:root { --nx-float-gap: 24px; --nx-float-base: calc(max(var(--nx-float-gap), env(safe-area-inset-bottom, 0px)) + var(--nxc-h, 0px)); }
.sound-btn  { left: max(var(--nx-float-gap), env(safe-area-inset-left, 0px)); right: auto; bottom: var(--nx-float-base); }
.audio-toast { left: max(var(--nx-float-gap), env(safe-area-inset-left, 0px)); right: auto; bottom: calc(var(--nx-float-base) + 62px); }
.backtop    { right: max(var(--nx-float-gap), env(safe-area-inset-right, 0px)); left: auto; bottom: var(--nx-float-base); }
.sound-btn.is-loading i { animation: none; }

/* ---------- Light mode: the dark hero photograph must not sit behind dark text ---------- */
:root[data-theme="light"] body:before { opacity: .2; filter: saturate(.6) brightness(1.5); }
:root[data-theme="light"] .hero-copy,
:root[data-theme="light"] .hero p { color: #1E293B; }
:root[data-theme="light"] .audio-toast-btn { background: #0369A1; color: #fff; }

/* Phones: the logo file has a wide black margin around its ring, so at header size the emblem
   looked small and cramped. Scale it so the ring fills the circle; glow comes from the ring itself. */
@media (max-width: 560px) {
  /* clip-path مع transform على صورة decoding=async يظهر فارغًا في بعض متصفحات الجوال (iOS Safari خصوصًا)؛
     استُبدل بدائرة border-radius وتكبير بسيط، وثُبّت الحجم لمنع انكماش الصورة. */
  .topbar .brand img {
    display: block;
    width: 46px;
    height: 46px;
    min-width: 46px;
    flex: 0 0 46px;
    opacity: 1;
    visibility: visible;
    border-radius: 50%;
    box-shadow: none;
    transform: scale(1.15);
    clip-path: none;
  }
}

/* ---------- Smooth scrolling ----------
   Below-the-fold sections are skipped by layout/paint until they approach the viewport. */
.section:not(#home) { content-visibility: auto; contain-intrinsic-size: auto 700px; }
/* Touch devices (including a phone's "Desktop site" mode): no animated backdrop or heavy blur. */
html.nx-touch body:before { animation: none; will-change: auto; }
html.nx-touch .topbar { -webkit-backdrop-filter: none; backdrop-filter: none; }
