:root {
    --bg: #0d0d1a;
    --surface: #16162a;
    --surface2: #1e1e38;
    --surface3: #282848;
    --accent: #6c63ff;
    --accent-hover: #7b73ff;
    --text: #e8e8f0;
    --text-muted: #8888aa;
    --danger: #ff4757;
    --success: #2ed573;
    --border: #2a2a44;
    --radius: 12px;
    --radius-sm: 8px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg); color: var(--text);
    height: 100vh; overflow: hidden;
}
#app { height: 100vh; display: flex; flex-direction: column; }
.screen { height: 100vh; display: flex; }

/* TOKEN SCREEN */
#token-screen { align-items: center; justify-content: center; }
.token-box {
    background: var(--surface); padding: 48px 40px 40px;
    border-radius: var(--radius); width: 420px; max-width: 90vw;
    text-align: center; border: 1px solid var(--border);
}
.brand { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 6px; }
.brand h1 { font-size: 26px; font-weight: 700; }
.subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 6px; }
.info-text { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; line-height: 1.5; }
.input-group { margin-bottom: 14px; text-align: left; }
.input-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; font-weight: 500; }
.input-group input {
    width: 100%; padding: 12px 16px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface2); color: var(--text); font-size: 15px;
    outline: none; transition: border .2s;
}
.input-group input:focus { border-color: var(--accent); }
.btn-primary {
    width: 100%; padding: 12px; border: none; border-radius: var(--radius-sm);
    background: var(--accent); color: #fff; font-size: 15px;
    font-weight: 600; cursor: pointer; transition: background .2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
    padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: transparent; color: var(--text-muted); font-size: 13px; cursor: pointer;
}
.btn-secondary:hover { color: var(--danger); border-color: var(--danger); }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 20px; }
.privacy-note { color: var(--text-muted); font-size: 11px; line-height: 1.5; margin-top: 16px; }
.admin-link {
    display: inline-block; margin-top: 14px; font-size: 11.5px;
    color: var(--text-muted); text-decoration: none;
    border-bottom: 1px dotted var(--border); padding-bottom: 1px;
}
.admin-link:hover { color: var(--accent-hover); border-color: var(--accent); }
.admin-empty { color: var(--text-muted); font-size: 13px; padding: 12px 0; }

/* ROOM SCREEN */
#room-screen { flex-direction: column; }

/* Topbar */
.room-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 20px; background: var(--surface);
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.room-info { display: flex; align-items: center; gap: 10px; }
.room-name { font-size: 16px; font-weight: 600; }
.room-meta { font-size: 12px; color: var(--text-muted); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-btn {
    padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface2); color: var(--text); cursor: pointer;
    font-size: 14px; transition: all .2s; white-space: nowrap;
}
.topbar-btn:hover { background: var(--surface3); }
.topbar-btn.leave-btn { background: var(--danger); color: #fff; border-color: var(--danger); }
.topbar-btn.leave-btn:hover { opacity: .85; }
.topbar-btn.off { opacity: .35; }
.topbar-btn.active { background: var(--success); color: #fff; border-color: var(--success); }
.video-tile audio { display: none; }
.me-tag { color: var(--text-muted); font-size: 11px; }

/* Room Content */
.room-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }

/* Video Gallery */
.video-gallery {
    flex: 1 1 auto; min-height: 130px; overflow-y: auto;
    background: var(--bg); padding: 12px;
}
.video-grid {
    display: flex; flex-wrap: wrap; gap: 12px;
    align-items: center; justify-content: center;
    min-height: 100%;
}
.video-tile {
    position: relative; background: var(--surface);
    border-radius: var(--radius); overflow: hidden;
    aspect-ratio: 16/9; min-height: 150px;
    flex: 0 1 360px; max-width: 460px; width: 100%;
    display: flex; align-items: center; justify-content: center;
}
.video-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-placeholder {
    display: none; flex-direction: column;
    align-items: center; justify-content: center; gap: 8px;
    width: 100%; height: 100%; background: var(--surface2);
}
.video-tile.video-off .video-placeholder { display: flex; }
.video-tile.video-off video { display: none; }
.placeholder-avatar {
    width: 72px; height: 72px; border-radius: 50%;
    background: var(--accent); display: flex;
    align-items: center; justify-content: center;
    font-size: 32px; font-weight: 700; color: #fff;
}
.placeholder-label { font-size: 13px; color: var(--text-muted); }
.tile-label {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 8px 12px;
    background: linear-gradient(transparent, rgba(0,0,0,.7));
    display: flex; align-items: center; gap: 6px;
}
.tile-name { font-size: 13px; font-weight: 500; }
.tile-status { font-size: 12px; }

/* Panels */
.room-panels { display: flex; flex: 0 0 auto; height: min(320px, 42vh); min-height: 190px; border-top: 1px solid var(--border); }

/* Chat Panel */
.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--border); }
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; border-bottom: 1px solid var(--border);
    font-size: 13px; font-weight: 600; color: var(--text-muted); flex-shrink: 0;
}
.chat-tabs { display: flex; gap: 4px; }
.chat-tab {
    padding: 4px 12px; border: 1px solid var(--border); border-radius: 4px;
    background: transparent; color: var(--text-muted); cursor: pointer;
    font-size: 12px; transition: all .2s;
}
.chat-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chat-title-label { font-size: 13px; }

