/* ==========================================================================
   Shared header / tab bar — ใช้เหมือนกันทั้งเว็บ (หน้าแรก .site-header
   และหน้าคำสั่ง .tabbar) โหลดเป็นไฟล์สุดท้ายเพื่อทับสไตล์เดิม
   สีอ้างอิง DESIGN.md:
   - สว่าง: primary #4D238D, accent #D6A83F, text #241B32
   - มืด:   bg #100D1C, panel #1C172A, primary #9364DF, accent #F0C96D, text #F5F1FC
   - เมนูไม่มีพื้นหลังวงรี มีเพียงขีดทองใต้เมนูที่เลือก
   ========================================================================== */

/* ---------- แถบ (โหมดสว่าง): ม่วงเข้มเด่นกว่าพื้นหลัง ---------- */

.site-header,
.tabbar__inner {
  width: auto;
  margin: 0.75rem 40px 0;
  border-radius: 1.75rem;
}

/* ใช้ selector [data-theme] เพื่อให้เฉพาะเจาะจงเท่ากับ style.css และโหลดทีหลังจึงทับได้ */
[data-theme="light"] .site-header,
[data-theme="light"] .tabbar__inner {
  border: 1px solid rgba(77, 35, 141, 0.22);
  background-color: transparent;
  background-image: linear-gradient(120deg, #FFFFFF 0%, #F7F3FD 60%, #EFE7FB 100%);
  box-shadow: 0 14px 30px -14px rgba(20, 8, 40, 0.55),
    inset 0 1px 0 #FFFFFF;
}

/* ---------- เมนู (โหมดสว่าง) ---------- */

.nav-link,
.tabbar__link {
  background: none;
  color: #241B32;
  font-size: 1rem;
  font-weight: 600;
}

.nav-link:hover,
.tabbar__link:hover,
.nav-item--dropdown > .nav-link__toggle:hover,
.nav-item--dropdown.is-open > .nav-link__toggle,
.tabbar__dropdown.open > .tabbar__link {
  background: none;
  color: #4D238D;
}

.nav-link.is-active,
.tabbar__link.is-active {
  background: none;
  color: #4D238D;
  font-weight: 700;
}

/* ---------- ปุ่มขวา (โหมดสว่าง) ---------- */

.font-size,
.tabbar__font-sizes {
  background: #FFFFFF;
  border: 1px solid rgba(77, 35, 141, 0.28);
}

.font-size__btn,
.tabbar__size-btn,
.icon-btn,
.tabbar__icon-btn,
.tabbar__menu-btn {
  color: #241B32;
  font-weight: 600;
}

.font-size__btn:hover,
.tabbar__size-btn:hover {
  background: rgba(77, 35, 141, 0.08);
  color: #4D238D;
}

.icon-btn:hover,
.tabbar__icon-btn:hover,
.tabbar__menu-btn:hover {
  background: rgba(77, 35, 141, 0.1);
  color: #4D238D;
}

/* ป้าย TH ของปุ่มภาษา: ม่วงเข้มตัดกับแถบขาว */
.tabbar__language-btn::after {
  background: #4D238D;
  color: #FFFFFF;
}

/* ---------- แถบ (โหมดมืด): เข้มกว่าพื้นหลัง ขอบม่วงเรืองแสง ---------- */

[data-theme="dark"] .site-header,
[data-theme="dark"] .tabbar__inner {
  border: 0;
  background-color: transparent;
  background-image: linear-gradient(90deg, #a497bf 0%, #241248 15%, #170B30 100%);
  /* ขอบบนสว่าง ขอบล่างเข้ม ให้แถบดูนูนขึ้นจากพื้นหลัง */
  box-shadow: 0 16px 28px -10px rgba(0, 0, 0, 0.75),
    inset 0 2px 0 rgba(255, 255, 255, 0.14),
    inset 0 -2px 0 rgba(0, 0, 0, 0.45);
}

/* ---------- เมนู (โหมดมืด) ---------- */

[data-theme="dark"] .nav-link,
[data-theme="dark"] .tabbar__link {
  background: none;
  color: #FFFFFF;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] .nav-link:hover,
[data-theme="dark"] .nav-link:focus-visible,
[data-theme="dark"] .nav-link.is-active,
[data-theme="dark"] .nav-item--dropdown > .nav-link__toggle:hover,
[data-theme="dark"] .nav-item--dropdown.is-open > .nav-link__toggle,
[data-theme="dark"] .tabbar__link:hover,
[data-theme="dark"] .tabbar__link.is-active,
[data-theme="dark"] .tabbar__dropdown.open > .tabbar__link {
  background: none;
  color: #F0C96D;
}

/* ---------- ปุ่มขวา (โหมดมืด) ไม่มีกรอบ ---------- */

[data-theme="dark"] .font-size,
[data-theme="dark"] .tabbar__font-sizes {
  background: rgba(255, 255, 255, 0.06);
  border-color: transparent;
}

[data-theme="dark"] .font-size__btn,
[data-theme="dark"] .tabbar__size-btn,
[data-theme="dark"] .icon-btn,
[data-theme="dark"] .tabbar__icon-btn,
[data-theme="dark"] .tabbar__menu-btn {
  color: #FFFFFF;
}

[data-theme="dark"] .font-size__btn:hover,
[data-theme="dark"] .tabbar__size-btn:hover,
[data-theme="dark"] .icon-btn:hover,
[data-theme="dark"] .tabbar__icon-btn:hover,
[data-theme="dark"] .tabbar__menu-btn:hover {
  background: rgba(240, 201, 109, 0.14);
  color: #F0C96D;
}

/* โลโก้ในโหมดมืด: ไม่มีกรอบ ใช้แสงขอบบาง ๆ ให้เห็นชัดบนพื้นมืด */
[data-theme="dark"] .brand__logo,
[data-theme="dark"] .tabbar__brand img {
  filter: brightness(1.4) saturate(1.1);
}

.tabbar__brand {
  padding: 0.3rem 0.6rem;
  border-radius: 1rem;
}

[data-theme="dark"] .tabbar__language-btn::after {
  background: #9364DF;
  color: #120C1F;
}

/* ---------- ขีดใต้เมนูที่เลือก (ไม่มีวงรี) ---------- */

.nav-link.is-active[href]::after,
.tabbar__link.is-active::after {
  background-color: #D6A83F;
}

[data-theme="dark"] .nav-link.is-active[href]::after,
[data-theme="dark"] .tabbar__link.is-active::after {
  background-color: #D6A83F;
}

/* ---------- หน้าแรก: ภาพปกเต็มหน้า ไม่มีขอบขาว ----------
   ดึงภาพปกขึ้นไปอยู่ใต้ header ที่ลอยทับ แล้วให้สูงเต็มจอ */

.hero-stage {
  margin: calc(-1 * (var(--header-height) + 0.75rem)) 0 0;
  height: 100vh;
  height: 100svh;
  border-radius: 0;
}

/* ---------- มือถือ ---------- */

@media (max-width: 767px) {
  .site-header,
  .tabbar__inner {
    margin-inline: 0.5rem;
    border-radius: 1.25rem;
  }
}

/* ---------- แถบ (โหมดสว่าง) ไล่สีให้เด่นกว่าพื้นหลัง: ขาว–ลาเวนเดอร์ มีแสงทองมุมซ้าย ---------- */
[data-theme="light"] .site-header,
[data-theme="light"] .tabbar__inner {
  background-image:
    radial-gradient(120% 160% at 0% 0%, rgba(214, 168, 63, 0.20) 0%, rgba(214, 168, 63, 0) 46%),
    linear-gradient(105deg, #FFFFFF 0%, #FBF7FF 34%, #F1E6FF 68%, #E2CFFF 100%);
  border: 1px solid rgba(155, 107, 232, 0.38);
  box-shadow: 0 18px 34px -16px rgba(40, 15, 80, 0.70),
    0 0 0 4px rgba(255, 255, 255, 0.32),
    inset 0 1px 0 #FFFFFF,
    inset 0 -1px 0 rgba(155, 107, 232, 0.25);
}

/* ---------- แถบ (โหมดมืด) ไล่สีให้เด่นกว่าพื้นหลัง: โทนอ่อนอยู่ฝั่งโลโก้ให้โลโก้เห็นชัด ค่อยเข้มไปทางเมนูและไอคอน ---------- */
[data-theme="dark"] .site-header,
[data-theme="dark"] .tabbar__inner {
  background-image:
    radial-gradient(90% 140% at 0% 50%, rgba(255, 255, 255, 0.18) 0%, rgba(255, 255, 255, 0) 55%),
    linear-gradient(90deg, #B7A2DE 0%, #6F4FB0 10%, #3B2373 20%, #1E1143 62%, #120828 100%);
  border: 1px solid rgba(190, 160, 255, 0.45);
  box-shadow: 0 18px 34px -12px rgba(0, 0, 0, 0.80),
    0 0 0 4px rgba(147, 100, 223, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -2px 0 rgba(0, 0, 0, 0.40);
}

/* ==========================================================================
   Mobile (≤767px): responsive fixes only. Desktop and design are unchanged.
   - The menu row scrolls sideways on one line instead of wrapping into rows.
   - The hero picture fills its panel and is cropped, never pushed off-screen.
   ========================================================================== */
@media (max-width: 767px) {
  .nav-list {
    width: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .nav-list > li {
    flex: 0 0 auto;
  }

  /* ภาพปกเต็มจอ และประกาศลอยทับภาพปกด้านล่างเหมือนเดสก์ท็อป */
  .hero-stage {
    max-width: 100%;
    overflow-x: clip;
  }

  .hero__image {
    width: 100%;
    max-width: none;
    height: 100%;
    object-fit: cover;
    /* ครอปกลางภาพ ให้โลโก้และข้อความ UP GRADUATE อยู่กึ่งกลางจอมือถือ */
    object-position: 50% 35%;
  }

  .announce {
    position: absolute;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    height: auto;
    padding-block: 0 clamp(1.25rem, 4.5vh, 2.5rem);
  }
}


/* ---------- มือถือ: ภาพปกเริ่มจากขอบบนของจอพอดี (ใช้ความสูงจริงของ header ที่วัดด้วย JS) ---------- */
@media (max-width: 767px) {
  .hero-stage {
    margin: calc(-1 * (var(--header-h, var(--header-height)) + 0.75rem)) 0 0;
  }
}

/* มือถือ: แถบเมนูต้องไม่กว้างเกินจอ (ป้องกันแถบดำด้านข้างจากการล้นแนวนอน 14px) */
@media (max-width: 767px) {
  .site-header__inner,
  .primary-nav {
    min-width: 0;
    max-width: 100%;
  }
}

/* ---------- มือถือ: ประกาศแบบเดียวกับเดสก์ท็อป (การ์ดขนาดเดิม เรียงแนวนอนเลื่อนได้) ---------- */
@media (max-width: 767px) {
  .announce > .container {
    max-width: 100%;
  }

  .announce__grid {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: var(--space-md);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    padding: 0.5rem var(--container-pad) 0.75rem;
  }

  .announce__grid::-webkit-scrollbar {
    display: none;
  }

  .announce__grid li {
    flex: 0 0 10.5rem;
    max-width: none;
    scroll-snap-align: start;
  }
}

/* ---------- มือถือ: กล่องข่าวลอยย่อลงและย้ายขึ้นไปใต้เมนู ไม่ทับแถวประกาศ ---------- */
@media (max-width: 767px) {
  /* กลางจอแนวตั้ง ทับชื่อมหาวิทยาลัยบนภาพปก */
  .promo {
    top: 55%;
    bottom: auto;
    inset-block-start: 55%;
    inset-block-end: auto;
    inset-inline-start: auto;
    left: auto;
    right: 1.25rem;
    inset-inline-end: 1.25rem;
    width: 14rem;
    max-width: calc(100vw - 1.5rem);
    /* ย่อทั้งการ์ดตามสัดส่วนเดิม (รูปแบบเดิมไม่เปลี่ยน) ให้ขอบขวาอยู่ที่เดิม */
    transform: translateY(-50%) scale(0.8);
    transform-origin: right center;
    /* ตัดส่วนที่เลยกรอบกล่องออก ไม่ให้ขอบที่เกินโผล่ออกนอกหน้าจอ */
    overflow: hidden;
  }

  .promo__stage,
  .promo__dock {
    max-width: 100%;
  }
}

/* ---------- มือถือ: ป๊อปอัพประชาสัมพันธ์ย่อให้พอดีจอ (ขนาดเดสก์ท็อปไม่เปลี่ยน) ---------- */
@media (max-width: 767px) {
  .promo__modal {
    padding: 1.25rem;
  }

  /* กล่องอยู่กึ่งกลางคอลัมน์ของป๊อปอัพ ระยะซ้ายขวาจึงเท่ากันเสมอ */
  .promo__dialog {
    width: 100%;
    max-width: 24rem;
    justify-self: center;
    margin-inline: auto;
  }
}

/* ---------- มือถือ: ภาพปกเต็มจอถึงขอบล่างและขอบขวา (ไม่มีช่องว่างเหลือจากการคำนวณความสูงเดิม) ---------- */
@media (max-width: 767px) {
  .hero-stage {
    height: 100svh;
    min-height: 0;
  }

  .hero {
    border-radius: 0;
  }
}

/* Mobile: no reserved scrollbar gutter, so the page fills the full width */
@media (max-width: 767px) {
  html {
    scrollbar-gutter: auto;
  }
}

/* มือถือ: โลโก้และไอคอนลดตามปุ่ม A- ได้ แต่ล็อกไม่ขยายเกินขนาดเริ่มต้น (16px) เพื่อให้ทั้งแถวอยู่บรรทัดเดียวเสมอ */
@media (max-width: 767px) {
  .brand__logo {
    height: min(3rem, 48px);
  }

  .icon-btn,
  .lang-btn,
  .font-size {
    height: min(2.5rem, 40px);
  }

  .icon-btn,
  .lang-btn {
    width: min(2.5rem, 40px);
  }

  .icon-btn svg,
  .lang-btn svg {
    width: min(1.25rem, 20px);
    height: min(1.25rem, 20px);
  }

  .font-size__btn {
    font-size: min(0.8125rem, 13px);
    min-width: min(1.75rem, 28px);
  }

  .header-actions {
    gap: 4px;
  }

  .site-header__inner {
    padding-inline: 12px;
    column-gap: 8px;
  }
}

/* มือถือ: กดเมนูประกาศแล้วเฉพาะรายการย่อยลอยทับเนื้อหา กรอบแถบเมนูไม่ขยายตาม */
@media (max-width: 767px) {
  .nav-item--dropdown {
    position: static;
  }

  .nav-item--dropdown .dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    z-index: 60;
    width: max-content;
    min-width: 15rem;
    max-width: 100%;
    margin: 0 auto;
    padding: 0.375rem;
    border: 1px solid var(--color-border);
    box-shadow: 0 16px 30px -14px rgba(40, 15, 80, 0.55);
  }
}

/* มือถือ: โลโก้กับไอคอนอยู่แถวเดียวกันเสมอเมื่อเพิ่ม/ลดตัวอักษร (ใช้กริด: โลโก้หดได้ ไอคอนไม่หดและไม่ตกแถว, เมนูอยู่แถวล่างเต็มความกว้าง) */
@media (max-width: 767px) {
  .site-header__inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .brand {
    min-width: 0;
    align-items: flex-start;
  }

  .brand__logo {
    max-width: 100%;
    object-fit: contain;
  }

  .header-actions {
    grid-column: 2;
  }

  .primary-nav {
    grid-column: 1 / -1;
  }
}

/* มือถือ: ประกาศซ่อนไว้ตอนเปิดหน้า/รีเฟรช และจะขึ้นเมื่อผู้ใช้เลื่อนขึ้น (เหมือนเดสก์ท็อป) */
@media (max-width: 767px) {
  html[data-announce="wait"] .announce {
    opacity: 0;
    pointer-events: none;
    transform: translateY(4rem);
    transition: opacity 220ms var(--ease), transform 220ms var(--ease);
  }

  html[data-announce="wait"] .announce > .container {
    pointer-events: none;
  }

  html[data-announce="wait"] .announce-card {
    opacity: 0;
  }
}

/* ==========================================================================
   Desktop ≥1200px: สมดุลระยะขอบและช่องไฟของ Navbar
   - padding ซ้าย-ขวา 28px (โลโก้ถึงขอบซ้าย = ปุ่มเข้าสู่ระบบถึงขอบขวา)
   - margin ซ้าย-ขวาของแถบเท่ากัน 40px
   - กริด 3 คอลัมน์: โลโก้ชิดซ้าย / เมนูกึ่งกลาง / ไอคอนชิดขวา
   - เมนูกลางเว้นช่อง 24px ไม่ตัดบรรทัด และห่างจากกลุ่มไอคอนอย่างน้อย 32px
   - กลุ่มไอคอนฝั่งขวาเว้นช่อง 12px
   มือถือและแท็บเล็ตไม่เปลี่ยน
   ========================================================================== */
@media (min-width: 1200px) {
  .site-header {
    margin-inline: 40px;
  }

  .site-header .site-header__inner {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding-inline: 28px;
  }

  .site-header .brand {
    justify-self: start;
  }

  .site-header .primary-nav {
    justify-self: center;
    margin-inline: 32px;
  }

  .site-header .nav-list {
    flex-wrap: nowrap;
    gap: 24px;
  }

  .site-header .nav-link {
    white-space: nowrap;
  }

  .site-header .header-actions {
    justify-self: end;
    gap: 12px;
  }
}

/* ปุ่มเข้าสู่ระบบ: ตัวหนังสือบรรทัดเดียวเสมอ (ไม่ตัดเป็นสองบรรทัด) */
.site-header .header-login {
  white-space: nowrap;
  width: auto;
}

/* ==========================================================================
   Desktop 1200–1919px: แถบเมนูเต็มความกว้างเลยขอบบน และเมนูอยู่บรรทัดเดียวกับโลโก้/ไอคอน
   - ไม่มีช่องว่างด้านบนและด้านข้าง (แถบติดขอบบนจอ)
   - กริด 1 แถว: โลโก้ซ้าย / เมนูกึ่งกลาง / ไอคอนขวา
   - ลดขนาดตัวอักษรและระยะห่างเมนูลงเล็กน้อยให้พอดีบรรทัดเดียว
   ========================================================================== */
@media (min-width: 1200px) and (max-width: 1919px) {
  .site-header {
    margin: 0;
    border-radius: 0;
  }

  .site-header .site-header__inner {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 16px;
    padding-inline: 24px;
  }

  .site-header .primary-nav {
    grid-row: auto;
    grid-column: auto;
    justify-self: center;
    margin-inline: 0;
    min-width: 0;
  }

  .site-header .nav-list {
    flex-wrap: nowrap;
    gap: 14px;
    justify-content: center;
  }

  .site-header .nav-link {
    font-size: 0.875rem;
    padding-inline: 0.375rem;
  }

  .site-header .header-actions {
    gap: 8px;
  }
}

/* จอ 1920px ขึ้นไป: เมนูและตัวอักษรเล็กลงเล็กน้อยให้พอดีบรรทัดเดียว */
@media (min-width: 1920px) {
  .site-header .nav-list {
    gap: 12px;
  }

  .site-header .nav-link {
    font-size: 0.92rem;
    padding-inline: 0.55rem;
  }
}
