/*
|--------------------------------------------------------------------------
| public/css/nav.css
|--------------------------------------------------------------------------
| ระบบเมนูทั้งหมดของ So ezbuy (โหลดหลัง index.css เสมอ)
|
| - Header 2 แถว : โลโก้ + ค้นหา + ผู้ใช้ / Mega Menu + ลิงก์หลัก
| - Mega Menu แบบ 2 คอลัมน์บนเดสก์ท็อป
| - Drawer เต็มจอบนมือถือ พร้อม Accordion หมวดหมู่
| - เมนูหลังบ้าน (Sidebar) ที่ย่อเป็น Drawer บนมือถือ
| - รองรับ Dark mode, Safe area ของ iPhone, และ prefers-reduced-motion
|--------------------------------------------------------------------------
*/

:root {
    --header-height: 68px;
    --nav-z: 1200;
    --drawer-z: 1400;
    --drawer-width: min(88vw, 340px);
    --nav-ring: 0 0 0 3px rgba(227, 6, 19, 0.22);
}

/* =========================================================
   0. ยูทิลิตี้
========================================================= */

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 9999;
    background: var(--color-brand);
    color: #fff;
    padding: 10px 18px;
    border-radius: 0 0 12px 0;
    font-weight: 700;
}

.skip-link:focus {
    left: 0;
    color: #fff;
}

body.nav-locked {
    overflow: hidden;
    touch-action: none;
}

.site-header :focus-visible,
.mobile-drawer :focus-visible,
.admin-sidebar :focus-visible {
    outline: none;
    box-shadow: var(--nav-ring);
    border-radius: 10px;
}

/* =========================================================
   1. โครงสร้าง Header
========================================================= */

.site-header {
    position: sticky;
    top: 0;
    z-index: var(--nav-z);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    backdrop-filter: saturate(180%) blur(14px);
}

html[data-theme="dark"] .site-header {
    background: color-mix(in srgb, var(--color-bg) 94%, #fff);
}

.site-header .header-top-inner {
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 14px;
}

.site-header .site-logo {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
}

.site-header .site-logo-image {
    width: 180px;
    max-height: 52px;
    height: auto;
    object-fit: contain;
}

/* ---------- ช่องค้นหา ---------- */

.site-header .header-search {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 640px;
    width: auto;
    padding: 5px 5px 5px 8px;
    background: var(--color-bg-soft);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    transition: border-color .2s ease, box-shadow .2s ease;
}

.site-header .header-search:focus-within {
    border-color: var(--color-brand);
    box-shadow: var(--nav-ring);
}

.site-header .header-search input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--color-text);
    font-size: 15px;
    padding: 9px 8px;
}

.site-header .header-search button {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 0;
    padding: 10px 18px;
    border-radius: var(--radius-pill);
    background: var(--color-brand);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
}

.site-header .header-search button:hover {
    background: var(--color-brand-dark);
}

.header-search-icon {
    font-size: 17px;
    line-height: 1;
}

/* ---------- ปุ่มด้านขวา ---------- */

.site-header .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    margin-left: auto;
}

.site-header .icon-button {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    background: var(--color-bg-card);
    color: var(--color-text);
    border-radius: var(--radius-pill);
    font-size: 14px;
    font-weight: 700;
    transition: var(--transition);
}

.site-header .icon-button:hover {
    border-color: var(--color-brand);
    color: var(--color-brand);
}

.site-header .search-toggle {
    display: none;
    font-size: 20px;
}

.site-header .auth-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- เมนูผู้ใช้ ---------- */

.site-header .user-menu {
    position: relative;
}

.site-header .user-menu-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 6px;
    border: 1px solid var(--color-border);
    background: var(--color-bg-card);
    color: var(--color-text);
    border-radius: var(--radius-pill);
    font-weight: 700;
    font-size: 14px;
    max-width: 190px;
}

.site-header .user-menu-button:hover {
    border-color: var(--color-brand);
}

.user-avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--color-brand);
    color: #fff;
    font-weight: 800;
    text-transform: uppercase;
}

