/* ==========================================================================
   Shared styles — live screen & camera sharing
   ========================================================================== */

:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e8eaed;
    --text-dim: #9aa3b2;
    --accent: #4f8cff;
    --accent-hover: #3d7aff;
    --danger: #ff4d4f;
    --success: #22c55e;
    --warn: #f59e0b;
    --radius: 12px;
    --shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 64px;
}

/* ---------- Header ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.topbar nav { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.card h2 { margin: 0 0 6px; font-size: 19px; }
.card p.sub { margin: 0 0 20px; color: var(--text-dim); font-size: 14px; line-height: 1.55; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

/* ---------- Buttons ---------- */
button, .btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 11px 18px;
    font-size: 15px;
    font-family: inherit;
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
button:hover:not(:disabled), .btn:hover { background: #262b36; border-color: #3a4150; }
button:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 13px; font-size: 13px; border-radius: 8px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Inputs ---------- */
label.field { display: block; margin-bottom: 8px; font-size: 13px; color: var(--text-dim); font-weight: 500; }
input[type="text"] {
    width: 100%;
    padding: 13px 15px;
    font-size: 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: inherit;
}
input[type="text"]:focus { outline: none; border-color: var(--accent); }
input.code-input {
    font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
    letter-spacing: 3px;
    text-transform: uppercase;
    text-align: center;
    font-size: 19px;
}

/* ---------- Room ID display ---------- */
.room-id-box {
    background: var(--bg);
    border: 2px dashed var(--accent);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    margin: 16px 0;
}
.room-id-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--text-dim); margin-bottom: 10px; }
.room-id {
    font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
    font-size: clamp(20px, 5.5vw, 32px);
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--accent);
    word-break: break-all;
    line-height: 1.35;
}

/* ---------- Video ---------- */
/* The shell follows the incoming video's shape. --ar is set from JS whenever
   the track's dimensions change, so a phone rotating to landscape reflows the
   container instead of letterboxing a portrait frame inside a 16:9 box. */
.video-shell {
    position: relative;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    aspect-ratio: var(--ar, 16 / 9);
    /* Portrait video on a tall screen would otherwise push the controls off
       the page, so cap the height and let width shrink to match. */
    max-height: 78vh;
    margin: 0 auto;
    transition: aspect-ratio .28s ease;
    /* Establishes cqw/cqh units, which the rotation correction uses to size a
       quarter-turned video against the container's opposite dimension. */
    container-type: size;
}
.video-shell video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #000;
}

/* Fullscreen: fill the screen edge-to-edge, ignoring the tracked ratio. */
.video-shell:fullscreen,
.video-shell:-webkit-full-screen {
    aspect-ratio: auto;
    max-height: none;
    width: 100vw;
    height: 100vh;
    border: none;
    border-radius: 0;
}
.video-shell:fullscreen video { object-fit: contain; }
.video-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-dim);
    text-align: center;
    padding: 24px;
    background: var(--surface);
}
.video-overlay.hidden { display: none; }

.live-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    background: var(--danger);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .6px;
    padding: 5px 11px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 2;
}
.live-badge::before {
    content: "";
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #fff;
    animation: blink 1.4s infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---------- Status / alerts ---------- */
.status {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 14px;
    color: var(--text-dim);
    padding: 11px 14px;
    background: var(--surface-2);
    border-radius: 9px;
    margin: 14px 0;
    line-height: 1.5;
}
.status .ind { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.status.ok .ind { background: var(--success); }
.status.err .ind { background: var(--danger); }
.status.warn .ind { background: var(--warn); }
.status.live .ind { background: var(--danger); animation: blink 1.4s infinite; }

.alert { padding: 13px 15px; border-radius: 9px; font-size: 14px; margin: 14px 0; line-height: 1.55; }
.alert-warn { background: rgba(245, 158, 11, .12); border: 1px solid rgba(245, 158, 11, .35); color: #fcd34d; }
.alert-err { background: rgba(255, 77, 79, .12); border: 1px solid rgba(255, 77, 79, .35); color: #ffa3a4; }
.alert-info { background: rgba(79, 140, 255, .1); border: 1px solid rgba(79, 140, 255, .3); color: #a9c6ff; }

/* ---------- Viewer list ---------- */
.people { list-style: none; margin: 0; padding: 0; }
.person {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 15px;
    background: var(--surface-2);
    border-radius: 10px;
    margin-bottom: 9px;
    flex-wrap: wrap;
}
.person-meta { min-width: 0; }
.person-name { font-weight: 600; font-size: 14px; }
.person-sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; font-family: monospace; }
.person-actions { display: flex; gap: 7px; flex-shrink: 0; }
.person.pending { border: 1px solid var(--warn); background: rgba(245, 158, 11, .07); }

.empty { color: var(--text-dim); font-size: 14px; text-align: center; padding: 22px; }

/* ---------- Capture bar (viewer side) ---------- */
.capture-bar {
    margin-top: 16px;
    padding: 15px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 11px;
}
.capture-bar-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.1px;
    color: var(--text-dim);
    margin-bottom: 11px;
    font-weight: 600;
}
.capture-hint { font-size: 12.5px; color: var(--text-dim); margin-top: 11px; line-height: 1.5; }

/* Recording state: pulse the button so it is obvious a capture is running. */
#recBtn.recording {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    font-weight: 600;
    animation: recpulse 1.5s infinite;
}
@keyframes recpulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, .55); }
    70%      { box-shadow: 0 0 0 9px rgba(255, 77, 79, 0); }
}

/* Brief white flash over the video to acknowledge a screenshot. */
.shutter {
    position: absolute;
    inset: 0;
    background: #fff;
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}
.shutter.fire { animation: shutter .32s ease-out; }
@keyframes shutter { 0% { opacity: .85; } 100% { opacity: 0; } }

/* ---------- Capture gallery ---------- */
.shot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 11px;
}
.shot {
    position: relative;
    border-radius: 9px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #000;
}
/* Thumbnails keep a uniform grid, but 'contain' preserves portrait captures
   instead of cropping their sides off. */
.shot img, .shot video {
    width: 100%;
    display: block;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: #000;
}
.shot-actions {
    display: flex;
    gap: 5px;
    padding: 7px;
    background: var(--surface-2);
}
.shot-actions button { flex: 1; padding: 5px 7px; font-size: 11.5px; border-radius: 6px; }
.shot-tag {
    position: absolute;
    top: 6px; left: 6px;
    background: rgba(0, 0, 0, .72);
    color: #fff;
    font-size: 10.5px;
    padding: 2px 7px;
    border-radius: 4px;
}

/* ---------- Misc ---------- */
.hidden { display: none !important; }
.qr-box { text-align: center; margin: 16px 0; }
.qr-box canvas, .qr-box img { background: #fff; padding: 10px; border-radius: 10px; max-width: 190px; height: auto; }
.share-link {
    font-family: monospace;
    font-size: 12.5px;
    color: var(--text-dim);
    word-break: break-all;
    background: var(--bg);
    padding: 11px;
    border-radius: 8px;
    margin-top: 10px;
}
.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }
.count-badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; margin-left: 7px; }

.section-title { display: flex; align-items: center; font-size: 15px; font-weight: 600; margin: 0 0 13px; }

footer.foot { text-align: center; color: var(--text-dim); font-size: 13px; padding: 28px 20px; line-height: 1.7; }

@media (max-width: 600px) {
    .wrap { padding: 16px 14px 48px; }
    .card { padding: 18px; }
    .btn-row button, .btn-row .btn { flex: 1 1 auto; }
}
