/*
 * SEMPI MOBILE & RESPONSIVE OPTIMIZATION
 * Comprehensive mobile-first responsive design
 * Fixes overlapping issues on all screen sizes
 * Breakpoints: 480px (small phones), 768px (tablets), 1024px (small desktops), 1200px (large)
 */

/* ==========================================
   BASE FIXES - Prevent Overflow
   ========================================== */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

* {
  box-sizing: border-box;
}

img {
  max-width: 100%;
  height: auto;
}

/* ==========================================
   SMALL MOBILE (max-width: 480px)
   ========================================== */
@media (max-width: 480px) {
  /* Typography - Smaller on tiny screens */
  .hero h1 {
    font-size: 1.75rem !important;
    line-height: 1.2;
    padding: 0 0.5rem;
  }

  .hero-lead {
    font-size: 0.95rem !important;
    padding: 0 0.5rem;
  }

  .section-header h2 {
    font-size: 1.5rem !important;
    padding: 0 0.5rem;
  }

  .section-header p {
    font-size: 0.9rem !important;
  }

  /* Hero section - Compact */
  .hero {
    padding: 3rem 1rem 2rem !important;
    min-height: auto !important;
  }

  .hero-content {
    padding: 0 !important;
  }

  /* Hero stats grid - Stack on small mobile */
  .hero-stats,
  .hero-content > div[style*="display: grid"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
  }

  .stat-mini {
    padding: 1rem !important;
  }

  .stat-mini strong {
    font-size: 2rem !important;
  }

  /* Spacing reduction */
  .section {
    padding: 2.5rem 1rem !important;
  }

  .section-header {
    margin-bottom: 1.5rem !important;
  }

  .section-inner {
    padding: 0 !important;
  }

  /* Buttons - Full width on small screens */
  .hero-actions {
    flex-direction: column !important;
    width: 100% !important;
    gap: 0.75rem !important;
    padding: 0 0.5rem !important;
  }

  .hero-actions .btn {
    width: 100% !important;
    padding: 0.875rem 1rem !important;
    font-size: 0.9rem !important;
  }

  .btn {
    padding: 0.875rem 1.25rem !important;
    font-size: 0.9rem !important;
    width: 100%;
  }

  /* ALL grids - Force single column */
  .cards-grid,
  .case-study-grid,
  .pillars-grid,
  .contact-grid,
  .footer-grid,
  .story-grid,
  .pricing-grid,
  div[style*="grid-template-columns: repeat(auto-fit"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.25rem !important;
  }

  /* Cards - Proper spacing */
  .card {
    padding: 1.25rem !important;
    margin: 0 !important;
    width: 100% !important;
  }

  .card h3 {
    font-size: 1.2rem !important;
  }

  /* Case study cards */
  .case-study-card {
    margin: 0 !important;
  }

  .case-study-image {
    height: 160px !important;
  }

  .case-study-content {
    padding: 1.25rem !important;
  }

  .case-study-metrics {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
  }

  /* Navbar adjustments */
  .navbar {
    padding: 0.75rem 1rem !important;
  }

  .navbar-logo img {
    width: 36px !important;
    height: auto !important;
  }

  .navbar-logo-text {
    font-size: 0.9rem !important;
  }

  /* Footer - Single column */
  .footer {
    padding: 2rem 1rem !important;
  }

  .footer-bottom {
    flex-direction: column !important;
    text-align: center !important;
    gap: 1rem !important;
  }

  /* Timeline - More compact */
  .timeline {
    gap: 1rem !important;
  }

  .timeline-step {
    padding: 1.25rem !important;
    margin-left: 0 !important;
  }

  .timeline-step h3 {
    font-size: 1.1rem !important;
  }

  /* Video placeholder in hero */
  .hero-content > div[style*="max-width: 600px"] {
    margin-top: 1.5rem !important;
  }

  /* CTA boxes */
  div[style*="max-width: 900px"][style*="padding: 3rem"],
  div[style*="max-width: 800px"][style*="padding: 3rem"] {
    padding: 1.5rem !important;
    margin: 2rem 0.5rem 0 !important;
    border-radius: 16px !important;
  }

  div[style*="max-width: 900px"] h3,
  div[style*="max-width: 800px"] h3 {
    font-size: 1.4rem !important;
  }

  div[style*="max-width: 900px"] p,
  div[style*="max-width: 800px"] p {
    font-size: 0.95rem !important;
  }

  /* Utility bar - Smaller */
  .utility-bar {
    font-size: 0.65rem !important;
    padding: 0.35rem 0.5rem !important;
  }

  /* FAQ */
  .accordion-trigger {
    font-size: 0.95rem !important;
    padding: 1rem 0 !important;
  }

  /* Forms */
  .form-group {
    margin-bottom: 1rem !important;
  }

  .form-group input,
  .form-group textarea,
  .form-group select {
    padding: 0.875rem !important;
    font-size: 16px !important; /* Prevents iOS zoom */
  }

  /* Hide decorative backgrounds */
  .hero > div[style*="position: absolute"],
  div[style*="position: absolute"][style*="opacity: 0.05"],
  div[style*="position: absolute"][style*="opacity: 0.1"],
  div[style*="position: absolute"][style*="opacity: 0.15"] {
    display: none !important;
  }

  /* Scroll hint */
  .scroll-hint {
    display: none !important;
  }

  /* Testimonials */
  .testimonial-card {
    padding: 1.5rem !important;
  }

  .testimonial-card p {
    font-size: 1rem !important;
  }

  /* Filters */
  .filters {
    gap: 0.5rem !important;
    justify-content: flex-start !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 0.5rem !important;
  }

  .filter-btn {
    padding: 0.5rem 0.875rem !important;
    font-size: 0.8rem !important;
    white-space: nowrap !important;
  }
}

