/*
 * Bootstrap 5 responsive layer.
 * Breakpoints: xs <576, sm >=576, md >=768, lg >=992, xl >=1200.
 * Loaded last so page libraries cannot undo the shared layout safeguards.
 */

html,
body,
.dialog-off-canvas-main-canvas {
  max-width: 100%;
}

.site-shell {
  overflow-x: clip;
}

.site-shell main,
.site-shell .region,
.site-shell .block,
.site-shell .field,
.site-shell .field__item,
.site-shell [class$="-layout"],
.site-shell [class$="-grid"] {
  min-width: 0;
}

.site-shell img,
.site-shell video,
.site-shell canvas,
.site-shell svg,
.site-shell iframe {
  max-width: 100%;
}

.site-shell input:not([type="checkbox"]):not([type="radio"]),
.site-shell select,
.site-shell textarea,
.site-shell button {
  max-width: 100%;
}

.site-shell table {
  max-width: 100%;
}

/* Service nodes render inside Bootstrap's 8px content-region gutter. */
.service-detail.certification-page,
.service-detail.relations-page {
  width: auto;
  margin: 0 -8px;
}

.history-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  row-gap: .35rem;
  overflow-wrap: anywhere;
}

.publication-tabs,
.application-tabs,
.knowledge-tabs,
.member-services-tabs {
  max-width: 100%;
}

.publication-tabs {
  scrollbar-width: thin;
  overscroll-behavior-inline: contain;
}

.footer-grid > *,
.copyright > * {
  min-width: 0;
}

/* Bootstrap md and below use the compact navigation. */
@media (max-width: 991.98px) {
  .topbar {
    display: none;
  }

  .main-header,
  .header-inner {
    height: 70px;
  }

  .header-inner {
    padding-right: 1rem !important;
    padding-left: 1rem !important;
  }

  .brand {
    flex: 0 1 190px;
    width: auto;
    height: 58px;
    margin-right: 0;
    border: 0;
  }

  .desktop-nav {
    position: absolute;
    top: 70px;
    right: 0;
    left: 0;
    display: none;
    max-height: calc(100vh - 70px);
    overflow-y: auto;
    padding: 1rem;
    background: #fff;
    box-shadow: 0 12px 26px rgba(17, 24, 39, .16);
  }

  .desktop-nav.open {
    display: block;
  }

  .desktop-nav.open .ktso-main-menu {
    display: block;
    height: auto;
  }

  .desktop-nav.open .ktso-main-menu > .menu-item {
    display: block;
    padding: .7rem 1rem;
  }

  .desktop-nav.open .ktso-main-menu > .menu-item:first-child {
    display: none;
  }

  .desktop-nav.open .menu-chevron {
    display: none !important;
  }

  .desktop-nav.open .mega-menu {
    position: static;
    display: none;
    width: 100%;
    min-height: 0;
    margin-top: .65rem;
    grid-template-columns: 1fr;
    visibility: visible;
    opacity: 1;
    transform: none;
    box-shadow: none;
  }

  .desktop-nav.open .has-mega-menu:focus-within > .mega-menu {
    display: grid;
  }

  .desktop-nav.open .has-mega-menu.is-submenu-open > .mega-menu {
    display: grid;
  }

  .desktop-nav.open .mega-menu__intro {
    display: none;
  }

  .desktop-nav.open .mega-menu__links {
    grid-template-columns: 1fr !important;
  }

  .header-actions {
    display: none;
  }

  .mobile-toggle {
    display: block;
    flex: 0 0 auto;
    margin-left: auto;
    border: 0;
    background: transparent;
    font-size: 1.65rem;
  }

  .footer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2rem;
  }
}

/* Bootstrap lg keeps the desktop header; late mega menus open inward. */
@media (min-width: 992px) and (max-width: 1199.98px) {
  .site-shell .container {
    max-width: 960px !important;
  }

  .ktso-main-menu > .menu-item:nth-last-child(-n + 4) > .mega-menu {
    right: 0;
    left: auto;
  }

  .copyright {
    gap: 2rem;
  }
}

/* md and below: long content becomes a single readable column. */
@media (max-width: 991.98px) {
  .history-layout,
  .president-layout,
  .mission-vision-layout,
  .capacity-layout,
  .contact-message-layout,
  .fair-form-layout,
  .sanho-application-layout,
  .application-form-layout,
  .certification-layout,
  .relations-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .copyright {
    gap: 1.25rem;
  }

  .publications-hero {
    padding-bottom: 1rem;
  }

  .publications-page .publication-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: 1fr;
    gap: .5rem;
    margin: 1.5rem 0 0;
    padding: 0;
    overflow: visible;
  }

  .publications-page .publication-tabs > a {
    display: flex;
    width: 100%;
    min-height: 3rem;
    align-items: center;
    justify-content: flex-start;
    gap: .55rem;
    padding: .65rem .75rem;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: .5rem;
    background: rgba(255, 255, 255, .045);
    color: #c4cddd;
    white-space: normal;
    font-size: .68rem;
    line-height: 1.35;
  }

  .publications-page .publication-tabs > a.is-active {
    border-color: #fff;
    border-radius: .5rem;
    background: #fff;
    color: #111827;
  }

}

/* sm and below: cards, forms and navigation stack without fixed widths. */
@media (max-width: 767.98px) {
  .site-shell .row > [class*="col-"] {
    min-width: 0;
  }

  .site-shell h1 {
    overflow-wrap: anywhere;
  }

  .footer-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .copyright {
    flex-direction: column;
  }

  .publications-page .publication-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .publications-page .publication-tabs > a:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .application-intro-card,
  .application-summary,
  .application-form-card > header,
  .contact-form-card > header,
  .fair-form-main > header,
  .sanho-form-card > header {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .application-fees > div,
  .fair-application__actions {
    flex-direction: column;
  }

  .application-fees article,
  .fair-application__actions a {
    width: 100%;
    min-width: 0;
  }

  .table-responsive,
  .certification-table-wrap,
  .member-services-richtext {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* xs: preserve useful content width and comfortable touch targets. */
@media (max-width: 575.98px) {
  .site-shell .container,
  .login-page .container {
    width: 100%;
    max-width: none !important;
    padding-right: 1rem !important;
    padding-left: 1rem !important;
  }

  .brand {
    flex-basis: 155px;
  }

  .brand img {
    width: 145px;
  }

  .history-breadcrumb {
    font-size: .72rem;
  }

  .site-shell a[class*="btn"],
  .site-shell button[type="submit"],
  .site-shell input[type="submit"] {
    min-height: 44px;
  }

  .site-shell code,
  .site-shell a,
  .site-shell p,
  .site-shell td,
  .site-shell th {
    overflow-wrap: anywhere;
  }
}
