:root {
    --z-layer-content: 1;
    --z-layer-sticky: 20;
    --z-layer-dropdown: 100;
    --z-layer-drawer: 1300;
    --z-layer-rtc-pill: 1500;
    --z-layer-modal: 1600;
    --z-layer-critical: 1700;
    --znode-bottom-obstruction-height: 0px;
}

.znode-surface-content {
    display: contents;
}

.znode-live-session-portal {
    position: fixed;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: var(--z-layer-rtc-pill);
    display: grid;
    gap: 8px;
    max-width: min(340px, calc(100vw - 28px));
    pointer-events: none;
}

.znode-live-session-portal[hidden] {
    display: none;
}

body:has(:is([role="dialog"]:not(.screen-share-viewer-shell), .attachment-action-modal):not([hidden])) .znode-live-session-portal {
    width: min(230px, calc(100vw - 24px)) !important;
    max-width: min(230px, calc(100vw - 24px));
    z-index: var(--z-layer-critical);
    pointer-events: none;
}

body:has(:is([role="dialog"]:not(.screen-share-viewer-shell), .attachment-action-modal):not([hidden])) .znode-live-session-pill {
    width: 100%;
    min-width: 0;
    min-height: 52px;
}

body:has(:is([role="dialog"]:not(.screen-share-viewer-shell), .attachment-action-modal):not([hidden])) .znode-live-session-action {
    display: none;
}

.znode-live-session-portal[data-positioned="true"] {
    right: auto;
    bottom: auto;
    width: min(340px, calc(100vw - 24px));
    max-width: min(340px, calc(100vw - 24px));
}

.znode-live-session-portal[data-dragging="true"] {
    will-change: transform;
}

.znode-group-call-tray {
    position: fixed;
    left: 50%;
    top: max(12px, env(safe-area-inset-top));
    z-index: var(--z-layer-drawer);
    transform: translateX(-50%);
    display: block;
    pointer-events: auto;
}

.znode-group-call-tray[hidden] {
    display: none;
}