.site-header .user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.site-header .user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    width: 250px;
    padding: 8px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-floating);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
    z-index: 20;
}

.site-header .user-dropdown.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.site-header .user-dropdown-header {
    display: grid;
    padding: 10px 12px 12px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--color-border);
}

.site-header .user-dropdown-header small {
    color: var(--color-muted);
    font-size: 12.5px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.site-header .user-dropdown a {
    display: block;
    padding: 10px 12px;
    border-radius: var(--radius-small);
    font-size: 14.5px;
    font-weight: 600;
    color: var(--color-text);
}

.site-header .user-dropdown a:hover {
    background: var(--color-bg-soft);
    color: var(--color-brand);
}

/* =========================================================
   2. แถวล่าง + Mega Menu (เดสก์ท็อป)
========================================================= */

.site-header .header-bottom {
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
}

.site-header .header-bottom-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 52px;
}

.site-header .nav-mega-wrap {
    position: relative;
    flex: 0 0 auto;
}

.site-header .nav-mega-button {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    height: 40px;
    padding: 0 18px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--color-brand);
    color: #fff;
    font-weight: 700;
    font-size: 14.5px;
    transition: var(--transition);
}

.site-header .nav-mega-button:hover,
.site-header .nav-mega-wrap.is-open .nav-mega-button {
    background: var(--color-brand-dark);
}

.nav-mega-icon {
    font-size: 16px;
    line-height: 1;
}

.site-header .mega-menu-panel {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    display: grid;
    grid-template-columns: 262px minmax(0, 1fr);
    width: min(94vw, 940px);
    min-height: 380px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow-floating);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
    z-index: 30;
}

.site-header .nav-mega-wrap.is-open .mega-menu-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.site-header .mega-menu-left {
    padding: 10px;
    border-right: 1px solid var(--color-border);
    background: var(--color-bg-soft);
    max-height: 460px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.site-header .mega-menu-category {
    width: 100%;
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) 16px;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius-small);
    background: transparent;
    color: var(--color-text);
    font-size: 14.5px;
    font-weight: 600;
    text-align: left;
    transition: var(--transition);
}

.site-header .mega-menu-category:hover,
.site-header .mega-menu-category.is-active {
    background: var(--color-bg-card);
    color: var(--color-brand);
    box-shadow: var(--shadow-soft);
}

.mega-menu-category-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mega-menu-category-arrow {
    color: var(--color-muted);
    font-size: 17px;
}

.site-header .mega-menu-right {
    padding: 22px 26px;
    max-height: 460px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.site-header .mega-menu-sub {
    display: none;
}

.site-header .mega-menu-sub.is-active {
    display: block;
    animation: navFadeIn .18s ease;
}

@keyframes navFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}

.site-header .mega-menu-sub-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    color: var(--color-text);
    font-size: 17px;
    font-weight: 800;
    border-bottom: 2px solid var(--color-brand);
}

.site-header .mega-menu-sub-title:hover {
    color: var(--color-brand);
}

.site-header .mega-menu-sub-links {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 2px 14px;
}

.site-header .mega-menu-sub-links a {
    display: block;
    padding: 9px 10px;
    border-radius: var(--radius-small);
    color: var(--color-muted);
    font-size: 14.5px;
    font-weight: 500;
}

.site-header .mega-menu-sub-links a:hover {
    background: var(--color-bg-soft);
    color: var(--color-brand);
}

/* ---------- ลิงก์หลักข้าง Mega Menu ---------- */

.site-header .nav-links {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.site-header .nav-links::-webkit-scrollbar {
    display: none;
}

.site-header .nav-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 9px 14px;
    border-radius: var(--radius-pill);
    color: var(--color-muted);
    font-size: 14.5px;
    font-weight: 600;
    white-space: nowrap;
    border: 0;
    background: transparent;
    transition: var(--transition);
}

.site-header .nav-link:hover,
.site-header .nav-link.is-current {
    background: var(--color-bg-soft);
    color: var(--color-brand);
}

.site-header .nav-extra-wrap {
    position: relative;
}

