/* ==========================================================================
   home-refresh.css
   ใช้เฉพาะหน้าแรก (index.html และ en/index.html) — ไม่กระทบหน้าอื่น
   ไฟล์นี้ปรับเฉพาะการแสดงผล (layout / responsive / animation)
   ไม่ได้เปลี่ยนเนื้อหา ข้อความ หรือรูปภาพใดๆ
   ย้อนกลับ: ลบบรรทัด <link ... home-refresh.css> ออกจากทั้งสองหน้า
   ========================================================================== */

/* --------------------------------------------------------------------------
   ข้อ 1: เมนู dropdown ล้นจอ
   เมนูย่อยที่ซ่อนอยู่ยังกินพื้นที่ทำให้หน้ากว้างเกินจอ
   -------------------------------------------------------------------------- */
html,
body {
  overflow-x: clip; /* กันไม่ให้อะไรดันหน้าให้กว้างเกินจอ */
}

/* เมนูสุดท้าย (เลือกภาษา) ให้ dropdown เปิดชิดขวา ไม่ล้นออกนอกจอ */
.site-navbar .site-navigation .site-menu > li.has-children:last-child > .dropdown {
  left: auto;
  right: 0;
}

/* --------------------------------------------------------------------------
   ข้อ 2: ปุ่ม ☰ บนมือถือ/แท็บเล็ต
   ไฟล์ bootstrap.min.css ที่ใช้ร่วมกันถูกแก้ให้ d-lg-* เริ่มที่ 100px
   (ทำให้เมนูเต็มแสดงทุกขนาดจอ และปุ่ม ☰ ถูกซ่อน)
   ที่นี่คืนค่าเฉพาะหน้าแรก: จอเล็กกว่า 992px ใช้ปุ่ม ☰
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
  .site-navbar .site-menu.main-menu.d-lg-block {
    display: none !important;
  }

  .site-navbar .toggle-button.d-lg-none {
    display: inline-block !important;
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
  }

  .site-navbar .toggle-button .site-menu-toggle {
    display: inline-block;
    padding: 8px !important;
    line-height: 1;
  }

  .site-navbar .site-logo {
    padding-right: 56px; /* เว้นที่ให้ปุ่ม ☰ */
  }

  /* เมนูสไลด์ด้านข้าง: ให้ไม่กว้างเกินจอมือถือเล็ก */
  .site-mobile-menu {
    width: min(300px, 85vw);
  }
}

/* --------------------------------------------------------------------------
   ข้อ 5: การ์ดข่าว หัวข้อ และ header บนมือถือ/แท็บเล็ต
   ปรับแค่ระยะห่างและขนาดตัวอักษร — ไม่เปลี่ยนลำดับหรือเนื้อหา
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
  /* header สูง 137px บนมือถือ กินพื้นที่จอมากตอนติดด้านบน */
  .site-navbar {
    padding-top: 20px !important;
    padding-bottom: 20px !important;
  }

  /* การ์ดเต็มความกว้างคอลัมน์ ไม่บีบ */
  #tour .thumbnail {
    max-width: 100%;
  }

  #tour .thumbnail img {
    max-width: 100%;
    height: auto;
  }

  /* แท็บเล็ต: หัวข้อข่าวเด่นอยู่ในคอลัมน์ครึ่งจอ ตัวใหญ่เกินไป */
  #tour h2 {
    font-size: 26px;
    line-height: 1.35;
  }
}

@media (max-width: 767.98px) {
  .site-navbar .site-logo a {
    font-size: 26px;
  }

  /* หัวข้อข่าวเด่นใหญ่เกินจอมือถือ (32px) */
  #tour h2 {
    font-size: 24px;
    line-height: 1.35;
  }

  #tour h3 {
    font-size: 22px;
  }

  /* footer: ข้อความยาวไม่ล้นจอ */
  footer {
    overflow-wrap: anywhere;
  }
}

/* --------------------------------------------------------------------------
   ข้อ 7: Animation
   - ใช้เฉพาะ transform / opacity (ลื่น ไม่กินเครื่อง)
   - ซ่อนการ์ดก่อนปรากฏ "เฉพาะเมื่อ JS ทำงาน" (html.home-anim) —
     ถ้า JS ไม่ทำงาน เนื้อหาแสดงตามปกติทั้งหมด
   - ผู้ใช้ที่ตั้งค่าลดการเคลื่อนไหว (prefers-reduced-motion) จะไม่เห็น animation
   -------------------------------------------------------------------------- */

