/* AsbestiComms — Asbestikum brand: navy chassis, Primary-Blue signal.
   Palette (from BrandGuide.pdf):
     --bg0  #0B121B  deepest (rail)
     --bg1  #101A26  chat surface (brand Black)
     --bg2  #18242F  raised elements
     --line #25364A  hairlines
     --txt  #F4F5F9  primary text (light grey)
     --mut  #8A93A5  muted text
     --sig  #19499C  Primary Blue (accent / primary actions)
     --live #07CC96  brand green (connected / speaking)
     --bad  #EF3E36  brand red (danger)
     --warn #FFDC02  brand yellow (away / idle)
*/

:root {
  --bg0: #0B121B;
  --bg1: #101A26;
  --bg2: #18242F;
  --line: #25364A;
  --txt: #F4F5F9;
  --mut: #8A93A5;
  --sig: #19499C;
  --live: #07CC96;
  --bad: #EF3E36;
  --warn: #FFDC02;
  --display: "Montserrat", system-ui, sans-serif;
  --body: "Open Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The whole app shows/hides elements via the `hidden` attribute, but an
   author `display:` rule (flex/grid/…) silently overrides the UA
   `[hidden]{display:none}`. This makes the attribute authoritative again, so
   `el.hidden = true` actually hides — without it the auth overlay (display:flex)
   never disappears after login. */
[hidden] { display: none !important; }

html, body { height: 100%; overflow: hidden; } /* only #messages scrolls; page never does */

/* Add-to-home-screen prompt (pwa-install.js) — bottom banner on mobile. */
#install-banner {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 250;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--sig); color: #fff;
  border-radius: 10px; font: 600 13px var(--body);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
#install-banner .ib-x { margin-left: auto; color: rgba(255, 255, 255, 0.85); font-size: 15px; padding: 4px 9px; border-radius: 5px; }
#install-banner .ib-x:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* "New version available" banner (update-banner.js) — fixed across the top. */
#update-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  height: 34px; padding: 0 12px;
  background: var(--sig); color: #fff;
  font: 600 13px var(--body);
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  animation: ub-drop 0.25s ease;
}
@keyframes ub-drop { from { transform: translateY(-100%); } to { transform: translateY(0); } }
#update-banner .ub-text u { text-underline-offset: 2px; }
#update-banner .ub-dismiss {
  position: absolute; right: 8px;
  color: rgba(255, 255, 255, 0.85); font-size: 15px; line-height: 1;
  padding: 4px 9px; border-radius: 5px;
}
#update-banner .ub-dismiss:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* Themed scrollbars — replace the chunky OS default with a slim navy thumb that
   matches the chassis. Chromium (Electron + PWA) uses ::-webkit-scrollbar; the
   scrollbar-* props cover Firefox. Uses theme vars so it adapts to light mode. */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
  border: 2px solid transparent; /* inset padding so the thumb looks slim */
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--sig); background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }

body {
  font-family: var(--body);
  font-size: 15px;
  color: var(--txt);
  background: var(--bg1);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:focus-visible, input:focus-visible, .channel-list li:focus-visible {
  outline: 2px solid var(--sig);
  outline-offset: 2px;
}

/* ---------- Wordmark ---------- */

.wordmark {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.22em;
  font-size: 28px;
}
.wordmark.small { font-size: 15px; letter-spacing: 0.2em; }
.wordmark .dot {
  display: inline-block;
  width: 0.42em; height: 0.42em;
  margin-left: 0.18em;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 8px var(--live);
}
.wordmark .mark {
  height: 0.92em;
  width: auto;
  margin-right: 0.4em;
  vertical-align: -0.14em;
}

/* ---------- Join overlay ---------- */

#auth-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg0);
  z-index: 10;
}
.join-card {
  width: min(360px, 90vw);
  padding: 40px 32px;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
}
.join-sub { color: var(--mut); font-size: 13px; margin: 12px 0 24px; }
.join-card input {
  width: 100%;
  padding: 11px 14px;
  font: 500 15px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
#ms-login-btn {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font: 600 14px var(--body);
  color: #1b1b1b;
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  cursor: pointer;
}
#ms-login-btn:hover { background: #f3f3f3; }
#ms-login-btn .ms-logo {
  width: 18px; height: 18px; flex: none;
  background:
    linear-gradient(#f25022 0 0) 0 0 / 8px 8px no-repeat,
    linear-gradient(#7fba00 0 0) 100% 0 / 8px 8px no-repeat,
    linear-gradient(#00a4ef 0 0) 0 100% / 8px 8px no-repeat,
    linear-gradient(#ffb900 0 0) 100% 100% / 8px 8px no-repeat;
}
.join-card button {
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  font: 600 14px var(--display);
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--sig);
  border-radius: 6px;
}
.join-card button:hover { filter: brightness(1.08); }

#auth-form { display: flex; flex-direction: column; gap: 10px; }
#auth-form input { text-align: left; }
.auth-error { color: var(--bad); font-size: 13px; margin: 0; text-align: left; }
.auth-switch { color: var(--mut); font-size: 13px; margin-top: 16px; }
.auth-switch a { color: var(--sig); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* ---------- App shell ---------- */

#app {
  display: grid;
  grid-template-columns: 240px 1fr 220px;
  height: 100vh;
  height: 100dvh; /* dynamic viewport: fits mobile exactly, no URL-bar gap/scroll */
  overflow: hidden;
}

/* ---------- Left rail ---------- */

#rail {
  display: flex;
  flex-direction: column;
  min-height: 0; /* grid item: shrink to the viewport so the rail-scroll can scroll */
  background: var(--bg0);
  border-right: 1px solid var(--line);
}
.rail-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.rail-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 8px 12px; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 8px 6px;
  font: 600 11px var(--display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mut);
}
.add-btn {
  width: 18px; height: 18px;
  line-height: 16px;
  font-size: 14px;
  color: var(--mut);
  border-radius: 4px;
}
.add-btn:hover { color: var(--txt); background: var(--bg2); }

.channel-list { list-style: none; }
.channel-list > li {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 8px;
  margin: 1px 0;
  border-radius: 5px;
  color: var(--mut);
  cursor: pointer;
  user-select: none;
}
.channel-list > li:hover { background: var(--bg2); color: var(--txt); }
.channel-list > li.active { background: var(--bg2); color: var(--txt); }
.channel-list .hash { opacity: 0.6; font-weight: 600; }
.channel-list li.has-unread { color: var(--txt); font-weight: 600; }
.channel-list .badge {
  margin-left: auto;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 9px;
  text-align: center;
  font: 600 11px var(--body);
  color: var(--bg0);
  background: var(--mut);
}
.channel-list .badge.mention { background: var(--bad); color: #fff; }
/* Muted channels: dimmed, no unread count (mentions still show). */
.channel-list > li.muted-channel { opacity: 0.45; font-weight: 400; }
.channel-list > li.muted-channel.active { opacity: 0.85; }
.channel-list > li.muted-channel:hover { opacity: 0.8; }
.channel-list .chan-muted { margin-left: 4px; font-size: 11px; opacity: 0.75; }
#chan-pop .menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.msg.mentions-me {
  background: rgba(245, 165, 36, 0.07);
  border-left: 2px solid var(--sig);
  padding-left: 8px;
  margin-left: -10px;
}

