:root {
    --mobile-bottom-nav-height: 78px;
    --flashchat-layer-call: 1725;
    --flashchat-layer-call-controls: 1735;
}

.nav-rail-btn {
    gap: 6px;
    flex-direction: column;
}

.nav-rail-btn-label {
    display: none;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1;
}

.nav-rail-btn.is-active {
    background: rgba(59, 130, 246, 0.22);
    box-shadow: inset 0 0 0 1px rgba(191, 219, 254, 0.24);
}

.nav-rail-btn[disabled],
.call-action-btn[disabled],
.call-control-btn[disabled] {
    opacity: 0.46;
    pointer-events: none;
}

#chatHeaderActions {
    min-width: 0;
}

.call-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--flashchat-layer-call);
    display: none;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    background:
        radial-gradient(circle at top, rgba(37, 99, 235, 0.24), transparent 28%),
        rgba(2, 6, 23, 0.9);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.call-overlay.active {
    display: flex;
}

.call-sheet {
    width: 100%;
    min-height: 100%;
    border-radius: 0;
    border: 0;
    background:
        radial-gradient(circle at top, rgba(37, 99, 235, 0.2), transparent 30%),
        linear-gradient(180deg, rgba(15, 23, 42, 0.99), rgba(15, 23, 42, 0.96));
    box-shadow: none;
    padding:
        max(32px, env(safe-area-inset-top))
        24px
        calc(32px + env(safe-area-inset-bottom));
    color: #f8fafc;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.incoming-call-avatar,
.call-avatar-fallback {
    width: 84px;
    height: 84px;
    margin: 0 auto 16px;
    border-radius: 26px;
    background: rgba(37, 99, 235, 0.16);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: #dbeafe;
    font-size: 1.7rem;
    font-weight: 800;
}

.incoming-call-avatar img,
.call-avatar-fallback img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.incoming-call-name {
    font-size: 1.2rem;
    font-weight: 800;
    margin-bottom: 6px;
}

.incoming-call-meta {
    color: #93c5fd;
    font-size: 0.92rem;
    line-height: 1.55;
}

.incoming-call-actions {
    display: flex;
    gap: 12px;
    margin-top: 22px;
}

.incoming-call-btn {
    flex: 1;
    min-height: 52px;
    border: 0;
    border-radius: 18px;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
}

.incoming-call-btn.reject {
    background: #ef4444;
}

.incoming-call-btn.accept {
    background: linear-gradient(135deg, #16a34a, #22c55e);
}

.call-modal {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 0;
    overflow: hidden;
    border: 0;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.92));
    box-shadow: none;
}

.call-modal-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #020617;
}

.call-remote-audio {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.call-remote-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px 22px 120px;
    text-align: center;
    color: #dbeafe;
    background:
        radial-gradient(circle at top, rgba(37, 99, 235, 0.18), transparent 32%),
        rgba(15, 23, 42, 0.72);
}

.call-remote-placeholder p {
    max-width: 240px;
    color: #cbd5e1;
    font-size: 0.95rem;
    line-height: 1.55;
}

.call-topbar {
    position: absolute;
    inset: 0 0 auto 0;
    z-index: var(--flashchat-layer-call-controls);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: max(18px, env(safe-area-inset-top)) 18px 12px;
    background: linear-gradient(180deg, rgba(2, 6, 23, 0.78), transparent);
}

.call-topbar-copy {
    min-width: 0;
}

.call-topbar-copy strong {
    display: block;
    font-size: 1.05rem;
    font-weight: 800;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.call-topbar-copy span {
    display: block;
    margin-top: 4px;
    color: #bfdbfe;
    font-size: 0.85rem;
}

.call-topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.call-topbar-btn,
.call-end-inline {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.76);
    color: #fff;
    cursor: pointer;
}

.call-topbar-btn.active {
    background: rgba(37, 99, 235, 0.28);
}

.call-end-inline {
    background: rgba(239, 68, 68, 0.92);
}

