/* ==========================================================================
   MEDIPE2 GLOBAL RESPONSIVE ENHANCEMENT (All Devices: 320px -> Ultrawide)
   Loaded across homepage & all 46 subpages via includes/header.php
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  max-width: 100%;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

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

iframe {
  max-width: 100%;
}

/* Prevent long URLs / emails / words from breaking mobile layout */
p, li, td, th, dd, dt, .staff-info, .faculty-info, .content-wrapper {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Smooth horizontal scrolling for tables everywhere */
.table-responsive-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Improve homepage card titles so Thai/English text never clips */
body .card-info h5 {
  height: auto !important;
  min-height: 2.7em;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Large Tablet / Small Laptop (<= 1024px) ---- */
@media (max-width: 1024px) {
  body .navbar {
    padding: 10px 16px !important;
    gap: 10px;
  }
  body .navbar .logo img {
    max-height: 52px;
    width: auto;
    max-width: 240px;
    object-fit: contain;
  }
  body .menu,
  body #nav-menu {
    max-height: calc(100vh - 72px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  body .menu a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  body .mega-menu-content {
    grid-template-columns: 1fr !important;
    padding: 12px 16px !important;
  }
  body .staff-grid,
  body .faculty-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 18px !important;
  }
  body .content-wrapper {
    padding: 36px 20px !important;
  }
}

/* ---- Tablet Portrait (<= 991px) ---- */
@media (max-width: 991px) {
  body .top-grid-layout {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }
  body .contact-grid,
  body .contact-container,
  body .detail-container,
  body .book-detail-container {
    grid-template-columns: 1fr !important;
    flex-direction: column !important;
    gap: 20px !important;
  }
  body iframe {
    width: 100% !important;
    min-height: 300px;
  }
}

/* ---- Mobile Landscape & Large Phones (<= 768px) ---- */
@media (max-width: 768px) {
  body .container {
    max-width: 100% !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
  body .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    max-width: 100% !important;
    gap: 14px !important;
  }
  body .services-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px !important;
  }
  body .video-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  body .section-header {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px !important;
  }
  body .section-header .btn-pill {
    width: auto !important;
    padding: 8px 16px !important;
    font-size: 0.88rem !important;
  }
  body .collaborators-wrapper {
    gap: 18px !important;
  }
  body .partner-logo {
    width: 96px !important;
    height: 56px !important;
  }
  body .content-wrapper {
    padding: 24px 16px !important;
  }
  body .content-wrapper h1,
  body .page-banner h1,
  body .hero-banner h1 {
    font-size: clamp(1.5rem, 5.5vw, 2.1rem) !important;
    line-height: 1.3 !important;
  }
  body .content-wrapper h2 {
    font-size: clamp(1.3rem, 4.8vw, 1.75rem) !important;
    margin: 24px 0 14px !important;
  }
  body .content-wrapper p {
    font-size: 1rem !important;
    text-align: left !important;
    line-height: 1.7 !important;
  }
  /* Make any unwrapped data table horizontally scrollable on mobile */
  body .content-wrapper table,
  body main table {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  body .staff-grid,
  body .faculty-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    padding: 16px !important;
  }
  body .staff-card,
  body .faculty-card {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  body .staff-image-container,
  body .faculty-image-container {
    width: 100% !important;
    max-width: 240px !important;
    margin: 0 auto !important;
  }
  body .book-cover,
  body .book-image,
  body .detail-image {
    width: 100% !important;
    max-width: 320px !important;
    margin: 0 auto !important;
  }
  /* Footer stacking */
  body footer .footer-container,
  body footer .footer-grid,
  body .footer-content {
    grid-template-columns: 1fr !important;
    flex-direction: column !important;
    gap: 20px !important;
    text-align: left !important;
  }
}

/* ---- Small Phones (<= 540px) ---- */
@media (max-width: 540px) {
  body .navbar .logo img {
    max-height: 44px;
    max-width: 195px;
  }
  body .card-grid,
  body .services-grid {
    grid-template-columns: 1fr !important;
  }
  body .card-thumb {
    height: 185px !important;
  }
  body .section-header {
    flex-direction: column !important;
    align-items: flex-start !important;
  }
  body .section-header .btn-pill {
    width: 100% !important;
    text-align: center !important;
  }
}
