/**
 * Site-wide mobile & responsive utilities
 * Loaded on every page via header.php
 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

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

table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

pre,
code {
  max-width: 100%;
  overflow-x: auto;
  word-break: break-word;
}

/* Bootstrap-style rows used on cart / legacy pages */
@media (max-width: 767px) {
  div.row {
    flex-wrap: wrap;
    margin-left: 0;
    margin-right: 0;
  }

  .container,
  .container-fluid {
    padding-left: 16px;
    padding-right: 16px;
    max-width: 100%;
  }
}

/* Touch-friendly controls */
@media (max-width: 768px) {
  button,
  .btn,
  .lp-btn,
  .lp-filter-chip,
  .btn-details,
  .add-to-cart-button,
  .load-more-past-papers,
  .mobile-filter-toggle,
  .filter-dropdown-btn,
  .plan-btn-modern {
    min-height: 44px;
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  select,
  textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
  }
}

/* Paper browse grid */
@media (max-width: 768px) {
  #paperCardsListBucket.papers-grid {
    margin: 0;
    padding: 0;
  }

  .popular-searches {
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
  }
}

/* Past paper answers */
@media (max-width: 992px) {
  .answers-grid-container {
    grid-template-columns: 1fr !important;
    gap: 20px;
  }

  .pdf-viewer-column {
    position: relative !important;
    top: 0 !important;
    max-width: 100% !important;
    order: -1;
    padding: 20px 16px !important;
  }

  .pdf-viewer-wrapper {
    height: min(55vh, 420px) !important;
  }

  .past-paper-answer .content-container {
    padding: 12px 16px;
  }
}

@media (max-width: 480px) {
  .dictionary-dropdown-popup,
  .flag-dropdown-menu {
    width: calc(100vw - 32px) !important;
    max-width: calc(100vw - 32px) !important;
    left: 16px !important;
    right: 16px !important;
  }

  .report li,
  .answerList li {
    min-width: 40px;
  }
}

/* Dashboard & auth pages */
@media (max-width: 768px) {
  .dashboard-container,
  .login-container,
  .help-container {
    padding-left: 16px;
    padding-right: 16px;
  }

  .packed-card,
  .paper-card-dashboard {
    max-width: 100%;
  }
}

/* Help page */
@media (max-width: 768px) {
  .hero-section {
    padding: 48px 16px !important;
  }

  .hero-title {
    font-size: clamp(1.75rem, 8vw, 2.25rem) !important;
  }

  .help-section,
  .faq-section,
  .contact-section {
    padding-left: 16px;
    padding-right: 16px;
  }

  .faq-question {
    font-size: 1rem;
    padding: 16px;
  }
}

/* Cart */
@media (max-width: 767px) {
  .cart-page .cart-summary,
  .cart-summary {
    width: 100%;
  }

  .cart-item-row .cart-item-actions {
    width: 100%;
    justify-content: center;
  }
}

/* Pricing widget (paperpack) */
@media (max-width: 768px) {
  .pricing-grid {
    padding: 0 4px;
  }

  .pricing-card {
    padding: 24px 18px !important;
  }

  .plan-price {
    font-size: clamp(2rem, 10vw, 2.75rem) !important;
  }
}

/* Utility */
.u-mobile-scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

body.mobile-nav-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Homepage (landing-page) */
@media (max-width: 768px) {
  body.landing-page .modern-footer .footer-grid {
    grid-template-columns: 1fr;
    gap: 28px;
    text-align: center;
  }

  body.landing-page .modern-footer .footer-brand,
  body.landing-page .modern-footer .footer-social {
    align-items: center;
    justify-content: center;
  }

  body.landing-page .modern-footer .footer-bottom {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  body.landing-page .modern-footer .footer-legal {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 12px;
  }
}

/* Legacy bootstrap columns */
@media (max-width: 767px) {
  [class*="col-md-"],
  [class*="col-lg-"],
  [class*="col-sm-"] {
    width: 100%;
    max-width: 100%;
    flex: 0 0 100%;
  }

  .modern-footer .footer-container {
    padding-left: 16px;
    padding-right: 16px;
  }
}
