/* ============================================================
   Asira — global mobile responsive overrides
   Loaded LAST so it wins specificity battles with inline styles.
   Targets common patterns: 2-col grids, hero sections, illustrations,
   project rows, paddings, font sizes.

   Breakpoints:
     >980px   — desktop (default)
     880-980  — tablet-leaning desktop (hamburger menu kicks in at 980px)
     481-880  — tablet / large mobile (most overrides start here)
     <=480    — small mobile
     <=380    — tiny mobile
============================================================ */

/* ---------- Universal mobile safety net ---------- */
@media (max-width: 880px) {
  html, body { overflow-x: hidden; max-width: 100vw; }
  *, *::before, *::after { box-sizing: border-box; }
  img, svg, video, canvas, iframe { max-width: 100%; height: auto; }
  /* CRITICAL: grid/flex items must shrink — prevents text/dashboard overflow */
  [style*="display:grid"] > *,
  [style*="display: grid"] > * { min-width: 0; }
  /* Anything inside containers cannot overflow */
  .container { padding-left: 16px !important; padding-right: 16px !important; max-width: 100% !important; }
  .container > *, section > * { max-width: 100%; }
  .section { padding: 48px 0 !important; }
  section[style*="padding:"] { padding-top: 40px !important; padding-bottom: 40px !important; }
  /* Long Arabic words (e.g. "MedMax") should never push their parent wide */
  h1, h2, h3, h4, p, span, a, strong, em {
    overflow-wrap: anywhere;
    word-break: normal;
  }
  /* Tighter body line-height so dense Arabic paragraphs don't waste vertical space */
  body { font-size: 15px; line-height: 1.7; }
}

/* ---------- Stack any 2-3 column grid ---------- */
@media (max-width: 880px) {
  /* Inline grid layouts that use 1fr 1fr or 1fr X.Yfr stacks */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1.1fr"],
  [style*="grid-template-columns: 1fr 1.2fr"],
  [style*="grid-template-columns: 1fr 1.4fr"],
  [style*="grid-template-columns: 1.05fr 1fr"],
  [style*="grid-template-columns: 1.1fr 1fr"],
  [style*="grid-template-columns: 1.2fr 1fr"],
  [style*="grid-template-columns: 1.4fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 28px !important;
  }
  /* 4-col stat / step rows: 2x2 on mobile */
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px !important;
  }
  /* 5-col how-we-work flow */
  [style*="grid-template-columns: repeat(5, 1fr)"],
  [style*="grid-template-columns:repeat(5,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px !important;
  }
  /* Inline padding cleanups (huge cards on desktop become unusable on mobile) */
  [style*="padding: 56px"],
  [style*="padding:56px"] { padding: 24px !important; }
  [style*="padding: 40px"],
  [style*="padding:40px"] { padding: 22px !important; }
  [style*="padding: 36px"],
  [style*="padding:36px"] { padding: 20px !important; }
  [style*="padding:40px 44px"] { padding: 22px !important; }
  /* Excessive gaps */
  [style*="gap:56px"],
  [style*="gap: 56px"] { gap: 24px !important; }
  [style*="gap:48px"],
  [style*="gap: 48px"] { gap: 22px !important; }
  [style*="gap:40px"],
  [style*="gap: 40px"] { gap: 20px !important; }
}

