/* ======================================================================
   Design tokens — one place to tune the whole theme.
   Direction: depth-by-surface (shade + soft shadow) instead of borders.
   ====================================================================== */
:root {
  color-scheme: dark;
  --bg-deep: #0b0d11;   /* recessed surfaces: sidebar, chat log, tiles area, logs */
  --bg:      #0e1014;   /* app canvas */
  --s1:      #161a21;   /* panels, cards, modals, heads, pills */
  --s2:      #1d222b;   /* raised: message bubbles, inputs, ghost buttons */
  --s3:      #262c37;   /* hover / active */
  --text:    #e7e9ee;
  --muted:   #9aa3b0;
  --faint:   #6b7480;
  --accent:  #3b82f6;
  --accent-h:#2f6fe0;
  --accent-soft: rgba(59,130,246,.16);
  --accent-tint: rgba(59,130,246,.10);
  --bubble-mine: #20395a;
  --hairline: rgba(255,255,255,.07);
  --danger:  #c8474f;
  --danger-h:#d6565e;
  --ok:      #41c971;
  --warn:    #f2c14e;
  --r: 12px; --r-sm: 9px; --r-pill: 999px;
  --sh-sm: 0 2px 12px rgba(0,0,0,.30);
  --sh-lg: 0 24px 64px rgba(0,0,0,.5);
}
* { box-sizing: border-box; }
::selection { background: rgba(59,130,246,.35); }

/* thin, unobtrusive scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.16) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,.13); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.24); background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

body {
  margin: 0; min-height: 100vh; display: grid; place-items: center;
  background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 24px; -webkit-font-smoothing: antialiased;
}

.card { background: var(--s1); border: none; border-radius: 16px; padding: 28px; width: 100%; max-width: 440px; box-shadow: var(--sh-lg); }
.card.wide { max-width: 960px; }

h1 { margin: 0 0 8px; font-size: 22px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

button { font: inherit; cursor: pointer; border: none; background: var(--s2); color: var(--text); padding: 10px 16px; border-radius: var(--r-sm); transition: background .14s, color .14s, box-shadow .14s, opacity .14s; }
button:hover { background: var(--s3); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-h); }
button.big { font-size: 18px; padding: 14px 22px; width: 100%; margin-top: 8px; }

.linkrow { display: flex; gap: 8px; margin: 4px 0 16px; }
.linkrow input { flex: 1; padding: 11px 13px; border-radius: var(--r-sm); border: none; background: var(--s2); color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.linkrow input:focus { outline: none; box-shadow: inset 0 0 0 1px var(--accent); }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.badge { color: var(--muted); font-size: 14px; margin-left: auto; }
.status { color: #cbd1da; min-height: 1.4em; font-size: 14px; }

video { width: 100%; border-radius: var(--r); background: #000; margin-top: 12px; aspect-ratio: 16 / 9; object-fit: contain; }
#preview { max-height: 300px; }

.videowrap { position: relative; }
.overlay { position: absolute; top: 22px; right: 12px; display: flex; gap: 8px; }
.overlay-btn { background: rgba(15,17,21,.72); backdrop-filter: blur(4px); }
.overlay-btn:hover { background: rgba(15,17,21,.92); }
.videowrap:fullscreen, .videowrap:-webkit-full-screen { width: 100vw; height: 100vh; background: #000; display: flex; align-items: center; justify-content: center; }
.videowrap:fullscreen video, .videowrap:-webkit-full-screen video { width: 100%; height: 100%; max-height: 100vh; aspect-ratio: auto; border-radius: 0; margin: 0; }
.videowrap:fullscreen .overlay, .videowrap:-webkit-full-screen .overlay { top: 16px; right: 16px; }

/* ---- collaboration room ---- */
.roomhead { display: flex; align-items: center; gap: 12px; }
.roomhead h1 { margin: 0; }
.roomhead .badge { margin-left: auto; }