/* ==========================================
   MOBILE & TABLET (max-width: 768px)
   ========================================== */
@media (max-width: 768px) {
  /* Prevent horizontal overflow */
  body {
    overflow-x: hidden;
  }

  /* Navigation - Mobile menu */
  .navbar-links {
    display: none;
  }

  .navbar-links.open {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.98);
    backdrop-filter: blur(20px);
    padding: 1.5rem;
    gap: 0.5rem;
    z-index: 99;
    animation: slideDown 0.3s ease;
    overflow-y: auto;
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .navbar-links.open a {
    font-size: 1rem;
    padding: 0.875rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .navbar-cta,
  .navbar-login {
    display: none;
  }

  .navbar-links.open .navbar-cta,
  .navbar-links.open .navbar-login {
    display: inline-flex;
    width: 100%;
    justify-content: center;
    margin-top: 0.75rem;
  }

  .navbar-links.open .navbar-login {
    margin-right: 0;
    margin-top: 0.5rem;
    order: -1;
  }

  .menu-toggle {
    display: block;
    z-index: 100;
  }

  /* Hero section - Mobile optimized */
  .hero {
    padding: 4rem 1.25rem 3rem;
    min-height: auto;
  }

  .hero h1 {
    font-size: 2rem;
  }

  .hero-lead {
    font-size: 1rem;
    margin-bottom: 1.5rem;
  }

  .hero-actions {
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
    margin: 0 auto 1.5rem;
  }

  .hero-actions .btn {
    width: 100%;
  }

  /* Hide decorative absolute positioned elements */
  .hero > div[style*="position: absolute"] {
    display: none !important;
  }

  /* Sections - Better spacing */
  .section {
    padding: 3rem 1.25rem;
  }

  .section-header {
    margin-bottom: 2rem;
  }

  .section-header h2 {
    font-size: 1.75rem;
  }

  .section-header p {
    font-size: 0.95rem;
  }

  /* ALL grids - Single column */
  .cards-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
  }

  .pillars-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
  }

  .case-study-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
  }

  .contact-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
  }

  /* Inline grid styles override */
  div[style*="grid-template-columns: repeat(auto-fit, minmax(3"],
  div[style*="grid-template-columns: repeat(auto-fit, minmax(2"],
  div[style*="grid-template-columns: repeat(auto-fit, minmax(1"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
  }

  /* Cards - Proper width */
  .card {
    padding: 1.5rem;
    width: 100%;
  }

  /* Reduce hover effects on mobile (performance) */
  .card:hover {
    transform: none;
  }

  /* Case studies */
  .case-study-card:hover {
    transform: translateY(-4px);
  }

  .case-study-image {
    height: 180px;
  }

  .case-study-content {
    padding: 1.25rem;
  }

  .case-study-metrics {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.75rem !important;
  }

  .metric-item {
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .metric-value {
    font-size: 1.25rem;
  }

  /* Timeline - More compact */
  .timeline {
    gap: 1.25rem;
  }

  .timeline-step {
    padding: 1.5rem;
  }

  /* Comparison table - Horizontal scroll */
  .comparison-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .comparison-table table {
    min-width: 600px;
  }

  .comparison-table th,
  .comparison-table td {
    padding: 0.875rem 0.75rem;
    font-size: 0.85rem;
  }

  /* Testimonials - Mobile friendly */
  .testimonial-card {
    padding: 1.75rem;
  }

  .testimonial-card p {
    font-size: 1rem;
  }

  .testimonial-card p::before,
  .testimonial-card p::after {
    font-size: 1.5rem;
  }

  /* FAQ - Better touch targets */
  .accordion-trigger {
    font-size: 1rem;
    padding: 1.25rem 0;
    min-height: 48px;
  }

  /* Forms */
  .form-group input,
  .form-group textarea,
  .form-group select {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 1rem;
  }

  /* Footer - Responsive */
  .footer {
    padding: 2.5rem 1.25rem 2rem;
  }

  .footer-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1.5rem !important;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
    gap: 1rem;
  }

  /* CTA boxes - Proper sizing */
  div[style*="max-width: 900px"][style*="padding: 3rem"],
  div[style*="max-width: 800px"][style*="padding: 3rem"] {
    padding: 2rem 1.5rem !important;
    margin: 2.5rem 0 0 !important;
  }

  div[style*="max-width: 900px"] h3,
  div[style*="max-width: 800px"] h3 {
    font-size: 1.5rem !important;
  }

  /* Button containers in CTA boxes */
  div[style*="display: flex"][style*="gap: 1rem"][style*="justify-content: center"] {
    flex-direction: column !important;
    gap: 0.75rem !important;
    width: 100% !important;
  }

  div[style*="display: flex"][style*="gap: 1rem"] .btn,
  div[style*="display: flex"][style*="gap: 0.75rem"] .btn {
    width: 100% !important;
    text-align: center !important;
  }

  /* Remove transform effects */
  .btn-primary:hover,
  .btn-outline:hover {
    transform: none;
  }

  /* Ensure touch targets are at least 44x44px */
  .btn,
  .navbar-cta,
  .menu-toggle,
  .accordion-trigger,
  .filter-btn {
    min-height: 44px;
  }

  /* Logo clickable area */
  .navbar-logo {
    min-height: 44px;
  }

  /* Social links - Larger touch targets */
  .social-links a {
    width: 48px;
    height: 48px;
  }
}

