/*
 * Services mega menu. Built from the site's own tokens, type, radii and dark-mode treatment.
 * Desktop (1024px and up): one rounded two-column panel under the floating header.
 * Mobile (below 1024px): nested accordion inside the existing mobile menu.
 * Behaviour lives in assets/js/main.js; the menu content is in config/nav.php ('services_menu').
 * NOTE: the desktop grid is laid out for five categories (rows are placed by nth-child below). Adding a sixth means
 * one more nth-child rule, a taller grid-template-rows and moving the pane span and footer row down by one.
 */

/* ------------------------------------------------------------------ shared */
/* The optional one-line description is desktop only (the mobile accordion stays compact). */
#cs-navigation .cs-mega__item-text {
  display: none;
}
#cs-navigation .cs-mega__trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  text-align: inherit;
}
#cs-navigation .cs-mega__trigger .cs-drop-icon {
  transition: transform 0.3s;
}
#cs-navigation .cs-mega.is-open .cs-mega__trigger .cs-drop-icon {
  transform: rotate(180deg);
}
.cs-mega__group {
  display: contents;
}
.cs-mega__chev {
  flex: none;
  transition: transform 0.25s, opacity 0.25s;
}
.cs-mega__cat,
.cs-mega__item,
.cs-mega__footer a {
  text-decoration: none;
}
.cs-mega__item--soon small:not(.cs-mega__item-text) {
  flex: none;
  border-radius: 3.75rem;
  padding: 0.2rem 0.55rem;
  text-transform: uppercase;
  font-family: var(--navFont);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2em;
  white-space: nowrap;
}
@keyframes cs-mega-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------------ desktop */
@media only screen and (min-width: 1024px) {
  /* Centre the nav list without a transform, so the panel below can anchor to the floating header. */
  #cs-navigation .cs-ul-wrapper {
    top: 0;
    right: 0;
    left: 0;
    margin: 0 auto;
    transform: none;
    width: max-content;
  }
  #cs-navigation .cs-mega {
    position: relative;
  }
  /* Invisible bridge so the pointer can travel from the link to the panel without it closing. */
  #cs-navigation .cs-mega:after {
    content: "";
    position: absolute;
    top: 100%;
    right: -1rem;
    left: -1rem;
    height: 1.5rem;
  }
  #cs-navigation .cs-mega.is-open .cs-mega__trigger {
    color: var(--primaryLight);
  }

  #cs-navigation .cs-mega__panel {
    position: fixed;
    top: calc(100% + 0.75rem);
    left: 50%;
    z-index: 30;
    display: grid;
    grid-template-columns: 17.5rem minmax(0, 1fr);
    grid-template-rows: repeat(5, auto) 1fr auto;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(-50%, 0.75rem);
    border: 1px solid rgba(0, 31, 63, 0.08);
    border-radius: 1.5rem;
    background-color: #fff;
    width: min(62rem, calc(100vw - 2rem));
    max-height: calc(100vh - 10.5rem);
    overflow: auto;
    overscroll-behavior: contain;
    box-shadow: rgba(0, 31, 63, 0.2) 0px 24px 60px, rgba(149, 157, 165, 0.2) 0px 8px 24px;
    text-align: left;
    transition: opacity 0.25s, transform 0.25s, visibility 0.25s;
  }
  #cs-navigation .cs-mega.is-open .cs-mega__panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translate(-50%, 0);
  }
  /* The tinted left column. */
  #cs-navigation .cs-mega__panel:before {
    content: "";
    grid-column: 1;
    grid-row: 1 / span 6;
    background-color: #f7f7f7;
  }

  /* Categories (left column). Rows are placed explicitly so the right pane can span them. */
  #cs-navigation .cs-mega__cat {
    grid-column: 1;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin: 0 0.75rem;
    border: 0;
    border-radius: 1rem;
    background: none;
    padding: 0.7rem 0.85rem;
    width: auto;
    text-align: left;
    font-family: var(--navFont);
    font-size: 1.0625rem;
    line-height: 1.2em;
    font-weight: 600;
    color: var(--headerColor);
    cursor: pointer;
    transition: background-color 0.25s, color 0.25s;
  }
  #cs-navigation .cs-mega__group:nth-child(1) .cs-mega__cat {
    grid-row: 1;
    margin-top: 0.75rem;
  }
  #cs-navigation .cs-mega__group:nth-child(2) .cs-mega__cat {
    grid-row: 2;
  }
  #cs-navigation .cs-mega__group:nth-child(3) .cs-mega__cat {
    grid-row: 3;
  }
  #cs-navigation .cs-mega__group:nth-child(4) .cs-mega__cat {
    grid-row: 4;
  }
  #cs-navigation .cs-mega__group:nth-child(5) .cs-mega__cat {
    grid-row: 5;
  }
  #cs-navigation .cs-mega__cat:hover {
    background-color: #e8edf2;
  }
  #cs-navigation .cs-mega__group[data-active] > .cs-mega__cat {
    background-color: var(--primary);
    color: #fff;
  }
  #cs-navigation .cs-mega__icon {
    display: grid;
    flex: none;
    place-items: center;
    border-radius: 0.75rem;
    background-color: var(--primary);
    height: 2.5rem;
    width: 2.5rem;
    transition: background-color 0.25s;
  }
  #cs-navigation .cs-mega__icon img {
    height: 1.375rem;
    width: auto;
    filter: brightness(0) invert(1);
    transition: filter 0.25s;
  }
  #cs-navigation .cs-mega__group[data-active] > .cs-mega__cat .cs-mega__icon {
    background-color: #fff;
  }
  #cs-navigation .cs-mega__group[data-active] > .cs-mega__cat .cs-mega__icon img {
    filter: none;
  }
  #cs-navigation .cs-mega__name {
    flex: 1;
  }
  #cs-navigation .cs-mega__cat .cs-mega__chev {
    opacity: 0.35;
  }
  #cs-navigation .cs-mega__group[data-active] > .cs-mega__cat .cs-mega__chev {
    opacity: 1;
    transform: translateX(2px);
  }

  /* The active category's services (right column). */
  #cs-navigation .cs-mega__pane {
    grid-column: 2;
    grid-row: 1 / span 6;
    display: none;
    align-self: start;
    padding: 1.75rem 2rem 1.25rem;
  }
  /* Every category panel is the same height (the tallest, Digital Marketing with seven services), and the service
     cards in shorter categories share the space evenly, so the menu never jumps when the category changes. */
  #cs-navigation .cs-mega__group[data-active] > .cs-mega__pane {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-height: 21.9rem;
    animation: cs-mega-in 0.25s ease;
  }
  #cs-navigation .cs-mega__title {
    margin: 0 0 0.35rem;
    font-family: var(--navFont);
    font-size: 1.625rem;
    line-height: 1.15em;
    font-weight: 700;
    color: var(--headerColor);
  }
  #cs-navigation .cs-mega__desc {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    line-height: 1.5em;
    color: var(--bodyTextColor);
  }
  #cs-navigation .cs-mega__items {
    display: grid;
    flex: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(min-content, 1fr);
    gap: 0.625rem;
    margin: 0.5rem 0 0;
    padding: 0;
    list-style: none;
  }
  #cs-navigation .cs-mega__items li {
    display: flex;
    margin: 0;
    height: auto;
    padding: 0;
    text-align: left;
  }
  #cs-navigation .cs-mega__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    border: 1px solid #e3e8ee;
    border-radius: 1rem;
    background-color: #fff;
    flex: 1;
    padding: 0.7rem 1rem;
    min-height: 3rem;
    font-family: var(--navFont);
    font-size: 1rem;
    line-height: 1.25em;
    font-weight: 600;
    color: var(--headerColor);
    transition: border-color 0.25s, transform 0.25s, box-shadow 0.25s, background-color 0.25s;
  }
  #cs-navigation a.cs-mega__item:hover {
    transform: translateY(-2px);
    border-color: var(--secondary);
    box-shadow: rgba(67, 183, 255, 0.2) 0px 8px 24px;
  }
  #cs-navigation a.cs-mega__item .cs-mega__chev {
    color: var(--secondary);
  }
  #cs-navigation a.cs-mega__item:hover .cs-mega__chev {
    transform: translateX(3px);
  }
  /* Two or three services: one column of fuller cards. They share the panel height but are capped, so they never become
     oversized, and any spare space falls quietly at the bottom of the panel. */
  #cs-navigation .cs-mega__items--few,
  #cs-navigation .cs-mega__items--stack {
    grid-template-columns: 1fr;
    align-content: start;
  }
  #cs-navigation .cs-mega__items--few {
    grid-auto-rows: minmax(min-content, 5.5rem);
  }
  #cs-navigation .cs-mega__items--stack {
    grid-auto-rows: minmax(min-content, 4rem);
  }
  #cs-navigation .cs-mega__items--few .cs-mega__item {
    padding: 1rem 1.25rem;
    min-height: 4.25rem;
  }
  #cs-navigation .cs-mega__item-main {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
  }
  #cs-navigation .cs-mega__item-text {
    display: block;
    font-family: var(--navFont);
    font-size: 0.875rem;
    line-height: 1.4em;
    font-weight: 400;
    color: var(--bodyTextColor);
  }
  #cs-navigation .cs-mega__item--soon {
    border-style: dashed;
    background-color: transparent;
    color: #5f6e7f;
    cursor: default;
  }
  #cs-navigation .cs-mega__item--soon small:not(.cs-mega__item-text) {
    background-color: #eef2f6;
    color: #4f5f71;
  }

  /* Footer strip under both columns. */
  #cs-navigation .cs-mega__footer {
    grid-column: 1 / -1;
    grid-row: 7;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1.5rem;
    border-top: 1px solid #e3e8ee;
    background-color: #fafbfc;
    padding: 0.9rem 2rem;
  }
  #cs-navigation .cs-mega__footer a {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-family: var(--navFont);
    font-size: 1rem;
    line-height: 1.5em;
    font-weight: 600;
    color: var(--headerColor);
    transition: color 0.25s;
  }
  #cs-navigation .cs-mega__footer a:hover {
    color: var(--linkOnLight, var(--primary));
  }
  #cs-navigation .cs-mega__footer a:hover .cs-mega__chev {
    transform: translateX(3px);
  }

  /* Dark mode */
  html.dark-mode #cs-navigation .cs-mega.is-open .cs-mega__trigger {
    color: var(--secondary);
  }
  html.dark-mode #cs-navigation .cs-mega__panel {
    border-color: rgba(255, 255, 255, 0.12);
    background-color: var(--dark);
    box-shadow: rgba(67, 183, 255, 0.2) 0px 0px 24px, rgba(67, 183, 255, 0.15) 0px 0px 60px, rgba(0, 0, 0, 0.6) 0px 24px 60px;
  }
  html.dark-mode #cs-navigation .cs-mega__item-text {
    color: rgba(255, 255, 255, 0.72);
  }
  html.dark-mode #cs-navigation .cs-mega__panel:before {
    background-color: rgba(255, 255, 255, 0.04);
  }
  html.dark-mode #cs-navigation .cs-mega__cat {
    color: #fff;
  }
  html.dark-mode #cs-navigation .cs-mega__cat:hover {
    background-color: rgba(255, 255, 255, 0.08);
  }
  html.dark-mode #cs-navigation .cs-mega__group[data-active] > .cs-mega__cat {
    background: linear-gradient(45deg, #cecece 0%, #ffffff 100%);
    color: var(--primary);
    box-shadow: rgba(67, 183, 255, 0.25) 0px 0px 24px;
  }
  html.dark-mode #cs-navigation .cs-mega__icon {
    background-color: var(--primary);
  }
  html.dark-mode #cs-navigation .cs-mega__group[data-active] > .cs-mega__cat .cs-mega__icon {
    background-color: var(--primary);
  }
  html.dark-mode #cs-navigation .cs-mega__group[data-active] > .cs-mega__cat .cs-mega__icon img {
    filter: brightness(0) invert(1);
  }
  html.dark-mode #cs-navigation .cs-mega__title {
    color: #fff;
  }
  html.dark-mode #cs-navigation .cs-mega__desc {
    color: rgba(255, 255, 255, 0.78);
  }
  html.dark-mode #cs-navigation .cs-mega__item {
    border-color: rgba(255, 255, 255, 0.14);
    background-color: rgba(255, 255, 255, 0.04);
    color: #fff;
  }
  html.dark-mode #cs-navigation a.cs-mega__item:hover {
    border-color: var(--secondary);
    background-color: rgba(67, 183, 255, 0.1);
    box-shadow: rgba(67, 183, 255, 0.25) 0px 0px 24px;
  }
  html.dark-mode #cs-navigation .cs-mega__item--soon {
    border-color: rgba(255, 255, 255, 0.18);
    background-color: transparent;
    color: rgba(255, 255, 255, 0.55);
  }
  html.dark-mode #cs-navigation .cs-mega__item--soon small:not(.cs-mega__item-text) {
    background-color: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
  }
  html.dark-mode #cs-navigation .cs-mega__footer {
    border-top-color: rgba(255, 255, 255, 0.1);
    background-color: rgba(255, 255, 255, 0.03);
  }
  html.dark-mode #cs-navigation .cs-mega__footer a {
    color: #fff;
  }
  html.dark-mode #cs-navigation .cs-mega__footer a:hover {
    color: var(--secondary);
  }
}