/* voice channel occupant rows */
.voice-occupants { list-style: none; padding: 2px 0 4px 22px; }
.voice-occupants li {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 4px;
  font-size: 13px;
  color: var(--mut);
}
.voice-occupants .vc-icon { display: inline-flex; align-items: center; color: var(--bad); }
.voice-occupants .vc-icon svg {
  width: 14px; height: 14px;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Avatars + the speaking ring (signature) ---------- */

.avatar {
  position: relative;
  width: 26px; height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  background: var(--bg2);
  border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  font: 700 12px var(--display);
  color: var(--txt);
}
.avatar.speaking {
  border-color: var(--sig);
  animation: ring 1.1s ease-out infinite;
}
@keyframes ring {
  0%   { box-shadow: 0 0 0 0 rgba(245, 165, 36, 0.55); }
  100% { box-shadow: 0 0 0 7px rgba(245, 165, 36, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .avatar.speaking { animation: none; box-shadow: 0 0 0 3px rgba(245,165,36,0.45); }
}

/* ---------- Voice dock ---------- */

#voice-dock {
  flex: 0 0 auto; /* pinned below the scrolling channel list */
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--bg1);
}
.dock-status { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
#voice-warning {
  margin-bottom: 8px;
  padding: 7px 9px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--bad);
  background: rgba(229, 72, 77, 0.1);
  border: 1px solid rgba(229, 72, 77, 0.4);
  border-radius: 6px;
}
#voice-warning[hidden] { display: none; }
.dock-live {
  font: 600 10px var(--display);
  letter-spacing: 0.14em;
  color: var(--live);
}
#dock-channel { font-size: 13px; color: var(--txt); }
.dock-controls { display: flex; gap: 6px; }
.dock-controls button {
  flex: 1;
  padding: 6px 0;
  font: 600 12px var(--body);
  color: var(--mut);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.dock-controls button:hover { color: var(--txt); }
.dock-controls button:disabled { opacity: 0.45; cursor: not-allowed; }
.dock-controls button.on { color: #fff; background: var(--sig); border-color: var(--sig); }

/* Mute/Deafen are icon-only: show a plain mic/headset, and swap to the slashed
   version (in red) when active, so the button mirrors the on/off state. */
.dock-controls .vc-btn-ic {
  width: 16px; height: 16px; vertical-align: middle;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
#mute-btn .ic-active, #deafen-btn .ic-active { display: none; }
#mute-btn.on .ic-idle, #deafen-btn.on .ic-idle { display: none; }
#mute-btn.on .ic-active, #deafen-btn.on .ic-active { display: inline; }
.dock-controls #mute-btn.on, .dock-controls #deafen-btn.on {
  color: #fff; background: var(--bad); border-color: var(--bad);
}
.dock-controls button.danger:hover { color: #fff; background: var(--bad); border-color: var(--bad); }

#self-bar {
  flex: 0 0 auto; /* always pinned at the bottom of the rail */
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}
.self-top {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 6px; border-radius: 8px; cursor: pointer;
}
.self-top:hover { background: var(--bg2); }
.self-top .avatar { width: 40px; height: 40px; font-size: 16px; flex: 0 0 auto; }
.self-id { flex: 1; display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.self-gear {
  flex: 0 0 auto;
  width: 30px; height: 30px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--mut); font-size: 16px; line-height: 1;
}
.self-gear:hover { color: var(--txt); background: var(--bg1); }
#self-bar #self-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.self-status { font-size: 12px; color: var(--mut); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.self-status:empty { display: none; }

/* Connection-strength meter (Discord-style signal bars + label) */
.conn-signal {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 5px 8px; margin: 0;
  background: var(--bg2); border: 0; border-radius: 8px; cursor: pointer; text-align: left;
}
.conn-signal:hover { background: var(--line); }
.conn-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 16px; flex: 0 0 auto; }
.conn-bars i {
  width: 3px; border-radius: 1px;
  background: var(--mut); opacity: .35;
  transition: background .2s, opacity .2s;
}
.conn-bars i:nth-child(1) { height: 5px; }
.conn-bars i:nth-child(2) { height: 8px; }
.conn-bars i:nth-child(3) { height: 11px; }
.conn-bars i:nth-child(4) { height: 14px; }
#conn-text { font-size: 12px; color: var(--mut); overflow-wrap: anywhere; line-height: 1.3; }
.conn-signal.q-excellent .conn-bars i { background: var(--live); opacity: 1; }
.conn-signal.q-good .conn-bars i:nth-child(-n+3) { background: var(--live); opacity: 1; }
.conn-signal.q-fair .conn-bars i:nth-child(-n+2) { background: var(--warn); opacity: 1; }
.conn-signal.q-poor .conn-bars i:nth-child(-n+1) { background: var(--bad); opacity: 1; }
.conn-signal.q-offline .conn-bars i { background: var(--bad); opacity: .45; }
.conn-signal.q-connecting .conn-bars i { background: var(--mut); opacity: .5; animation: connpulse 1s ease-in-out infinite; }
.conn-signal.q-connecting .conn-bars i:nth-child(2) { animation-delay: .12s; }
.conn-signal.q-connecting .conn-bars i:nth-child(3) { animation-delay: .24s; }
.conn-signal.q-connecting .conn-bars i:nth-child(4) { animation-delay: .36s; }
@keyframes connpulse { 0%, 100% { opacity: .25; } 50% { opacity: .85; } }

.self-actions { display: flex; gap: 8px; }
.self-actions button {
  flex: 1; font: 600 12px var(--body); color: var(--mut);
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: transparent; cursor: pointer;
}
.self-actions button:hover { color: var(--txt); background: var(--bg2); }
#logout-btn:hover { color: #fff; background: var(--bad); border-color: var(--bad); }

/* ---------- Chat column ---------- */

/* min-height:0 lets this grid item shrink to the viewport row instead of
   growing with its content — without it the message list pushes the composer
   (and itself) off-screen instead of scrolling. */
#chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* Voice/call stage — its own page in this column while in/viewing a call. */
#stage { display: none; }
#chat.stage-mode > *:not(#stage) { display: none !important; }
#chat.stage-mode #stage { display: flex; flex: 1; min-height: 0; flex-direction: column; }
#stage-head {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  padding: 0 16px; height: 53px; border-bottom: 1px solid var(--line);
  font: 700 16px var(--display);
}
#stage-head .hash { color: var(--sig); }
#stage-head #stage-title { color: var(--txt); }
#stage-chat {
  margin-left: auto; padding: 5px 12px; border-radius: 6px;
  font: 600 12px var(--body); color: var(--mut);
  background: var(--bg2); border: 1px solid var(--line); cursor: pointer;
}
#stage-chat:hover { color: var(--txt); border-color: var(--sig); }
#stage-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 16px;
}
#stage-participants { display: flex; flex-wrap: wrap; gap: 14px; align-content: flex-start; }
.stage-tile {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: 150px; padding: 22px 12px;
  background: var(--bg1); border: 1px solid var(--line); border-radius: 12px;
}
.stage-tile .avatar.lg { width: 76px; height: 76px; font-size: 28px; flex: 0 0 auto; }
.stage-name { font-size: 13px; color: var(--txt); display: inline-flex; align-items: center; gap: 5px; }
.dock-status { cursor: pointer; }

#chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font: 700 16px var(--display);
}
#chat-header .hash { color: var(--sig); }

#messages {
  flex: 1;
  min-height: 0; /* flexbox: allow shrinking below content so it scrolls, not grows */
  overflow-y: auto;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { line-height: 1.45; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; }
.msg .author { font-weight: 600; font-size: 14px; }
.msg .ts { font-size: 11px; color: var(--mut); }
.msg .body { color: var(--txt); word-wrap: break-word; white-space: pre-wrap; }
.msg.system { color: var(--mut); font-size: 13px; font-style: italic; }

#composer {
  display: flex; gap: 8px;
  padding: 12px 18px 16px;
}
#composer input {
  flex: 1;
  padding: 11px 14px;
  font: 400 15px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 7px;
}
#composer button {
  padding: 0 18px;
  font: 600 13px var(--display);
  letter-spacing: 0.06em;
  color: #fff;
  background: var(--sig);
  border-radius: 7px;
}

