/** Grade de vídeo e palco de apresentação. */

.stage {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    align-content: center;
    justify-items: center;
    gap: 10px;
    padding: 12px;
    /* O palco é uma área fixa da chamada: a página e a grade não devem ganhar uma
       barra vertical quando entram mais participantes. */
    overflow: hidden;
    min-height: 0;
    position: relative;
    background: var(--bg-rail);
    container-type: size;
}

.stage__header,
.stage__main,
.stage__strip,
.stage__notice {
    display: none;
}

.stage--presentation {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    align-content: stretch;
    /* O palco principal, cabeçalho e faixa precisam preencher a coluna; a centralização
       da grade comum vale apenas para os cards fora do modo de apresentação. */
    justify-items: stretch;
    overflow: hidden;
}

.stage--presentation .stage__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 38px;
    padding: 0 4px;
}

.stage__context {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-strong);
}

.stage__context-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stage__presenter {
    flex-shrink: 0;
    padding: 2px 7px;
    border-radius: var(--r-pill);
    background: rgba(88, 101, 242, 0.24);
    color: #c9d0ff;
    font-size: 0.7rem;
}

.stage__actions {
    display: flex;
    gap: 4px;
}

.stage__action {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--interactive);
}

.stage__action:hover,
.stage__action[aria-pressed="true"] {
    background: var(--bg-elevated);
    color: var(--text-strong);
}

