/* ═══════════════════════════════════════════════════════════════════
   Voice / screen-share rooms (spike — see docs/SPIKE_VOICE_CHAT.md)
   Stage / header / controls vocabulary mirrors Google Meet / Whereby
   so the layout reads as a "real" call view rather than a settings page
   with extra buttons.
   ═══════════════════════════════════════════════════════════════════ */

.cv-call {
    /* Full available column height — the page body is already scrollable,
       but the call view should occupy the full viewport visually so the
       toolbar pins to the bottom. */
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 52px); /* navbar */
    background: var(--cv-bg);
}

/* ── Top toolbar ──────────────────────────────────────────────────── */
.cv-call-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .65rem 1rem;
    background: var(--cv-surface);
    border-bottom: 1px solid var(--cv-border);
    flex-shrink: 0;
}
.cv-call-header-left,
.cv-call-header-right {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}
.cv-call-mode-badge,
.cv-call-e2e-badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .75rem;
    padding: .2rem .55rem;
    border-radius: 999px;
    background: var(--cv-surface-2);
    color: var(--cv-text-2);
}
.cv-call-mode-badge svg { width: 14px; height: 14px; }
.cv-call-e2e-verified {
    background: rgba(25, 135, 84, .12);
    color: #1b7d4d;
}
.cv-call-e2e-failed {
    background: rgba(220, 53, 69, .12);
    color: #b3263a;
}
[data-theme="dark"] .cv-call-e2e-verified { color: #4cd685; }
[data-theme="dark"] .cv-call-e2e-failed   { color: #ff7080; }

.cv-call-link-pill {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .25rem .35rem .25rem .65rem;
    background: var(--cv-surface-2);
    border: 1px solid var(--cv-border);
    border-radius: 999px;
    max-width: 320px;
    font-size: .75rem;
    color: var(--cv-text-2);
    overflow: hidden;
}
.cv-call-link-pill code {
    background: transparent;
    color: var(--cv-text-2);
    padding: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    font-size: .72rem;
}
.cv-call-link-pill .btn {
    padding: .1rem .45rem;
    font-size: .7rem;
}

/* ── Stage (the big middle area) ───────────────────────────────────── */
.cv-call-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--cv-bg);
    min-height: 0;       /* keep flex children from blowing out the column */
    overflow: hidden;
    position: relative;  /* anchor for the self-preview PIP */
}

.cv-call-video-frame {
    position: relative;
    width: 100%;
    max-width: 1100px;
    max-height: 100%;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .2);
}
.cv-call-video-frame video {
    width: 100%;
    height: auto;
    max-height: 75vh;
    display: block;
}
/* When no remote video, this overlay covers the (always-mounted, empty)
   frame and renders the avatar tiles. The frame underneath keeps its
   <video> element ready for the moment a stream arrives — much more
   reliable than swapping the slot in and out of the DOM, which was the
   root of the "peer doesn't see my share" regression. */
.cv-call-overlay {
    position: absolute;
    inset: 1.5rem;            /* match cv-call-stage padding */
    background: var(--cv-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    border-radius: 12px;
    z-index: 2;
    pointer-events: auto;
}

/* Floating controls in the top-right of the video frame. */
.cv-call-frame-controls {
    position: absolute;
    top: .5rem;
    right: .5rem;
    display: flex;
    gap: .35rem;
    z-index: 3;
    opacity: 0;
    transition: opacity .15s ease;
}
.cv-call-video-frame:hover .cv-call-frame-controls,
.cv-call-frame-controls:focus-within {
    opacity: 1;
}
.cv-call-frame-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0, 0, 0, .55);
    border: 1px solid rgba(255, 255, 255, .18);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .12s ease;
}
.cv-call-frame-btn:hover { background: rgba(0, 0, 0, .8); }
.cv-call-frame-btn .cv-call-icon { width: 18px; height: 18px; }

/* ── Page fullscreen (CSS-only — hides chrome, expands stage) ─────── */
.cv-call-page-fs .cv-call-header,
.cv-call-page-fs .cv-call-side {
    display: none;
}
.cv-call-page-fs .cv-call-stage {
    padding: 0;
}
.cv-call-page-fs .cv-call-video-frame {
    max-width: none;
    max-height: none;
    border-radius: 0;
    width: 100%;
    height: 100%;
}
.cv-call-page-fs .cv-call-video-frame video {
    max-height: 100%;
    height: 100%;
    object-fit: contain;
}
.cv-call-page-fs .cv-call-overlay {
    inset: 0;
    border-radius: 0;
}