.site-header .nav-extra-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 230px;
    padding: 8px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-floating);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
    z-index: 25;
}

.site-header .nav-extra-wrap.is-open .nav-extra-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.site-header .nav-extra-panel a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-small);
    color: var(--color-text);
    font-size: 14.5px;
    font-weight: 600;
}

.site-header .nav-extra-panel a:hover {
    background: var(--color-bg-soft);
    color: var(--color-brand);
}

.nav-item-icon {
    width: 20px;
    flex: 0 0 20px;
    text-align: center;
}

/* =========================================================
   3. ปุ่มแฮมเบอร์เกอร์ + Overlay
========================================================= */

.site-header .nav-burger {
    display: none;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    background: var(--color-bg-card);
}

.site-header .nav-burger span {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 2px;
    background: var(--color-text);
    transition: transform .25s ease, opacity .2s ease;
}

.site-header .nav-burger[aria-expanded="true"] span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.site-header .nav-burger[aria-expanded="true"] span:nth-child(2) {
    opacity: 0;
}

.site-header .nav-burger[aria-expanded="true"] span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.nav-overlay {
    position: fixed;
    inset: 0;
    z-index: calc(var(--drawer-z) - 1);
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity .25s ease;
}

.nav-overlay[hidden] {
    display: none;
}

.nav-overlay.is-visible {
    opacity: 1;
}

/* =========================================================
   4. Drawer มือถือ
========================================================= */

.mobile-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--drawer-width);
    max-width: 100%;
    z-index: var(--drawer-z);
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    border-right: 1px solid var(--color-border);
    box-shadow: var(--shadow-floating);
    transform: translateX(-102%);
    transition: transform .28s cubic-bezier(.22, .61, .36, 1);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 0);
    visibility: hidden;
}

.mobile-drawer.is-open {
    transform: translateX(0);
    visibility: visible;
}

.mobile-drawer-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.mobile-drawer-logo img {
    width: 138px;
    max-height: 42px;
    height: auto;
    object-fit: contain;
}

.mobile-drawer-close {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-bg-card);
    color: var(--color-text);
    font-size: 17px;
}

.mobile-drawer-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-soft);
}

.mobile-drawer-user span > strong {
    display: block;
    font-size: 15px;
}

.mobile-drawer-user span > small {
    display: block;
    color: var(--color-muted);
    font-size: 12.5px;
    word-break: break-all;
}

.mobile-drawer-auth {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 14px 16px 4px;
}

.btn-block {
    width: 100%;
    justify-content: center;
    text-align: center;
}

.mobile-drawer-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 14px 16px;
    padding: 5px 5px 5px 12px;
    background: var(--color-bg-soft);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
}

.mobile-drawer-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--color-text);
    font-size: 16px; /* 16px กัน iOS ซูมอัตโนมัติตอนโฟกัส */
    padding: 9px 0;
}

.mobile-drawer-search button {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 0;
    border-radius: 50%;
    background: var(--color-brand);
    color: #fff;
    font-size: 18px;
}

.mobile-drawer-nav {
    padding: 0 10px 18px;
}

.mobile-drawer-heading {
    margin: 16px 8px 8px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--color-muted);
}

.drawer-accordion {
    border-bottom: 1px solid var(--color-border);
}

.drawer-accordion-head {
    display: flex;
    align-items: stretch;
}

.drawer-accordion-link {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 52px;
    padding: 8px 10px;
    color: var(--color-text);
    font-size: 15.5px;
    font-weight: 600;
}

.drawer-accordion-link:active {
    background: var(--color-bg-soft);
}

.drawer-accordion-icon {
    width: 26px;
    flex: 0 0 26px;
    text-align: center;
    font-size: 18px;
}

.drawer-accordion-toggle {
    width: 52px;
    flex: 0 0 52px;
    border: 0;
    background: transparent;
    color: var(--color-muted);
    font-size: 18px;
}

.drawer-accordion-toggle span {
    display: inline-block;
    transition: transform .22s ease;
}

.drawer-accordion-toggle[aria-expanded="true"] span {
    transform: rotate(180deg);
    color: var(--color-brand);
}

