/**
 * Mobile Optimization CSS
 * iPhone 16 & Modern iOS Responsive Design
 * Preserves Frutiger Aero aesthetic while optimizing for mobile
 * 
 * IMPORTANT: Load this CSS AFTER main-layout.css to override desktop styles
 * Link: <link rel="stylesheet" href="css/mobile-optimization.css">
 */

/* ================================================================
   ROOT-LEVEL RESPONSIVE TYPOGRAPHY & SPACING SCALE
   ================================================================ */

:root {
  /* ===== Responsive Font Sizes (clamp for fluid scaling) ===== */
  --font-size-h1: clamp(1.75rem, 6vw, 3rem);
  --font-size-h2: clamp(1.25rem, 4.5vw, 2rem);
  --font-size-h3: clamp(1.1rem, 3.5vw, 1.5rem);
  --font-size-h4: clamp(1rem, 3vw, 1.25rem);
  --font-size-body: 16px; /* iOS standard */
  --font-size-small: clamp(0.75rem, 2.5vw, 0.875rem);
  --font-size-tiny: clamp(0.625rem, 2vw, 0.75rem);

  /* ===== Responsive Spacing Scale ===== */
  --space-xs: clamp(0.25rem, 1vw, 0.5rem);
  --space-sm: clamp(0.5rem, 2vw, 1rem);
  --space-md: clamp(1rem, 3vw, 1.5rem);
  --space-lg: clamp(1.5rem, 4vw, 2rem);
  --space-xl: clamp(2rem, 5vw, 3rem);
  --space-2xl: clamp(2.5rem, 6vw, 4rem);

  /* ===== Touch Target Sizing ===== */
  --tap-target-min: 44px;
  --tap-target-sm: 48px;
  --tap-target-lg: 56px;

  /* ===== Line Height for Readability ===== */
  --line-height-tight: 1.2;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;
}

/* ================================================================
   BODY & GLOBAL BASELINE
   ================================================================ */

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%; /* Prevent font scaling on rotation */
}

body {
  font-size: 16px; /* iOS minimum readable size */
  line-height: var(--line-height-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  
  /* iOS Safe Area Padding - remove top padding to allow main content to go to top */
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-top: 0;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  
  /* Prevent rubber-band scroll */
  height: 100%;
  overflow: hidden;
}

/* ================================================================
   IMAGES & MEDIA - FULL RESPONSIVENESS
   ================================================================ */

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

img {
  -webkit-user-select: none;
  user-select: none;
}

/* Product images */
.product-image,
.main-product-image,
.gallery-image,
.featured-image {
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: cover;
}

/* Aspect ratio containers for videos */
.video-container,
.iframe-container,
.image-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
}

@media (max-width: 480px) {
  .video-container {
    aspect-ratio: 9 / 16; /* Portrait on mobile */
  }
}

/* ================================================================
   RESPONSIVE TYPOGRAPHY - HEADINGS & TEXT
   ================================================================ */

h1, .h1 {
  font-size: var(--font-size-h1);
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-md);
}

h2, .h2 {
  font-size: var(--font-size-h2);
  line-height: 1.3;
  margin-bottom: var(--space-md);
}

h3, .h3 {
  font-size: var(--font-size-h3);
  line-height: 1.4;
  margin-bottom: var(--space-sm);
}

h4, h5, h6 {
  font-size: var(--font-size-h4);
  margin-bottom: var(--space-sm);
}

p {
  line-height: var(--line-height-normal);
  margin-bottom: var(--space-md);
}

small,
.small {
  font-size: var(--font-size-small);
}

/* ================================================================
   MOBILE-FIRST SIDEBAR NAVIGATION
   ================================================================ */

.sidebar {
  /* Desktop default - visible on right side */
  position: fixed;
  left: 20px;
  top: 20px;
  width: 200px;
  z-index: 6;
  opacity: 1;
  transform: translateX(0);
  transition: all 0.3s ease;
}

@media (max-width: 768px) {
  /* Tablet & Mobile - convert to overlay */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 220px;
    height: 100vh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  /* Mobile menu toggle - show hamburger */
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Sidebar open state */
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
  }

  /* Mobile overlay backdrop */
  .mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 950;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .mobile-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* Ensure sidebar nav-links are always clickable when menu is open */
  .sidebar.mobile-open .nav-link,
  .sidebar.mobile-open a,
  .sidebar.mobile-open button {
    pointer-events: auto !important;
    z-index: 2001 !important;
  }
  
  /* Keep .sidebar-overlay for backward compatibility */
  .sidebar-overlay {
    display: none;
  }

  .sidebar-overlay.active {
    display: none;
  }

  /* Navigation items - increase touch targets */
  .nav-link {
    padding: 12px 16px;
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: 16px;
  }
}

