/**
 * CMS mobile upgrade — touch-first layout, drawer nav, safe areas
 * Loaded after main.css / home.css / footer.css
 */

/* —— Base touch & overflow —— */
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-overflow-scrolling: touch;
}
img, video, iframe {
  max-width: 100%;
  height: auto;
}
a, button, .qa-card, .event-item, .nav-link {
  -webkit-tap-highlight-color: rgba(122, 28, 28, 0.12);
  touch-action: manipulation;
}

/* Menu backdrop */
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.45);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.nav-backdrop.show {
  display: block;
  opacity: 1;
}
body.nav-open {
  overflow: hidden;
  touch-action: none;
}

/* Sticky header safe area */
.top-header {
  padding-top: env(safe-area-inset-top);
}

/* —— Tablet & phone nav —— */
@media (max-width: 992px) {
  .header-inner {
    padding: 8px 4px;
    gap: 8px;
  }
  .school-crest {
    height: 64px !important;
    width: 64px !important;
    padding: 6px !important;
    margin-bottom: 0 !important;
    border-width: 2px !important;
  }
  .menu-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 48px;
    border-radius: 12px;
    background: rgba(122, 28, 28, 0.06);
    z-index: 110;
  }
  .menu-toggle[aria-expanded="true"] {
    background: var(--primary-maroon);
    color: var(--accent-gold);
  }
  .main-menu {
    display: none;
    flex-direction: column;
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    width: min(86vw, 320px) !important;
    height: 100dvh !important;
    max-height: 100vh;
    padding: calc(72px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom)) !important;
    background: #fff !important;
    box-shadow: -12px 0 40px rgba(0,0,0,0.18) !important;
    gap: 4px !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 100 !important;
    transform: translateX(105%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .main-menu.open {
    display: flex !important;
    transform: translateX(0);
    animation: none !important;
  }
  .main-menu a {
    padding: 14px 16px !important;
    font-size: 1.05rem !important;
    text-align: left !important;
    border-radius: 12px;
    border-bottom: none !important;
    min-height: 48px;
    display: flex;
    align-items: center;
  }
  .main-menu a:hover,
  .main-menu a:focus {
    background: rgba(122, 28, 28, 0.06);
  }
  .main-menu a.portal-link {
    margin-top: 12px !important;
    justify-content: center;
    text-align: center !important;
    width: 100% !important;
    box-sizing: border-box;
  }
}