/* ------------------------------------------------------------------ mobile (nested accordion) */
@media only screen and (max-width: 1023px) {
  /* The Services row is a primary item: same left-aligned row as the other links (see nav.css), with a chevron. */
  #cs-navigation .cs-mega__trigger {
    display: flex;
    justify-content: space-between;
    margin: 0;
    padding: 0.5rem 0;
    width: 100%;
    text-align: left;
  }
  #cs-navigation .cs-mega.is-open .cs-mega__trigger {
    color: var(--linkOnLight, var(--primary));
  }
  #cs-navigation .cs-mega__trigger .cs-drop-icon {
    position: static;
    margin-left: auto;
    transform: none;
    height: auto;
    width: 0.8rem;
    opacity: 0.6;
  }
  #cs-navigation .cs-mega.is-open .cs-mega__trigger .cs-drop-icon {
    transform: rotate(180deg);
    opacity: 1;
  }
  /* Expanded Services: a soft tinted card holding the five divisions. */
  #cs-navigation .cs-mega__panel {
    display: none;
    margin: 0.25rem 0 0.75rem;
    border-radius: 1.125rem;
    background-color: #f4f8fb;
    padding: 0.15rem 1rem 0.35rem;
    width: 100%;
    text-align: left;
  }
  #cs-navigation .cs-mega.is-open .cs-mega__panel {
    display: block;
    animation: cs-mega-in 0.22s ease;
  }
  #cs-navigation .cs-mega__group {
    display: block;
    border-top: 1px solid rgba(0, 31, 63, 0.09);
  }
  #cs-navigation .cs-mega__group:first-child {
    border-top: 0;
  }
  #cs-navigation .cs-mega__cat {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin: 0;
    border: 0;
    background: none;
    padding: 0.35rem 0;
    width: 100%;
    min-height: 3.5rem;
    text-align: left;
    font-family: var(--navFont);
    font-size: 1.0625rem;
    line-height: 1.25em;
    font-weight: 600;
    color: var(--headerColor);
    cursor: pointer;
  }
  #cs-navigation .cs-mega__icon {
    display: grid;
    flex: none;
    place-items: center;
    border-radius: 0.7rem;
    background-color: var(--primary);
    height: 2.25rem;
    width: 2.25rem;
  }
  #cs-navigation .cs-mega__icon img {
    height: 1.125rem;
    width: auto;
    filter: brightness(0) invert(1);
  }
  #cs-navigation .cs-mega__name {
    flex: 1;
  }
  #cs-navigation .cs-mega__cat .cs-mega__chev {
    transform: rotate(90deg);
    opacity: 0.55;
  }
  #cs-navigation .cs-mega__group.is-open > .cs-mega__cat .cs-mega__chev {
    transform: rotate(-90deg);
    opacity: 1;
  }
  #cs-navigation .cs-mega__pane {
    display: none;
    padding: 0 0 0.6rem 3.05rem;
  }
  #cs-navigation .cs-mega__group.is-open > .cs-mega__pane {
    display: block;
    animation: cs-mega-in 0.22s ease;
  }
  #cs-navigation .cs-mega__title,
  #cs-navigation .cs-mega__desc {
    display: none;
  }
  #cs-navigation .cs-mega__items {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  #cs-navigation .cs-mega__items li {
    margin: 0;
    width: 100%;
    padding: 0;
    text-align: left;
  }
  #cs-navigation .cs-mega__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0;
    min-height: 2.75rem;
    font-family: var(--navFont);
    font-size: 1rem;
    line-height: 1.3em;
    font-weight: 500;
    color: var(--headerColor);
  }
  #cs-navigation .cs-mega__item .cs-mega__chev {
    opacity: 0.5;
  }
  #cs-navigation .cs-mega__item--soon {
    color: #6b7889;
  }
  #cs-navigation .cs-mega__item--soon small:not(.cs-mega__item-text) {
    background-color: #e6edf3;
    color: #5b6b7d;
  }
  /* "View all services" closes the card; the second footer link is replaced by the enquiry panel. */
  #cs-navigation .cs-mega__footer {
    display: flex;
    flex-direction: column;
    border-top: 1px solid rgba(0, 31, 63, 0.09);
  }
  #cs-navigation .cs-mega__footer a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0;
    min-height: 3rem;
    font-family: var(--navFont);
    font-size: 1rem;
    line-height: 1.3em;
    font-weight: 700;
    color: var(--linkOnLight, var(--primary));
  }
  #cs-navigation .cs-mega__footer a:nth-child(2) {
    display: none;
  }
  #cs-navigation .cs-mega__footer .cs-mega__chev {
    opacity: 0.7;
  }

  /* Dark mode */
  #cs-navigation .cs-mega__panel,
  html.dark-mode #cs-navigation .cs-mega__panel {
    box-shadow: none;
  }
  html.dark-mode #cs-navigation .cs-mega__panel {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background-color: rgba(255, 255, 255, 0.05);
  }
  html.dark-mode #cs-navigation .cs-mega.is-open .cs-mega__trigger {
    color: var(--secondary);
  }
  html.dark-mode #cs-navigation .cs-mega__group,
  html.dark-mode #cs-navigation .cs-mega__footer {
    border-color: rgba(255, 255, 255, 0.12);
  }
  html.dark-mode #cs-navigation .cs-mega__cat,
  html.dark-mode #cs-navigation .cs-mega__item {
    color: #fff;
  }
  html.dark-mode #cs-navigation .cs-mega__icon {
    background-color: rgba(67, 183, 255, 0.16);
    box-shadow: inset 0 0 0 1px rgba(67, 183, 255, 0.28);
  }
  html.dark-mode #cs-navigation .cs-mega__footer a {
    color: var(--secondary);
  }
  html.dark-mode #cs-navigation .cs-mega__item--soon {
    color: rgba(255, 255, 255, 0.6);
  }
  html.dark-mode #cs-navigation .cs-mega__item--soon small:not(.cs-mega__item-text) {
    background-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.75);
  }
}