/* ================================================================
   MAIN CONTENT LAYOUT - RESPONSIVE MARGINS
   ================================================================ */

.main-layout-container {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
}

.main-content-panel {
  margin-left: 240px;
  width: calc(100% - 240px);
  max-width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
  .main-content-panel {
    margin-left: 0;
    width: 100%;
    padding: 0;
    height: auto;
    align-self: flex-start;
  }
}

/* ================================================================
   CONTENT WINDOW - RESPONSIVE HEIGHT & WIDTH
   ================================================================ */

.content-window {
  height: 85vh;
  width: 90%;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(20px);
}

@media (max-width: 1024px) {
  .content-window {
    width: 92%;
    margin-top: 1rem;
    margin-bottom: 1rem;
  }
}

@media (max-width: 768px) {
  .content-window {
    width: 100%;
    height: auto;
    min-height: 60vh;
    max-height: 90vh;
    margin: 0;
    border-radius: 0;
    background: transparent;
    backdrop-filter: none;
  }
}

@media (max-width: 480px) {
  .content-window {
    min-height: 50vh;
  }
}

/* Window header sticky on mobile */
.window-header {
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
  padding: var(--space-md);
}

@media (max-width: 480px) {
  .window-header {
    padding: var(--space-sm);
  }
}

/* Dynamic content area - smooth scrolling */
.dynamic-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding: var(--space-md);
}

@media (max-width: 480px) {
  .dynamic-content {
    padding: var(--space-sm);
  }
}

/* ================================================================
   TOUCH TARGET SIZING - 44px MINIMUM
   ================================================================ */

/* Navigation and menu buttons */
.nav-link,
.menu-btn,
.hamburger-btn {
  min-height: var(--tap-target-min);
  min-width: var(--tap-target-min);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.nav-link:active,
.menu-btn:active,
.hamburger-btn:active {
  background: rgba(0, 201, 215, 0.2);
  transform: scale(0.95);
}

/* Primary buttons */
button,
[role="button"],
.btn,
.aero-button {
  min-height: var(--tap-target-min);
  padding: 10px 16px;
  font-size: 16px;
  border-radius: 12px;
  transition: all 0.2s ease;
  cursor: pointer;
  
  /* Remove tap highlight on iOS */
  -webkit-tap-highlight-color: transparent;
}

button:active,
[role="button"]:active,
.btn:active,
.aero-button:active {
  opacity: 0.85;
  transform: translateY(1px);
}

/* Large action buttons on mobile */
@media (max-width: 480px) {
  .add-to-cart-btn,
  .buy-now-btn,
  .checkout-btn,
  .primary-action {
    min-height: var(--tap-target-sm);
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
  }
}

/* Form controls */
input,
textarea,
select {
  min-height: var(--tap-target-min);
  padding: 10px 12px;
  font-size: 16px; /* Prevents auto-zoom on iOS */
  border-radius: 8px;
  border: 1px solid rgba(0, 201, 215, 0.3);
  background: rgba(255, 255, 255, 0.9);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #00C9D7;
  box-shadow: 0 0 0 3px rgba(0, 201, 215, 0.1);
}

/* Close buttons - always accessible */
.close,
.btn-close {
  min-height: var(--tap-target-min);
  min-width: var(--tap-target-min);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ================================================================
   RESPONSIVE GRID LAYOUTS
   ================================================================ */

.product-grid,
.services-grid,
.gallery-grid,
.feature-grid {
  display: grid;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.product-grid {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.services-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* Tablet breakpoint */
@media (max-width: 768px) {
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-md);
  }

  .services-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
  }
}

/* Mobile breakpoint */
@media (max-width: 480px) {
  .product-grid,
  .services-grid,
  .gallery-grid,
  .feature-grid,
  .stats-grid,
  .collection-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }

  /* Show 2-column for product thumbnails */
  .product-thumbnail-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }
}

/* ================================================================
   RESPONSIVE PADDING & MARGINS
   ================================================================ */

.content-section,
.section-container,
.panel {
  padding: var(--space-lg);
}

.card,
.product-card,
.service-card {
  padding: var(--space-md);
}

@media (max-width: 768px) {
  .content-section,
  .section-container,
  .panel {
    padding: var(--space-md);
  }

  .card,
  .product-card,
  .service-card {
    padding: var(--space-sm);
  }
}

@media (max-width: 480px) {
  .content-section,
  .section-container,
  .panel {
    padding: var(--space-md);
  }

  .card,
  .product-card,
  .service-card {
    padding: var(--space-sm);
  }
}

/* ================================================================
   FLEX LAYOUTS - RESPONSIVE DIRECTION
   ================================================================ */

.flex-row {
  display: flex;
  flex-direction: row;
  gap: var(--space-md);
}

