/* ==========================================================================
   THE STANDARD GLOBAL — Header
   ใช้ฟอนต์จาก :root ของเว็บ (--fontBody / --fontHeadline)
   ========================================================================== */

:root {
  --global-red: #E31E24;
  --global-ink: #000;
  --global-paper: #fff;
  --global-soft: #f4f4f4;
  --global-rule-soft: #e3e3e3;
  --global-ease: cubic-bezier(.22, .61, .36, 1);
  --global-speed: .3s;

  /* JS วัดค่าจริงแล้ว override ให้ — ค่านี้เป็น fallback ก่อน JS ทำงาน */
  --global-header-h: 210px;      /* ความสูง header ปกติ (ใช้กับ spacer) */
  --global-header-offset: 84px;  /* ความสูงตอน shrink (ใช้ offset ตอน scroll ไป section) */
  --global-sbw: 0px;             /* scrollbar width ตอนล็อก scroll */
}

@media (max-width: 768px) {
  :root {
    --global-header-h: 140px;
    --global-header-offset: 100px;
  }
}

html {
  scroll-padding-top: var(--global-header-offset);
}

html.global-is-locked,
html.global-is-locked body {
  overflow: hidden;
}

html.global-is-locked body {
  padding-right: var(--global-sbw);
}

.global-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Header shell
   -------------------------------------------------------------------------- */

.global-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--global-paper);
  color: var(--global-ink);
  font-family: var(--fontBody);
  transition: box-shadow var(--global-speed) var(--global-ease);
  border-bottom: 1px solid #ddd;
}

html.global-is-locked .global-header {
  padding-right: var(--global-sbw);
}

.admin-bar .global-header {
  top: var(--wp-admin--admin-bar--height, 32px);
}

@media (max-width: 600px) {
  .admin-bar .global-header { top: 0; }
}

/* style.css เดิมเผื่อ padding ให้ .gtco-nav ตัวเก่า — header ใหม่ใช้ spacer แทน */
body.admin-bar #page {
  padding-top: 0;
}

.global-header *,
.global-header *::before,
.global-header *::after {
  box-sizing: border-box;
}

.global-header.is-shrink {
  box-shadow: 0 1px 0 rgba(0, 0, 0, .08), 0 6px 18px rgba(0, 0, 0, .06);
}

/* ใช้ตอน JS วัดความสูง — ปิด transition ชั่วคราว */
.global-header.is-measuring,
.global-header.is-measuring * {
  transition: none !important;
}

.global-header-spacer {
  height: var(--global-header-h);
}

/* Desktop grid
   ┌──────────────┬────────┬──────────────┐
   │ search       │        │   SUBSCRIBE  │
   ├──────────────┤  LOGO  ├──────────────┤
   │ menu (left)  │        │ menu (right) │
   └──────────────┴────────┴──────────────┘ */
.global-header__inner {
  /*max-width: 1140px;*/
  margin: 0 auto;
  padding: 20px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "tools logo cta"
    "menuL logo menuR";
  column-gap: clamp(28px, 4.5vw, 64px);
  row-gap: 20px;
  align-items: center;
  transition: padding var(--global-speed) var(--global-ease);
}

.global-header__tools {
  grid-area: tools;
  align-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
}

.global-header__logo {
  grid-area: logo;
  line-height: 0;
}

.global-header__cta {
  grid-area: cta;
  align-self: end;
  justify-self: end;
}

/* Focus ring */
.global-header a:focus-visible,
.global-header button:focus-visible,
.global-drawer a:focus-visible,
.global-drawer button:focus-visible,
.global-search a:focus-visible,
.global-search button:focus-visible {
  outline: 2px solid var(--global-red);
  outline-offset: 3px;
}

/* --------------------------------------------------------------------------
   Icon buttons (hamburger / search)
   -------------------------------------------------------------------------- */

.global-header__icon-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  transition: color .2s;
}

.global-header__icon-btn:hover {
  color: var(--global-red);
}

.global-header__icon-btn svg {
  width: 36px;
  height: 36px;
  transition: width var(--global-speed) var(--global-ease), height var(--global-speed) var(--global-ease);
}

.global-header__toggle {
  display: none; /* desktop ไม่มี hamburger */
}

.global-burger {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 28px;
  height: 20px;
}

.global-burger span {
  display: block;
  height: 1.5px;
  background: currentColor;
}

/* --------------------------------------------------------------------------
   Logo
   -------------------------------------------------------------------------- */

.global-logo {
  display: block;
}

.global-logo img {
  display: block;
  width: clamp(145px, 12vw, 175px);
  max-width: 100%;
  height: auto;
  transition: width var(--global-speed) var(--global-ease);
}