.drawer-accordion-panel {
    padding: 2px 10px 12px 48px;
}

.drawer-accordion-panel[hidden] {
    display: none;
}

.drawer-accordion-panel a {
    display: block;
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-radius: var(--radius-small);
    color: var(--color-muted);
    font-size: 15px;
}

.drawer-accordion-panel a:active {
    background: var(--color-bg-soft);
    color: var(--color-brand);
}

.drawer-plain-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 50px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: 15.5px;
    font-weight: 600;
}

.drawer-plain-link-danger {
    color: var(--color-danger);
}

.mobile-drawer-foot {
    margin-top: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 14px 16px calc(18px + env(safe-area-inset-bottom, 0));
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-soft);
}

.drawer-foot-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    background: var(--color-bg-card);
    color: var(--color-text);
    font-size: 14px;
    font-weight: 700;
}

/* =========================================================
   5. Breakpoints
========================================================= */

/* จอกลาง : ซ่อนลิงก์ที่ยาวเกิน */
@media (max-width: 1100px) {
    .site-header .site-logo-image { width: 160px; }
    .site-header .mega-menu-panel { width: min(96vw, 820px); }
}

/* มือถือ / แท็บเล็ต */
@media (max-width: 992px) {

    .site-header .header-bottom {
        display: none;                 /* แถบ Mega Menu ใช้เฉพาะเดสก์ท็อป */
    }

    .site-header .nav-burger {
        display: inline-flex;
    }

    .site-header .header-top-inner {
        flex-wrap: wrap;
        gap: 10px;
        padding-block: 10px;
    }

    .site-header .site-logo {
        margin-right: auto;
    }

    .site-header .site-logo-image {
        width: 142px;
        max-height: 44px;
    }

    .site-header .header-search {
        order: 3;
        flex: 1 0 100%;
        max-width: none;
        display: none;                 /* เปิดด้วยปุ่มแว่นขยาย */
    }

    .site-header .header-search.is-open {
        display: flex;
    }

    .site-header .header-search input {
        font-size: 16px;               /* กัน iOS ซูม */
    }

    .site-header .header-search button {
        padding: 10px 14px;
    }

    .header-search-text {
        display: none;
    }

    .site-header .search-toggle {
        display: inline-flex;
    }

    .site-header .language-switch,
    .site-header .theme-toggle {
        display: none;                 /* ย้ายไปอยู่ใน Drawer แล้ว */
    }

    .site-header .user-name,
    .site-header .user-caret {
        display: none;
    }

    .site-header .user-menu-button {
        width: 42px;
        height: 42px;
        padding: 0;
        justify-content: center;
    }
}

@media (max-width: 560px) {

    .site-header .icon-button,
    .site-header .nav-burger {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }

    .site-header .auth-buttons .btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    .hide-mobile {
        display: none !important;
    }

    .mobile-drawer-auth {
        grid-template-columns: 1fr;
    }
}

/* =========================================================
   6. เมนูหลังบ้าน (Admin)
========================================================= */

.admin-layout {
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}

.admin-sidebar {
    position: sticky;
    top: calc(var(--header-height) + 14px);
    max-height: calc(100vh - var(--header-height) - 28px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow-soft);
}

.admin-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}

.admin-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-sidebar-badge {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: var(--color-brand);
    color: #fff;
    font-weight: 800;
    font-size: 14px;
}

.admin-sidebar-brand strong {
    display: block;
    font-size: 15px;
    line-height: 1.3;
}

.admin-sidebar-brand small {
    display: block;
    font-size: 11.5px;
    color: var(--color-muted);
    letter-spacing: .05em;
    text-transform: uppercase;
}

.admin-sidebar-close {
    display: none;
    width: 38px;
    height: 38px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-bg);
    color: var(--color-text);
}

.admin-sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    margin-bottom: 12px;
    border-radius: var(--radius);
    background: var(--color-bg-soft);
}

.admin-sidebar-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--color-brand);
    color: #fff;
    font-weight: 800;
    text-transform: uppercase;
}

