/**
 * Minh Duc Land responsive and cross-browser compatibility layer.
 * Loaded after the main site bundle so legacy templates keep their styling
 * while shared layout constraints remain safe at every viewport width.
 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Final root-width guard. It also covers logged-in/admin markup and stale
 * third-party widgets that can otherwise extend the document canvas. */
html,
body,
#page {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden !important;
}

@supports (overflow: clip) {
  html,
  body,
  #page {
    overflow-x: clip !important;
  }
}

body,
#page,
#mdl-route,
#content,
#content > .container,
#content > .container > .row {
  min-width: 0;
  max-width: 100%;
}

/* Shared wide desktop rail for every public template. Keep a compact 24px
 * gutter on regular desktops, then use the same 86.4vw / 1728px rail on wide
 * displays. Tablet/mobile retain their existing fluid layout. */
@media (min-width: 1029px) {
  #content > .container,
  .site-footer .container {
    width: calc(100vw - 48px);
    max-width: 1728px;
    margin-right: auto;
    margin-left: auto;
  }

  /* A few legacy archive templates add a second Bootstrap container inside
   * the shared content row. Let it fill the new rail instead of falling back
   * to Bootstrap's old 1140px ceiling. */
  #content > .container > .row > .container {
    width: 100%;
    max-width: none;
  }
}

@media (min-width: 1440px) {
  #content > .container,
  .site-footer .container {
    width: 86.4vw;
  }
}

img,
picture,
video,
canvas,
svg {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

/* The home template is a direct child of Bootstrap's flex row. Without these
 * constraints its intrinsic content width expands the complete document. */
body.home #content > .container > .row > #main.site-main {
  display: block;
  flex: 0 0 100%;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding-right: 0;
  padding-left: 0;
}

body.home #main > *,
body.home .bds-news-module,
body.home .home-re,
body.home .home-re__grid,
body.home .re-carousel,
body.home .re-carousel__wrap,
body.home .re-carousel__viewport,
body.home .re-carousel__track {
  min-width: 0;
  max-width: 100%;
}

/* Header */
.bds-header > .bds-header__inner,
.bds-mobilebar {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.bds-header__inner > *,
.bds-header .bds-nav,
.bds-header .bds-right,
.bds-header .bds-user,
.bds-header .bds-user__trigger {
  min-width: 0;
}

/* Logged-in accounts add notification and account controls to the desktop
 * header. Keep that state compact around the desktop/tablet breakpoint. */
@media (min-width: 1029px) and (max-width: 1200px) {
  body.logged-in .bds-header .bds-logo img {
    max-width: 160px;
  }

  body.logged-in .bds-header .bds-nav {
    margin-left: 12px;
  }

  body.logged-in .bds-header .bds-nav .menu {
    gap: 12px;
  }

  body.logged-in .bds-header .bds-right {
    gap: 8px !important;
  }

  body.logged-in .bds-header .bds-user__trigger {
    gap: 4px;
    padding-right: 6px;
    padding-left: 6px;
  }

  body.logged-in .bds-header .bds-user__name {
    max-width: 72px;
  }
}

/* Home introduction */
body.home .intro-section {
  width: 100%;
  max-width: 1200px;
  padding: 28px 16px 20px;
  column-gap: 48px;
  row-gap: 20px;
}

body.home .intro-image,
body.home .intro-content {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: 100%;
}

body.home .intro-content,
body.home .intro-content * {
  overflow-wrap: break-word;
}

body.home .intro-image img {
  width: 360px;
  max-width: 100%;
  height: auto;
}

/* Content modules */
body.home .bds-news-tabs,
body.home .bds-list-mobile,
body.home .bds-row,
body.home .bds-row__body,
body.home .home-re__header,
body.home .home-re__grid,
body.home .re-card,
body.home .re-card__body,
body.home .re-carousel__header,
body.home .re-carousel__track,
body.home .re-carousel__item {
  min-width: 0;
}

body.home #main .mdloc-section {
  width: 100%;
  max-width: 100%;
  padding-right: 0;
  padding-left: 0;
}

body.home #main .mdloc-frame,
body.home #main .mdloc-stack,
body.home #main .mdloc-card {
  min-width: 0;
  max-width: 100%;
}