/* 7.1 การ์ด/หัวข้อค่อยๆ ปรากฏเมื่อเลื่อนมาถึง */
html.home-anim .reveal {
  opacity: 0;
  transform: translateY(24px);
  transition:
    opacity 0.6s ease-out,
    transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: var(--reveal-delay, 0ms);
}

html.home-anim .reveal.is-visible {
  opacity: 1;
  transform: none;
}

/* 7.2 การ์ดลอยขึ้นเล็กน้อยเมื่อชี้เมาส์ (เฉพาะอุปกรณ์ที่มีเมาส์) */
@media (hover: hover) and (pointer: fine) {
  #tour .thumbnail {
    transition:
      border 0.2s ease-in-out,
      transform 0.5s cubic-bezier(0.22, 1, 0.36, 1),
      opacity 0.6s ease-out;
    transition-delay: 0ms, var(--reveal-delay, 0ms), var(--reveal-delay, 0ms);
  }

  html.home-anim #tour .thumbnail.reveal.is-visible:hover,
  html:not(.home-anim) #tour .thumbnail:hover {
    transform: translateY(-6px);
    transition-delay: 0ms;
  }

  /* 7.3 เมนูบน: เส้นใต้วิ่งออกจากกลางเมื่อชี้ */
  .site-navbar .site-menu.main-menu > li > a.nav-link {
    position: relative;
  }

  .site-navbar .site-menu.main-menu > li > a.nav-link::after {
    content: "";
    position: absolute;
    left: 10%;
    right: 10%;
    bottom: 4px;
    height: 2px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 0.25s ease-out;
  }

  .site-navbar .site-menu.main-menu > li:hover > a.nav-link::after,
  .site-navbar .site-menu.main-menu > li > a.nav-link:focus-visible::after {
    transform: scaleX(1);
  }
}

/* 7.4 เมนู dropdown เลื่อนลงนุ่มขึ้น (เดิมกระตุกเพราะ transition ทุก property) */
.site-navbar .site-navigation .site-menu .has-children .dropdown {
  transition:
    opacity 0.2s ease-out,
    margin-top 0.2s ease-out,
    visibility 0.2s;
}

/* 7.5 header มีเงาบางๆ เมื่อเลื่อนหน้าแล้ว header ติดด้านบน */
.sticky-wrapper .site-navbar {
  transition: box-shadow 0.3s ease;
}

.sticky-wrapper.is-sticky .site-navbar {
  box-shadow: 0 4px 16px -8px rgba(0, 0, 0, 0.25);
}

/* 7.6 เมนูมือถือ: พื้นหลังจางลงเมื่อเปิดเมนู */
@media (max-width: 991.98px) {
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1999; /* ใต้เมนู (z-index 2000) */
  }

  body.offcanvas-menu::after {
    opacity: 1;
  }
}

/* ปิด animation ทั้งหมดสำหรับผู้ใช้ที่ตั้งค่าลดการเคลื่อนไหว */
@media (prefers-reduced-motion: reduce) {
  html.home-anim .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }

  #tour .thumbnail,
  .site-navbar .site-menu.main-menu > li > a.nav-link::after,
  .site-navbar .site-navigation .site-menu .has-children .dropdown,
  body::after {
    transition: none !important;
  }

  #tour .thumbnail:hover {
    transform: none !important;
  }
}

/* --------------------------------------------------------------------------
   การ์ดสูงเท่ากันในแถวเดียวกัน + ปุ่ม "อ่านข้อมูลเพิ่มเติม" ชิดล่าง
   - ใช้เฉพาะแถวที่เป็นการ์ดล้วน (ไม่รวมแถวข่าวเด่นที่มีหัวข้อใหญ่ h2)
   - ไม่ตัด/ยืด/ครอปรูป รูปแสดงขนาดเดิม
   -------------------------------------------------------------------------- */
@media (min-width: 576px) {
  #tour .row:not(:has(h2)) > [class*="col-"]:has(> .thumbnail) {
    display: flex;
    flex-direction: column;
  }

  #tour .row:not(:has(h2)) > [class*="col-"] > .thumbnail {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
  }

  /* เส้นคั่นและปุ่มถูกดันไปอยู่ล่างสุดของการ์ด ให้ปุ่มทุกใบอยู่ระดับเดียวกัน */
  #tour .row:not(:has(h2)) > [class*="col-"] > .thumbnail > hr {
    margin-top: auto;
    width: 100%;
  }

  #tour .row:not(:has(h2)) > [class*="col-"] > .thumbnail > .btn {
    align-self: center;
  }

  /* ข้อความที่อยู่ในการ์ดโดยตรง (ไม่มีแท็กครอบ) ยังจัดกลางเหมือนเดิม */
  #tour .row:not(:has(h2)) > [class*="col-"] > .thumbnail > * {
    max-width: 100%;
  }
}