.messages-area {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 16px;
    display: flex; flex-direction: column; gap: 6px;
}
.msg {
    max-width: 80%; padding: 8px 12px;
    border-radius: 12px; font-size: 14px; line-height: 1.4; word-wrap: break-word;
}
.msg.me { align-self: flex-end; background: var(--accent); border-bottom-right-radius: 4px; }
.msg.other { align-self: flex-start; background: var(--surface2); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: var(--text-muted); font-size: 12px; padding: 4px 12px; }
.msg.private { border-left: 3px solid var(--success); }
.msg .msg-sender { font-size: 11px; font-weight: 600; color: var(--accent-hover); margin-bottom: 2px; }
.msg.other .msg-sender { color: var(--text-muted); }
.msg .msg-time { font-size: 10px; color: rgba(255,255,255,.4); margin-top: 3px; text-align: right; }
.msg.other .msg-time { color: var(--text-muted); }
.msg .file-link { display: block; margin-top: 4px; color: var(--accent-hover); text-decoration: none; font-size: 13px; }
.msg .file-link:hover { text-decoration: underline; }
.msg .private-label { font-size: 10px; color: var(--success); font-weight: 600; margin-bottom: 2px; }

.chat-input-area {
    display: flex; gap: 8px; align-items: flex-end;
    padding: 10px 16px; border-top: 1px solid var(--border);
}
.chat-icon-btn {
    width: 36px; height: 36px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface2);
    color: var(--text); cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chat-input-area textarea {
    flex: 1; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface2); color: var(--text); font-size: 14px;
    resize: none; outline: none; min-height: 36px; max-height: 80px;
}
.chat-input-area textarea:focus { border-color: var(--accent); }
.send-btn {
    padding: 9px 20px; border: none; border-radius: var(--radius-sm);
    background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
    cursor: pointer; flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); }

