/* Therapist phone — CSS-first layouts. Videos stay in .video-section (never reparented).
   Disable with ?phoneBooth=0 */

html.therapist-phone-chrome body.therapist {
    --tpb-bar-h: 76px;
    /* Tall enough for Cat/Tennis scene previews (was 120px — too short). */
    --tpb-stage-h: 168px;
    --tpb-video-strip-h: 150px;
}

/* Shared: hide desktop chrome noise */
html.therapist-phone-chrome #sandboxVoicePanel,
html.therapist-phone-chrome #sandboxVoicePanelToggle,
html.therapist-phone-chrome body.therapist .bls-rail-collapse-tab,
html.therapist-phone-chrome body.therapist .apple-speed-pip-control,
html.therapist-phone-chrome body.therapist .therapist-bls-preview-overlay,
html.therapist-phone-chrome body.therapist .pip-resize-handle,
html.therapist-phone-chrome body.therapist .therapist-client-view-pip-hints,
html.therapist-phone-chrome body.therapist .bottom-video-controls #bottomReceiveNoiseFilter,
html.therapist-phone-chrome body.therapist .media-controls,
html.therapist-phone-chrome body.therapist .nav-buttons,
html.therapist-phone-chrome body.therapist .status-info,
html.therapist-phone-chrome body.therapist .therapist-video-bar,
html.therapist-phone-chrome body.therapist .therapist-session-timer.therapist-only {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

html.therapist-phone-chrome body.therapist .bottom-video-controls {
    z-index: 41000 !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    padding: 8px 10px !important;
    border-radius: 18px !important;
}

html.therapist-phone-chrome body.therapist .bottom-video-controls .bottom-btn-label,
html.therapist-phone-chrome body.therapist #bottomTherapistBallAudio {
    display: none !important;
}

html.therapist-phone-chrome body.therapist #bottomTherapistBLS .bottom-btn-text {
    font-size: 11px;
    font-weight: 700;
}

html.therapist-phone-chrome body.therapist .main-content {
    display: none !important;
}

