/*
 * Header mega menus (Category / Chains) — markup in inc/nav-menu.php, behaviour in js/menu.js.
 * Desktop: floating card under the header. Mobile (<=768px): full-height sheet with accordions.
 */

.w3-icon { display: inline-block; flex-shrink: 0; vertical-align: middle; }

/* Toggle caret */
.header-nav-btn .w3-caret { opacity: .75; transition: transform .2s ease; margin-left: 2px; }
.header-nav-btn.active .w3-caret,
.header-nav-btn[aria-expanded="true"] .w3-caret { transform: rotate(180deg); opacity: 1; }
.header-search-container .header-search-icon { left: 14px; top: 50%; transform: translateY(-50%); color: rgba(255, 255, 255, .7); }

/* ---------- Container ---------- */
.w3-mega {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1001;
    display: flex;
    justify-content: center;
    padding: 10px 16px 0;
    pointer-events: none;
}
.w3-mega[hidden] { display: none; }

.w3-mega__panel {
    pointer-events: auto;
    width: min(1080px, 100%);
    max-height: calc(100vh - var(--header-height, 80px) - 28px);
    overflow: auto;
    overscroll-behavior: contain;
    background: #fff;
    color: #111827;
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: 16px;
    box-shadow: 0 2px 4px rgba(15, 23, 42, .04), 0 12px 24px -6px rgba(15, 23, 42, .12), 0 28px 60px -12px rgba(36, 80, 241, .18);
    padding: 20px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 8px 24px;
    opacity: 0;
    transform: translateY(-6px) scale(.985);
    transform-origin: top center;
    transition: opacity .16s ease, transform .18s cubic-bezier(.2, .8, .2, 1);
}
.w3-mega.is-open .w3-mega__panel { opacity: 1; transform: none; }

.w3-mega__panel--chains { width: min(760px, 100%); display: block; }

.w3-mega__aside {
    border-left: 1px solid rgba(15, 23, 42, .07);
    padding-left: 20px;
}

/* ---------- Groups ---------- */
.w3-mega__group + .w3-mega__group { margin-top: 14px; }
.w3-mega__title,
.w3-mega__lead {
    margin: 0 0 8px;
    padding: 0 10px;
    font-family: var(--font-heading, inherit);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #5b6474;
}
.w3-mega__acc { display: none; }

