
/* Navbar Overflow - Prevent Flash of Unstyled Content (FOUC) */
/* Only hide on desktop screens where overflow handler is active */
@media (min-width: 992px) {
    /* Hide navbar items initially and prevent overflow flash */
    #navbarMain:not(.navbar-overflow-ready) .navbar-nav:first-child {
        opacity: 0 !important;
        visibility: hidden !important;
        overflow: hidden !important; /* Prevent overflow during calculation */
    }

    /* Also hide individual items until ready - prevents inline style override */
    #navbarMain:not(.navbar-overflow-ready) .navbar-nav:first-child .nav-item {
        opacity: 0 !important;
        visibility: hidden !important;
    }

    /* Show navbar once JS is ready */
    #navbarMain.navbar-overflow-ready .navbar-nav:first-child {
        opacity: 1;
        visibility: visible;
        overflow: visible; /* Restore overflow after calculation */
        transition: opacity 0.15s ease;
    }

    /* Show items once ready */
    #navbarMain.navbar-overflow-ready .navbar-nav:first-child .nav-item {
        opacity: 1;
        visibility: visible;
    }

    /* Prevent individual items from showing overflow during calculation */
    #navbarMain:not(.navbar-overflow-ready) .navbar-nav:first-child .nav-item:not(#navbarMoreDropdown) {
        transition: none !important; /* No transition during initial calculation */
    }
}

