/* SPDX-License-Identifier: AGPL-3.0-only */
/* ---------- Room ---------- */

.room {
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.room-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    gap: 12px;
    min-height: 48px;
}

.room-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    /* The connection status and the theme button stay on the right. */
    margin-inline-end: auto;
}

.room-info strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-timer {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* The last minutes of a meeting with a time limit. */
.room-timer.ending {
    color: var(--danger-text);
    font-weight: 600;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--surface-2);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
}

.pill svg {
    width: 15px;
    height: 15px;
    color: var(--muted);
}

.tag-text {
    margin-inline-start: 0.25em;
}

.tag > svg {
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
}

.tag {
    background: var(--surface-2);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
}

.tag.rec {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger-text);
    font-weight: 600;
    letter-spacing: 0.04em;
}

.rec-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    animation: rec-pulse 1.4s ease-in-out infinite;
}

@keyframes rec-pulse {
    50% {
        opacity: 0.3;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rec-dot,
    .spinner {
        animation: none;
    }
}

/* Role badges (header, tiles, People panel): indigo crown for the host, teal shield for co-hosts. */
.tag.host,
.host-tag {
    --role-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 19 2 7l5.5 4.5L12 4l4.5 7.5L22 7l-2 12H4Z'/%3E%3C/svg%3E");
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(99, 102, 241, 0.25);
    color: var(--host-text);
}

.tag.host.cohost,
.host-tag.cohost {
    --role-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 1 3 5v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V5l-9-4Z'/%3E%3C/svg%3E");
    background: rgba(45, 212, 191, 0.18);
    color: var(--cohost-text);
}

.tag.host::before,
.host-tag::before {
    content: '';
    flex-shrink: 0;
    width: 1em;
    height: 1em;
    background: currentColor;
    mask: var(--role-icon) center / contain no-repeat;
}

.status {
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(234, 179, 8, 0.15);
    color: var(--warning-text);
}

.room-body {
    flex: 1;
    display: flex;
    min-height: 0;
    padding: 0 12px;
    gap: 12px;
}

.stage {
    position: relative;
    flex: 1;
    display: flex;
    gap: 10px;
    min-width: 0;
    min-height: 0;
}

.spotlight {
    --cols: 1;
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    gap: 10px;
}

.stage:not(.has-spotlight) .spotlight,
.stage.has-spotlight .grid:empty {
    display: none;
}

.grid {
    --cols: 1;
    --rows: 1;
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-template-rows: repeat(var(--rows), minmax(120px, 1fr));
    gap: 10px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.stage.has-spotlight .grid {
    flex: 0 0 240px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-rows: 150px;
    align-content: start;
}

/* The shared whiteboard takes the stage's place; the tiles go in a strip beside it (in the page, not the
   picture-in-picture window). Excalidraw fills .whiteboard-canvas. */
.whiteboard {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}

.whiteboard-canvas {
    position: absolute;
    inset: 0;
}

.whiteboard-loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    margin: 0;
    color: var(--muted);
}

.whiteboard:not([hidden]) ~ .stage {
    flex: 0 0 240px;
}

.whiteboard:not([hidden]) ~ .stage .grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-rows: 150px;
    align-content: start;
}

.tile {
    /* Names, badges and buttons sit on dark overlays over the video in both themes, so they keep the dark
       theme's colours (see base.css). */
    --danger: #f25c5c;
    --host-text: #c7d2fe;
    --cohost-text: #99f6e4;
    position: relative;
    /* Narrow tiles fold their buttons into the ⋯ menu (below). */
    container: tile / inline-size;
    background: var(--surface);
    color: #fff;
    border-radius: var(--radius);
    overflow: hidden;
    min-height: 0;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.tile.speaking {
    border-color: var(--speaking);
}

.tile video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

/* Your own camera shows like a mirror, except the back camera, which films what you see. */
.tile.local:not(.screen) video:not(.back-camera) {
    transform: scaleX(-1);
}

.tile.screen video {
    object-fit: contain;
}

.tile:not(.has-video) video {
    display: none;
}

.avatar {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
}

.tile.has-video .avatar {
    display: none;
}

.avatar span {
    width: clamp(56px, 22%, 110px);
    aspect-ratio: 1;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: clamp(20px, 3vw, 40px);
    font-weight: 600;
    background: var(--avatar-bg, var(--primary));
    color: #fff;
    text-transform: uppercase;
}

.tile-footer {
    position: absolute;
    inset-inline-start: 8px;
    bottom: 8px;
    max-width: calc(100% - 16px);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.6);
    font-size: 13px;
}