/* ---------- Lists & items ---------- */
.w3-mega__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.w3-mega__list--card { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.w3-mega__list--compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.w3-mega__aside .w3-mega__list--compact { grid-template-columns: 1fr; }
.w3-mega__list--chains { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.w3-mega__item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 7px 10px;
    border-radius: 10px;
    color: inherit;
    text-decoration: none;
    transition: background-color .15s ease, color .15s ease;
}
.w3-mega__list--card .w3-mega__item { align-items: flex-start; padding: 10px; gap: 12px; }
.w3-mega__item:hover,
.w3-mega__item:focus-visible { background: rgba(36, 80, 241, .07); color: #1e3fd0; }
.w3-mega__item:focus-visible { outline: 2px solid #2450f1; outline-offset: -2px; }

.w3-mega__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 8px;
    background: #f1f4fe;
    color: #2450f1;
    font-size: 13px;
    transition: background-color .15s ease, color .15s ease;
}
.w3-mega__list--card .w3-mega__icon { width: 36px; height: 36px; border-radius: 10px; font-size: 15px; }
.w3-mega__item:hover .w3-mega__icon { background: #2450f1; color: #fff; }
.w3-mega__icon--chain,
.w3-mega__item:hover .w3-mega__icon--chain { background: transparent; border: 0; }
.w3-mega__icon--chain svg,
.w3-mega__icon--chain img { width: 28px; height: 28px; border-radius: 8px; }

.w3-mega__text { display: flex; flex-direction: column; min-width: 0; }
.w3-mega__name { font-size: 14px; font-weight: 500; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w3-mega__list--card .w3-mega__name { font-family: var(--font-heading, inherit); font-weight: 600; }
.w3-mega__desc { margin-top: 2px; font-size: 12.5px; line-height: 1.4; color: #5b6474; }

/* ---------- Dark mode ---------- */
body.theme-dark .w3-mega__panel {
    background: #141b2d;
    color: #e5e9f0;
    border-color: rgba(255, 255, 255, .08);
    box-shadow: 0 12px 24px -6px rgba(0, 0, 0, .5), 0 28px 60px -12px rgba(0, 0, 0, .6);
}
body.theme-dark .w3-mega__aside { border-left-color: rgba(255, 255, 255, .07); }
body.theme-dark .w3-mega__title,
body.theme-dark .w3-mega__lead,
body.theme-dark .w3-mega__desc { color: #9aa6b8; }
body.theme-dark .w3-mega__item:hover,
body.theme-dark .w3-mega__item:focus-visible { background: rgba(99, 132, 255, .12); color: #fff; }
body.theme-dark .w3-mega__icon { background: rgba(99, 132, 255, .14); color: #9db2ff; }
body.theme-dark .w3-mega__icon--chain,
body.theme-dark .w3-mega__item:hover .w3-mega__icon--chain { background: transparent; }
body.theme-dark .w3-mega__item:hover .w3-mega__icon { background: #2450f1; color: #fff; }

/* ---------- Tablet ---------- */
@media (max-width: 1024px) and (min-width: 769px) {
    .w3-mega__panel { grid-template-columns: 1fr; }
    .w3-mega__aside { border-left: 0; padding-left: 0; border-top: 1px solid rgba(15, 23, 42, .07); padding-top: 14px; }
    .w3-mega__aside .w3-mega__list--compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .w3-mega__list--card { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .w3-mega__list--chains { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Mobile: sheet + accordions ---------- */
@media (max-width: 768px) {
    .header-nav-btn .w3-caret { display: none; }
    .w3-mega {
        position: fixed;
        top: var(--header-height, 60px);
        bottom: 0;
        padding: 0;
        display: block;
        background: rgba(15, 23, 42, .35);
    }
    .w3-mega__panel {
        width: 100%;
        max-height: 100%;
        height: auto;
        display: block;
        border-radius: 0 0 18px 18px;
        border-width: 0 0 1px;
        padding: 8px 12px 16px;
        transform: translateY(-8px);
    }
    .w3-mega__aside { border: 0; padding: 0; }
    .w3-mega__group { border-bottom: 1px solid rgba(15, 23, 42, .07); }
    .w3-mega__group + .w3-mega__group { margin-top: 0; }
    .w3-mega__title { display: none; }
    .w3-mega__acc {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        min-height: 52px;
        padding: 0 6px;
        background: none;
        border: 0;
        color: inherit;
        font: 600 15px/1.2 var(--font-heading, inherit);
        text-align: left;
        cursor: pointer;
    }
    .w3-mega__acc .w3-mega__chev { transition: transform .2s ease; opacity: .6; }
    .w3-mega__group.is-open .w3-mega__chev { transform: rotate(180deg); }
    .w3-mega__body { display: none; padding: 0 0 12px; }
    .w3-mega__group.is-open .w3-mega__body { display: block; }
    .w3-mega__list--card,
    .w3-mega__list--compact,
    .w3-mega__aside .w3-mega__list--compact { grid-template-columns: 1fr 1fr; gap: 4px; }
    .w3-mega__list--card .w3-mega__desc { display: none; }
    .w3-mega__list--card .w3-mega__item { align-items: center; padding: 8px; }
    .w3-mega__list--card .w3-mega__icon { width: 32px; height: 32px; }
    .w3-mega__item { min-height: 44px; }
    .w3-mega__lead { padding: 12px 6px 8px; }
    .w3-mega__list--chains { grid-template-columns: 1fr 1fr; padding-bottom: 4px; }

    /* Projects panel header row (desktop styles live in header-desktop.css) */
    .w3-mega__head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin: 4px 0 8px;
        padding: 12px;
        border-radius: 10px;
        background: rgba(36, 80, 241, .06);
        color: inherit;
        text-decoration: none;
    }
    .w3-mega__head-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
    .w3-mega__head-title { font-size: 14px; font-weight: 700; color: var(--text-primary, #0f172a); }
    .w3-mega__head .w3-mega__desc { font-size: 12px; color: var(--text-secondary, #64748b); }
    .w3-mega__head-cta {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        font-size: 12.5px;
        font-weight: 600;
        color: var(--primary-color, #2450f1);
        white-space: nowrap;
        flex-shrink: 0;
    }
    body.theme-dark .w3-mega__head { background: rgba(96, 130, 255, .10); }
    body.theme-dark .w3-mega__head-cta { color: #9db2ff; }
    body.theme-dark .w3-mega__group { border-bottom-color: rgba(255, 255, 255, .07); }
}

@media (max-width: 360px) {
    .w3-mega__list--card,
    .w3-mega__list--compact,
    .w3-mega__aside .w3-mega__list--compact,
    .w3-mega__list--chains { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .w3-mega__panel,
    .header-nav-btn .w3-caret,
    .w3-mega__acc .w3-mega__chev { transition: none; transform: none; }
}


/* Chain icons are self-framed square tiles: no chip behind them in any state */
.w3-mega .w3-mega__item .w3-mega__icon--chain,
body.theme-dark .w3-mega .w3-mega__item:hover .w3-mega__icon--chain { background: transparent; }
