/* =============================================================================
   MOBILE PRODUCTION READINESS - Croydon Metropolitan College
   Comprehensive mobile optimizations for flawless UX
   ============================================================================= */

/* ===== CRITICAL MOBILE FIXES ===== */

/* Prevent any horizontal overflow */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  position: relative;
  width: 100%;
}

/* Body scroll lock when mobile menu is open */
body.menu-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* ===== MOBILE MENU ENHANCEMENTS ===== */

@media (max-width: 980px) {

  /* Hamburger button - works with both SVG and span-based markup */
  .hamburger {
    position: relative;
    z-index: 9999 !important;
    /* Force it to be on top of everything */
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    gap: 6px;
  }

  /* SVG hamburger icon styling */
  .hamburger .hamburger-icon,
  .hamburger svg:not(.caret) {
    width: 32px;
    height: 32px;
    stroke: #0b3d91;
    transition: all 0.3s ease;
    opacity: 1;
    transform: scale(1);
  }

  /* Hide SVG when menu is active, show X instead */
  .hamburger.is-active .hamburger-icon,
  .hamburger.is-active svg:not(.caret) {
    opacity: 0;
    transform: scale(0.5);
  }

  /* Close X button using pseudo-elements */
  .hamburger::before,
  .hamburger::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    opacity: 0;
    transition: all 0.3s ease;
    transform-origin: center;
    pointer-events: none;
    /* Ensure clicks pass through */
  }

  .hamburger::before {
    transform: translate(-50%, -50%) rotate(0deg);
  }

  .hamburger::after {
    transform: translate(-50%, -50%) rotate(0deg);
  }

  /* Show X when active */
  .hamburger.is-active::before {
    content: '' !important;
    opacity: 1 !important;
    transform: translate(-50%, -50%) rotate(45deg) !important;
    background: #fff !important;
    z-index: 10000;
  }

  .hamburger.is-active::after {
    content: '' !important;
    opacity: 1 !important;
    transform: translate(-50%, -50%) rotate(-45deg) !important;
    background: #fff !important;
    z-index: 10000;
  }

  /* Custom animated hamburger lines (span-based fallback) */
  .hamburger__line {
    display: none;
  }

  /* Ensure button stays fixed and transparent when open */
  .hamburger.is-active {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10001;
    background: transparent !important;
    border: none !important;
    width: 48px;
    height: 48px;
  }

  /* ===== FULLSCREEN MOBILE MENU ===== */
  #menu {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: #0b162b;
    z-index: 1000;
    padding: 100px 2rem 2rem 2rem;
    margin: 0;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    list-style: none;
  }

  #menu.open {
    display: flex !important;
    opacity: 1;
    visibility: visible;
  }

  /* Menu Items - Professional layout */
  #menu>li {
    width: 100%;
    max-width: 350px;
    padding: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    opacity: 0;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }

  #menu>li:last-child {
    border-bottom: none;
  }

  #menu>li>a {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 1rem 0;
    color: #fff;
    font-family: 'Nunito Sans', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: color 0.2s ease;
  }

  #menu>li>a:hover,
  #menu>li>a:focus {
    color: #F4C84A;
  }

  /* ===== PLUS BUTTON FOR SUBMENUS ===== */
  .submenu-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: transparent;
    border: none;
    border-radius: 0;
    color: #fff;
    cursor: pointer;
    transition: all 0.25s ease;
    margin-left: auto;
    flex-shrink: 0;
  }

  .submenu-toggle:hover {
    background: transparent;
    border-color: transparent;
  }

  .submenu-toggle svg,
  .submenu-toggle .caret {
    display: none;
  }

  /* Plus icon using pseudo-elements */
  .submenu-toggle::before,
  .submenu-toggle::after {
    content: '';
    position: absolute;
    background: #fff;
    border-radius: 2px;
    transition: all 0.3s ease;
  }

  .submenu-toggle::before {
    width: 14px;
    height: 2px;
  }

  .submenu-toggle::after {
    width: 2px;
    height: 14px;
  }

  /* Active state - rotate to X */
  .submenu-toggle.is-active {
    background: transparent;
    border-color: transparent;
    transform: rotate(45deg);
  }

  .submenu-toggle.is-active::before,
  .submenu-toggle.is-active::after {
    background: #fff;
  }

  /* ===== DROPDOWN SUBMENUS ===== */
  .dropdown {
    display: none;
    width: 100%;
    padding: 0.5rem 0 0.75rem 1rem;
    margin: 0;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    list-style: none;
    border-left: 2px solid #F4C84A;
  }

  .has-dropdown.open .dropdown {
    display: block;
    animation: slideDown 0.3s ease;
  }

  .dropdown li {
    margin: 0;
  }

  .dropdown a {
    display: block;
    padding: 0.5rem 0.75rem;
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    border-radius: 6px;
  }

  .dropdown a:hover,
  .dropdown a:focus {
    color: #fff;
    background: rgba(244, 200, 74, 0.1);
    padding-left: 1rem;
  }

  /* ===== ANIMATIONS ===== */
  @keyframes fadeInUp {
    from {
      opacity: 0;
      transform: translateY(15px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-8px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Ensure all interactive elements meet 44x44px minimum */
  a,
  button,
  .btn,
  .apply,
  .topbar-btn,
  input[type="submit"],
  input[type="button"] {
    min-height: 44px;
  }

  /* Social icons */
  .social a {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Footer links need adequate spacing */
  .footer__list a,
  .footer__contact-list a {
    display: inline-block;
    padding: 0.4rem 0;
    min-height: 44px;
    line-height: 2.2;
  }
}

/* ===== IMPROVED TAP FEEDBACK ===== */

@media (hover: none) and (pointer: coarse) {

  /* Active states for touch devices */
  .btn:active,
  .apply:active,
  .topbar-btn:active {
    transform: scale(0.97);
    opacity: 0.9;
  }

  .pathways-card:active {
    transform: scale(0.98);
  }

  .t-card:active {
    transform: scale(0.98);
  }

  /* Remove hover effects that cause sticky states on touch */
  .pathways-card:hover {
    transform: none;
  }

  .t-card:hover {
    transform: none;
  }

  /* Better tap highlighting */
  a,
  button {
    -webkit-tap-highlight-color: rgba(11, 61, 145, 0.15);
  }
}

/* ===== MOBILE TYPOGRAPHY ===== */

@media (max-width: 480px) {
  body {
    font-size: 15px;
    line-height: 1.6;
  }

  h1 {
    font-size: 1.75rem;
    line-height: 1.2;
  }

  h2 {
    font-size: 1.4rem;
    line-height: 1.25;
  }

  h3 {
    font-size: 1.15rem;
  }

  p {
    font-size: 0.95rem;
  }
}

/* ===== MOBILE FORMS ===== */

@media (max-width: 768px) {

  /* Prevent iOS zoom on input focus (16px minimum) */
  input,
  select,
  textarea {
    font-size: 16px !important;
    min-height: 48px;
    padding: 0.9rem 1rem;
    border-radius: 8px;
    -webkit-appearance: none;
    appearance: none;
  }

  input[type="checkbox"],
  input[type="radio"] {
    min-width: 24px;
    min-height: 24px;
    margin-right: 0.5rem;
  }

  label {
    display: block;
    padding: 0.5rem 0;
    font-weight: 600;
  }

  /* Form buttons */
  input[type="submit"],
  input[type="button"],
  button[type="submit"] {
    width: 100%;
    min-height: 52px;
    font-size: 1rem;
    font-weight: 700;
  }

  /* Better form layout */
  .apply-layout {
    flex-direction: column;
    gap: 1.5rem;
  }

  .apply-layout__content {
    max-width: none;
    width: 100%;
  }

  .apply-layout__figure {
    max-width: 100%;
  }

  .apply-layout__figure img {
    border-radius: 12px;
    max-height: 300px;
    object-fit: cover;
    width: 100%;
  }
}

/* ===== SAFE AREA INSETS (Notched devices) ===== */

@supports (padding: max(0px)) {

  /* Top bar */
  .topbar {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  /* Footer */
  .footer {
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }

  /* Cookie consent */
  .cookie-consent {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  @media (max-width: 980px) {

    /* Mobile menu */
    #menu {
      padding-top: max(6rem, calc(4rem + env(safe-area-inset-top)));
      padding-left: max(1.5rem, env(safe-area-inset-left));
      padding-right: max(1.5rem, env(safe-area-inset-right));
      padding-bottom: max(2rem, env(safe-area-inset-bottom));
    }

    /* Navigation bar */
    .nav {
      padding-left: max(1rem, env(safe-area-inset-left));
      padding-right: max(1rem, env(safe-area-inset-right));
    }

    /* Container */
    .container {
      padding-left: max(0.5rem, env(safe-area-inset-left));
      padding-right: max(0.5rem, env(safe-area-inset-right));
    }
  }
}

/* ===== iOS SPECIFIC FIXES ===== */

@supports (-webkit-touch-callout: none) {

  /* Fix iOS Safari 100vh issue */
  .hero,
  .home-hero {
    min-height: -webkit-fill-available;
  }

  /* Prevent rubber-band scrolling issues */
  html {
    height: -webkit-fill-available;
  }

  body {
    min-height: -webkit-fill-available;
  }

  /* Smooth scrolling in overflowing elements */
  #menu {
    -webkit-overflow-scrolling: touch;
  }
}

/* ===== MOBILE HERO SECTION ===== */

@media (max-width: 768px) {

  .hero,
  .home-hero {
    min-height: 100svh;
    min-height: 100vh;
    height: auto;
  }

  .hero .media {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    object-fit: cover;
  }

  .hero .content {
    padding: 2rem 1rem;
  }
}

@media (max-width: 480px) {

  .hero,
  .home-hero {
    min-height: 85svh;
    min-height: 85vh;
  }
}

/* ===== LANDSCAPE ORIENTATION ===== */

@media (max-width: 900px) and (orientation: landscape) {

  .hero,
  .home-hero {
    min-height: 100svh;
    height: auto;
  }

  /* Compact header in landscape */
  :root {
    --nav-height: 60px;
  }

  .brand.brand--mark {
    width: 50px;
    height: 50px;
    min-width: 50px;
  }

  /* Mobile menu scrollable in landscape */
  #menu {
    padding-top: 4rem;
  }

  #menu>li>a {
    padding: 0.75rem 0;
    min-height: 48px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {

  .hero,
  .home-hero {
    min-height: auto;
    height: auto;
    padding: 1.5rem 0;
  }

  #menu {
    padding-top: 1rem;
    max-height: 100vh;
  }
}

/* ===== ACCESSIBILITY ===== */

/* Focus states */
a:focus-visible,
button:focus-visible,
.apply:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #0b3d91;
  outline-offset: 2px;
  border-radius: 4px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .hero .media {
    display: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {

  .btn,
  .apply,
  .topbar-btn {
    border: 2px solid currentColor;
  }

  a {
    text-decoration: underline;
  }
}

/* ===== MOBILE NAVIGATION BAR ===== */

@media (max-width: 980px) {
  header {
    position: sticky;
    top: 0;
    z-index: 1100;
    /* Increased to ensure header stays on top */
  }

  .nav {
    height: 70px;
    padding: 0 1rem;
    gap: 1rem;
  }

  .brand.brand--mark {
    width: 55px;
    height: 55px;
    min-width: 55px;
  }

  /* Hide desktop nav */
  .nav>nav>ul {
    display: none;
  }

  .nav>nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 1;
    padding-right: 0;
  }

  /* Hide desktop apply button */
  .nav-actions {
    display: none;
  }
}

/* ===== MOBILE TOPBAR ===== */

@media (max-width: 768px) {
  .topbar {
    background-color: #0b162b;
    /* Dark background */
    color: #fff;
    padding: 0.5rem 1rem;
  }

  .topbar__row {
    padding: 0;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
  }

  .topbar__meta {
    width: 100%;
    justify-content: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
  }

  .topbar__meta::before {
    display: none;
  }

  .topbar__tagline {
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    text-align: center;
    color: rgba(255, 255, 255, 0.9);
  }

  /* Container for Social + Controls */
  .topbar__row>div:not(.topbar__meta) {
    display: flex;
    align-items: center;
  }

  /* We need to group social and controls if they aren't already grouped in HTML.
   Looking at HTML: .topbar__social and .topbar__controls are siblings.
   We can use a flex wrap or just style them individually.
*/

  .topbar__social {
    display: flex;
    /* Show social icons */
    gap: 1rem;
    margin-bottom: 0.25rem;
  }

  .topbar__social a {
    opacity: 0.8;
    transition: opacity 0.2s;
  }

  .topbar__social a:hover {
    opacity: 1;
  }

  .topbar__controls {
    width: 100%;
    justify-content: center;
    gap: 1rem;
  }

  .topbar-btn {
    font-size: 0.8rem;
    padding: 0.4rem 1rem;
    min-height: 40px;
  }

  /* Specific styling for Apply button to pop */
  .topbar-btn--primary {
    background-color: #F4C84A;
    /* Gold to match desktop */
    border-color: #F4C84A;
    color: #0a1326;
    /* Navy text */
    font-weight: 700;
  }
}

@media (max-width: 400px) {

  /* Hide phone text, keep icon */
  .topbar-btn--ghost span {
    display: none;
  }

  .topbar-btn--ghost {
    padding: 0.45rem;
    min-width: 40px;
  }
}

/* ===== MOBILE CONTENT SECTIONS ===== */

@media (max-width: 768px) {
  .section {
    padding: 2.5rem 0;
  }

  .container {
    width: 94%;
  }

  /* Welcome section */
  .section-welcome {
    padding: 2rem 0;
  }

  .welcome-wrap {
    flex-direction: column;
    gap: 2rem;
  }

  .welcome-copy {
    text-align: center;
    gap: 1rem;
  }

  .welcome-title {
    font-size: clamp(1.75rem, 5vw, 2.4rem);
  }

  .welcome-lead,
  .welcome-body {
    font-size: 0.95rem;
  }

  .welcome-highlights {
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }

  .welcome-highlight img {
    max-height: 120px;
  }

  .welcome-caption {
    font-size: 0.75rem;
  }

  .welcome-banner {
    border-radius: 12px;
    min-height: 180px;
    margin: 0 auto;
    /* Center the banner */
    background: transparent;
    /* Remove navy background/border effect */
    box-shadow: none;
    /* Remove shadow if it contributes to the border look */
    width: 100%;
    max-width: 100%;
  }

  /* Pathways cards */
  .pathways-section {
    padding: 3rem 0;
  }

  .pathways__grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .pathways-card {
    min-height: 180px;
    border-radius: 14px;
  }

  .pathways-card__label {
    padding: 1.2rem;
  }

  .pathways-card__title {
    font-size: 1.15rem;
  }

  /* Testimonials */
  .section-gold {
    padding: 3rem 0;
  }

  .section-gold h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
  }

  .t-wall {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .t-card {
    border-radius: 10px;
  }

  /* International section */
  .grid-2.equal {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .page-hero img {
    border-radius: 10px;
  }

  /* Exam boards logos */
  .section[aria-label="Accredited exam boards"] {
    padding: 2rem 0;
  }

  .section[aria-label="Accredited exam boards"] img {
    height: 30px !important;
  }
}

@media (max-width: 500px) {
  .welcome-highlights {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .welcome-highlight {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    max-width: 260px;
    margin: 0 auto;
  }

  .welcome-highlight img {
    width: 70px;
    height: 70px;
    max-height: 70px;
    flex-shrink: 0;
  }

  .welcome-caption {
    text-align: left;
    font-size: 0.85rem;
  }
}

/* ===== MOBILE FOOTER ===== */

@media (max-width: 768px) {
  .footer {
    margin-top: 2rem;
  }

  .footer__inner {
    grid-template-columns: 1fr;
    gap: 2rem;
    padding: 2.5rem 0 2rem;
  }

  .footer__heading {
    font-size: 1.1rem;
    text-align: center;
  }

  .footer__tagline,
  .footer__principal {
    text-align: center;
  }

  .footer__contact {
    align-items: center;
  }

  .footer__contact-list {
    text-align: center;
  }

  .footer__social-wrap {
    align-items: center;
  }

  .footer__social {
    justify-content: center;
  }

  .footer__column--links {
    text-align: center;
  }

  .footer__list {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    justify-items: center;
  }

  .footer__bottom-inner {
    flex-direction: column;
    text-align: center;
    padding: 1rem 0;
  }
}

/* ===== PRINT STYLES ===== */

@media print {

  .topbar,
  .hamburger,
  .nav-actions,
  .footer__social,
  .social,
  .cookie-consent,
  #menu {
    display: none !important;
  }

  body {
    font-size: 12pt;
    color: #000;
    background: #fff;
  }

  .hero {
    min-height: auto;
    height: auto;
    page-break-after: always;
  }

  .section {
    page-break-inside: avoid;
  }
}