/**
 * Global mobile & touch optimizations for MyNest
 * Load after page-specific CSS
 */

/* Safe areas for notched phones */
@supports (padding: max(0px)) {
  header {
    padding-left: max(5%, env(safe-area-inset-left));
    padding-right: max(5%, env(safe-area-inset-right));
  }
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Prevent horizontal overflow sitewide */
html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

img,
video,
iframe {
  max-width: 100%;
  height: auto;
}

/* Touch-friendly minimum tap targets */
button,
.nav-cta,
.btn,
.filter-option,
.search-mockup-btn,
a.footer-social-btn {
  min-height: 44px;
}

@media (max-width: 968px) {
  .hero-content p {
    margin-left: auto;
    margin-right: auto;
  }

  .search-mockup-form {
    flex-direction: column;
  }

  .search-mockup-group {
    min-width: 100%;
  }

  .search-mockup-btn {
    width: 100%;
    min-height: 48px;
    padding: 0.9rem 1.5rem;
  }

  .hero-image {
    width: 100%;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
  }

  .hero-image img {
    width: 100% !important;
    max-width: 280px;
  }

  .section-header h2,
  .cta-banner h2 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
  }

  .cta-banner h2 {
    font-size: clamp(1.75rem, 6vw, 2.5rem);
  }

  .cta-banner p {
    font-size: 1rem;
    padding: 0 0.5rem;
  }

  .accommodations-section,
  .regional-section,
  .audiences-section,
  .owners-portal,
  .glimpse,
  .features,
  .seo-cloud-section,
  .assam-seo-footer {
    padding: 48px 5%;
  }

  .service-premium-card,
  .city-card,
  .audience-card {
    padding: 2rem 1.5rem;
  }

  .audience-card {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }

  .audience-icon {
    margin: 0 auto;
  }

  .presence-grid {
    flex-direction: column;
    gap: 2rem;
  }

  .presence-box {
    width: 100%;
    min-width: unset;
  }

  .assam-seo-content h2 {
    font-size: clamp(1.4rem, 5vw, 2rem);
  }

  .assam-seo-content p {
    font-size: 1rem;
  }

  body:not(.premium-page) .assistance-hero {
    padding: 110px 5% 40px;
  }

  body:not(.premium-page) .assistance-hero h1 {
    font-size: clamp(1.75rem, 6vw, 2.5rem);
  }

  body.premium-page .assistance-card {
    padding: 1.75rem 1.25rem;
  }

  body:not(.premium-page) .form-toggle-bar {
    flex-direction: column;
    border-radius: 16px;
  }

  body:not(.premium-page) .toggle-tab-btn {
    width: 100%;
  }

  nav.active {
    max-height: 320px;
  }

  .logo-container img {
    height: 56px;
  }

  .logo-container span {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .hero-content h1 {
    font-size: 1.85rem;
  }

  .hero {
    padding-top: 100px;
    padding-bottom: 48px;
  }

  .seo-cloud-wrapper a {
    font-size: 0.8rem;
    padding: 0.45rem 0.9rem;
  }

  .footer-content {
    gap: 2.5rem;
  }

  .category-grid,
  .city-showcase-grid {
    grid-template-columns: 1fr;
  }

  .benefit-card {
    padding: 1.75rem 1.25rem;
  }
}

/* App pages (home, property details) */
@media (max-width: 768px) {
  .menu-toggle {
    min-width: 48px;
    min-height: 48px;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
  }

  .main {
    padding: 72px 12px 24px !important;
  }

  .property-card {
    height: auto !important;
    min-height: unset !important;
    max-height: none !important;
  }

  .card-body {
    height: auto !important;
    min-height: unset !important;
  }

  .card-img {
    height: 200px !important;
  }

  .card-body h3 {
    height: auto !important;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .amenities {
    height: auto !important;
    min-height: 48px;
  }

  #user-info {
    bottom: max(12px, env(safe-area-inset-bottom)) !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    left: auto !important;
    max-width: calc(100vw - 24px);
    font-size: 0.8rem !important;
    padding: 8px 12px !important;
  }

  .quick-filters {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    scrollbar-width: none;
  }

  .quick-filters::-webkit-scrollbar {
    display: none;
  }

  .filter-option {
    flex-shrink: 0;
  }

  .search-box input,
  .search-box button {
    font-size: 16px; /* prevents iOS zoom on focus */
  }
}

@media (max-width: 768px) {
  .property-details-page .top-row {
    flex-direction: column;
  }

  .scrollable-gallery {
    -webkit-overflow-scrolling: touch;
  }

  .contact-section .contact-btn,
  .mynest-contact-btn {
    width: 100%;
    min-height: 48px;
  }

  .pg-details-box,
  .details-box {
    width: 100%;
    box-sizing: border-box;
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Auth pages (login, signup, reset) ─────────────────────────────────── */
@media (max-width: 768px) {
  .auth-page .app-container,
  .auth-page .content {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .auth-card {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
  }

  .auth-form input,
  .auth-form select,
  .auth-form button {
    font-size: 16px;
    min-height: 48px;
  }

  .back-button {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
  }
}

/* ── Dashboards (owner, admin, my-requests, my-properties) ───────────── */
@media (max-width: 900px) {
  .admin-page .admin-main {
    margin-left: 0 !important;
    padding: 72px 12px 32px !important;
  }

  .admin-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .admin-tabs::-webkit-scrollbar {
    display: none;
  }

  .admin-tab {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .admin-topbar h1 {
    font-size: 1.45rem;
  }

  .admin-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .field,
  .field--grow,
  .field--select {
    min-width: 100%;
    width: 100%;
  }

  .create-admin-form {
    grid-template-columns: 1fr;
  }

  .create-admin-form .btn-primary {
    width: 100%;
  }

  .provenance-legend li {
    align-items: flex-start;
  }

  .kpi-grid,
  .kpi-grid--compact {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .properties-hub-grid {
    grid-template-columns: 1fr;
  }

  .hub-leads-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .insights-grid {
    grid-template-columns: 1fr !important;
  }

  .dashboard-header h1 {
    font-size: 1.45rem;
  }

  .stats-cards {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .cell-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .cell-actions button {
    width: 100%;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .kpi-grid,
  .kpi-grid--compact,
  .stats-cards,
  .summary-row {
    grid-template-columns: 1fr !important;
  }

  .admin-panel {
    padding: 16px 14px 18px;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .page-header .add-btn {
    width: 100%;
    justify-content: center;
  }

  .drawer {
    width: 100vw !important;
    max-width: 100vw !important;
  }

  .modal-box {
    padding: 24px 16px !important;
    border-radius: 16px !important;
  }

  .fg2,
  .fg3 {
    grid-template-columns: 1fr !important;
  }
}

/* Form pages — prevent iOS input zoom */
@media (max-width: 768px) {
  .form-card input,
  .form-card select,
  .form-card textarea,
  .input {
    font-size: 16px;
  }
}