.stage--presentation .stage__main {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.stage--presentation .stage__main .tile {
    flex: 0 1 auto;
    min-width: 0;
    width: min(100%, var(--stage-main-card-width, 100%));
    height: auto;
}

/* Dois pins dividem a largura disponível, mas cada fonte continua em 16:9. */
.stage--presentation .stage__main:has(.tile:nth-child(2)) .tile {
    width: min(calc(50% - 5px), var(--stage-main-card-width, 100%));
}

.stage--presentation .stage__strip {
    display: flex;
    min-height: 0;
    gap: 8px;
    padding-top: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}

.stage--presentation:not(.stage--has-strip) .stage__strip {
    display: none;
}

.tile {
    position: relative;
    /* A largura nunca pode fazer a altura 16:9 ultrapassar o palco. Sem esse limite,
       um card único ficava alguns pixels maior que a área disponível e era cortado. */
    width: min(100%, 177.778cqh);
    aspect-ratio: 16 / 9;
    border-radius: var(--r-md);
    overflow: hidden;
    background: var(--bg-tile);
    cursor: pointer;
    box-shadow: inset 0 0 0 0 transparent;
    transition: box-shadow 0.1s ease;
}

.tile:hover { box-shadow: inset 0 0 0 2px var(--bg-elevated); }
.tile--speaking, .tile--speaking:hover { box-shadow: inset 0 0 0 3px var(--ok); }
.tile--video { cursor: default; }
.tile--avatar { cursor: pointer; }

.tile--grid { min-width: 0; }
.tile--thumbnail { flex: 0 0 140px; height: 79px; }
.tile--thumbnail.tile--avatar { aspect-ratio: 16 / 9; }

.tile video { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile--screen video { object-fit: contain; }
.tile--mirror video { transform: scaleX(-1); }

.tile__avatar {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    background: var(--bg-sidebar);
}

.tile__avatar .avatar {
    width: clamp(36px, 45%, 96px);
    aspect-ratio: 1;
    height: auto;
    font-size: clamp(0.7rem, 2.2vw, 1.6rem);
}

.tile__footer {
    position: absolute;
    inset: auto 8px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.tile__name {
    max-width: 100%;
    padding: 2px 8px;
    border-radius: var(--r-sm);
    background: rgba(0, 0, 0, 0.65);
    font-size: 0.8rem;
    color: var(--text-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tile__badges { display: flex; gap: 4px; }
.badge, .tile__quality {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: var(--r-sm);
    background: rgba(0, 0, 0, 0.65);
}
.badge { color: var(--danger); }
.tile__quality { position: absolute; top: 8px; right: 8px; background: rgba(0, 0, 0, 0.55); pointer-events: none; }
.tile__quality[data-quality="excellent"], .tile__quality[data-quality="good"], .tile__quality[data-quality="unknown"] { display: none; }
.tile__quality[data-quality="poor"] { color: var(--warn); }
.tile__quality[data-quality="lost"] { color: var(--danger); }

.tile__pin {
    position: absolute;
    top: 8px;
    left: 8px;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: var(--r-sm);
    background: rgba(0, 0, 0, 0.65);
    color: var(--text-strong);
    opacity: 0;
}
.tile:hover .tile__pin, .tile:focus-within .tile__pin, .tile--pinned .tile__pin { opacity: 1; }
.tile__pin:hover, .tile--pinned .tile__pin { background: var(--accent); color: #fff; }

/* Volume da transmissão: ao lado do botão de fixar (8 + 30 + 8 = 46px), com a mesma
   altura, e só com o mouse em cima - um controle fixo por cima de um slide ou de um jogo
   é ruído o tempo todo pra resolver algo que se faz de vez em quando. */
.tile__volume {
    position: absolute;
    top: 8px;
    left: 46px;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border-radius: var(--r-sm);
    background: rgba(0, 0, 0, 0.65);
    color: var(--text-strong);
    opacity: 0;
    transition: opacity 0.12s ease;
}
.tile:hover .tile__volume, .tile:focus-within .tile__volume { opacity: 1; }
/* Nas miniaturas (104-140px) não cabe; o volume continua no popover da pessoa. */
.tile--thumbnail .tile__volume { display: none; }

.tile__volume-toggle {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: inherit;
}
.tile__volume-toggle:hover { background: rgba(255, 255, 255, 0.12); }

/* O slider fica recolhido e abre ao passar o mouse no próprio controle - o tile mostra
   só um ícone pequeno até alguém realmente ir mexer no volume. */
.tile__volume-slider {
    width: 0;
    margin: 0;
    opacity: 0;
    accent-color: var(--accent);
    cursor: pointer;
    transition: width 0.15s ease, opacity 0.15s ease, margin 0.15s ease;
}
.tile__volume:hover .tile__volume-slider,
.tile__volume:focus-within .tile__volume-slider { width: 90px; margin: 0 6px 0 2px; opacity: 1; }

/* Em tela de toque não existe hover: o controle fica sempre visível e aberto. */
@media (hover: none) {
    .tile__volume { opacity: 1; }
    .tile__volume-slider,
    .tile__volume:hover .tile__volume-slider,
    .tile__volume:focus-within .tile__volume-slider { width: 64px; margin: 0 6px 0 2px; opacity: 1; }
}

.stage__notice {
    position: absolute;
    right: 16px;
    bottom: 104px;
    align-items: center;
    gap: 10px;
    max-width: min(360px, calc(100% - 32px));
    padding: 8px 10px 8px 12px;
    border-radius: var(--r-md);
    background: var(--bg-float);
    box-shadow: var(--shadow-pill);
    color: var(--text);
    font-size: 0.8rem;
    z-index: var(--z-stage-overlay);
}
.stage__notice:not(.hidden) { display: flex; }
.stage__notice-action {
    flex-shrink: 0;
    border: none;
    border-radius: var(--r-sm);
    padding: 5px 8px;
    background: var(--accent);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 600;
}

.stage .call-controls { display: none; }
.stage:fullscreen {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    width: 100vw;
    height: 100dvh;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: var(--bg-rail);
}
.stage:fullscreen .call-controls {
    display: flex;
    grid-row: 4;
    padding: 10px 0 0;
    background: transparent;
    box-shadow: none;
}
.stage:fullscreen .stage__notice { bottom: 86px; }

@media (max-width: 600px) {
    .stage { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; padding: 8px; }
    .stage--presentation .stage__header { min-height: 34px; }
    .tile--thumbnail { flex-basis: 104px; height: 59px; }
    .stage__notice { right: 8px; bottom: 76px; }
    .stage:fullscreen .call-controls { gap: 8px; }
}