/* Carousel arrows stay inside the content box. The legacy negative outset
 * makes the root document a few pixels wider on desktop/tablet. */
body.home .re-carousel__nav--prev {
  left: 4px;
}

body.home .re-carousel__nav--next {
  right: 4px;
}

/* Compact search bar: allow the input-like button to shrink instead of
 * pushing the submit button outside narrow Safari/Chrome viewports. */
@media (max-width: 1028px) {
  html body #home_slider_div,
  html body #home_slider_div > .advanced-search,
  html body #home_slider_div #advSearch,
  html body #home_slider_div #advSearch .as-mbar {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  html body #home_slider_div #advSearch {
    margin-right: 0;
    margin-left: 0;
  }

  html body #advSearch .as-mbar__fake {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: 100%;
  }

  html body #advSearch .as-mbar__text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html body #advSearch .as-mbar__go {
    flex: 0 0 44px;
  }

  html body #advSearch input,
  html body #advSearch select,
  html body #advSearch textarea {
    font-size: 16px;
  }

  /* A three-column grid keeps the logo centered while reserving predictable
   * space for the back button and right-side actions. */
  html body .bds-mobilebar {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px !important;
    padding-right: 8px;
    padding-left: 8px;
  }

  html body .bds-mobilebar .bds-logo {
    display: block;
    min-width: 0;
    justify-self: center;
  }

  html body .bds-mobilebar .bds-logo img {
    display: block;
    width: 150px;
    max-width: 100%;
    height: auto;
    margin-left: 0;
  }

  html body .bds-mobilebar > .bds-flex {
    min-width: 0;
    margin-left: 0 !important;
    float: none !important;
    justify-self: end;
  }

  body.home .intro-section {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    padding: 18px 15px 12px;
    gap: 12px;
  }

  body.home .intro-image,
  body.home .intro-content {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }

  body.home .intro-image img {
    width: 226px;
    max-width: 100%;
  }

  body.home .intro-content .description {
    text-align: left;
  }

  body.home .bds-mquick {
    width: 100%;
    max-width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 0 10px;
  }

  body.home .bds-mquick .mq-card {
    min-width: 0;
    padding: 10px 6px;
  }

  body.home .bds-mquick .mq-ico {
    width: 100%;
    max-width: 64px;
  }

  body.home .bds-news-tabs {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  body.home .bds-news-tabs::-webkit-scrollbar {
    display: none;
  }

  body.home .bds-news-tabs button {
    flex: 0 0 auto;
  }

  body.home .bds-row__body {
    flex: 1 1 auto;
    overflow: hidden;
  }

  body.home .home-re__header,
  body.home .re-carousel__header {
    flex-wrap: wrap;
    gap: 8px;
  }

  body.home .home-re__tabs {
    display: none;
  }

  body.home .home-re__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.home .re-carousel__viewport {
    width: 100%;
    overflow: hidden;
  }

  body.home .re-carousel__track {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.home .re-carousel__nav {
    display: none;
  }
}

@media (max-width: 575.98px) {
  body.home .intro-section {
    padding-right: 15px;
    padding-left: 15px;
  }

  body.home .intro-content .main-title {
    font-size: 20px;
    line-height: 1.4;
  }

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

  body.home #main .mdloc-stack {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

@media (max-width: 359.98px) {
  html body .bds-mobilebar {
    grid-template-columns: 36px minmax(0, 1fr) auto;
  }

  html body .bds-mobilebar .bds-logo img {
    width: 132px;
  }

  html body .bds-mobilebar .bds-heart {
    display: none;
  }

  body.home .bds-mquick .mq-txt {
    font-size: 12px;
  }
}

/* Standalone PWA safe areas on notched iOS/Android devices. */
@media (display-mode: standalone) {
  body .bds-header {
    height: calc(var(--bds-header-h) + env(safe-area-inset-top)) !important;
    padding-top: env(safe-area-inset-top);
  }

  body .bds-drawer,
  body .notify-mobile {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@supports selector(:focus-visible) {
  a:focus-visible,
  button:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: 2px solid #e03c31;
    outline-offset: 2px;
  }
}