@media (prefers-reduced-motion: reduce) {
  #cs-navigation .cs-mega__panel,
  #cs-navigation .cs-mega__pane,
  #cs-navigation .cs-mega__item,
  #cs-navigation .cs-mega__chev {
    animation: none !important;
    transition: none !important;
  }
}

/* "Digital Marketing Overview": a link to the parent page inside the Digital Marketing category. It is an ordinary
   service link (the category buttons stay selectors only). Desktop: it fills the eighth slot of the grid, so the panel
   height is unchanged. Mobile: a separate link comes first in the accordion (see .cs-mega__ovm below). */
@media only screen and (min-width: 1024px) {
  #cs-navigation .cs-mega__overview a.cs-mega__item {
    border-color: rgba(67, 183, 255, 0.55);
    background-color: rgba(67, 183, 255, 0.08);
    font-weight: 700;
  }
  html.dark-mode #cs-navigation .cs-mega__overview a.cs-mega__item {
    border-color: rgba(67, 183, 255, 0.55);
    background-color: rgba(67, 183, 255, 0.12);
  }
}
/* Mobile: the desktop grid link is hidden and a mobile-only link (.cs-mega__ovm, placed before the services in the markup)
   takes its place, looking exactly like the other service rows. Document order, visual order and tab order all agree. */
#cs-navigation .cs-mega__ovm {
  display: none;
}
@media only screen and (max-width: 1023px) {
  #cs-navigation .cs-mega__overview {
    display: none;
  }
  #cs-navigation .cs-mega__group.is-open > .cs-mega__ovm {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0 0.4rem 3.05rem;
    min-height: 2.75rem;
    font-family: var(--navFont);
    font-size: 1rem;
    line-height: 1.3em;
    font-weight: 700;
    color: var(--headerColor);
    animation: cs-mega-in 0.22s ease;
  }
  #cs-navigation .cs-mega__ovm .cs-mega__chev {
    opacity: 0.5;
  }
  html.dark-mode #cs-navigation .cs-mega__ovm {
    color: #fff;
  }
}
@media (prefers-reduced-motion: reduce) {
  #cs-navigation .cs-mega__ovm {
    animation: none !important;
  }
}