/* ==========================================
   TABLET (481px - 768px)
   ========================================== */
@media (min-width: 481px) and (max-width: 768px) {
  /* 2-column grid for cards on tablets */
  .cards-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .pillars-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
  }

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

  /* Hero buttons side by side on tablet */
  .hero-actions {
    flex-direction: row !important;
    gap: 1rem !important;
  }

  .hero-actions .btn {
    flex: 1 !important;
    width: auto !important;
  }

  /* Hero stats - 3 columns on tablet */
  .hero-stats,
  .hero-content > div[style*="display: grid"][style*="minmax(150px"] {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* ==========================================
   SMALL DESKTOP (769px - 1024px)
   ========================================== */
@media (min-width: 769px) and (max-width: 1024px) {
  /* Adjust max-width for better use of space */
  .section-inner {
    max-width: 95%;
  }

  /* 2-3 column grids */
  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }

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

  /* Reduce padding slightly */
  .section {
    padding: 4.5rem 1.5rem;
  }

  .hero {
    padding: 6rem 1.5rem 4rem;
  }

  /* Navigation - Compact for small desktop */
  .navbar-links {
    gap: 1.25rem;
    font-size: 0.85rem;
  }

  .navbar-cta,
  .navbar-login {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
  }
}

/* ==========================================
   LARGE DESKTOP (1025px+)
   ========================================== */
