/**
 * Mobile Responsive CSS Foundation
 * Provides responsive breakpoints, touch targets, and mobile-first design
 * Requirements: 1.1, 1.2, 1.4
 */

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */

:root {
  /* Touch Target Sizes (WCAG 2.1 Level AAA) */
  --touch-target-min: 44px;
  --touch-target-comfortable: 48px;
  --touch-target-large: 56px;

  /* Spacing Scale */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-2xl: 48px;

  /* Typography Scale - Mobile First */
  --font-size-xs: 12px;
  --font-size-sm: 14px;
  --font-size-base: 16px;
  --font-size-lg: 18px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;
  --font-size-3xl: 30px;
  --font-size-4xl: 36px;

  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;

  /* Breakpoints (for JS usage) */
  --breakpoint-mobile: 768px;
  --breakpoint-tablet: 1024px;
}


/* ============================================
   Base Mobile Styles (Mobile First)
   ============================================ */

/* Touch target sizes only apply on mobile devices */
@media (max-width: 767px) {
  button,
  a,
  input[type="button"],
  input[type="submit"],
  input[type="reset"],
  .btn,
  .touch-target {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
  }
}

/* Prevent text size adjustment on orientation change */
html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Smooth scrolling for better mobile experience */
html {
  scroll-behavior: smooth;
}

/* Prevent horizontal overflow */
body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* Responsive images by default */
img {
  max-width: 100%;
  height: auto;
}


/* ============================================
   Mobile Breakpoint (<768px)
   ============================================ */

@media (max-width: 767px) {
  /* Typography adjustments for mobile */
  body {
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
  }

  h1 {
    font-size: var(--font-size-3xl);
    line-height: var(--line-height-tight);
  }

  h2 {
    font-size: var(--font-size-2xl);
    line-height: var(--line-height-tight);
  }

  h3 {
    font-size: var(--font-size-xl);
    line-height: var(--line-height-normal);
  }

  h4 {
    font-size: var(--font-size-lg);
    line-height: var(--line-height-normal);
  }

  /* Spacing adjustments for mobile */
  .container,
  .content-wrapper {
    padding-left: var(--spacing-md);
    padding-right: var(--spacing-md);
  }

  /* Stack elements vertically on mobile */
  .flex-row-desktop {
    flex-direction: column;
  }

  /* Full width buttons on mobile */
  .btn-mobile-full {
    width: 100%;
    display: block;
  }

  /* Increase touch targets on mobile */
  button:not(.editor-toolbar button):not(.ql-toolbar button),
  a.btn,
  .btn {
    min-height: var(--touch-target-comfortable);
    padding: var(--spacing-sm) var(--spacing-md);
  }

  /* Hide desktop-only elements */
  .desktop-only {
    display: none !important;
  }

  /* Show mobile-only elements */
  .mobile-only {
    display: block !important;
  }
}


/* ============================================
   Tablet Breakpoint (768px - 1024px)
   ============================================ */

@media (min-width: 768px) and (max-width: 1023px) {
  /* Typography adjustments for tablet */
  body {
    font-size: var(--font-size-base);
  }

  h1 {
    font-size: var(--font-size-4xl);
  }

  h2 {
    font-size: var(--font-size-3xl);
  }

  h3 {
    font-size: var(--font-size-2xl);
  }

  /* Spacing adjustments for tablet */
  .container,
  .content-wrapper {
    padding-left: var(--spacing-lg);
    padding-right: var(--spacing-lg);
  }

  /* Touch targets remain comfortable on tablet - but not for editor buttons */
  button:not(.editor-toolbar button):not(.ql-toolbar button),
  a.btn,
  .btn {
    min-height: var(--touch-target-min);
  }

  /* Hide mobile-only elements on tablet */
  .mobile-only {
    display: none !important;
  }

  /* Show tablet-specific elements */
  .tablet-only {
    display: block !important;
  }
}


/* ============================================
   Desktop Breakpoint (>1024px)
   ============================================ */