/* ---------- Hero typography ---------- */
@media (max-width: 880px) {
  h1, .hero h1, section h1 {
    font-size: clamp(26px, 7vw, 36px) !important;
    line-height: 1.25 !important;
    letter-spacing: -0.01em !important;
    word-break: normal;
    overflow-wrap: break-word;
    margin-bottom: 14px !important;
  }
  h2, .hero h2, section h2 {
    font-size: clamp(22px, 5.8vw, 30px) !important;
    line-height: 1.3 !important;
    letter-spacing: -0.005em !important;
    word-break: normal;
    overflow-wrap: break-word;
  }
  h3 { font-size: clamp(17px, 4.4vw, 21px) !important; line-height: 1.4 !important; }
  h4 { font-size: 16px !important; }
  .lead,
  p.lead {
    font-size: 15px !important;
    line-height: 1.75 !important;
    color: var(--text-2) !important;
  }
  .section-head { margin-bottom: 28px !important; }
  /* Hero CTAs: full-width on small mobile so primary action stands out */
  .hero-cta,
  [style*="display:flex; gap:14px"],
  [style*="display:flex; gap:12px"] {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
  }
  .btn.btn-lg { padding: 13px 20px !important; font-size: 14.5px !important; min-height: 46px; }
  .btn { padding: 11px 18px !important; font-size: 13.5px !important; min-height: 42px; display: inline-flex !important; align-items: center; justify-content: center; }
  /* Make the first/primary button take full width on tiny screens for clearer CTA */
}
@media (max-width: 480px) {
  .hero-cta .btn:first-child,
  [style*="display:flex; gap:14px"] > .btn-primary:first-child {
    flex: 1 1 100%;
  }
}
@media (max-width: 880px) {
  /* Hero stat counters: 3 columns that breathe, with a soft separator */
  [style*="display:flex; gap:32px"] {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 12px !important;
    padding: 18px 0 !important;
    border-top: 1px solid var(--border) !important;
    margin-top: 28px !important;
    text-align: center;
  }
  [style*="display:flex; gap:32px"] > div { text-align: center; }
}