/* On mobile, always show (Bootstrap collapse handles it) */
@media (max-width: 991.98px) {
    header[role="banner"] .navbar .container-fluid {
        position: relative;
    }

    header[role="banner"] .navbar-brand {
        /* Reserve space so title never collides with mobile action icons */
        padding-inline-end: 84px;
    }

    header[role="banner"].container-lg {
        margin-top: .2rem !important;
        margin-bottom: .2rem !important;
    }

    header[role="banner"] .navbar {
        min-height: 44px !important;
        padding-top: .15rem !important;
        padding-bottom: .15rem !important;
    }

    header[role="banner"] .navbar .container-fluid {
        padding-left: .55rem !important;
        padding-right: .55rem !important;
    }

    header[role="banner"] .navbar-brand img,
    header[role="banner"] .navbar-brand #siteLogo {
        width: 20px !important;
        height: 20px !important;
    }

    /* Keep brand visible on small devices */
    .navbar-brand .site-name {
        display: inline !important;
        /* Was .98rem to squeeze a four-word name onto one line. The brand is one
           short word now, so it can sit at a legible size without overflowing. */
        font-size: 1.06rem !important;
        line-height: 1.1;
        margin-inline-start: .2rem;
    }

    /* Top hamburger is redundant after bottom nav; open drawer from bottom "More". */
    .navbar-toggler {
        display: none !important;
    }

    /* Mobile header (عند تسجيل الدخول): [أيقونة الحساب] اللوجو والعنوان في النص [أيقونة الرسائل] — منع تداخل اللوجو مع الأيقونات */
    header[role="banner"] .navbar .container-fluid:has(.mobile-header-left) {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        flex-wrap: nowrap !important;
        gap: 0 !important;
        min-height: 44px !important;
    }
    header[role="banner"] .mobile-header-left {
        order: 1;
        flex: 0 0 44px !important;
        width: 44px !important;
        min-width: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        z-index: 2 !important;
    }
    /* عنوان الموقع + اللوجو في سطر واحد مضغوط مثل التفضيلات */
    header[role="banner"] .navbar-brand.mobile-header-brand-center {
        order: 2;
        flex: 1 1 0% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        padding-inline: 0.35rem !important;
        overflow: hidden !important;
        z-index: 1 !important;
        min-height: 44px !important;
    }
    header[role="banner"] .navbar-brand.mobile-header-brand-center .d-flex {
        justify-content: center !important;
        align-items: center !important;
        min-width: 0 !important;
        overflow: hidden !important;
        flex-wrap: nowrap !important;
        gap: 0.35rem !important;
        line-height: 1.25 !important;
    }
    header[role="banner"] .navbar-brand.mobile-header-brand-center .site-name {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        font-size: 1.04rem !important;
        line-height: 1.25 !important;
        font-weight: 700 !important;
    }
    header[role="banner"] .navbar-brand.mobile-header-brand-center img,
    header[role="banner"] .navbar-brand.mobile-header-brand-center #siteLogo {
        width: 18px !important;
        height: 18px !important;
        flex-shrink: 0 !important;
    }
    header[role="banner"] .mobile-header-actions:has(.mobile-header-messages-btn) {
        order: 3;
        flex: 0 0 auto !important;
        min-width: 44px !important;
        width: auto !important;
        gap: 6px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        z-index: 2 !important;
    }
    header[role="banner"] .mobile-header-actions > * {
        display: inline-flex !important;
        flex: 0 0 auto !important;
        align-items: center !important;
    }

    /* قائمة الحساب على الموبايل — offcanvas من الجانب مثل فلتر الهوم (ارتفاع كامل، إغلاق واضح، محتوى قابل للتمرير) */
    .account-menu-offcanvas.offcanvas {
        height: 100dvh;
        max-height: 100dvh;
        background: var(--theme-bg-primary, #0a101e);
    }
    [data-theme="light"] .account-menu-offcanvas.offcanvas {
        background: var(--theme-bg-primary, #fff);
    }
    .account-menu-offcanvas .offcanvas-header {
        position: sticky;
        top: 0;
        z-index: 20;
        background: var(--theme-bg-primary, #0a101e);
        padding-top: calc(env(safe-area-inset-top, 0px) + 0.75rem);
        padding-bottom: 0.75rem;
        padding-inline: 0.9rem 0.5rem;
        border-bottom-color: rgba(255, 255, 255, 0.1);
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    [data-theme="light"] .account-menu-offcanvas .offcanvas-header {
        background: var(--theme-bg-primary, #fff);
        border-bottom-color: rgba(0, 0, 0, 0.1);
    }
    .account-menu-offcanvas-header-user {
        margin: 0;
        padding: 0;
        font-size: inherit;
        font-weight: inherit;
    }
    .account-menu-offcanvas-header .profile-menu-user-block {
        padding: 0;
    }
    .account-menu-offcanvas-header .profile-menu-user-block .fw-bold { font-size: 0.95rem; }
    .account-menu-offcanvas-header .profile-menu-user-email { font-size: 0.72rem !important; }
    .account-menu-offcanvas-body {
        height: calc(100dvh - 88px);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding-top: 0.15rem;
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
    }
    .account-menu-offcanvas-body > .list-unstyled {
        padding-bottom: 0.25rem;
    }
    .account-menu-offcanvas-body > .list-unstyled > li {
        margin: 0 !important;
        padding: 0 !important;
        min-height: 0;
    }
    .account-menu-offcanvas-body .dropdown-item,
    .account-menu-offcanvas-body .dropdown-item-text,
    .account-menu-offcanvas-body > .list-unstyled > li > .dropdown-item,
    .account-menu-offcanvas-body > .list-unstyled > li > .dropdown-item-text {
        min-height: 42px;
        display: flex;
        align-items: center;
        padding: 0.35rem 0.9rem !important;
        font-size: 0.925rem;
    }
    .account-menu-offcanvas-body > .list-unstyled > li.border-bottom {
        padding: 0 !important;
    }
    .account-menu-offcanvas-body > .list-unstyled > li.border-bottom > div {
        padding: 0.4rem 0.9rem !important;
        min-height: 42px;
        display: flex;
        align-items: center;
    }
    .account-menu-offcanvas-body .dropdown-item {
        width: 100%;
        border-radius: 0;
        text-decoration: none;
    }
    .account-menu-offcanvas-body .dropdown-item.active {
        background: rgba(255, 255, 255, 0.12);
        font-weight: 600;
    }
    [data-theme="light"] .account-menu-offcanvas-body .dropdown-item.active {
        background: rgba(0, 0, 0, 0.08);
    }
    .account-menu-offcanvas-body .dropdown-item-text {
        width: 100%;
    }
    .account-menu-offcanvas-body .dropdown-divider {
        margin: 0.15rem 0.9rem !important;
        opacity: 0.6;
    }
    .account-menu-offcanvas-body .border-bottom .fw-bold {
        font-size: 0.925rem;
    }
    .account-menu-offcanvas-body .border-bottom .text-muted {
        font-size: 0.72rem;
    }
    .account-menu-offcanvas-body form {
        margin: 0 !important;
    }
    .account-menu-offcanvas-body form button.dropdown-item {
        padding: 0.35rem 0.9rem !important;
        min-height: 42px;
    }
    /* قسم متصل / غير متصل — شكل أوضح وأنسب للموبايل */
    .account-menu-offcanvas-body .account-menu-status-wrap {
        padding: 0.25rem 0.9rem 0.4rem;
    }
    .account-menu-offcanvas-body .account-menu-status {
        background: rgba(255, 255, 255, 0.06);
        border-radius: 999px;
        padding: 0.5rem 0.85rem !important;
        min-height: 44px;
        display: flex;
        align-items: center;
        border: 1px solid rgba(255, 255, 255, 0.08);
    }
    [data-theme="light"] .account-menu-offcanvas-body .account-menu-status {
        background: rgba(0, 0, 0, 0.04);
        border-color: rgba(0, 0, 0, 0.08);
    }
    .account-menu-offcanvas-body .account-menu-status-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        flex-shrink: 0;
        margin-inline-end: 0.5rem;
    }
    .account-menu-offcanvas-body .account-menu-status-dot.status-online {
        background-color: #28a745;
        box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.35);
    }
    .account-menu-offcanvas-body .account-menu-status-dot.status-offline {
        background-color: #6c757d;
        box-shadow: 0 0 0 2px rgba(108, 117, 125, 0.25);
    }
    .account-menu-offcanvas-body .account-menu-status-label {
        font-size: 0.95rem;
        font-weight: 500;
    }
    .account-menu-offcanvas-body .account-menu-status .form-check-input {
        width: 2.5rem;
        height: 1.35rem;
        cursor: pointer;
    }

    /* Mobile safety fallback: show nav items even if JS fails before removing [hidden] */
    #navbarMain #mainNavList[hidden] {
        display: flex !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    #navbarMain #mainNavList {
        display: flex;
        flex-direction: column;
    }

    #navbarMain .navbar-nav:first-child {
        opacity: 1 !important;
        visibility: visible !important;
        overflow: visible !important;
    }
    header[role="banner"] {
        position: relative;
        z-index: 1080;
    }

    body.public-home header[role="banner"].container-lg {
        margin-top: .25rem !important;
        margin-bottom: .1rem !important;
    }

    body.public-home header[role="banner"] .navbar {
        min-height: 56px;
        padding-top: .2rem !important;
        padding-bottom: .2rem !important;
    }

    .navbar-toggler {
        position: relative;
        z-index: 1082;
        width: 42px;
        height: 42px;
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.22) !important;
    }

    .navbar-toggler .navbar-toggler-icon {
        opacity: .95;
    }

    /* Stable mobile dropdown panel */
    #navbarMain.navbar-collapse {
        position: absolute;
        top: calc(100% + .45rem);
        inset-inline: .5rem;
        width: auto;
        max-height: min(86vh, calc(100dvh - 64px));
        padding: 2.65rem .68rem .72rem;
        overflow-y: auto;
        overflow-x: hidden;
        border-radius: 1.25rem;
        border: 1px solid rgba(255, 255, 255, 0.18);
        background: rgba(10, 16, 30, 0.985) !important;
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45);
        z-index: 1081;
        opacity: 0;
        transform: translateY(-6px);
        transition: opacity .18s ease, transform .18s ease;
    }

    #navbarMain.navbar-collapse.show,
    #navbarMain.navbar-collapse.collapsing {
        opacity: 1;
        transform: translateY(0);
    }

    /* Hard fallback for cases where Bootstrap updates aria-expanded but misses .show */
    .navbar-toggler[aria-expanded="true"] + #navbarMain.navbar-collapse {
        display: block !important;
        opacity: 1 !important;
        transform: translateY(0) !important;
    }

    .navbar-toggler[aria-expanded="false"] + #navbarMain.navbar-collapse:not(.show):not(.collapsing) {
        display: none !important;
    }

    #navbarMain.navbar-collapse.collapsing {
        height: auto !important;
    }

    [data-theme="light"] #navbarMain.navbar-collapse {
        background: rgba(255, 255, 255, 0.995) !important;
        border-color: rgba(25, 135, 84, 0.2);
        box-shadow: 0 16px 34px rgba(16, 24, 40, 0.22);
    }

    body.public-home #navbarMain.navbar-collapse {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        border-radius: 1.1rem !important;
        inset-inline: .5rem !important;
        width: auto !important;
        max-width: none !important;
        box-sizing: border-box !important;
        min-height: 0 !important;
        height: auto !important;
        aspect-ratio: auto !important;
        clip-path: none !important;
    }

    [data-theme="dark"] body.public-home #navbarMain.navbar-collapse {
        background: rgba(8, 12, 24, 0.995) !important;
        border-color: rgba(255, 255, 255, 0.22);
        color: rgba(248, 250, 252, 0.95) !important;
    }

    [data-theme="light"] body.public-home #navbarMain.navbar-collapse,
    html:not([data-theme="dark"]) body.public-home #navbarMain.navbar-collapse {
        background: rgba(255, 255, 255, 0.995) !important;
        border-color: rgba(17, 24, 39, 0.14) !important;
        color: #111827 !important;
    }

    [data-theme="light"] body.public-home #navbarMain .nav-link,
    [data-theme="light"] body.public-home #navbarMain .mobile-drawer-close,
    [data-theme="light"] body.public-home #navbarMain .theme-toggle,
    html:not([data-theme="dark"]) body.public-home #navbarMain .nav-link,
    html:not([data-theme="dark"]) body.public-home #navbarMain .mobile-drawer-close,
    html:not([data-theme="dark"]) body.public-home #navbarMain .theme-toggle {
        color: #111827 !important;
    }

    /* Kill any decorative pseudo layers that can create circular overlays on public hero */
    body.public-home #navbarMain.navbar-collapse::before,
    body.public-home #navbarMain.navbar-collapse::after {
        content: none !important;
        display: none !important;
    }

    #navbarMain .navbar-nav {
        gap: .28rem;
        flex-wrap: nowrap !important;
    }

    .mobile-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: .6rem;
        margin-bottom: .55rem;
        padding: .2rem .2rem .55rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.14);
    }

    [data-theme="light"] .mobile-drawer-header {
        border-bottom-color: rgba(0, 0, 0, 0.12);
    }

    .mobile-drawer-title {
        font-weight: 700;
        font-size: .98rem;
    }

    .mobile-drawer-close {
        width: 36px;
        height: 36px;
        border-radius: 999px;
        border: 1px solid rgba(255, 255, 255, 0.22);
        background: rgba(255, 255, 255, 0.07);
        color: inherit;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-drawer-close-floating {
        position: absolute;
        top: .65rem;
        inset-inline-start: .65rem;
        inset-inline-end: auto;
        z-index: 2;
    }

    html[dir="ltr"] .mobile-drawer-close-floating {
        inset-inline-start: auto;
        inset-inline-end: .65rem;
    }

    [data-theme="light"] .mobile-drawer-close {
        border-color: rgba(0, 0, 0, 0.2);
        background: rgba(0, 0, 0, 0.03);
    }

    #navbarMain .navbar-nav .nav-item {
        width: 100%;
    }

    #navbarMain .navbar-nav .nav-link {
        min-height: 2.3rem;
        width: 100%;
        display: flex;
        align-items: center;
        padding-block: .42rem !important;
        padding-inline: .75rem !important;
        border-radius: .85rem;
        white-space: normal;
        line-height: 1.35;
        font-size: .9rem;
    }

    #navbarMain .navbar-nav.ms-auto .nav-link,
    #navbarMain .navbar-nav.ms-auto .theme-toggle,
    #navbarMain .navbar-nav.ms-auto .lang-toggle {
        justify-content: flex-start !important;
        gap: .55rem;
        text-align: start;
    }

    #navbarMain #userDropdown {
        width: 100% !important;
        height: auto !important;
        border-radius: .85rem !important;
        justify-content: flex-start !important;
        gap: .55rem;
        padding-inline: .9rem !important;
    }

    #navbarMain #userDropdown .status-indicator-nav {
        top: 50% !important;
        inset-inline-end: .9rem !important;
        transform: translateY(-50%) !important;
    }

    .mobile-nav-inline-label {
        display: inline-flex;
        align-items: center;
        font-size: .94rem;
        font-weight: 600;
        line-height: 1.2;
    }

    #navbarMain .navbar-nav.ms-auto {
        margin-top: .5rem;
        padding-top: .55rem;
        border-top: 1px solid rgba(255, 255, 255, 0.14);
    }

    /* Mobile drawer dropdowns: مساحة كافية لعرض كل العناصر (إدارة الحساب، التفضيلات، الدعم، تسجيل الخروج...) */
    #navbarMain .nav-item.dropdown .dropdown-menu,
    #navbarMain .nav-item.dropdown .dropdown-menu.show {
        position: static !important;
        inset: auto !important;
        transform: none !important;
        width: 100% !important;
        min-width: 0 !important;
        margin-top: .3rem !important;
        max-height: min(72vh, 520px) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        border-radius: .8rem !important;
        z-index: 1 !important;
        padding-bottom: 0.5rem !important;
    }

    #navbarMain .nav-item.dropdown #userDropdown + .dropdown-menu,
    #navbarMain .nav-item.dropdown #userDropdown + .dropdown-menu.show {
        max-height: min(78vh, 560px) !important;
    }

    #navbarMain .nav-item.dropdown .dropdown-item {
        padding-top: .5rem !important;
        padding-bottom: .5rem !important;
        padding-inline: 1rem !important;
        font-size: .95rem !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
    }

    #navbarMain .nav-item.dropdown #userDropdown + .dropdown-menu {
        margin-bottom: .25rem;
    }

    [data-theme="light"] #navbarMain .navbar-nav.ms-auto {
        border-top-color: rgba(0, 0, 0, 0.1);
    }

    /* Mobile bottom navigation (high-level pattern: 4 core destinations + More) */
    .mobile-bottom-nav {
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
        width: min(96vw, 460px);
        z-index: 1075;
        display: block;
    }

    .mobile-bottom-nav__shell {
        border-radius: 1.4rem;
        border: 1px solid rgba(255, 255, 255, 0.18);
        background: var(--theme-bg-primary, rgba(16, 22, 40, 0.98));
        box-shadow: 0 16px 30px rgba(0, 0, 0, 0.28);
        padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom, 0px));
    }

    .mobile-bottom-nav__list {
        list-style: none;
        margin: 0;
        padding: 0;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: end;
        gap: .2rem;
    }

    .mobile-bottom-nav__item {
        text-decoration: none;
        color: inherit;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: .15rem;
        min-height: 48px;
        padding: .22rem .15rem;
        border-radius: .8rem;
        border: 0;
        background: transparent;
        width: 100%;
    }

    .mobile-bottom-nav__item i {
        font-size: 1.05rem;
        line-height: 1;
    }

    .mobile-bottom-nav__label {
        font-size: .68rem;
        line-height: 1.1;
        text-align: center;
        white-space: nowrap;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-bottom-nav__item.is-center {
        transform: translateY(-10px);
    }

    .mobile-bottom-nav__item.is-center .mobile-bottom-nav__icon-wrap {
        width: 40px;
        height: 40px;
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(255, 255, 255, 0.24);
        background: var(--theme-bg-secondary, rgba(255, 255, 255, 0.08));
        box-shadow: 0 6px 14px rgba(0, 0, 0, 0.2);
    }

    .mobile-bottom-nav__item.active {
        background: rgba(255, 255, 255, 0.11);
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
        font-weight: 700;
    }

    .mobile-bottom-nav__item.active i,
    .mobile-bottom-nav__item.active .mobile-bottom-nav__label {
        color: #7fc0ff;
    }

    .mobile-bottom-nav__item.is-center.active .mobile-bottom-nav__icon-wrap {
        border-color: rgba(127, 192, 255, 0.65);
        box-shadow: 0 0 0 2px rgba(127, 192, 255, 0.2), 0 6px 14px rgba(0, 0, 0, 0.2);
    }

    [data-theme="light"] .mobile-bottom-nav__shell {
        border-color: rgba(17, 24, 39, 0.14);
        box-shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
    }

    [data-theme="light"] .mobile-bottom-nav__item.active {
        background: rgba(17, 24, 39, 0.06);
        box-shadow: inset 0 0 0 1px rgba(17, 24, 39, 0.16);
    }

    [data-theme="light"] .mobile-bottom-nav__item.active i,
    [data-theme="light"] .mobile-bottom-nav__item.active .mobile-bottom-nav__label,
    html:not([data-theme="dark"]) .mobile-bottom-nav__item.active i,
    html:not([data-theme="dark"]) .mobile-bottom-nav__item.active .mobile-bottom-nav__label {
        color: #0b5ed7;
    }

    body {
        padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px));
    }
}