.flex-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* Stack on mobile */
@media (max-width: 768px) {
  .flex-row-to-col {
    flex-direction: column;
  }

  .flex-row {
    gap: var(--space-sm);
  }
}

/* ================================================================
   PRODUCT PAGE RESPONSIVE - SHOP
   ================================================================ */

.product-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-xl);
  padding: var(--space-lg);
}

.product-image-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.product-info-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

@media (max-width: 768px) {
  .product-container {
    grid-template-columns: 1fr;
    gap: var(--space-md);
    padding: var(--space-md);
  }
}

/* Product options - make larger on mobile */
.color-options,
.size-options {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.size-option,
.color-option {
  min-height: 44px;
  min-width: 44px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Sticky mobile cart button */
@media (max-width: 768px) {
  .mobile-sticky-cart {
    position: fixed;
    bottom: max(1rem, env(safe-area-inset-bottom));
    left: max(1rem, env(safe-area-inset-left));
    right: max(1rem, env(safe-area-inset-right));
    z-index: 100;
    padding: var(--space-sm);
    background: rgba(0, 201, 215, 0.95);
    border-radius: 12px;
    backdrop-filter: blur(20px);
    min-height: var(--tap-target-sm);
  }
}

/* ================================================================
   MODAL & DIALOG OPTIMIZATION
   ================================================================ */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2000;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1999;
}

.modal-content {
  background: white;
  border-radius: 20px 20px 0 0;
  padding: var(--space-lg);
  padding-bottom: max(var(--space-lg), env(safe-area-inset-bottom));
  max-height: 90vh;
  width: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* Modal close button */
.modal-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.1);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  z-index: 2001;
}

/* ================================================================
   REDUCED MOTION SUPPORT
   ================================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ================================================================
   DARK MODE SUPPORT (if applicable)
   ================================================================ */

@media (prefers-color-scheme: dark) {
  input,
  textarea,
  select {
    background: rgba(0, 0, 0, 0.3);
    color: white;
    border-color: rgba(0, 201, 215, 0.5);
  }

  input::placeholder,
  textarea::placeholder {
    color: rgba(255, 255, 255, 0.5);
  }
}

/* ================================================================
   HIGH CONTRAST MODE
   ================================================================ */

@media (prefers-contrast: more) {
  .aero-glass,
  .content-window,
  .sidebar {
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(0, 0, 0, 0.5);
  }
}

/* ================================================================
   LANDSCAPE ORIENTATION (iPhone in horizontal)
   ================================================================ */

@media (max-height: 500px) {
  .content-window {
    height: auto;
    min-height: auto;
  }

  .dynamic-content {
    max-height: 70vh;
  }

  h1 {
    font-size: clamp(1.5rem, 3vw, 1.75rem);
  }
}

/* ================================================================
   390PX IPHONE 16 SPECIFIC OPTIMIZATION
   ================================================================ */

@media (max-width: 392px) {
  :root {
    --space-lg: clamp(1.5rem, 3vw, 1.5rem);
    --space-xl: clamp(2rem, 4vw, 2rem);
  }

  .product-container {
    gap: var(--space-md);
  }

  .product-info-section {
    gap: var(--space-md);
  }

  /* Increase padding for comfortable scrolling */
  .dynamic-content {
    padding: 1rem;
  }

  /* Make buttons full width on 390px */
  .primary-action {
    width: 100%;
  }
}

/* ================================================================
   PERFORMANCE OPTIMIZATIONS
   ================================================================ */

/* Reduce backdrop-filter on lower-end devices */
@supports not (backdrop-filter: blur(1px)) {
  .aero-glass,
  .content-window,
  .sidebar {
    background: rgba(0, 20, 40, 0.9) !important;
  }
}

/* Hardware acceleration */
.sidebar,
.modal,
.dynamic-content {
  will-change: transform;
  transform: translateZ(0);
}

/* ================================================================
   ACCESSIBILITY IMPROVEMENTS
   ================================================================ */

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid #00C9D7;
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid #00C9D7;
  outline-offset: 2px;
}

/* Increase contrast on interactive elements */
a {
  color: #0077B6;
  text-decoration: underline;
}

a:visited {
  color: #0052A3;
}

/* ================================================================
   UTILITY CLASSES
   ================================================================ */

.hide-desktop {
  display: none !important;
}

@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }

  .show-mobile {
    display: block !important;
  }

  .hide-desktop {
    display: block !important;
  }
}

.container-responsive {
  width: 100%;
  max-width: 100%;
  padding: 0 var(--space-md);
}

@media (min-width: 769px) {
  .container-responsive {
    max-width: 1200px;
    margin: 0 auto;
  }
}

/* End of Mobile Optimization CSS */