/* ---------- Members column ---------- */

#members {
  background: var(--bg0);
  border-left: 1px solid var(--line);
  padding: 8px;
  overflow-y: auto;
  overflow-x: hidden; /* never a horizontal scrollbar; rows fit/truncate instead */
}
.avatar-wrap { position: relative; display: inline-flex; flex: 0 0 auto; }
.status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg0); /* member-list background, so the dot reads as separate */
  box-sizing: border-box;
}
.status-dot.online { background: var(--live); }   /* green  */
.status-dot.away { background: var(--warn); }      /* yellow */
.status-dot.dnd { background: var(--bad); }        /* red    */
.status-dot.offline { background: var(--mut); }    /* gray   */
/* Mobile presence: the dot becomes a small phone silhouette (Discord-style),
   keeping the status colour. */
.status-dot.mobile {
  width: 9px; height: 14px;
  border-radius: 3px;
  bottom: -2px; right: -3px;
}
.status-dot.mobile::after {
  content: "";
  position: absolute; left: 1.5px; right: 1.5px; bottom: 1px;
  height: 1.5px; border-radius: 1px;
  background: rgba(0, 0, 0, 0.4);
}
#member-list { list-style: none; }
#member-list li {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 14px;
  color: var(--txt);
}
/* Make member rows read as interactive (click = profile, right-click = menu). */
#member-list li:not(.member-sep):not(.member-company) { cursor: pointer; transition: background 0.12s ease, opacity 0.12s ease; }
#member-list li:not(.member-sep):not(.member-company):hover { background: var(--bg2); }
#member-list li:not(.member-sep):not(.member-company):hover .member-name { color: #fff; }
#member-list li.offline:hover { opacity: 0.75; } /* lift the dimmed offline rows on hover */
#member-list .in-voice { font-size: 11px; color: var(--live); margin-left: 4px; }
#member-list .member-sep {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 14px 8px 4px;
  font: 600 11px var(--display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mut);
}
/* Department subheadings sit a step in from the company root. */
#member-list .member-sep:not(.member-company) { padding-left: 16px; }
#member-list .member-company {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 8px 4px;
  font: 700 13px var(--display);
  letter-spacing: 0.06em;
  color: var(--txt);
  border-bottom: 1px solid var(--line);
}
.member-sep-counts {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--mut);
}
.count-part { display: inline-flex; align-items: center; gap: 4px; }
.count-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.count-dot.online { background: var(--live); }   /* green */
.count-dot.offline { background: var(--mut); }    /* gray  */
.count-sep { color: var(--line); }
#member-list li.offline { opacity: 0.45; }
/* Name takes the slack and ellipsizes so the row (avatar + name + tag + actions)
   always fits the fixed-width column — shrinks but never grows. */
#member-list .member-name {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#member-list .last-seen {
  flex: 0 0 auto;
  font-size: 10px; line-height: 16px;
  color: var(--mut);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 7px;
  white-space: nowrap;
}

#audio-sink { display: none; }

#notify-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px;
  font-size: 13px;
  color: var(--txt);
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
}
#notify-banner button {
  padding: 4px 10px;
  font: 600 12px var(--body);
  color: var(--bg0);
  background: var(--sig);
  border-radius: 5px;
}
#notify-banner button.ghost { color: var(--mut); background: none; border: 1px solid var(--line); }

/* #settings-btn inherits .self-actions button so it matches the Sign out button. */
#settings-panel {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40; /* above the mobile slide-out drawers (z-index 30) */
}
.settings-card {
  width: min(460px, 94vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  padding: 18px 22px 16px;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.settings-tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.settings-tab {
  padding: 8px 12px;
  font: 600 13px var(--display);
  color: var(--mut);
  border: 0; background: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.settings-tab:hover { color: var(--txt); }
.settings-tab.active { color: var(--txt); border-bottom-color: var(--sig); }
.settings-tab[hidden] { display: none; }
.settings-body { overflow-y: auto; flex: 1; }
.settings-pane[hidden] { display: none; }

/* About panel */
.about-box { text-align: center; padding: 28px 12px; }
.about-logo {
  width: 80px; height: 80px; margin: 0 auto 16px;
  background: url("/symbol.png") center / contain no-repeat;
}
.about-name {
  font-family: var(--display); font-size: 24px; font-weight: 700;
  color: var(--txt); margin-bottom: 4px;
}
.about-version { color: var(--mut); margin-bottom: 18px; }
.about-by { color: var(--mut); font-size: 13px; }

/* Connection-status banner (shown while connecting/reconnecting) */
#conn-status {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  z-index: 9999; background: var(--warn); color: #1a1a1a;
  padding: 7px 18px; border-radius: 0 0 10px 10px;
  font-size: 13px; font-weight: 600; letter-spacing: .2px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .35);
}

/* Profile: name editor + account info */
.profile-name-row { display: flex; gap: 8px; align-items: center; }
.profile-name-row input { flex: 1; }
.profile-info { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 6px 0 0; }
.profile-info dt { color: var(--mut); }
.profile-info dd { color: var(--txt); margin: 0; word-break: break-word; }
/* Admin health dashboard */
#health-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin: 6px 0 10px; }
.health-stat {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 10px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 7px;
}
.health-stat .hs-label { font-size: 11px; color: var(--mut); }
.health-stat .hs-value { font-size: 15px; font-weight: 600; color: var(--txt); }
.health-stat.warn { border-color: var(--bad); }
.health-stat.warn .hs-value { color: var(--bad); }

.my-activity-summary { color: var(--txt); font-size: 13px; margin: 4px 0 8px; }
.signout-btn {
  margin-top: 16px;
  padding: 8px 14px; border-radius: 6px;
  color: var(--bad); background: transparent; border: 1px solid var(--line);
  font: 600 13px var(--body); cursor: pointer;
}
.signout-btn:hover { color: #fff; background: var(--bad); border-color: var(--bad); }

/* Camera-background picker (None / Blur / image thumbnails) */
.bg-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; margin: 6px 0 8px; }
.bg-tile {
  position: relative; aspect-ratio: 16 / 10; padding: 0;
  border: 2px solid var(--line); border-radius: 6px; overflow: hidden;
  background: var(--bg2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--mut); font: 600 12px var(--body);
}
.bg-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bg-tile:hover { border-color: var(--mut); }
.bg-tile.active { border-color: var(--sig); }

/* Direct/group call cards (incoming + outgoing ringing) */
.call-backdrop {
  position: fixed; inset: 0; z-index: 11000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}
.call-card {
  width: 300px; max-width: 88vw;
  background: var(--bg1); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px 22px 20px; text-align: center;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}
.call-avatar {
  width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--sig); color: #fff; font: 700 30px var(--display);
  background-size: cover; background-position: center;
}
#call-pop .call-avatar, .call-avatar.ringing { animation: call-pulse 1.4s ease-in-out infinite; }
@keyframes call-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(25, 73, 156, 0.5); }
  50% { box-shadow: 0 0 0 14px rgba(25, 73, 156, 0); }
}
.call-name { font: 700 18px var(--display); color: var(--txt); }
.call-sub { font-size: 13px; color: var(--mut); margin-top: 4px; }
.call-actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; }
.call-btn {
  flex: 1; max-width: 120px; padding: 11px 0; border-radius: 8px;
  border: none; cursor: pointer; font: 600 14px var(--body); color: #fff;
}
.call-btn.accept { background: #2c9c5a; }
.call-btn.accept:hover { background: #25884e; }
.call-btn.decline { background: var(--bad); }
.call-btn.decline:hover { filter: brightness(1.12); }

.my-activity-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.my-activity-table th { color: var(--mut); font-weight: 600; padding: 4px 2px; text-align: center; }
.my-activity-table td { padding: 5px 2px; text-align: center; color: var(--txt); }

/* Avatar crop editor */
.avatar-editor-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(4, 9, 14, 0.72);
  display: flex; align-items: center; justify-content: center;
}
.avatar-editor-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px 22px; width: min(360px, 92vw); text-align: center;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .5);
}
.avatar-editor-card h3 { margin: 0 0 14px; color: var(--txt); }
.avatar-editor-canvas {
  width: 288px; height: 288px; max-width: 100%; display: block; margin: 0 auto;
  border-radius: 12px; background: #0a121a; cursor: grab; touch-action: none;
}
.avatar-editor-canvas:active { cursor: grabbing; }
.avatar-editor-zoom {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 2px 2px; color: var(--mut); font-size: 13px;
}
.avatar-editor-zoom input { flex: 1; }
.avatar-editor-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.settings-pane select {
  width: 100%; box-sizing: border-box; margin-top: 4px;
  padding: 8px 10px; font: 400 14px var(--body);
  color: var(--txt); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 7px;
}
.settings-pane select:disabled { opacity: 0.5; }
#audio-volume { width: 100%; accent-color: var(--sig); margin-top: 6px; }
.settings-card h2 { font: 700 16px var(--display); margin-bottom: 12px; }
.settings-card h3 { font: 600 12px var(--display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--mut); margin: 16px 0 4px; }
.settings-card label { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; }
.settings-hint { color: var(--mut); font-size: 12px; margin-bottom: 6px; }
#mute-list { list-style: none; }
#settings-close {
  margin-top: 16px;
  padding: 8px 14px;
  font: 600 13px var(--display);
  color: #fff;
  background: var(--sig);
  border-radius: 6px;
}