.admin-sidebar-user-text {
    min-width: 0;
}

.admin-sidebar-user-text strong {
    display: block;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-sidebar-user-text small {
    display: block;
    font-size: 11.5px;
    color: var(--color-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-menu {
    display: block;
}

.admin-menu-group + .admin-menu-group {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}

.admin-menu-group-title {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 0 0 6px;
    padding: 0 8px;
    font-size: 11.5px;
    font-weight: 800;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--color-muted);
}

.admin-menu .admin-menu-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 6px 10px;
    border-radius: var(--radius-small);
    color: var(--color-text);
    font-size: 14.5px;
    font-weight: 600;
    transition: var(--transition);
}

.admin-menu .admin-menu-link:hover {
    background: var(--color-bg-soft);
    color: var(--color-brand);
}

.admin-menu .admin-menu-link.is-active {
    background: color-mix(in srgb, var(--color-brand) 12%, transparent);
    color: var(--color-brand);
    box-shadow: inset 3px 0 0 var(--color-brand);
}

.admin-menu .admin-menu-link-danger {
    color: var(--color-danger);
}

.admin-menu-icon {
    width: 22px;
    flex: 0 0 22px;
    text-align: center;
    font-size: 15px;
}

.admin-menu-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-sidebar-toggle {
    display: none;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    margin-bottom: 14px;
    padding: 0 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-card);
    color: var(--color-text);
    font-size: 15px;
    font-weight: 700;
}

.admin-sidebar-toggle-bars {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
}

.admin-sidebar-toggle-bars span {
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: var(--color-text);
}

.admin-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: calc(var(--drawer-z) - 1);
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity .25s ease;
}

.admin-sidebar-backdrop[hidden] {
    display: none;
}

.admin-sidebar-backdrop.is-visible {
    opacity: 1;
}

@media (max-width: 992px) {

    .admin-layout {
        display: block;
    }

    .admin-sidebar-toggle {
        display: flex;
    }

    .admin-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--drawer-width);
        max-height: none;
        z-index: var(--drawer-z);
        border-radius: 0;
        border: 0;
        border-right: 1px solid var(--color-border);
        transform: translateX(-102%);
        visibility: hidden;
        transition: transform .28s cubic-bezier(.22, .61, .36, 1);
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
    }

    .admin-sidebar.is-open {
        transform: translateX(0);
        visibility: visible;
    }

    .admin-sidebar-close {
        display: inline-flex;
    }

    .admin-content {
        min-width: 0;
    }
}

/* ตารางหลังบ้านให้เลื่อนแนวนอนได้บนมือถือ */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
    .table-wrap table {
        min-width: 640px;
    }
}

/* =========================================================
   7. ลดการเคลื่อนไหวตามการตั้งค่าเครื่อง
========================================================= */

@media (prefers-reduced-motion: reduce) {
    .mobile-drawer,
    .admin-sidebar,
    .nav-overlay,
    .admin-sidebar-backdrop,
    .site-header .mega-menu-panel,
    .site-header .user-dropdown,
    .site-header .nav-extra-panel {
        transition: none !important;
        animation: none !important;
    }
}

/* =========================================================
   8. หน้าคูปอง (coupons.php)
========================================================= */

.section-subtitle-strong {
    margin: 34px 0 16px;
    font-size: 20px;
    font-weight: 800;
}

.coupon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
    gap: 18px;
}

.coupon-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    transition: var(--transition);
}

.coupon-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-card);
}

.coupon-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.coupon-platform-logo {
    max-height: 28px;
    width: auto;
    object-fit: contain;
}

.coupon-platform-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--color-muted);
}

.coupon-expiry {
    font-size: 12.5px;
    color: var(--color-muted);
}

.coupon-discount {
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    background: var(--color-brand);
    color: #fff;
    font-size: 12.5px;
    font-weight: 800;
}

.coupon-product-link {
    display: block;
    border-radius: var(--radius-small);
    overflow: hidden;
    background: var(--color-bg-soft);
}

.coupon-product-image {
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: contain;
}

