/* =============================================
   Mobile Bottom Navigation Bar
   ============================================= */

/* ===== Global: Prevent horizontal scrolling on ALL pages =====
   This file is loaded on every page, so these rules guarantee
   the page always stays full-width and cannot be swiped
   left/right on mobile. */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
  overscroll-behavior-x: none;
}

/* Hide on desktop */
.mobile-bottom-nav {
  display: none;
}

/* The search panel <div> is appended straight to <body> by
   mobile-bottom-nav.js on EVERY page load, regardless of viewport width
   (the button that opens it is only reachable on mobile, but the panel
   markup itself still exists in the DOM everywhere) — hide it by default
   so it never renders as stray block content on desktop; the mobile media
   query below switches it back to a real display value before toggling
   visibility via .is-open. */
.mobile-search-panel {
  display: none;
}

/* Show only on mobile */
@media (max-width: 767px) {
  /* Hide the top header nav links on mobile to prevent wrapping */
  .custom-header__nav,
  .crystal-header__nav,
  .anniv-header__nav {
    display: none !important;
  }

  /* Make top header compact on mobile */
  .custom-header {
    padding: 8px 15px !important;
    flex-direction: row !important;
    /* flex-start (thay vì space-between mặc định) + gap để logo và link
       "Liên hệ" (chèn kế logo — xem custom-header.js) nằm sát cạnh nhau ở
       đầu thanh, không bị đẩy dạt ra 2 đầu đối diện. */
    justify-content: flex-start !important;
    gap: 12px !important;
  }
  .crystal-header {
    height: 50px !important;
    padding: 0 15px !important;
  }
  .anniv-header {
    height: 50px !important;
    padding: 0 15px !important;
  }

  /* Add bottom padding to body so content is not hidden behind nav.
     NOTE: padding-bottom is set to 0 so no white gap appears below the
     footer. The footer itself gets extra bottom padding (see below) so
     its dark background extends down behind the fixed bottom nav. */
  body {
    padding-bottom: 0;
    padding-top: 50px;
  }

  /* Extend footer backgrounds down behind the fixed bottom nav so there
     is no white gap below the footer on mobile. */
  .vt-footer {
    padding-bottom: calc(1rem + 64px);
  }
  .sk-footer {
    padding-bottom: calc(20px + 64px);
  }
  .crystal-footer {
    padding-bottom: calc(20px + 64px);
  }
  .anniv-footer {
    padding-bottom: calc(20px + 64px);
  }

  /* Prevent hero section from overlapping the fixed header on mobile */
  .s-mv {
    margin-top: 0 !important;
    padding-top: 0;
    min-height: auto;
  }
  .s-mv__img {
    top: 0 !important;
    position: static !important;
    width: 100% !important;
    margin-inline: auto;
  }
  .s-mv__logo {
    margin-top: 2rem;
  }
  .cvArea__link--top {
    top: calc(2rem + 50px) !important;
  }

  /* ===== Bottom Navigation Bar ===== */
  /* NOTE: style.css has `body > * { position: relative; z-index: 1; }`
     which has HIGHER specificity than `.mobile-bottom-nav` and would
     override `position: fixed`. We must use `!important` on position
     so the nav stays fixed and always on top of page content. */
  .mobile-bottom-nav {
    display: block !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 2147483647 !important;
    /* Create an isolated stacking context so no page content
       (e.g. .s-about with overflow/transform children, .s-echo, .s-voice)
       can ever paint on top of the nav. */
    isolation: isolate;
    /* Promote to its own compositor layer above page content */
    transform: translate3d(0, 0, 0) !important;
    -webkit-transform: translate3d(0, 0, 0) !important;
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    background: #ffffff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.12);
    border-top: 1px solid #e5e5e5;
    font-family: "Noto Serif JP", serif;
    pointer-events: auto !important;
  }

  /* Override body > * { position:relative; z-index:1 } for the nav specifically */
  body > .mobile-bottom-nav {
    position: fixed !important;
    z-index: 2147483647 !important;
  }


  /* Prevent .cvArea from blocking the bottom nav on mobile */
  /* .cvArea is a fixed full-screen overlay (z-index 99) on the homepage.
     Its children (<a>) keep pointer-events:auto by default because
     pointer-events is NOT inherited, so taps can be swallowed by it. */
  .cvArea,
  .cvArea * {
    pointer-events: none !important;
  }
  .cvArea__link--bottom {
    bottom: calc(2rem + 64px) !important;
  }

  /* Ensure all nav interactive elements are always clickable */
  .mobile-bottom-nav__list,
  .mobile-bottom-nav__item,
  .mobile-bottom-nav__link,
  .mobile-bottom-nav__dropdown,
  .mobile-bottom-nav__dropdown-item {
    pointer-events: auto !important;
  }

  /* Prevent .pop_banner from blocking the bottom nav on mobile */
  .pop_banner {
    bottom: calc(10px + 64px) !important;
    z-index: 2147483646 !important;
    pointer-events: none !important;
  }

  /* Prevent .s-about (images + absolutely-positioned texts) from
     swallowing taps on the bottom nav when scrolled into view.
     Keep z-index:1 (same as other body > * children) so the section
     stays above the fixed-noise overlays (z-index:0 on mobile) while
     still remaining far below the fixed bottom nav (z-index:2147483647). */
  .s-about {
    z-index: 1 !important;
    pointer-events: none !important;
  }
  .s-about * {
    pointer-events: none !important;
  }
  /* Re-enable pointer events for the "Tìm hiểu thêm về chúng tôi" link
     so it remains clickable on mobile. */
  .s-about__cta,
  .s-about__cta * {
    pointer-events: auto !important;
  }


  /* Prevent .s-mv (hero section with absolutely-positioned images
     and links) from swallowing taps on the bottom nav when scrolled
     back to the top of the page. */
  .s-mv,
  .s-mv * {
    pointer-events: none !important;
  }

  .mobile-bottom-nav__list {
    display: flex;
    justify-content: space-around;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 6px 0;
    height: 64px;
    box-sizing: border-box;
    /* offsetParent cho .mobile-bottom-nav__thread bên dưới — để left/top đo
       được của thread tính đúng theo toạ độ trong <ul> này. */
    position: relative;
  }

  .mobile-bottom-nav__item {
    flex: 1;
    text-align: center;
    position: relative;
  }
  /* Icon + chữ phải nổi TRÊN viên kính trượt (thread nằm cùng cấp trong
     <ul>, canh theo toạ độ item đang active — xem mobile-bottom-nav.js). */
  .mobile-bottom-nav__item,
  .mobile-bottom-nav__link {
    z-index: 1;
  }

  /* "Viên kính" báo hiệu mục đang xem trên thanh bottom nav — cùng ý tưởng
     với .s-quicknav__thread (product/index.html): 1 khối liquid glass bo
     tròn tự trượt theo left/top/width/height của <li> đang active (JS đo
     offsetLeft/offsetTop/offsetWidth/offsetHeight, coi .mobile-bottom-nav__list
     là offsetParent nhờ position:relative ở trên), KHÔNG dùng để làm mờ cả
     thanh nav. Track nền vẫn trắng đục bình thường nên viên kính cần tự có
     viền sáng + đổ bóng để phân biệt được với nền trắng phía sau (trắng
     trong suốt trên nền trắng sẽ vô hình nếu chỉ dựa vào độ trong suốt). */
  .mobile-bottom-nav__thread {
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.7);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    backdrop-filter: blur(12px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12), inset 0 1px 1px rgba(255, 255, 255, 0.9), inset 0 -1px 1px rgba(0, 0, 0, 0.04);
    /* KHÔNG đặt opacity:0 mặc định ở đây — nếu không, lúc JS "xoá" opacity
       inline để hiện viên kính ra (positionThread(), style.opacity = "")
       nó sẽ rơi về đúng opacity:0 của CSS gốc này chứ không phải mặc định
       CSS (opacity:1), khiến viên kính không bao giờ hiện được. Mặc định
       để hiện (opacity CSS ban đầu = 1); JS chỉ set "0" khi thật sự KHÔNG
       có mục nào active (width/height cũng về 0 lúc đó) — giống đúng cách
       .s-quicknav__thread (style.css) đang xử lý. */
    pointer-events: none;
    z-index: 0;
    /* opacity riêng trong transition — width/height về 0 không tự làm viền
       1px + box-shadow biến mất hẳn (vẫn để lại 1 chấm nhỏ), giống bug đã
       gặp và xử lý ở .s-quicknav__thread. */
    transition: left 0.3s cubic-bezier(0.65, 0, 0.35, 1), top 0.3s cubic-bezier(0.65, 0, 0.35, 1),
      width 0.3s cubic-bezier(0.65, 0, 0.35, 1), height 0.3s cubic-bezier(0.65, 0, 0.35, 1), opacity 0.3s ease;
  }

  .mobile-bottom-nav__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    /* !important vì một số trang (crystal.html, 30th-anniversary.html...)
       có luật toàn cục "a:link { color: ... }" với đặc tả cao hơn 1 class
       đơn (.mobile-bottom-nav__link), khiến chữ label bị đổi màu theo màu
       nền trang đó (VD: gần trắng trên crystal.html) và biến mất trên
       thanh nav luôn có nền trắng. */
    color: #666 !important;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    padding: 4px 2px;
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    user-select: none;
  }

  .mobile-bottom-nav__link:active {
    color: #1a1a2e !important;
  }