@media (min-width: 1024px) {
  /* Typography adjustments for desktop */
  body {
    font-size: var(--font-size-base);
  }

  h1 {
    font-size: var(--font-size-4xl);
  }

  h2 {
    font-size: var(--font-size-3xl);
  }

  h3 {
    font-size: var(--font-size-2xl);
  }

  /* Spacing adjustments for desktop */
  .container,
  .content-wrapper {
    padding-left: var(--spacing-xl);
    padding-right: var(--spacing-xl);
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
  }

  /* Hide mobile and tablet only elements */
  .mobile-only,
  .tablet-only {
    display: none !important;
  }

  /* Show desktop-only elements */
  .desktop-only {
    display: block !important;
  }
}


/* ============================================
   Orientation Change Handling
   Requirement: 1.3 - Adjust layout within 500ms
   ============================================ */

@media (orientation: portrait) {
  .orientation-landscape-only {
    display: none !important;
  }

  .orientation-portrait-only {
    display: block !important;
  }
}

@media (orientation: landscape) {
  .orientation-portrait-only {
    display: none !important;
  }

  .orientation-landscape-only {
    display: block !important;
  }
}

/* Smooth transitions for orientation changes */
* {
  transition: width 0.3s ease, height 0.3s ease, padding 0.3s ease, margin 0.3s ease;
}

/* Disable transitions for elements that shouldn't animate */
*:not(.animate-on-orientation) {
  transition: none;
}

/* Enable transitions only for layout properties on orientation change */
.responsive-container,
.responsive-layout {
  transition: all 0.3s ease;
}


/* ============================================
   Utility Classes
   ============================================ */

/* Responsive display utilities */
.hide-mobile {
  display: none !important;
}

@media (min-width: 768px) {
  .hide-mobile {
    display: block !important;
  }
  
  .hide-tablet {
    display: none !important;
  }
}

@media (min-width: 1024px) {
  .hide-tablet {
    display: block !important;
  }
  
  .hide-desktop {
    display: none !important;
  }
}

/* Responsive text alignment */
.text-center-mobile {
  text-align: center;
}

@media (min-width: 768px) {
  .text-center-mobile {
    text-align: left;
  }
}

/* Responsive spacing utilities */
.stack-mobile > * + * {
  margin-top: var(--spacing-md);
}

@media (min-width: 768px) {
  .stack-mobile {
    display: flex;
    gap: var(--spacing-md);
  }
  
  .stack-mobile > * + * {
    margin-top: 0;
  }
}

/* Touch-friendly spacing */
.touch-spacing {
  padding: var(--spacing-md);
}

@media (max-width: 767px) {
  .touch-spacing {
    padding: var(--spacing-lg);
  }
}


/* ============================================
   Editor Responsive Styles
   Requirement: 1.1, 1.2 - Prevent horizontal scrolling
   ============================================ */

.editor,
.editor-content,
.editor-wrapper {
  max-width: 100%;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

@media (max-width: 767px) {
  .editor,
  .editor-content {
    width: 100%;
    padding: var(--spacing-md);
  }

  /* Ensure editor toolbar is touch-friendly */
  .editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
  }

  .editor-toolbar button {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
  }

  /* Make editor inputs full width on mobile */
  .editor input[type="text"],
  .editor textarea {
    width: 100%;
    font-size: var(--font-size-base);
  }
}

/* Prevent zoom on input focus (iOS) */
@media (max-width: 767px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  textarea,
  select {
    font-size: 16px !important;
  }
}


/* ============================================
   Accessibility & Touch Enhancements
   ============================================ */

/* Increase tap target size for small elements */
@media (max-width: 767px) {
  /* Links in text should have adequate spacing */
  p a,
  li a {
    padding: var(--spacing-xs) 0;
    display: inline-block;
  }

  /* Icon buttons need larger touch targets */
  .icon-btn,
  button[aria-label] {
    min-width: var(--touch-target-comfortable);
    min-height: var(--touch-target-comfortable);
    padding: var(--spacing-sm);
  }

  /* Form controls should be easy to tap */
  input[type="checkbox"],
  input[type="radio"] {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
  }
}

/* Focus styles for keyboard navigation */
*:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Remove focus outline for mouse users */
*:focus:not(:focus-visible) {
  outline: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  button,
  a,
  input {
    border: 2px solid currentColor;
  }
}

/* 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;
  }
}