.call-status-badge {
    position: absolute;
    top: max(86px, calc(env(safe-area-inset-top) + 64px));
    left: 50%;
    z-index: var(--flashchat-layer-call-controls);
    transform: translateX(-50%);
    border-radius: 999px;
    padding: 8px 14px;
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.2);
    color: #e2e8f0;
    font-size: 0.78rem;
    font-weight: 700;
    backdrop-filter: blur(10px);
}

.call-local-preview {
    position: absolute;
    top: max(72px, calc(env(safe-area-inset-top) + 54px));
    right: 16px;
    z-index: var(--flashchat-layer-call-controls);
    width: 116px;
    height: 154px;
    border-radius: 24px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(15, 23, 42, 0.86);
    box-shadow: 0 18px 42px rgba(2, 6, 23, 0.34);
}

.call-local-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.call-local-preview video.call-video-rotate-fix {
    transform: rotate(90deg) scale(1.34);
    transform-origin: center center;
}

.call-secondary-actions {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: calc(104px + env(safe-area-inset-bottom));
    z-index: var(--flashchat-layer-call-controls);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.call-chip-btn {
    min-height: 42px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(15, 23, 42, 0.72);
    color: #e2e8f0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.call-chip-btn.active {
    background: rgba(37, 99, 235, 0.24);
    border-color: rgba(96, 165, 250, 0.42);
    color: #dbeafe;
}

.call-chip-btn[disabled] {
    opacity: 0.46;
    pointer-events: none;
}

.call-controls {
    position: absolute;
    inset: auto 0 0 0;
    z-index: var(--flashchat-layer-call-controls);
    display: flex;
    justify-content: center;
    gap: 14px;
    padding: 20px 20px calc(18px + env(safe-area-inset-bottom));
    background: linear-gradient(0deg, rgba(2, 6, 23, 0.92), transparent);
}

.call-control-btn {
    width: 58px;
    height: 58px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(30, 41, 59, 0.84);
    color: #fff;
    cursor: pointer;
}

.call-control-btn.active {
    background: rgba(37, 99, 235, 0.22);
    border-color: rgba(96, 165, 250, 0.4);
    color: #dbeafe;
}

.call-control-btn.end {
    border: 0;
    background: #ef4444;
}

.call-modal[data-has-remote-video="true"] .call-remote-placeholder {
    opacity: 0;
    pointer-events: none;
}

.call-modal[data-call-mode="audio"] .call-local-preview,
.call-modal[data-call-mode="audio"] .call-modal-video {
    display: none;
}

.call-modal[data-call-mode="audio"] .call-remote-placeholder {
    opacity: 1;
    pointer-events: auto;
}

.call-overlay.minimized {
    display: block;
    pointer-events: none;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.call-overlay.minimized .call-modal {
    position: fixed;
    top: max(14px, calc(env(safe-area-inset-top) + 8px));
    right: 14px;
    width: min(88vw, 360px);
    height: 220px;
    border-radius: 28px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    overflow: hidden;
    pointer-events: auto;
    box-shadow: 0 24px 60px rgba(2, 6, 23, 0.42);
}

.call-overlay.minimized .call-topbar {
    padding: 12px;
}

.call-overlay.minimized .call-topbar-copy strong {
    font-size: 0.95rem;
}

.call-overlay.minimized .call-topbar-copy span {
    font-size: 0.75rem;
}

.call-overlay.minimized .call-status-badge {
    top: 60px;
    left: 14px;
    transform: none;
    font-size: 0.68rem;
    padding: 6px 10px;
}

.call-overlay.minimized .call-local-preview {
    top: 70px;
    right: 12px;
    width: 72px;
    height: 96px;
    border-radius: 18px;
}

.call-overlay.minimized .call-secondary-actions {
    display: none;
}

.call-overlay.minimized .call-controls {
    justify-content: flex-end;
    gap: 10px;
    padding: 0 12px 12px;
    background: linear-gradient(0deg, rgba(2, 6, 23, 0.9), transparent 88%);
}

.call-overlay.minimized .call-control-btn {
    width: 46px;
    height: 46px;
}

.call-overlay.minimized .call-remote-placeholder {
    align-items: flex-start;
    justify-content: flex-end;
    text-align: left;
    padding: 70px 16px 68px;
    gap: 8px;
}

.call-overlay.minimized .call-avatar-fallback {
    width: 56px;
    height: 56px;
    margin: 0;
    border-radius: 18px;
}

.call-overlay.minimized .call-remote-placeholder p {
    max-width: 180px;
    font-size: 0.82rem;
}

@media (max-width: 767px) {
    .nav-rail {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        min-width: 0;
        height: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
        gap: 12px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        border-right: 0;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        background: linear-gradient(180deg, rgba(30, 64, 175, 0.98), rgba(29, 78, 216, 0.98));
        box-shadow: 0 -14px 36px rgba(2, 6, 23, 0.38);
    }

    .nav-rail-brand,
    #navRailConnCount {
        display: none !important;
    }

    .nav-rail-actions {
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        gap: 8px;
    }

    .nav-rail-btn {
        width: calc(25% - 6px);
        min-width: 0;
        height: 58px;
        border-radius: 18px;
        padding: 8px 4px;
    }

    .nav-rail-btn-label {
        display: block;
    }

    #sidebar {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        transform: none !important;
        overflow: visible;
        pointer-events: none;
    }

    #chatArea {
        width: 100%;
        flex: 1;
        margin-left: 0;
    }

    #sidebarMain {
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
        width: auto;
        max-width: none;
        height: auto;
        margin-left: 0;
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
        border-right: 0;
        box-shadow: 0 20px 42px rgba(2, 6, 23, 0.4);
        z-index: 75;
    }

    #sidebar.chat-open-mobile #sidebarMain {
        transform: translateY(calc(100% + 16px));
        opacity: 0;
        pointer-events: none;
    }

    #sidebar.chat-open-mobile.rail-open #sidebarMain {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-topbar {
        display: grid;
        position: sticky;
        top: 0;
        z-index: 2;
        grid-template-columns: 40px minmax(0, 1fr) 40px;
        gap: 12px;
        padding: 12px 14px;
        padding-top: max(12px, env(safe-area-inset-top));
        justify-content: stretch;
        align-items: center;
    }

    .sidebar-mobile-actions {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        width: 40px;
        gap: 0;
    }

    .sidebar-topbar-copy span {
        display: inline;
    }

    .sidebar-rail-overlay {
        display: block;
        position: fixed;
        inset: 0 0 calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom)) 0;
        background: rgba(15, 23, 42, 0.42);
        backdrop-filter: blur(3px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.24s ease;
        z-index: 70;
    }

    #sidebar.chat-open-mobile.rail-open .sidebar-rail-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    body:not(.chat-mobile-open) #activeChat,
    body:not(.chat-mobile-open) #emptyState {
        padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
    }

    body:not(.chat-mobile-open) #messagesContainer {
        scroll-padding-bottom: calc(220px + var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
    }

    body.chat-mobile-open .nav-rail {
        transform: translateY(calc(100% + 16px)) !important;
        opacity: 0;
        pointer-events: none;
    }

    body.chat-mobile-open #activeChat,
    body.chat-mobile-open #emptyState {
        padding-bottom: 0;
    }

    body.chat-mobile-open #messagesContainer {
        scroll-padding-bottom: calc(170px + env(safe-area-inset-bottom));
    }

    #chatHeaderActions {
        overflow-x: auto;
        scrollbar-width: none;
        padding-bottom: 2px;
    }

    #chatHeaderActions::-webkit-scrollbar {
        display: none;
    }

    .call-modal {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .call-local-preview {
        width: 92px;
        height: 124px;
        right: 12px;
    }

    .call-secondary-actions {
        left: 12px;
        right: 12px;
        bottom: calc(96px + env(safe-area-inset-bottom));
        gap: 8px;
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }

    .call-secondary-actions::-webkit-scrollbar {
        display: none;
    }

    .call-chip-btn {
        flex: 0 0 auto;
    }

    .call-overlay.minimized .call-modal {
        top: auto;
        bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom) + 12px);
        right: 12px;
        width: min(92vw, 330px);
        height: 196px;
    }
}