/* Teilnehmer Panel */
.participants-panel { width: 240px; min-width: 240px; display: flex; flex-direction: column; }
.count-badge { background: var(--surface3); padding: 1px 8px; border-radius: 10px; font-size: 11px; margin-left: 6px; }
.participants-list { flex: 1; overflow-y: auto; padding: 8px; }
.participant-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; border-radius: var(--radius-sm);
    cursor: pointer; transition: background .2s;
}
.participant-item:hover { background: var(--surface2); }
.participant-item .p-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--accent); display: flex;
    align-items: center; justify-content: center;
    font-size: 14px; font-weight: 600; color: #fff; flex-shrink: 0;
}
.participant-item .p-name { flex: 1; font-size: 13px; }
.participant-item .p-private-btn {
    font-size: 15px; cursor: pointer; opacity: .65; transition: opacity .2s;
    background: none; border: none; color: var(--text); padding: 6px;
}
.participant-item .p-private-btn:hover { opacity: 1; }
.participant-item .p-mod-btn {
    font-size: 16px; cursor: pointer; opacity: .8; transition: opacity .2s, background .2s;
    background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 5px 7px; min-width: 34px; min-height: 32px; line-height: 1;
}
.participant-item .p-mod-btn:hover, .participant-item .p-mod-btn:active { opacity: 1; background: var(--surface3); }
.mobile-only { display: none; }
.sheet-close {
    margin-left: auto; background: none; border: none; color: var(--text-muted);
    font-size: 16px; cursor: pointer; padding: 2px 6px;
}
#hc-toast {
    position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
    background: var(--surface3); color: var(--text); border: 1px solid var(--border);
    border-left: 3px solid var(--accent); border-radius: var(--radius-sm);
    padding: 11px 16px; font-size: 13px; max-width: 88vw; z-index: 2000;
    opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