/* Ensure More button is hidden initially */
#navbarMoreDropdown {
    display: none !important;
}

/* Show More button only when ready and visible */
#navbarMain.navbar-overflow-ready #navbarMoreDropdown[data-visible="true"] {
    display: block !important;
}

@media (min-width: 992px) {
    .navbar-nav.ms-auto {
        align-items: center;
        gap: .3rem;
    }

    #notificationDropdown {
        width: 42px;
        min-width: 42px;
        height: 42px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: .45rem !important;
        border-radius: 999px !important;
        background: transparent;
        border: none;
        box-shadow: none;
        color: #ffffff !important;
    }

    #notificationDropdown .bi-bell {
        font-size: 1.3rem;
        line-height: 1;
        color: inherit;
    }

    #notificationDropdown:hover,
    #notificationDropdown:focus-visible {
        background: rgba(255, 255, 255, 0.08);
    }

    #notificationBadge {
        top: -4px !important;
        right: -4px !important;
        inset-inline-end: auto !important;
        left: auto !important;
        transform: none !important;
        z-index: 2;
        pointer-events: none;
        min-width: 20px;
        height: 20px;
        padding: 0 5px;
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: .72rem;
        font-weight: 700;
        line-height: 1;
        padding-top: 1px;
        border: 2px solid #0b0f17;
    }

    [data-theme="light"] #notificationDropdown,
    html:not([data-theme="dark"]) #notificationDropdown {
        background: transparent;
        border: none;
        box-shadow: none;
        color: #111827 !important;
    }

    [data-theme="light"] #notificationDropdown:hover,
    [data-theme="light"] #notificationDropdown:focus-visible,
    html:not([data-theme="dark"]) #notificationDropdown:hover,
    html:not([data-theme="dark"]) #notificationDropdown:focus-visible {
        background: rgba(0, 0, 0, 0.06);
    }

    [data-theme="light"] #notificationBadge,
    html:not([data-theme="dark"]) #notificationBadge {
        border-color: #ffffff;
    }
}

