/* ═══════════════════════════════════════════════════════════════════════════
   call-floater.css — In-page floating call window
   Modes: expanded (full-screen mobile / modal desktop) + PiP mini-bubble
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Root shell ─────────────────────────────────────────────────────────── */
#callFloater {
    position: fixed;
    z-index: 9980;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    pointer-events: none; /* children opt-in */
    /* transition applied on the wrapper for pip ↔ expand */
    transition: width .32s cubic-bezier(.4,0,.2,1),
                height .32s cubic-bezier(.4,0,.2,1),
                border-radius .32s cubic-bezier(.4,0,.2,1),
                right .32s cubic-bezier(.4,0,.2,1),
                bottom .32s cubic-bezier(.4,0,.2,1),
                top .32s cubic-bezier(.4,0,.2,1),
                left .32s cubic-bezier(.4,0,.2,1),
                box-shadow .32s ease;
    will-change: transform;
}

#callFloater * { box-sizing: border-box; }

/* ── Expanded state ─────────────────────────────────────────────────────── */
#callFloater.cf-expanded {
    pointer-events: all;
    /* Mobile: fullscreen */
    top: 0; right: 0; bottom: 0; left: 0;
    width: 100%; height: 100%;
    border-radius: 0;
    background: #000;
    overflow: hidden;
    box-shadow: none;
}

@media (min-width: 600px) {
    #callFloater.cf-expanded {
        top: auto; left: auto;
        right: 16px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 72px);
        width: 360px;
        height: 580px;
        border-radius: 20px;
        box-shadow: 0 24px 80px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.08);
    }
}

/* ── PiP (minimized) state ──────────────────────────────────────────────── */
#callFloater.cf-pip {
    pointer-events: all;
    right: 16px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
    width: 140px;
    height: 188px;
    border-radius: 16px;
    background: #111;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 12px 40px rgba(0,0,0,.5), 0 0 0 2px rgba(255,255,255,.12);
    top: auto; left: auto;
    transition: transform .15s ease, box-shadow .15s ease;
}

#callFloater.cf-pip:hover {
    transform: scale(1.04);
    box-shadow: 0 16px 50px rgba(0,0,0,.6), 0 0 0 2px rgba(255,255,255,.2);
}

/* Dragging state */
#callFloater.cf-dragging {
    transition: none;
    cursor: grabbing !important;
    box-shadow: 0 28px 90px rgba(0,0,0,.7), 0 0 0 2px rgba(255,255,255,.18) !important;
    transform: scale(1.03);
}

/* ── Hidden state ───────────────────────────────────────────────────────── */
#callFloater.cf-hidden { display: none; }

/* ── Remote video — fills entire floater ───────────────────────────────── */
.cf-remote-video {
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: center;
    background: #000;
    display: none; /* shown when stream arrives */
}
.cf-remote-video.active { display: block; }

/* Remote audio */
.cf-remote-audio { display: none; }

/* ── Avatar background (voice calls / no remote video yet) ─────────────── */
.cf-avatar-bg {
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 40%, #0f3460 100%);
    flex-direction: column;
    gap: 14px;
}

.cf-avatar-circle {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 0 0 8px rgba(99,102,241,.18), 0 8px 32px rgba(99,102,241,.3);
    position: relative;
}

/* Pulse ring animation on avatar during ringing */
.cf-avatar-circle.pulsing::before {
    content: '';
    position: absolute;
    top: -10px; right: -10px; bottom: -10px; left: -10px;
    border-radius: 50%;
    border: 2px solid rgba(99,102,241,.4);
    animation: cfPulse 1.4s ease-out infinite;
}
.cf-avatar-circle.pulsing::after {
    content: '';
    position: absolute;
    top: -20px; right: -20px; bottom: -20px; left: -20px;
    border-radius: 50%;
    border: 2px solid rgba(99,102,241,.2);
    animation: cfPulse 1.4s ease-out .4s infinite;
}

@keyframes cfPulse {
    0%   { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.35); opacity: 0; }
}

.cf-avatar-name-label {
    color: rgba(255,255,255,.7);
    font-size: 15px;
    font-weight: 500;
}

/* ── Gradient overlays ──────────────────────────────────────────────────── */
.cf-grad-top {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 140px;
    background: linear-gradient(to bottom, rgba(0,0,0,.72) 0%, transparent 100%);
    pointer-events: none;
}

.cf-grad-bottom {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 180px;
    background: linear-gradient(to top, rgba(0,0,0,.85) 0%, transparent 100%);
    pointer-events: none;
}

/* ── Top bar ────────────────────────────────────────────────────────────── */
.cf-topbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 14px;
    padding-top: max(14px, calc(env(safe-area-inset-top, 0px) + 8px));
    color: #fff;
    z-index: 10;
}

.cf-topbar-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    flex-shrink: 0;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background .15s, transform .1s;
}
.cf-topbar-btn:active { transform: scale(.92); }
.cf-topbar-btn:hover  { background: rgba(255,255,255,.22); }