/* Sit just above the call bar so it stays readable in Video + BLS modes */
html.therapist-phone-chrome .app-version-phone {
    display: block !important;
    bottom: calc(var(--tpb-bar-h, 76px) + 6px + env(safe-area-inset-bottom, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    color: rgba(255, 255, 255, 0.4);
    z-index: 40990;
}

/* ========== VIDEO MODE: client full + self PiP ========== */
html.therapist-phone-chrome.tpb-video-mode .tpb-root {
    display: none !important;
}

html.therapist-phone-chrome.tpb-video-mode body.therapist {
    overflow: hidden;
}

html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section,
html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section.fullscreen {
    position: fixed !important;
    inset: 0 0 calc(var(--tpb-bar-h) + env(safe-area-inset-bottom, 0px)) 0 !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 5 !important;
    background: #000 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: calc(var(--tpb-bar-h) + env(safe-area-inset-bottom, 0px)) !important;
}

html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section .video-container.fullscreen-video,
html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section .video-container:has(#remoteVideo) {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    transform: none !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 1 !important;
}

html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section .video-container.fullscreen-video video,
html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section .video-container:has(#remoteVideo) video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section .video-container.pip-video,
html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section .video-container:has(#localVideo) {
    position: absolute !important;
    top: max(10px, env(safe-area-inset-top, 0px)) !important;
    right: 10px !important;
    left: auto !important;
    bottom: auto !important;
    width: 112px !important;
    height: 148px !important;
    max-width: 34vw !important;
    max-height: 22vh !important;
    z-index: 20 !important;
    border-radius: 10px !important;
    overflow: hidden !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45) !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section .video-container.pip-video video,
html.therapist-phone-chrome.tpb-video-mode body.therapist .video-section .video-container:has(#localVideo) video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* ========== BLS MODE: stage + video strip (videos stay in .video-section) + controls ========== */
html.therapist-phone-chrome.tpb-bls-mode body.therapist {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    background: #0b1220;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-root {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #0b1220;
    /* Leave a hole for the fixed video strip between stage and controls */
    padding-top: 0;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-stage {
    flex: 0 0 var(--tpb-stage-h);
    min-height: var(--tpb-stage-h);
    max-height: var(--tpb-stage-h);
    position: relative;
    overflow: hidden;
    background: #000;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 4;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-canvas {
    position: absolute;
    inset: 0 96px 0 0;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-canvas .emdr-canvas-container {
    position: absolute !important;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    transform: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-canvas .emdr-canvas,
html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-canvas #emdrCanvas {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: block !important;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-side {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    background: rgba(0, 0, 0, 0.45);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-side .start-bls-container {
    margin: 0 !important;
    padding: 0 !important;
    width: 100%;
    display: flex !important;
    justify-content: center;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-side .bls-control-lead-spacer {
    display: none !important;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-side .bls-control-suffix {
    margin: 0 !important;
    width: 100%;
    display: flex;
    justify-content: center;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-side .start-bls-btn {
    width: 72px !important;
    height: 72px !important;
    min-width: 72px !important;
    min-height: 72px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 13px;
    font-weight: 700;
}

/* Videos stay in .video-section — restyle as the strip under the stage */
html.therapist-phone-chrome.tpb-bls-mode body.therapist .video-section,
html.therapist-phone-chrome.tpb-bls-mode body.therapist .video-section.fullscreen {
    position: fixed !important;
    top: calc(var(--tpb-stage-h) + env(safe-area-inset-top, 0px)) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: auto !important;
    width: 100% !important;
    height: var(--tpb-video-strip-h) !important;
    max-height: var(--tpb-video-strip-h) !important;
    margin: 0 !important;
    padding: 6px 8px !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 6 !important;
    background: #0b1220 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
}

html.therapist-phone-chrome.tpb-bls-mode body.therapist .video-section .video-container {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    transform: none !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 10px !important;
    box-shadow: none !important;
    overflow: hidden !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    background: #111 !important;
}

html.therapist-phone-chrome.tpb-bls-mode body.therapist .video-section .video-container video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

html.therapist-phone-chrome.tpb-bls-mode body.therapist .video-section .video-label,
html.therapist-phone-chrome.tpb-bls-mode body.therapist .video-section .client-name-display,
html.therapist-phone-chrome.tpb-bls-mode body.therapist .video-section .therapist-session-timer {
    display: none !important;
}

/* Desktop rail was hidden — don't pop the settings list back when the window goes narrow. */
html.therapist-phone-chrome.tpb-rail-collapsed .tpb-controls-shell {
    display: none !important;
}

/* Controls fill remaining space below the video strip */
html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #141c2e;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    margin-top: var(--tpb-video-strip-h);
    /* Call bar + Safari chrome + safe area — Auto Stop / photo rows must clear VIDEO MODE. */
    padding: 10px 12px calc(var(--tpb-bar-h) + 140px + env(safe-area-inset-bottom, 0px));
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .emdr-controls {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    visibility: visible !important;
    opacity: 1 !important;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .start-bls-container,
html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .emdr-title-container,
html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .waiting-room-indicator {
    display: none !important;
}

/* Match in-person controller: Random sits after colours / auto-stop (DOM order
   still has it early for desktop rail). */
html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .random-quick-controls {
    order: 100;
    margin-top: 6px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    opacity: 0.92;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    width: 100% !important;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .random-quick-label {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .random-quick-suffix {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
    align-items: start !important;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .random-quick-chip {
    min-width: 0;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .random-quick-btn {
    width: 100%;
    padding: 6px 8px !important;
    font-size: 12px !important;
    line-height: 1.1;
    border-radius: 8px;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .random-quick-interval {
    min-width: 0;
    width: 100%;
}

html.therapist-phone-chrome.tpb-bls-mode .tpb-controls-shell .random-mini-slider {
    min-width: 0;
    max-width: none;
}

/* Chat at top on phone — bottom placement sits under the call bar / soft keyboard
   so the input cannot be focused or typed into. */
html.therapist-phone-chrome body.therapist .chat-panel:not(.hidden) {
    top: calc(10px + env(safe-area-inset-top, 0px)) !important;
    bottom: auto !important;
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-width: none !important;
    /* svh = small viewport; plain vh grows when the keyboard opens on iOS and
       makes the panel taller than the visible area (Send falls off-screen). */
    max-height: min(48svh, 380px) !important;
    z-index: 42000 !important;
}

html.therapist-phone-chrome body.therapist .chat-panel:not(.hidden) .chat-body {
    height: min(36svh, 260px);
    min-height: 0;
}

/* iOS Safari auto-zooms focused inputs under 16px — that zooms the whole session
   UI and clips the Send button. Keep 16px on phone only. */
html.therapist-phone-chrome body.therapist .chat-input {
    font-size: 16px !important;
    line-height: 1.25;
}

html.therapist-phone-chrome body.therapist .chat-send-btn {
    flex-shrink: 0;
    font-size: 15px;
    padding: 8px 14px;
}

/* Collapsed: keep only the header visible at the top (desktop rule slides downward). */
html.therapist-phone-chrome body.therapist .chat-panel.collapsed:not(.hidden) {
    transform: translateY(calc(-100% + 48px)) !important;
}

@media (orientation: landscape) and (max-height: 520px) {
    html.therapist-phone-chrome body.therapist {
        --tpb-stage-h: 112px;
        --tpb-video-strip-h: 96px;
        --tpb-bar-h: 56px;
    }

    html.therapist-phone-chrome.tpb-bls-mode .tpb-stage-side .start-bls-btn {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
        min-height: 56px !important;
        font-size: 11px;
    }

    html.therapist-phone-chrome body.therapist .chat-panel:not(.hidden) {
        max-height: min(42svh, 260px) !important;
    }

    html.therapist-phone-chrome body.therapist .chat-panel:not(.hidden) .chat-body {
        height: min(28svh, 160px);
    }
}
