/**
 * Turismo MT - Mobile Responsive
 * Layout V2 - Sprint 9
 * Version: 1.0
 */

/* ==========================================
   FIX 1: Global Overflow Prevention
   ========================================== */

html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

/* ==========================================
   FIX 2: Touch Targets (min 44x44px)
   ========================================== */

@media (max-width: 767px) {
  a,
  button,
  .btn,
  input[type="button"],
  input[type="submit"],
  [role="button"] {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Inline links exception */
  p a,
  span a,
  li a:not(.btn) {
    min-height: auto;
    min-width: auto;
    padding: 4px 0;
  }
}

/* ==========================================
   FIX 3: Header Mobile
   ========================================== */

@media (max-width: 767px) {
  .header {
    height: var(--header-height-mobile);
    padding: 0 var(--space-4);
  }
  
  .header-logo {
    max-width: 120px;
  }
  
  .header-logo img {
    height: 32px;
    width: auto;
  }
  
  /* Menu toggle */
  .menu-toggle {
    display: flex;
    width: 44px;
    height: 44px;
    padding: var(--space-2);
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    cursor: pointer;
    z-index: calc(var(--z-fixed) + 10);
  }
  
  .menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--color-text-primary);
    margin: 3px auto;
    transition: var(--transition-fast);
    border-radius: 2px;
  }
  
  .menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
  }
  
  .menu-toggle.active span:nth-child(2) {
    opacity: 0;
  }
  
  .menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
  }
  
  /* Nav drawer */
  .nav-menu,
  .header-nav {
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    background: var(--color-bg-secondary);
    padding: calc(var(--header-height-mobile) + var(--space-4)) var(--space-4) var(--space-8);
    flex-direction: column;
    gap: 0;
    transition: right 0.3s ease;
    z-index: var(--z-fixed);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-left: 1px solid var(--color-border);
  }
  
  .nav-menu.active,
  .header-nav.active {
    right: 0;
  }
  
  .nav-link {
    display: flex;
    align-items: center;
    width: 100%;
    padding: var(--space-4);
    font-size: var(--text-base);
    border-bottom: 1px solid var(--color-border);
    min-height: 52px;
  }
  
  .nav-link:last-child {
    border-bottom: none;
  }
  
  /* Hide desktop nav items */
  .header-actions .hide-mobile {
    display: none;
  }
}

@media (min-width: 768px) {
  .menu-toggle {
    display: none;
  }
}

/* ==========================================
   FIX 4: Hero Section Mobile
   ========================================== */

@media (max-width: 767px) {
  .hero {
    min-height: 100vh;
    min-height: 100dvh;
    padding: calc(var(--header-height-mobile) + var(--space-8)) var(--space-4) var(--space-8);
  }
  
  .hero-content {
    max-width: 100%;
    text-align: center;
  }
  
  .hero h1,
  .hero-title {
    font-size: clamp(1.75rem, 7vw, 2.5rem);
    line-height: var(--leading-tight);
  }
  
  .hero-description {
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
  }
  
  .hero-actions {
    flex-direction: column;
    gap: var(--space-3);
    width: 100%;
  }
  
  .hero-actions .btn {
    width: 100%;
    justify-content: center;
  }
  
  /* Stats grid 2x2 */
  .hero-stats,
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
  }
  
  .stat-item {
    padding: var(--space-3);
    text-align: center;
  }
  
  .stat-number {
    font-size: var(--text-2xl);
  }
  
  .stat-label {
    font-size: var(--text-xs);
  }
}

/* ==========================================
   FIX 5: Cards & Grids Mobile
   ========================================== */

@media (max-width: 767px) {
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .md\:grid-cols-2,
  .md\:grid-cols-3,
  .lg\:grid-cols-3,
  .lg\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }
  
  .card,
  .card-destino,
  .card-bioma,
  .card-cidade,
  .card-prestador {
    padding: var(--space-4);
  }
  
  .card-image {
    height: 180px;
  }
  
  .card-content {
    padding: var(--space-4);
  }
}

/* ==========================================
   FIX 6: Sections Mobile
   ========================================== */

@media (max-width: 767px) {
  section {
    padding: var(--space-12) 0;
  }
  
  .section-header {
    text-align: center;
    margin-bottom: var(--space-8);
  }
  
  .section-header h2 {
    font-size: clamp(1.5rem, 5vw, var(--text-3xl));
  }
  
  .section-header p {
    font-size: var(--text-base);
  }
}

/* ==========================================
   FIX 7: Footer Mobile
   ========================================== */