/* Keep PWA CTA contrast readable across desktop/mobile themes */
#pwa-install-banner {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    z-index: 1080;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

#pwa-install-close {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid rgba(255,255,255,.35);
    background: rgba(15, 23, 42, 0.72);
    color: #ffffff;
}

#pwa-install-close i {
    line-height: 1;
    font-size: .95rem;
}

#pwa-install-btn {
    background: #0b5ed7 !important;
    border-color: #0a58ca !important;
    color: #ffffff !important;
    font-weight: 700 !important;
}

#pwa-install-btn #install-btn-text,
#pwa-install-btn i {
    color: #ffffff !important;
}

/* Mobile: keep PWA CTA compact and visually detached from bottom nav */
@media (max-width: 768px) {
    #pwa-install-banner {
        left: 56% !important;
        transform: translateX(-50%) !important;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 108px) !important;
        max-width: min(92vw, 280px) !important;
    }

    #pwa-install-close {
        width: 34px;
        height: 34px;
        flex: 0 0 34px;
    }

    #pwa-install-btn {
        width: auto !important;
        max-width: min(74vw, 230px) !important;
        min-height: 36px;
        padding: .34rem .82rem !important;
        border-radius: 999px !important;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        gap: .4rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28) !important;
        z-index: 1072 !important;
        font-size: .95rem !important;
    }

    #pwa-install-btn #install-btn-text {
        max-width: 52vw;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Keep scroll-to-top away from bottom-nav actions */
    #scrollToTopBtn,
    .scroll-to-top-btn,
    .scroll-to-top-floating {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 108px) !important;
        inset-inline-end: 12px !important;
        inset-inline-start: auto !important;
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        z-index: 1072 !important;
    }

    /* Chat page: avoid overlap with message composer and bottom nav actions */
    body.is-chat-page #pwa-install-banner,
    body.is-chat-page #pwa-install-btn {
        display: none !important;
    }
}