/* ---------- HTML/CSS illustrations (.ill scenes) ---------- */
@media (max-width: 880px) {
  .ill {
    width: 100%;
    max-width: 100%;
    border-radius: 14px;
    padding: 6px;
  }
  .ill__chrome { padding: 4px 8px 6px; }
  .ill__chrome .url {
    font-size: 9.5px;
    padding: 2px 8px;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Hide complex admin scenes' sidebar, show only main content */
  .scene-admin {
    grid-template-columns: 1fr !important;
    min-height: 320px !important;
  }
  .scene-admin .side { display: none !important; }
  .scene-admin .main { padding: 10px !important; gap: 8px !important; }
  .scene-admin .kpis { grid-template-columns: repeat(3, 1fr) !important; gap: 6px !important; }
  .scene-admin .kpi { padding: 8px !important; }
  .scene-admin .kpi .val { font-size: 14px !important; }
  .scene-admin .kpi .lbl { font-size: 9px !important; }
  .scene-admin .kpi .delta { font-size: 8.5px !important; top: 6px !important; right: 6px !important; }
  .scene-admin .bars { height: 80px !important; }
  .scene-admin .line-wrap { height: 80px !important; }
  .scene-admin .card-chart { padding: 9px !important; }
  .scene-admin .row2 { grid-template-columns: 1fr !important; gap: 6px !important; }

  /* Website-preview scene: smaller hero */
  .scene-site .hero-area { grid-template-columns: 1fr !important; gap: 14px !important; padding: 14px !important; }
  .scene-site .cards-row { grid-template-columns: 1fr !important; padding: 0 14px 14px !important; }
  .scene-site .nav { padding: 10px 14px !important; }
  .scene-site .nav .links { display: none !important; }
  .scene-site .hero-text h2 { font-size: 16px !important; }
  .scene-site .hero-img { aspect-ratio: 16/9; }

  /* Phone mockup scene: scale phone smaller */
  .scene-phone-bg { padding: 20px 0 !important; min-height: 360px !important; }
  .phone { width: 200px !important; }
  .scene-phone-bg::before { width: 200px !important; height: 200px !important; }

  /* AI chat scene */
  .scene-ai { min-height: 340px !important; padding: 12px !important; gap: 8px !important; }
  .scene-ai .msg { max-width: 92% !important; }
  .scene-ai .msg .bubble { font-size: 10.5px !important; padding: 8px 10px !important; }

  /* Bot/WhatsApp scene */
  .scene-bot { min-height: 360px !important; }
  .scene-bot .head { padding: 8px 10px !important; }
  .scene-bot .body { padding: 10px !important; gap: 4px !important; }
  .scene-bot .b { font-size: 10.5px !important; padding: 6px 9px !important; max-width: 85% !important; }

  /* Integration flow */
  .scene-flow { min-height: 320px !important; padding: 14px !important; }
  .scene-flow .stage { min-height: 280px !important; }
  .scene-flow .hub { width: 70px !important; height: 70px !important; }
  .scene-flow .hub .mk { font-size: 20px !important; }
  .scene-flow .hub .lb { font-size: 8.5px !important; }
  .scene-flow .node { padding: 6px 8px !important; font-size: 10px !important; }
  .scene-flow .node .ic { width: 22px !important; height: 22px !important; }
  .scene-flow .node .meta b { font-size: 9.5px !important; }
  .scene-flow .node .meta span { font-size: 8px !important; }
  .scene-flow .node.n3, .scene-flow .node.n4 { display: none !important; }
  .scene-flow .tip { font-size: 9.5px !important; padding: 4px 10px !important; }

  /* Smart home (Bayt) */
  .scene-smart { padding: 12px !important; min-height: 320px !important; }
  .scene-smart .rooms { gap: 6px !important; }
  .scene-smart .room { padding: 8px !important; }
  .scene-smart .room .val { font-size: 14px !important; }
  .scene-smart .room .ic { width: 24px !important; height: 24px !important; }

  /* Kanban / TaskFlow */
  .scene-kanban { padding: 10px !important; }
  .scene-kanban .cols { grid-template-columns: 1fr !important; }
  .scene-kanban .col { padding: 8px !important; }

  /* Menu / Cafe */
  .scene-menu { padding: 12px !important; }
  .scene-menu .items { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .scene-menu .item .img { height: 60px !important; }

  /* HR grid */
  .scene-hr { padding: 12px !important; }
  .scene-hr .stats { grid-template-columns: repeat(3, 1fr) !important; gap: 6px !important; }
  .scene-hr .grid { grid-template-columns: repeat(2, 1fr) !important; gap: 6px !important; }
  .scene-hr .stat { padding: 8px !important; }
  .scene-hr .stat b { font-size: 14px !important; }
  .scene-hr .emp { padding: 8px !important; }

  /* Delivery map */
  .scene-map .info { padding: 9px 11px !important; min-width: 160px !important; }
  .scene-map .info b { font-size: 11px !important; }
  .scene-map .pin { font-size: 10px !important; padding: 5px 8px !important; }
  .scene-map .truck { width: 48px !important; height: 48px !important; }

  /* Education / EduSpark */
  .scene-edu .phone { width: 190px !important; }
  .scene-edu::before { width: 180px !important; height: 180px !important; }
}

/* ---------- Project showcase rows (projects.html) ---------- */
@media (max-width: 880px) {
  .project-row {
    grid-template-columns: 1fr !important;
  }
  .project-row .visual {
    padding: 18px !important;
    min-height: auto !important;
  }
  .project-row .body {
    padding: 22px !important;
  }
  .project-row .body h3 { font-size: 18px !important; }
}

/* ---------- Header / navigation ---------- */
@media (max-width: 980px) {
  .site-header .nav-links { display: none !important; }
  .site-header .menu-toggle { display: inline-flex !important; }
  .site-header .nav-cta .btn:not(.menu-toggle) { display: none !important; }
  .site-header .brand .logo { height: 32px !important; max-width: 140px !important; }
  .site-header .nav { padding: 12px 0 !important; height: 64px !important; }
  :root { --header-h: 64px; }
  .menu-toggle {
    width: 44px !important; height: 44px !important;
    border-radius: 12px !important;
    background: #fff !important;
    border: 1px solid var(--border) !important;
    color: var(--asira-navy) !important;
  }
  .menu-toggle:active { background: var(--bg-soft) !important; }
  /* Mobile menu polish: bigger touch targets, subtle dividers, smooth open */
  .mobile-menu {
    padding: 10px !important;
    box-shadow: 0 16px 40px rgba(11,36,71,.12) !important;
    border-radius: 0 0 16px 16px;
  }
  .mobile-menu a {
    padding: 14px 16px !important;
    font-size: 15.5px !important;
    border-radius: 10px !important;
    color: var(--text) !important;
    font-weight: 600 !important;
  }
  .mobile-menu a + a { margin-top: 2px; }
}
@media (max-width: 480px) {
  .site-header .brand .logo { height: 28px !important; max-width: 110px !important; }
}

/* ---------- Footer ---------- */
@media (max-width: 640px) {
  .footer-grid { grid-template-columns: 1fr !important; gap: 24px !important; }
  .footer-bottom { flex-direction: column !important; gap: 8px !important; text-align: center !important; }
}

/* ---------- Service cards ---------- */
@media (max-width: 640px) {
  .service-card { padding: 22px 18px !important; }
  .service-card .icon { width: 44px !important; height: 44px !important; }
  .service-card h3 { font-size: 16.5px !important; }
}

/* ---------- Sliders (swiper) navigation hidden on small screens ---------- */
@media (max-width: 640px) {
  .swiper-button-next,
  .swiper-button-prev { display: none !important; }
}

/* ---------- Forms ---------- */
@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr !important; }
  input, textarea, select { font-size: 16px !important; /* prevents iOS auto-zoom */ }
}