.grid { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 16px; }
.tile { background: var(--s1); border: none; border-radius: var(--r); overflow: hidden; flex: 1 1 520px; min-width: 0; max-width: 100%; display: flex; flex-direction: column; box-shadow: var(--sh-sm); }
.share-offer { aspect-ratio: 16 / 9; max-height: 64vh; align-items: center; justify-content: center; text-align: center; gap: 6px; padding: 18px; background: var(--s1); }
.share-offer .so-ico { font-size: 34px; line-height: 1; opacity: .9; }
.share-offer .so-name { font-weight: 700; font-size: 15px; }
.share-offer .so-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.share-offer .so-watch { background: var(--accent); color: #fff; border: none; border-radius: var(--r-sm); padding: 9px 20px; font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; }
.share-offer .so-watch:hover { background: var(--accent-h); }

/* near-fullscreen message editor pop-up */
.edit-modal { position: fixed; inset: 0; z-index: 9999; background: rgba(3,5,10,.62); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 24px; }
.edit-modal-box { width: min(960px, 96vw); height: min(82vh, 1000px); background: var(--s1); border: none; border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--sh-lg); }
.em-head { padding: 15px 18px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--hairline); }
.em-area { flex: 1; width: 100%; resize: none; border: none; outline: none; background: var(--bg-deep); color: var(--text); font: inherit; font-size: 15px; line-height: 1.6; padding: 16px 18px; box-sizing: border-box; }
.em-foot { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--hairline); }
.em-hint { color: var(--faint); font-size: 12px; }
.em-spacer { margin-left: auto; }
.em-btn { background: var(--s2); color: var(--text); border: none; border-radius: var(--r-sm); padding: 9px 18px; font: inherit; font-weight: 600; cursor: pointer; transition: background .14s; }
.em-btn:hover { background: var(--s3); }
.em-btn.primary { background: var(--accent); color: #fff; }
.em-btn.primary:hover { background: var(--accent-h); }
.em-btn:disabled { opacity: .6; cursor: default; }
.em-btn.danger { background: transparent; color: #f1a7ad; }
.em-btn.danger:hover { background: rgba(200,71,79,.16); color: #ffd2d6; }

/* duplicate-tab takeover overlay */
.dup-overlay { position: fixed; inset: 0; z-index: 10000; background: rgba(6,8,13,.88); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 24px; }
.dup-box { max-width: 430px; text-align: center; background: var(--s1); border: none; border-radius: 18px; padding: 30px 28px; box-shadow: var(--sh-lg); }
.dup-title { font-weight: 800; font-size: 19px; margin-bottom: 10px; }
.dup-sub { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin-bottom: 22px; }
.dup-btn { background: var(--accent); color: #fff; border: none; border-radius: var(--r-sm); padding: 12px 22px; font: inherit; font-weight: 700; font-size: 14.5px; cursor: pointer; }
.dup-btn:hover { background: var(--accent-h); }

/* marked / collaborative messages */
.marked { margin-top: 14px; border: none; border-radius: var(--r); overflow: hidden; background: var(--bg-deep); }
.marked-head { padding: 10px 13px; font-size: 13px; font-weight: 700; background: var(--s1); }
.marked-count { color: var(--muted); font-weight: 600; }
.marked-list { max-height: 300px; overflow-y: auto; overflow-x: hidden; padding: 8px 12px; }
.marked-empty { color: var(--faint); font-size: 12.5px; padding: 6px 2px; }
.marked-item { border-left: 2px solid var(--warn); padding: 3px 0 4px 10px; min-width: 0; max-width: 100%; box-sizing: border-box; }
.marked-item + .marked-item { margin-top: 8px; }
.mi-who { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; min-width: 0; }
.mi-who > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mi-who .time { color: var(--faint); font-weight: 400; font-size: 11.5px; }
.mi-body { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; margin-top: 2px; color: #dfe3ea; }
.mi-body.condensed { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; color: #c2c8d2; max-width: 100%; min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.mi-vbadge { color: #cbd5e1; font-weight: 600; font-size: 11px; background: var(--s2); padding: 1px 7px; border-radius: var(--r-pill); }
.msg-btn.marked-on { color: var(--warn); }
.msg.flash { background: rgba(245,179,1,.16); border-radius: 8px; }

/* collaborative mark expand view */
.mark-modal { height: min(86vh, 1100px); }
.mm-head { display: flex; align-items: center; gap: 10px; }
.mm-body { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.mm-current { background: var(--s2); border: none; border-radius: var(--r); padding: 13px 15px; }
.mm-cur-head { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.mm-cur-body { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; line-height: 1.55; }
.mm-link { background: none; border: none; color: #7db3ff; cursor: pointer; padding: 0; font: inherit; font-size: 13px; text-align: left; }
.mm-link:hover { color: #9cc5ff; }
.mm-hist-head { font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.mm-hist-toggle { background: none; border: none; color: #cbd5e1; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; padding: 4px 0; text-align: left; }
.mm-hist-toggle:hover { color: #fff; }
.mm-ver-list { margin-top: 10px; }
.msg-markref { margin-top: 6px; align-self: flex-start; background: var(--accent-tint); border: none; color: #9cc5ff; border-radius: var(--r-sm); padding: 5px 11px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.msg-markref:hover { background: var(--accent-soft); }
.mm-ver { border-left: 2px solid var(--hairline); padding: 1px 0 10px 12px; margin-bottom: 10px; }
.mm-ver-head { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 5px; }
.mm-ver-label { background: var(--s2); color: #cbd5e1; font-weight: 700; border-radius: 6px; padding: 1px 7px; font-size: 11px; }
.mm-ver-by { font-weight: 600; }
.mm-ver-head .time { color: var(--faint); }
.mm-diff { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.55; }
.mm-diff .d-add { background: rgba(45,180,90,.28); color: #cdf6d6; border-radius: 3px; }
.mm-diff .d-del { background: rgba(220,70,80,.24); color: #ffd2d6; text-decoration: line-through; border-radius: 3px; }

/* confirmation dialog */
.confirm-modal { z-index: 10001; }
.confirm-box { max-width: 410px; background: var(--s1); border: none; border-radius: 16px; padding: 22px 22px 18px; box-shadow: var(--sh-lg); }
.cf-title { font-weight: 800; font-size: 16px; margin-bottom: 8px; }
.cf-msg { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin-bottom: 18px; }
.cf-row { display: flex; justify-content: flex-end; gap: 10px; }

/* secret admin panel */
.uw-settings.wide { width: 384px; }
.uws-sep { height: 1px; background: var(--hairline); margin: 10px 0 8px; }
.uws-admin-toggle { width: 100%; text-align: left; background: var(--s2); border: none; color: #cbd5e1; padding: 9px 11px; border-radius: var(--r-sm); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.uws-admin-toggle:hover { background: var(--s3); }
.uws-admin-body { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.adm-pass { background: var(--s2); border: none; color: var(--text); padding: 8px 11px; border-radius: var(--r-sm); font: inherit; font-size: 13px; width: 100%; }
.adm-pass:focus { outline: none; box-shadow: inset 0 0 0 1px var(--accent); }
.uws-acct .acct-input { margin-bottom: 6px; }
.uws-acct-who { font-size: 13px; color: #7fe0a8; font-weight: 700; margin: 2px 0 6px; }
.acct-err { color: #f5a3a8 !important; margin-top: 2px; }
.uws-acct .adm-btn.primary-ish { margin-top: 6px; background: var(--accent); color: #fff; }
.uws-acct .adm-btn.primary-ish:hover { background: var(--accent-h); }
.pw-wrap { position: relative; }
.pw-wrap .pw-input { width: 100%; padding-right: 34px; }
.pw-eye { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 14px; opacity: .55; padding: 4px 6px; line-height: 1; }
.pw-eye:hover, .pw-eye.on { opacity: 1; }
.adm-btn { background: var(--s2); border: none; color: var(--text); padding: 8px 12px; border-radius: var(--r-sm); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: background .14s; }
.adm-btn:hover { background: var(--s3); }
.adm-btn.block { width: 100%; }
.adm-btn.danger { background: var(--danger); color: #fff; }
.adm-btn.danger:hover { background: var(--danger-h); }
.adm-h { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin-top: 8px; }
.adm-row { display: flex; gap: 6px; }
.adm-row .adm-btn { flex: 1; }
.adm-log { max-height: 240px; overflow: auto; background: var(--bg-deep); border: none; border-radius: var(--r-sm); padding: 9px 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; line-height: 1.45; color: #c2c8d2; white-space: pre-wrap; word-break: break-word; }
.adm-entry { margin-bottom: 8px; }
.adm-entry-h { font-weight: 700; color: var(--text); }
.adm-peer { color: var(--muted); }
.adm-peer.q-poor { color: #f0a0a6; }
.adm-peer.q-fair { color: #e8c98a; }
.adm-peer.q-reconnecting { color: #f0a0a6; }
.adm-errline { color: #f0a0a6; }
.mic-ic.sharing { filter: none; }

.tile-head { display: flex; align-items: center; gap: 8px; padding: 9px 11px; font-size: 13px; background: var(--s1); }
.tile-head .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-head .spacer { margin-left: auto; }
.tile-head button.mini { background: transparent; color: #aeb4c0; }
.tile-head button.mini:hover { background: rgba(255,255,255,.10); color: #fff; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.tile-media { position: relative; background: #000; aspect-ratio: 16 / 9; max-height: 64vh; }
.tile-media video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile-media canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

button.mini { padding: 5px 10px; font-size: 12px; border-radius: 8px; }

/* Document Picture-in-Picture window */
.pip-body { margin: 0; background: var(--bg); display: flex; }
.pip-body .tile { width: 100%; flex: 1; border: 0; border-radius: 0; box-shadow: none; }
.pip-body .tile-media { flex: 1; aspect-ratio: auto; }

/* ---- voice call (legacy bars) ---- */
.spacer { margin-left: auto; }
.callbar, .incoming { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 11px 13px; border-radius: var(--r); font-size: 14px; }
.callbar { background: rgba(52,199,89,.10); border: none; color: #cfeeda; }
.incoming { background: rgba(242,193,78,.10); border: none; color: #f2e3b0; }
.calldot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); animation: callpulse 1.2s infinite; flex: 0 0 auto; }
@keyframes callpulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
button.danger { background: var(--danger); color: #fff; }
button.danger:hover { background: var(--danger-h); }
button.mini.primary { background: var(--accent); color: #fff; }

/* in-page floating presentation window */
.float-win { position: fixed; z-index: 9000; background: #000; border: none; border-radius: var(--r); overflow: hidden; box-shadow: var(--sh-lg); resize: both; min-width: 240px; min-height: 150px; max-width: 96vw; max-height: 92vh; }
.fw-media { position: relative; width: 100%; height: 100%; background: #000; }
.fw-media .tile-media { width: 100%; height: 100%; aspect-ratio: auto; }
.fw-media video { width: 100%; height: 100%; object-fit: contain; display: block; }
.fw-media canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.fw-controls { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: 8px; background: linear-gradient(to bottom, rgba(0,0,0,.62), rgba(0,0,0,0)); opacity: 0; transition: opacity .15s; }
.float-win:hover .fw-controls, .fw-controls:focus-within { opacity: 1; }
.fw-drag { flex: 1; cursor: move; font-size: 12px; font-weight: 600; color: #fff; text-shadow: 0 1px 3px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; user-select: none; }
.fw-btn { flex: 0 0 auto; background: rgba(15,17,21,.66); border: none; color: #fff; border-radius: 8px; width: 28px; height: 26px; cursor: pointer; font-size: 13px; line-height: 1; padding: 0; transition: background .14s; }
.fw-btn:hover { background: rgba(15,17,21,.92); }
.fw-btn.on { background: var(--accent); color: #fff; }
.fw-btn.on:hover { background: var(--accent-h); }
.float-min { position: fixed; z-index: 9001; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); border: none; color: #fff; font-size: 22px; cursor: pointer; box-shadow: var(--sh-lg); touch-action: none; user-select: none; }
.float-min:hover { background: var(--accent-h); }

/* ---- unified pop-out: real detached OS window (Document PiP) or in-page float ---- */
.sb-pop { margin-left: auto; background: none; border: none; color: var(--faint); cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px; line-height: 1; }
.sb-pop:hover { color: var(--text); background: rgba(255,255,255,.06); }
.sb-pop.on { color: #7db3ff; }

/* the detached PiP document — height is CONTENT-driven (not 100vh) so the window can be auto-fit
   down to exactly what's shown; theater mode re-pins to full height below. */
.pop-doc { margin: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
/* in-page fallback host reuses .float-win but lays out like the doc */
.float-win.pop-win { background: var(--s1); width: 360px; height: auto; max-height: 86vh; display: flex; flex-direction: column; resize: both; }

.pop-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--s1); border-bottom: 1px solid var(--hairline); flex: 0 0 auto; }
.pop-title { flex: 1; text-shadow: none; color: #cbd1da; font-size: 12.5px; }
.pop-body { flex: 1 1 auto; min-height: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.pop-chan { display: flex; flex-direction: column; gap: 10px; }
.pop-chan .voice-panel { margin-top: 0; }
/* compact icon-only action buttons (mute · disconnect · share) — tooltips carry the labels */
.pop-icons { display: flex; gap: 6px; }
.pic { flex: 0 0 auto; width: 34px; height: 30px; padding: 0; font-size: 15px; line-height: 1; background: var(--s2); color: var(--text); border: none; border-radius: var(--r-sm); cursor: pointer; }
.pic:hover { background: var(--s3); }
.pic.danger, .pic.on { background: #3a2327; color: #f1b0b4; }
.pic.danger:hover, .pic.on:hover { background: #46282d; }
/* stage: even grid by default; click a screen to focus it (others -> thumb rail) */
.pop-videos { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.pop-vid { background: #000; border-radius: var(--r); overflow: hidden; box-shadow: var(--sh-sm); flex: 1 1 100%; cursor: pointer; position: relative; }
.pop-videos:not(.has-focus) .pop-vid { flex: 1 1 calc(50% - 4px); min-width: 150px; }
.pop-videos.has-focus .pop-vid.focused { flex: 1 1 100%; order: -1; }
.pop-videos.has-focus .pop-vid:not(.focused) { flex: 0 0 96px; }
.pop-vid.focused { outline: 2px solid var(--accent); outline-offset: -2px; }
.pv-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: var(--s1); }
.pv-name { font-size: 12px; font-weight: 600; color: #cbd1da; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pop-vid .tile-media { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.pop-vid .tile-media video { width: 100%; height: 100%; object-fit: contain; display: block; }
.pop-vid .tile-media canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* minimized: a compact bar that keeps mute (and share) reachable */
.pop-mini { display: inline-flex; align-items: center; gap: 5px; background: var(--s1); border: none; border-radius: var(--r-pill); padding: 4px 6px; box-shadow: var(--sh-lg); touch-action: none; width: max-content; }
.pop-doc .pop-mini { position: static; margin: 4px; }
.float-win .pop-mini, body > .pop-mini { position: fixed; z-index: 9001; right: 14px; bottom: 94px; }
.cm-drag { cursor: move; color: var(--muted); padding: 0 4px; user-select: none; font-size: 14px; }
.pop-mini .mini { margin: 0; padding: 5px 8px; }
.pop-mini .fw-btn { background: var(--s2); }
.pop-mini .fw-btn:hover { background: var(--s3); }

/* Detached PiP window chrome: a slim bar holding the ONE control the native title bar lacks —
   minimize. (Move / close / return-to-tab all come from the OS title bar.) */
.pop-barmin { display: flex; align-items: center; justify-content: flex-end; gap: 6px; padding: 0 4px; flex: 0 0 auto; }
.pop-barmin .fw-btn { background: var(--s2); }
.pop-barmin .fw-btn:hover { background: var(--s3); }

/* Minimized (compact): everything on ONE line — minimize toggle + mute + disconnect + share —
   and the window auto-fits tightly around it. */
.pop-doc.compact { flex-direction: row; align-items: center; justify-content: center; gap: 6px; padding: 4px; }
.pop-doc.compact .pop-barmin { padding: 0; order: 2; flex: 0 0 auto; }
.pop-doc.compact .pop-barmin .fw-btn { width: 34px; height: 30px; }   /* match the .pic icon buttons so the row aligns */
.pop-doc.compact .pop-body { padding: 0; gap: 0; flex: 0 0 auto; overflow: visible; }
.pop-doc.compact .pop-chan, .pop-doc.compact .voice-panel, .pop-doc.compact .vp-controls { margin: 0; border: none; padding: 0; gap: 6px; }
.pop-doc.compact .sb-subtitle, .pop-doc.compact .members, .pop-doc.compact .pop-videos, .pop-doc.compact .vp-row { display: none; }

/* MID mode: presenters' streams + essential controls, but NO channel member list */
.pop-doc.mode-mid .sb-subtitle, .pop-doc.mode-mid .members, .pop-doc.mode-mid .vp-row { display: none; }
.pop-doc.mode-mid .voice-panel { margin-top: 0; border-top: none; padding-top: 0; }
.pop-doc.mode-mid .pop-chan { gap: 6px; }

/* MIN mode mini-feeds: tiny live thumbnails so you can tell who's presenting without growing */
.mini-feeds { display: none; align-items: center; gap: 4px; }
.pop-doc.compact .mini-feeds { display: flex; }
.mini-feed { width: 40px; height: 24px; object-fit: cover; border-radius: 4px; background: #000; flex: 0 0 auto; }
.mini-feed-ico { font-size: 14px; line-height: 1; flex: 0 0 auto; }

/* Theater (PiP "fullscreen"): one screen fills the window; panel + other screens hide. */
.pop-doc.theater-mode { overflow: hidden; }
.pop-doc.theater-mode .pop-barmin, .pop-doc.theater-mode .pop-chan { display: none; }
.pop-doc.theater-mode .pop-body { padding: 0; gap: 0; height: 100vh; }
.pop-doc.theater-mode .pop-videos { display: block; height: 100%; }
.pop-doc.theater-mode .pop-vid:not(.theater) { display: none; }
.pop-doc.theater-mode .pop-vid.theater { height: 100%; display: flex; flex-direction: column; background: #000; }
.pop-doc.theater-mode .pop-vid.theater .tile-media { flex: 1 1 auto; aspect-ratio: auto; height: auto; min-height: 0; }

.tile-media:fullscreen, .tile-media:-webkit-full-screen { width: 100vw; height: 100vh; aspect-ratio: auto; background: #000; }
.tile-media:fullscreen video, .tile-media:-webkit-full-screen video { width: 100%; height: 100%; }
.tile-media:fullscreen canvas, .tile-media:-webkit-full-screen canvas { width: 100%; height: 100%; }

/* call bar rows + participant strip */
.callbar { flex-direction: column; align-items: stretch; gap: 8px; }
.callbar-row { display: flex; align-items: center; gap: 10px; }
.call-peers { display: flex; flex-wrap: wrap; gap: 6px; }
.cpeer { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 3px 9px; border-radius: var(--r-pill); background: rgba(255,255,255,.05); }
.cpeer .vdot { width: 9px; height: 9px; border-radius: 50%; background: #3a4150; flex: 0 0 auto; transition: background .1s, box-shadow .1s; }
.cpeer.talking .vdot { background: var(--ok); box-shadow: 0 0 0 3px rgba(52,199,89,.3); }
.cpeer.muted { opacity: .65; }
.cpeer .ic { font-size: 12px; }
.cpeer.bad { color: #f1a7ad; }
.echo-warn { font-size: 12.5px; color: var(--warn); background: rgba(242,193,78,.1); border: none; border-radius: var(--r-sm); padding: 7px 11px; }

/* ---- text chat ---- */
.chat { margin-top: 16px; border: none; border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; background: var(--bg-deep); }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 11px 14px; font-size: 13px; font-weight: 700; letter-spacing: .01em; background: var(--s1); }
.chat-expand { margin-left: auto; background: transparent; border: none; color: #aeb4c0; border-radius: 8px; padding: 5px 11px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; transition: background .14s, color .14s; }
.chat-expand:hover { background: rgba(255,255,255,.10); color: #fff; }

/* Expanded chat fills the main area; sidebar stays */
.app.chat-expanded .app-main { height: 100vh; overflow: hidden; padding: 12px 14px; display: flex; }
.app.chat-expanded .card.wide { padding: 0; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.app.chat-expanded .card.wide > * { display: none; }
.app.chat-expanded .card.wide > .chat { display: flex; flex: 1; min-height: 0; margin-top: 0; }
.app.chat-expanded .chat-log { flex: 1; min-height: 0; height: auto; }
.app.chat-expanded .chat-head { padding-right: 280px; }
.chat-log { height: clamp(340px, 48vh, 720px); overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; background: var(--bg-deep); }
.msg { max-width: 82%; }
.msg.mine { align-self: flex-end; }
.msg .who { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; font-weight: 600; }
.msg .time { font-size: 11px; color: var(--faint); font-weight: 400; }
.msg .edited { font-size: 11px; color: var(--faint); font-weight: 400; font-style: italic; }
.msg-btn { background: none; border: none; color: #79808d; font-size: 11px; padding: 2px 7px; border-radius: 6px; cursor: pointer; transition: opacity .12s ease, background .12s, color .12s; }
.msg-btn:hover { color: #f0f2f5; background: rgba(255,255,255,.08); }
.msg-btn.first-right { margin-left: auto; }
.msg-btn.primary-sm { background: var(--accent); color: #fff; }
.msg-btn.primary-sm:hover { background: var(--accent-h); }
.msg-btn.danger-sm { color: #f1a7ad; }
.msg-btn.danger-sm:hover { background: rgba(200,71,79,.18); color: #ffd2d6; }
@media (hover: hover) {
  .msg .who .msg-btn { opacity: 0; }
  .msg:hover .who .msg-btn, .msg .who .msg-btn.marked-on { opacity: 1; }
}
.msg.deleted .body { color: var(--faint); font-style: italic; background: transparent; box-shadow: inset 0 0 0 1px var(--hairline); }
.msg-edit-area { width: 100%; box-sizing: border-box; margin-top: 6px; min-height: 60px; max-height: 220px; border-radius: var(--r-sm); border: none; background: var(--s2); color: var(--text); font: inherit; padding: 9px; resize: vertical; }
.msg-edit-area:focus { outline: none; box-shadow: inset 0 0 0 1px var(--accent); }
.edit-bar { display: flex; gap: 6px; margin-top: 4px; }
.msg-more { margin-top: 4px; background: none; border: none; color: #7db3ff; font-size: 12px; font-weight: 600; padding: 3px 0; cursor: pointer; align-self: flex-start; }
.msg-more:hover { text-decoration: underline; }

/* fork-note "information" message */
.msg.msg-info { max-width: 100%; align-self: stretch; display: flex; align-items: center; gap: 9px; justify-content: center; background: rgba(245,179,1,.06); border: none; border-radius: var(--r); padding: 8px 14px; font-size: 12.5px; color: #b9c0cc; }
.msg-info .mi-icon { flex: 0 0 auto; }
.msg-info .mi-text { color: #cdd3dd; }
.msg-info .mi-view { flex: 0 0 auto; background: var(--accent-tint); border: none; color: #9cc5ff; border-radius: 8px; padding: 4px 11px; font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer; }
.msg-info .mi-view:hover { background: var(--accent-soft); }

.msgmodal-text { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; line-height: 1.6; color: var(--text); }
.msg .body { font-size: 14px; line-height: 1.5; color: var(--text); background: var(--s2); border-radius: var(--r); padding: 8px 12px; margin-top: 3px; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.msg .body.clamped { max-height: 168px; overflow: hidden; -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent 100%); mask-image: linear-gradient(to bottom, #000 72%, transparent 100%); }
.chat-link { color: #7db3ff; text-decoration: underline; word-break: break-all; }
.chat-link:hover { color: #9cc5ff; }
.msg.mine .body { background: var(--bubble-mine); }

/* reply */
.reply-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--s1); }
.rb-quote { flex: 1; min-width: 0; display: flex; flex-direction: column; border-left: 2px solid var(--accent); padding-left: 8px; }
.rb-name { font-size: 11.5px; color: #7db3ff; font-weight: 600; }
.rb-text { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rb-x { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; flex: 0 0 auto; padding: 2px 6px; }
.rb-x:hover { color: #fff; }
.reply-quote { display: flex; flex-direction: column; align-items: flex-start; gap: 0; margin: 2px 0 0; padding: 4px 9px; background: var(--accent-tint); border-left: 2px solid var(--accent); border-radius: 7px; cursor: pointer; max-width: 100%; min-width: 0; text-align: left; font: inherit; }
.reply-quote:hover { background: var(--accent-soft); }
.rq-name { font-size: 11px; color: #7db3ff; font-weight: 600; }
.rq-text { font-size: 12px; color: #aeb4c0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.chat-input { display: flex; gap: 8px; padding: 11px 12px; background: var(--s1); align-items: flex-end; }
.chat-input textarea { flex: 1; min-width: 0; padding: 10px 13px; border-radius: var(--r); border: none; background: var(--s2); color: var(--text); font: inherit; resize: none; line-height: 1.4; height: 42px; max-height: 140px; overflow-y: auto; }
.chat-input textarea:focus { outline: none; box-shadow: inset 0 0 0 1px var(--accent); }
.newmsgs { display: block; width: 100%; text-align: center; background: var(--accent); color: #fff; border: none; padding: 7px; font: inherit; font-size: 12.5px; cursor: pointer; }
.newmsgs[hidden] { display: none; }
.newmsgs:hover { background: var(--accent-h); }
.body.file { font-size: 13.5px; }
.filelink { color: #7db3ff; text-decoration: none; }
.filelink:hover { text-decoration: underline; }

/* file transfer message */
.filemsg { max-width: 100%; width: 100%; }
.ft-head { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.ft-row { display: flex; align-items: center; gap: 8px; margin-top: 5px; font-size: 12px; }
.ft-label { color: #cbd1da; white-space: nowrap; max-width: 42%; overflow: hidden; text-overflow: ellipsis; }
.ft-bar { flex: 1; height: 6px; min-width: 50px; background: rgba(255,255,255,.08); border-radius: 4px; overflow: hidden; }
.ft-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }
.ft-bar.done i { background: var(--ok); }
.ft-status { white-space: nowrap; color: var(--muted); }
.ft-status.ok { color: #67d98c; }
.ft-status.bad { color: #f1a7ad; }
.filelink.dl { display: inline-block; margin-top: 6px; padding: 5px 12px; background: var(--s2); border: none; border-radius: 8px; color: #7db3ff; }
.filelink.dl:hover { background: var(--s3); text-decoration: none; }

/* landing divider */
.or { color: var(--faint); font-size: 13px; text-align: center; margin: 18px 0 10px; }

/* ---- channel sidebar ---- */
body.app-body { display: block; padding: 0; }
.app { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar { width: 232px; flex: 0 0 232px; background: var(--bg-deep); border-right: none; padding: 16px 12px; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.app-main { flex: 1; min-width: 0; display: block; padding: 16px 20px; }
.app-main .card.wide { max-width: none; width: 100%; }
.sb-title { font-weight: 700; font-size: 15px; padding: 2px 6px 6px; letter-spacing: -.01em; }
.ch-list { display: flex; flex-direction: column; gap: 2px; flex: 0 1 auto; }
.ch { display: flex; align-items: center; border-radius: var(--r-sm); }
.ch:hover { background: rgba(255,255,255,.05); }
.ch.active { background: var(--accent-soft); }
.ch-name { flex: 1; min-width: 0; text-align: left; background: none; border: none; color: #cbd1da; padding: 8px 10px; cursor: pointer; font: inherit; font-size: 14px; border-radius: var(--r-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch.active .ch-name { color: #fff; font-weight: 600; }
.ch-name:hover { background: none; }
.ch-x { background: none; border: none; color: var(--faint); cursor: pointer; padding: 4px 9px; font-size: 17px; line-height: 1; border-radius: 6px; }
.ch-x:hover { color: #f1a7ad; background: none; }
.ch-empty { color: var(--faint); font-size: 12.5px; padding: 8px 6px; line-height: 1.4; }
.ch-badge { background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: var(--r-pill); display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; flex: 0 0 auto; }
.sb-add { display: flex; gap: 6px; }
.sb-add input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: var(--r-sm); border: none; background: var(--s2); color: var(--text); font: inherit; font-size: 13px; }
.sb-add input:focus { outline: none; box-shadow: inset 0 0 0 1px var(--accent); }
.sb-home { color: var(--muted); font-size: 12.5px; text-decoration: none; padding: 4px 6px; }
.sb-home:hover { color: var(--text); }

.sb-members { margin-top: 8px; }
.sb-subtitle { display: flex; align-items: center; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 4px 6px; }
.members { display: flex; flex-direction: column; gap: 1px; }
.member { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--r-sm); font-size: 13.5px; color: #cbd1da; }
.member:hover { background: rgba(255,255,255,.04); }
.mdot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; transition: box-shadow .08s; }
.mname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.member .mic, .member .mic-ic { font-size: 12px; flex: 0 0 auto; }
.member.talking .mdot { box-shadow: 0 0 0 3px rgba(52,199,89,.6); }
.member.away { opacity: .5; }
.member.bad .mname { color: #f1a7ad; }

/* voice status panel */
.voice-panel { position: relative; margin-top: auto; border-top: 1px solid var(--hairline); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.sound-overlay { position: absolute; left: -4px; right: -4px; top: 6px; bottom: -4px; background: rgba(15,17,21,.94); border: 1px solid rgba(242,193,78,.4); border-radius: var(--r); display: flex; align-items: center; justify-content: center; text-align: center; font-size: 13px; font-weight: 600; color: #ffd66b; cursor: pointer; z-index: 5; padding: 6px; }
.sound-overlay:hover { background: rgba(15,17,21,.99); border-color: rgba(242,193,78,.7); }
.vp-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.voice-panel.connected .vp-row { color: #67d98c; }
.vp-dot { width: 9px; height: 9px; border-radius: 50%; background: #3a4150; flex: 0 0 auto; }
.voice-panel.connected .vp-dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(52,199,89,.18); }
.vp-controls { display: flex; gap: 6px; }
.vp-controls .mini { flex: 1; }
.sound-state { font-size: 12px; white-space: nowrap; }
.sound-state.ok { color: #67d98c; }
.sound-state.warn { color: var(--warn); }

/* connection-quality indicators */
.conn-pip { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--ok); }
.conn-pip.good { background: var(--ok); }
.conn-pip.fair { background: var(--warn); }
.conn-pip.poor { background: #f59e42; }
.conn-pip.reconnecting, .conn-pip.connecting { background: #f1454d; animation: callpulse 1s infinite; }
.badge.conn { font-weight: 600; }
.badge.conn.ok { color: #67d98c; }
.badge.conn.warn { color: var(--warn); }
.badge.conn.weak { color: #f59e42; }

/* collapsible sidebar */
.sb-collapse { position: absolute; top: 9px; right: 8px; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 7px; border-radius: 6px; }
.sb-collapse:hover { color: var(--text); background: rgba(255,255,255,.06); }
.sb-show { position: fixed; top: 12px; left: 12px; z-index: 45; display: none; background: var(--s1); border: none; color: var(--text); border-radius: var(--r-sm); padding: 8px 13px; font: inherit; font-size: 13px; cursor: pointer; box-shadow: var(--sh-sm); }
.sb-show:hover { background: var(--s2); }
.app.sidebar-hidden .sidebar { display: none; }
.app.sidebar-hidden .sb-show { display: block; }

/* ---- responsive ---- */
@media (max-width: 900px) { .card.wide { max-width: 100%; } }
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex: 0 0 auto; height: auto; max-height: 44vh; position: relative; border-right: none; border-bottom: 1px solid var(--hairline); }
  .app-main { padding: 14px; align-items: stretch; }
  .card { padding: 18px; }
  .card.wide { padding: 16px; }
  .tile { width: 100%; }
  .roomhead { flex-wrap: wrap; row-gap: 6px; }
  .controls { flex-wrap: wrap; }
  .user-widget { top: 8px; right: 8px; }
  .uw-input { width: 130px; }
  .sb-show { top: 8px; left: 8px; padding: 6px 10px; }
}
@media (max-width: 480px) {
  .app-main { padding: 10px; }
  .card { padding: 13px; }
  h1 { font-size: 19px; }
  .msg { max-width: 92%; }
  .chat-log { height: 200px; }
  .linkrow { flex-wrap: wrap; }
  .uw-text { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* top-right editable name pill */
.user-widget { position: fixed; top: 12px; right: 14px; z-index: 50; display: flex; align-items: center; gap: 6px; }
.uw-gear { display: inline-flex; align-items: center; justify-content: center; background: var(--s1); border: none; color: #cbd1da; border-radius: 50%; width: 34px; height: 34px; flex: 0 0 34px; cursor: pointer; font-size: 15px; line-height: 1; padding: 0; box-shadow: var(--sh-sm); transition: background .14s, color .14s; }
.uw-gear:hover { background: var(--s2); color: var(--text); }
.uw-settings { position: absolute; top: 42px; right: 0; width: 256px; background: var(--s1); border: none; border-radius: var(--r); padding: 11px; box-shadow: var(--sh-lg); z-index: 60; }
.uws-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin-bottom: 6px; padding: 0 2px; }
.uws-opt { display: grid; grid-template-columns: auto 1fr; gap: 1px 8px; align-items: start; padding: 8px 6px; border-radius: var(--r-sm); cursor: pointer; }
.uws-opt:hover { background: rgba(255,255,255,.05); }
.uws-opt input { margin: 3px 0 0; grid-row: span 2; accent-color: var(--accent); }
.uws-label { font-size: 13px; color: var(--text); font-weight: 600; }
.uws-desc { grid-column: 2; font-size: 11.5px; color: var(--muted); }
.uws-note { font-size: 11px; color: var(--faint); margin-top: 6px; padding: 0 3px; line-height: 1.45; }
.mic-ic.relay { font-size: 11px; }
.uw-name { display: flex; align-items: center; gap: 8px; background: var(--s1); border: none; color: var(--text); padding: 8px 14px; border-radius: var(--r-pill); font: inherit; font-size: 13px; cursor: pointer; box-shadow: var(--sh-sm); transition: background .14s; }
.uw-name:hover { background: var(--s2); }
.uw-dot { width: 9px; height: 9px; border-radius: 50%; }
.uw-edit { font-size: 11px; opacity: .55; margin-left: 1px; }
.uw-name:hover .uw-edit { opacity: 1; }
.uw-input { background: var(--s2); border: none; color: var(--text); padding: 8px 14px; border-radius: var(--r-pill); font: inherit; font-size: 13px; width: 190px; box-shadow: var(--sh-sm); }
.uw-input:focus { outline: none; box-shadow: inset 0 0 0 1px var(--accent), var(--sh-sm); }

.incoming.joincall { background: rgba(59,130,246,.12); border: none; color: #cfe0ff; }

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; flex: none; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--hairline); flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sb-title { width: 100%; }
  .ch-list { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; }
  .app-main { padding: 16px; }
}