/* Smart mobile handoff banner: open installed app vs continue in browser */
#open-app-handoff {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 116px);
    width: min(92vw, 420px);
    max-width: 92vw;
    border-radius: 14px;
    padding: .72rem .75rem .68rem;
    z-index: 1073;
    display: none;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#open-app-handoff.show {
    display: block;
}

#open-app-handoff .handoff-title {
    font-weight: 700;
    font-size: .95rem;
    line-height: 1.2;
    margin-bottom: .28rem;
}

#open-app-handoff .handoff-desc {
    font-size: .82rem;
    line-height: 1.35;
    opacity: .92;
    margin-bottom: .58rem;
}

#open-app-handoff .handoff-actions {
    display: flex;
    align-items: center;
    gap: .42rem;
}

#open-app-handoff .handoff-btn {
    min-height: 34px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: .82rem;
    font-weight: 700;
    padding: .36rem .72rem;
    line-height: 1;
    white-space: nowrap;
}

#open-app-handoff .handoff-close {
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
    border-radius: 999px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#open-app-handoff .handoff-hint {
    margin-top: .45rem;
    font-size: .76rem;
    line-height: 1.3;
    opacity: .9;
    display: none;
}

#open-app-handoff .handoff-hint.show {
    display: block;
}

[data-theme="dark"] #open-app-handoff {
    background: rgba(10, 16, 28, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #f8fafc;
}

