/*
 * Shared video-call UI styling for portal.html, join.html and call.html.
 * Industry-standard meeting layout: full-bleed video stage, speaker view with
 * picture-in-picture self view, translucent overlay control bars, and support
 * for immersive (default), windowed (pop-out card) and browser-fullscreen modes.
 */

/* ============================ Modal / stage shell ============================ */

.pl-call-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    background: #000;
    touch-action: manipulation;
}

.pl-call-modal.hidden {
    display: none;
}

.pl-call-container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-height: 100dvh;
    overflow: hidden;
    background: #000;
}

.call-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    background: #000;
}

/* Windowed (pop-out) card — only meaningful on larger screens. */
@media (min-width: 768px) {
    .pl-call-modal.call-windowed {
        align-items: center;
        justify-content: center;
        padding: 1.5rem;
        background: rgba(0, 0, 0, 0.88);
    }
    .pl-call-modal.call-windowed .pl-call-container {
        width: 100%;
        max-width: 1120px;
        height: auto;
        aspect-ratio: 16 / 9;
        max-height: min(calc(100dvh - 3rem), 780px);
        border-radius: 1rem;
        box-shadow: 0 30px 90px rgba(0, 0, 0, 0.65);
    }
}

/* Browser Fullscreen API target fills the monitor regardless of mode. */
.pl-call-container:fullscreen,
.pl-call-container:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: 100vh;
    aspect-ratio: auto;
    border-radius: 0;
    box-shadow: none;
}

/* ============================ Video layouts ============================ */

#videoCallLayout {
    flex: 1 1 auto;
    min-height: 0;
}

.video-cell {
    position: relative;
    min-height: 0;
    border-radius: 0.75rem;
    overflow: hidden;
    background: #0b0f17;
}

.pl-call-modal .call-video,
.pl-call-modal #localVideo,
.pl-call-modal #remoteVideo {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #0b0f17;
    color: #6b7280;
    font-size: 0.85rem;
    text-align: center;
}

/* Agora injects a wrapper + <video>/<canvas>; force it to fill the tile. */
.pl-call-modal #localVideo video,
.pl-call-modal #localVideo canvas,
.pl-call-modal #remoteVideo video,
.pl-call-modal #remoteVideo canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Speaker view: remote fills the stage, self view is a floating PiP. */
.video-layout-speaker {
    position: absolute;
    inset: 0;
}
.video-layout-speaker .remote-cell {
    position: absolute;
    inset: 0;
    border-radius: 0;
}
.video-layout-speaker .local-cell {
    position: absolute;
    right: 1rem;
    bottom: 6rem;
    width: clamp(108px, 20vw, 192px);
    aspect-ratio: 4 / 3;
    border-radius: 0.85rem;
    border: 2px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    z-index: 6;
}
.video-layout-speaker .pl-tile-label {
    display: none;
}
.video-layout-speaker #remoteVideo video,
.video-layout-speaker #remoteVideo canvas,
.video-layout-speaker #localVideo video,
.video-layout-speaker #localVideo canvas {
    object-fit: cover !important;
}

/* Side-by-side view: two equal tiles. Preserve full frame (no crop). */
.video-layout-sidebyside {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    padding: 4.75rem 0.75rem 6rem;
}
.video-layout-sidebyside #remoteVideo video,
.video-layout-sidebyside #remoteVideo canvas,
.video-layout-sidebyside #localVideo video,
.video-layout-sidebyside #localVideo canvas {
    object-fit: contain !important;
}
@media (max-width: 767px) {
    .video-layout-sidebyside {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 4.5rem 0.6rem 6.5rem;
    }
}

.pl-tile-label {
    position: absolute;
    left: 0.6rem;
    bottom: 0.6rem;
    z-index: 3;
    padding: 0.18rem 0.6rem;
    border-radius: 0.5rem;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    backdrop-filter: blur(6px);
    pointer-events: none;
}

/* ============================ Overlay bars ============================ */

.call-top-bar,
.call-bottom-bar {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 8;
    display: flex;
    transition: opacity 0.25s ease;
}

.call-top-bar {
    top: 0;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top, 0px));
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
}

.call-bottom-bar {
    bottom: 0;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    padding: 1.25rem;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
}

.call-controls-hidden .call-top-bar,
.call-controls-hidden .call-bottom-bar {
    opacity: 0;
    pointer-events: none;
}

.call-top-left {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
}

.call-peer-name {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.call-status-pill {
    align-self: flex-start;
    margin: 0;
    padding: 0.16rem 0.65rem;
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.16);
    color: #e5e7eb;
    font-size: 0.72rem;
    font-weight: 600;
    backdrop-filter: blur(8px);
}

.call-top-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* ============================ Buttons ============================ */

.call-pill-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}
.call-pill-btn:hover {
    background: rgba(255, 255, 255, 0.28);
}
.call-pill-btn.is-active {
    background: #2563eb;
}
.call-pill-btn svg {
    width: 20px;
    height: 20px;
}

.call-low-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #fbbf24;
    pointer-events: none;
}
.call-low-badge.hidden {
    display: none;
}

.call-ctrl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}
.call-ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: translateY(-1px);
}
.call-ctrl-btn:active {
    transform: translateY(0);
}
.call-ctrl-btn svg {
    width: 24px;
    height: 24px;
}
.call-ctrl-btn.is-off {
    background: #dc2626;
}
.call-ctrl-btn.is-off:hover {
    background: #ef4444;
}
.call-ctrl-btn.is-active {
    background: #2563eb;
}
.call-ctrl-btn.is-active:hover {
    background: #3b82f6;
}
.call-ctrl-btn.is-end {
    width: 64px;
    height: 64px;
    background: #dc2626;
}
.call-ctrl-btn.is-end:hover {
    background: #ef4444;
}
.call-ctrl-btn.is-end svg {
    transform: rotate(135deg);
}
.call-ctrl-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}
.call-ctrl-btn.hidden,
.call-pill-btn.hidden {
    display: none;
}

/* Icon on/off swap driven by button state classes. */
.call-ctrl-btn .call-icon-off,
.call-pill-btn .call-icon-off {
    display: none;
}
.call-ctrl-btn.is-off .call-icon-on,
.call-pill-btn.is-active .call-icon-on {
    display: none;
}
.call-ctrl-btn.is-off .call-icon-off,
.call-pill-btn.is-active .call-icon-off {
    display: inline-flex;
}

/* ============================ Billing panel ============================ */

.call-billing-panel {
    position: absolute;
    top: 4.75rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9;
    width: min(680px, calc(100% - 1.5rem));
    padding: 1rem;
    border: 1px solid #1f2937;
    border-radius: 1rem;
    background: rgba(17, 24, 39, 0.92);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
}
.call-billing-panel.hidden {
    display: none;
}

/* ============================ Responsive tweaks ============================ */

@media (max-width: 640px) {
    .call-peer-name {
        font-size: 0.95rem;
    }
    .call-pill-btn {
        width: 38px;
        height: 38px;
    }
    .call-pill-btn svg {
        width: 18px;
        height: 18px;
    }
    .call-ctrl-btn {
        width: 50px;
        height: 50px;
    }
    .call-ctrl-btn svg {
        width: 22px;
        height: 22px;
    }
    .call-ctrl-btn.is-end {
        width: 58px;
        height: 58px;
    }
    .call-bottom-bar {
        gap: 0.55rem;
        padding: 1rem;
        padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    }
    .video-layout-speaker .local-cell {
        right: 0.75rem;
        bottom: 5.5rem;
    }
}