/* จอ 576–767px: เดิมการ์ดเรียงแถวละ 4 ใบ กว้างแค่ ~100px
   ปรับเป็นแถวละ 2 ใบ (แถวข่าวเด่นเต็มความกว้าง) */
@media (min-width: 576px) and (max-width: 767.98px) {
  #tour .row:not(:has(h2)) > .col-sm-3 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  #tour .row:has(h2) > [class*="col-sm-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* การ์ดที่มีข้อความวางตรงในการ์ด (strong <br> ข้อความ <br> ข้อความ)
   ในโหมดการ์ดเท่ากัน ข้อความแต่ละช่วงขึ้นบรรทัดใหม่เองอยู่แล้ว
   <br> จึงกลายเป็นช่องว่างเกิน — ซ่อนเฉพาะ <br> ชุดนี้ */
@media (min-width: 576px) {
  #tour .row:not(:has(h2)) > [class*="col-"] > .thumbnail > strong + br {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   ล็อกความสูงแบนเนอร์สไลด์ — แก้ปัญหาหน้าขยับ/เลื่อนเองตอนสไลด์เปลี่ยนภาพ
   สาเหตุ: รูปแบนเนอร์สัดส่วนไม่เท่ากัน (0.361 กับ 0.291) ความสูงจึงเปลี่ยน
   ทุกครั้งที่เปลี่ยนภาพ และไม่มีการจองพื้นที่ก่อนรูปโหลดเสร็จ
   - รูปไม่ถูกตัด/ยืด (object-fit: contain) รูปที่เตี้ยกว่าจะมีแถบว่างบน-ล่าง
   - หน้าไทย: ล็อกที่สัดส่วนแบนเนอร์ไว้อาลัย (2654×958)
     ⚠️ เมื่อเอาแบนเนอร์ไว้อาลัยออกแล้ว ให้เปลี่ยนค่าหน้าไทยเป็น 2553 / 742
   - หน้าอังกฤษ: ทุกรูปเป็น 2553×742 อยู่แล้ว ล็อกเพื่อจองพื้นที่ก่อนรูปโหลด
   -------------------------------------------------------------------------- */
#demo {
  --banner-ratio: 2553 / 742;
  position: relative;
}

html[lang="th"] #demo {
  --banner-ratio: 2654 / 958;
}

#demo .carousel-item {
  aspect-ratio: var(--banner-ratio);
}

#demo .carousel-item > a {
  display: block;
  height: 100%;
}

#demo .carousel-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* หน้าอังกฤษแบ่งสไลด์ไว้หลายชุด (.carousel-inner หลายกล่อง)
   ตอนเปลี่ยนภาพข้ามชุด ภาพใหม่ไปต่อท้ายด้านล่าง ทำให้แบนเนอร์สูงขึ้นชั่วขณะ
   (วัดได้ 405 → 777px) — ให้ชุดที่ไม่ได้แสดงอยู่วางซ้อนทับตำแหน่งเดิมแทน */
#demo > .carousel-inner:not(:has(> .carousel-item.active)) {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}

/* --------------------------------------------------------------------------
   ปุ่มเลื่อนสไลด์ ซ้าย/ขวา — เปลี่ยนเฉพาะดีไซน์เป็นปุ่มกลม
   ตำแหน่งคงเดิม: ใต้แบนเนอร์ มุมซ้าย เรียงคู่กัน (ซ้าย-ขวา)
   (เดิมเป็นปุ่มเทาสี่เหลี่ยมค่าเริ่มต้นของเบราว์เซอร์)
   -------------------------------------------------------------------------- */
#demo .carousel-control-prev,
#demo .carousel-control-next {
  position: static !important; /* อยู่ในตำแหน่งเดิม ไม่ลอยทับแบนเนอร์ */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: top;
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 6px 0 0 6px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  backdrop-filter: blur(10px) saturate(140%);
  box-shadow:
    0 4px 14px -6px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  opacity: 1;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    background-color 0.2s ease,
    box-shadow 0.2s ease;
}

/* ไอคอนลูกศรสีเข้ม เส้นบาง */
#demo .carousel-control-prev-icon,
#demo .carousel-control-next-icon {
  width: 16px;
  height: 16px;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  filter: none;
}

#demo .carousel-control-prev-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f2328' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M15 5l-7 7 7 7'/%3e%3c/svg%3e");
}

#demo .carousel-control-next-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f2328' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M9 5l7 7-7 7'/%3e%3c/svg%3e");
}

#demo .carousel-control-prev:hover,
#demo .carousel-control-next:hover {
  background: #fff;
  transform: scale(1.08);
  box-shadow:
    0 6px 18px -6px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