[data-theme="dark"] #open-app-handoff .handoff-btn-primary {
    background: #2563eb;
    color: #fff;
    border-color: #1d4ed8;
}

[data-theme="dark"] #open-app-handoff .handoff-btn-secondary,
[data-theme="dark"] #open-app-handoff .handoff-close {
    background: rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
    border-color: rgba(255, 255, 255, 0.18);
}

[data-theme="light"] #open-app-handoff,
html:not([data-theme="dark"]) #open-app-handoff {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(17, 24, 39, 0.14);
    color: #111827;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
}

[data-theme="light"] #open-app-handoff .handoff-btn-primary,
html:not([data-theme="dark"]) #open-app-handoff .handoff-btn-primary {
    background: #0b5ed7;
    color: #fff;
    border-color: #0a58ca;
}

[data-theme="light"] #open-app-handoff .handoff-btn-secondary,
[data-theme="light"] #open-app-handoff .handoff-close,
html:not([data-theme="dark"]) #open-app-handoff .handoff-btn-secondary,
html:not([data-theme="dark"]) #open-app-handoff .handoff-close {
    background: rgba(15, 23, 42, 0.06);
    color: #111827;
    border-color: rgba(15, 23, 42, 0.14);
}

@media (max-width: 575.98px) {
    #open-app-handoff {
        width: min(94vw, 420px);
        bottom: calc(env(safe-area-inset-bottom, 0px) + 108px);
        padding: .64rem .66rem .6rem;
    }

    #open-app-handoff .handoff-title {
        font-size: .9rem;
    }

    #open-app-handoff .handoff-desc {
        font-size: .79rem;
    }

    #open-app-handoff .handoff-btn {
        min-height: 33px;
        font-size: .78rem;
        padding: .34rem .62rem;
    }
}
