/* =======================================
   SOULFULSYNC — MOBILE HEADER (SocialV-style)
   Top: logo | tema | hamburguesa
   Utils: iconos rápidos
   ======================================= */

@media (min-width: 1024px) {
    .ssx-mobile-header {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    body {
        padding-top: 0 !important;
    }
}

@media (max-width: 1023px) {

    :root {
        /* top 56 + utils 48 */
        --ss-mobile-top-h: 56px;
        --ss-mobile-utils-h: 48px;
        --ss-admin-bar-h: 0px;
        --ss-theme-header-offset: calc(var(--ss-mobile-top-h) + var(--ss-mobile-utils-h) + env(safe-area-inset-top, 0px));
        --ss-theme-bottom-nav-height: 0px;
        --ss-mobile-menu-offset: 28px;
    }

    /* En móvil el chrome de la app ocupa el top. La admin bar de WP
       (html margin-top anulado + header top:46px) dejaba un hueco
       con el hero visible encima del menú. */
    body.admin-bar {
        --ss-admin-bar-h: 0px;
        --ss-theme-header-offset: calc(var(--ss-mobile-top-h) + var(--ss-mobile-utils-h) + env(safe-area-inset-top, 0px));
    }

    #wpadminbar {
        display: none !important;
    }

    .ssx-desktop-header {
        display: none !important;
    }

    .ssx-desktop-header-spacer {
        display: none !important;
        height: 0 !important;
    }

    .ssx-mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: auto;
        min-height: calc(var(--ss-mobile-top-h) + var(--ss-mobile-utils-h) + env(safe-area-inset-top, 0px));
        padding-top: env(safe-area-inset-top, 0px);
        background: var(--ss-header-bg, #FCFAFF);
        backdrop-filter: blur(18px) saturate(150%);
        -webkit-backdrop-filter: blur(18px) saturate(150%);
        z-index: 99999;
        border-bottom: 1px solid var(--ss-header-border, rgba(228, 223, 242, 0.9));
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        overflow: visible;
        margin: 0;
    }

    html[data-theme="dark"] .ssx-mobile-header {
        background: rgba(12, 10, 20, 0.92);
        border-bottom-color: rgba(50, 46, 68, 0.9);
    }

    /* Fixed al borde superior del viewport (admin bar oculta en móvil). */
    body.admin-bar .ssx-mobile-header {
        top: 0;
        padding-top: env(safe-area-inset-top, 0px);
    }

    @media screen and (max-width: 782px) {
        body.admin-bar {
            --ss-theme-header-offset: calc(var(--ss-mobile-top-h) + var(--ss-mobile-utils-h) + env(safe-area-inset-top, 0px));
        }

        body.admin-bar .ssx-mobile-header {
            top: 0;
            padding-top: env(safe-area-inset-top, 0px);
        }
    }

    /* /chat desktop rules no aplican aquí; si Bridge fuerza relative en móvil, anular padding. */
    body.soulfulsync-web-chat-page .ssx-mobile-header,
    body.soulfulsync-web-chat-page.admin-bar .ssx-mobile-header {
        padding-top: 0 !important;
    }

    .ssx-mobile-top {
        height: var(--ss-mobile-top-h);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 14px;
        gap: 10px;
        box-sizing: border-box;
    }

    .ssx-mobile-logo {
        display: flex;
        align-items: center;
        max-height: 40px;
        min-width: 0;
        flex: 1;
    }

    .ssx-mobile-logo img {
        max-height: 36px !important;
        max-width: min(150px, 48vw) !important;
        width: auto !important;
        height: auto !important;
        object-fit: contain !important;
    }

    .ssx-mobile-top__actions {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
        position: relative;
        z-index: 2;
    }

    .ssx-mobile-icon-btn {
        width: 40px;
        height: 40px;
        border-radius: 12px;
        border: 1px solid rgba(155, 140, 255, 0.18);
        background: rgba(155, 140, 255, 0.08);
        color: var(--ss-ink, #0C0A14);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        padding: 0;
        text-decoration: none;
        flex-shrink: 0;
    }

    html[data-theme="dark"] .ssx-mobile-icon-btn {
        color: #F0ECFA;
        background: rgba(155, 140, 255, 0.12);
        border-color: rgba(184, 168, 255, 0.22);
    }

    .ssx-mobile-theme-btn__moon {
        display: none;
    }

    html[data-theme="dark"] .ssx-mobile-theme-btn__sun {
        display: none;
    }

    html[data-theme="dark"] .ssx-mobile-theme-btn__moon {
        display: inline;
    }

    /* Logos light/dark en topbar móvil (paridad desktop) */
    .ssx-mobile-header .ssx-logo-light { display: block !important; }
    .ssx-mobile-header .ssx-logo-dark { display: none !important; }
    html[data-theme="dark"] .ssx-mobile-header .ssx-logo-light { display: none !important; }
    html[data-theme="dark"] .ssx-mobile-header .ssx-logo-dark { display: block !important; }

    html[data-theme="light"] .ssx-mobile-header {
        background: rgba(252, 250, 255, 0.96);
        border-bottom-color: #E4DFF2;
    }

    html[data-theme="light"] .ssx-mobile-icon-btn {
        background: #F3EEFF;
        border-color: #D9D0EF;
        color: #2A2640;
    }

    html[data-theme="light"] .ssx-mobile-utils {
        border-top-color: #E4DFF2;
        background: rgba(252, 250, 255, 0.92);
    }

    html[data-theme="light"] .ssx-mobile-utils__item {
        color: #5C5D6B;
    }

    .ssx-hamburger {
        width: 40px;
        height: 40px;
        padding: 10px;
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        align-items: stretch;
        gap: 5px;
        flex-shrink: 0;
        cursor: pointer;
        border-radius: 12px;
        border: 1px solid #D4CCFF;
        background: #EDE8FA;
        color: #1E1A2E;
        appearance: none;
        -webkit-appearance: none;
        box-sizing: border-box;
    }

    .ssx-hamburger span {
        display: block;
        flex: 0 0 2.5px;
        height: 2.5px;
        min-height: 2.5px;
        width: 100%;
        border-radius: 3px;
        background-color: #1E1A2E !important;
        opacity: 1;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    html[data-theme="dark"] .ssx-hamburger {
        background: rgba(155, 140, 255, 0.18);
        border-color: rgba(184, 168, 255, 0.32);
        color: #F0ECFA;
    }

    html[data-theme="dark"] .ssx-hamburger span {
        background-color: #F0ECFA !important;
    }

    body.ssx-mobile-open .ssx-hamburger span:nth-child(1) {
        transform: translateY(7.5px) rotate(45deg);
    }
    body.ssx-mobile-open .ssx-hamburger span:nth-child(2) {
        opacity: 0;
    }
    body.ssx-mobile-open .ssx-hamburger span:nth-child(3) {
        transform: translateY(-7.5px) rotate(-45deg);
    }

    /* —— Barra de iconos (SocialV) —— */
    .ssx-mobile-utils {
        height: var(--ss-mobile-utils-h);
        display: flex;
        align-items: center;
        justify-content: space-around;
        padding: 0 6px;
        border-top: 1px solid var(--ss-header-border, rgba(228, 223, 242, 0.85));
        box-sizing: border-box;
        gap: 2px;
    }

    html[data-theme="dark"] .ssx-mobile-utils {
        border-top-color: rgba(50, 46, 68, 0.9);
    }

    .ssx-mobile-utils__item {
        width: 42px;
        height: 42px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        color: var(--ss-muted, #6B6580);
        text-decoration: none;
        border-radius: 12px;
        flex: 1 1 0;
        max-width: 56px;
        position: relative;
    }

    html[data-theme="dark"] .ssx-mobile-utils__item {
        color: #A39BB8;
    }

    .ssx-mobile-utils__item:hover,
    .ssx-mobile-utils__item:active {
        color: var(--ss-violet-deep, #6E5CE6);
        background: rgba(110, 92, 230, 0.08);
    }

    .ssx-mobile-utils__item--slot:empty {
        display: none !important;
    }

    button.ssx-mobile-utils__item,
    .ssx-mobile-utils__fill {
        border: 0;
        background: transparent;
        padding: 0;
        cursor: pointer;
        font: inherit;
        color: inherit;
        width: 100%;
        height: 100%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .ssx-mobile-utils__item--slot {
        overflow: visible;
    }

    .ssx-mobile-utils__item--slot .ss-chat-portable__launcher,
    .ssx-mobile-utils__notif [data-ss-web-notif-mount],
    .ssx-mobile-utils__notif .ss-web-notif {
        margin: 0 !important;
    }

    .ssx-mobile-utils__avatar {
        width: 28px !important;
        height: 28px !important;
        max-width: none !important;
        border-radius: 50% !important;
        display: block;
        object-fit: cover !important;
        object-position: center;
        float: none !important;
    }

    body {
        padding-top: calc(var(--ss-mobile-top-h) + var(--ss-mobile-utils-h) + env(safe-area-inset-top, 0px));
    }

    body.admin-bar {
        padding-top: calc(var(--ss-mobile-top-h) + var(--ss-mobile-utils-h) + env(safe-area-inset-top, 0px));
    }

    @media screen and (max-width: 782px) {
        body.admin-bar {
            padding-top: calc(var(--ss-mobile-top-h) + var(--ss-mobile-utils-h) + env(safe-area-inset-top, 0px));
        }
    }

    /* Appbar inferior sustituida por la barra de iconos superior */
    .ssx-mobile-appbar {
        display: none !important;
    }

    /* /account: un solo header (logo + menú). Sin barra de iconos duplicada. */
    body.ssync-account-page {
        --ss-mobile-utils-h: 0px;
        --ss-theme-header-offset: calc(var(--ss-mobile-top-h) + var(--ss-admin-bar-h, 0px) + env(safe-area-inset-top, 0px));
        padding-top: calc(var(--ss-mobile-top-h) + var(--ss-admin-bar-h, 0px) + env(safe-area-inset-top, 0px)) !important;
    }
    body.ssync-account-page.admin-bar {
        --ss-theme-header-offset: calc(var(--ss-mobile-top-h) + env(safe-area-inset-top, 0px));
        padding-top: calc(var(--ss-mobile-top-h) + env(safe-area-inset-top, 0px)) !important;
    }
    body.ssync-account-page .ssx-mobile-utils {
        display: none !important;
        height: 0 !important;
        min-height: 0 !important;
        overflow: hidden !important;
        border: 0 !important;
        padding: 0 !important;
        pointer-events: none !important;
    }
    body.ssync-account-page .ssx-mobile-header {
        min-height: var(--ss-mobile-top-h);
    }
}