.msg .body pre {
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 4px 0;
  overflow-x: auto;
  font-size: 13px;
}
.msg .body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg0);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 13px;
}
.msg .body pre code { background: none; padding: 0; }
.msg .body a { color: var(--sig); }

#composer { position: relative; }
#mention-pop {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 18px;
  min-width: 220px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px;
  z-index: 6;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.mention-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 14px;
  cursor: pointer;
}
.mention-row:hover, .mention-row.selected { background: var(--bg1); }
.msg .mention {
  color: var(--sig);
  background: rgba(245, 165, 36, 0.12);
  border-radius: 3px;
  padding: 0 3px;
  font-weight: 600;
}
.msg .mention.self { color: #fff; background: var(--sig); }
/* In your own (blue) bubble, blue mention text is invisible — use white on a
   translucent pill so @names stay readable. */
.msg.mine .mention { color: #fff; background: rgba(255, 255, 255, 0.22); }
.msg.mine .mention.self { color: #fff; background: rgba(255, 255, 255, 0.34); }

.msg { position: relative; padding: 2px 8px 2px 56px; margin: 0 -8px; border-radius: 5px; }
.msg:hover { background: var(--bg2); }
/* Message grouping: consecutive messages from one author collapse — the meta
   line is hidden and a hover-revealed timestamp sits in the left gutter. */
.msg:not(.grouped) { margin-top: 14px; }
#messages .msg:first-child { margin-top: 0; }
.msg.grouped .meta { display: none; }
.msg .gutter-ts {
  position: absolute; left: 6px; width: 44px; top: 3px;
  text-align: right; font-size: 10px; color: var(--mut); opacity: 0;
  pointer-events: none; transition: opacity .12s;
}
.msg.grouped:hover .gutter-ts { opacity: .65; }
.msg.mentions-me { padding-left: 56px; }
.msg .author { cursor: pointer; }
.msg .author:hover { text-decoration: underline; }

/* "New messages" unread divider */
.unread-divider {
  display: flex; align-items: center; gap: 8px;
  margin: 12px -8px 2px; color: var(--bad);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
}
.unread-divider::before, .unread-divider::after { content: ""; flex: 1; height: 1px; background: var(--bad); opacity: .5; }
.unread-divider span { flex: 0 0 auto; }

/* Jump-to-bottom pill */
#chat { position: relative; }
.jump-bottom {
  position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%);
  z-index: 8; background: var(--bg2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 16px;
  padding: 6px 16px; font: 600 13px var(--body); cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.jump-bottom:hover { background: var(--line); }
.jump-bottom.has-new { background: var(--sig); border-color: var(--sig); color: #fff; }

/* Quick switcher (Ctrl/Cmd-K) */
#quick-switch {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
}
#quick-switch[hidden] { display: none; }
.qs-card {
  width: min(560px, 92vw); max-height: 60vh; display: flex; flex-direction: column;
  background: var(--bg1); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); overflow: hidden;
}
#qs-input {
  padding: 16px 18px; font: 400 17px var(--body); color: var(--txt);
  background: transparent; border: 0; border-bottom: 1px solid var(--line); outline: none;
}
#qs-list { list-style: none; overflow-y: auto; padding: 6px; }
.qs-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 7px; cursor: pointer;
}
.qs-item.selected { background: var(--sig); }
.qs-label { flex: 1; color: var(--txt); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-sub { font-size: 11px; color: var(--mut); }
.qs-item.selected .qs-sub { color: rgba(255, 255, 255, 0.8); }

/* Profile popout */
.profile-pop {
  position: fixed; z-index: 60; width: 260px;
  background: var(--bg1); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5); padding: 16px; overflow: hidden;
}
.pp-head { display: flex; align-items: center; gap: 12px; }
.pp-avatar { width: 52px; height: 52px; font-size: 20px; flex: 0 0 auto; }
.pp-name { font-weight: 700; font-size: 17px; color: var(--txt); }
.pp-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--mut); margin-top: 2px; }
.pp-status .status-dot { position: static; }
.pp-customstatus {
  margin-top: 12px; padding: 8px 10px; background: var(--bg2); border-radius: 7px;
  font-size: 13px; color: var(--txt);
}
.pp-meta { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.pp-meta > div { font-size: 13px; color: var(--txt); }
.pp-meta span { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--mut); margin-bottom: 1px; }
.pp-message {
  margin-top: 14px; width: 100%; padding: 9px; border-radius: 7px;
  background: var(--sig); color: #fff; font: 600 13px var(--body); cursor: pointer; border: 0;
}
.pp-message:hover { filter: brightness(1.1); }
.msg-tools {
  position: absolute;
  top: -10px; right: 8px;
  display: none;
  gap: 2px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px;
}
.msg-tools button { padding: 2px 7px; font-size: 13px; border-radius: 4px; color: var(--mut); }
.msg-tools button:hover { background: var(--bg1); color: var(--txt); }
/* Touch devices have no hover — keep the message tools visible and tappable. */
@media (hover: none) {
  .msg-tools { display: flex; }
  .msg-tools button { padding: 6px 9px; font-size: 16px; }
}
/* Long-press targets (member/channel rows) shouldn't fire the native callout. */
#member-list li, .channel-list > li { -webkit-touch-callout: none; }
#member-list li:not(.member-sep):not(.member-company) { -webkit-user-select: none; user-select: none; }
.msg .edited { font-size: 10px; color: var(--mut); }
.edit-input {
  width: 100%;
  padding: 6px 10px;
  font: 400 15px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--sig);
  border-radius: 6px;
}
.reply-quote {
  display: flex; gap: 6px; align-items: center;
  font-size: 12px;
  color: var(--mut);
  cursor: pointer;
  margin-bottom: 1px;
}
.reply-quote:hover { color: var(--txt); }
.msg.flash { animation: flashbg 1.2s ease-out; }
@keyframes flashbg {
  0% { background: rgba(245, 165, 36, 0.25); }
  100% { background: transparent; }
}
.reactions { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
.reactions:empty { display: none; }
.reaction-chip {
  display: inline-flex; gap: 4px; align-items: center;
  padding: 1px 7px;
  border-radius: 9px;
  background: var(--bg2);
  border: 1px solid var(--line);
  font-size: 13px;
  cursor: pointer;
}
.reaction-chip.mine { border-color: var(--sig); background: rgba(245, 165, 36, 0.12); }

#reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 18px;
  font-size: 13px;
  color: var(--mut);
  background: var(--bg2);
  border-top: 1px solid var(--line);
}
#reply-bar button { margin-left: auto; color: var(--mut); padding: 2px 6px; border-radius: 4px; }
#reply-bar button:hover { color: var(--txt); background: var(--bg1); }