@media (hover: hover) and (min-width: 768px) {
  .mobile-bottom-nav__link:hover {
    color: #1a1a2e !important;
  }
}

  .mobile-bottom-nav__icon {
    display: block;
    width: 24px;
    height: 24px;
    margin-bottom: 3px;
  }

  .mobile-bottom-nav__icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
  }

  .mobile-bottom-nav__icon img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }

  /* ===== Dropdown (Danh mục) ===== */
  /* Fixed + right-aligned to the viewport so it can never overflow
     the screen on narrow mobile devices. */
  .mobile-bottom-nav__dropdown {
    position: fixed;
    right: 8px;
    bottom: calc(64px + 8px);
    left: auto;
    transform: translateY(8px);
    width: max-content;
    max-width: calc(100vw - 16px);
    min-width: 200px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid #eee;
    padding: 8px 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
  }

  .mobile-bottom-nav__item.is-open .mobile-bottom-nav__dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .mobile-bottom-nav__dropdown-item {
    display: block;
    text-decoration: none;
    color: #333 !important;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 20px;
    text-align: left;
    white-space: normal;
    word-break: break-word;
    transition: background 0.2s ease, color 0.2s ease;
  }

  @media (hover: hover) and (min-width: 768px) {
  .mobile-bottom-nav__dropdown-item:hover {
    background: #f5f5f5;
    color: #1a1a2e !important;
  }
}

  /* Trang con đang xem (Về chúng tôi / Showroom / …) — xem mobile-bottom-nav.js */
  .mobile-bottom-nav__dropdown-item.is-active {
    color: #c9a227 !important;
  }

  .mobile-bottom-nav__dropdown-item + .mobile-bottom-nav__dropdown-item {
    border-top: 1px solid #f0f0f0;
  }

  /* Overlay when dropdown is open */
  .mobile-bottom-nav__overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.3);
    z-index: 9997 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
  }

  .mobile-bottom-nav__overlay.is-visible {
    opacity: 1;
    visibility: visible;
  }

  /* Chữ tô vàng khi mục ĐANG được viên kính bọc quanh — cố ý tách riêng
     khỏi .is-active (đánh dấu trang hiện tại nói chung, dùng cho logic
     nhận diện ở JS) bằng 1 class riêng ".is-lit", vì lúc chuyển trang viên
     kính có thể ĐANG NẰM Ở MỤC CŨ một nhịp trước khi trượt sang (xem
     mobile-bottom-nav.js) — nếu tô vàng theo .is-active (đã đúng mục MỚI
     ngay từ đầu) thì chữ vàng hiện lên TRƯỚC khi viên kính trượt tới nơi,
     nhìn lệch/không đồng bộ. ".is-lit" luôn do JS gán ĐÚNG lúc viên kính
     thật sự có mặt ở đó. */
  .mobile-bottom-nav__item.is-lit .mobile-bottom-nav__link {
    color: #c9a227 !important;
    /* Đổi vàng NGAY, không mờ dần/không delay (chủ site yêu cầu). */
    transition: none;
  }

  /* The "Tìm kiếm" button is a <button>, not an <a> like the other 4 items.
     2 lần sửa trước (khai lại từng thuộc tính font-size/weight/letter-
     spacing riêng) vẫn không ăn — tức UA stylesheet của <button> trên máy
     người dùng còn thắng ở MỘT thuộc tính nào đó mình chưa liệt kê hết.
     Đổi hẳn chiến lược: `all: unset` XÓA SẠCH mọi style mặc định của
     <button> trước (kể cả những gì chưa nghĩ ra), rồi khai lại TOÀN BỘ
     đúng y hệt propety-by-property của rule `.mobile-bottom-nav__link`
     phía trên NGAY TRONG rule này — không dựa vào việc thuộc tính "không
     bị đụng tới thì tự kế thừa đúng" nữa, vì thực tế đã sai 2 lần liền. */
  button.mobile-bottom-nav__link {
    all: unset;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 0;
    padding: 4px 2px;
    border: none;
    background: none;
    text-decoration: none;
    color: #666;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    /* KHÔNG tự khai letter-spacing ở đây (kể cả "0.1em"). body trong
       style.css có `letter-spacing: 0.1em`, nhưng "em" luôn tính theo
       font-size CỦA CHÍNH element đang khai — nếu ghi thẳng 0.1em ở đây
       thì nó tính theo font-size 11px của nút này (~1.1px), KHÁC với giá
       trị "Sản phẩm" (<a>, không tự đặt letter-spacing riêng) thật sự
       đang có: giá trị ĐÃ TÍNH SẴN (computed) từ font-size của body lúc
       kế thừa xuống — không phải luôn bằng 1.1px, tuỳ font-size body theo
       breakpoint. Cách ăn chắc duy nhất là để `all: unset` phía trên tự
       kế thừa (unset trên 1 thuộc tính có tính kế thừa = inherit), tức
       KHÔNG viết dòng letter-spacing nào ở rule này — y hệt cách "Sản
       phẩm" cũng chẳng tự đặt gì cả. */
    text-align: center;
    transition: color 0.2s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-appearance: none;
    appearance: none;
  }

  /* ===== Search panel (Tìm kiếm) ===== */
  /* Dừng lại ngay TRÊN thanh bottom nav (cao 64px — xem
     .mobile-bottom-nav__list) thay vì phủ kín toàn màn hình (inset: 0),
     để thanh bottom nav luôn hiện rõ và bấm được kể cả khi đang tìm kiếm —
     không bị panel che hay làm tối đi. Panel được JS gắn thẳng vào <body>
     — nội dung bên trong (hint/chip/result...) hầu hết đã tự đặt màu
     !important, NHƯNG chưa đặt letter-spacing riêng, nên trên các trang
     có body{letter-spacing} khác site chính (VD 30th-anniversary-style.css,
     crystal-style.css: 0.07em thay vì 0.1em ở style.css) thì cả khối chữ
     trong panel bị kế thừa giãn cách khác hẳn, nhìn "lệch" so với panel ở
     các trang khác dù cùng 1 file CSS/JS. Panel là component DÙNG CHUNG,
     không nên phụ thuộc kiểu chữ riêng của từng trang — ép letter-spacing
     (và font-family cho chắc) về 1 giá trị cố định ngay từ gốc .mobile-
     search-panel để mọi thứ bên trong đồng nhất bất kể đang mở từ trang
     nào. */
  .mobile-search-panel {
    display: block;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 64px !important;
    z-index: 2147483646 !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    font-family: "Noto Serif JP", serif !important;
    letter-spacing: normal !important;
  }

  .mobile-search-panel.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.mobile-search-panel-open {
    overflow: hidden;
  }

  .mobile-search-panel__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
  }

  /* height (KHÔNG phải max-height) — panel neo vào cạnh dưới (bottom: 0)
     nên bề cao càng lớn thì cạnh TRÊN (nơi có ô nhập + con trỏ đang gõ)
     càng bị đẩy lên cao. Trước đây dùng max-height nên panel chỉ cao vừa
     đủ nội dung: lúc mới mở (chưa gõ gì, chỉ có gợi ý ngắn) panel thấp,
     vừa gõ ký tự đầu tiên thì kết quả tìm kiếm đổ vào .mobile-search-panel__body
     khiến panel cao vọt lên NGAY LẬP TỨC — kéo theo cả ô nhập nhảy lên
     theo, đúng lỗi thật khách báo (đang gõ mà ô nhập nhảy vị trí, phải
     kéo lên mới thấy). Cố định LUÔN 80vh ngay từ lúc mở (dù đang trống)
     để chiều cao KHÔNG đổi theo lượng kết quả — ô nhập đứng yên 1 chỗ từ
     đầu đến cuối, chỉ có phần kết quả bên trong (.mobile-search-panel__body,
     đã overflow-y: auto) tự cuộn khi nội dung nhiều/ít. */
  .mobile-search-panel__sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
    transform: translateY(16px);
    transition: transform 0.25s ease;
  }

  .mobile-search-panel.is-open .mobile-search-panel__sheet {
    transform: translateY(0);
  }

  .mobile-search-panel__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
  }

  .mobile-search-panel__icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: #999;
    display: flex;
  }

  .mobile-search-panel__icon svg {
    width: 100%;
    height: 100%;
  }

  .mobile-search-panel__input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    /* font-size 16px để Safari iOS không tự zoom trang khi focus input */
    font-size: 16px;
    font-family: "Noto Serif JP", serif;
    color: #1a1a1a;
    background: transparent;
  }

  .mobile-search-panel__close {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    padding: 4px;
    border: none;
    background: transparent;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .mobile-search-panel__close svg {
    width: 100%;
    height: 100%;
  }

  .mobile-search-panel__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0 calc(env(safe-area-inset-bottom, 0px) + 24px);
    /* Chặn "scroll chaining" — chạm đáy/đỉnh danh sách kết quả không còn
       tràn cuộn sang trang phía sau nữa (cùng lý do/fix với bản desktop
       ở .custom-header__search-panel-body trong style.css). */
    overscroll-behavior: contain;
  }

  .mobile-search-panel__hint {
    margin: 0;
    padding: 16px 18px;
    color: #888;
    font-size: 13px;
    line-height: 1.6;
  }

  .mobile-search-panel__hint a {
    color: #c9a227 !important;
  }

  .mobile-search-panel__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 14px 8px;
  }

  .mobile-search-panel__chip {
    display: inline-block;
    padding: 7px 14px;
    border-radius: 999px;
    background: #f7f5f0;
    border: 1px solid #eee;
    color: #333 !important;
    font-size: 12.5px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
  }

  .mobile-search-panel__result {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 18px;
    text-decoration: none;
    border-bottom: 1px solid #f5f5f5;
  }

  .mobile-search-panel__result-cat {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #c9a227 !important;
  }

  .mobile-search-panel__result-title {
    font-size: 14.5px;
    font-weight: 600;
    color: #1a1a1a !important;
    line-height: 1.35;
  }

  .mobile-search-panel__result-desc {
    font-size: 12px;
    color: #888 !important;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}