/* ============================================================
   Portal — Mobile Responsive Styles
   Breakpoints: mobile < 768px, tablet 768–1024px
   ============================================================ */

/* ============================================================
   MOBILE NAV — hamburger + dropdown menu
   ============================================================ */

/* Hamburger button */
.mobile-menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.mobile-menu-btn:hover {
  background: hsl(var(--muted) / 0.5);
}

.mobile-menu-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: hsl(var(--foreground));
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.25s ease;
  transform-origin: center;
}

/* Hamburger → X animation */
.mobile-menu-btn.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.mobile-menu-btn.open span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.mobile-menu-btn.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Mobile nav dropdown */
.mobile-nav-menu {
  display: none;
  position: fixed;
  top: 80px; /* height of nav */
  left: 0;
  right: 0;
  z-index: 999;
  background: hsl(var(--background) / 0.97);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid hsl(var(--border));
  padding: 16px 20px 20px;
  flex-direction: column;
  gap: 4px;
  transform: translateY(-8px);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.mobile-nav-menu.open {
  display: flex;
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

.mobile-nav-menu a {
  display: block;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  border-radius: 10px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.mobile-nav-menu a:hover,
.mobile-nav-menu a.active {
  background: hsl(var(--muted) / 0.6);
  color: hsl(var(--foreground));
}

.mobile-nav-menu .mobile-nav-cta {
  margin-top: 8px;
  width: 100%;
  display: flex;
  justify-content: center;
}

.mobile-nav-menu .mobile-nav-cta a {
  width: 100%;
  justify-content: center;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-weight: 600;
  border-radius: 10px;
}

.mobile-nav-menu .mobile-nav-cta a:hover {
  background: hsl(var(--primary) / 0.85);
  color: hsl(var(--primary-foreground));
}

@media (max-width: 767px) {
  .mobile-menu-btn {
    display: flex;
  }

  /* Hide Contact button text on small screens, show hamburger only */
  nav .uk-btn-primary.uk-btn-sm {
    font-size: 0.75rem !important;
    padding: 6px 12px !important;
    white-space: nowrap;
  }
}

/* ============================================================
   GLOBAL MOBILE — reduce heavy vertical padding
   ============================================================ */
@media (max-width: 767px) {
  .py-32 {
    padding-top: 3.5rem !important;
    padding-bottom: 3.5rem !important;
  }

  .py-24 {
    padding-top: 2.5rem !important;
    padding-bottom: 2.5rem !important;
  }

  .py-16 {
    padding-top: 1.5rem !important;
    padding-bottom: 1.5rem !important;
  }

  .mb-16 {
    margin-bottom: 2rem !important;
  }

  .mb-12 {
    margin-bottom: 1.5rem !important;
  }

  .pt-44 {
    padding-top: 7rem !important;
  }

  .pb-32 {
    padding-bottom: 3.5rem !important;
  }
}

/* ============================================================
   HERO — mobile typography + layout
   ============================================================ */
@media (max-width: 767px) {
  /* Hero headline */
  h1.text-5xl {
    font-size: 2rem !important;
    line-height: 1.2 !important;
    margin-bottom: 1.25rem !important;
  }

  /* Hero subtitle */
  .text-xl.text-muted-foreground.leading-relaxed {
    font-size: 1rem !important;
    margin-bottom: 1.75rem !important;
  }

  /* CTA button — full width */
  .flex.justify-center > .uk-btn-lg {
    width: 100%;
    max-width: 340px;
  }

  /* Final CTA section — stack buttons */
  section .flex.gap-4.justify-center {
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  section .flex.gap-4.justify-center .uk-btn {
    width: 100%;
    max-width: 340px;
    justify-content: center;
  }
}

/* ============================================================
   DEMO IFRAME — reduce height on mobile
   ============================================================ */
@media (max-width: 767px) {
  .portal-demo-float iframe,
  iframe[src*="demo.html"] {
    height: 630px !important;
  }

  .portal-demo-float {
    border-radius: 14px !important;
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  .portal-demo-float iframe,
  iframe[src*="demo.html"] {
    height: 610px !important;
  }
}

@media (max-width: 374px) {
  .portal-demo-float iframe,
  iframe[src*="demo.html"] {
    height: 560px !important;
  }
}

/* ============================================================
   SVG DIAGRAMS — scroll on mobile
   ============================================================ */
@media (max-width: 767px) {
  /* Wrap SVGs in scrollable container */
  .uk-card svg[viewBox] {
    min-width: 600px;
    height: auto !important;
  }

  .uk-card .svg-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
  }

  /* Card padding reduction */
  .uk-card-body.p-8 {
    padding: 1.25rem !important;
  }

  .uk-card-body.p-10 {
    padding: 1.25rem !important;
  }

  .uk-card-body.p-6 {
    padding: 1rem !important;
    overflow-x: auto;
  }
}

/* ============================================================
   SECTION HEADINGS — scale down on mobile
   ============================================================ */
@media (max-width: 767px) {
  h2.text-4xl,
  h2.text-5xl {
    font-size: 1.5rem !important;
    line-height: 1.25 !important;
  }

  .text-4xl.font-extrabold,
  .text-5xl.font-extrabold {
    font-size: 1.5rem !important;
  }

  /* Remove forced <br> on mobile — let headings flow naturally */
  h1 br, h2 br {
    display: none;
  }

  p.text-xl {
    font-size: 0.95rem !important;
  }

  /* Trust bar / section label */
  .text-xs.uppercase.tracking-widest {
    font-size: 0.7rem !important;
  }
}

/* ============================================================
   GRID — ensure single column on mobile
   ============================================================ */
@media (max-width: 767px) {
  .grid-cols-1.md\:grid-cols-3,
  .grid-cols-1.md\:grid-cols-2,
  .grid-cols-1.md\:grid-cols-4 {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
}

/* ============================================================
   MARQUEE — ensure it works on mobile
   ============================================================ */
@media (max-width: 767px) {
  .portal-marquee {
    /* Prevent marquee from expanding document width */
  }

  .portal-marquee-item {
    padding: 0 18px;
    font-size: 0.78rem;
  }

  /* The marquee wrapper needs overflow containment */
  div[style*="mask-image"] {
    overflow: hidden !important;
    max-width: 100vw;
  }

  /* Trust bar section that contains marquee */
  .py-16.border-y {
    overflow: hidden;
    max-width: 100vw;
  }
}

/* ============================================================
   CERTIFICATION BAR — wrap on mobile
   ============================================================ */
@media (max-width: 767px) {
  .flex.flex-wrap.items-center.justify-center.gap-8 {
    gap: 0.75rem 1rem !important;
  }

  /* Hide decorative separators on mobile */
  .opacity-30 {
    display: none;
  }
}

/* ============================================================
   FOOTER — ensure proper stacking
   ============================================================ */
@media (max-width: 767px) {
  footer .grid {
    gap: 2rem !important;
  }

  footer .mt-16 {
    margin-top: 2rem !important;
  }
}

/* ============================================================
   HOW-IT-WORKS page — step sections
   ============================================================ */
@media (max-width: 767px) {
  /* Any side-by-side flex layout should stack */
  .flex.gap-12:not(nav > div),
  .flex.gap-16:not(nav > div),
  .flex.gap-20:not(nav > div) {
    flex-direction: column !important;
    gap: 2rem !important;
  }

  /* Number / step circles */
  .step-number,
  .w-16.h-16 {
    width: 3rem !important;
    height: 3rem !important;
    font-size: 1rem !important;
  }

  /* Step divider pill rows — stack vertically on mobile */
  .flex.items-center.gap-4:has(.rounded-full) {
    flex-direction: column !important;
    gap: 0.5rem !important;
    align-items: stretch !important;
  }

  .flex.items-center.gap-4:has(.rounded-full) .flex-1.h-px {
    display: none !important;
  }

  .flex.items-center.gap-4:has(.rounded-full) .rounded-full {
    text-align: center !important;
    white-space: normal !important;
    justify-content: center !important;
  }
}

/* ============================================================
   NAV LOGO — constrain on mobile
   ============================================================ */
@media (max-width: 767px) {
  nav svg.h-7 {
    height: 1.25rem !important;
    width: auto !important;
    max-width: 120px !important;
  }
}

/* ============================================================
   CONTACT page — form
   ============================================================ */
@media (max-width: 767px) {
  form .grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  form input,
  form textarea,
  form select {
    font-size: 16px !important; /* prevents iOS zoom on focus */
  }

  /* Info cards below contact form - force single column and reduce padding */
  section .grid-cols-1.md\:grid-cols-3,
  section .grid-cols-1.md\:grid-cols-2 {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ALL cards on contact page - reduce padding and force width constraints */
  .uk-card-body.p-10 {
    padding: 1rem !important;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  .uk-card-body.p-10 > * {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .uk-card {
    margin-left: 0 !important;
    margin-right: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  /* Force container to respect viewport on mobile */
  section .uk-container,
  section .uk-container-lg {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    max-width: 100vw !important;
    width: 100% !important;
    overflow-x: hidden !important;
  }
}

/* ============================================================
   APP page — general mobile
   ============================================================ */
@media (max-width: 767px) {
  /* App store buttons should stack or fill */
  .app-store-buttons {
    flex-direction: column !important;
    align-items: stretch !important;
  }
}

/* ============================================================
   USE CASE CARDS — reduce padding on mobile
   ============================================================ */
@media (max-width: 767px) {
  .uk-card-body.p-10 {
    padding: 1.25rem !important;
  }

  .uk-card-body h3.text-2xl {
    font-size: 1.25rem !important;
  }
}

/* ============================================================
   HERO — GSAP fallback: ensure content is visible even without JS
   ============================================================ */
@media (max-width: 767px) {
  /* GSAP sets autoAlpha:0. This ensures a CSS fallback shows content */
  section:first-of-type h1,
  section:first-of-type h1 + p,
  section:first-of-type .flex.justify-center,
  section:first-of-type .flex.gap-4.justify-center {
    animation: portal-mobile-hero-fallback 0s 1.5s forwards;
  }
}

@keyframes portal-mobile-hero-fallback {
  to {
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
  }
}

/* ============================================================
   DIAGRAMS — Switch to HTML version on mobile
   ============================================================ */
@media (max-width: 767px) {
  .desktop-diagram {
    display: none !important;
  }
  
  .mobile-diagram-alt {
    display: block !important;
  }
  
  /* Ensure SVG wrapper doesn't force width */
  .svg-scroll-wrap {
    display: none !important;
  }
}

@media (min-width: 768px) {
  .mobile-diagram-alt {
    display: none !important;
  }
}

/* ============================================================
   HOW-IT-WORKS — step flow cards horizontal scroll
   ============================================================ */
@media (max-width: 767px) {
  .flex.gap-3:has(> .uk-card),
  .flex.gap-4:has(> .uk-card) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding-bottom: 8px;
  }

  .flex.gap-3:has(> .uk-card) > .uk-card,
  .flex.gap-4:has(> .uk-card) > .uk-card {
    min-width: 260px;
    flex-shrink: 0;
    scroll-snap-align: start;
  }
}

/* ============================================================
   LARGE PADDING — reduce py-40 on mobile
   ============================================================ */
@media (max-width: 767px) {
  .py-40 {
    padding-top: 4rem !important;
    padding-bottom: 4rem !important;
  }

  .mb-20 {
    margin-bottom: 2.5rem !important;
  }

  /* Code blocks — prevent overflow */
  .font-mono {
    font-size: 0.75rem !important;
    word-break: break-all;
  }

  /* CTA sections — stack buttons */
  .flex.gap-4.justify-center {
    flex-direction: column !important;
    align-items: center !important;
    gap: 12px !important;
  }

  .flex.gap-4.justify-center .uk-btn {
    width: 100%;
    max-width: 340px;
    justify-content: center;
    text-align: center;
  }
}

/* ============================================================
   TABLET — 768px–1024px tweaks
   ============================================================ */
@media (min-width: 768px) and (max-width: 1024px) {
  .uk-container-lg {
    padding-left: 2rem;
    padding-right: 2rem;
  }

  .portal-demo-float iframe {
    height: 600px !important;
  }

  h1 {
    font-size: 3.5rem !important;
  }
}

/* ============================================================
   PREVENT HORIZONTAL OVERFLOW globally
   ============================================================ */
html {
  overflow-x: hidden;
  width: 100%;
}

body {
  overflow-x: hidden;
  width: 100%;
  min-width: 0;
}

@media (max-width: 767px) {
  *:not(svg):not(svg *):not(.lucide):not(.portal-marquee):not(.portal-marquee *) {
    box-sizing: border-box;
  }

  /* Constrain images but exclude icons */
  img, svg.h-7:not(.lucide) {
    max-width: 100% !important;
    height: auto !important;
  }

  /* Franken UI containers use content-box — force proper mobile widths */
  .uk-container {
    box-sizing: border-box !important;
    max-width: 100% !important;
    width: 100% !important;
    padding-left: 1.25rem !important;
    padding-right: 1.25rem !important;
  }

  .uk-container-lg,
  .uk-container-xl,
  .uk-container-sm {
    max-width: 100% !important;
  }

  /* Cards should have right padding and not overflow */
  .uk-card {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .uk-card-body {
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box !important;
  }
}

/* ============================================================
   DIAGRAMS — Switch to HTML version on mobile
   ============================================================ */
@media (max-width: 767px) {
  .desktop-diagram {
    display: none !important;
  }
  
  .mobile-diagram-alt {
    display: block !important;
  }
  
  /* Ensure SVG wrapper doesn't force width */
  .svg-scroll-wrap {
    display: none !important;
  }
}

@media (min-width: 768px) {
  .mobile-diagram-alt {
    display: none !important;
  }
}

/* ============================================================
   LUCIDE ICONS — preserve explicit sizes, don't expand on mobile
   ============================================================ */
svg.lucide { flex-shrink: 0; }
svg.lucide.w-4 { width: 1rem    !important; height: 1rem    !important; max-width: 1rem    !important; }
svg.lucide.w-5 { width: 1.25rem !important; height: 1.25rem !important; max-width: 1.25rem !important; }
svg.lucide.w-6 { width: 1.5rem  !important; height: 1.5rem  !important; max-width: 1.5rem  !important; }
svg.lucide.w-7 { width: 1.75rem !important; height: 1.75rem !important; max-width: 1.75rem !important; }
svg.lucide.w-8 { width: 2rem    !important; height: 2rem    !important; max-width: 2rem    !important; }
svg.lucide.h-4 { height: 1rem    !important; }
svg.lucide.h-5 { height: 1.25rem !important; }
svg.lucide.h-6 { height: 1.5rem  !important; }
svg.lucide.h-7 { height: 1.75rem !important; }
svg.lucide.h-8 { height: 2rem    !important; }