#demo .carousel-control-prev:active,
#demo .carousel-control-next:active {
  transform: scale(0.95);
}

#demo .carousel-control-prev:focus,
#demo .carousel-control-next:focus {
  outline: none;
}

#demo .carousel-control-prev:focus-visible,
#demo .carousel-control-next:focus-visible {
  outline: 2px solid #0093b2;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  #demo .carousel-control-prev,
  #demo .carousel-control-next {
    transition: none;
  }
}

/* --------------------------------------------------------------------------
   ประกาศเด่น (featured-notice) — ใช้กับแถวประกาศสำคัญบนหน้าแรก TH/EN
   ใส่ class "featured-notice" ที่ .row และ <span class="featured-badge"> ไว้ในแถว
   - กรอบสีส้ม + ป้าย "ประกาศสำคัญ" มุมซ้ายบน + ปุ่มในการ์ดเป็นสีส้ม
   - เลิกเน้นเมื่อหมดช่วงประกาศ: ลบ class featured-notice และ span ป้ายออก
   -------------------------------------------------------------------------- */
.featured-notice {
  position: relative;
  margin: 28px 0 40px;
  padding: 28px 12px 16px;
  border: 2px solid #f26a21;
  border-radius: 16px;
}

.featured-notice > .featured-badge {
  position: absolute;
  top: -14px;
  left: 24px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 14px;
  border-radius: 999px;
  background: #f26a21;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  z-index: 1;
}

.featured-notice > .featured-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.85;
}

/* ปุ่มสีส้ม: ให้ลิงก์ด้านในเป็นตัวปุ่ม เพื่อให้กดได้ทั้งพื้นที่ */
.featured-notice .thumbnail .btn {
  display: block;
  width: calc(100% - 20px);
  margin: 0 auto 10px;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}

.featured-notice .thumbnail .btn > a {
  display: block;
  padding: 11px 16px;
  border-radius: 8px;
  background: #f26a21;
  color: #fff !important;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.featured-notice .thumbnail .btn > a::after {
  content: " \2192";
}

.featured-notice .thumbnail .btn > a:hover,
.featured-notice .thumbnail .btn > a:focus-visible {
  background: #d9560f;
}

/* ปุ่มขึ้นบรรทัดใหม่ได้ถ้าการ์ดแคบ (Bootstrap ตั้ง .btn เป็น nowrap) */
.featured-notice .thumbnail .btn {
  white-space: normal;
}

/* จอ 576–767px: คอลัมน์ col-sm-3 / col-sm-7 แคบเกินไป (การ์ดเหลือ ~110px)
   ให้การ์ดและข้อความเรียงลงมาเต็มความกว้าง การ์ดกว้างไม่เกิน 360px อยู่กลาง
   (หน้าอังกฤษไม่ได้อยู่ใน #tour จึงไม่โดนกฎแถวข่าวเด่นด้านบน) */
@media (max-width: 767.98px) {
  .featured-notice > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .featured-notice > [class*="col-"] > .thumbnail {
    max-width: 360px;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 575.98px) {
  .featured-notice {
    margin: 24px 4px 32px;
    padding: 26px 4px 12px;
  }

  .featured-notice > .featured-badge {
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
  }
}

/* --------------------------------------------------------------------------
   เงาการ์ดข่าว — ลดลง 2 ระดับ (เฉพาะหน้าแรก TH/EN)
   เดิม (css/app.css .thumbnail): 0 30px 50px rgba(0,0,0,.24) เข้มและฟุ้งมาก
   ระดับ 1: 0 20px 36px rgba(0,0,0,.16)
   ระดับ 2 (ใช้อยู่): 0 12px 24px rgba(0,0,0,.10)
   ถ้าอยากเข้มขึ้นหนึ่งระดับ ให้เปลี่ยนเป็นค่าระดับ 1
   -------------------------------------------------------------------------- */
#tour .thumbnail,
.featured-notice .thumbnail {
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.10);
}

/* --------------------------------------------------------------------------
   ระยะห่างรอบหัวข้อส่วนข่าว ("ข่าวสารจากสำนักคอมพิวเตอร์", "ข่าวสารกิจกรรม", "Announcement")
   - เหนือหัวข้อ: กรอบประกาศเด่นเว้นด้านล่าง 40px (รวม ~64px บนคอม / ~56px บนมือถือ)
   - ใต้หัวข้อ: เพิ่มจาก 8px เป็น 20px ก่อนถึงการ์ดแถวแรก
   -------------------------------------------------------------------------- */
#tour > .container > h3.text-center {
  margin-bottom: 20px;
}