.znode-group-call-tray-list {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.znode-group-call-avatar-button {
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: color-mix(in srgb, var(--zn-member-bg-card, #111821) 94%, transparent);
    color: var(--zn-member-text-primary, #f5f7fa);
    box-shadow:
        0 0 0 2px color-mix(in srgb, var(--zn-member-accent-border-strong, #31b6d9) 72%, transparent),
        0 12px 30px rgba(0, 0, 0, 0.32);
    cursor: pointer;
    overflow: hidden;
}

.znode-group-call-avatar-image,
.znode-group-call-avatar-fallback {
    width: 100%;
    height: 100%;
}

.znode-group-call-avatar-image {
    display: block;
    object-fit: cover;
}

.znode-group-call-avatar-fallback {
    display: grid;
    place-items: center;
    font-size: 0.9rem;
    font-weight: 800;
}

.znode-group-call-avatar-button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.znode-live-session-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: min(320px, calc(100vw - 28px));
    min-height: 58px;
    padding: 6px;
    border: 1px solid color-mix(in srgb, var(--zn-member-border-soft, #435066) 86%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--zn-member-bg-card, #111821) 94%, transparent);
    color: var(--zn-member-text-primary, #f5f7fa);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(18px);
    pointer-events: auto;
}

.znode-live-session-pill[data-dragging="true"] {
    user-select: none;
    cursor: grabbing;
}

.znode-live-session-pill[data-status="recovering"],
.znode-live-session-pill[data-status="reconnecting"] {
    border-color: color-mix(in srgb, #e7b84b 72%, transparent);
}

.znode-live-session-pill[data-memo-status="requested"],
.znode-live-session-pill[data-memo-status="starting"],
.znode-live-session-pill[data-memo-status="recording"] {
    box-shadow: inset 3px 0 0 #ef4444;
}

.znode-live-session-return {
    display: grid;
    grid-template-columns: 14px 42px minmax(0, 1fr);
    align-items: center;
    gap: 9px;
    min-width: 0;
    min-height: 44px;
    flex: 1 1 auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.znode-live-session-drag-grip {
    display: block;
    width: 14px;
    height: 28px;
    border-radius: 7px;
    background-image: radial-gradient(circle, currentColor 1.4px, transparent 1.7px);
    background-position: 0 0;
    background-size: 7px 7px;
    color: color-mix(in srgb, var(--zn-member-text-muted, #aab4c2) 82%, transparent);
    opacity: 0.84;
    touch-action: none;
}

.znode-live-session-pill[data-dragging="true"] .znode-live-session-return {
    cursor: grabbing;
}

.znode-live-session-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--zn-member-accent-border-strong, #31b6d9);
    color: var(--zn-member-primary-text, #071014);
    font-size: 0.9rem;
    overflow: hidden;
}

.znode-live-session-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.znode-live-session-avatar-fallback {
    display: grid;
    width: 100%;
    height: 100%;
    place-items: center;
}

.znode-live-session-copy {
    min-width: 0;
    display: grid;
    gap: 2px;
    line-height: 1.1;
}

.znode-live-session-copy strong,
.znode-live-session-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.znode-live-session-copy strong {
    font-size: 0.86rem;
}

.znode-live-session-copy span {
    color: var(--zn-member-text-muted, #aab4c2);
    font-size: 0.7rem;
    font-weight: 700;
}

.znode-live-session-action {
    display: grid;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    place-items: center;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--zn-member-border-soft, #435066) 86%, transparent);
    border-radius: 50%;
    background: color-mix(in srgb, var(--zn-member-bg-soft, #202a36) 94%, transparent);
    color: #fff;
    cursor: pointer;
}

.znode-live-session-action svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.znode-live-session-mute[data-active="true"] {
    border-color: color-mix(in srgb, #e7b84b 72%, transparent);
    background: color-mix(in srgb, #e7b84b 24%, var(--zn-member-bg-soft, #202a36));
}

.znode-live-session-end {
    border-color: color-mix(in srgb, #e5484d 62%, transparent);
    background: color-mix(in srgb, #e5484d 88%, #111 12%);
}

.znode-live-session-action:disabled {
    cursor: wait;
    opacity: 0.62;
}

.znode-live-session-return:focus-visible,
.znode-live-session-action:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.znode-surface-navigation-error {
    position: fixed;
    left: 50%;
    top: max(14px, env(safe-area-inset-top));
    z-index: var(--z-layer-modal);
    width: min(620px, calc(100vw - 28px));
    transform: translateX(-50%);
    padding: 11px 14px;
    border: 1px solid color-mix(in srgb, #e5484d 56%, transparent);
    border-radius: 7px;
    background: #241417;
    color: #fff0f1;
    box-shadow: 0 14px 42px rgba(0, 0, 0, 0.32);
    font-size: 0.82rem;
    font-weight: 700;
}

.znode-surface-navigation-error[hidden] {
    display: none;
}

@media (max-width: 620px) {
    body.user-body-messaging {
        --znode-bottom-obstruction-height: var(--znode-composer-height, var(--composer-height, 88px));
    }

    .znode-live-session-portal {
        left: max(12px, env(safe-area-inset-left));
        right: max(12px, env(safe-area-inset-right));
        bottom: calc(
            max(
                var(--znode-mobile-nav-height, var(--bottom-nav-height, 78px)),
                var(--znode-bottom-obstruction-height, 0px)
            )
            + max(12px, env(safe-area-inset-bottom))
            + var(--znode-viewport-bottom-inset, 0px)
            + 12px
        );
        max-width: none;
    }

    .znode-live-session-pill {
        min-width: 0;
        width: 100%;
    }

    .znode-live-session-portal[data-positioned="true"] {
        width: min(300px, calc(100vw - 24px));
        max-width: min(300px, calc(100vw - 24px));
    }

    html[data-keyboard-open="true"] .znode-live-session-portal {
        left: auto;
        width: auto;
    }

    html[data-keyboard-open="true"] .znode-live-session-pill {
        width: auto;
        min-width: 0;
    }

    html[data-keyboard-open="true"] .znode-live-session-copy {
        display: none;
    }

    .znode-group-call-tray {
        top: max(10px, env(safe-area-inset-top));
    }
}

/* Surface transition ownership. Theme values are consumed here, while the
   component behavior stays with the shared app shell. */
.znode-surface-stage {
    position: relative;
    perspective: 1400px;
    perspective-origin: center center;
}

.znode-surface-stage.is-surface-flip-lock {
    overflow: hidden;
}

.znode-surface-shell {
    position: relative;
    isolation: isolate;
    transform: translate3d(0, 0, 0) rotateY(0deg) scale(1);
    transform-origin: center center;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    will-change: transform, opacity;
    transition:
        transform 440ms cubic-bezier(.18, .86, .18, 1),
        opacity 300ms ease;
}

.znode-surface-shell.is-surface-flip-live-hidden {
    visibility: hidden;
}

.znode-surface-shell::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 2147483000;
    border-radius: inherit;
    background:
        linear-gradient(
            112deg,
            transparent 0%,
            transparent 34%,
            rgba(255, 255, 255, 0.11) 48%,
            transparent 64%,
            transparent 100%
        );
    opacity: 0;
    pointer-events: none;
    transform: translate3d(-16%, 0, 0);
    transition:
        opacity 300ms ease,
        transform 440ms cubic-bezier(.18, .86, .18, 1);
}

.znode-surface-shell.is-surface-flip-out {
    transform: translate3d(14px, 0, -24px) rotateY(78deg) scale(0.975);
    opacity: 0.34;
    pointer-events: none;
}

.znode-surface-shell.is-surface-flip-in {
    transform: translate3d(-14px, 0, -24px) rotateY(-78deg) scale(0.975);
    opacity: 0.34;
}

.znode-surface-shell.is-surface-flip-out.is-surface-flip-to-user {
    transform: translate3d(-14px, 0, -24px) rotateY(-78deg) scale(0.975);
}

.znode-surface-shell.is-surface-flip-in.is-surface-flip-to-user {
    transform: translate3d(14px, 0, -24px) rotateY(78deg) scale(0.975);
}

.znode-surface-shell.is-surface-flip-ready {
    transform: translate3d(0, 0, 0) rotateY(0deg) scale(1);
    opacity: 1;
}

.znode-surface-shell.is-surface-flip-out::before,
.znode-surface-shell.is-surface-flip-in::before {
    opacity: 1;
    transform: translate3d(18%, 0, 0);
}

.znode-surface-shell.is-surface-flip-ready::before {
    opacity: 0;
    transform: translate3d(38%, 0, 0);
}

.znode-surface-flip-scene {
    --zn-surface-flip-dir: 1;
    position: fixed;
    inset: 0;
    z-index: 2147483400;
    overflow: hidden;
    perspective: 1500px;
    perspective-origin: center center;
    background: var(--zn-bg-app, #f6f7fa);
    pointer-events: none;
    contain: layout paint style;
}

.znode-surface-flip-scene.znode-surface-flip-to-user {
    --zn-surface-flip-dir: -1;
}

.znode-surface-flip-face {
    position: absolute;
    inset: 0;
    overflow: hidden;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    will-change: transform, opacity;
}

.znode-surface-flip-face > .znode-surface-shell {
    min-height: 100vh;
}

.znode-surface-flip-face-target {
    opacity: 0;
    transform: translate3d(calc(var(--zn-surface-flip-dir) * 34px), 0, -42px)
        rotateY(calc(var(--zn-surface-flip-dir) * 92deg))
        scale(0.975);
}

.znode-surface-flip-scene.is-surface-flip-running .znode-surface-flip-face-current {
    animation: znode-surface-current-flip-out 820ms cubic-bezier(.22, .82, .18, 1) forwards;
}

.znode-surface-flip-scene.is-surface-flip-running .znode-surface-flip-face-target {
    animation: znode-surface-target-flip-in 820ms cubic-bezier(.22, .82, .18, 1) forwards;
}

@keyframes znode-surface-current-flip-out {
    0% {
        opacity: 1;
        transform: translate3d(0, 0, 0) rotateY(0deg) scale(1);
    }

    42% {
        opacity: 0.18;
        transform: translate3d(calc(var(--zn-surface-flip-dir) * -24px), 0, -34px)
            rotateY(calc(var(--zn-surface-flip-dir) * -88deg))
            scale(0.98);
    }

    100% {
        opacity: 0;
        transform: translate3d(calc(var(--zn-surface-flip-dir) * -42px), 0, -64px)
            rotateY(calc(var(--zn-surface-flip-dir) * -108deg))
            scale(0.965);
    }
}

@keyframes znode-surface-target-flip-in {
    0%,
    36% {
        opacity: 0;
        transform: translate3d(calc(var(--zn-surface-flip-dir) * 34px), 0, -42px)
            rotateY(calc(var(--zn-surface-flip-dir) * 92deg))
            scale(0.975);
    }

    48% {
        opacity: 0.72;
    }

    100% {
        opacity: 1;
        transform: translate3d(0, 0, 0) rotateY(0deg) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .znode-surface-shell {
        transition: none !important;
        transform: none !important;
        opacity: 1 !important;
    }

    .znode-surface-shell::before {
        display: none !important;
    }

    .znode-surface-flip-scene {
        display: none !important;
    }
}

/* In-app notification ownership. Theme custom properties define appearance;
   shell components own layout, interaction, and responsive behavior. */
.in-app-toast-container {
    position: fixed;
    right: max(18px, env(safe-area-inset-right));
    top: max(18px, env(safe-area-inset-top));
    z-index: 1200;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    width: min(380px, calc(100vw - 28px));
    pointer-events: none;
}

.in-app-toast {
    width: 100%;
    border: 1px solid var(--zn-border-strong);
    border-left: 3px solid var(--zn-accent);
    border-radius: 8px;
    padding: 11px 12px;
    background: var(--zn-bg-surface-elevated);
    background: color-mix(in srgb, var(--zn-bg-surface-elevated) 94%, black);
    box-shadow: var(--zn-shadow);
    color: var(--zn-text-primary);
    pointer-events: auto;
}

.in-app-toast.is-clickable {
    cursor: pointer;
}

.in-app-toast.is-clickable:hover,
.in-app-toast.is-clickable:focus-visible {
    border-color: var(--zn-accent-border);
    outline: none;
    box-shadow: var(--zn-shadow), 0 0 0 3px var(--zn-accent-soft);
}

.in-app-toast.severity-warn {
    border-left-color: var(--zn-warning);
}

.in-app-toast.severity-error,
.in-app-toast.severity-urgent {
    border-left-color: var(--zn-danger);
}

.in-app-toast-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 5px;
}

.in-app-toast-source,
.in-app-toast-action {
    color: var(--zn-text-secondary);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.in-app-toast-action {
    color: var(--zn-text-primary);
    letter-spacing: 0;
    text-transform: none;
}

.in-app-toast-title {
    display: block;
    color: var(--zn-text-primary);
    font-size: 0.86rem;
    font-weight: 800;
    line-height: 1.25;
}

.in-app-toast-detail {
    display: block;
    margin-top: 3px;
    color: var(--zn-text-secondary);
    font-size: 0.78rem;
    line-height: 1.35;
}

.flash-banner-success,
.flash-banner-error,
.flash-banner-warning {
    display: none;
}

.surface-switcher-link.has-in-app-activity,
.user-bottom-nav-link.has-in-app-activity,
.sidebar-link.has-in-app-activity {
    position: relative;
    border-color: var(--zn-warning-border, var(--zn-accent-border));
    box-shadow: inset 0 1px 0 var(--zn-surface-glint-soft), 0 0 0 1px var(--zn-warning-soft, var(--zn-accent-soft));
}

.surface-switcher-link.has-in-app-activity::before,
.user-bottom-nav-link.has-in-app-activity::before,
.sidebar-link.has-in-app-activity::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--zn-warning);
    box-shadow: 0 0 0 3px var(--zn-warning-soft), 0 0 18px var(--zn-warning);
}

.surface-switcher-link.has-in-app-activity::before,
.user-bottom-nav-link.has-in-app-activity::before {
    top: 5px;
    right: 7px;
}

.sidebar-link.has-in-app-activity::after {
    top: 10px;
    right: 10px;
}

.surface-switcher-link[data-in-app-severity="error"]::before,
.surface-switcher-link[data-in-app-severity="urgent"]::before,
.user-bottom-nav-link[data-in-app-severity="error"]::before,
.user-bottom-nav-link[data-in-app-severity="urgent"]::before,
.sidebar-link[data-in-app-severity="error"]::after,
.sidebar-link[data-in-app-severity="urgent"]::after {
    background: var(--zn-danger);
    box-shadow: 0 0 0 3px var(--zn-danger-soft), 0 0 18px var(--zn-danger);
}

@media (max-width: 720px) {
    .in-app-toast-container {
        right: 12px;
        top: max(12px, env(safe-area-inset-top));
        width: calc(100vw - 24px);
    }

    .in-app-toast {
        padding: 10px 11px;
    }
}