@media (max-width: 767px) {
  .footer {
    padding: var(--space-12) var(--space-4) var(--space-8);
  }
  
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-8);
    text-align: center;
  }
  
  .footer-col ul {
    align-items: center;
  }
  
  .footer-social {
    justify-content: center;
  }
  
  .footer-bottom {
    flex-direction: column;
    gap: var(--space-4);
    text-align: center;
  }
}

/* ==========================================
   FIX 8: Forms Mobile
   ========================================== */

@media (max-width: 767px) {
  /* Prevent iOS zoom */
  input,
  textarea,
  select {
    font-size: 16px !important;
  }
  
  input,
  select {
    min-height: 48px;
    padding: var(--space-3) var(--space-4);
  }
  
  textarea {
    min-height: 120px;
    padding: var(--space-3) var(--space-4);
  }
  
  .form-row,
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-4);
  }
  
  .form-actions {
    flex-direction: column;
    gap: var(--space-3);
  }
  
  .form-actions .btn {
    width: 100%;
  }
}

/* ==========================================
   FIX 9: Chat Widget Mobile
   ========================================== */

@media (max-width: 767px) {
  .chat-fab {
    width: 56px;
    height: 56px;
    bottom: var(--space-4);
    right: var(--space-4);
  }
  
  .chat-widget {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }
  
  .chat-header {
    padding: var(--space-4);
    border-radius: 0;
  }
  
  .chat-messages {
    height: calc(100vh - 140px);
    height: calc(100dvh - 140px);
  }
  
  .chat-input-area {
    padding: var(--space-3);
  }
}

/* ==========================================
   FIX 10: Filters Drawer Mobile
   ========================================== */

@media (max-width: 767px) {
  .filters-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 300px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    background: var(--color-bg-secondary);
    z-index: var(--z-modal);
    padding: var(--space-6);
    transition: left 0.3s ease;
    overflow-y: auto;
    border-right: 1px solid var(--color-border);
  }
  
  .filters-sidebar.active {
    left: 0;
  }
  
  .filters-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-modal) - 1);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }
  
  .filters-backdrop.active {
    opacity: 1;
    visibility: visible;
  }
  
  .filters-toggle {
    display: flex;
  }
}

@media (min-width: 768px) {
  .filters-toggle,
  .filters-backdrop {
    display: none;
  }
}

/* ==========================================
   FIX 11: Safe Areas (Notch/Home Indicator)
   ========================================== */

@supports (padding: env(safe-area-inset-bottom)) {
  .footer {
    padding-bottom: calc(var(--space-8) + env(safe-area-inset-bottom));
  }
  
  .nav-menu,
  .header-nav {
    padding-bottom: calc(var(--space-8) + env(safe-area-inset-bottom));
  }
  
  .chat-fab {
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }
  
  .chat-input-area {
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  }
}

/* ==========================================
   FIX 12: Landscape Mobile
   ========================================== */

@media (max-width: 896px) and (orientation: landscape) {
  .hero {
    min-height: 100vh;
    padding-top: calc(var(--header-height-mobile) + var(--space-4));
    padding-bottom: var(--space-4);
  }
  
  .hero h1 {
    font-size: var(--text-2xl);
  }
  
  .hero-stats,
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2);
  }
}

/* ==========================================
   FIX 13: Small Screens (iPhone SE)
   ========================================== */

@media (max-width: 375px) {
  .container {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
  
  .hero h1 {
    font-size: 1.5rem;
  }
  
  .hero-description {
    font-size: var(--text-sm);
  }
  
  .section-header h2 {
    font-size: 1.25rem;
  }
  
  .card,
  .card-destino {
    padding: var(--space-3);
  }
  
  .nav-menu,
  .header-nav {
    width: 100%;
    max-width: 100%;
  }
}

/* ==========================================
   FIX 14: Accessibility Mobile
   ========================================== */

@media (max-width: 767px) {
  *:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
  }
  
  .skip-to-content {
    position: absolute;
    top: -100px;
    left: var(--space-4);
    background: var(--color-primary);
    color: var(--color-bg-primary);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-weight: var(--font-semibold);
    z-index: var(--z-max);
    transition: top 0.2s ease;
  }
  
  .skip-to-content:focus {
    top: var(--space-4);
  }
}

/* ==========================================
   FIX 15: Performance Mobile
   ========================================== */

@media (max-width: 767px) {
  /* Disable heavy effects on low-end devices */
  @media (max-resolution: 1.5dppx) {
    .bg-glass {
      backdrop-filter: none;
      -webkit-backdrop-filter: none;
      background: var(--color-bg-secondary);
    }
  }
  
  /* Reduce motion if preferred */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}