@media (min-width: 1025px) {
  /* Ensure proper grid layouts */
  .cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .pillars-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .case-study-grid {
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  }

  /* Hero stats */
  .hero-stats,
  .hero-content > div[style*="display: grid"] {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* ==========================================
   TOUCH DEVICE OPTIMIZATIONS
   ========================================== */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .card:hover,
  .case-study-card:hover,
  .btn:hover,
  .navbar-links a:hover::after {
    transform: none;
  }

  /* Larger tap targets */
  a, button, .btn, .accordion-trigger {
    min-height: 44px;
  }

  /* Disable complex animations */
  .hero::before,
  .card::before,
  .pain-card::before {
    display: none;
  }

  /* Remove glow effects */
  div[style*="position: absolute"][style*="radial-gradient"] {
    display: none !important;
  }
}

/* ==========================================
   LANDSCAPE MOBILE
   ========================================== */
@media (max-width: 768px) and (orientation: landscape) {
  .hero {
    min-height: auto;
    padding: 2.5rem 1.5rem 2rem;
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .section {
    padding: 2.5rem 1.5rem;
  }

  /* 2 column layout in landscape */
  .cards-grid,
  .pillars-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Hero actions side by side */
  .hero-actions {
    flex-direction: row !important;
  }

  .hero-actions .btn {
    flex: 1 !important;
    width: auto !important;
  }
}

/* ==========================================
   ACCESSIBILITY - Focus States
   ========================================== */
@media (max-width: 768px) {
  *:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 4px;
  }

  /* Skip to content link for keyboard users */
  .skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary);
    color: white;
    padding: 0.75rem 1.5rem;
    z-index: 1000;
  }

  .skip-link:focus {
    top: 0;
  }
}

/* ==========================================
   PERFORMANCE - Reduce motion
   ========================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================
   PRINT STYLES
   ========================================== */
@media print {
  .navbar,
  .menu-toggle,
  .scroll-hint,
  .hero-actions,
  footer,
  .utility-bar {
    display: none !important;
  }

  .section {
    padding: 1rem !important;
  }

  .card,
  .case-study-card {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

/* ==========================================
   FIX SPECIFIC OVERLAPPING ISSUES
   ========================================== */

/* Fix inline grids that use minmax with values too large for mobile */
@media (max-width: 768px) {
  /* Override all inline grid styles */
  [style*="grid-template-columns"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
  }

  /* But restore for specific tablet cases */
  .footer-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (max-width: 480px) {
  /* Force all grids to single column on small mobile */
  .footer-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Fix z-index issues */
header {
  z-index: 1000 !important;
}

.navbar-links.open {
  z-index: 999 !important;
}

/* Fix absolute positioned decorative elements */
@media (max-width: 768px) {
  [style*="position: absolute"][style*="opacity"] {
    display: none !important;
  }

  /* Keep only essential absolute elements */
  .hero-content {
    position: relative !important;
    z-index: 2 !important;
  }
}

/* Fix button containers inside cards */
@media (max-width: 768px) {
  .card [style*="display: flex"][style*="gap"] {
    flex-direction: column !important;
  }

  .card .btn {
    width: 100% !important;
    text-align: center !important;
  }
}

/* Fix icon boxes */
@media (max-width: 480px) {
  div[style*="width: 80px"][style*="height: 80px"],
  div[style*="width: 70px"][style*="height: 70px"] {
    width: 60px !important;
    height: 60px !important;
  }

  div[style*="width: 60px"][style*="height: 60px"] {
    width: 50px !important;
    height: 50px !important;
  }
}

/* Fix text overflow */
@media (max-width: 768px) {
  h1, h2, h3, h4, h5, h6, p {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
  }
}

/* Fix video placeholder */
@media (max-width: 480px) {
  div[style*="padding-bottom: 56.25%"] {
    margin: 1.5rem 0 !important;
  }

  div[style*="max-width: 600px"][style*="margin: 3rem auto"] {
    margin: 1.5rem auto 0 !important;
  }
}
