/* Scoped styles: reuse the palette variables without changing server chat. */
#dmView[hidden],#dmList[hidden],#callStage[hidden],#screenWrap[hidden],#localScreen[hidden],#callOpen[hidden]{display:none!important}
#chat{position:relative} #dmView{position:absolute;inset:0;background:var(--main);z-index:3;display:flex;flex-direction:column;min-width:0;overflow:hidden}
#dmList{flex:1;overflow-y:auto;padding:8px} .dm-list-btn{display:flex;gap:8px;align-items:center;width:100%;border:0;border-radius:6px;padding:8px;background:transparent;color:var(--muted);text-align:left;overflow:hidden}.dm-list-btn:hover,.dm-list-btn.active{background:var(--input);color:var(--text)} .dm-list-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dm-list-btn .ava{width:28px;height:28px;font-size:13px;cursor:default}
.dm-header{gap:8px}.dm-header strong{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dm-btn{border:0;border-radius:6px;background:var(--input);color:var(--text);padding:8px 10px;font:inherit;cursor:pointer}.dm-btn:hover{background:var(--accent);color:white}.dm-btn:disabled{opacity:.5;cursor:not-allowed}.dm-btn[aria-pressed=true]{background:var(--accent);color:white}.dm-btn.danger{background:#a33945;color:white}
.dm-messages{flex:1 1 auto;overflow-y:auto;padding:16px 0;min-height:0}.dm-messages .msg{overflow-wrap:anywhere}.dm-bottom{flex:0 0 auto;padding:0 16px 8px}.dm-bottom form{display:flex;align-items:center;gap:8px;background:var(--rail);border-radius:8px;padding:8px}.dm-bottom textarea{resize:none;flex:1;min-width:0;height:44px;background:transparent;border:0;color:var(--text);font:inherit;padding:10px;outline:none}#dmTyping{min-height:20px;color:var(--muted);font-size:13px}#dmStatus{color:var(--danger);font-size:13px;margin:3px 0;min-height:1em}
.call-stage{flex:0 0 auto;background:var(--rail);padding:10px;max-height:48%;overflow:auto}.call-participants{display:flex;align-items:center;gap:10px;color:var(--muted)}.call-avatar{width:42px;height:42px;border-radius:50%;background:var(--input);display:grid;place-items:center;color:var(--text);font-weight:700;overflow:hidden}.call-avatar.speaking{outline:3px solid var(--online)}.call-controls{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:10px}.call-controls .dm-btn{min-height:36px;padding:7px 10px}.call-controls .dm-btn.icon-button{display:grid;place-items:center;flex:0 0 44px;width:44px;min-width:44px;height:44px;min-height:44px;padding:0;border-radius:50%}.call-controls .dm-btn.icon-button svg{display:block;width:21px;height:21px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}.call-controls #callEnd{margin-left:auto}.call-grid{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}.call-grid video{background:#121318;max-height:180px;max-width:220px;border-radius:8px}.call-grid video:not([srcObject]){min-width:0}.call-grid #screenWrap{flex:1 1 100%;min-width:0}.call-grid #screenVideo{width:100%;max-width:none;max-height:38vh;object-fit:contain}.screen-controls{display:flex;align-items:center;gap:12px}.screen-controls label{display:flex;align-items:center;gap:8px}.screen-controls input{width:100px;padding:0}
#callOpen{position:fixed;z-index:10;right:18px;bottom:18px;display:grid;place-items:center;width:48px;height:48px;padding:0;border:1px solid rgba(255,255,255,.2);border-radius:50%;background:var(--accent);color:#fff;box-shadow:0 8px 24px #0008;cursor:pointer}
#callOpen:hover{filter:brightness(1.12)}
#callOpen svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
#incomingCall{background:var(--side);color:var(--text);border:1px solid var(--accent);border-radius:12px;padding:24px;width:min(390px,92vw);animation:call-pulse 1.3s ease-in-out infinite}#incomingCall::backdrop{background:#0009}.incoming-actions{display:flex;gap:10px} @keyframes call-pulse{50%{box-shadow:0 0 0 7px #4f8cff44}} @media(max-width:520px){#callOpen{right:12px;bottom:calc(12px + env(safe-area-inset-bottom))}.dm-bottom{padding:0 6px 6px}.call-grid video{max-width:48%}.dm-header .dm-btn{font-size:12px}}

.dm-rail{position:relative}.dm-rail[data-unread=true]::after{content:'';position:absolute;right:1px;top:1px;width:10px;height:10px;background:var(--danger);border:2px solid var(--rail);border-radius:50%}

/* Keep the call controls inside the call view instead of covering the composer. */
.call-grid #screenWrap{order:-1}
.call-grid #screenVideo{max-height:26vh}
.call-grid video:not(#screenVideo){max-height:120px}

/* Videos load on demand and never overflow a conversation column. */
.video-player{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:8px 0;max-width:min(100%,460px);min-width:0}
.video-player .chat-video{flex:1 0 100%;display:block;width:100%;max-width:100%;max-height:55vh;border-radius:10px;background:#111;object-fit:contain}
.video-player .chat-video[hidden]{display:none}.video-status{font-size:13px;color:var(--muted)}
.dm-video-button{flex:none;width:44px;height:44px;font-size:22px}.mobile-nav-toggle,.mobile-backdrop{display:none}

@media(max-width:700px){
  html,body{height:100%;overflow:hidden}
  #auth{height:100vh;height:100dvh;min-height:0;overflow-y:auto;align-items:start;padding:calc(24px + env(safe-area-inset-top)) 0 calc(24px + env(safe-area-inset-bottom))}
  #app{height:100vh;height:100dvh;grid-template-columns:minmax(0,1fr);position:relative}
  #chat{grid-column:1;min-width:0;width:100%;height:100%;padding-top:env(safe-area-inset-top)}
  #members,#rail,#side{display:none}
  #app.mobile-menu-open #rail{display:flex;position:fixed;z-index:22;top:0;bottom:0;left:0;width:64px;padding-top:calc(12px + env(safe-area-inset-top));padding-bottom:env(safe-area-inset-bottom)}
  #app.mobile-menu-open #side{display:flex;position:fixed;z-index:22;top:0;bottom:0;left:64px;width:min(320px,calc(100vw - 64px));padding-top:env(safe-area-inset-top);padding-bottom:env(safe-area-inset-bottom);box-shadow:8px 0 28px #0008}
  #app.mobile-menu-open #mobileBackdrop{display:block;position:fixed;inset:0;z-index:21;border:0;background:#0009}
  .mobile-nav-toggle{display:inline-grid;place-items:center;flex:none;width:44px;height:44px;margin-left:-8px;border:0;border-radius:7px;background:transparent;color:var(--text);font-size:21px}
  .mobile-menu-icon{display:block;width:20px;height:2px;border-radius:2px;background:currentColor;box-shadow:0 -6px 0 currentColor,0 6px 0 currentColor}
  .mobile-nav-toggle:active{background:var(--input)}
  #chat>header,#dmView>.dm-header{justify-content:flex-start;gap:8px;min-width:0}
  #chat>header #chName,#dmTitle{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  #dmView{padding-top:env(safe-area-inset-top)}
  #msgs,.dm-messages{overscroll-behavior:contain}
  #msgs .msg,.dm-messages .msg{padding:7px 10px;gap:8px}
  .msg>div:last-child{min-width:0;max-width:calc(100% - 46px)}
  #bottom,.dm-bottom{padding-left:8px;padding-right:8px;padding-bottom:calc(8px + env(safe-area-inset-bottom))}
  #composer{min-height:56px}#attach,#emojiToggle{width:44px;height:44px}
  #msg,#dmInput{font-size:16px;min-height:44px}
  .dm-bottom form{gap:3px;padding:4px}.dm-bottom form>button[type=submit]{font-size:13px;min-height:44px;padding:6px 8px}
  .call-stage{max-height:44%;padding:8px}.call-controls .dm-btn{min-height:40px;font-size:12px;padding:6px 8px}.call-grid #screenVideo{max-height:24vh}.screen-controls{flex-wrap:wrap}
  .video-player{max-width:100%}.video-player .chat-video{max-height:44vh}
}
/* Chat attachments only. WebRTC call elements keep their own presentation. */
.media-stage{position:relative;flex:1 0 100%;min-width:0;background:var(--rail);border:1px solid #ffffff1c;border-radius:10px;overflow:hidden}
.media-stage[hidden]{display:none}.video-player .chat-video{width:100%;max-width:100%;display:block;max-height:55vh;object-fit:contain;background:#111}
.video-player .chat-audio{display:none}.media-controls{display:flex;align-items:center;gap:4px;padding:6px;background:var(--rail);color:var(--text);min-width:0}
.video-player .media-controls{position:absolute;inset:auto 0 0;background:linear-gradient(transparent,#101116f2);padding:22px 8px 8px;transition:opacity .2s ease}
.video-player .media-stage.controls-hidden .media-controls{opacity:0;pointer-events:none}.video-player .media-stage:focus-within .media-controls{opacity:1;pointer-events:auto}
.media-controls button{flex:none;border:0;background:#32353dcc;color:#fff;border-radius:6px;min-width:36px;height:36px;padding:0 7px;font:inherit;font-size:13px}.media-controls button:hover{background:var(--accent)}.media-controls button[hidden]{display:none}
.media-timeline,.media-volume{appearance:none;-webkit-appearance:none;border:0;padding:0;min-width:0;height:6px;border-radius:4px;cursor:pointer;touch-action:pan-y}
.media-timeline{flex:1;background:linear-gradient(to right,var(--accent) 0 var(--played,0%),#b8c1d1 var(--played,0%) var(--buffer,0%),#666c78 var(--buffer,0%) 100%)}.media-volume{width:58px;background:#777;accent-color:var(--accent)}
.media-timeline::-webkit-slider-thumb,.media-volume::-webkit-slider-thumb{-webkit-appearance:none;width:14px;height:14px;border-radius:50%;background:#fff}.media-timeline::-moz-range-thumb,.media-volume::-moz-range-thumb{width:14px;height:14px;border:0;border-radius:50%;background:#fff}
.media-time{flex:none;color:#fff;font-size:12px;font-variant-numeric:tabular-nums;white-space:nowrap}.audio-player .media-controls{position:static;background:var(--input);padding:8px}.audio-player .media-time{color:var(--text)}
.media-stage:fullscreen{display:flex;align-items:center;justify-content:center;background:#101116}.media-stage:fullscreen .chat-video{max-height:100vh;height:100%;object-fit:contain}
@media(max-width:700px){.media-controls{gap:3px}.media-controls button{min-width:38px;height:44px;padding:0 5px}.media-volume{width:38px}.media-time{font-size:11px}.video-player .media-controls{padding:24px 5px 5px}.video-player .chat-video{max-height:44vh}}
@media(prefers-reduced-motion:reduce){.video-player .media-controls{transition:none}}

.media-controls button svg{display:block;width:20px;height:20px;margin:auto}
@media(max-width:700px){
  .video-player:not(.audio-player) .media-controls{flex-wrap:wrap;gap:2px}
  .video-player:not(.audio-player) .media-timeline{order:-1;flex:0 0 100%;height:6px;margin:4px 0 6px}
  .video-player:not(.audio-player) .media-controls button{min-width:38px;height:44px}
  .video-player:not(.audio-player) .media-volume{width:32px}
}
.video-player:not(.audio-player) .media-controls{flex-wrap:wrap}
.video-player:not(.audio-player) .media-timeline{order:-1;flex:0 0 100%;height:6px;margin:4px 0 6px}

/* Inline media is visible immediately; loading has no extra caption. */
.media-stage.is-loading::after{content:'';position:absolute;top:12px;right:12px;width:16px;height:16px;border:2px solid #ffffff55;border-top-color:#fff;border-radius:50%;animation:media-spin .8s linear infinite;pointer-events:none}
@keyframes media-spin{to{transform:rotate(360deg)}}
.media-retry{border:0;background:var(--input);color:var(--text);border-radius:6px;padding:8px 12px;font:inherit;cursor:pointer}.media-retry[hidden]{display:none}
.video-player:not(.audio-player) .chat-video{aspect-ratio:16/9}
.att img[hidden]{display:none}.att img{max-width:min(360px,100%);max-height:300px;object-fit:contain}
@media(prefers-reduced-motion:reduce){.media-stage.is-loading::after{animation:none}}

/* Keep the timeline and actions on separate compact rows on narrow screens. */
.video-player:not(.audio-player) .media-controls{display:flex;flex-direction:column;align-items:stretch;flex-wrap:nowrap;gap:5px}
.video-player:not(.audio-player) .media-progress,.media-video-row{display:flex;align-items:center;gap:5px;min-width:0;width:100%}
.video-player:not(.audio-player) .media-timeline{order:0;flex:1 1 auto;width:auto;margin:0}
.media-video-row{justify-content:space-between}.media-video-row .media-volume{flex:1 1 30px;max-width:58px}
@media(max-width:700px){.video-player:not(.audio-player) .media-controls{padding:18px 5px 5px}.media-video-row{gap:2px}.media-video-row button{min-width:36px!important;width:36px;height:40px!important;padding:0!important}.media-video-row .media-volume{max-width:34px}.media-time{font-size:11px}.audio-player .media-controls{gap:3px}.audio-player .media-timeline{min-width:30px}}
.message-link{color:#8fc7ff;overflow-wrap:anywhere;text-decoration:underline;text-underline-offset:2px}.message-link:hover{color:#bee0ff}
.link-preview{position:relative;max-width:440px;margin-top:8px;border:1px solid #ffffff1a;border-left:3px solid var(--accent);border-radius:8px;background:var(--input);overflow:hidden}.link-preview.loading{height:8px;opacity:.55}.link-preview-content{display:flex;flex-direction:column;gap:5px;padding:12px 38px 12px 12px;color:var(--text);text-decoration:none;overflow-wrap:anywhere}.link-preview-site{font-size:12px;color:var(--muted)}.link-preview-title{font-size:14px;color:#9dcaff}.link-preview-description{font-size:13px;line-height:1.4;color:var(--text)}.link-preview-image{display:block;max-width:100%;max-height:240px;width:auto;object-fit:contain;border-radius:6px;margin-top:5px}.link-preview-close{position:absolute;z-index:1;top:4px;right:4px;width:32px;height:32px;border:0;border-radius:6px;background:transparent;color:var(--muted);font-size:22px;cursor:pointer}.link-preview-close:hover,.link-preview-close:focus-visible{color:var(--text);background:#ffffff18}.link-preview.loading .link-preview-close{display:none}
/* Expand the message body independently of the source video's resolution. */
#msgs .msg > div:last-child,.dm-messages .msg > div:last-child{flex:1 1 auto;min-width:0}
.video-player:not(.audio-player){width:min(100%,460px)}

.voice-record-trigger{position:relative;display:grid;place-items:center;flex:none;width:44px;height:44px;min-width:44px;min-height:44px;padding:0;border:0;border-radius:10px;background:transparent;color:var(--muted);cursor:pointer}
.voice-record-trigger svg{width:21px;height:21px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.voice-record-trigger:not(:disabled):hover{background:color-mix(in srgb,var(--accent) 20%,transparent);color:var(--text)}
.voice-record-trigger:disabled{opacity:.42;cursor:not-allowed}
.voice-recorder-panel{display:flex;align-items:center;flex-wrap:wrap;gap:10px;margin:0 0 8px;padding:10px 12px;border:1px solid var(--line-2);border-radius:12px;background:color-mix(in srgb,var(--side) 90%,transparent);color:var(--text)}
.voice-recorder-panel[hidden]{display:none!important}
.voice-recorder-info{display:flex;align-items:center;gap:9px;min-width:0;flex:1 1 150px}
.voice-recorder-title{font-size:13px;font-weight:600}
.voice-recorder-time{color:var(--muted);font-size:12px;font-variant-numeric:tabular-nums}
.voice-recorder-dot{width:9px;height:9px;flex:none;border-radius:50%;background:var(--muted)}
.voice-recorder-panel.is-recording .voice-recorder-dot{background:var(--danger);box-shadow:0 0 0 4px color-mix(in srgb,var(--danger) 18%,transparent);animation:voice-pulse 1.2s ease-in-out infinite}
.voice-recorder-panel.is-review .voice-recorder-dot{background:var(--online)}
.voice-recorder-actions{display:flex;gap:6px;flex:none}
.voice-recorder-actions button{min-height:38px;padding:7px 12px;border:1px solid var(--line-2);border-radius:9px;background:var(--glass);color:var(--text);font:inherit;font-size:13px;font-weight:600;cursor:pointer}
.voice-recorder-actions button[hidden]{display:none!important}
.voice-recorder-actions .voice-recorder-send{border-color:transparent;background:var(--accent);color:#fff}
.voice-recorder-actions button:disabled{opacity:.5;cursor:not-allowed}
.voice-recorder-preview{flex:1 1 100%;width:min(100%,420px);height:40px}
.voice-recorder-status{display:none;margin:2px 8px 6px;color:var(--muted);font-size:12px;overflow-wrap:anywhere}
.voice-recorder-status:not(:empty){display:block}

/* Voice notes use a soft-touch bubble; the native range remains keyboard-seekable. */
.audio-player{display:block;width:min(100%,420px);max-width:100%;min-width:0;margin:8px 0}
.audio-player .media-stage.audio-stage{display:block;flex:none;width:100%;min-width:0;overflow:visible;border:0;border-radius:26px;background:transparent}
.audio-player .chat-audio{display:none}
.audio-player .media-controls.audio-controls{display:block;position:static;inset:auto;min-width:0;padding:0;background:transparent}
.audio-bubble{display:grid;grid-template-columns:56px minmax(0,1fr);align-items:center;gap:13px;width:100%;min-width:0;padding:14px 16px;border-radius:25px}
.audio-play{position:relative;z-index:0;display:grid;place-items:center;flex:none;width:56px;height:56px;min-width:56px;min-height:56px;padding:0;border:0;border-radius:50%;color:var(--accent);background:var(--text);box-shadow:inset 0 1px 2px #ffffffa8,inset 0 -3px 6px #0002,0 5px 14px #0003;cursor:pointer}
.audio-play svg{width:23px;height:23px}
.audio-content{display:grid;gap:8px;min-width:0}
.audio-waveform{position:relative;display:flex;align-items:center;justify-content:space-between;gap:2px;width:100%;height:32px;min-width:0;overflow:hidden}
.audio-wave-bar{position:relative;z-index:0;display:block;flex:0 1 3px;min-width:2px;max-width:4px;border-radius:999px;background:var(--audio-wave,var(--muted));opacity:.57;transition:background-color .16s,opacity .16s}
.audio-wave-bar.is-played{background:var(--audio-progress,var(--accent));opacity:1}
.audio-player .media-timeline.audio-timeline{position:absolute;z-index:2;inset:0;width:100%;height:100%;margin:0;padding:0;border:0;border-radius:0;background:transparent;opacity:0;cursor:pointer;touch-action:pan-x}
.audio-player .media-timeline.audio-timeline:focus-visible{opacity:.35;outline:2px solid var(--accent-2);outline-offset:2px}
.audio-player .media-timeline.audio-timeline::-webkit-slider-runnable-track{height:100%;background:transparent}
.audio-player .media-timeline.audio-timeline::-moz-range-track{height:100%;background:transparent}
.audio-player .media-timeline.audio-timeline::-webkit-slider-thumb{-webkit-appearance:none;width:14px;height:14px;border:2px solid white;border-radius:50%;background:var(--accent);box-shadow:0 1px 5px #0007}
.audio-player .media-timeline.audio-timeline::-moz-range-thumb{width:14px;height:14px;border:2px solid white;border-radius:50%;background:var(--accent);box-shadow:0 1px 5px #0007}
.audio-footer{display:flex;align-items:center;gap:7px;min-width:0;font-size:12px;font-variant-numeric:tabular-nums;line-height:1}
.audio-current-time{color:var(--text);font-weight:650;white-space:nowrap}
.audio-duration{color:var(--audio-muted,var(--muted));white-space:nowrap}
.audio-speed{flex:none;width:auto;min-width:36px!important;height:26px!important;margin-left:auto;padding:0 7px!important;border:1px solid color-mix(in srgb,var(--audio-progress,var(--accent)) 32%,transparent)!important;border-radius:999px!important;background:color-mix(in srgb,var(--audio-progress,var(--accent)) 12%,transparent)!important;color:var(--text)!important;font-size:11px!important;font-weight:650!important}
.audio-speed:hover{background:color-mix(in srgb,var(--audio-progress,var(--accent)) 25%,transparent)!important}
.audio-player .video-status{display:block;margin-top:5px}
.audio-player .media-stage.is-loading::after{top:8px;right:8px;width:12px;height:12px}
.sound-player .media-controls.sound-controls{position:static;display:grid;grid-template-columns:54px minmax(0,1fr);align-items:center;gap:14px;padding:14px;border:1px solid var(--line-2);border-radius:20px;background:var(--card)}
.sound-player .sound-play{display:grid;place-items:center;width:54px;height:54px;min-width:54px;padding:0;border-radius:50%;color:var(--accent-text);background:var(--accent)}
.sound-player .sound-play svg{width:22px;height:22px}
.sound-player .sound-play:active{transform:translateY(1px)}
.sound-player .sound-play:focus-visible{outline:2px solid var(--accent-2);outline-offset:3px}
.sound-card{display:grid;gap:8px;min-width:0}
.sound-heading{display:flex;align-items:center;gap:9px;min-width:0}
.sound-icon{display:grid;place-items:center;flex:none;width:30px;height:30px;border-radius:9px;color:var(--accent-2);background:color-mix(in srgb,var(--accent) 16%,var(--input));font-size:19px}
.sound-details{display:flex;align-items:baseline;gap:8px;min-width:0}
.sound-title{overflow:hidden;color:var(--text);font-size:13px;text-overflow:ellipsis;white-space:nowrap}
.sound-format{flex:none;color:var(--muted);font-size:10px;font-weight:700;letter-spacing:.07em}
.sound-progress{min-width:0}
.sound-player .media-timeline{display:block;width:100%;height:5px}
.sound-footer{display:flex;align-items:center;gap:7px;min-width:0;color:var(--muted);font-size:12px;font-variant-numeric:tabular-nums}
.sound-current,.sound-duration{color:var(--text);font-weight:650;white-space:nowrap}
.sound-time-separator{color:var(--muted)}
.sound-format[hidden]{display:none}
.sound-download{display:grid;place-items:center;flex:none;width:36px!important;min-width:36px!important;height:36px!important;padding:0!important;border:1px solid var(--line-2)!important;border-radius:11px!important;color:var(--text)!important;background:var(--input)!important;font-size:18px!important;line-height:1}
.sound-download:hover{background:var(--accent)!important}
.sound-download:disabled{opacity:.55;cursor:wait}
@media(max-width:700px){
  .audio-player{width:min(100%,400px)}
  .sound-player .media-controls.sound-controls{grid-template-columns:46px minmax(0,1fr);gap:10px;padding:11px;border-radius:17px}
  .sound-player .sound-play{width:46px;height:46px;min-width:46px}
  .sound-footer{gap:5px}
  .audio-bubble{grid-template-columns:50px minmax(0,1fr);gap:10px;padding:12px 13px;border-radius:22px}
  .audio-play{width:50px;height:50px;min-width:50px;min-height:50px}
  .audio-waveform{height:30px}
  .audio-player .media-controls.audio-controls{gap:0}
}
#dmStatus:not(:empty){margin-top:4px}
@keyframes voice-pulse{50%{opacity:.55;transform:scale(.9)}}
@media(prefers-reduced-motion:reduce){.voice-recorder-panel.is-recording .voice-recorder-dot{animation:none}}
@media(max-width:700px){#voiceChannelButton{width:40px;min-width:40px}#dmView #dmVoiceButton{width:36px;min-width:36px}}
@media(max-width:370px){#dmView #dmVoiceButton{width:32px;min-width:32px}}
