/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
    --bg-base: #0d0d1a;
    --bg-surface: #151525;
    --bg-card: #1c1c32;
    --bg-hover: #22223a;
    --accent: #6c63ff;
    --accent-hover: #5a52e0;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --text-primary: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #2a2a45;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow: 0 4px 24px rgba(0, 0, 0, .4);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text-primary);
    white-space: nowrap;
}

.logo-icon {
    width: 22px;
    height: 22px;
    color: var(--accent);
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.room-badge {
    display: flex;
    align-items: center;
    gap: 7px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.badge-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: .5;
        transform: scale(.8);
    }
}

/* ── Error banner ───────────────────────────────────────────────────────── */
.error-banner {
    background: rgba(239, 68, 68, .12);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 0.82rem;
    color: #fca5a5;
    max-width: 520px;
    text-align: center;
}

/* ── Main layout ────────────────────────────────────────────────────────── */
.layout {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ── Video area ─────────────────────────────────────────────────────────── */
.video-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 14px;
    gap: 12px;
    overflow: hidden;
    min-width: 0;
}

/* ── Video grid ─────────────────────────────────────────────────────────── */
.video-grid {
    flex: 1;
    display: grid;
    gap: 10px;
    overflow: hidden;
    min-height: 0;
}

.video-grid.peers-1 {
    grid-template-columns: 1fr;
}

.video-grid.peers-2 {
    grid-template-columns: repeat(2, 1fr);
}

.video-grid.peers-3,
.video-grid.peers-4 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

/* ── Video tile ─────────────────────────────────────────────────────────── */
.video-item {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    transition: border-color .2s;
}

.video-item:hover {
    border-color: var(--accent);
}

.video-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Camera-off overlay — hidden by default, shown via .cam-is-off parent class */
.cam-off-overlay {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.video-item.cam-is-off video {
    display: none;
}

.video-item.cam-is-off .cam-off-overlay {
    display: flex;
}

/* Name label */
.video-label {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(4px);
    color: #fff;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 500;
    pointer-events: none;
}

/* ── Controls bar ───────────────────────────────────────────────────────── */
.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-shrink: 0;
}

.ctrl-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 12px 22px;
    min-width: 80px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50px;
    color: var(--text-primary);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
    user-select: none;
}

.ctrl-btn svg {
    width: 20px;
    height: 20px;
}

.ctrl-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.ctrl-btn:active {
    transform: translateY(0);
}

.ctrl-btn.is-active {
    background: #2a2a44;
    border-color: #6b7280;
    color: #9ca3af;
}

.ctrl-btn--danger {
    background: var(--danger);
    border-color: var(--danger);
}

.ctrl-btn--danger:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
    width: 270px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    overflow-y: auto;
}

.sidebar-section {
    padding: 18px 18px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-section:last-child {
    border-bottom: none;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--text-muted);
}

/* ── QR wrapper ─────────────────────────────────────────────────────────── */
.qr-wrapper {
    background: #fff;
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}

#qr-code img,
#qr-code canvas {
    display: block;
    border-radius: 4px;
}

.section-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
}

/* ── Share link ─────────────────────────────────────────────────────────── */
.share-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.share-input {
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-family: 'Consolas', 'Courier New', monospace;
    cursor: text;
}

.copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 9px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, transform .1s;
}

.copy-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.copy-btn:active {
    transform: translateY(0);
}

.copy-btn.is-copied {
    background: var(--success);
}

/* ── Participants ───────────────────────────────────────────────────────── */
.status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
    animation: pulse-dot 2s ease-in-out infinite;
}

/* ── Video grid – fix implicit row height so video fills container ────────
   Without grid-auto-rows the implicit row is "auto" = content height = 0
   when a <video> with srcObject has no intrinsic size yet.              */
.video-grid {
    grid-auto-rows: 1fr;
}

/* ── Recording button ───────────────────────────────────────────────────── */
.ctrl-btn.is-recording {
    background: var(--danger);
    border-color: var(--danger);
    animation: rec-pulse 1.4s ease-in-out infinite;
}

@keyframes rec-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: .65;
    }
}

/* ── Participant list ────────────────────────────────────────────────────── */
#participant-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 8px;
}

.participant-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 5px 8px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
}

.participant-name {
    flex: 1;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pctrl-group {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.pctrl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-hover);
    color: var(--text-muted);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.pctrl-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pctrl-btn--danger:hover {
    background: var(--danger);
    border-color: var(--danger);
}

/* ── Recordings section ──────────────────────────────────────────────────── */
#recordings-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-top: 8px;
}

.recording-link {
    display: block;
    padding: 8px 10px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 0.76rem;
    text-decoration: none;
    word-break: break-all;
    transition: background .15s;
}

.recording-link:hover {
    background: rgba(108, 99, 255, .15);
}

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    .sidebar-section {
        flex: 1;
        min-width: 200px;
        border-bottom: none;
        border-right: 1px solid var(--border);
    }

    .sidebar-section:last-child {
        border-right: none;
    }

    html,
    body {
        overflow: auto;
    }

    .layout {
        overflow: visible;
    }
}