/*
 * CraftyTemps Mega Menu + Mobile Drawer
 * All selectors scoped under .ctm-mega-menu or .ctm-mobile-drawer
 * to avoid conflicts with existing Kedai theme styles.
 *
 * Breakpoint: 1200px  (matches Kedai's xl / d-xl-block)
 */

/* ── Suppress old Kedai nav when JS hides it ───────────────────────────────
   When the JS fallback runs and sets oldNav.hidden = true, ensure the old
   navigation block is fully removed from layout (browsers should honour the
   [hidden] attribute natively, but add !important for safety).
   ────────────────────────────────────────────────────────────────────────── */
.wp-block-navigation[hidden] { display: none !important; }

/* ── Kedai header overflow fix ─────────────────────────────────────────────
   The mega panel must escape the constrained .primary-nav wrapper.
   We make .desktop-header the absolute positioning context (it is alignfull),
   then strip position from every ancestor between it and .ctm-mega-panel.
   ────────────────────────────────────────────────────────────────────────── */
.desktop-header {
    position: relative !important;
    overflow: visible !important;
}
.primary-nav,
.primary-nav > .wp-block-group,
.ctm-mega-menu,
.ctm-nav-list,
.ctm-nav-item {
    position: static !important;
}

/* ══════════════════════════════════════════════════════════════════════════
   DESKTOP MEGA MENU
   ══════════════════════════════════════════════════════════════════════════ */

.ctm-mega-menu {
    width: 100%;
}

/* ── Nav list (horizontal bar) ─────────────────────────────────────────── */
.ctm-nav-list {
    display: flex !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    gap: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    list-style: none !important;
    height: 100% !important;
}

/* ── Nav links ──────────────────────────────────────────────────────────── */
.ctm-nav-link {
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    padding: 10px 14px !important;
    color: inherit !important;
    text-decoration: none !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    white-space: nowrap !important;
    letter-spacing: 0.01em !important;
    border-radius: 0 !important;
    transition: opacity 0.15s ease !important;
    line-height: 1.4 !important;
}
.ctm-nav-link:hover,
.ctm-has-mega.ctm-active > .ctm-nav-link {
    opacity: 0.72 !important;
    text-decoration: none !important;
}

/* "Shop All" slight accent */
.ctm-shop-all {
    font-weight: 700 !important;
}

/* Chevron icon */
.ctm-chevron {
    flex-shrink: 0;
    transition: transform 0.2s ease;
    margin-top: 1px;
}
.ctm-has-mega.ctm-active .ctm-chevron {
    transform: rotate(180deg);
}

/* ── Mega panel ─────────────────────────────────────────────────────────── */
.ctm-mega-panel {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 99999 !important;

    background: #18042d !important;
    border-top: 2px solid rgba(255,255,255,0.12) !important;
    box-shadow: 0 12px 40px rgba(0,0,0,0.45) !important;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}
.ctm-has-mega.ctm-active > .ctm-mega-panel {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: translateY(0) !important;
}

/* ── Mega inner layout ──────────────────────────────────────────────────── */
.ctm-mega-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 24px 32px;
}

/* ── Mega header row (category title + view-all link) ───────────────────── */
.ctm-mega-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
}
.ctm-mega-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.5);
}
.ctm-mega-view-all {
    font-size: 13px;
    font-weight: 600;
    color: #9b8cff !important;
    text-decoration: none !important;
    transition: color 0.15s;
}
.ctm-mega-view-all:hover {
    color: #c4b8ff !important;
}

/* ── Subcategory columns grid ───────────────────────────────────────────── */
.ctm-mega-cols {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 4px 24px !important;
    margin: 0 !important;
    padding: 0 !important;
    list-style: none !important;
}
@media (max-width: 1400px) {
    .ctm-mega-cols { grid-template-columns: repeat(3, 1fr) !important; }
}

.ctm-mega-cols li {
    margin: 0 !important;
    padding: 0 !important;
}
.ctm-mega-cols a {
    display: block !important;
    padding: 8px 10px !important;
    color: #d4c8ff !important;
    font-size: 13.5px !important;
    font-weight: 400 !important;
    text-decoration: none !important;
    border-radius: 6px !important;
    transition: background 0.15s, color 0.15s !important;
    line-height: 1.35 !important;
}
.ctm-mega-cols a:hover {
    background: rgba(255,255,255,0.08) !important;
    color: #ffffff !important;
}

/* ══════════════════════════════════════════════════════════════════════════
   HAMBURGER BUTTON (inside mobile header)
   ══════════════════════════════════════════════════════════════════════════ */

.ctm-hamburger {
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 5px !important;
    width: 44px !important;
    height: 44px !important;
    padding: 10px !important;
    background: none !important;
    border: none !important;
    cursor: pointer !important;
    border-radius: 6px !important;
    transition: background 0.15s !important;
    flex-shrink: 0 !important;
}
.ctm-hamburger:hover {
    background: rgba(255,255,255,0.12) !important;
}
.ctm-hamburger span {
    display: block !important;
    width: 22px !important;
    height: 2px !important;
    background: currentColor !important;
    border-radius: 2px !important;
    transition: transform 0.25s ease, opacity 0.25s ease, width 0.25s ease !important;
    transform-origin: center !important;
}
/* Animate hamburger → X when drawer is open */
.ctm-drawer-open .ctm-hamburger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg) !important;
}
.ctm-drawer-open .ctm-hamburger span:nth-child(2) {
    opacity: 0 !important;
    transform: scaleX(0) !important;
}
.ctm-drawer-open .ctm-hamburger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg) !important;
}

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE DRAWER BACKDROP
   ══════════════════════════════════════════════════════════════════════════ */

