/**
 * Mobile Optimizations for Surprise Granite
 * iOS/Apple Best Practices Implementation
 * - 44pt minimum touch targets (Apple HIG)
 * - Safe area insets for notch/home indicator
 * - Native iOS animations and gestures
 * - Prevent zoom, bounce, and scroll issues
 */

/* ===== iOS ROOT FIXES ===== */

/* Fix iOS 100vh bug - use -webkit-fill-available */
@supports (-webkit-touch-callout: none) {
  :root {
    --vh: 1vh;
    --app-height: 100vh;
  }

  @media (max-width: 768px) {
    :root {
      --app-height: -webkit-fill-available;
    }
  }
}

/* iOS System Font Stack */
html {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
               'Helvetica Neue', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent iOS text size adjustment */
@media (max-width: 768px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
}

/* iOS Safe Area Variables */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* iOS Spring Animation Curves (matches UIKit) */
:root {
  --ios-spring: cubic-bezier(0.23, 1, 0.32, 1);
  --ios-ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ios-ease-in-out: cubic-bezier(0.42, 0, 0.58, 1);
  --ios-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== GLOBAL MOBILE FIXES ===== */

/* Ensure minimum touch target sizes */
@media (max-width: 768px) {
  /* All buttons minimum 48px height */
  button,
  .button,
  .w-button,
  input[type="submit"],
  input[type="button"],
  a.button {
    min-height: 48px;
    padding: 12px 24px;
    font-size: 16px;
  }

  /* Form inputs - prevent iOS zoom and ensure touch-friendly */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="password"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px !important; /* Prevents iOS zoom */
    min-height: 48px;
    padding: 12px 16px;
    border-radius: 8px;
  }

  /* Larger tap targets for links in navigation */
  nav a,
  .nav-link,
  .footer5_link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 8px 4px;
  }
}

/* ===== MAIN CTA BUTTONS ===== */
@media (max-width: 768px) {
  .main-estimate-btn {
    min-height: 56px;
    padding: 16px 32px;
    font-size: 18px;
    width: 100%;
    max-width: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-radius: 12px;
  }

  .btn-icon {
    font-size: 24px;
  }

  .btn-text {
    font-size: 18px;
    font-weight: 600;
  }
}

@media (max-width: 480px) {
  .main-estimate-btn {
    min-height: 52px;
    padding: 14px 28px;
    font-size: 16px;
    max-width: 100%;
  }

  .btn-icon {
    font-size: 20px;
  }

  .btn-text {
    font-size: 16px;
  }

  .cta-note {
    font-size: 14px;
    margin-top: 12px;
  }

  .cta-note a {
    font-size: 16px;
    padding: 4px;
  }
}

/* ===== CHAT WIDGET MOBILE ===== */

@media (max-width: 768px) {
  /* Mobile chat button positioning */
  #sg-chat-widget {
    bottom: 16px !important;
    right: 16px !important;
  }

  #sg-chat-button {
    width: 60px;
    height: 60px;
  }

  #sg-chat-button svg {
    width: 28px;
    height: 28px;
  }
}