#emoji-pop {
  position: fixed;
  z-index: 60; /* above the mobile drawers */
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
#emoji-pop[hidden] { display: none; }
#emoji-pop button { font-size: 18px; padding: 4px; border-radius: 5px; }
#emoji-pop button:hover { background: var(--bg1); }

#typing-line {
  display: flex; align-items: center; gap: 7px;
  padding: 3px 18px 5px;
  font-size: 12px;
  font-style: italic;
  color: var(--mut);
}
#typing-line[hidden] { display: none; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor;
  animation: typing-bounce 1.3s infinite ease-in-out both;
}
.typing-dots i:nth-child(2) { animation-delay: 0.18s; }
.typing-dots i:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing-bounce {
  0%, 70%, 100% { transform: translateY(0); opacity: 0.35; }
  35% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Responsive ---------- */

/* Mobile header buttons — shown only on narrow screens (toggle the drawers). */
#rail-toggle, #members-toggle, #stage-rail-toggle {
  display: none;
  background: none; border: none; color: var(--txt);
  font-size: 19px; line-height: 1; padding: 2px 8px; cursor: pointer;
}
#members-toggle { margin-left: auto; } /* sits at the right of the header */

@media (max-width: 900px) {
  #app { grid-template-columns: 200px 1fr; }
  /* Members list becomes a right-side drawer, toggled by the 👥 button. */
  #members {
    position: fixed; top: 0; right: 0; bottom: 0; left: auto;
    width: 250px; max-width: 80%; z-index: 30;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    box-shadow: -3px 0 28px rgba(0, 0, 0, 0.55);
  }
  #members.open { transform: translateX(0); }
  #members-toggle { display: inline-block; }
}

@media (max-width: 600px) {
  #app { grid-template-columns: 1fr; }
  /* Channel rail slides in over the chat; tapping the chat closes it. */
  #rail {
    position: fixed; inset: 0 22% 0 0; z-index: 30; max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 3px 0 28px rgba(0, 0, 0, 0.55);
  }
  #rail.open { transform: translateX(0); }
  #rail-toggle, #stage-rail-toggle { display: inline-block; }

  /* Header wraps so the search box drops to its own full-width row. */
  #chat-header { flex-wrap: wrap; row-gap: 8px; padding: 10px 12px; }
  #search-input { order: 10; flex-basis: 100%; width: 100%; margin-left: 0; }

  #messages { padding-left: 12px; padding-right: 12px; }
  #composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  #composer input { font-size: 16px; } /* >=16px stops iOS zooming the page on focus */
  .channel-list li { padding-top: 9px; padding-bottom: 9px; }
}

#attach-btn {
  padding: 0 14px;
  font-size: 20px;
  color: var(--mut);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 7px;
}
#attach-btn:hover { color: var(--txt); }
#attach-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 6px 18px;
  font-size: 13px;
  color: var(--mut);
  background: var(--bg2);
  border-top: 1px solid var(--line);
}
#attach-cancel { margin-left: auto; color: var(--mut); padding: 2px 6px; border-radius: 4px; }
#attach-bar button:hover { color: var(--txt); background: var(--bg1); }
#attach-tray { display: flex; flex-wrap: wrap; gap: 6px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 200px;
  padding: 3px 4px 3px 9px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 13px;
  color: var(--txt); font-size: 12px;
}
.attach-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .chip-x {
  flex: 0 0 auto; margin: 0; padding: 0;
  width: 18px; height: 18px; border-radius: 50%;
  color: var(--mut); font-size: 11px; line-height: 1;
}
.attach-chip .chip-x:hover { color: #fff; background: var(--bad); }

.attachment-fig { margin: 4px 0 0; max-width: min(420px, 90%); }
.attachment-img {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 7px;
  border: 1px solid var(--line);
}
.attachment-cap {
  margin-top: 3px;
  font-size: 11px;
  color: var(--mut);
  word-break: break-word;
}
.file-card {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  margin-top: 4px;
  max-width: min(360px, 90%);
  padding: 9px 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--txt);
  text-decoration: none;
  font-size: 14px;
}
.file-card:hover { border-color: var(--sig); background: var(--bg1); }
.file-card .file-icon { font-size: 22px; line-height: 1; flex: 0 0 auto; }
.file-card .file-meta { display: flex; flex-direction: column; min-width: 0; }
.file-card .file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .file-size { color: var(--mut); font-size: 12px; }
.file-card .file-dl { margin-left: auto; padding-left: 6px; color: var(--mut); font-size: 18px; flex: 0 0 auto; }
.file-card:hover .file-dl { color: var(--sig); }

/* Drag-and-drop "drop to send" overlay (covers the chat column while dragging) */
#drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 18, 27, 0.8);
}
#drop-overlay .drop-card {
  pointer-events: none; /* keep drag events on the overlay, not its label */
  padding: 26px 44px;
  border: 2px dashed var(--sig);
  border-radius: 14px;
  background: rgba(25, 73, 156, 0.14);
  color: var(--txt);
  font: 700 18px var(--display);
  letter-spacing: 0.02em;
}

