/* ============================================================================
   MATH V.2 — CMU-style shell (opt-in: <html class="v2">, enabled with ?v2=1)
   Loaded ONLY when ?v2=1 is present, so the production page keeps its current
   bytes until the owner flips the default. No URL, route or alias is changed.
   Scope: >=1024 desktop shell (sidebar + top bar + toolbar + carousel),
   768-1023 tablet keeps the current header and only gains the toolbar,
   <=767 the approved mobile layer (ds/mobile.css) owns the page.
   ========================================================================== */
html.v2 { --v2-rail: 255px; --v2-top: 64px; --v2-purple: #6E4E8A;
  --v2-purple-deep: #4A2A64; --v2-gold: #FFD300; --v2-ink: #212529; --v2-line: #E4E7EB; }

/* ---------------- desktop shell ------------------------------------------ */
@media (min-width: 1200px) {
  html.v2 body { padding-left: var(--v2-rail) !important; background: #F5F6F7; }

  /* 1 · left rail — the existing navbar, re-flowed vertically (no duplicated menu) */
  html.v2 .navbar.navbar-default.navbar-static-top {
    position: fixed !important;
    left: 0; top: 0; bottom: 0;
    width: var(--v2-rail) !important; height: 100vh; min-height: 0 !important;
    margin: 0 !important; padding: 0 !important;
    background: var(--v2-purple) !important;
    border: 0 !important; border-radius: 0 !important; box-shadow: none !important;
    overflow-y: auto; overflow-x: hidden; z-index: 1035;
    display: block !important;
  }
  html.v2 body .navbar.navbar-default.navbar-static-top > .container {
    display: block !important; width: auto !important; max-width: none !important;
    min-height: 0 !important; padding: 0 !important; margin: 0 !important;
  }
  html.v2 .navbar-header {
    display: block !important; float: none !important; width: auto !important; height: auto !important;
    min-height: 0 !important; padding: 20px 16px 16px !important;
    border-bottom: 1px solid rgba(255,255,255,.16);
  }
  html.v2 .navbar-header > br { display: none !important; }
  html.v2 .navbar-header > a { display: block !important; height: auto !important; padding: 0 !important; margin: 0 !important; }
  html.v2 .navbar-header picture.d-logo img {
    width: 100% !important; max-width: 190px !important; height: auto !important;
    padding: 0 !important; background: #FFF; border-radius: 8px;
  }
  html.v2 .navbar-toggle { display: none !important; }

  /* desktop.css hides the legacy collapse (it uses a relocated inline menu);
     the v2 rail needs the real menu list back, so the selector chain is raised. */
  html.v2 body .navbar > .container > .navbar-collapse,
  html.v2 body .navbar > .container > .navbar-collapse.collapse,
  html.v2 body .navbar > .container > .navbar-collapse.collapse.in {
    display: block !important; visibility: visible !important;
    position: static !important;
    height: auto !important; max-height: none !important; width: auto !important;
    padding: 6px 0 32px !important; margin: 0 !important;
    background: transparent !important; border: 0 !important; box-shadow: none !important;
    overflow: visible !important;
  }
  /* 3 · vertical menu: group labels + items
     (semantics.css hides .navbar-disable on desktop — the rail needs it back) */
  html.v2 body .navbar-collapse .navbar-disable { display: block !important; }
  html.v2 body .navbar-collapse .navbar-disable > div {
    margin: 0 !important; padding: 16px 16px 6px !important;
    border: 0 !important; background: none !important;
    color: var(--v2-gold) !important; font-size: 11px !important; font-weight: 600;
    letter-spacing: .1em; text-transform: uppercase; opacity: .95;
  }
  html.v2 .navbar-collapse ul.nav.navbar-nav { float: none !important; display: block !important; margin: 0 !important; }
  html.v2 .navbar-collapse ul.nav.navbar-nav > li { float: none !important; display: block !important; }
  html.v2 .navbar-collapse ul.nav.navbar-nav > li > a {
    display: block !important; padding: 9px 14px 9px 15px !important;
    color: #FFF !important; font-size: 14px !important; line-height: 1.45;
    border-left: 3px solid transparent; text-decoration: none !important;
  }
  html.v2 .navbar-collapse ul.nav.navbar-nav > li > a:hover,
  html.v2 .navbar-collapse ul.nav.navbar-nav > li > a:focus-visible {
    background: rgba(255,255,255,.10) !important; border-left-color: var(--v2-gold);
  }
  html.v2 .navbar-collapse ul.nav.navbar-nav > li > a:focus-visible { outline: 2px solid var(--v2-gold); outline-offset: -2px; }

  /* 2 + 5 · top bar: brand + utility (search, TH|EN) */
  html.v2 .v2-top {
    position: sticky; top: 0; z-index: 1020;
    display: flex; align-items: center; gap: 16px;
    min-height: var(--v2-top); padding: 0 24px;
    background: #FFF; border-bottom: 1px solid var(--v2-line);
  }
  html.v2 .v2-top .v2-brand { display: flex; align-items: center; gap: 10px; text-decoration: none !important; color: var(--v2-ink) !important; }
  html.v2 .v2-top .v2-brand-mark {
    width: 34px; height: 34px; border-radius: 50%;
    background: url(/favicon.ico) center/contain no-repeat;
    box-shadow: 0 0 0 1px var(--v2-line);
  }
  html.v2 .v2-top .v2-brand-text { font-size: 15px; font-weight: 600; line-height: 1.2; }
  html.v2 .v2-top .v2-brand-text small { display: block; font-size: 10.5px; font-weight: 400; letter-spacing: .08em; text-transform: uppercase; color: #6C757D; }
  html.v2 .v2-top .v2-util { margin-left: auto; display: flex; align-items: center; gap: 14px; }
  html.v2 .v2-top .v2-util a { color: var(--v2-ink) !important; text-decoration: none !important; font-size: 14px; }
  /* 8 · language as plain text */
  html.v2 .v2-lang { display: flex; align-items: center; gap: 2px; font-size: 13px; letter-spacing: .04em; }
  html.v2 .v2-lang a { padding: 6px 8px; border-radius: 6px; color: #6C757D !important; }
  html.v2 .v2-lang a.on { background: var(--v2-purple); color: #FFF !important; font-weight: 600; }
  html.v2 .v2-lang a:focus-visible { outline: 2px solid var(--v2-gold); outline-offset: 2px; }

  /* 6 · full-width slider (offset by the rail, no horizontal scroll) */
  html.v2 #slider, html.v2 .rev_slider_wrapper, html.v2 .tp-fullwidth-forcer { width: 100% !important; max-width: 100% !important; }
  html.v2 .rev_slider_wrapper, html.v2 .rev_slider { margin-left: 0 !important; }
  html.v2 .kenburns, html.v2 .slides { width: 100% !important; }

  /* 7 · news carousel: 4 cards, autoplay */
  html.v2 .v2-news { padding: 28px 84px 8px 24px; }
  html.v2 .v2-news-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
  html.v2 .v2-news-head h2 { margin: 0; font-size: 24px; font-weight: 700; color: var(--v2-ink); }
  html.v2 .v2-news-head span { width: 44px; height: 4px; border-radius: 2px; background: var(--v2-gold); }
  html.v2 .v2-news-head a { margin-left: auto; font-size: 13.5px; color: #6E4E8A !important; text-decoration: none !important; }
  html.v2 .v2-track {
    display: flex; gap: 16px; overflow-x: auto; scroll-snap-type: x mandatory;
    scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 4px;
  }
  html.v2 .v2-track::-webkit-scrollbar { display: none; }
  html.v2 .v2-card {
    flex: 0 0 calc((100% - 48px) / 4); min-width: 0; scroll-snap-align: start;
    background: #FFF; border: 1px solid #EDEBF1; border-radius: 16px; overflow: hidden;
    text-decoration: none !important; color: inherit !important; display: block;
    transition: transform .18s ease, box-shadow .18s ease;
  }
  html.v2 .v2-card:hover, html.v2 .v2-card:focus-visible { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(16,24,40,.10); }
  html.v2 .v2-card img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
  html.v2 .v2-card .v2-card-body { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px 16px; min-height: 118px; }
  html.v2 .v2-card .v2-card-title {
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
    margin: 0 0 8px; font-size: 15px; font-weight: 700; line-height: 1.45; color: var(--v2-ink);
  }
  html.v2 .v2-card .v2-card-meta { margin-top: auto; font-size: 13px; color: #5C636A; }
  html.v2 .v2-nav { display: flex; align-items: center; gap: 8px; padding: 12px 24px 0; }
  html.v2 .v2-nav button {
    width: 40px; height: 40px; border: 1px solid var(--v2-line); border-radius: 10px;
    background: #FFF; color: #6E4E8A; font-size: 16px; line-height: 1; cursor: pointer;
  }
  html.v2 .v2-nav button:focus-visible { outline: 2px solid var(--v2-gold); outline-offset: 2px; }
  html.v2 .v2-dots { display: flex; gap: 6px; margin-left: 6px; }
  html.v2 .v2-dots button { width: 24px; height: 24px; border: 0; background: transparent; padding: 0; display: flex; align-items: center; justify-content: center; cursor: pointer; }
  html.v2 .v2-dots button::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #CFC8DA; }
  html.v2 .v2-dots button.on::before { width: 20px; border-radius: 4px; background: var(--v2-purple); }

  /* 4 · floating toolbar (right edge, 45x45 tiles) */
  html.v2 .v2-tools {
    position: fixed; right: 15px; top: 50%; transform: translateY(-50%);
    display: flex; flex-direction: column; gap: 6px; z-index: 1030;
  }
  html.v2 .v2-tools a {
    width: 45px; height: 45px; display: flex; align-items: center; justify-content: center;
    background: var(--v2-purple); color: #FFF !important; font-size: 17px;
    border-radius: 8px; text-decoration: none !important;
    box-shadow: 0 2px 8px rgba(16,24,40,.18);
    transition: background .15s ease, transform .15s ease;
  }
  html.v2 .v2-tools a:hover, html.v2 .v2-tools a:focus-visible { background: var(--v2-purple-deep); transform: translateX(-3px); }
  html.v2 .v2-tools a:focus-visible { outline: 2px solid var(--v2-gold); outline-offset: 2px; }
}

/* ---------------- V.1 news tabs are replaced by the V.2 carousel ---------- */
html.v2 ul.nav.nav-tabs,
html.v2 .tab-content { display: none !important; }

/* ---------------- tablet 768–1199: toolbar column + 2-up carousel -------- */
@media (min-width: 768px) and (max-width: 1199px) {
  html.v2 .v2-tools {
    position: fixed; right: 12px; top: 50%; transform: translateY(-50%);
    display: flex; flex-direction: column; gap: 5px; z-index: 1030;
  }
  html.v2 .v2-tools a {
    width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
    background: var(--v2-purple); color: #FFF !important; font-size: 16px;
    border-radius: 8px; text-decoration: none !important; box-shadow: 0 2px 8px rgba(16,24,40,.18);
  }
  html.v2 .v2-top { display: none; }
  html.v2 .v2-track { scroll-snap-type: x mandatory; }
  html.v2 .v2-card { scroll-snap-align: start; flex: 0 0 calc((100% - 16px) / 2); }
}

/* ---------------- mobile ≤767: bottom toolbar, V.1 header keeps the drawer */
@media (max-width: 767px) {
  html.v2 .v2-top { display: none !important; }        /* V.1 header provides logo + hamburger + drawer */
  html.v2 .v2-tools {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; transform: none;
    display: flex; flex-direction: row; justify-content: space-around; align-items: center;
    gap: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--v2-purple); border-top: 1px solid rgba(255,255,255,.18);
    z-index: 1035; box-shadow: 0 -2px 10px rgba(16,24,40,.16);
  }
  html.v2 .v2-tools a {
    width: auto; min-width: 52px; height: 44px; flex: 1 1 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; background: transparent !important; box-shadow: none !important;
    color: #FFF !important; font-size: 15px; text-decoration: none !important;
    border-radius: 8px; outline-offset: -2px;
  }
  html.v2 .v2-tools a span { font-size: 10px; line-height: 1; opacity: .9; }
  html.v2 .v2-tools a:focus-visible { outline: 2px solid var(--v2-gold); }
  html.v2 .v2-news { display: block !important; padding-bottom: 84px; }
  html.v2 .v2-track {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory; scrollbar-width: none;
  }
  html.v2 .v2-track::-webkit-scrollbar { display: none; }
  html.v2 .v2-card { scroll-snap-align: center; flex: 0 0 100%; }
  html.v2 .v2-card img { height: 200px !important; }
  html.v2 .v2-news-head h2 { font-size: 19px !important; }
  html.v2 .v2-nav { display: flex !important; }
}

/* ---------------- carousel mechanics for the non-desktop shells ---------- */
@media (max-width: 1199px) {
  html.v2 .v2-news {
    display: block !important; width: auto !important; max-width: none !important;
    margin: 0 !important; padding: 24px 16px 88px !important;
  }
  html.v2 .v2-news-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
  html.v2 .v2-news-head h2 { margin: 0; flex: 1 1 auto; font-size: 20px; color: #212529; }
  html.v2 .v2-track {
    display: flex !important; gap: 16px; overflow-x: auto; overflow-y: hidden;
    scroll-behavior: smooth; scroll-snap-type: x mandatory;
    padding: 2px 2px 6px; scrollbar-width: none;
  }
  html.v2 .v2-track::-webkit-scrollbar { display: none; }
  html.v2 .v2-card { flex: 0 0 calc((100% - 16px) / 2); scroll-snap-align: start; }
  html.v2 .v2-nav { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 12px; }
}
@media (max-width: 599px) {
  html.v2 .v2-card { flex: 0 0 100%; scroll-snap-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  html.v2 .v2-track { scroll-behavior: auto; }
}

/* card structure for tablet widths (desktop rules must not leak in) */
@media (min-width: 768px) and (max-width: 1199px) {
  html.v2 .v2-card { display: block !important; background: #FFF; border-radius: 12px; overflow: hidden;
    box-shadow: 0 1px 3px rgba(16,24,40,.10); text-decoration: none !important; }
  html.v2 .v2-card img { display: block !important; width: 100% !important; height: 180px !important;
    object-fit: cover !important; max-height: none !important; }
  html.v2 .v2-card-body { display: block !important; padding: 12px 14px 14px !important; }
  html.v2 .v2-card-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; font-size: 14.5px; line-height: 1.5; color: #212529; }
  html.v2 .v2-card-meta { display: block; margin-top: 8px; font-size: 12px; color: #6B7280; }
}

/* the carousel scrolls natively at every width (JS drives scrollLeft) */
html.v2 .v2-track {
  display: flex !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
html.v2 .v2-track::-webkit-scrollbar { display: none; }
html.v2 .v2-track > * { scroll-snap-align: start; }

/* ---------------- sidebar menu: drop duplicated group labels ------------- */
/* V.1 renders a static "หน้าหลัก" header div next to the real <li>; the V.2
   sidebar shows the <li> itself, so the bare label is a duplicate. */
html.v2 .navbar-collapse div[style*="border-bottom: solid 2px #ccc"] { display: none !important; }
html.v2 .navbar-collapse > div > div:empty { display: none !important; }
/* inline font-size:18px on the first item unbalances the sidebar rhythm */
html.v2 .navbar-collapse ul.nav.navbar-nav > li > a > span[style*="font-size:18px"] { font-size: 14px !important; color: inherit !important; }

/* V.2 desktop rail: V.1 renders a one-item “หน้าหลัก” block (.navbar-disable)
   beside the real menu. The rail shows Home from the main list, so the block is
   a duplicate — hide it on DESKTOP ONLY; on mobile it is the drawer's first item. */
@media (min-width: 1024px) {
  html.v2 .navbar-collapse .navbar-disable { display: none !important; }
}

/* carousel moves by transform: the news box clips, the track never scrolls */
html.v2 .v2-news { overflow: hidden !important; }
html.v2 .v2-track {
  overflow: visible !important;
  position: relative; left: 0;
  transition: left .45s cubic-bezier(.4,0,.2,1);
  touch-action: pan-y;
}
@media (prefers-reduced-motion: reduce) { html.v2 .v2-track { transition: none; } }

/* ============================================================================
   V.2 RIGHT ICON NAVIGATION  (Bootstrap 3.3.5 dropdown pattern, same as the
   CMU reference: ul.nav.nav-pills > li.dropdown > a.dropdown-toggle
   [data-toggle="dropdown"] + ul.dropdown-menu).
   The markup is the site's ORIGINAL navbar-right list — icons, labels, URLs
   and targets are untouched; only the placement and the fly-out direction
   change (right edge, opens right-to-left). Desktop only (>=1200px).
   ========================================================================== */
@media (min-width: 768px) {
  /* top bar hidden: TH/EN live above the icon rail, no duplicate top-right */
  html.v2 .v2-top { display: none !important; }
  html.v2 .body-light { padding-top: 0 !important; margin-top: 0 !important; }
  html.v2 .bannercontainer, html.v2 .bannercontainer.centerme {
    margin-top: 0 !important; top: 0 !important;
  }
  html.v2 .navbar.navbar-default.navbar-static-top { top: 0 !important; margin-top: 0 !important; }
}

@media (min-width: 1200px) {
  /* ---- TH/EN: above the rail, never inside a dropdown ------------------- */
  html.v2 .v2-rail-lang {
    position: fixed; right: 14px; top: 96px; width: 84px;
    display: flex; gap: 8px; justify-content: center; align-items: center;
    padding: 6px; background: #FFFFFF; border: 1px solid var(--v2-line);
    border-radius: 12px; box-shadow: 0 4px 18px rgba(16,24,40,.12); z-index: 1040;
  }
  html.v2 .v2-rail-lang li { list-style: none !important; float: none !important; margin: 0 !important; }
  html.v2 .v2-rail-lang li br { display: none !important; }
  html.v2 .v2-rail-lang a {
    display: flex !important; align-items: center; justify-content: center;
    width: 28px; height: 26px; border-radius: 6px; background: #F5F6F7;
    text-decoration: none !important;
  }
  html.v2 .v2-rail-lang a:hover, html.v2 .v2-rail-lang a:focus-visible { background: #F3EDF6; }
  html.v2 .v2-rail-lang a:focus-visible { outline: 2px solid var(--v2-gold); outline-offset: 1px; }
  html.v2 .v2-rail-lang img { height: 15px !important; width: auto !important; max-width: 24px !important; }

  /* ---- the rail itself: the original navbar-right list, re-flowed ------- */
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right {
    display: flex !important; flex-direction: column; align-items: stretch; gap: 10px;
    position: fixed !important;
    right: calc(8px + env(safe-area-inset-right, 0px));
    top: calc(8px + env(safe-area-inset-top, 0px)); width: 84px;
    margin: 0 !important; padding: 8px !important;
    background: #FFFFFF; border: 1px solid var(--v2-line); border-radius: 14px;
    box-shadow: 0 4px 18px rgba(16,24,40,.12); z-index: 1055;
    float: none !important; order: 0 !important; flex: none !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li {
    position: relative; float: none !important; width: 100% !important; margin: 0 !important;
    display: block !important;
  }
  /* icon = the dropdown toggle, 60x60 click target */
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a.dropdown-toggle {
    display: flex !important; align-items: center; justify-content: center;
    width: 68px !important; height: 68px !important; margin: 0 auto; padding: 0 !important;
    border-radius: 14px; background: #F5F6F7; overflow: hidden;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a:hover,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a:focus-visible,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li.open > a {
    background: var(--v2-purple) !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a:focus-visible {
    outline: 2px solid var(--v2-gold); outline-offset: 2px;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a img {
    height: 56px !important; width: 56px !important; max-width: 56px !important;
    max-height: none !important; object-fit: contain !important; display: block;
  }

  /* ---- tooltip ---------------------------------------------------------- */
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a[data-tip]::after {
    content: attr(data-tip);
    position: absolute; right: calc(100% + 10px); top: 50%; transform: translateY(-50%);
    white-space: nowrap; background: #2F2A36; color: #FFFFFF;
    font-size: 12.5px; line-height: 1; padding: 7px 10px; border-radius: 6px;
    opacity: 0; pointer-events: none; transition: opacity .12s ease; z-index: 1046;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a[data-tip]:hover::after,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a[data-tip]:focus-visible::after { opacity: 1; }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li.open > a[data-tip]::after { opacity: 0 !important; }

  /* ---- fly-out: right-to-left, vertical, scrolls inside, never clipped --- */
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu {
    /* the rail is fixed, so the fly-out is fixed too: same top edge for every
       menu, capped by the viewport height so a long list always scrolls inside */
    position: fixed !important; right: 102px !important; left: auto !important;
    top: 8px !important; transform: none; float: none !important; margin: 0 !important;
    min-width: 0 !important; width: 340px !important; max-width: 340px !important;
    max-height: calc(100vh - 24px); overflow-y: auto; overflow-x: hidden;
    padding: 8px !important; background: #FFFFFF; border: 1px solid var(--v2-line);
    border-radius: 12px; box-shadow: 0 8px 28px rgba(16,24,40,.18); z-index: 1060;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu li,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu ul { list-style: none; }
  /* the Student menu is a V.1 two-column mega menu — flatten it to one column */
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu ul.col-sm-6 {
    float: none !important; width: 100% !important; max-width: none !important;
    padding: 0 !important; margin: 0 !important; position: static !important; display: block !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu > li,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu > li > ul > li {
    width: 100% !important; float: none !important; display: block !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu a {
    display: block; white-space: normal !important; line-height: 1.45;
    padding: 8px 10px !important; border-radius: 8px; font-size: 13.5px; color: var(--v2-ink) !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu a:hover,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu a:focus-visible {
    background: #F3EDF6 !important; color: #4B2E63 !important;
  }

  /* keep the rail from covering the news row */
  html.v2 .v2-news { padding-right: 104px !important; }
  /* the old 5-icon shortcut rail would duplicate the 4 group icons */
  html.v2 .v2-tools { display: none !important; }
}

@media (max-width: 1199px) {
  html.v2 .v2-rail-lang { display: none !important; }   /* tablet/mobile keep their own switch */
}


/* ============================================================================
   V.2 LEFT SIDEBAR — 7 top-level entries; each one opens a REAL dropdown card
   (same component as the right icon rail: 340px white card, 12px radius,
   0 8px 28px shadow, #F3EDF6 hover, click / outside-click / Escape).
   Nothing is expanded before a click; the list is never an inline accordion.
   ========================================================================== */
@media (min-width: 1200px) {
  html.v2 .navbar-header picture.d-logo { display: none !important; }
  html.v2 .navbar-header .v2-logo {
    display: block; width: 100%; max-width: 238px; height: auto; margin: 0 auto;
    padding: 0; background: none !important; border: 0 !important; border-radius: 0 !important;
    box-shadow: none !important; filter: none !important;
  }
}

/* legacy horizontal inline menu (V.1 desktop) must not surface */
html.v2 .navbar-full_Disable { display: none !important; }

/* ---- the 7 headers ---------------------------------------------------- */
html.v2 .v2-group { display: block; position: relative; border-top: 1px solid rgba(255,255,255,.10); }
html.v2 .v2-group-toggle {
  display: flex !important; flex-wrap: nowrap; align-items: center; gap: 10px; width: 100%;
  margin: 0; padding: 14px 16px; border: 0; background: transparent;
  text-align: left; cursor: pointer; font: inherit;
  color: var(--v2-gold); font-size: 11.5px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
}
html.v2 .v2-group-label { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
html.v2 .v2-group-toggle:hover { background: rgba(255,255,255,.08); }
html.v2 .v2-group-toggle:focus-visible { outline: 2px solid var(--v2-gold); outline-offset: -2px; }
html.v2 .v2-group-toggle.open { background: rgba(255,255,255,.10); }
html.v2 .v2-group.open > .v2-group-toggle { color: #FFF; }

/* a section that is a single direct link (หน้าหลัก / ติดต่อเรา) */
html.v2 .v2-group-link {
  display: flex; align-items: center; width: 100%; padding: 14px 16px;
  color: var(--v2-gold); font-size: 11.5px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; text-decoration: none !important;
}
html.v2 .v2-group-link:hover, html.v2 .v2-group-link:focus-visible { background: rgba(255,255,255,.08); color: #FFF; }
html.v2 .v2-group-link:focus-visible { outline: 2px solid var(--v2-gold); outline-offset: -2px; }
html.v2 .v2-group-link.is-active { background: rgba(255,211,0,.14); color: #FFF; }

html.v2 .v2-caret {
  flex: 0 0 auto; width: 7px; height: 7px; margin-top: -3px;
  border-right: 2px solid rgba(255,255,255,.72); border-bottom: 2px solid rgba(255,255,255,.72);
  transform: rotate(-45deg); transition: transform .2s ease, border-color .2s ease;   /* ▶ */
}
html.v2 .v2-group-toggle.open .v2-caret { transform: rotate(45deg); margin-top: -6px; border-color: var(--v2-gold); }  /* ▼ */

/* ---- the dropdown card (identical tokens to the right rail card) ------ */
html.v2 .v2-dd {
  display: none; position: fixed; z-index: 1050;
  width: 340px; max-height: 70vh; overflow-y: auto; overflow-x: hidden;
  padding: 8px; background: #FFFFFF; border: 1px solid var(--v2-line);
  border-radius: 12px; box-shadow: 0 8px 28px rgba(16,24,40,.18);
  z-index: 1060;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
html.v2 .v2-dd.open { display: block; }
html.v2 .v2-dd-list { list-style: none; margin: 0 !important; padding: 0 !important; float: none !important; }
html.v2 .v2-dd-list > li { display: block !important; float: none !important; margin: 0 !important; }
html.v2 .v2-dd-list > li > a {
  display: block !important; padding: 9px 12px !important; border-radius: 8px;
  font-size: 13.5px !important; line-height: 1.45 !important; font-weight: 600 !important;
  color: var(--v2-ink) !important; text-decoration: none !important;
  border: 0 !important; background: transparent !important;
}
html.v2 .v2-dd-list > li.v2-dd-sub > a {
  padding: 8px 12px 8px 22px !important; font-size: 13px !important; font-weight: 400 !important;
  color: #4B5563 !important;
}
html.v2 .v2-dd-list > li > a:hover,
html.v2 .v2-dd-list > li > a:focus-visible {
  background: #F3EDF6 !important; color: #4B2E63 !important; outline: none;
}
html.v2 .v2-dd-list > li > a:focus-visible { box-shadow: inset 0 0 0 2px var(--v2-gold); }
html.v2 .v2-dd-list > li > a.is-active {
  background: #E9DFF1 !important; color: #4B2E63 !important;
  box-shadow: inset 3px 0 0 var(--v2-purple);
}

/* ---- keep the rail scrollable, thin scrollbar ------------------------ */
html.v2 .navbar.navbar-default.navbar-static-top {
  overscroll-behavior: contain; scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.38) transparent;
}
html.v2 .navbar.navbar-default.navbar-static-top::-webkit-scrollbar { width: 8px; }
html.v2 .navbar.navbar-default.navbar-static-top::-webkit-scrollbar-thumb { background: rgba(255,255,255,.34); border-radius: 4px; }
html.v2 .navbar.navbar-default.navbar-static-top::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) { html.v2 .v2-caret { transition: none !important; } }

/* ============================================================================
   TABLET / MOBILE — the drawer uses the same 7 dropdown headers (light theme).
   ========================================================================== */
@media (max-width: 1199px) {
  html.v2 .navbar-header .v2-logo { display: none !important; }
  html.v2 .v2-group { border-top: 0; border-bottom: 1px solid #E4E7EB; }
  html.v2 .v2-group-toggle {
    padding: 12px 15px; color: #4B2E63 !important; font-size: 15px; font-weight: 700;
    letter-spacing: 0; text-transform: none;
  }
  html.v2 .v2-group-toggle:hover { background: #F5F6F7; }
  html.v2 .v2-group.open > .v2-group-toggle { background: #F3EDF6; color: #4B2E63 !important; }
  html.v2 .v2-group-link {
    padding: 12px 15px; color: #4B2E63 !important; font-size: 15px; font-weight: 700;
    letter-spacing: 0; text-transform: none;
  }
  html.v2 .v2-group-link:hover, html.v2 .v2-group-link:focus-visible { background: #F5F6F7; color: #4B2E63; }
  html.v2 .v2-group-link.is-active { background: #F3EDF6; color: #4B2E63 !important; }
  html.v2 .v2-caret { border-right-color: #6E4E8A; border-bottom-color: #6E4E8A; }
  html.v2 .v2-group-toggle.open .v2-caret { border-color: #6E4E8A; }
  html.v2 .v2-dd-list > li.v2-dd-sub > a { color: #495057 !important; }
}

/* ============================================================================
   V.2 HERO — 3:1 frame (source slides are 1169×299 ≈ 3.91:1, so the picture is
   fitted inside the frame with no cropping and no distortion).
   ========================================================================== */
@media (min-width: 1200px) {
  html.v2 .bannercontainer.centerme,
  html.v2 .bannercontainer {
    width: min(1600px, calc(100% - 48px)) !important;
    max-width: 1600px !important;
    height: calc(1600px / 3);            /* read by the slider for its ratio */
    margin: 0 auto !important;
    border-radius: 20px !important;
    overflow: hidden;
    background: #14100F;
  }
  html.v2 .bannercontainer img { object-fit: contain !important; }
  html.v2 .bannercontainer .kenburn-bg { background-size: cover; }
}


/* ============================================================================
   MOBILE (<=767px) — the four department-group icons (Staff / Students /
   Admission / Alumni) as a right-hand rail, same artwork and dropdown
   behaviour as desktop, sized for touch. Bottom toolbar, hamburger drawer,
   left menu and the slider are untouched.
   ========================================================================== */
@media (max-width: 767px) {
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right {
    display: flex !important; flex-direction: column; align-items: center; gap: 8px;
    position: fixed !important;
    right: calc(8px + env(safe-area-inset-right, 0px));
    top: 50%;
    transform: translateY(-50%);
    width: 56px; margin: 0 !important; padding: 0 !important;
    float: none !important; background: transparent; border: 0; box-shadow: none;
    z-index: 1055;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li {
    position: relative; display: block !important; float: none !important;
    width: 56px !important; margin: 0 !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a.dropdown-toggle {
    display: flex !important; align-items: center; justify-content: center;
    width: 56px !important; height: 56px !important; padding: 0 !important; margin: 0 !important;
    border-radius: 14px; background: #FFFFFF;
    border: 1px solid var(--v2-line); box-shadow: 0 4px 14px rgba(16,24,40,.16);
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a img {
    height: 36px !important; width: 36px !important; max-width: 36px !important;
    max-height: none !important; object-fit: contain !important; display: block;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a:hover,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li.open > a {
    background: var(--v2-purple) !important;
  }
  /* fly-out opens to the left, never wider than the viewport */
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu {
    position: fixed !important; right: 74px !important; left: auto !important;
    top: 8px !important; transform: none; float: none !important; margin: 0 !important;
    width: min(300px, calc(100vw - 96px)) !important; min-width: 0 !important; max-width: none !important;
    max-height: calc(100vh - 24px); overflow-y: auto; padding: 8px !important;
    background: #FFF; border: 1px solid var(--v2-line); border-radius: 12px;
    box-shadow: 0 8px 28px rgba(16,24,40,.18); z-index: 1045;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu ul.col-sm-6 {
    float: none !important; width: 100% !important; padding: 0 !important; margin: 0 !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu li,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu li > ul {
    width: 100% !important; float: none !important; display: block !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu > li > a,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu li ul li a {
    display: block; white-space: normal !important; padding: 9px 10px !important;
    border-radius: 8px; font-size: 13px; line-height: 1.4; color: var(--v2-ink) !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu a:hover {
    background: #F3EDF6 !important; color: #4B2E63 !important;
  }
}


/* ============================================================================
   TABLET (768–1199px) — the same top-right icon group as desktop/mobile:
   fixed to the viewport corner (8px / 8px), vertical, above slider & content.
   ========================================================================== */
@media (min-width: 768px) and (max-width: 1199px) {
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right {
    display: flex !important; flex-direction: column; align-items: center; gap: 8px;
    position: fixed !important;
    right: calc(8px + env(safe-area-inset-right, 0px)) !important;
    top: calc(8px + env(safe-area-inset-top, 0px)) !important;
    width: 56px !important; margin: 0 !important; padding: 0 !important;
    float: none !important; background: transparent; border: 0; box-shadow: none;
    z-index: 1055 !important; order: 0 !important; flex: none !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li {
    position: relative; display: block !important; float: none !important; width: 56px !important; margin: 0 !important;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a,
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a.dropdown-toggle {
    display: flex !important; align-items: center; justify-content: center;
    width: 56px !important; height: 56px !important; padding: 0 !important; margin: 0 !important;
    border-radius: 14px; background: #FFFFFF;
    border: 1px solid var(--v2-line); box-shadow: 0 4px 14px rgba(16,24,40,.16);
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right > li > a img {
    height: 36px !important; width: 36px !important; max-width: 36px !important;
    max-height: none !important; object-fit: contain !important; display: block;
  }
  html.v2 body .navbar > .container > ul.nav.navbar-nav.navbar-right .dropdown-menu {
    position: fixed !important; right: 74px !important; left: auto !important;
    top: 8px !important; transform: none; float: none !important; margin: 0 !important;
    width: min(320px, calc(100vw - 96px)) !important; min-width: 0 !important; max-width: none !important;
    max-height: calc(100vh - 24px); overflow-y: auto; padding: 8px !important;
    background: #FFF; border: 1px solid var(--v2-line); border-radius: 12px;
    box-shadow: 0 8px 28px rgba(16,24,40,.18); z-index: 1060;
  }
}


/* ============================================================================
   V.2 HERO — slide layer (replaces the canvas paint so nothing is cropped).
   Images are 3.9:1 inside a 3:1 frame: fitting by height shows the whole
   picture (heads included) with no stretch; Ken Burns zoom + dots kept.
   ========================================================================== */
html.v2 .bannercontainer .v2-hero { position: absolute; inset: 0; overflow: hidden; background: #14100F; }
html.v2 .bannercontainer[data-v2hero] .slide_mainmask,
html.v2 .bannercontainer[data-v2hero] .kenburn-bg,
html.v2 .bannercontainer[data-v2hero] .thumbbuttons { display: none !important; }
html.v2 .v2-hero-slide { position: absolute; inset: 0; display: block; opacity: 0; transition: opacity .5s ease; }
html.v2 .v2-hero-slide.on { opacity: 1; }
html.v2 .v2-hero-slide img {
  width: 100% !important; height: 100% !important; display: block;
  object-fit: cover !important; object-position: center 30% !important;
  max-width: none !important; max-height: none !important;
  transform-origin: center 32%;
}
html.v2 .v2-hero-slide.on img { animation: v2-kenburns 8s ease-out forwards; }
@keyframes v2-kenburns {
  from { transform: scale(1.02); }
  to   { transform: scale(1.08); }
}
html.v2 .v2-hero-dots {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 14px;
  display: flex; gap: 7px; z-index: 3;
}
html.v2 .v2-hero-dots button {
  width: 10px; height: 10px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.45); cursor: pointer;
}
html.v2 .v2-hero-dots button.on { width: 24px; border-radius: 5px; background: #FFF; }
html.v2 .v2-hero-dots button:focus-visible { outline: 2px solid var(--v2-gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  html.v2 .v2-hero-slide.on img { animation: none !important; }
}


/* mobile: while the drawer is open the floating rail steps aside */
@media (max-width: 767px) {
  html.v2.v2-drawer-open ul.navbar-right { opacity: 0; pointer-events: none; }
}