/* ---------- CTA banner ---------- */
@media (max-width: 768px) {
  .cta-banner {
    grid-template-columns: 1fr !important;
    text-align: center !important;
    padding: 28px 22px !important;
  }
  .cta-banner .actions { justify-content: center !important; flex-wrap: wrap !important; }
}

/* ---------- Tiny screens — extra defensive ---------- */
@media (max-width: 380px) {
  .container { padding-left: 14px; padding-right: 14px; }
  .scene-admin .kpis { grid-template-columns: 1fr !important; }
  .scene-hr .grid { grid-template-columns: 1fr 1fr !important; }
  .scene-menu .items { grid-template-columns: 1fr !important; }
  .ill__chrome .dot { width: 8px; height: 8px; }
}

/* ============================================================
   POLISH PASS — added during mobile audit. Targets specific
   patterns that survived the initial sweep.
============================================================ */

/* ---------- Images / SVGs — never crop, never overflow ---------- */
@media (max-width: 880px) {
  /* Project visuals: SVG logos were being squeezed when natural ratio differed
     from the container. Force object-fit:contain so the WHOLE logo shows. */
  .project-row .visual img,
  .project-row .visual svg {
    max-width: 220px !important;
    width: 70% !important;
    height: auto !important;
    object-fit: contain !important;
  }
  /* Inline-styled hero illustrations occasionally use fixed widths */
  [style*="max-width:280px"][style*="width:80%"] {
    max-width: 200px !important;
    width: 60% !important;
  }
  /* Generic safety: any image inside a card should never break out */
  .card img, section img, .panel img { max-width: 100%; height: auto; }
}

/* ---------- Cards / panels — consistent padding and radius on mobile ---------- */
@media (max-width: 640px) {
  .card,
  .panel,
  .t-card,
  .pricing-card,
  .feature-card {
    padding: 22px 18px !important;
    border-radius: 16px !important;
  }
  /* Card grid spacing */
  .grid-3, .grid-2, .grid-4 { gap: 16px !important; }
  /* Inline grid-3 / grid-2 sometimes set wider gaps via style attribute */
  [style*="gap:28px"] { gap: 16px !important; }
}