/* Link preview cards (unfurled URLs) */
.link-preview {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  max-width: min(440px, 100%);
  padding: 10px 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--sig);
  border-radius: 6px;
  color: var(--txt);
  text-decoration: none;
}
.link-preview:hover { border-color: var(--sig); background: var(--bg1); }
.link-preview-body { flex: 1 1 auto; min-width: 0; }
.link-preview-site { font-size: 11px; color: var(--mut); margin-bottom: 3px; }
.link-preview-title {
  font-size: 14px; font-weight: 600; color: var(--txt); margin-bottom: 3px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.link-preview-desc {
  font-size: 12px; color: var(--mut); line-height: 1.4;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.link-preview-img {
  flex: 0 0 auto; width: 72px; height: 72px;
  object-fit: cover; border-radius: 5px; align-self: flex-start;
}
.bubble .link-preview { max-width: 100%; }

/* Full-screen image viewer (lightbox.js) */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(8, 14, 22, 0.93);
  display: flex;
  flex-direction: column;
  padding: 14px;
}
.lightbox-bar { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; padding: 2px 4px 12px; }
.lightbox-name {
  margin-right: auto;
  color: var(--txt); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lightbox-dl {
  flex: 0 0 auto;
  padding: 6px 13px; border-radius: 6px;
  color: var(--txt); background: var(--bg2);
  border: 1px solid var(--line);
  font-size: 13px; text-decoration: none;
}
.lightbox-dl:hover { color: #fff; background: var(--sig); border-color: var(--sig); }
.lightbox-close {
  flex: 0 0 auto;
  width: 34px; height: 34px; border-radius: 6px;
  color: var(--mut); font-size: 20px; line-height: 1;
}
.lightbox-close:hover { color: #fff; background: var(--bg2); }
.lightbox-img {
  flex: 1 1 auto; min-height: 0;
  max-width: 100%; margin: auto; display: block;
  object-fit: contain; border-radius: 6px;
  cursor: zoom-out;
}

#share-area {
  padding: 10px 18px 4px;
  border-bottom: 1px solid var(--line);
}
#share-video {
  display: block;
  width: 100%;
  max-height: 45vh;
  background: #000;
  border-radius: 8px;
  border: 1px solid var(--line);
}
#share-label {
  display: block;
  padding: 4px 2px 6px;
  font-size: 12px;
  color: var(--mut);
}
.share-stage { position: relative; line-height: 0; }
#share-controls {
  position: absolute; top: 8px; right: 8px;
  display: flex; gap: 6px;
  opacity: 0; transition: opacity 0.15s;
}
.share-stage:hover #share-controls, #share-controls:focus-within { opacity: 1; }
#share-controls button {
  width: 32px; height: 32px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; background: rgba(11, 18, 27, 0.72);
  border: 1px solid var(--line);
}
#share-controls button:hover { background: var(--sig); border-color: var(--sig); }
.share-ctrl-ic { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* Fullscreen: let the video fill the screen, keep the controls reachable. */
.share-stage.maximized { position: fixed; inset: 0; z-index: 200; background: #000; display: flex; align-items: center; justify-content: center; }
.share-stage.maximized #share-video { width: 100%; height: 100%; max-height: none; border: none; border-radius: 0; object-fit: contain; }
.share-stage.maximized #share-controls { opacity: 1; position: fixed; top: 16px; right: 16px; }
.dock-controls #share-btn.on { color: #fff; background: var(--live); border-color: var(--live); }
.dock-controls #camera-btn.on { color: #fff; background: var(--live); border-color: var(--live); }

/* Webcam tiles (camera grid above the messages). */
#camera-grid {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 8px 18px;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
}
#camera-grid[hidden] { display: none; }
.cam-tile {
  position: relative;
  width: 180px; height: 135px;
  border-radius: 8px; overflow: hidden;
  background: #000; border: 1px solid var(--line);
}
.cam-tile { cursor: pointer; transition: border-color 0.1s ease, box-shadow 0.1s ease; }
/* Speaking: green glow round the tile, matching the avatar speaking ring. */
.cam-tile.speaking { border-color: var(--live); box-shadow: 0 0 0 2px var(--live), 0 0 14px rgba(7, 204, 150, 0.45); }
.cam-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-tile.self.mirror video { transform: scaleX(-1); } /* mirror your own preview (toggle) */
/* Spotlight: click a tile to fill the window. */
.cam-tile.cam-max {
  position: fixed; inset: 0; z-index: 200;
  width: auto; height: auto;
  border: none; border-radius: 0; background: #000;
}
.cam-tile.cam-max video { object-fit: contain; }
.cam-tile.cam-max .cam-name { left: 16px; bottom: 16px; font-size: 13px; }
.cam-tile .cam-name {
  position: absolute; left: 6px; bottom: 5px;
  padding: 1px 7px; border-radius: 9px;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 11px;
}

.voice-occupants .vol-slider {
  width: 64px;
  margin-left: auto;
  accent-color: var(--sig);
}

.ptt-key-row { font-size: 13px; color: var(--mut); }
#ptt-key-btn {
  padding: 3px 10px;
  font: 600 12px ui-monospace, monospace;
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 5px;
}

.avatar { overflow: hidden; }
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-lg { width: 56px; height: 56px; flex: 0 0 56px; font-size: 22px; }
.profile-row { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.profile-actions { display: flex; flex-direction: column; gap: 6px; }
.profile-actions button {
  padding: 5px 12px;
  font: 600 12px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.profile-actions button:hover { border-color: var(--sig); }

#chat-header { display: flex; align-items: center; gap: 6px; }
#chat-header #chat-title { margin-right: auto; } /* push the action cluster to the right */
#search-input {
  width: 190px;
  padding: 5px 10px;
  font: 400 13px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
#search-input:focus { border-color: var(--sig); outline: none; }
#search-panel {
  position: fixed;
  top: 56px;
  right: 12px;
  width: min(420px, 90vw);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 9;
}
#search-panel[hidden] { display: none; }
.search-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--mut);
}
.search-head button { margin-left: auto; color: var(--mut); padding: 2px 6px; border-radius: 4px; }
.search-head button:hover { color: var(--txt); background: var(--bg2); }
#search-results { list-style: none; overflow-y: auto; padding: 6px; }
#search-results li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
#search-results li:hover { background: var(--bg2); }
.result-meta { font-size: 11px; color: var(--mut); margin-bottom: 2px; }
.result-snippet { font-size: 13px; }
.result-snippet mark {
  background: rgba(245, 165, 36, 0.25);
  color: var(--sig);
  border-radius: 2px;
  padding: 0 1px;
}
@media (max-width: 600px) {
  #search-input { width: 110px; }
}
.avatar-sm { width: 20px; height: 20px; flex: 0 0 20px; font-size: 10px; }
#dm-channels li { gap: 8px; }
#member-list .dm-btn {
  margin-left: auto;
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--mut);
  font-size: 13px;
  visibility: hidden;
}
#member-list li:hover .dm-btn { visibility: visible; }
#member-list .dm-btn:hover { color: var(--txt); background: var(--bg2); }
.profile-actions button.ghost { color: var(--mut); }
.role-chip { font-size: 11px; margin-left: 2px; }
.dept-chip {
  font-size: 10px;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 9px;
  color: var(--mut);
  background: var(--bg2);
  border: 1px solid var(--line);
}

/* ---------- Departments admin (settings) ---------- */
#departments-section #dept-create-row { display: flex; gap: 8px; margin: 8px 0; }
#departments-section #dept-new-name { flex: 1; }
#departments-section button {
  font: 600 12px var(--body);
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg2);
  color: var(--txt);
}
#departments-section button.ghost { color: var(--mut); }
#departments-section button:hover { border-color: var(--sig); }
.dept-row, .dept-member-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.dept-row .dept-name { font-weight: 600; min-width: 110px; }
.dept-member-row { justify-content: space-between; }
.dept-admin-chip {
  font-size: 11px; padding: 1px 4px 1px 8px; border-radius: 9px;
  background: var(--bg2); border: 1px solid var(--line); color: var(--sig);
  display: inline-flex; align-items: center; gap: 4px;
}
.dept-admin-revoke { padding: 0 4px !important; border: 0 !important; background: none !important; color: var(--mut) !important; }
#departments-section select {
  background: var(--bg2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; font: inherit;
}
#activity-link { display: inline-block; margin-top: 12px; color: var(--sig); text-decoration: none; }
#activity-link:hover { text-decoration: underline; }

/* ---------- Activity panel ---------- */
#activity-panel {
  position: fixed;
  top: 56px; right: 12px;
  width: min(680px, 94vw);
  max-height: 80vh;
  display: flex; flex-direction: column;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 9;
  overflow: auto;
  padding-bottom: 12px;
}
#activity-panel[hidden] { display: none; }
.activity-controls { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.activity-controls select { background: var(--bg2); color: var(--txt); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; }
#activity-csv {
  margin-left: auto; padding: 6px 12px; border-radius: 6px;
  background: var(--sig); color: #fff; font-weight: 600; border: 0; cursor: pointer;
}
.activity-h { padding: 6px 14px 2px; color: var(--mut); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
#activity-online { padding: 0 14px; display: flex; flex-wrap: wrap; gap: 6px 14px; }
#activity-online li { list-style: none; }
.activity-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.activity-table th, .activity-table td { text-align: left; padding: 6px 14px; border-bottom: 1px solid var(--line); }
.activity-table th { color: var(--mut); font-weight: 600; }
.activity-table tr.live td { color: var(--live); }
.activity-scroll { overflow-x: auto; } /* daily grid can be wide on small screens */
#activity-daily-table td:not(:first-child), #activity-daily-table th:not(:first-child) { text-align: right; white-space: nowrap; }
#member-list .mod-btn {
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--mut);
  font-size: 13px;
  visibility: hidden;
}
#member-list li:hover .mod-btn { visibility: visible; }
#member-list .mod-btn:hover { color: var(--txt); background: var(--bg2); }
#mod-pop {
  position: fixed;
  z-index: 60; /* above the mobile drawers (30) + settings (40) */
  display: flex;
  flex-direction: column;
  min-width: 180px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