.ctm-drawer-backdrop {
    position: fixed !important;
    inset: 0 !important;
    z-index: 99998 !important;
    background: rgba(0,0,0,0.55) !important;
    backdrop-filter: blur(2px) !important;
    -webkit-backdrop-filter: blur(2px) !important;
    opacity: 0;
    transition: opacity 0.3s ease !important;
}
.ctm-drawer-backdrop.ctm-backdrop-visible {
    opacity: 1 !important;
}

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE DRAWER PANEL
   ══════════════════════════════════════════════════════════════════════════ */

.ctm-mobile-drawer {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(320px, 88vw) !important;
    z-index: 99999 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;

    background: #18042d !important;
    box-shadow: 6px 0 32px rgba(0,0,0,0.5) !important;

    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}
.ctm-mobile-drawer.ctm-drawer-open {
    transform: translateX(0) !important;
}

/* Prevent body scroll while drawer is open */
body.ctm-drawer-open {
    overflow: hidden !important;
}

/* ── Drawer header (brand + close) ─────────────────────────────────────── */
.ctm-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}
.ctm-drawer-brand {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff !important;
    text-decoration: none !important;
    letter-spacing: 0.02em;
}
.ctm-drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.1) !important;
    border: none;
    border-radius: 50%;
    color: #ffffff !important;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
    padding: 0;
    flex-shrink: 0;
}
.ctm-drawer-close:hover {
    background: rgba(255,255,255,0.2) !important;
}

/* ── Shop All link ──────────────────────────────────────────────────────── */
.ctm-drawer-shop-all {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    color: #9b8cff !important;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none !important;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    letter-spacing: 0.02em;
    min-height: 44px;
    flex-shrink: 0;
    transition: background 0.15s;
}
.ctm-drawer-shop-all:hover {
    background: rgba(255,255,255,0.06) !important;
}

/* ── Drawer nav list ────────────────────────────────────────────────────── */
.ctm-drawer-nav {
    list-style: none !important;
    margin: 0 !important;
    padding: 8px 0 24px !important;
    flex: 1 0 auto;
}

/* ── Drawer item ────────────────────────────────────────────────────────── */
.ctm-drawer-item {
    border-bottom: 1px solid rgba(255,255,255,0.06) !important;
}

/* Row: link + toggle button side by side */
.ctm-drawer-item-row {
    display: flex;
    align-items: stretch;
}

/* ── Drawer top-level links ─────────────────────────────────────────────── */
.ctm-drawer-link {
    display: flex !important;
    align-items: center !important;
    flex: 1 !important;
    padding: 0 20px !important;
    min-height: 48px !important;
    color: #e8e0ff !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    text-decoration: none !important;
    transition: color 0.15s, background 0.15s !important;
}
.ctm-drawer-link--leaf {
    padding: 0 20px !important;
    min-height: 48px !important;
}
.ctm-drawer-link:hover,
.ctm-drawer-link--leaf:hover {
    color: #ffffff !important;
    background: rgba(255,255,255,0.06) !important;
}

/* ── Accordion toggle button (+ / –) ───────────────────────────────────── */
.ctm-drawer-toggle {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 52px !important;
    min-height: 48px !important;
    background: none !important;
    border: none !important;
    border-left: 1px solid rgba(255,255,255,0.08) !important;
    color: rgba(255,255,255,0.6) !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
    transition: color 0.15s, background 0.15s !important;
    padding: 0 !important;
}
.ctm-drawer-toggle:hover {
    color: #ffffff !important;
    background: rgba(255,255,255,0.06) !important;
}
/* Rotate the vertical line of the + to form – when expanded */
.ctm-drawer-has-children.ctm-expanded .ctm-toggle-v {
    transform: scaleY(0);
    transform-origin: center;
    transition: transform 0.2s ease;
}
.ctm-toggle-v {
    transition: transform 0.2s ease;
}

/* ── Drawer subnav (accordion body) ────────────────────────────────────── */
.ctm-drawer-subnav {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    max-height: 0 !important;
    transition: max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    background: rgba(0,0,0,0.18) !important;
}
.ctm-drawer-has-children.ctm-expanded .ctm-drawer-subnav {
    /* max-height set by JS to scrollHeight */
}
.ctm-drawer-sublink {
    display: flex !important;
    align-items: center !important;
    min-height: 44px !important;
    padding: 0 20px 0 36px !important;
    color: rgba(212,200,255,0.85) !important;
    font-size: 13.5px !important;
    text-decoration: none !important;
    transition: color 0.15s, background 0.15s !important;
    border-top: 1px solid rgba(255,255,255,0.04) !important;
}
.ctm-drawer-sublink:hover {
    color: #ffffff !important;
    background: rgba(255,255,255,0.06) !important;
}