#hc-toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* Admin */
.admin-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.7); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.admin-panel {
    background: var(--surface); border-radius: var(--radius);
    width: 740px; max-width: 94vw; max-height: 80vh;
    display: flex; flex-direction: column;
}
.admin-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.admin-header h2 { font-size: 17px; }
.admin-body { padding: 20px; overflow-y: auto; flex: 1; }
.admin-create {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 20px; flex-wrap: wrap;
}
.admin-create input {
    padding: 8px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface2);
    color: var(--text); font-size: 14px; outline: none;
}
.admin-create input:focus { border-color: var(--accent); }
.admin-create span { font-size: 13px; color: var(--text-muted); }
.admin-gate-hint { color: var(--text-muted); font-size: 13px; margin-bottom: 10px; line-height: 1.5; }
.admin-gate-row { display: flex; gap: 8px; }
.admin-gate-row input {
    flex: 1; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface2);
    color: var(--text); font-size: 14px; outline: none;
}
.admin-gate-row input:focus { border-color: var(--accent); }
.admin-gate-row .btn-primary { width: auto; padding: 10px 18px; }
.admin-token-list { display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; }
.admin-token-head,
.admin-token-item {
    display: grid; grid-template-columns: minmax(210px, 1fr) 130px 100px 130px; gap: 12px; align-items: center;
}
.admin-token-head {
    padding: 0 12px 6px; font-size: 11px; text-transform: uppercase;
    letter-spacing: .04em; color: var(--text-muted); font-weight: 600;
}
.admin-token-item {
    padding: 9px 12px; background: var(--surface2);
    border-radius: var(--radius-sm); font-size: 13px;
}
.admin-token-item .tok-code {
    display: flex; align-items: center; gap: 8px; min-width: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px; color: var(--text);
}
.admin-token-item .tok-text {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    user-select: all;
}
.admin-token-item .tok-copy {
    border: 1px solid var(--border); background: transparent; color: var(--text-muted);
    border-radius: 5px; cursor: pointer; font-size: 11px; padding: 2px 7px; flex-shrink: 0;
}
.admin-token-item .tok-copy:hover { color: var(--text); border-color: var(--accent); }
.admin-token-item .tok-name { color: var(--text); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-token-item .tok-meta { color: var(--text-muted); font-size: 11.5px; white-space: nowrap; }
.admin-token-item .tok-status { font-size: 12px; font-weight: 600; white-space: nowrap; }
.admin-token-item .tok-status.open { color: var(--accent-hover); }
.admin-token-item .tok-status.used { color: var(--success); }
.admin-token-item .tok-status.expired { color: var(--danger); }

/* Gerätestatus + Ton-Banner im Raum */
.media-status {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 7px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
    font-size: 11.5px;
}
.media-status:empty { display: none; }
.mstatus {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border);
    color: var(--text-muted); white-space: nowrap;
}
.mstatus.ok { color: #6ee7a1; border-color: rgba(46,213,115,.4); background: rgba(46,213,115,.08); }
.mstatus.warn { color: #ffc266; border-color: rgba(255,165,2,.38); background: rgba(255,165,2,.08); }
.mstatus.bad { color: #ff8b95; border-color: rgba(255,71,87,.4); background: rgba(255,71,87,.1); }
.mstatus-btn {
    border: 1px solid var(--accent); background: transparent; color: var(--accent-hover);
    border-radius: 999px; padding: 3px 11px; font-size: 11.5px; cursor: pointer; font-family: inherit;
}
.mstatus-btn:hover { background: rgba(108,99,255,.15); }
.audio-banner {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 16px; background: rgba(255,165,2,.12);
    border-bottom: 1px solid rgba(255,165,2,.35); color: #ffc266; font-size: 12.5px;
}
.audio-banner-btn {
    border: 1px solid rgba(255,165,2,.6); background: transparent; color: #ffc266;
    border-radius: 6px; padding: 4px 12px; font-size: 12px; cursor: pointer; font-family: inherit;
}
.audio-banner-btn:hover { background: rgba(255,165,2,.15); }
.conn-dot {
    display: inline-block; width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-muted); margin: 0 6px; flex-shrink: 0;
}
.conn-dot.ok { background: var(--success); }
.conn-dot.warn { background: var(--warn, #ffa502); }
.conn-dot.bad { background: var(--danger); }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Handy / kleine Tablets */
@supports (height: 100dvh) {
    body, #app, .screen { height: 100dvh; }
}
@media (max-width: 820px) {
    .room-topbar { padding: 8px 10px; gap: 8px; }
    .room-info { min-width: 0; }
    .room-info > svg { display: none; }
    .room-name { font-size: 14px; }
    .room-meta {
        font-size: 11px; max-width: 40vw;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .topbar-actions { gap: 5px; }
    .topbar-btn { padding: 8px 10px; font-size: 15px; }
    .topbar-btn.leave-btn { font-size: 12px; padding: 8px 10px; }
    .mobile-only { display: inline-flex; align-items: center; gap: 3px; }

    .media-status { padding: 6px 10px; flex-wrap: nowrap; overflow-x: auto; }
    .media-status::-webkit-scrollbar { display: none; }

    .video-gallery { flex: 0 0 auto; max-height: 44vh; padding: 8px; }
    .video-grid { gap: 8px; }
    .video-tile { flex: 1 1 100%; max-width: none; min-height: 120px; }

    .room-panels { height: auto; flex: 1 1 auto; min-height: 0; flex-direction: column; }
    .chat-panel { border-right: none; }
    .chat-input-area textarea { font-size: 16px; }  /* sonst zoomt iOS beim Tippen */

    /* Teilnehmerliste als hochschiebbares Blatt */
    .participants-panel {
        position: fixed; left: 0; right: 0; bottom: 0; top: auto;
        width: 100%; min-width: 0; max-height: 66vh; z-index: 60;
        background: var(--surface); border-top: 1px solid var(--border);
        border-radius: 14px 14px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.55);
        transform: translateY(103%); transition: transform .22s ease;
    }
    .participants-panel.open { transform: translateY(0); }
    .participants-list { padding: 6px 8px calc(16px + env(safe-area-inset-bottom, 0px)); }
    .participant-item { padding: 10px 8px; }
    .participant-item .p-mod-btn { min-width: 44px; min-height: 44px; font-size: 18px; }
    .participant-item .p-private-btn { min-width: 44px; min-height: 44px; font-size: 17px; }
}
@media (max-width: 430px) {
    .room-name { font-size: 13px; }
    .topbar-btn { padding: 7px 8px; font-size: 14px; }
    .video-tile { min-height: 150px; }
}