/*
  ANANFX Academy — Global Mobile Drawer
  ใช้ร่วมกันทุกหน้าที่มีปุ่ม [data-open-drawer]
  Drawer ถูกสร้างด้วย JavaScript เฉพาะ viewport ไม่เกิน 767px และถูกถอดออกจาก DOM ตั้งแต่ 768px ขึ้นไป
*/

@media (max-width: 767px) {
  :root {
    --ananfx-yellow: #ffde02;
    --ananfx-yellow-hover: #f2d300;
    --ananfx-yellow-pressed: #e5c700;
    --ananfx-yellow-soft: #fff8cc;
    --ananfx-text-primary: #141d22;
    --ananfx-text-black: #000000;
    --ananfx-text-secondary: #72777a;
    --ananfx-background: #ffffff;
    --ananfx-surface: #f3f5f6;
    --ananfx-border: #e2e3e4;
    --ananfx-overlay: rgba(0, 0, 0, 0.40);
    --ananfx-mobile-menu-icon: #728393;
    --ananfx-mobile-icon: var(--ananfx-mobile-menu-icon);
    --ananfx-primary: var(--ananfx-yellow);
    --ananfx-primary-hover: var(--ananfx-yellow-hover);
    --ananfx-primary-pressed: var(--ananfx-yellow-pressed);
    --ananfx-primary-soft: var(--ananfx-yellow-soft);
  }
  html body[data-page-key] button[data-open-drawer] {
    min-width: 44px;
    min-height: 44px;
    box-sizing: border-box;
  }

  .auth-mobile-drawer-trigger {
    position: absolute;
    top: calc(24px + env(safe-area-inset-top));
    left: max(4px, env(safe-area-inset-left));
    z-index: 2;
    display: grid;
    width: 44px;
    height: 44px;
    padding: 8px;
    place-items: center;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--ananfx-mobile-menu-icon);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .auth-mobile-drawer-trigger img {
    display: block;
    width: 28px;
    height: 28px;
    object-fit: contain;
  }

  .auth-mobile-drawer-trigger:focus-visible {
    outline: 3px solid rgba(255, 222, 2, 0.58);
    outline-offset: 2px;
  }

  .ananfx-mobile-drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 980;
    border: 0;
    padding: 0;
    background: var(--ananfx-overlay);
    opacity: 0;
    visibility: hidden;
    cursor: default;
    transition: opacity 180ms ease, visibility 0s linear 180ms;
    -webkit-tap-highlight-color: transparent;
  }

  .ananfx-mobile-drawer-overlay.is-visible {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
  }

  .ananfx-mobile-drawer {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 990;
    display: flex;
    width: min(90vw, 420px);
    max-width: calc(100vw - 36px);
    height: 100vh;
    height: 100svh;
    max-height: 100svh;
    flex-direction: column;
    overflow: hidden;
    background: var(--ananfx-background);
    color: var(--ananfx-text-primary);
    box-shadow: 22px 0 60px rgba(5, 5, 5, 0.16);
    transform: translate3d(-104%, 0, 0);
    transition: transform 230ms cubic-bezier(0.2, 0.78, 0.22, 1);
    contain: layout paint;
  }

  .ananfx-mobile-drawer.is-open {
    transform: translate3d(0, 0, 0);

  }

  .ananfx-mobile-drawer__header {
    display: flex;
    min-height: calc(104px + env(safe-area-inset-top));
    padding:
      calc(20px + env(safe-area-inset-top))
      clamp(18px, 5vw, 28px)
      18px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex: 0 0 auto;
    border-bottom: 1px solid var(--ananfx-border);
    background: var(--ananfx-background);
  }

  .ananfx-mobile-drawer__brand {
    display: block;
    width: clamp(166px, 51vw, 214px);
    max-width: calc(100% - 68px);
    line-height: 0;
  }

  .ananfx-mobile-drawer__brand img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
  }

  .ananfx-mobile-drawer__close {
    display: grid;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    padding: 0;
    place-items: center;
    border: 1px solid var(--ananfx-border);
    border-radius: 14px;
    background: var(--ananfx-background);
    color: var(--ananfx-text-primary);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .ananfx-mobile-drawer__close svg,
  .ananfx-mobile-drawer__chevron {
    display: block;
    width: 24px;
    height: 24px;
    flex: 0 0 auto;
  }

  .ananfx-mobile-drawer__close:active {
    background: var(--ananfx-surface);
    transform: scale(0.98);
  }

  .ananfx-mobile-drawer__scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .ananfx-mobile-drawer.is-open .ananfx-mobile-drawer__scroll {
    overflow-y: auto;
  }

  .ananfx-mobile-drawer__nav {
    padding: 16px clamp(18px, 5vw, 28px) 0;
  }

  .ananfx-mobile-drawer__direct,
  .ananfx-mobile-drawer__group-toggle,
  .ananfx-mobile-drawer__sub-link {
    position: relative;
    display: flex;
    width: 100%;
    align-items: center;
    border: 0;
    background: transparent;
    color: var(--ananfx-text-primary);
    font-family: inherit;
    text-decoration: none;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .ananfx-mobile-drawer__direct {
    min-height: 62px;
    padding: 13px 14px 13px 20px;
    font-size:var(--anan-type-control);
    font-weight: 700;
    line-height: 1.45;
    letter-spacing: -0.02em;
  }

  .ananfx-mobile-drawer__direct::before,
  .ananfx-mobile-drawer__sub-link::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    width: 3px;
    height: 30px;
    border-radius: 999px;
    background: var(--ananfx-yellow);
    opacity: 0;
    transform: translateY(-50%) scaleY(0.35);
    transition: opacity 150ms ease, transform 150ms ease;
  }

  .ananfx-mobile-drawer__direct.is-active,
  .ananfx-mobile-drawer__sub-link.is-active {
    color: var(--ananfx-text-primary);
    font-weight: 700;
  }

  .ananfx-mobile-drawer__direct.is-active::before,
  .ananfx-mobile-drawer__sub-link.is-active::before {
    opacity: 1;
    transform: translateY(-50%) scaleY(1);
  }

  .ananfx-mobile-drawer__divider {
    height: 1px;
    margin: 3px 0;
    background: var(--ananfx-border);
  }

  .ananfx-mobile-drawer__group {
    border-bottom: 1px solid var(--ananfx-border);
  }

  .ananfx-mobile-drawer__group-toggle {
    min-height: 66px;
    padding: 14px 14px 14px 14px;
    justify-content: space-between;
    gap: 16px;
    font-size:var(--anan-type-control);
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: -0.02em;
  }

  .ananfx-mobile-drawer__group-toggle.has-active-child {
    color: var(--ananfx-text-primary);
  }

  .ananfx-mobile-drawer__chevron {
    width: 21px;
    height: 21px;
    transition: transform 180ms ease;
  }

  .ananfx-mobile-drawer__group-toggle[aria-expanded="true"] .ananfx-mobile-drawer__chevron {
    transform: rotate(180deg);
  }

  .ananfx-mobile-drawer__submenu-wrap {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 200ms ease;
  }

  .ananfx-mobile-drawer__submenu-wrap.is-open {
    grid-template-rows: 1fr;
  }

  .ananfx-mobile-drawer__submenu {
    min-height: 0;
    overflow: hidden;
  }

  .ananfx-mobile-drawer__submenu-inner {
    display: grid;
    padding: 0 4px 14px 34px;
  }

  .ananfx-mobile-drawer__sub-link {
    min-height: 44px;
    padding: 8px 10px 8px 14px;
    font-size:var(--anan-type-secondary);
    font-weight: 400;
    line-height: 1.45;
  }

  .ananfx-mobile-drawer__sub-link::before {
    left: -2px;
    width: 2px;
    height: 22px;
  }

  .ananfx-mobile-drawer__account {
    display: grid;
    gap: 12px;
    padding:
      24px
      clamp(18px, 5vw, 28px)
      calc(24px + env(safe-area-inset-bottom));
  }

  .ananfx-mobile-drawer__account-button {
    display: flex;
    width: 100%;
    min-height: 52px;
    padding: 12px 18px;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size:var(--anan-type-control);
    font-weight: 700;
    line-height: 1.35;
    text-decoration: none;
    cursor: pointer;
  }

  .ananfx-mobile-drawer__account-button--outline {
    border: 1.5px solid var(--ananfx-yellow);
    background: var(--ananfx-background);
    color: var(--ananfx-text-primary);
  }

  .ananfx-mobile-drawer__account-button--gold {
    border: 1.5px solid var(--ananfx-yellow);
    background: var(--ananfx-yellow);
    color: var(--ananfx-text-primary);
  }

  .ananfx-mobile-drawer__account-button--outline:active {
    background: var(--ananfx-yellow-soft);
  }

  .ananfx-mobile-drawer__account-button--gold:active {
    border-color: var(--ananfx-yellow-pressed);
    background: var(--ananfx-yellow-pressed);
  }

  .ananfx-mobile-drawer__profile {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--ananfx-border);
    border-radius: 14px;
    background: var(--ananfx-background);
  }

  .ananfx-mobile-drawer__avatar {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    overflow: hidden;
    border-radius: 999px;
    background: var(--ananfx-surface);
    color: var(--ananfx-text-primary);
    font-size:var(--anan-type-control);
    font-weight: 700;
  }

  .ananfx-mobile-drawer__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .ananfx-mobile-drawer__profile-copy {
    min-width: 0;
    align-self: center;
  }

  .ananfx-mobile-drawer__profile-copy strong,
  .ananfx-mobile-drawer__profile-copy span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ananfx-mobile-drawer__profile-copy strong {
    color: var(--ananfx-text-primary);
    font-size:var(--anan-type-control);
    line-height: 1.45;
  }

  .ananfx-mobile-drawer__profile-copy span {
    margin-top: 2px;
    color: var(--ananfx-text-secondary);
    font-size:var(--anan-type-detail);
    line-height: 1.45;
  }

  .ananfx-mobile-drawer__close:focus-visible,
  .ananfx-mobile-drawer__direct:focus-visible,
  .ananfx-mobile-drawer__group-toggle:focus-visible,
  .ananfx-mobile-drawer__sub-link:focus-visible,
  .ananfx-mobile-drawer__account-button:focus-visible {
    outline: 3px solid rgba(255, 222, 2, 0.42);
    outline-offset: 2px;
  }

  @media (hover: hover) {
    .ananfx-mobile-drawer__close:hover,
    .ananfx-mobile-drawer__direct:hover,
    .ananfx-mobile-drawer__group-toggle:hover,
    .ananfx-mobile-drawer__sub-link:hover {
      background: var(--ananfx-surface);
    }

    .ananfx-mobile-drawer__account-button--outline:hover:not(:active) {
      background: var(--ananfx-yellow-soft);
    }

    .ananfx-mobile-drawer__account-button--gold:hover:not(:active) {
      border-color: var(--ananfx-yellow-hover);
      background: var(--ananfx-yellow-hover);
    }
  }

  @media (max-width: 359px) {
    .ananfx-mobile-drawer {
      width: min(91vw, 420px);
      max-width: calc(100vw - 28px);
    }

    .ananfx-mobile-drawer__header {
      min-height: calc(94px + env(safe-area-inset-top));
      padding-inline: 16px;
    }

    .ananfx-mobile-drawer__brand {
      width: 158px;
    }

    .ananfx-mobile-drawer__nav,
    .ananfx-mobile-drawer__account {
      padding-inline: 16px;
    }
  }

  @media (orientation: landscape) and (max-height: 500px) {
    .ananfx-mobile-drawer__header {
      min-height: calc(78px + env(safe-area-inset-top));
      padding-top: calc(10px + env(safe-area-inset-top));
      padding-bottom: 10px;
    }

    .ananfx-mobile-drawer__brand {
      width: 158px;
    }
  }
}

/* Desktop hard guard: mobile drawer และ overlay ต้องไม่แสดงตั้งแต่ 768px ขึ้นไป */
@media (min-width: 768px) {
  .ananfx-mobile-drawer,
  .ananfx-mobile-drawer-overlay {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ananfx-mobile-drawer,
  .ananfx-mobile-drawer-overlay,
  .ananfx-mobile-drawer__chevron,
  .ananfx-mobile-drawer__submenu-wrap,
  .ananfx-mobile-drawer__direct::before,
  .ananfx-mobile-drawer__sub-link::before {
    transition-duration: 0.01ms !important;
  }
}