#mod-pop[hidden] { display: none; }
#mod-pop button {
  text-align: left;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--txt);
}
#mod-pop button:hover { background: var(--bg1); }
#mod-pop button.danger { color: var(--bad); }
#mod-pop button.danger:hover { background: var(--bad); color: #fff; }
#mod-pop .menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
#kicked-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg0);
  z-index: 20;
}
#kicked-overlay[hidden] { display: none; }
#bans-list { list-style: none; }
#bans-list li { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 14px; }
#bans-list .ban-date { color: var(--mut); font-size: 12px; margin-left: auto; }
#bans-list button {
  padding: 3px 10px;
  font: 600 12px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 5px;
}
#bans-list button:hover { border-color: var(--sig); }

/* ---------- Channel management (V4-M1) ---------- */

#member-list .chan-btn, .channel-list .chan-btn {
  margin-left: auto;
  padding: 0 5px;
  border-radius: 4px;
  color: var(--mut);
  font-size: 13px;
  visibility: hidden;
}
.channel-list > li:hover .chan-btn { visibility: visible; }
.channel-list .chan-btn:hover { color: var(--txt); background: var(--bg1); }
.channel-list > li.has-unread .badge { margin-left: 4px; }
#chan-pop {
  position: fixed;
  z-index: 60; /* above the mobile drawers + settings */
  display: flex;
  flex-direction: column;
  min-width: 170px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
#chan-pop[hidden] { display: none; }
#chan-pop button { text-align: left; padding: 7px 10px; border-radius: 5px; font-size: 13px; color: var(--txt); }
#chan-pop button:hover { background: var(--bg1); }
#chan-pop button.danger { color: var(--bad); }
#chan-pop button.danger:hover { background: var(--bad); color: #fff; }
#create-pop, #prompt-pop {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50; /* above the mobile drawers + settings (dialogs can open from settings) */
}
#create-pop[hidden], #prompt-pop[hidden] { display: none; }
.prompt-card {
  width: min(360px, 92vw);
  padding: 20px 22px;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.prompt-card h3 { font: 700 15px var(--display); margin-bottom: 12px; }
.prompt-card #prompt-input {
  width: 100%; box-sizing: border-box;
  padding: 9px 10px; font: 400 14px var(--body);
  color: var(--txt); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 7px;
}
.prompt-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.prompt-actions button {
  padding: 8px 16px; border-radius: 6px; font: 600 13px var(--body);
  background: var(--sig); color: #fff; border: 0; cursor: pointer;
}
.prompt-actions button.ghost { background: var(--bg2); color: var(--txt); border: 1px solid var(--line); }
.create-card {
  width: min(340px, 92vw);
  padding: 20px 22px;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.create-card h2 { font: 700 15px var(--display); margin-bottom: 12px; }
.create-card input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  font: 500 14px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.create-card label { display: flex; align-items: center; gap: 8px; padding: 8px 0 2px; font-size: 13px; }
#create-members { list-style: none; max-height: 180px; overflow-y: auto; margin-top: 6px; }
#create-members label { padding: 3px 0; }
.create-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.create-actions button {
  padding: 7px 14px;
  font: 600 13px var(--display);
  color: #fff;
  background: var(--sig);
  border-radius: 6px;
}
.create-actions button.ghost { color: var(--mut); background: none; border: 1px solid var(--line); }
.channel-list > li[draggable="true"] { cursor: grab; }

/* Group DM rail + header actions (V4-M2) */
.group-avatar { font-size: 11px; background: var(--bg2); }
#chat-header #group-add, #chat-header #group-leave, #chat-header #call-btn {
  padding: 5px 11px;
  font: 600 12.5px var(--body);
  color: var(--mut);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
#chat-header #group-add:hover { color: var(--txt); border-color: var(--sig); }
#chat-header #call-btn { color: #2c9c5a; background: rgba(44, 156, 90, 0.12); border-color: transparent; }
#chat-header #call-btn:hover { color: #fff; background: #2c9c5a; border-color: #2c9c5a; }

/* Pinned messages (V4-M3) */
.pinned-mark { font-size: 10px; }
#chat-header #pins-btn, #chat-header #mentions-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  border: none; background: none; border-radius: 7px; cursor: pointer;
  color: var(--mut); font: 700 16px var(--display);
}
#chat-header #pins-btn:hover, #chat-header #mentions-btn:hover { color: var(--txt); background: var(--bg2); }
#chat-header #pins-btn svg, #chat-header #mentions-btn svg {
  width: 18px; height: 18px; display: block; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
#pins-panel {
  position: fixed;
  top: 56px;
  right: 12px;
  width: min(420px, 90vw);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 9;
}
#pins-panel[hidden] { display: none; }
#pins-list { list-style: none; overflow-y: auto; padding: 6px; }
#pins-list li { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
#pins-list li:hover { background: var(--bg2); }
#chat-header #group-leave:hover { color: #fff; background: var(--bad); border-color: var(--bad); }

/* Mentions inbox (M18) — same overlay pattern as pins; button styled with #pins-btn */
#mentions-panel {
  position: fixed;
  top: 56px;
  right: 12px;
  width: min(420px, 90vw);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 9;
}
#mentions-panel[hidden] { display: none; }
#mentions-list { list-style: none; overflow-y: auto; padding: 6px; }
#mentions-list li { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
#mentions-list li:hover { background: var(--bg2); }

/* Audit log (M18) */
#audit-section { margin-top: 18px; }
#audit-list { list-style: none; padding: 0; max-height: 320px; overflow-y: auto; }
#audit-list li {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#audit-list .audit-action { color: var(--txt); }
#audit-list .audit-when { color: var(--mut); font-size: 11px; }

/* Invite manager (V5-M1) */
#server-section button,
#invite-list button {
  padding: 4px 10px;
  font: 600 12px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 5px;
}
#server-section button:hover, #invite-list button:hover { border-color: var(--sig); }
#invite-link {
  width: 100%;
  margin-top: 6px;
  padding: 6px 10px;
  font: 400 12px ui-monospace, monospace;
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 5px;
}
#invite-list { list-style: none; margin-top: 8px; }
#invite-list li { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 13px; }
#invite-list .invite-status { color: var(--mut); font-size: 12px; margin-left: auto; }
#auth-invite[hidden] { display: none; }

/* Webhooks (V5-M2) */
.app-badge {
  font: 700 9px var(--display);
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--sig);
  border-radius: 3px;
  padding: 1px 4px;
}
.webhook-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.webhook-row button {
  padding: 3px 8px;
  font: 600 11px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.webhook-row button:hover { border-color: var(--sig); }
.webhook-row.empty { color: var(--mut); }
.webhook-row span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* Channel categories (V5-M3) */
.channel-list .category-head {
  margin-top: 8px;
  padding: 4px 8px 2px;
  font: 600 10px var(--display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mut);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}
.channel-list .category-head:hover { color: var(--txt); background: none; }
.cat-arrow { font-size: 9px; width: 10px; }
.cat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mut);
  margin-left: auto;
}
.cat-dot.mention { background: var(--bad); }
#backup-link {
  display: inline-block;
  margin-top: 4px;
  padding: 5px 12px;
  font: 600 12px var(--body);
  color: var(--txt);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 5px;
  text-decoration: none;
}
#backup-link:hover { border-color: var(--sig); }