/* --------------------------------------------------------------------------
   Subscribe
   -------------------------------------------------------------------------- */

.global-header__subscribe,
.global-header__subscribe:visited,
.global-header__subscribe:focus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  border-radius: 10px;
  background: var(--global-ink);
  color: var(--global-paper);
  font-family: var(--fontBody);
  font-size: 16px;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition:
    background-color .2s,
    padding var(--global-speed) var(--global-ease),
    font-size var(--global-speed) var(--global-ease);
}

.global-header__subscribe:hover,
.global-header__subscribe:focus-visible {
  background: var(--global-red);
  color: var(--global-paper);
  text-decoration: none;
}

/* --------------------------------------------------------------------------
   Menubar (row 2)
   -------------------------------------------------------------------------- */

/* desktop: wrapper หายไปจาก layout ให้ <ul> ทั้งสองไปวางใน grid เอง */
.global-menubar {
  display: contents;
}

.global-menu {
  display: flex;
  align-items: stretch;
  min-width: 0;
  margin: 0;
  padding: 12px 0;
  list-style: none;
  border-top: 1px solid var(--global-ink);
  border-bottom: 1px solid var(--global-ink);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  transition: padding var(--global-speed) var(--global-ease), border-color var(--global-speed);
}

.global-menu::-webkit-scrollbar {
  display: none;
}

.global-menu--left  { grid-area: menuL; }
.global-menu--right { grid-area: menuR; }

.global-menu__item {
  position: relative;
  flex: 1 0 auto;            /* กระจายเต็มแถบ แต่ไม่บีบ → ล้นแล้ว scroll */
  display: flex;
  justify-content: center;
  margin: 0;
  padding: 0;
}

/* เส้นคั่นแนวตั้ง */
.global-menu__item + .global-menu__item::before {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  width: 1px;
  background: var(--global-ink);
}

.global-menu__link,
.global-menu__link:visited,
.global-menu__link:focus {
  display: inline-flex;
  align-items: center;
  padding: 5px clamp(5px, 0.25vw, 15px);
  color: var(--global-ink);
  font-family: var(--fontBody);
  font-size: clamp(15px, 1.25vw, 20px);
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  transition: color .2s, font-size var(--global-speed) var(--global-ease), padding var(--global-speed) var(--global-ease);
}

.global-menu__link:focus-visible {
  outline-offset: -2px;
}

.global-menu__text,
.global-drawer__text {
  position: relative;
  padding: 0;
}

/* เส้นใต้ active */
.global-menu__text::after,
.global-drawer__text::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transition: transform .25s var(--global-ease);
}

.global-menu__link:hover,
.global-menu__link:focus-visible,
.global-menu__link.is-active {
  color: var(--global-red);
  text-decoration: none;
}

.global-menu__link.is-active .global-menu__text::after {
  transform: scaleX(1);
}

/* --------------------------------------------------------------------------
   Desktop — shrink (แถวเดียว: search | menuL | logo | menuR | subscribe)
   -------------------------------------------------------------------------- */

@media (min-width: 769px) {
  .global-header.is-shrink .global-header__inner {
    padding-top: 10px;
    padding-bottom: 10px;
    grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr) auto;
    grid-template-rows: auto;
    grid-template-areas: "tools menuL logo menuR cta";
    column-gap: 24px;
  }

  .global-header.is-shrink .global-header__tools,
  .global-header.is-shrink .global-header__cta {
    align-self: center;
  }

  .global-header.is-shrink .global-logo img {
    width: 120px;
  }

  .global-header.is-shrink .global-header__icon-btn svg {
    width: 28px;
    height: 28px;
  }

  .global-header.is-shrink .global-menu {
    padding: 4px 0;
    border-color: transparent;
  }

  .global-header.is-shrink .global-menu__link {
    font-size: clamp(14px, 1.15vw, 17px);
    padding-left: clamp(10px, 0.85vw, 16px);
    padding-right: clamp(10px, 0.85vw, 16px);
  }

  .global-header.is-shrink .global-header__subscribe {
    padding: 10px 16px;
    font-size: 15px;
    border-radius: 8px;
  }
}

