/* =========================================================
   AFAR CULTURE GLOBAL MOBILE RESPONSIVE RECOVERY
   Safe final override loaded after page CSS.
   Fixes mobile overflow caused by large hero cards/buttons.
   ========================================================= */

*, *::before, *::after { box-sizing: border-box !important; }
html, body { width: 100% !important; max-width: 100% !important; overflow-x: hidden !important; }
img, svg, video, canvas, iframe { max-width: 100% !important; height: auto; }
body { -webkit-text-size-adjust: 100%; }

/* Keep all common containers inside the viewport */
.container,
.container-fluid,
section > .container,
header > .container,
.hero > .container,
.section-hero > .container,
.platform-hero-sub > .container,
.tourism-hero > .container,
.about-hero > .container,
.culture-hero > .container,
.customs-hero > .container,
.gallery-hero > .container,
.contact-hero > .container,
.page-hero > .container {
  max-width: min(100% - 28px, 1180px) !important;
  width: min(100% - 28px, 1180px) !important;
  margin-left: auto !important;
  margin-right: auto !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

/* Navbar: prevent brand/nav/language overflow on phones */
@media (max-width: 991.98px) {
  .navbar,
  .site-navbar,
  .main-navbar {
    min-height: auto !important;
    padding: 10px 0 !important;
    overflow: visible !important;
  }

  .navbar > .container,
  .site-navbar > .container,
  .main-navbar > .container {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
    width: min(100% - 24px, 1140px) !important;
    max-width: min(100% - 24px, 1140px) !important;
  }

  .navbar-brand,
  .brand-modern {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: calc(100% - 62px) !important;
    width: auto !important;
    display: inline-flex !important;
    align-items: center !important;
    overflow: hidden !important;
  }

  .navbar-brand img,
  .brand-main-logo,
  .brand-modern img {
    flex: 0 0 52px !important;
    width: 52px !important;
    height: 52px !important;
    max-width: 52px !important;
    max-height: 52px !important;
    object-fit: contain !important;
  }

  .brand-name,
  .navbar-brand strong,
  .navbar-brand .brand-name {
    display: block !important;
    color: #fff !important;
    font-size: clamp(1rem, 5vw, 1.35rem) !important;
    line-height: 1.05 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .brand-sub,
  .navbar-brand small,
  .navbar-brand .brand-sub {
    display: block !important;
    color: #ffd700 !important;
    font-size: clamp(.48rem, 2.4vw, .68rem) !important;
    line-height: 1.1 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    letter-spacing: .12em !important;
  }

  .navbar-toggler {
    flex: 0 0 46px !important;
    width: 46px !important;
    height: 46px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-left: auto !important;
  }

  .navbar-collapse {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    position: static !important;
    margin-top: 10px !important;
    padding: 12px !important;
    border-radius: 18px !important;
    background: #05283d !important;
    overflow-y: auto !important;
    max-height: 76vh !important;
  }

  .navbar-collapse .navbar-nav,
  .navbar-nav {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 7px !important;
    align-items: stretch !important;
  }

  .navbar .nav-link,
  .navbar-collapse .nav-link {
    width: 100% !important;
    min-height: 42px !important;
    padding: 11px 14px !important;
    border-radius: 12px !important;
    text-align: left !important;
    white-space: normal !important;
    line-height: 1.2 !important;
  }

  .language-selector,
  .lang-switcher,
  .navbar .language-selector {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    gap: 8px !important;
    margin-top: 8px !important;
  }

  .language-selector a,
  .lang-switcher a,
  .lang-btn {
    flex: 0 1 auto !important;
    max-width: 100% !important;
    white-space: nowrap !important;
  }
}

/* Hero and glass-card recovery */
@media (max-width: 767.98px) {
  .hero,
  header.hero,
  .section-hero,
  .platform-hero-sub,
  .tourism-hero,
  .about-hero,
  .culture-hero,
  .customs-hero,
  .gallery-hero,
  .contact-hero,
  .page-hero {
    display: block !important;
    min-height: auto !important;
    height: auto !important;
    padding: 56px 0 92px !important;
    overflow: hidden !important;
  }

  .hero .row,
  .hero-row,
  .hero-grid,
  .section-hero-grid,
  .platform-hero-grid,
  .tourism-hero-grid,
  .about-hero-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 18px !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .hero-glass,
  .hero-card,
  .hero-content,
  .hero-text,
  .platform-hero-card,
  .section-hero-card,
  .tourism-hero-card,
  .about-hero-card,
  .culture-hero-card,
  .customs-hero-card,
  .gallery-hero-card,
  .contact-hero-card,
  .qafar-hero-card,
  .qafaraf-hero-card {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: clamp(20px, 6vw, 28px) !important;
    border-radius: 24px !important;
    transform: none !important;
    left: auto !important;
    right: auto !important;
  }

  .hero h1,
  .section-hero h1,
  .platform-hero-sub h1,
  .hero-glass h1,
  .hero-card h1,
  .hero-text h1,
  .hero-text h2,
  .platform-hero-card h1 {
    font-size: clamp(2.15rem, 13vw, 3.9rem) !important;
    line-height: .98 !important;
    letter-spacing: -0.055em !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
  }

  .hero p,
  .section-hero p,
  .platform-hero-sub p,
  .hero-glass p,
  .hero-card p,
  .hero-text p,
  .platform-hero-card p {
    font-size: clamp(1rem, 5.2vw, 1.2rem) !important;
    line-height: 1.55 !important;
    overflow-wrap: anywhere !important;
  }

  .hero-actions,
  .hero-buttons,
  .hero-quick-tools,
  .platform-hero-actions,
  .section-hero-actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-top: 22px !important;
  }

  .hero-actions a,
  .hero-actions button,
  .hero-buttons a,
  .hero-buttons button,
  .hero-quick-tools a,
  .hero-quick-tools button,
  .platform-hero-actions a,
  .section-hero-actions a {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 48px !important;
    justify-content: center !important;
    text-align: center !important;
    white-space: normal !important;
  }

  /* The Updates button should not become a flex child that pushes the hero sideways. */
  .afc-hero-updates-host { position: relative !important; }
  .afc-hero-updates-corner {
    position: absolute !important;
    left: 18px !important;
    right: 18px !important;
    top: auto !important;
    bottom: 18px !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    display: flex !important;
    justify-content: center !important;
    z-index: 80 !important;
    pointer-events: none !important;
  }
  .afc-hero-updates-link {
    pointer-events: auto !important;
    width: 100% !important;
    max-width: 390px !important;
    min-height: 48px !important;
    padding: 12px 16px !important;
    border-radius: 999px !important;
    font-size: .96rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
}

@media (max-width: 420px) {
  .container,
  .container-fluid,
  section > .container,
  header > .container,
  .hero > .container,
  .section-hero > .container,
  .platform-hero-sub > .container,
  .tourism-hero > .container,
  .about-hero > .container,
  .culture-hero > .container,
  .customs-hero > .container,
  .gallery-hero > .container,
  .contact-hero > .container,
  .page-hero > .container {
    width: min(100% - 22px, 1180px) !important;
    max-width: min(100% - 22px, 1180px) !important;
  }

  .hero-glass,
  .hero-card,
  .hero-content,
  .hero-text,
  .platform-hero-card,
  .section-hero-card,
  .tourism-hero-card,
  .about-hero-card,
  .culture-hero-card,
  .customs-hero-card,
  .gallery-hero-card,
  .contact-hero-card {
    padding: 20px !important;
    border-radius: 22px !important;
  }

  .hero h1,
  .section-hero h1,
  .platform-hero-sub h1,
  .hero-glass h1,
  .hero-card h1,
  .hero-text h1,
  .hero-text h2,
  .platform-hero-card h1 {
    font-size: clamp(2rem, 12.4vw, 3.2rem) !important;
  }
}

/* Qafar-Af page has very specific hero rules; keep it safe on phones. */
@media (max-width: 767.98px) {
  body:has(.qafaraf-nav-logo) .hero {
    padding: 52px 0 92px !important;
    min-height: auto !important;
  }
  body:has(.qafaraf-nav-logo) .hero .container.hero-grid,
  body:has(.qafaraf-nav-logo) .hero-grid {
    width: min(100% - 26px, 760px) !important;
    max-width: min(100% - 26px, 760px) !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    padding: 14px !important;
    gap: 14px !important;
    margin-inline: auto !important;
  }
  body:has(.qafaraf-nav-logo) .hero-text,
  body:has(.qafaraf-nav-logo) .hero-panel {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
  }
}

/* If :has is unsupported, these generic Qafar-Af selectors still prevent overflow. */
@media (max-width: 767.98px) {
  .qafaraf-nav-logo ~ .navbar-toggler,
  .qafaraf-nav-logo-mobile ~ .navbar-toggler { margin-left: 0 !important; }
  .hero .container.hero-grid {
    max-width: min(100% - 26px, 1320px) !important;
  }
}