/* —— Phone refinements —— */
@media (max-width: 768px) {
  .container {
    padding-left: 0px;
    padding-right: 0px;
  }

  /* Hero slider: fit short phones */
  .slider-section {
    height: auto !important;
    min-height: 0 !important;
  }
  .slider-container {
    height: min(72vh, 420px) !important;
    min-height: 280px !important;
  }
  .slide-text-side {
    padding: 1.25rem 1rem 4.5rem !important;
  }
  .slide-content h2 {
    font-size: clamp(1.45rem, 6vw, 1.85rem) !important;
    line-height: 1.15 !important;
    margin-bottom: 8px !important;
  }
  .slide-content p {
    font-size: 0.95rem !important;
    line-height: 1.45 !important;
  }
  .slider-arrows {
    bottom: 12px !important;
  }
  .slider-arrows button {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    min-height: 44px;
  }

  /* Sections */
  .quick-actions-section,
  .core-values-section,
  .stats-section,
  .headteacher-about,
  .events-row,
  .gallery-section {
    padding: 2.5rem 1rem !important;
  }
  .headteacher-about {
    flex-direction: column;
    gap: 1.5rem !important;
  }
  .about-school h3 {
    font-size: 1.45rem !important;
  }
  .cms-rich-content p {
    font-size: 0.98rem !important;
  }
  .badge-row span {
    font-size: 0.82rem;
    padding: 8px 14px;
  }

  .qa-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
  .qa-card {
    flex-direction: row !important;
    text-align: left !important;
    padding: 18px 16px !important;
    gap: 14px !important;
  }
  .qa-icon {
    width: 52px !important;
    height: 52px !important;
    font-size: 1.4rem !important;
    margin: 0 !important;
    flex-shrink: 0;
  }
  .qa-text h4 {
    font-size: 1.05rem !important;
  }
  .qa-text p {
    font-size: 0.88rem !important;
  }

  .cv-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }
  .cv-icon {
    font-size: 2.2rem !important;
    margin-bottom: 10px !important;
  }
  .cv-item h4 {
    font-size: 1.05rem !important;
  }
  .cv-item p {
    font-size: 0.85rem !important;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 20px !important;
  }
  .stat-item .stat-number {
    font-size: 2.4rem !important;
  }
  .stat-item .stat-label {
    font-size: 0.78rem !important;
  }

  .gallery-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }
  .gallery-item {
    height: 160px !important;
  }
  /* Touch devices: always show caption strip */
  .gallery-overlay {
    opacity: 1 !important;
    padding: 20px 10px 10px !important;
    background: linear-gradient(0deg, rgba(26,26,26,0.92) 0%, rgba(26,26,26,0.15) 100%) !important;
  }
  .gallery-cap {
    font-size: 0.78rem !important;
  }

  .incoming-events,
  .past-events {
    padding: 1.25rem !important;
  }
  .event-item {
    padding: 12px !important;
    gap: 12px !important;
  }
  .event-desc strong {
    font-size: 0.98rem !important;
  }

  .news-ticker-wrap {
    flex-direction: column;
  }

  /* Footer */
  .footer-grid,
  .site-footer .footer-inner,
  .footer-content {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
  }
  .footer-bottom {
    flex-direction: column !important;
    text-align: center !important;
    gap: 10px !important;
  }

  /* Floating WhatsApp — clear bottom nav / safe area */
  #whatsapp-float {
    bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    right: calc(14px + env(safe-area-inset-right)) !important;
    width: 54px !important;
    height: 54px !important;
    z-index: 80;
  }
}

/* Very small phones */
@media (max-width: 400px) {
  .cv-grid {
    grid-template-columns: 1fr !important;
  }
  .gallery-grid {
    grid-template-columns: 1fr !important;
  }
  .gallery-item {
    height: 200px !important;
  }
  .stats-grid {
    grid-template-columns: 1fr !important;
  }
  .slider-container {
    height: min(68vh, 360px) !important;
  }
}

/* Landscape phones */
@media (max-width: 900px) and (orientation: landscape) {
  .slider-container {
    height: min(88vh, 320px) !important;
    min-height: 220px !important;
  }
  .slide-content h2 {
    font-size: 1.35rem !important;
  }
  .main-menu {
    width: min(70vw, 360px) !important;
  }
}

/* —— CMS Admin mobile —— */
@media (max-width: 992px) {
  .admin-layout .main-content h1 {
    font-size: 1.35rem;
    line-height: 1.25;
    padding-right: 8px;
  }
  .admin-layout .main-content h2 {
    font-size: 1.15rem;
  }
  .admin-layout table {
    font-size: 0.88rem;
  }
  .admin-layout th,
  .admin-layout td {
    padding: 10px 8px;
  }
  .admin-layout .preview-img {
    width: 72px;
    height: 48px;
  }
  .admin-layout .btn-del {
    display: inline-block;
    min-height: 40px;
    line-height: 40px;
    padding: 0 12px;
  }
  .admin-layout input,
  .admin-layout select,
  .admin-layout textarea,
  .admin-layout button {
    min-height: 48px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  .admin-layout textarea {
    min-height: 120px;
  }
  .sidebar {
    width: min(82vw, 280px) !important;
    padding-top: calc(20px + env(safe-area-inset-top)) !important;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .admin-toggle {
    top: calc(10px + env(safe-area-inset-top)) !important;
    left: calc(10px + env(safe-area-inset-left)) !important;
  }
}