/* --------------------------------------------------------------------------
   Mobile ≤ 768px
   ┌──────────┬──────┬───────────┐
   │ ☰  🔍    │ LOGO │ SUBSCRIBE │
   ├──────────┴──────┴───────────┤
   │ HOME | OP-ED | ECONOMICS …  │  ← slide
   └─────────────────────────────┘
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {

  body.admin-bar .global-header-spacer {
    height: 69px;
  }

  .global-header__inner {
    padding: 14px 0 10px;
    grid-template-rows: auto auto;
    grid-template-areas:
      "tools logo cta"
      "menu  menu menu";
    column-gap: 8px;
    row-gap: 14px;
  }

  .global-header__tools {
    align-self: center;
    gap: 6px;
  }

  .global-header__cta {
    align-self: center;
  }

  .global-header__toggle {
    display: inline-flex;
  }

  .global-header__icon-btn {
    width: 36px;
    height: 36px;
  }

  .global-header__icon-btn svg {
    width: 28px;
    height: 28px;
  }

  .global-burger {
    width: 26px;
    height: 17px;
  }

  .global-logo img {
    width: clamp(108px, 32vw, 170px);
  }

  .global-header__subscribe,
  .global-header__subscribe:visited,
  .global-header__subscribe:focus {
    padding: 10px 12px;
    font-size: 12px;
    border-radius: 8px;
  }


  /* menubar กลายเป็นแถบ scroll เดียว รวม 2 <ul> ต่อกัน */
  .global-menubar {
    grid-area: menu;
    display: flex;
    min-width: 0;
    border-top: 1px solid var(--global-ink);
    border-bottom: 1px solid var(--global-ink);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .global-menubar::-webkit-scrollbar {
    display: none;
  }

  /* fade ขาว + ลูกศร ขอบขวา (sticky ติดขอบ scrollport) */
  .global-menubar::after {
    content: "";
    position: sticky;
    right: 0;
    flex: 0 0 56px;
    margin-left: -56px;            /* ซ้อนทับเนื้อหา ไม่กินพื้นที่ */
    align-self: stretch;
    pointer-events: none;          /* แตะทะลุไปโดนลิงก์ข้างใต้ได้ */
    background:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6l6 6-6 6'/%3E%3C/svg%3E")
        right 2px center / 18px 18px no-repeat,
      linear-gradient(to right, rgba(255, 255, 255, 0) 0%, var(--global-paper) 65%);
    transition: opacity .2s var(--global-ease);
  }

  /* เผื่อที่ท้ายเมนู ให้เมนูสุดท้ายไม่ถูกบังตอนเลื่อนสุด */
  .global-menu--right {
    padding-right: 24px;
  }

  /* เลื่อนสุดแล้ว / เมนูไม่ล้น → ซ่อน */
  .global-menubar.is-end::after {
    opacity: 0;
  }

  .global-menu {
    flex: 1 0 auto;
    padding: 8px 0;
    border: 0;
    overflow: visible;
  }

  /* เส้นคั่นระหว่าง ul ซ้ายกับขวา */
  .global-menu--right > .global-menu__item:first-child::before {
    content: "";
    position: absolute;
    top: 2px;
    bottom: 2px;
    left: 0;
    width: 1px;
    background: var(--global-ink);
  }

  .global-menu__link,
  .global-menu__link:visited {
    padding: 0px 10px;
    font-size: 14px;
  }

  /* shrink */
  .global-header.is-shrink .global-header__inner {
    padding-top: 8px;
    padding-bottom: 6px;
    row-gap: 8px;
  }

  .global-header.is-shrink .global-logo img {
    width: 92px;
  }

  .global-header.is-shrink .global-header__icon-btn svg {
    width: 24px;
    height: 24px;
  }

  .global-header.is-shrink .global-header__subscribe {
    padding: 8px 10px;
    font-size: 12px;
  }

  .global-header.is-shrink .global-menu {
    padding: 4px 0;
  }
}

/* --------------------------------------------------------------------------
   Compact mode (.global-header--compact) เช่นหน้า newsletters
   ไม่มีแถบเมนูแถวสอง → แถวเดียว: ☰ 🔍 | LOGO | SUBSCRIBE ทุกขนาดจอ
   (วางหลัง desktop/mobile/shrink เพื่อให้ override ได้)
   -------------------------------------------------------------------------- */

.global-header--compact .global-header__inner,
.global-header--compact.is-shrink .global-header__inner {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto;
  grid-template-areas: "tools logo cta";
}

.global-header--compact .global-header__tools,
.global-header--compact .global-header__cta {
  align-self: center;
}

.global-header--compact .global-header__toggle {
  display: inline-flex;
}

/* --------------------------------------------------------------------------
   Drawer (hamburger)
   -------------------------------------------------------------------------- */

.global-drawer {
  position: fixed;
  inset: 0;
  z-index: 1100;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear .35s;
}

.global-drawer.is-open {
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.global-drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  opacity: 0;
  transition: opacity .35s var(--global-ease);
}

.global-drawer.is-open .global-drawer__backdrop {
  opacity: 1;
}

.global-drawer__panel {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(86vw, 380px);
  display: flex;
  flex-direction: column;
  padding: 14px 24px 32px;
  background: var(--global-paper);
  color: var(--global-ink);
  font-family: var(--fontBody);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateX(-100%);
  transition: transform .35s var(--global-ease);
}