.tile-footer svg {
    width: 16px;
    height: 16px;
    color: var(--danger);
}

.tile-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quality {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
}

.quality[data-q='excellent'] {
    background: var(--success);
}

.quality[data-q='good'] {
    background: #eab308;
}

.quality[data-q='poor'],
.quality[data-q='lost'] {
    background: var(--danger);
}

.tile-tools {
    position: absolute;
    top: 8px;
    inset-inline-end: 8px;
    display: flex;
    gap: 6px;
}

.tile-tools button {
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    width: 34px;
    height: 34px;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition:
        opacity 0.15s,
        background 0.15s;
}

.tile-tools button:hover {
    background: rgba(0, 0, 0, 0.75);
}

.tile-tools svg {
    width: 18px;
    height: 18px;
}

.tile:hover .tile-tools button,
.tile-tools button:focus-visible,
.tile.pinned .pin-btn,
.tile.spotlit .spotlight-btn {
    opacity: 1;
}

.tile.pinned .pin-btn,
.tile.spotlit .spotlight-btn {
    background: var(--primary);
}

.tile-tools .spotlight-btn {
    display: none;
}

.room.is-host .tile-tools .spotlight-btn {
    display: grid;
}

.tile-tools button:disabled {
    cursor: progress;
}

/* Drawing on a screen share: the canvas takes the pointer (and touch) only while the pen is on. */
.annotations {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.tile.annotating {
    border-color: var(--primary);
}

.tile.annotating .annotations {
    pointer-events: auto;
    cursor: crosshair;
    touch-action: none;
}

.tile.annotating .annotate-btn {
    opacity: 1;
    background: var(--primary);
}

@media (hover: none) {
    .tile-tools .pin-btn,
    .tile-tools .spotlight-btn,
    .tile-tools .annotate-btn {
        opacity: 1;
    }
}

.host-tag {
    flex-shrink: 0;
    height: 20px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.tile-footer .hand-tag {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    margin-inline-start: -4px;
    border-radius: 50%;
    background: var(--hand);
    animation: hand-wave 0.6s ease-in-out 2;
    transform-origin: 50% 90%;
}

.tile-footer .hand-tag svg {
    width: 13px;
    height: 13px;
    color: #1f1300;
}

/* The tile a host put in the spotlight for everyone. */
.tile-footer .spotlight-tag {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
}

.tile-footer .spotlight-tag svg {
    width: 13px;
    height: 13px;
}

@keyframes hand-wave {
    25% {
        transform: rotate(-14deg);
    }
    75% {
        transform: rotate(14deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .tile-footer .hand-tag {
        animation: none;
    }
}

.host-actions {
    position: absolute;
    top: 8px;
    inset-inline-start: 8px;
    display: none;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.15s;
}

.room.is-host .tile:not(.local):not(.screen) .host-actions {
    display: flex;
}

.tile:hover .host-actions,
.host-actions:focus-within {
    opacity: 1;
}

.host-actions button {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.5);
    transition: background 0.15s;
}

.host-actions svg {
    width: 18px;
    height: 18px;
}

.host-actions .host-mute:hover,
.host-actions .host-camera-off:hover {
    background: rgba(0, 0, 0, 0.75);
}

.host-actions .host-kick:hover {
    background: var(--danger-fill);
}

.host-actions button:disabled {
    opacity: 0.5;
    cursor: progress;
}

@media (hover: none) {
    .host-actions {
        opacity: 1;
    }
}

/* ---------- Tile ⋯ menu ---------- */

/* Narrow tiles (the strip beside a screen share or the whiteboard, a crowded grid, phones) fold their buttons
   into one ⋯ menu (tile-menu.js), so they don't overlap each other or cover the video. Buttons that are on
   (pinned, in the spotlight, drawing) stay in sight. Hosts' tiles of others have the most buttons, so they
   fold first. */
.tile-tools .tile-more {
    display: none;
}

.tile-tools .tile-more[aria-expanded='true'] {
    opacity: 1;
    background: rgba(0, 0, 0, 0.75);
}

@container tile (max-width: 219px) {
    .tile .tile-tools .tile-more {
        display: grid;
    }

    .tile .tile-tools button:not(.tile-more):not([aria-pressed='true']) {
        display: none;
    }
}

@container tile (max-width: 339px) {
    .room.is-host .tile:not(.local):not(.screen) .host-actions {
        display: none;
    }

    .room.is-host .tile:not(.local):not(.screen) .tile-more {
        display: grid;
    }

    .room.is-host .tile:not(.local):not(.screen) .tile-tools button:not(.tile-more):not([aria-pressed='true']) {
        display: none;
    }
}

/* Very small tiles (the phone strip): smaller buttons, closer to the corner. */
@container tile (max-width: 179px) {
    .tile .tile-tools {
        top: 6px;
        inset-inline-end: 6px;
        gap: 4px;
    }

    .tile .tile-tools button {
        width: 28px;
        height: 28px;
    }

    .tile .tile-tools svg {
        width: 16px;
        height: 16px;
    }
}

@media (hover: none) {
    .tile-tools .tile-more {
        opacity: 1;
    }
}

/* A popover (top layer): not clipped by the tile, and shown in fullscreen too. Dark like the tile's overlays. */
.tile-menu {
    position: fixed;
    inset: auto;
    margin: 0;
    flex-direction: column;
    gap: 2px;
    min-width: 200px;
    max-width: min(280px, calc(100vw - 8px));
    max-height: calc(100vh - 8px);
    overflow-y: auto;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    background: rgba(24, 26, 33, 0.96);
    color: #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.tile-menu:popover-open {
    display: flex;
}

.tile-menu button {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 14px;
    text-align: start;
}

.tile-menu svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: rgba(255, 255, 255, 0.72);
}

.tile-menu span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tile-menu button:hover,
.tile-menu button:focus-visible {
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

/* On (pinned, in the spotlight, drawing): highlighted like the buttons. */
.tile-menu [aria-checked='true'] svg {
    color: #a5b4fc;
}

.tile-menu [aria-checked='true']::after {
    content: '';
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    margin-inline-start: auto;
    border-radius: 50%;
    background: var(--primary);
}

.tile-menu .menu-divider {
    height: 1px;
    margin: 4px 6px;
    background: rgba(255, 255, 255, 0.12);
}

.tile-menu .danger,
.tile-menu .danger svg {
    color: var(--danger);
}

.tile-menu .danger:hover,
.tile-menu .danger:focus-visible {
    background: rgba(239, 68, 68, 0.18);
}

/* ---------- Reactions ---------- */

.reactions {
    position: absolute;
    inset: 0;
    z-index: 5;
    overflow: hidden;
    pointer-events: none;
}

.reaction {
    position: absolute;
    left: var(--x, 50%);
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    animation: reaction-float 4s ease-out forwards;
}

.reaction-emoji {
    font-size: 40px;
    line-height: 1;
}

.reaction-name {
    max-width: 120px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@keyframes reaction-float {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.6);
    }
    10% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    75% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateY(-55vh);
    }
}

@keyframes reaction-fade {
    0%,
    100% {
        opacity: 0;
    }
    10%,
    75% {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .reaction {
        bottom: 12px;
        animation-name: reaction-fade;
    }
}

/* ---------- Live captions ---------- */

.captions {
    position: absolute;
    left: 50%;
    /* Above the name labels at the bottom of the tiles. */
    bottom: 52px;
    z-index: 6;
    width: min(860px, calc(100% - 32px));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transform: translateX(-50%);
    pointer-events: none;
}

.caption {
    max-width: 100%;
    margin: 0;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    font-size: 18px;
    line-height: 1.4;
    text-align: center;
    overflow-wrap: anywhere;
}

.caption-name {
    margin-inline-end: 6px;
    color: #a5b4fc;
    font-weight: 600;
}

.caption.interim .caption-text {
    opacity: 0.85;
}

body.pip .caption {
    padding: 3px 8px;
    font-size: 13px;
}

/* ---------- Picture-in-picture ---------- */

/* The PiP window's own page: the stage and a small control bar. */
body.pip {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    overflow: hidden;
}

body.pip .pip-controls {
    height: auto;
    padding: 0;
}

body.pip .ctrl-btn {
    width: 40px;
    height: 40px;
}

body.pip .ctrl-btn[data-media]:not(.on) {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger-text);
}

body.pip .fullscreen-btn {
    display: none;
}

/* Where the stage was in the meeting page while it's in the PiP window. */
.pip-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
}

.pip-placeholder p {
    margin: 0;
}
