/* =============================================================================
   ECA v4 · Mobile Header (from scratch) + User Drawer
   - Replaces broken eca_v3 mobile header at ≤991.98px
   - Reuses autohide via body.eca-nav-hidden (defined in eca-mobile.css)
   - Brand colors: #2f503e (primary green) / #f0c451 (accent gold)
   ============================================================================= */

/* -------- Desktop: nothing from this file is visible -------- */
@media (min-width: 992px) {
    .ecav4-mh { display: none !important; }
    .ecav4-mh-search-overlay { display: none !important; }
    .ecav4-ud,
    .ecav4-ud-backdrop { display: none !important; }
}

/* ============================================================================
   MOBILE / TABLET (≤991.98px)
   ============================================================================ */
@media (max-width: 991.98px) {

    /* ---- Hide the original eca_v3 mobile header pieces; we render our own ---- */
    .main-header .ele_navbar_top { display: none !important; }
    .main-header .ele_navbar_top_right { display: none !important; }
    .main-header .ele_header_shadow { display: none !important; }

    /* Hide the floating "+" FAB since "+" now lives in mobile header */
    .ele_create_dropup { display: none !important; }

    /* ---- .main-header becomes a fixed top bar wrapping our mobile header ---- */
    .main-header {
        position: fixed;
        top: 0; left: 0; right: 0;
        z-index: 1000;
        background: transparent;
        box-shadow: none;
        padding: 0;
        height: auto;
    }

    /* SnGine's style.min.css already sets:
         body { padding-top: 56px; }              -> clears the original fixed .ele_navbar_top
       Our mobile header (.ecav4-mh inside .main-header) is ALSO fixed at top, height 56px,
       so we MUST NOT add an extra padding-top to .main-wrapper or the gap doubles.
       We only need padding-bottom for the bottom-bar clearance. */
    body .main-wrapper { padding-top: 0; padding-bottom: 70px; }

    /* 25px breathing room between mobile header and the first page container.
       SnGine pages start with <div class="container mt20"> (mt20 = margin-top:20px).
       We override that to exactly 25px on mobile. Used on feed, pages, groups, events,
       blogs, market, jobs, forums, settings, search — every page that uses the
       standard SnGine container layout. */
    body .main-wrapper > .container.mt20,
    body .main-wrapper > .container-fluid.mt20 { margin-top: 25px !important; }
    /* Fallback: any direct container child of main-wrapper (covers pages that don't use .mt20) */
    body .main-wrapper > .container:first-of-type,
    body .main-wrapper > .container-fluid:first-of-type { margin-top: 25px; }

    /* SnGine sets .main-header { margin-bottom: 30px } — kill it on mobile since
       our fixed header doesn't need it (margin on fixed elements visually pushes
       any in-flow sibling, which we don't want). */
    .main-header { margin-bottom: 0 !important; }

    /* When the system shows the live top-bar (body.n_live), SnGine sets
       body { padding-top: 100px } to clear a 44px notice + 56px header.
       That stays as-is — our mobile header still fits the 56px slot. */

    /* ====================== MOBILE HEADER ====================== */
    .ecav4-mh {
        background: #2f503e;
        color: #fff;
        height: 56px;
        width: 100%;
        box-shadow: 0 1px 3px rgba(0,0,0,.15);
    }
    body.night-mode .ecav4-mh {
        background: #1c2421;
        box-shadow: 0 1px 3px rgba(0,0,0,.4);
    }

    .ecav4-mh-inner {
        display: flex;
        flex-direction: row-reverse;       /* render ecav4-mh-left visually on left, ecav4-mh-right on right */
        align-items: center;
        justify-content: space-between;
        height: 56px;
        padding: 0 6px;
    }

    .ecav4-mh-left,
    .ecav4-mh-right {
        display: flex;
        align-items: center;
        gap: 2px;
    }

    /* ---- Icon buttons (same look for +, search, market, hamburger) ---- */
    .ecav4-mh-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        background: transparent;
        border: 0;
        padding: 0;
        color: rgba(255,255,255,.92);
        border-radius: 8px;
        cursor: pointer;
        transition: background .15s ease, color .15s ease;
        text-decoration: none;
    }
    .ecav4-mh-btn:hover,
    .ecav4-mh-btn:focus,
    .ecav4-mh-btn:active {
        background: rgba(255,255,255,.10);
        color: #fff;
        outline: none;
        text-decoration: none;
    }
    .ecav4-mh-btn svg { display: block; }

    /* ---- Logo (right side) ---- */
    .ecav4-mh-logo {
        display: inline-flex;
        align-items: center;
        height: 42px;
        padding: 0 6px;
        text-decoration: none;
        color: #fff;
    }
    .ecav4-mh-logo img {
        max-height: 30px;
        width: auto;
        display: block;
    }
    .ecav4-mh-logo-text {
        font-weight: 700;
        font-size: 16px;
        color: #fff;
    }

    /* ---- "+" create dropdown menu ---- */
    .ecav4-mh-create-menu.dropdown-menu {
        position: absolute;
        margin-top: 6px;
        min-width: 220px;
        max-height: calc(100vh - 80px);
        overflow-y: auto;
        z-index: 1010;
        border-radius: 10px;
        box-shadow: 0 6px 24px rgba(0,0,0,.18);
        border: 1px solid rgba(0,0,0,.06);
    }
    .ecav4-mh-create-menu li a {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 14px;
        font-size: 14px;
    }
    .ecav4-mh-create-menu li a svg {
        flex-shrink: 0;
    }

    /* ====================== SEARCH OVERLAY ====================== */
    .ecav4-mh-search-overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: #2f503e;
        display: flex;
        align-items: center;
        padding: 0 6px;
        transform: translateY(-100%);
        opacity: 0;
        pointer-events: none;
        transition: transform .22s ease, opacity .18s ease;
        z-index: 2;
    }
    body.night-mode .ecav4-mh-search-overlay { background: #1c2421; }
    body.ecav4-mh-search-open .ecav4-mh-search-overlay {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }
    .ecav4-mh-search-form {
        display: flex;
        align-items: center;
        width: 100%;
        gap: 4px;
    }
    .ecav4-mh-search-close,
    .ecav4-mh-search-submit {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        background: transparent;
        border: 0;
        color: #fff;
        border-radius: 8px;
        cursor: pointer;
    }
    .ecav4-mh-search-close:hover,
    .ecav4-mh-search-submit:hover { background: rgba(255,255,255,.10); }
    .ecav4-mh-search-input.form-control {
        flex: 1 1 auto;
        height: 38px;
        border-radius: 19px;
        border: 0;
        background: rgba(255,255,255,.15);
        color: #fff;
        padding: 0 14px;
        font-size: 15px;
    }
    .ecav4-mh-search-input.form-control::placeholder { color: rgba(255,255,255,.65); }
    .ecav4-mh-search-input.form-control:focus {
        background: rgba(255,255,255,.22);
        box-shadow: none;
        outline: none;
        color: #fff;
    }

    /* ====================== AUTOHIDE compat ======================
       eca-mobile.css already defines:
         body.eca-nav-hidden .main-header { transform: translateY(-110%); ... }
       Since our ecav4-mh lives inside .main-header, autohide works as-is.
       But we override the main-header background transition since now main-header
       is just a transparent wrapper. */
    .main-header {
        transition: transform .28s cubic-bezier(.4,0,.2,1), opacity .22s ease;
        will-change: transform;
    }

    /* ====================== USER DRAWER (bottom sheet) ====================== */
    .ecav4-ud-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity .22s ease;
        z-index: 1040;
    }
    body.ecav4-ud-open .ecav4-ud-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .ecav4-ud {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        max-height: 88vh;
        background: #fff;
        color: #2c2c2c;
        border-top-left-radius: 18px;
        border-top-right-radius: 18px;
        box-shadow: 0 -8px 28px rgba(0,0,0,.22);
        transform: translateY(100%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
        z-index: 1050;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    body.night-mode .ecav4-ud {
        background: #21262b;
        color: #e6e6e6;
    }
    body.ecav4-ud-open .ecav4-ud {
        transform: translateY(0);
    }

    .ecav4-ud-grabber {
        width: 42px;
        height: 4px;
        background: rgba(0,0,0,.18);
        border-radius: 2px;
        margin: 8px auto 6px;
        flex-shrink: 0;
    }
    body.night-mode .ecav4-ud-grabber { background: rgba(255,255,255,.22); }

    .ecav4-ud-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 6px 14px 10px;
        gap: 10px;
        border-bottom: 1px solid rgba(0,0,0,.06);
        flex-shrink: 0;
    }
    body.night-mode .ecav4-ud-head { border-bottom-color: rgba(255,255,255,.08); }

    .ecav4-ud-user {
        display: flex;
        align-items: center;
        gap: 12px;
        flex: 1 1 auto;
        min-width: 0;
        text-decoration: none;
        color: inherit;
    }
    .ecav4-ud-avatar {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        object-fit: cover;
        flex-shrink: 0;
    }
    .ecav4-ud-user-meta { min-width: 0; }
    .ecav4-ud-user-name {
        font-weight: 700;
        font-size: 15px;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: inherit;
    }
    .ecav4-ud-user-sub {
        font-size: 12px;
        line-height: 1.2;
        color: rgba(0,0,0,.55);
        margin-top: 2px;
    }
    body.night-mode .ecav4-ud-user-sub { color: rgba(255,255,255,.55); }

    .ecav4-ud-close-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        background: transparent;
        border: 0;
        border-radius: 50%;
        color: inherit;
        cursor: pointer;
        flex-shrink: 0;
    }
    .ecav4-ud-close-btn:hover { background: rgba(0,0,0,.06); }
    body.night-mode .ecav4-ud-close-btn:hover { background: rgba(255,255,255,.08); }

    .ecav4-ud-stats {
        display: flex;
        gap: 8px;
        padding: 10px 14px 4px;
        flex-shrink: 0;
    }
    .ecav4-ud-stat {
        flex: 1 1 0;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 12px;
        background: rgba(47,80,62,.08);
        border-radius: 10px;
        text-decoration: none;
        color: inherit;
    }
    .ecav4-ud-stat:hover {
        background: rgba(47,80,62,.14);
        color: inherit;
        text-decoration: none;
    }
    body.night-mode .ecav4-ud-stat { background: rgba(255,255,255,.06); }
    body.night-mode .ecav4-ud-stat:hover { background: rgba(255,255,255,.10); }
    .ecav4-ud-stat svg { flex-shrink: 0; color: #2f503e; }
    body.night-mode .ecav4-ud-stat svg { color: #f0c451; }
    .ecav4-ud-stat-label {
        font-size: 11px;
        color: rgba(0,0,0,.55);
        line-height: 1.1;
    }
    body.night-mode .ecav4-ud-stat-label { color: rgba(255,255,255,.55); }
    .ecav4-ud-stat-value {
        font-weight: 700;
        font-size: 14px;
        line-height: 1.2;
        margin-top: 2px;
    }

    .ecav4-ud-list {
        flex: 1 1 auto;
        overflow-y: auto;
        padding: 6px 8px 8px;
        -webkit-overflow-scrolling: touch;
    }

    .ecav4-ud-item {
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 12px 12px;
        border-radius: 10px;
        text-decoration: none;
        color: inherit;
        font-size: 15px;
        line-height: 1.2;
        cursor: pointer;
        transition: background .12s ease;
    }
    .ecav4-ud-item:hover,
    .ecav4-ud-item:focus {
        background: rgba(0,0,0,.04);
        color: inherit;
        text-decoration: none;
    }
    body.night-mode .ecav4-ud-item:hover,
    body.night-mode .ecav4-ud-item:focus { background: rgba(255,255,255,.06); }
    .ecav4-ud-item svg { flex-shrink: 0; color: #2f503e; }
    body.night-mode .ecav4-ud-item svg { color: #f0c451; }
    .ecav4-ud-item-danger { color: #c0392b; }
    .ecav4-ud-item-danger svg { color: #c0392b; }
    body.night-mode .ecav4-ud-item-danger { color: #ff7a6b; }
    body.night-mode .ecav4-ud-item-danger svg { color: #ff7a6b; }

    .ecav4-ud-divider {
        height: 1px;
        background: rgba(0,0,0,.08);
        margin: 6px 12px;
    }
    body.night-mode .ecav4-ud-divider { background: rgba(255,255,255,.08); }

    .ecav4-ud-foot {
        padding: 10px 14px 14px;
        border-top: 1px solid rgba(0,0,0,.06);
        font-size: 11px;
        color: rgba(0,0,0,.55);
        flex-shrink: 0;
        /* safe-area for iOS home indicator */
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }
    body.night-mode .ecav4-ud-foot {
        border-top-color: rgba(255,255,255,.08);
        color: rgba(255,255,255,.55);
    }
    .ecav4-ud-foot .ecav4-ud-copy { margin-bottom: 4px; }
    .ecav4-ud-links a {
        color: inherit;
        margin-right: 8px;
        text-decoration: none;
    }
    .ecav4-ud-links a:hover { text-decoration: underline; }

    /* When drawer is open, prevent body scroll under it */
    body.ecav4-ud-open { overflow: hidden; }
}