.global-drawer.is-open .global-drawer__panel {
  transform: translateX(0);
}

.global-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--global-ink);
}

.global-drawer__logo img {
  display: block;
  width: 100px;
  height: auto;
}

.global-drawer__close,
.global-search__close {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--global-ink);
  cursor: pointer;
  transition: color .2s;
}

.global-drawer__close svg,
.global-search__close svg {
  width: 26px;
  height: 26px;
}

.global-drawer__close:hover,
.global-search__close:hover {
  color: var(--global-red);
}

.global-drawer__menu {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.global-drawer__item {
  margin: 0;
  border-bottom: 1px solid var(--global-rule-soft);
}

.global-drawer__link,
.global-drawer__link:visited,
.global-drawer__link:focus {
  display: flex;
  align-items: center;
  padding: 16px 0;
  color: var(--global-ink);
  font-size: 19px;
  line-height: 1.2;
  text-decoration: none;
  transition: color .2s;
}

.global-drawer__text {
  padding: 0;
}

.global-drawer__link:hover,
.global-drawer__link:focus-visible,
.global-drawer__link.is-active {
  color: var(--global-red);
  text-decoration: none;
}

.global-drawer__link.is-active .global-drawer__text::after {
  transform: scaleX(1);
}

@media (max-width: 768px) {
  .global-drawer__link,
  .global-drawer__link:visited,
  .global-drawer__link:focus {
    font-size: 16px;
  }
}

/* --------------------------------------------------------------------------
   Search overlay
   -------------------------------------------------------------------------- */

.global-search {
  position: fixed;
  inset: 0;
  z-index: 1200;
  overflow-y: auto;
  background: rgba(255, 255, 255, .98);
  color: var(--global-ink);
  font-family: var(--fontBody);
  visibility: hidden;
  opacity: 0;
  transition: opacity .25s var(--global-ease), visibility 0s linear .25s;
}

.global-search.is-open {
  visibility: visible;
  opacity: 1;
  transition-delay: 0s;
}

.global-search__close {
  position: fixed;
  top: 18px;
  right: 18px;
}

.global-search__inner {
  max-width: 880px;
  margin: 0 auto;
  padding: clamp(72px, 12vh, 140px) 24px 48px;
}

.global-search__field {
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 2px solid var(--global-ink);
  transition: border-color .2s;
}

.global-search__field:focus-within {
  border-color: var(--global-red);
}

.global-search__icon {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
}

.global-search__input {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: var(--global-ink);
  font-family: var(--fontHeadline);
  font-size: clamp(24px, 4vw, 40px);
  line-height: 1.2;
  appearance: none;
  box-shadow: none;
}

.global-search__input::placeholder {
  color: #9a9a9a;
}

.global-search__input::-webkit-search-cancel-button {
  appearance: none;
}

.global-search__status {
  min-height: 1.5em;
  margin: 14px 0 0;
  color: #666;
  font-size: 15px;
}

.global-search__list {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.global-search__item {
  margin: 0;
}

.global-search__item + .global-search__item {
  border-top: 1px solid var(--global-rule-soft);
}

.global-search__link,
.global-search__link:visited,
.global-search__link:focus {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 12px;
  color: var(--global-ink);
  text-decoration: none;
  transition: background-color .15s;
}

.global-search__item.is-active .global-search__link {
  background: var(--global-soft);
}

.global-search__item.is-active .global-search__title {
  color: var(--global-red);
}

.global-search__thumb {
  flex: 0 0 112px;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: var(--global-soft);
}

.global-search__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.global-search__meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.global-search__cat {
  color: var(--global-red);
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.global-search__title {
  display: -webkit-box;
  overflow: hidden;
  font-family: var(--fontHeadline);
  font-size: 19px;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  transition: color .15s;
}

.global-search__all,
.global-search__all:visited,
.global-search__all:focus {
  display: inline-block;
  margin-top: 20px;
  border-bottom: 1px solid currentColor;
  color: var(--global-ink);
  font-size: 15px;
  text-decoration: none;
}

.global-search__all:hover {
  color: var(--global-red);
}

.global-search__all[hidden] {
  display: none;
}

@media (max-width: 768px) {
  .global-search__inner {
    padding: 72px 20px 40px;
  }

  .global-search__thumb {
    flex-basis: 84px;
  }

  .global-search__title {
    font-size: 16px;
  }

  .global-search__link {
    padding: 12px 4px;
    gap: 12px;
  }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .global-header,
  .global-header *,
  .global-drawer,
  .global-drawer *,
  .global-search,
  .global-search * {
    transition-duration: .01ms !important;
  }
}