.coupon-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.45;
}

.coupon-description {
    margin: 0;
    font-size: 14px;
    color: var(--color-muted);
}

.coupon-price {
    margin: 0;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.coupon-price strong {
    font-size: 19px;
    color: var(--color-brand);
}

.coupon-price s {
    font-size: 14px;
    color: var(--color-muted);
}

.coupon-code-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.coupon-code {
    flex: 1 1 auto;
    min-width: 0;
    padding: 9px 12px;
    border: 1px dashed var(--color-brand);
    border-radius: var(--radius-small);
    background: color-mix(in srgb, var(--color-brand) 8%, transparent);
    color: var(--color-brand);
    font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
    font-size: 14.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.coupon-card .btn-block {
    margin-top: auto;
}

/* =========================================================
   9. หน้า Insight (insight.php)
========================================================= */

.insight-tabs {
    display: flex;
    gap: 8px;
    margin: 18px 0 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

.insight-tabs::-webkit-scrollbar {
    display: none;
}

.insight-tab {
    flex: 0 0 auto;
    padding: 9px 18px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    background: var(--color-bg-card);
    color: var(--color-muted);
    font-size: 14.5px;
    font-weight: 600;
    white-space: nowrap;
}

.insight-tab:hover {
    border-color: var(--color-brand);
    color: var(--color-brand);
}

.insight-tab.is-active {
    background: var(--color-brand);
    border-color: var(--color-brand);
    color: #fff;
}

.insight-heading {
    margin: 32px 0 16px;
    font-size: 20px;
    font-weight: 800;
}

.insight-keyword-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
}

.insight-keyword-card {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    gap: 2px 10px;
    padding: 12px 14px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    transition: var(--transition);
}

.insight-keyword-card:hover {
    border-color: var(--color-brand);
    transform: translateY(-2px);
}

.insight-keyword-rank {
    grid-row: span 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--color-bg-soft);
    color: var(--color-brand);
    font-size: 13px;
    font-weight: 800;
}

.insight-keyword-text {
    font-size: 15px;
    font-weight: 700;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.insight-keyword-meta {
    font-size: 12.5px;
    color: var(--color-muted);
}

.insight-click-count {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--color-muted);
}

.insight-article-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 18px;
}

.insight-article-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
}

.insight-article-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-card);
}

.insight-article-card img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

.insight-article-body {
    padding: 14px 16px 18px;
}

.insight-article-body h3 {
    margin: 0 0 8px;
    font-size: 16px;
    line-height: 1.45;
}

.insight-article-body p {
    margin: 0;
    font-size: 14px;
    color: var(--color-muted);
}

@media (max-width: 560px) {
    .coupon-grid,
    .insight-article-grid {
        grid-template-columns: 1fr;
    }

    .insight-keyword-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* =========================================================
   10. จัดลำดับชั้น (z-index) ให้ไม่ทับกัน
========================================================= */
/*
   เดิม cookie-consent = 10001 และ back-to-top = 9998
   ซึ่งสูงกว่า Drawer ทำให้ตอนเปิดเมนูบนมือถือ แถบคุกกี้ลอยทับเมนูอยู่
*/

.back-to-top {
    z-index: 900;
}

.cookie-consent {
    z-index: 1000;
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0));
}

/* เปิดเมนูอยู่ ให้ซ่อนแถบคุกกี้กับปุ่มขึ้นบนไว้ก่อน จะได้ไม่บังปุ่มในเมนู */
body.nav-locked .cookie-consent,
body.nav-locked .back-to-top {
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 640px) {
    .cookie-consent {
        left: 12px;
        right: 12px;
        bottom: 12px;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 16px;
    }

    .cookie-consent p {
        font-size: 13.5px;
    }
}

/* =========================================================
   11. ปรับความสูง Mega Menu ให้แสดงครบทุกหมวดโดยไม่ตัดกลางแถว
========================================================= */

.site-header .mega-menu-panel {
    min-height: 420px;
}

.site-header .mega-menu-left,
.site-header .mega-menu-right {
    max-height: 600px;
}