/* ───────── Status picker menu ───────── */
.status-menu {
  position: fixed; z-index: 60; min-width: 200px;
  background: var(--bg1); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5); padding: 6px;
}
.status-menu button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border-radius: 7px; color: var(--txt);
  font: 600 13px var(--body); background: transparent; border: 0; cursor: pointer; text-align: left;
}
.status-menu button:hover { background: var(--bg2); }
.status-menu .status-dot { position: static; width: 10px; height: 10px; }
.status-menu .status-custom { color: var(--mut); border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }

/* ───────── Toasts ───────── */
#toast-area {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto; cursor: pointer; max-width: 80vw;
  padding: 10px 16px; border-radius: 9px; font: 600 13px var(--body); color: #fff;
  background: var(--bg2); border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: #14532d; border-color: var(--live); }
.toast-error { background: #5a1a1a; border-color: var(--bad); }

/* ───────── Light theme ───────── */
:root.light {
  --bg0: #E4E9F0;
  --bg1: #FFFFFF;
  --bg2: #EEF2F7;
  --line: #D3DBE6;
  --txt: #16202B;
  --mut: #5A6B7B;
  --sig: #19499C;
  --live: #07A074;
  --bad: #D32F2F;
  --warn: #B7860B;
}
:root.light .toast { color: #fff; }
:root.light .msg .mention { background: rgba(25, 73, 156, 0.12); }

/* ═════════ Bubble chat layout (Teams / WhatsApp style) ═════════ */
#messages { display: flex; flex-direction: column; }
.msg {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 0 16px; margin: 0; max-width: 100%; border-radius: 0; position: static;
}
.msg:hover { background: transparent; }
.msg.theirs { justify-content: flex-start; }
.msg.mine { justify-content: flex-end; }
.msg:not(.grouped) { margin-top: 14px; }
.msg.grouped { margin-top: 2px; }
#messages .msg:first-child { margin-top: 6px; }

/* Avatar lines up with the top of the bubble (where the name is). */
.msg-avatar { width: 34px; height: 34px; flex: 0 0 34px; align-self: flex-start; margin-top: 2px; cursor: pointer; }
.msg-avatar.spacer { visibility: hidden; }

.msg-col { display: flex; flex-direction: column; min-width: 0; max-width: min(70%, 580px); }
.msg.mine .msg-col { align-items: flex-end; }
.msg.theirs .msg-col { align-items: flex-start; }
.msg .app-badge { font-size: 9px; margin-left: 4px; vertical-align: 1px; }

.bubble {
  position: relative; padding: 7px 11px; border-radius: 14px;
  font-size: 14px; line-height: 1.4; color: var(--txt);
  word-wrap: break-word; overflow-wrap: anywhere; min-width: 64px;
}
.msg.theirs .bubble { background: var(--bg2); border-top-left-radius: 4px; }
.msg.mine .bubble { background: var(--sig); color: #fff; border-top-right-radius: 4px; }
.msg.grouped.theirs .bubble { border-top-left-radius: 14px; }
.msg.grouped.mine .bubble { border-top-right-radius: 14px; }

/* Bubble tail on the first message of a group, pointing toward the avatar. */
.msg.theirs:not(.grouped) .bubble::before {
  content: ""; position: absolute; top: 1px; left: -6px; width: 0; height: 0;
  border-top: 8px solid var(--bg2);
  border-left: 7px solid transparent;
}
.msg.mine:not(.grouped) .bubble::before {
  content: ""; position: absolute; top: 1px; right: -6px; width: 0; height: 0;
  border-top: 8px solid var(--sig);
  border-right: 7px solid transparent;
}

/* Name inside the bubble (coloured per author). */
.bubble-name { display: inline-block; font-weight: 700; font-size: 13px; margin-bottom: 1px; cursor: pointer; }
.bubble-name:hover { text-decoration: underline; }

.msg .body { white-space: pre-wrap; color: inherit; }
.msg .body::after { content: ""; display: block; clear: both; } /* contain the floated time */
.msg.mine .body a { color: #cfe0ff; }
.msg.mine .body code, .msg.mine .body pre { background: rgba(0,0,0,.22); }
.msg .edited { font-size: 10px; opacity: .65; }

/* Time tucked bottom-right; floats so a short line keeps it inline. */
.bubble-time {
  float: right; font-size: 10px; color: var(--mut);
  margin: 6px 0 -1px 10px; line-height: 1; white-space: nowrap; user-select: none;
}
.msg.mine .bubble-time { color: rgba(255, 255, 255, 0.7); }

.msg .reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 4px 0; }
.msg.mine .reactions { justify-content: flex-end; }

/* Message toolbar: hidden inline; opens as a context menu on right-click. */
.msg-tools {
  position: static; display: none; align-self: center; gap: 2px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 2px;
  top: auto; right: auto;
}
.msg-tools.as-menu {
  display: flex; position: fixed; z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.msg-tools.as-menu button { padding: 5px 9px; font-size: 15px; }
.msg.mine .msg-tools { order: -1; }

/* mention highlight becomes a ring on the bubble */
.msg.mentions-me { background: transparent; border: 0; padding: 0 16px; margin-left: 0; }
.msg.mentions-me:not(.grouped) { margin-top: 14px; }
.msg.mentions-me .bubble { box-shadow: 0 0 0 2px var(--warn); }

/* attachments + reply quotes inside the bubble column */
.bubble .attachment-fig { max-width: 100%; margin-top: 6px; }
.bubble .attachment-img { max-height: 320px; border-radius: 10px; }
.bubble .file-card { margin-top: 6px; max-width: 100%; }
.msg .reply-quote { font-size: 12px; color: var(--mut); margin: 0 8px 3px; cursor: pointer; }
.msg.mine .reply-quote { text-align: right; }

/* the old left-gutter timestamp is unused in bubble mode */
.msg .gutter-ts { display: none; }

/* ───────── Attachment (+) menu ───────── */
#attach-menu {
  position: absolute; bottom: calc(100% + 8px); left: 6px; z-index: 14;
  background: var(--bg1); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5); padding: 6px; min-width: 220px;
}
#attach-menu[hidden] { display: none; }
#attach-menu button {
  display: flex; align-items: center; gap: 13px; width: 100%;
  padding: 10px 12px; border-radius: 8px; color: var(--txt);
  font: 600 14px var(--body); background: transparent; cursor: pointer; text-align: left;
}
#attach-menu button:hover { background: var(--bg2); }
#attach-menu .am-icon { font-size: 17px; width: 22px; text-align: center; }

/* inline video / audio attachments */
.attachment-video { max-width: 100%; max-height: 340px; border-radius: 10px; display: block; background: #000; }
.attachment-audio { width: 280px; max-width: 100%; display: block; }
.msg.mine .attachment-audio { filter: none; }

/* ───────── Upload progress bar ───────── */
#attach-progress {
  flex: 1; height: 6px; min-width: 60px;
  background: var(--bg0); border-radius: 4px; overflow: hidden; margin: 0 10px;
}
#attach-progress[hidden] { display: none; }
#attach-progress-fill {
  height: 100%; width: 0; background: var(--sig);
  border-radius: 4px; transition: width .15s ease;
}

/* ───────── Boot loader (prevents blank window on startup) ───────── */
#boot-loader {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg0);
}
#boot-loader[hidden] { display: none; }
.boot-box { text-align: center; }
.boot-logo { width: 76px; height: 76px; border-radius: 18px; margin: 0 auto 16px; display: block; }
.boot-title { font: 700 20px var(--display); letter-spacing: .12em; color: var(--txt); }
.boot-spinner {
  width: 34px; height: 34px; margin: 22px auto 10px;
  border: 3px solid var(--line); border-top-color: var(--sig); border-radius: 50%;
  animation: bootspin .9s linear infinite;
}
@keyframes bootspin { to { transform: rotate(360deg); } }
.boot-text { font-size: 14px; color: var(--mut); }
