/*
 * 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;
}

/* Screen share (desktop→desktop): letterbox in speaker view so the full frame is visible. */
.video-layout-speaker.remote-screen-sharing #remoteVideo video,
.video-layout-speaker.remote-screen-sharing #remoteVideo canvas,
.video-layout-speaker.remote-screen-sharing #localVideo video,
.video-layout-speaker.remote-screen-sharing #localVideo canvas {
    object-fit: contain !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: #FF6B35;
}
.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: #FF6B35;
}
.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 ============================ */

/* ============================ Session recording ============================ */

.pl-recording-root {
    position: absolute;
    inset: 0;
    z-index: 12;
    pointer-events: none;
}

.pl-recording-root > * {
    pointer-events: auto;
}

.pl-recording-consent {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.55);
    z-index: 14;
}

.pl-recording-consent.hidden,
.pl-recording-awaiting.hidden,
.pl-recording-indicator.hidden,
.pl-recording-picker.hidden {
    display: none;
}

.pl-recording-consent-card,
.pl-recording-picker-card {
    width: min(28rem, 100%);
    max-height: min(90vh, 640px);
    overflow-y: auto;
    padding: 1.5rem;
    border-radius: 1.25rem;
    background: #111827;
    border: 1px solid #374151;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.pl-recording-title {
    margin: 0 0 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
}

.pl-recording-lead,
.pl-recording-subcopy {
    margin: 0 0 0.75rem;
    color: #d1d5db;
    font-size: 0.95rem;
    line-height: 1.45;
}

.pl-recording-summary,
.pl-recording-subhead {
    margin: 0 0 0.75rem;
    color: #9ca3af;
    font-size: 0.9rem;
}

.pl-recording-terms {
    margin: 0 0 1rem;
    color: #9ca3af;
    font-size: 0.8rem;
    line-height: 1.45;
}

.pl-recording-check {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    margin: 0 0 1rem;
    color: #e5e7eb;
    font-size: 0.85rem;
    line-height: 1.35;
}

.pl-recording-check input {
    margin-top: 0.15rem;
    flex-shrink: 0;
}

.pl-recording-actions {
    display: flex;
    gap: 0.75rem;
}

.pl-recording-btn {
    border: none;
    border-radius: 0.75rem;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.pl-recording-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.pl-recording-btn-primary {
    background: #FF6B35;
    color: #fff;
}

.pl-recording-btn-primary:hover:not(:disabled) {
    background: #ef4444;
}

.pl-recording-btn-secondary {
    background: #374151;
    color: #fff;
}

.pl-recording-btn-secondary:hover:not(:disabled) {
    background: #4b5563;
}

.pl-recording-btn-block {
    width: 100%;
}

.pl-recording-awaiting {
    position: absolute;
    top: 4.75rem;
    left: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.85rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    backdrop-filter: blur(8px);
    z-index: 13;
}

.pl-recording-awaiting-spinner {
    width: 0.85rem;
    height: 0.85rem;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: pl-rec-spin 0.8s linear infinite;
}

@keyframes pl-rec-spin {
    to { transform: rotate(360deg); }
}

.pl-recording-awaiting-cancel {
    border: none;
    background: transparent;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: underline;
}

.pl-recording-indicator {
    position: absolute;
    top: 4.75rem;
    left: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.55rem 0.45rem 0.75rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    backdrop-filter: blur(8px);
    z-index: 13;
}

.pl-recording-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.pl-recording-rec-label {
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.pl-recording-elapsed {
    font-size: 0.78rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, 0.9);
}

.pl-recording-stop-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border: none;
    border-radius: 0.45rem;
    background: rgba(220, 38, 38, 0.9);
    color: #fff;
    cursor: pointer;
}

.pl-recording-stop-btn svg {
    width: 0.85rem;
    height: 0.85rem;
}

.pl-recording-picker {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.72);
    z-index: 15;
}

.pl-recording-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.pl-recording-picker-close {
    border: none;
    background: transparent;
    color: #9ca3af;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.pl-recording-choices {
    display: grid;
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.pl-recording-choice {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1px solid #374151;
    border-radius: 0.85rem;
    background: #1f2937;
    color: #fff;
    text-align: left;
    cursor: pointer;
}

.pl-recording-choice.is-selected {
    border-color: #2563eb;
    background: rgba(37, 99, 235, 0.14);
}

.pl-recording-choice-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.pl-recording-choice-sub {
    font-size: 0.8rem;
    color: #9ca3af;
}

.pl-recording-layout-picker {
    margin-bottom: 1rem;
}

.pl-recording-segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.pl-recording-seg {
    border: 1px solid #374151;
    border-radius: 0.65rem;
    padding: 0.55rem 0.75rem;
    background: #1f2937;
    color: #e5e7eb;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.pl-recording-seg.is-active {
    border-color: #2563eb;
    background: rgba(37, 99, 235, 0.18);
    color: #fff;
}

.call-ctrl-btn.is-recording,
.call-ctrl-btn.is-active.is-recording {
    background: rgba(220, 38, 38, 0.92);
}

.call-ctrl-btn.is-hipaa-blocked {
    opacity: 0.45;
    cursor: not-allowed;
}

#toggleRecordBtn .call-icon-off {
    display: none;
}

@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;
    }
}
