/**
 * Mobile Responsive Enhancements for MarketingOS
 * Comprehensive mobile-first responsive design improvements
 * Applies to all frontend pages
 */

/* ============================================
   GLOBAL MOBILE OPTIMIZATIONS
   ============================================ */

/* Ensure proper viewport scaling */
@viewport {
  width: device-width;
  zoom: 1;
}

/* Prevent horizontal scroll on mobile */
* {
  box-sizing: border-box;
  max-width: 100%;
}

html {
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* ============================================
   TYPOGRAPHY SCALING
   ============================================ */

/* Base font size responsive scaling */
html {
  font-size: 16px;
}

@media (max-width: 1200px) {
  html {
    font-size: 15px;
  }
}

@media (max-width: 768px) {
  html {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 13px;
  }
}

/* Heading responsive sizes */
h1, .text-4xl, .text-5xl {
  font-size: clamp(2rem, 5vw + 1rem, 3rem);
  line-height: 1.2;
}

h2, .text-3xl {
  font-size: clamp(1.75rem, 4vw + 0.5rem, 2.5rem);
  line-height: 1.3;
}

h3, .text-2xl {
  font-size: clamp(1.5rem, 3vw + 0.5rem, 2rem);
  line-height: 1.4;
}

h4, .text-xl {
  font-size: clamp(1.25rem, 2vw + 0.5rem, 1.5rem);
  line-height: 1.5;
}

/* ============================================
   SPACING & PADDING
   ============================================ */

/* Responsive padding for sections */
@media (max-width: 768px) {
  section {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  .content-max,
  .mx-auto {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Reduce vertical spacing on mobile */
  .py-16, .py-24 {
    padding-top: 3rem !important;
    padding-bottom: 3rem !important;
  }

  .py-12 {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }
}

@media (max-width: 480px) {
  section {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  .py-16, .py-24 {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }
}

/* ============================================
   GRID LAYOUTS
   ============================================ */

/* Responsive grid columns */
@media (max-width: 1024px) {
  .grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .md\\:grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (max-width: 768px) {
  .grid,
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .md\\:grid-cols-2,
  .md\\:grid-cols-3,
  .md\\:grid-cols-4 {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  /* Stack pricing cards */
  .price-card {
    margin-bottom: 1.5rem;
  }

  /* Remove transform scale on featured card for mobile */
  .price-card.featured {
    transform: none !important;
    scale: 1 !important;
  }
}

/* ============================================
   NAVIGATION & HEADER
   ============================================ */

/* Mobile header improvements */
@media (max-width: 768px) {
  header {
    padding: 0.75rem 1rem !important;
  }

  header .flex {
    gap: 0.5rem;
  }

  /* Ensure menu toggle button is visible and accessible */
  #menu-toggle {
    padding: 0.5rem;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
  }

  /* Mobile menu enhancements */
  .mobile-menu {
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  }

  .mobile-menu nav {
    padding: 1rem !important;
  }

  .mobile-menu a {
    padding: 0.75rem 0;
    display: block;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.9375rem;
  }

  .mobile-menu a:last-child {
    border-bottom: none;
  }

  /* Hide desktop nav on mobile */
  .md\\:flex {
    display: none !important;
  }
}

/* ============================================
   BUTTONS & FORMS
   ============================================ */

/* Touch-friendly buttons */
@media (max-width: 768px) {
  button,
  .btn,
  a.btn,
  input[type="submit"],
  input[type="button"] {
    min-height: 44px; /* Apple's recommended touch target size */
    min-width: 44px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
  }

  /* Ensure CTAs are prominent */
  .bg-black {
    font-weight: 500;
  }

  /* Stack button groups */
  .flex-col.sm\\:flex-row,
  .sm\\:space-x-4 {
    flex-direction: column !important;
    gap: 1rem !important;
  }

  .sm\\:space-x-4 > * {
    width: 100%;
  }
}

/* ============================================
   CARDS & CONTAINERS
   ============================================ */

/* Responsive cards */
@media (max-width: 768px) {
  .card,
  .price-card,
  .bg-gray-50 {
    padding: 1rem !important;
    margin-bottom: 1rem;
  }

  /* Status cards on homepage */
  .bg-gray-50.border {
    padding: 1rem !important;
  }

  .bg-gray-50.border .text-3xl {
    font-size: 2rem;
  }

  /* Capability cards */
  .bg-white.border-gray-200 {
    padding: 1rem !important;
  }
}

/* ============================================
   IMAGES & MEDIA
   ============================================ */

/* Responsive images */
img,
svg {
  max-width: 100%;
  height: auto;
}

@media (max-width: 768px) {
  svg {
    width: auto;
    max-width: 100%;
  }
}

/* ============================================
   TABLES
   ============================================ */

/* Responsive tables */
@media (max-width: 768px) {
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  thead {
    display: none;
  }

  tr {
    display: block;
    margin-bottom: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
  }

  td {
    display: block;
    text-align: right;
    padding: 0.5rem;
    border-bottom: 1px solid #f3f4f6;
  }

  td:last-child {
    border-bottom: none;
  }

  td::before {
    content: attr(data-label);
    float: left;
    font-weight: 600;
  }
}

/* ============================================
   DASHBOARD SPECIFIC
   ============================================ */

@media (max-width: 768px) {
  /* Hide sidebar on mobile, show hamburger menu instead */
  dashboard-sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    height: 100vh;
    width: 280px;
    background: #ffffff;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    transition: left 0.3s ease;
    z-index: 1000;
  }

  dashboard-sidebar.active {
    left: 0;
  }

  /* Main content takes full width */
  #main-content {
    padding: 1rem !important;
    width: 100%;
  }

  /* Adjust dashboard layout */
  dashboard-layout {
    grid-template-areas:
      "header"
      "main" !important;
    grid-template-columns: 1fr !important;
  }

  /* Campaign cards stack */
  campaign-card,
  .campaign-item {
    width: 100%;
    margin-bottom: 1rem;
  }
}

/* ============================================
   FORM PAGES (Login, Signup, Settings)
   ============================================ */

@media (max-width: 768px) {
  /* Form containers */
  .max-w-md,
  .max-w-lg,
  .max-w-xl {
    max-width: 100% !important;
    padding: 1rem;
  }

  /* Form inputs */
  input,
  select,
  textarea {
    font-size: 16px !important; /* Prevent zoom on iOS */
    padding: 0.75rem;
  }

  /* Onboarding wizard */
  .wizard-step {
    padding: 1rem;
  }

  /* Settings tabs */
  .settings-tab {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .settings-tab button {
    min-width: 100px;
    flex-shrink: 0;
  }
}

/* ============================================
   MODALS & OVERLAYS
   ============================================ */

@media (max-width: 768px) {
  /* Full-screen modals on mobile */
  .modal,
  [role="dialog"] {
    width: 100vw;
    height: 100vh;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    border-radius: 0;
  }

  /* Modal content scrollable */
  .modal-content {
    overflow-y: auto;
    max-height: calc(100vh - 4rem);
  }
}

/* ============================================
   FOOTER
   ============================================ */

@media (max-width: 768px) {
  footer {
    padding: 2rem 1rem !important;
  }

  footer .grid {
    grid-template-columns: 1fr !important;
    gap: 2rem !important;
  }

  footer .grid > div {
    text-align: center;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Mobile-only display */
.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none !important;
  }
}

/* Mobile text alignment */
@media (max-width: 768px) {
  .mobile-center {
    text-align: center !important;
  }

  .mobile-left {
    text-align: left !important;
  }
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */

/* Reduce animations on mobile for performance */
@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
  * {
    animation-duration: 0.3s !important;
    transition-duration: 0.2s !important;
  }
}

/* Disable animations if user prefers reduced 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;
  }
}

/* ============================================
   LANDSCAPE MOBILE OPTIMIZATION
   ============================================ */

@media (max-width: 896px) and (orientation: landscape) {
  /* Reduce header height in landscape */
  header {
    padding: 0.5rem 1rem !important;
  }

  /* Compact section padding */
  section {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }

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

/* ============================================
   SMALL MOBILE (< 400px)
   ============================================ */

@media (max-width: 400px) {
  /* Extra compact spacing */
  .content-max {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  /* Smaller font sizes */
  body {
    font-size: 0.875rem;
  }

  /* Compact buttons */
  button,
  .btn {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
  }

  /* Pricing cards */
  .price-card {
    padding: 1rem !important;
  }

  .price-card .text-4xl {
    font-size: 2rem;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  /* Hide navigation and non-essential elements */
  header,
  footer,
  .mobile-menu,
  #menu-toggle,
  button,
  .btn {
    display: none !important;
  }

  /* Full width for print */
  * {
    max-width: 100% !important;
  }

  /* Black text for better print */
  body {
    color: #000000;
  }

  /* Page breaks */
  section {
    page-break-inside: avoid;
  }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Focus visible for keyboard navigation */
@media (max-width: 768px) {
  a:focus-visible,
  button:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: 3px solid #000000;
    outline-offset: 2px;
  }

  /* Skip to main content link */
  .skip-to-main {
    position: absolute;
    left: -9999px;
    z-index: 999;
  }

  .skip-to-main:focus {
    left: 50%;
    transform: translateX(-50%);
    top: 1rem;
    background: #000000;
    color: #ffffff;
    padding: 1rem 2rem;
    border-radius: 0.5rem;
  }
}

/* ============================================
   DARK MODE READY (for future implementation)
   ============================================ */

@media (prefers-color-scheme: dark) {
  /* Placeholder for dark mode styles
     Will be populated when dark mode task is completed */
}