/* ===== SHOPIFY CART MOBILE ===== */
@media (max-width: 768px) {
  /* Cart drawer full width on mobile */
  .sg-cart-drawer {
    width: 100% !important;
    max-width: 100% !important;
    right: -100% !important;
  }

  .sg-cart-drawer.open {
    right: 0 !important;
  }

  /* Cart header */
  .sg-cart-header {
    padding: 16px 20px;
    min-height: 60px;
  }

  .sg-cart-header h3 {
    font-size: 1.25rem;
  }

  .sg-cart-close {
    min-width: 44px;
    min-height: 44px;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Cart items */
  .sg-cart-items {
    padding: 16px;
  }

  .sg-cart-item {
    padding: 16px 0;
    gap: 16px;
  }

  .sg-cart-item-image {
    width: 80px;
    height: 80px;
    border-radius: 12px;
  }

  .sg-cart-item-title {
    font-size: 1rem;
    line-height: 1.3;
  }

  .sg-cart-item-price {
    font-size: 1rem;
  }

  /* Quantity controls - CRITICAL for touch */
  .sg-cart-item-qty {
    gap: 12px;
  }

  .sg-qty-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    font-size: 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sg-cart-item-qty span {
    min-width: 32px;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
  }

  /* Remove button */
  .sg-cart-item-remove {
    min-width: 44px;
    min-height: 44px;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Cart footer */
  .sg-cart-footer {
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .sg-cart-subtotal-row {
    font-size: 1.2rem;
    margin-bottom: 20px;
  }

  .sg-checkout-btn {
    min-height: 56px;
    font-size: 18px;
    border-radius: 12px;
  }

  .sg-continue-shopping {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
  }
}

/* ===== SHOPYFLOW INTEGRATION MOBILE ===== */
@media (max-width: 768px) {
  /* Product cards */
  [sf-product] {
    padding: 16px;
  }

  /* Add to cart buttons */
  [sf-add-to-cart],
  .sf-add-to-cart-btn {
    min-height: 48px !important;
    padding: 12px 24px !important;
    font-size: 16px !important;
    border-radius: 8px;
  }

  /* Quantity inputs */
  [sf-change-quantity],
  .sf-quantity-input {
    min-height: 44px;
    min-width: 60px;
    font-size: 16px;
    text-align: center;
    border-radius: 8px;
  }

  /* Checkout button */
  [sf-checkout] {
    min-height: 56px !important;
    font-size: 18px !important;
  }

  /* Cart popup */
  .cart-popup_component {
    padding: 0;
  }

  .cart-popup_content-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
  }
}

/* ===== NAVIGATION MOBILE ===== */
@media (max-width: 991px) {
  /* Hamburger button */
  .navbar_menu-button,
  .w-nav-button {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Menu icon lines */
  .menu-icon_line {
    height: 3px;
    margin: 4px 0;
  }

  /* Mobile nav links */
  .navbar_link,
  .nav-link {
    min-height: 52px;
    padding: 14px 20px;
    font-size: 18px;
    display: flex;
    align-items: center;
  }

  /* Dropdown items */
  .navbar_dropdown-link {
    min-height: 48px;
    padding: 12px 24px;
    font-size: 16px;
  }
}

/* ===== FORM MODAL MOBILE ===== */
@media (max-width: 768px) {
  .form-modal-overlay {
    padding: 0 !important;
    align-items: flex-end !important;
  }

  .form-modal-card {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 95vh !important;
    border-radius: 24px 24px 0 0 !important;
    padding: 24px 20px !important;
    padding-bottom: max(24px, env(safe-area-inset-bottom)) !important;
  }

  .modal-close-btn {
    min-width: 44px;
    min-height: 44px;
    top: 12px;
    right: 12px;
  }

  /* Form steps */
  .step-title {
    font-size: 24px;
    line-height: 1.2;
  }

  .step-subtitle {
    font-size: 15px;
  }

  /* Project options */
  .project-option {
    min-height: 64px;
    padding: 16px 20px;
    gap: 16px;
  }

  .project-option .project-icon {
    font-size: 32px;
  }

  .project-option .project-name {
    font-size: 17px;
  }

  .project-option .project-desc {
    font-size: 14px;
  }

  /* Form inputs */
  .form-input {
    min-height: 52px;
    padding: 14px 18px;
    font-size: 16px;
    border-radius: 10px;
  }

  /* Selector buttons (budget, timeline) */
  .selector-btn {
    min-height: 48px;
    padding: 14px 16px;
    font-size: 14px;
    border-radius: 10px;
  }

  /* Form buttons */
  .btn-next,
  .btn-back,
  .btn-submit {
    min-height: 52px;
    font-size: 16px;
    border-radius: 10px;
  }
}

/* ===== HERO SECTION MOBILE ===== */
@media (max-width: 768px) {
  .modern-hero {
    min-height: auto;
    padding-bottom: 40px;
  }

  .hero-container {
    flex-direction: column;
    padding: 24px 20px;
    gap: 32px;
  }

  .hero-content {
    max-width: 100%;
    text-align: center;
  }

  .hero-title {
    font-size: 32px;
    line-height: 1.2;
    margin-bottom: 16px;
  }

  .hero-subtitle {
    font-size: 17px;
    line-height: 1.5;
    margin-bottom: 28px;
  }

  .trust-badges {
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
  }

  .badge-logo {
    height: 36px;
  }

  .google-rating {
    font-size: 13px;
  }

  /* Hide gallery on mobile */
  .hero-gallery {
    display: none;
  }
}

@media (max-width: 480px) {
  .hero-container {
    padding: 20px 16px;
  }

  .hero-title {
    font-size: 28px;
  }

  .hero-subtitle {
    font-size: 16px;
    margin-bottom: 24px;
  }

  .trust-badges {
    gap: 8px;
  }

  .badge-logo {
    height: 32px;
  }
}

/* ===== FOOTER MOBILE ===== */
@media (max-width: 768px) {
  .footer5_link {
    min-height: 44px;
    padding: 10px 0;
    font-size: 16px;
  }

  .footer5_links-header {
    font-size: 14px;
    margin-bottom: 12px;
  }

  /* Social icons */
  .footer5_link.is-icon {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }

  .social-icon svg {
    width: 24px;
    height: 24px;
  }
}

/* ===== SAFE AREA INSETS (iPhone X+) ===== */
@supports (padding: max(0px)) {
  @media (max-width: 768px) {
    .sg-chat-window,
    #sg-chat-window,
    .sg-cart-drawer,
    .form-modal-card {
      padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    /* Chat widget with safe area padding */
    #sg-chat-widget {
      bottom: max(16px, env(safe-area-inset-bottom)) !important;
    }
  }
}

/* ===== TOUCH FEEDBACK ===== */
@media (hover: none) and (pointer: coarse) {
  /* Re-enable tap highlight for better feedback */
  button,
  a,
  .button,
  [role="button"] {
    -webkit-tap-highlight-color: rgba(255, 215, 0, 0.2);
  }

  /* Active states for touch */
  button:active,
  .button:active,
  .main-estimate-btn:active,
  .sg-qty-btn:active {
    transform: scale(0.97);
    opacity: 0.9;
  }

  .project-option:active {
    transform: scale(0.98);
    border-color: #FFD700;
  }

  .selector-btn:active {
    transform: scale(0.97);
    background: rgba(255, 215, 0, 0.3);
  }
}

/* ===== SCROLL BEHAVIOR ===== */
@media (max-width: 768px) {
  /* Lock page width to prevent horizontal sliding */
  html {
    scroll-behavior: smooth;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }

  /* Prevent horizontal scroll and page sliding */
  body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    position: relative;
    -webkit-overflow-scrolling: touch;
  }

  /* Prevent any element from causing horizontal overflow */
  *,
  *::before,
  *::after {
    max-width: 100vw;
  }

  /* Page wrapper fix */
  .page-wrapper,
  .main-wrapper,
  main {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
  }

  /* Momentum scrolling for containers */
  .sg-chat-messages,
  .sg-cart-items,
  .form-modal-card {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Prevent rubber-band scrolling on iOS */
  .sg-chat-window.active ~ body,
  .sg-cart-drawer.open ~ body {
    overflow: hidden;
    position: fixed;
    width: 100%;
  }
}

/* ===== NOTIFICATION MOBILE ===== */
@media (max-width: 768px) {
  .sg-notification {
    left: 16px !important;
    right: 16px !important;
    transform: translateY(100px) !important;
    max-width: calc(100% - 32px);
    text-align: center;
    border-radius: 12px;
    padding: 16px 20px;
    font-size: 15px;
  }

  .sg-notification.show {
    transform: translateY(0) !important;
  }
}

/* ===== CART ICON IN HEADER ===== */
@media (max-width: 768px) {
  .sg-cart-icon {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }

  .sg-cart-icon svg {
    width: 24px;
    height: 24px;
  }

  .sg-cart-count {
    min-width: 20px;
    height: 20px;
    font-size: 12px;
    top: 2px;
    right: 2px;
  }
}

/* ===== PRODUCT GRID MOBILE ===== */
@media (max-width: 768px) {
  /* Ensure product grids are properly spaced */
  .collection-list,
  .product-grid {
    gap: 16px;
    padding: 16px;
  }

  .collection-item,
  .product-card {
    border-radius: 12px;
    overflow: hidden;
  }

  /* Product images */
  .product-image {
    aspect-ratio: 1;
    object-fit: cover;
  }

  /* Product info */
  .product-title {
    font-size: 16px;
    line-height: 1.3;
    margin-bottom: 8px;
  }

  .product-price {
    font-size: 18px;
    font-weight: 600;
  }
}

/* ===== ACCESSIBILITY FOCUS STATES ===== */
@media (max-width: 768px) {
  /* Visible focus for keyboard/switch users */
  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: 3px solid #FFD700;
    outline-offset: 2px;
  }

  /* Remove default focus ring */
  button:focus:not(:focus-visible),
  a:focus:not(:focus-visible) {
    outline: none;
  }
}