/* ---------- Swiper — better mobile pagination dots, edge padding ---------- */
@media (max-width: 640px) {
  .swiper { padding-bottom: 36px !important; }
  .swiper-pagination-bullet { width: 8px !important; height: 8px !important; }
  .swiper-pagination-bullet-active { width: 24px !important; border-radius: 4px !important; }
  /* Partners strip wraps nicely */
  .partners { gap: 12px !important; flex-wrap: wrap !important; justify-content: center !important; }
  .partner { font-size: 13px !important; padding: 8px 12px !important; }
}

/* ---------- Footer polish ---------- */
@media (max-width: 640px) {
  .site-footer { padding: 40px 0 24px !important; }
  .footer-grid { gap: 28px !important; }
  .footer-brand p { font-size: 13.5px; line-height: 1.7; }
  .footer-col h5 { font-size: 14px; margin-bottom: 10px; }
  .footer-col ul li { margin-bottom: 6px; }
  .footer-col a { font-size: 13.5px; }
  .footer-bottom { font-size: 12px; padding-top: 20px; }
}

/* ---------- Floating Action Buttons (WhatsApp + back-to-top) ---------- */
@media (max-width: 640px) {
  .fab { width: 48px !important; height: 48px !important; bottom: 16px !important; }
  .fab svg { width: 22px !important; height: 22px !important; }
  /* Stack the back-to-top BELOW the WhatsApp button so they don't collide */
  .fab.top { bottom: 76px !important; }
}

/* ---------- Section heads (eyebrow + h2 + subtitle) ---------- */
@media (max-width: 640px) {
  .section-divider,
  .eyebrow {
    font-size: 11.5px !important;
    padding: 4px 12px !important;
  }
  .section-head { text-align: center; margin-bottom: 24px !important; }
  .section-head h2 { margin: 10px auto 8px !important; }
  .section-head p { font-size: 14px !important; color: var(--text-3); }
}

/* ---------- Forms — comfortable touch targets ---------- */
@media (max-width: 640px) {
  input, textarea, select, .input, .textarea, .select {
    font-size: 16px !important; /* iOS auto-zoom prevention */
    padding: 13px 14px !important;
    border-radius: 12px !important;
  }
  label { font-size: 13.5px !important; margin-bottom: 6px !important; display: block; }
  textarea, .textarea { min-height: 110px !important; }
}

/* ---------- CTA banner — tighter and centered ---------- */
@media (max-width: 768px) {
  .cta-banner h2 { font-size: 20px !important; line-height: 1.35 !important; }
  .cta-banner p { font-size: 14px !important; margin-top: 8px !important; }
  .cta-banner .actions { gap: 8px !important; margin-top: 18px !important; }
  .cta-banner .actions .btn { flex: 1 1 calc(50% - 4px); }
}

/* ---------- Pills / tags ---------- */
@media (max-width: 640px) {
  .pill { font-size: 11.5px !important; padding: 4px 10px !important; }
  .tag  { font-size: 11.5px !important; padding: 3px 9px !important; }
}

/* ---------- "scrolled" header subtle elevation on mobile ---------- */
@media (max-width: 980px) {
  .site-header.scrolled { box-shadow: 0 2px 12px rgba(11,36,71,.06); }
}

/* ---------- Hero section padding (per-page styles override .section) ---------- */
@media (max-width: 880px) {
  section[style*="padding: 80px 0 60px"],
  section[style*="padding:80px 0 60px"] {
    padding: 36px 0 28px !important;
  }
  /* Push hero stats apart from CTAs */
  [style*="margin-top:40px"][style*="display:flex"] { margin-top: 28px !important; }
  [style*="margin-top:32px"][style*="display:flex"] { margin-top: 22px !important; }
}

/* ---------- Visually-rich illustrations: cap their height ---------- */
@media (max-width: 880px) {
  .ill, .scene-admin, .scene-site, .scene-bot, .scene-ai,
  .scene-phone-bg, .scene-flow, .scene-smart, .scene-kanban,
  .scene-menu, .scene-hr, .scene-map, .scene-edu {
    max-height: 460px;
    margin-inline: auto;
  }
}