.cf-topbar-center {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.cf-contact-name {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cf-status-label {
    font-size: 12px;
    color: rgba(255,255,255,.65);
    margin-top: 2px;
}

.cf-timer {
    font-size: 13px;
    color: rgba(255,255,255,.8);
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
    letter-spacing: .02em;
}

/* Quality signal indicator */
.cf-quality-badge {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
    background: rgba(255,255,255,.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #4ade80;
    border: 1.5px solid rgba(74,222,128,.35);
    cursor: pointer;
}

/* ── Self-view (local video PiP) ────────────────────────────────────────── */
.cf-selfview {
    position: absolute;
    top: 80px;
    right: 12px;
    width: 88px;
    height: 120px;
    border-radius: 12px;
    overflow: hidden;
    background: #222;
    z-index: 12;
    box-shadow: 0 4px 16px rgba(0,0,0,.5), 0 0 0 1.5px rgba(255,255,255,.14);
    cursor: move;
    touch-action: none;
    transition: opacity .2s;
}
.cf-selfview video {
    width: 100%; height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}
.cf-selfview.video-off { background: #1a1a1a; }
.cf-selfview.video-off video { display: none; }

/* ── Controls bar ───────────────────────────────────────────────────────── */
.cf-controls {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 16px 20px;
    padding-bottom: max(24px, calc(env(safe-area-inset-bottom, 0px) + 16px));
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    z-index: 12;
    transition: opacity .3s ease, transform .3s ease;
}

.cf-controls.cf-auto-hide {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

/* Individual control button */
.cf-ctrl {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    background: rgba(255,255,255,.16);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1.5px solid rgba(255,255,255,.12);
    border-radius: 18px;
    color: #fff;
    padding: 12px;
    width: 60px;
    font-size: 18px;
    cursor: pointer;
    transition: background .15s, transform .1s, border-color .15s;
    touch-action: manipulation;
    user-select: none;
}

.cf-ctrl span {
    font-size: 9px;
    font-weight: 500;
    letter-spacing: .02em;
    color: rgba(255,255,255,.75);
    line-height: 1;
}

.cf-ctrl:active { transform: scale(.9); }

.cf-ctrl:hover {
    background: rgba(255,255,255,.24);
    border-color: rgba(255,255,255,.2);
}

/* Active/muted state */
.cf-ctrl.active {
    background: rgba(255,255,255,.9);
    color: #000;
    border-color: transparent;
}
.cf-ctrl.active span { color: rgba(0,0,0,.65); }

/* End call button */
.cf-ctrl.cf-end {
    background: #ef4444;
    border-color: transparent;
    box-shadow: 0 4px 16px rgba(239,68,68,.45);
}
.cf-ctrl.cf-end:hover { background: #dc2626; }
.cf-ctrl.cf-end:active { transform: scale(.88); }

/* Video-only controls hidden during voice call */
.cf-controls.voice-call .cf-video-only { display: none; }

/* ── Ringing (incoming) sheet ───────────────────────────────────────────── */
.cf-ring-sheet {
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 32px 24px;
    padding-top: max(32px, calc(env(safe-area-inset-top, 0px) + 20px));
    padding-bottom: max(40px, calc(env(safe-area-inset-bottom, 0px) + 32px));
    z-index: 20;
}

.cf-ring-sheet .cf-ring-label {
    font-size: 13px;
    color: rgba(255,255,255,.65);
    letter-spacing: .04em;
    text-transform: uppercase;
    font-weight: 500;
}

.cf-ring-sheet .cf-ring-name {
    font-size: 26px;
    font-weight: 700;
    color: #fff;
    text-align: center;
}

.cf-ring-sheet .cf-ring-type {
    font-size: 14px;
    color: rgba(255,255,255,.6);
}

.cf-ring-actions {
    display: flex;
    gap: 52px;
    margin-top: 24px;
}

.cf-ring-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    font-size: 24px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    transition: transform .12s, box-shadow .12s;
}
.cf-ring-btn:active { transform: scale(.88); }

.cf-ring-accept {
    background: #22c55e;
    box-shadow: 0 6px 20px rgba(34,197,94,.5);
    animation: cfRingBounce .8s ease-in-out infinite alternate;
}
@keyframes cfRingBounce {
    from { transform: translateY(0); box-shadow: 0 6px 20px rgba(34,197,94,.5); }
    to   { transform: translateY(-8px); box-shadow: 0 14px 30px rgba(34,197,94,.45); }
}

.cf-ring-reject {
    background: #ef4444;
    box-shadow: 0 6px 20px rgba(239,68,68,.45);
}

/* ── Ringing out state ─────────────────────────────────────────────────── */
.cf-calling-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: rgba(255,255,255,.6);
    font-size: 14px;
}

.cf-calling-dots span {
    display: inline-block;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: rgba(255,255,255,.7);
    animation: cfDot 1.2s ease-in-out infinite;
}
.cf-calling-dots span:nth-child(2) { animation-delay: .15s; }
.cf-calling-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes cfDot {
    0%, 80%, 100% { opacity: .25; transform: scale(.8); }
    40%            { opacity: 1;   transform: scale(1.2); }
}

.cf-cancel-btn {
    margin-top: 32px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #ef4444;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(239,68,68,.45);
    transition: transform .12s;
}
.cf-cancel-btn:active { transform: scale(.88); }

/* ── PiP overlay (shown over video in pip mode) ─────────────────────────── */
.cf-pip-overlay {
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    background: linear-gradient(to bottom, rgba(0,0,0,.4) 0%, transparent 45%, rgba(0,0,0,.7) 100%);
    z-index: 15;
}

#callFloater.cf-pip .cf-pip-overlay { display: flex; }

.cf-pip-meta {
    width: 100%;
    text-align: center;
}

.cf-pip-name {
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 4px rgba(0,0,0,.6);
}

.cf-pip-timer {
    font-size: 10px;
    color: rgba(255,255,255,.8);
    font-variant-numeric: tabular-nums;
    margin-top: 1px;
    text-shadow: 0 1px 4px rgba(0,0,0,.6);
}

.cf-pip-end-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(239,68,68,.9);
    border: none;
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(0,0,0,.4);
    transition: transform .1s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.cf-pip-end-btn:active { transform: scale(.88); }

/* ── Expand hint on tap in pip mode ─────────────────────────────────────── */
#callFloater.cf-pip .cf-expand-hint {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 9px;
    color: rgba(255,255,255,.5);
    white-space: nowrap;
    pointer-events: none;
    z-index: 14;
    display: none;
}
#callFloater.cf-pip:hover .cf-expand-hint { display: block; }

/* Hide the full-call UI elements in pip mode */
#callFloater.cf-pip .cf-topbar,
#callFloater.cf-pip .cf-grad-top,
#callFloater.cf-pip .cf-grad-bottom,
#callFloater.cf-pip .cf-controls,
#callFloater.cf-pip .cf-selfview,
#callFloater.cf-pip .cf-ring-sheet,
#callFloater.cf-pip .cf-avatar-bg > :not(.cf-avatar-circle) { display: none; }

/* Show pip-specific avatar (smaller) */
#callFloater.cf-pip .cf-avatar-bg {
    background: linear-gradient(145deg, #1a1a2e, #0f3460);
}

#callFloater.cf-pip .cf-avatar-circle {
    width: 52px;
    height: 52px;
    font-size: 22px;
    box-shadow: none;
}

#callFloater.cf-pip .cf-avatar-circle.pulsing::before,
#callFloater.cf-pip .cf-avatar-circle.pulsing::after { display: none; }

#callFloater.cf-pip .cf-avatar-name-label { display: none; }

/* ── Ringing-in full-screen backdrop ────────────────────────────────────── */
#callFloater.cf-ringing-in.cf-expanded .cf-avatar-bg {
    background: linear-gradient(165deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
}

/* ── Connected shimmer bar (while ICE negotiating) ──────────────────────── */
.cf-connecting-bar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, #6366f1, #8b5cf6, transparent);
    background-size: 200% 100%;
    animation: cfSlide 1.4s ease-in-out infinite;
    z-index: 20;
}
@keyframes cfSlide {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Fade-in/out enter animations ────────────────────────────────────────── */
@keyframes cfSlideUp {
    from { opacity: 0; transform: translateY(32px); }
    to   { opacity: 1; transform: translateY(0); }
}

#callFloater.cf-expanded { animation: cfSlideUp .28s cubic-bezier(.4,0,.2,1); }

/* No animation on pip (feels cheaper) */
#callFloater.cf-pip { animation: none; }

/* ── Ringing states: the ring/calling sheets are the whole UI ───────────── */
/* They overlay the avatar layer and controls bar transparently, so hide    */
/* those or the user sees a duplicate avatar/name plus call controls        */
/* before the call is even accepted.                                        */
/* > child combinator: the ring sheet nests its own .cf-avatar-circle,
   which must stay visible — only the floater's top-level avatar layer
   contents are duplicates. The gradient backdrop itself is kept. */
#callFloater.cf-ringing-in .cf-controls,
#callFloater.cf-ringing-out .cf-controls,
#callFloater.cf-ringing-in.cf-expanded .cf-topbar,
#callFloater.cf-ringing-out.cf-expanded .cf-topbar,
#callFloater.cf-ringing-in.cf-expanded > .cf-avatar-bg > .cf-avatar-circle,
#callFloater.cf-ringing-in.cf-expanded > .cf-avatar-bg > .cf-avatar-name-label,
#callFloater.cf-ringing-out.cf-expanded > .cf-avatar-bg > .cf-avatar-circle,
#callFloater.cf-ringing-out.cf-expanded > .cf-avatar-bg > .cf-avatar-name-label { display: none; }
