/* ==========================================================================
   RESPONSIVE DESIGN & ADAPTIVE LAYOUTS
   ========================================================================== */

/* Tablet Optimization (769px to 1024px) */
@media (max-width: 1024px) {
  :root {
    --nav-height: 70px;
  }

  .hero-grid {
    grid-template-columns: 1fr;
    gap: 40px;
    text-align: center;
  }

  .hero-subtitle {
    margin: 0 auto 36px auto;
  }

  .hero-badge-group,
  .hero-cta-group {
    justify-content: center;
  }

  .process-grid {
    grid-template-columns: repeat(3, 1fr);
  }

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

  .modal-drawer {
    max-width: 100%;
    padding: 32px 24px;
  }

  .arch-node-container {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

/* Between 901 and 1099px the page layout is still the tablet one, but the
   full desktop nav (links + status pill + audio + CTA) no longer fits inside
   the header pill and spills past its right edge. Use the burger there too. */
@media (min-width: 901px) and (max-width: 1099px) {
  .nav-pill-menu {
    padding: 10px;
    border-radius: var(--radius-lg);
  }

  .brand-role {
    display: none;
  }
  .nav-wrapper {
    position: relative;
  }

  .nav-menu {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    width: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 10px;
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.16);
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }

  .nav-menu.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .nav-menu .nav-link {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    font-size: 1.05rem;
  }

  .nav-menu .nav-cta-mobile {
    display: block;
    margin-top: 6px;
  }

  .nav-menu .nav-cta-mobile .btn {
    width: 100%;
    justify-content: center;
  }

  .menu-toggle {
    display: block;
    min-width: 44px;
    min-height: 44px;
  }

  .nav-cta-desktop,
  #sfx-mute-btn,
  .status-pill {
    display: none;
  }
}

/* Mobile & Tablet Layout Adaptation (<= 900px) */
@media (max-width: 900px) {

  /* On mobile the menu pill becomes a dropdown, so it must not keep the
     desktop pill's inline layout or shadow. */
  .nav-pill-menu {
    padding: 10px;
    border-radius: var(--radius-lg);
  }

  /* Brand pill shrinks; the role line is dropped to save width. */
  .nav-pill-brand {
    padding: 6px 14px 6px 6px;
  }

  .brand-role {
    display: none;
  }

  .nav-pill-actions {
    padding: 6px;
    gap: 6px;
  }
  /* A dropdown card under the header pill — sized to its contents, not the
     whole screen. The desktop pill's radius must be reset or it renders as
     a blob at this width. */
  .nav-menu {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    width: auto;
    height: auto;
    max-height: calc(100vh - var(--nav-height) - 40px);
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 10px;
    background: var(--surface-card);
    backdrop-filter: blur(24px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.16);
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }

  .nav-menu.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  /* Primary CTA lives inside the opened menu on mobile */
  .nav-menu .nav-cta-mobile {
    display: block;
    margin-top: 6px;
  }

  .nav-menu .nav-cta-mobile .btn {
    width: 100%;
    justify-content: center;
  }

  .nav-menu .nav-link {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    font-size: 1.05rem;
  }

  .menu-toggle {
    display: block;
  }

  .status-pill {
    display: none; /* Hide status pill on small mobile screens to prevent overflow */
  }

  .hero-section {
    min-height: auto;
    align-items: flex-start;
    padding-top: calc(var(--nav-height) + 56px);
  }

  .split-2col,
  .form-row-2col,
  .capability-grid,
  .cs-features-grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  /* Stack the decision number above its text rather than beside it */
  .cs-decision {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 20px;
  }

  .project-card,
  .contact-card {
    padding: 28px 20px;
  }

  /* Full-width single column: let the image set its own height so there is
     no letterboxing above and below it */
  .project-media {
    height: auto;
    max-height: 60vh;
  }

  .process-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Nav bar: logo + name on one line, burger on the right */
  .nav-wrapper {
    position: relative; /* anchors the .nav-menu dropdown */
    width: calc(100% - 32px);
    gap: 10px;
  }

  .brand-logo {
    min-width: 0; /* let the name truncate instead of stretching the bar */
    gap: 10px;
    min-height: 44px;
  }

  .brand-name {
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-avatar-wrapper {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
  }

  /* Comfortable touch targets (Apple/Google both recommend ~44px) */
  .menu-toggle {
    min-width: 44px;
    min-height: 44px;
  }

  .btn {
    min-height: 44px;
  }

  .form-input,
  .form-select,
  .form-textarea {
    font-size: 16px; /* under 16px iOS Safari zooms the page on focus */
  }

  /* About stays side-by-side on tablets; the portrait just narrows */
  .about-profile-grid {
    grid-template-columns: auto 1fr;
    gap: 28px;
  }

  .about-portrait-frame {
    width: 270px;
  }

  /* Keep the nav to logo + burger on small screens; the CTA moves into the menu */
  .nav-cta-desktop,
  #sfx-mute-btn {
    display: none;
  }

  .hero-visual-composition {
    height: 480px;
  }

  .phone-mockup-frame {
    width: 250px;
    height: 460px;
    transform: rotateY(0deg) rotateX(0deg);
  }

  .floating-card-code {
    top: 10px;
    left: -10px;
    width: 180px;
    font-size: 0.75rem;
  }

  .floating-card-ai {
    bottom: 20px;
    right: -10px;
    width: 170px;
  }

  .floating-card-arch {
    display: none; /* Hide third floating element on small screens to prevent clutter */
  }

  .cs-title {
    font-size: 2rem;
  }

  .cs-impact-grid {
    grid-template-columns: 1fr;
  }

  .cs-banner-img {
    height: 220px;
  }
}

/* Narrow desktops: pull the decorative overhang inside the viewport */
@media (max-width: 1400px) and (min-width: 901px) {
  .floating-card-ai {
    right: 0;
  }

  .floating-card-code {
    left: 0;
  }

  .floating-card-arch {
    left: -20px;
  }
}

/* Small Phones (<= 480px) — previously uncovered */
@media (max-width: 480px) {
  .container {
    padding-left: 18px;
    padding-right: 18px;
  }

  .glass-card,
  .project-card,
  .contact-card {
    padding: 22px 16px;
  }

  /* Stacked, full-width CTAs are easier to hit than a cramped row */
  .hero-cta-group {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .hero-cta-group .btn {
    width: 100%;
    justify-content: center;
  }

  .hero-visual-composition {
    height: 400px;
  }

  .phone-mockup-frame {
    width: 210px;
    height: 400px;
  }

  .floating-card-code,
  .floating-card-ai {
    display: none; /* Overlap the phone too heavily at this width */
  }

  .nav-wrapper {
    gap: 8px;
    padding: 6px 10px 6px 12px;
  }

  .brand-name {
    font-size: 0.95rem;
  }

  .brand-avatar-wrapper {
    width: 34px;
    height: 34px;
  }

  .process-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .process-card-text {
    font-size: 0.9rem;
  }

  /* 100-120px of vertical padding is a lot of empty scrolling on a phone */
  section[id] {
    padding-top: 64px !important;
    padding-bottom: 64px !important;
  }

  #home {
    padding-top: calc(var(--nav-height) + 40px) !important;
  }

  .section-title {
    margin-bottom: 12px;
  }

  .section-subtitle {
    margin-bottom: 32px;
  }

  .tech-pill {
    font-size: 0.8rem;
    padding: 6px 11px;
  }

  .section-tag {
    font-size: 0.78rem;
    padding: 6px 13px;
  }
}

/* About: below ~600px the copy column gets too narrow to read, so stack */
@media (max-width: 600px) {
  .about-profile-grid {
    grid-template-columns: 1fr;
    gap: 28px;
    justify-items: center;
    text-align: center;
  }

  .about-portrait-frame {
    width: 280px;
  }
}

/* Large Desktop Displays (>= 1440px) */
@media (min-width: 1440px) {
  .phone-mockup-frame {
    width: 320px;
    height: 580px;
  }
}


/* ==========================================================================
   RTL / ARABIC
   Logical properties would avoid most of this, but the codebase uses physical
   left/right in inline styles, so the flips are declared explicitly.
   ========================================================================== */
[dir="rtl"] body {
  font-family: 'Tajawal', 'Inter', -apple-system, sans-serif;
}

[dir="rtl"] .hero-title,
[dir="rtl"] .section-title,
[dir="rtl"] .cs-title,
[dir="rtl"] .brand-name,
[dir="rtl"] .service-name,
[dir="rtl"] .workflow-title,
[dir="rtl"] .cs-section-heading,
[dir="rtl"] .cs-decision-title {
  font-family: 'Tajawal', 'Plus Jakarta Sans', sans-serif;
}

/* Latin-only elements keep their original face and direction. */
[dir="rtl"] .store-badge-btn,
[dir="rtl"] .tech-pill,
[dir="rtl"] .floating-card-code,
[dir="rtl"] .code-block {
  direction: ltr;
  font-family: var(--font-code);
}

[dir="rtl"] .store-badge-text {
  text-align: left;
}

/* Accent bars and bullet rails move to the right edge. */
[dir="rtl"] .cs-challenge,
[dir="rtl"] .service-fit {
  padding-left: 0;
  padding-right: 14px;
  border-left: none;
  border-right: 3px solid var(--cyan-flutter);
}

[dir="rtl"] .service-deliverables li {
  padding-left: 0;
  padding-right: 22px;
}

[dir="rtl"] .service-deliverables li::before {
  left: auto;
  right: 0;
}

/* The case study drawer slides in from the left in RTL. */
[dir="rtl"] .modal-backdrop {
  justify-content: flex-start;
}

[dir="rtl"] .modal-drawer {
  border-left: none;
  border-right: 1px solid var(--border-subtle);
  transform: translateX(-100%);
}

[dir="rtl"] .modal-backdrop.active .modal-drawer {
  transform: translateX(0);
}

[dir="rtl"] .modal-close-btn {
  float: left;
}

/* Directional glyphs in copy would point the wrong way in RTL. */
[dir="rtl"] .arrow-ltr {
  display: inline-block;
  transform: scaleX(-1);
}

/* Header pills: the brand leads on the right in RTL, preferences on the left.
   The DOM order stays brand → menu → actions; flex-direction does the flip. */
[dir="rtl"] .nav-wrapper {
  flex-direction: row-reverse;
}

[dir="rtl"] .nav-pill-brand {
  padding: 7px 8px 7px 20px;
}

[dir="rtl"] .brand-name,
[dir="rtl"] .brand-role {
  text-align: right;
}