/* Browser fullscreen flips the call root into a black, full-viewport box.
   The :fullscreen selector also matches automatically — we keep the
   explicit class as a fallback for older browsers. */
.cv-call-browser-fs,
.cv-call:fullscreen {
    background: #000;
}
.cv-call-browser-fs .cv-call-header,
.cv-call:fullscreen .cv-call-header,
.cv-call-browser-fs .cv-call-side,
.cv-call:fullscreen .cv-call-side {
    display: none;
}
.cv-call-browser-fs .cv-call-stage,
.cv-call:fullscreen .cv-call-stage {
    padding: 0;
}
.cv-call-browser-fs .cv-call-video-frame,
.cv-call:fullscreen .cv-call-video-frame {
    max-width: none;
    max-height: none;
    border-radius: 0;
    width: 100%;
    height: 100%;
}
.cv-call-browser-fs .cv-call-video-frame video,
.cv-call:fullscreen .cv-call-video-frame video {
    max-height: 100%;
    height: 100%;
    object-fit: contain;
}

/* Self-preview PIP — bottom-right of the stage, Meet-style. */
.cv-call-self-preview {
    position: absolute;
    right: 1.25rem;
    bottom: 1.25rem;
    width: clamp(140px, 18vw, 240px);
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
    border: 1px solid rgba(255, 255, 255, .12);
    z-index: 2;
}
.cv-call-self-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #000;
}
.cv-call-self-preview-label {
    position: absolute;
    left: .5rem;
    bottom: .35rem;
    font-size: .68rem;
    color: #fff;
    background: rgba(0, 0, 0, .55);
    padding: .1rem .45rem;
    border-radius: 4px;
    pointer-events: none;
}
.cv-call-self-preview-hidden {
    display: none;
}

.cv-call-avatar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    text-align: center;
    color: var(--cv-text);
}
.cv-call-avatar-icon {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: var(--cv-accent-sub);
    color: var(--cv-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .12);
}
.cv-call-peer-name {
    font-size: 1.4rem;
    font-weight: 600;
}
.cv-call-state {
    font-size: .85rem;
    color: var(--cv-text-3);
}

.cv-call-waiting {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.cv-call-waiting-content {
    width: 100%;
    max-width: 560px;
    background: var(--cv-surface);
    border-radius: 14px;
    box-shadow: var(--cv-shadow-md);
    padding: 2rem;
    text-align: center;
}
.cv-call-waiting-content h2 {
    margin-bottom: .35rem;
    font-size: 1.5rem;
}
.cv-call-waiting-content .lead {
    color: var(--cv-text-3);
    font-size: .95rem;
    margin-bottom: 1.25rem;
}
.cv-call-share-row {
    display: flex;
    gap: .5rem;
    align-items: stretch;
    margin-bottom: 1rem;
}
.cv-call-share-row input {
    flex: 1;
    font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    font-size: .82rem;
}
.cv-call-pending-list {
    text-align: left;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--cv-border);
}
.cv-call-pending-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .55rem .25rem;
    border-bottom: 1px solid var(--cv-border);
}
.cv-call-pending-row:last-child { border-bottom: none; }

/* ── Bottom controls ──────────────────────────────────────────────── */
.cv-call-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    padding: 1rem;
    background: var(--cv-surface);
    border-top: 1px solid var(--cv-border);
    flex-wrap: wrap;
    flex-shrink: 0;
}
.cv-call-btn {
    /* Circular pill buttons matching the Google Meet / Zoom idiom. */
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    background: var(--cv-surface-2);
    color: var(--cv-text);
    border: 1px solid var(--cv-border);
    padding: .65rem 1.1rem;
    border-radius: 999px;
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease;
}
.cv-call-btn:hover     { background: var(--cv-surface-3); }
.cv-call-btn:disabled  { opacity: .5; cursor: not-allowed; }
.cv-call-btn-active {
    background: var(--cv-accent-sub);
    border-color: var(--cv-accent);
    color: var(--cv-accent);
}
.cv-call-btn-danger {
    background: #dc3545;
    border-color: #dc3545;
    color: #fff;
}
.cv-call-btn-danger:hover { background: #b3263a; border-color: #b3263a; }
.cv-call-btn-warning {
    background: #f0ad4e;
    border-color: #f0ad4e;
    color: #2c1d00;
}
.cv-call-btn-warning:hover { background: #e09a3a; border-color: #e09a3a; }

/* SVG icon glyph inside any cv-call button or badge. Sized once here so
   the page markup doesn't have to set width/height on every <svg>. */
.cv-call-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}
.cv-call-btn .cv-call-icon { width: 20px; height: 20px; }
.cv-call-btn-label { display: inline-block; }

/* ── Stage + side-rail layout (in-call body) ───────────────────────── */
.cv-call-body {
    flex: 1;
    display: flex;
    min-height: 0;
}
.cv-call-side {
    width: 320px;
    border-left: 1px solid var(--cv-border);
    background: var(--cv-surface);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width .18s ease;
}
.cv-call-side-collapsed {
    width: 56px;
}
.cv-call-side-tabs {
    display: flex;
    gap: .25rem;
    padding: .5rem;
    border-bottom: 1px solid var(--cv-border);
}
.cv-call-side-tab {
    position: relative;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--cv-text-3);
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: background .12s ease, color .12s ease;
}
.cv-call-side-tab:hover {
    background: var(--cv-surface-2);
    color: var(--cv-text);
}
.cv-call-side-tab-active {
    background: var(--cv-accent-sub);
    color: var(--cv-accent);
}
.cv-call-side-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #dc3545;
    color: #fff;
    font-size: .7rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.cv-call-side-panel {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}
