/*
 * Phone and small-tablet layout for the CCES website (used with mobile-nav.js).
 * Desktop is unchanged: every rule here sits inside a max-width media query.
 * The page markup uses inline styles, so overrides need !important.
 */

/* the menu button and the Student Hub copy in the menu exist only on small screens */
.cces-burger, .cces-nav-hub { display: none; }

/* ---------- Header: fold the menu into a button (tablets and phones) ---------- */
@media (max-width: 960px) {
  header > div { gap: 12px !important; position: relative; }

  .cces-burger {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; margin-left: 4px; padding: 0; flex-shrink: 0;
    border: 1px solid var(--border-subtle, #dfe3ea); border-radius: var(--radius, 10px);
    background: #fff; color: var(--text-strong, #0e1726); cursor: pointer;
  }
  .cces-burger:focus-visible { outline: 3px solid rgba(4, 118, 208, .35); outline-offset: 2px; }
  .cces-burger svg { width: 22px; height: 22px; }
  .cces-burger .cces-icon-close { display: none; }
  header.cces-menu-open .cces-burger .cces-icon-open { display: none; }
  header.cces-menu-open .cces-burger .cces-icon-close { display: block; }

  /* push the right-hand group to the edge now that the menu is folded away */
  header > div > div:last-of-type { margin-left: auto !important; }

  /* the menu itself: hidden until opened, then a panel under the header bar */
  header nav { display: none !important; }
  header.cces-menu-open nav {
    display: flex !important; flex-direction: column; gap: 0 !important;
    position: absolute; top: 100%; left: 0; right: 0; margin: 0 !important;
    padding: 8px 24px 20px; background: #fff;
    border-bottom: 1px solid var(--border-subtle, #dfe3ea);
    box-shadow: 0 16px 32px rgba(14, 23, 38, .12);
    overflow: visible !important; white-space: normal !important;
  }
  header.cces-menu-open nav a {
    display: block; padding: 14px 0 !important; font-size: 17px !important;
    border-bottom: 1px solid var(--border-subtle, #eef0f4);
  }
  header.cces-menu-open nav a:last-child { border-bottom: 0; }
}

@media (max-width: 600px) {
  header > div { padding: 0 16px !important; height: 64px !important; }
  /* make room: the WiseTech badge and Student Hub button move into the menu */
  header > div > div:last-of-type > span,
  header > div > div:last-of-type > a { display: none !important; }
  .cces-nav-hub { display: block !important; font-weight: var(--fw-bold, 700) !important; color: var(--cces-primary, #0476d0) !important; }
  header.cces-menu-open nav { padding: 4px 16px 16px; }
}

/* ---------- Tablets and small laptops (up to 1180px) ----------
   Placed before the phone rules so those still win on phones. */
@media (max-width: 1180px) {
  /* text blocks given a fixed desktop width (e.g. the About intro) shrink to fit */
  section :is(p, h1, h2, h3, h4, li)[style*="width:"] { width: auto !important; max-width: min(100%, 70ch); }
  section :is(p, h1, h2, h3, h4, li)[style*="height:"] { height: auto !important; }

  /* Bachelor of Border Management, course structure: two equal columns of subjects */
  section [style*="grid-template-columns: max-content minmax(0"] {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important; gap: 40px !important;
  }
  section [style*="grid-template-columns: max-content minmax(0"] > [style*="width: 529px"] { width: auto !important; height: auto !important; }
  section [style*="grid-template-columns: max-content minmax(0"] [style*="white-space: nowrap"] { white-space: normal !important; }
}

/* ---------- Page content: stack columns and tighten spacing (phones) ---------- */
@media (max-width: 760px) {
  /* never wider than the screen */
  html, body { overflow-x: clip; }
  main img, section img, footer img { max-width: 100%; height: auto; }
  section *, footer * { max-width: 100% !important; min-width: 0; }
  /* elements that deliberately extend into their card's padding (e.g. full-width card photos) */
  section [style*="margin: 0px -"], section [style*="margin: 0 -"],
  section [style*="margin: -"] { max-width: none !important; }
  /* text blocks given a fixed desktop size grow to fit their text instead
     (not spans: those are used as fixed-size icon boxes) */
  section :is(p, h1, h2, h3, h4, li)[style*="width:"] { width: auto !important; }
  section :is(p, h1, h2, h3, h4, li)[style*="height:"] { height: auto !important; }
  section [style*="white-space: nowrap"], footer [style*="white-space: nowrap"] { white-space: normal !important; }

  /* multi-column grids become a single column... */
  section [style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; }
  /* ...except small icon + text rows, which fit side by side */
  section [style*="grid-template-columns: 64px"],
  section [style*="grid-template-columns: 56px"],
  section [style*="grid-template-columns: 48px"],
  section [style*="grid-template-columns: 40px"] { grid-template-columns: 48px minmax(0, 1fr) !important; gap: 16px !important; }
  section [style*="grid-template-columns: 64px"] > :first-child { width: 48px !important; height: 48px !important; }
  /* the team directory keeps two small cards per row */
  #team [style*="grid-template-columns: repeat(5"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }

  /* fixed-width rows of items wrap instead of running off the edge */
  section [style*="display: flex"] { flex-wrap: wrap; }
  /* vertical stacks never wrap (wrapping would push items into a second column,
     e.g. the "View the course" link on the back of the Study flip cards) */
  section [style*="display: flex"][style*="flex-direction: column"] { flex-wrap: nowrap; }
  section [data-marquee] [style*="display: flex"],
  section [data-research-rail], section [data-testimonial-rail],
  section [data-research-rail] [style*="display: flex"],
  section [data-testimonial-rail] [style*="display: flex"] { flex-wrap: nowrap; }

  /* spacing */
  section[style*="padding: 96px"], section[style*="padding: 112px"], section[style*="padding: 128px"] { padding-top: 56px !important; padding-bottom: 56px !important; }
  section[style*="padding: 64px"] { padding-top: 44px !important; padding-bottom: 44px !important; }
  section [style*="padding: 64px"], section [style*="padding: 56px"] { padding: 28px 20px !important; }
  section [style*="padding: 48px"] { padding: 24px 20px !important; }
  section [style*="padding: 40px"] { padding: 22px 18px !important; }
  section [style*="gap: 64px"], section [style*="gap: 56px"], section [style*="gap: 48px"] { gap: 28px !important; }
  section [style*="gap: 40px"] { gap: 20px !important; }

  /* headings */
  section h1[style*="font-size"] { font-size: clamp(32px, 9vw, 40px) !important; }
  section h2[style*="font-size: 4"], section h2[style*="font-size: 5"] { font-size: 30px !important; }
  section h2[style*="font-size: 36px"], section h2[style*="font-size: 38px"], section h3[style*="font-size: 36px"] { font-size: 26px !important; }

  /* footer: brand across the top, link columns two per row */
  footer [style*="grid-template-columns"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 28px 20px !important; }
  footer [style*="grid-template-columns"] > :first-child { grid-column: 1 / -1; }
  footer [style*="display: flex"] { flex-wrap: wrap; }

  /* Homepage "Learning solutions" cards: the light blue header keeps its icon and
     label side by side on one line, and stretches to the card edges as on desktop */
  #paths [style*="margin: -36px -36px"][style*="display: flex"] { flex-wrap: nowrap !important; }
  #paths [style*="margin: -36px -36px"][style*="display: flex"] > * { min-width: 0; }

  /* Homepage stats (180+ / WCO / 20+): keep three across, evenly spaced and centred */
  section [style*="margin-top: 72px"][style*="border-top: 1px solid rgba(255"][style*="grid-template-columns: repeat(3"] {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    margin-top: 40px !important;
  }
  section [style*="margin-top: 72px"][style*="border-top: 1px solid rgba(255"][style*="grid-template-columns: repeat(3"] > div {
    padding: 20px 6px 28px !important;
    text-align: center;
  }
  section [style*="margin-top: 72px"][style*="border-top: 1px solid rgba(255"][style*="grid-template-columns: repeat(3"] > div > div:first-child {
    font-size: 26px !important;
  }
  section [style*="margin-top: 72px"][style*="border-top: 1px solid rgba(255"][style*="grid-template-columns: repeat(3"] > div > div:last-child {
    font-size: 12.5px !important; line-height: 1.35;
  }

  /* ---------- Timelines become vertical: a line down the left, a dot per milestone ---------- */

  /* About page, history: the sideways-scrolling row of milestones */
  [data-tl-rail] {
    flex-direction: column !important; flex-wrap: nowrap !important;
    overflow: visible !important; scroll-snap-type: none !important;
    margin-top: 40px !important; padding: 0 0 0 5px !important;
  }
  [data-tl-rail] > [data-tl-item] {
    flex: none !important; width: auto !important;
    padding: 0 0 30px 26px !important;
    border-top: 0 !important; border-right: 0 !important;
    border-left: 1px solid var(--border-subtle) !important;
  }
  [data-tl-rail] > [data-tl-item]:last-child { padding-bottom: 4px !important; }
  [data-tl-rail] > [data-tl-item] > span[style*="border-radius: 50%"] { top: 9px !important; left: -5px !important; }

  /* Study page, pathway: the row of six steps joined by a line */
  #pathway [style*="grid-template-columns: repeat(6"] { gap: 0 !important; margin-top: 28px !important; }
  #pathway [style*="grid-template-columns: repeat(6"] > [style*="height: 2px"] {
    top: 8px !important; bottom: 8px !important; left: 6px !important; right: auto !important;
    width: 2px !important; height: auto !important;
  }
  #pathway [data-tl-item] { padding: 0 0 22px 34px !important; }
  #pathway [data-tl-item]:last-child { padding-bottom: 0 !important; }
  #pathway [data-tl-item] > div[style*="border-radius: 50%"] { top: 2px !important; }

  /* Community page, events list: date tile | text | button becomes
     date tile beside the text, with the Enquire / Register button below the text */
  #events [style*="gap: 28px"][style*="align-items: flex-start"] {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px 16px !important;
    align-items: start !important;
  }
  #events [style*="gap: 28px"][style*="align-items: flex-start"] > a {
    grid-column: 2;
    justify-self: start;
    max-width: 100%;
    white-space: normal !important;
  }
  #events [style*="padding: 28px"] { padding: 20px !important; }

  /* tables scroll sideways inside their own box instead of widening the page */
  section table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