.cv-call-side-section {
    margin-bottom: 1.25rem;
}
.cv-call-side-title {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--cv-text-3);
    margin-bottom: .5rem;
}
.cv-call-side-person {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .35rem 0;
}
.cv-call-side-person-name {
    font-weight: 500;
}

/* ── Participant tiles (avatar grid when no remote video) ──────────── */
.cv-call-participants {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}
.cv-call-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    padding: 1rem;
    min-width: 180px;
}
.cv-call-tile-avatar {
    position: relative;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--cv-accent-sub);
    color: var(--cv-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 600;
    box-shadow: 0 0 0 0 transparent;
    transition: box-shadow .18s ease;
}
.cv-call-tile-speaking .cv-call-tile-avatar {
    /* Pulsing green ring while speaking — same idiom as Meet / Discord. */
    box-shadow: 0 0 0 4px rgba(48, 195, 96, .8);
    animation: cvCallSpeakingPulse 1.4s ease-in-out infinite;
}
@keyframes cvCallSpeakingPulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(48, 195, 96, .8); }
    50%      { box-shadow: 0 0 0 8px rgba(48, 195, 96, .35); }
}
.cv-call-tile-mic-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #dc3545;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.cv-call-tile-mic-badge .cv-call-icon { width: 14px; height: 14px; }
.cv-call-tile-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--cv-text);
}
.cv-call-tile-sub {
    font-size: .8rem;
    color: var(--cv-text-3);
}
.cv-call-hint {
    width: 100%;
    margin-top: 1.25rem;
    text-align: center;
    color: var(--cv-text-3);
    font-size: .9rem;
}

/* ── Chat panel ────────────────────────────────────────────────────── */
.cv-call-chat {
    display: flex;
    flex-direction: column;
    padding: 0;
}
.cv-call-chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .55rem;
}
.cv-call-chat-empty {
    margin: auto;
    text-align: center;
    color: var(--cv-text-3);
    font-size: .85rem;
    padding: 1.5rem;
}
.cv-call-chat-msg {
    max-width: 85%;
    padding: .45rem .65rem;
    background: var(--cv-surface-2);
    border-radius: 10px;
    font-size: .88rem;
    word-wrap: break-word;
}
.cv-call-chat-msg-mine {
    align-self: flex-end;
    background: var(--cv-accent-sub);
    color: var(--cv-accent);
}
.cv-call-chat-author {
    font-size: .7rem;
    color: var(--cv-text-3);
    margin-bottom: .15rem;
    font-weight: 500;
}
.cv-call-chat-msg-mine .cv-call-chat-author { color: var(--cv-accent); opacity: .75; }
.cv-call-chat-body {
    white-space: pre-wrap;
}
.cv-call-chat-input {
    display: flex;
    gap: .4rem;
    padding: .65rem;
    border-top: 1px solid var(--cv-border);
}
.cv-call-chat-input input {
    flex: 1;
}

@media (max-width: 768px) {
    .cv-call-side { width: 100%; max-width: 280px; }
    .cv-call-btn-label { display: none; }   /* icon-only on mobile to save room */
}

@media (max-width: 600px) {
    .cv-call-header        { flex-direction: column; align-items: stretch; }
    .cv-call-link-pill     { max-width: 100%; }
    .cv-call-controls .cv-call-btn { padding: .55rem .8rem; font-size: .82rem; }
}
