/* CrewMeet – one stylesheet for all pages. Colors are tokens; dark mode follows the OS unless
   the theme toggle set data-theme on <html>. */

:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f0f2f7;
  --text: #1b2030;
  --muted: #646d82;
  --border: #dde1ea;
  --accent: #3b5bdb;
  --accent-hover: #3049b8;
  --accent-text: #ffffff;
  --accent-soft: #e7ecfd;
  --ok: #1f8a5b;
  --ok-soft: #e1f4ea;
  --warn: #a86b00;
  --warn-soft: #fbf0d9;
  --bad: #c9362c;
  --bad-soft: #fbe5e3;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 4px 16px rgb(16 24 40 / .06);
  --radius: 10px;
  --avatar-bg-l: 90%;
  --avatar-fg-l: 34%;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141b;
    --panel: #1a1d26;
    --panel-2: #222633;
    --text: #e6e8ef;
    --muted: #949bb0;
    --border: #2d3242;
    --accent: #7390ff;
    --accent-hover: #8fa6ff;
    --accent-text: #0d1126;
    --accent-soft: #232c4f;
    --ok: #4cc98f;
    --ok-soft: #173326;
    --warn: #e9b04d;
    --warn-soft: #382c14;
    --bad: #f0776d;
    --bad-soft: #3b1d1b;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
    --avatar-bg-l: 26%;
    --avatar-fg-l: 82%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12141b;
  --panel: #1a1d26;
  --panel-2: #222633;
  --text: #e6e8ef;
  --muted: #949bb0;
  --border: #2d3242;
  --accent: #7390ff;
  --accent-hover: #8fa6ff;
  --accent-text: #0d1126;
  --accent-soft: #232c4f;
  --ok: #4cc98f;
  --ok-soft: #173326;
  --warn: #e9b04d;
  --warn-soft: #382c14;
  --bad: #f0776d;
  --bad-soft: #3b1d1b;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
  --avatar-bg-l: 26%;
  --avatar-fg-l: 82%;
  color-scheme: dark;
}

/* ---- Base ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html.loading main { visibility: hidden; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }

/* ---- Controls ---- */
input, select, button {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
}
input, select { width: 100%; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { background: var(--panel-2); }
button:disabled, select:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.secondary { background: transparent; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
button.danger-outline { color: var(--bad); }
button.danger-outline:hover:not(:disabled) { background: var(--bad-soft); }
button.wide { width: 100%; padding: 10px; }
.icon-button { padding: 6px 10px; line-height: 1; font-size: 16px; }
.small-button { padding: 4px 10px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 13px; }
.alert {
  background: var(--bad-soft);
  color: var(--bad);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
}
.chip, .badge, .count {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  vertical-align: middle;
}
.badge { align-self: flex-start; }
.badge[data-status="active"] { background: var(--ok-soft); color: var(--ok); }
.badge[data-status="pending"] { background: var(--accent-soft); color: var(--accent); }
.badge[data-status="locked"] { background: var(--warn-soft); color: var(--warn); }
.badge[data-status="banned"] { background: var(--bad-soft); color: var(--bad); }

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px max(16px, calc((100% - 1100px) / 2 + 16px));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.nav-badge, .unread {
  display: inline-block;
  min-width: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.topbar-end { display: flex; align-items: center; gap: 8px; }

/* Role-based visibility (the server checks every request anyway) */
html:not([data-role="admin"]):not([data-role="superadmin"]) [data-needs="admin"],
html:not([data-role="superadmin"]) [data-needs="superadmin"],
html[data-role="member"] [data-needs="organizer"] { display: none !important; }

/* ---- Account menu ---- */
.menu { position: relative; }
.menu-trigger {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px 4px 4px;
  border-radius: 999px;
}
.menu-trigger::-webkit-details-marker { display: none; }
.menu-trigger:hover { background: var(--panel-2); }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
}
.menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-panel button { border: 0; text-align: left; background: transparent; }
.avatar {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.avatar[data-hue] {
  background: hsl(var(--hue) 65% var(--avatar-bg-l));
  color: hsl(var(--hue) 55% var(--avatar-fg-l));
}
.avatar[data-hue="0"] { --hue: 225; }
.avatar[data-hue="1"] { --hue: 160; }
.avatar[data-hue="2"] { --hue: 25; }
.avatar[data-hue="3"] { --hue: 285; }
.avatar[data-hue="4"] { --hue: 345; }
.avatar[data-hue="5"] { --hue: 195; }
.avatar.small { width: 26px; height: 26px; font-size: 12px; }
.avatar.tiny { width: 20px; height: 20px; font-size: 10px; }

/* ---- Views & panels ---- */
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
/* Home: the overview */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.home-card { padding: 16px; min-width: 0; }
.home-card h2 { font-size: 15px; margin: 0 0 10px; }
.home-card p { margin: 0; }
.home-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.home-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; color: var(--text); text-decoration: none; }
a.home-row:hover { background: var(--panel-2); }
.home-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); text-decoration: none; }
.home-live { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 10px; font-size: 13px; }
.home-people { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.home-people button { display: inline-flex; align-items: center; gap: 6px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.home-foot { margin-top: 16px; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); padding: 4px; border-radius: 10px; }
.tabs button { border: 0; background: transparent; color: var(--muted); font-weight: 500; }
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar p { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.filter { border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.filter[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.filter .count { margin-left: 4px; }
.empty { text-align: center; padding: 24px; margin: 0; }

/* ---- User list (admin) ---- */
.user-list { display: flex; flex-direction: column; }
.user-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 130px minmax(160px, 1.4fr) 130px auto;
  gap: 14px;
  align-items: center;
  padding: 12px 4px;
  border-top: 1px solid var(--border);
}
cm-user-row:first-child .user-row { border-top: 0; }
.user-row[data-status="banned"] .user-ident { opacity: .6; }
.user-ident { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-ident strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.user-actions button { padding: 5px 10px; font-size: 13px; }

@media (max-width: 860px) {
  .user-row { grid-template-columns: 1fr auto; }
  .user-status, .user-seen { grid-column: 1 / -1; }
  .user-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---- Audit log ---- */
.audit-list { list-style: none; margin: 0; padding: 0; }
.audit-list li {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 2px 14px;
  padding: 9px 4px;
  border-top: 1px solid var(--border);
}
.audit-list li:first-child { border-top: 0; }
.audit-list li > .small:last-child:not(time) { grid-column: 2; }

/* ---- Dialogs ---- */
dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  width: min(460px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(10 12 20 / .45); }
.dialog-form { padding: 22px; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 100;
}
.toast.error { background: var(--bad); color: #fff; }

/* ---- Login / set-password pages ---- */
.auth-page main { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.auth-card h1 { margin-bottom: 20px; text-align: center; }
.auth-card .small { text-align: center; margin: 14px 0 0; }

@media (max-width: 600px) {
  .topbar { gap: 10px; }
  .menu-name { display: none; }
  .audit-list li { grid-template-columns: 1fr; }
  .audit-list li > .small:last-child:not(time) { grid-column: 1; }
}

/* ---- Chat ---- */
.chat-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  height: calc(100dvh - 110px);
  min-height: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
/* Only the room links scroll, so the bell menu in the head isn't clipped */
.room-list { height: 100%; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel-2); }
.room-list > nav { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 16px; }
.room-list-head { display: flex; align-items: center; gap: 6px; padding: 16px 12px 0; position: relative; z-index: 5; }
.room-list-head h2 { margin: 0; flex: 1; }
.room-list .conn-status { margin: 6px 16px 0; }
.bell { list-style: none; cursor: pointer; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.bell::-webkit-details-marker { display: none; }
.room-list-head .menu-panel { left: 0; right: auto; width: 250px; }
.radio-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.radio-row:hover { background: var(--panel-2); }
.radio-row input { width: auto; margin-top: 4px; }
.menu-note { margin: 6px 10px 4px; }
.room-list h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 4px 6px; }
.conn-status { font-size: 12px; color: var(--muted); }
.conn-status::before { content: "●"; margin-right: 5px; color: var(--warn); }
.conn-status[data-status="online"]::before { color: var(--ok); }
.conn-status[data-status="offline"]::before { color: var(--bad); }
.rooms { list-style: none; margin: 0; padding: 0; }
.room-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}
.room-link:hover { background: var(--panel); }
.room-link.active { background: var(--accent-soft); color: var(--accent); }
.room-link.has-unread .room-name { font-weight: 700; }
.room-hash { color: var(--muted); }
.room-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-join { display: flex; align-items: center; gap: 4px; }
.room-join .room-link { flex: 1; color: var(--muted); }

.chat-main { min-width: 0; min-height: 0; height: 100%; }
.chat-main > cm-chat-room { display: block; height: 100%; }
.chat-placeholder { height: 100%; display: grid; place-items: center; padding: 24px; text-align: center; }
.chat-room { display: flex; flex-direction: column; height: 100%; }
.chat-room-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chat-room-head h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-room-head .topic { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-link { display: none; font-size: 26px; line-height: 1; text-decoration: none; padding: 0 6px; }
.chat-room-main { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 210px; }
.chat-room-main.no-members { grid-template-columns: 1fr; }
.chat-room-messages { min-height: 0; display: flex; flex-direction: column; }
.chat-room-messages > cm-message-list { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.oversight-note { margin: 0; padding: 8px 16px; background: var(--warn-soft); color: var(--warn); font-size: 13px; border-bottom: 1px solid var(--border); }
.join-preview { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 4px; }
.messages:focus-visible { outline-offset: -2px; }
.load-older { text-align: center; margin: 8px 0; }
.day-sep { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; color: var(--muted); font-size: 12px; font-weight: 600; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.msg-group { display: flex; gap: 10px; padding: 6px 0; }
.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-head time { color: var(--muted); font-size: 12px; }
.msg { position: relative; border-radius: 6px; padding: 1px 8px 1px 6px; margin-left: -6px; }
.msg:hover { background: var(--panel-2); }
.msg.mentioned { background: var(--warn-soft); box-shadow: inset 3px 0 0 var(--warn); }
.mention { color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.mention.me { color: var(--warn); background: var(--warn-soft); }
.unread.mention, .nav-badge.mention { background: var(--warn); color: #fff; }
.new-sep { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; color: var(--bad); font-size: 12px; font-weight: 700; }
.new-sep::before, .new-sep::after { content: ""; flex: 1; border-top: 1px solid var(--bad); }
.new-sep::before { flex: 0 0 0; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
/* Floating toolbar on hover / keyboard focus */
.msg-actions {
  position: absolute;
  right: 8px;
  top: -14px;
  display: none;
  gap: 1px;
  padding: 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 2;
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: flex; }
.msg-actions button { padding: 2px 7px; font-size: 14px; border: 0; background: transparent; }
.msg-actions button:hover:not(:disabled) { background: var(--panel-2); }
.msg.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { background: var(--accent-soft); } 100% { background: transparent; } }

.reply-quote {
  display: flex;
  align-items: baseline;
  gap: 4px;
  max-width: 100%;
  margin: 2px 0 2px;
  padding: 2px 8px;
  border: 0;
  border-left: 3px solid var(--border);
  border-radius: 0 6px 6px 0;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}
button.reply-quote:hover:not(:disabled) { border-left-color: var(--accent); color: var(--text); }
.reply-quote strong { color: var(--text); font-weight: 600; }
.reply-excerpt { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.reply-quote.deleted { display: block; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 2px; }
.reaction { padding: 0 8px; border-radius: 999px; font-size: 13px; line-height: 22px; }
.reaction .count { font-weight: 600; color: var(--muted); }
.reaction.mine { background: var(--accent-soft); border-color: var(--accent); }
.reaction.mine .count { color: var(--accent); }
.reaction:disabled { opacity: 1; }

.reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px;
  padding: 6px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 6px 6px 0 0;
  background: var(--accent-soft);
  font-size: 13px;
  white-space: nowrap;
  min-width: 0;
}
.reply-bar > span { overflow: hidden; text-overflow: ellipsis; }

.emoji-picker {
  position: fixed;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(8, 34px);
  gap: 2px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.emoji-option { padding: 0; height: 34px; font-size: 19px; border: 0; background: transparent; border-radius: 6px; }
.emoji-option:hover:not(:disabled), .emoji-option:focus-visible { background: var(--accent-soft); }
.msg-edit { padding-right: 6px; }
.msg-edit textarea, .composer textarea {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  width: 100%;
  resize: none;
}
.msg-edit .row { margin: 6px 0; }
.typing { min-height: 20px; margin: 0; padding: 0 16px; font-style: italic; }
.composer { position: relative; display: flex; align-items: flex-end; gap: 8px; padding: 6px 16px 14px; }
.mention-picker {
  position: absolute;
  left: 16px;
  bottom: calc(100% - 4px);
  width: min(340px, calc(100% - 32px));
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
}
.mention-picker li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.mention-picker li[aria-selected="true"] { background: var(--accent-soft); }
.composer textarea { flex: 1; max-height: 200px; }
.composer-count { align-self: center; }
.attach-button { align-self: flex-end; padding: 8px 10px; }
.composer.dropping textarea { outline: 2px dashed var(--accent); outline-offset: 2px; }

/* Attachments waiting to be sent */
.attachment-tray { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 16px; padding: 8px 0 0; }
.attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 6px 6px 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}
.attachment.failed { border-color: var(--bad); background: var(--bad-soft); }
.attachment img { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; }
.attachment-icon { font-size: 24px; }
.attachment-info { min-width: 0; }
.attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.attachment progress { width: 60px; }

/* Attachments in messages */
.msg-images { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.msg-images img {
  display: block;
  max-width: min(320px, 100%);
  max-height: 240px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.file-item { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.file-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 320px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
}
.file-chip:hover { border-color: var(--accent); }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }

.room-members { height: 100%; overflow-y: auto; border-left: 1px solid var(--border); padding: 12px; }
.chat-room-members { min-height: 0; }
.room-members h3 { font-size: 13px; margin: 0 0 8px; }
.room-members ul { list-style: none; margin: 0; padding: 0; }
.room-members li { display: flex; align-items: center; gap: 8px; padding: 4px 0; min-width: 0; }
.room-members li.away { opacity: .55; }
.member-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence-wrap { position: relative; display: inline-flex; }
.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: var(--muted);
}
li.online .presence-dot, .presence-wrap.online .presence-dot { background: var(--ok); }
.presence-wrap.away { opacity: .75; }
.room-link .presence-dot { width: 8px; height: 8px; border-color: var(--panel-2); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 6px; }
.room-list .section-head h3 { margin: 0 4px; }
.icon-button.tiny { padding: 0 7px; font-size: 15px; line-height: 20px; }
.link-button { border: 0; background: none; padding: 0; text-align: left; color: inherit; cursor: pointer; }
.link-button:hover:not(:disabled) { background: none; color: var(--accent); text-decoration: underline; }
fieldset.choice { border: 0; padding: 0; margin: 0 0 14px; }
fieldset.choice legend { font-weight: 600; font-size: 13px; padding: 0; margin-bottom: 4px; }
fieldset.choice .radio-row { padding: 6px 4px; }
.people-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 300px; overflow-y: auto; }
.people-list li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.people-list li:hover, .people-list li[aria-selected="true"] { background: var(--accent-soft); }
.people-list li.empty { cursor: default; justify-content: center; }
.people-list li.away .avatar { opacity: .7; }

/* Whiteboard: next to the messages (members hidden); the board stays white in both themes, so a drawing looks the same for everyone */
.chat-room-main.with-board { grid-template-columns: minmax(0, 1fr) 320px; }
.chat-room-main.with-board .chat-room-members { display: none; }
.chat-room-main.with-board .chat-room-messages { border-left: 1px solid var(--border); }
.chat-room-board { min-height: 0; min-width: 0; display: flex; }
.chat-room-board > cm-whiteboard { flex: 1; min-width: 0; display: flex; }
.board { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel-2); }
.board-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel); }
.board-tools .grow { flex: 1; }
.board-tools [data-ref="viewers"] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.board-group { display: flex; gap: 4px; padding-right: 6px; margin-right: 2px; border-right: 1px solid var(--border); }
.board-swatch { width: 26px; height: 26px; padding: 0; border-radius: 50%; background: var(--swatch); border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--border); }
.board-swatch:hover:not(:disabled) { background: var(--swatch); }
.board-swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--accent); }
.board-size { width: 32px; height: 28px; padding: 0; display: grid; place-items: center; }
.board-size span { width: var(--dot); height: var(--dot); border-radius: 50%; background: var(--text); }
.board-tool { width: 30px; height: 28px; padding: 0; font-size: 15px; line-height: 1; }
.board-tools [aria-checked="true"].board-size, .board-tools [aria-checked="true"].board-tool, .board-tools [aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.board-note { margin: 0; padding: 6px 12px; background: var(--warn-soft); color: var(--warn); }
.board-stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; padding: 12px; overflow: hidden; }
.board-stage canvas { display: block; background: #fff; border-radius: 6px; box-shadow: var(--shadow); touch-action: none; cursor: crosshair; }
.board-stage canvas.tool-select { cursor: default; }
.board-stage canvas.tool-eraser { cursor: cell; }
.board-stage canvas.tool-text { cursor: text; }
.board-stage canvas.over-item { cursor: move; }
.board-stage canvas.readonly { cursor: not-allowed; }
.board-stage canvas.panning { cursor: grab; }
/* Pen / eraser outline at the pointer (position and size set from script) */
.board-cursor { position: absolute; left: 0; top: 0; box-sizing: border-box; border: 1.5px solid #1e1e1e; border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 1px rgb(255 255 255 / .8); }
.board-cursor.eraser { border: 1.5px dashed #646d82; background: rgb(255 255 255 / .35); }
/* The text being typed, over the canvas where it will go */
.board-text { position: absolute; margin: 0; padding: 0; border: 0; outline: 1px dashed #3b5bdb; background: rgb(255 255 255 / .6); resize: none; overflow: hidden; white-space: pre; min-width: 8px; box-shadow: none; border-radius: 0; }
.board-zoom [data-ref="zoomReset"] { min-width: 52px; }
/* Expanded: the board fills the window above everything, over a dimmed page */
cm-whiteboard.expanded { position: fixed; inset: 16px; z-index: 1000; border-radius: var(--radius); box-shadow: var(--shadow); }
cm-whiteboard.expanded::before { content: ''; position: fixed; inset: 0; z-index: -1; background: rgb(10 12 20 / .55); }
cm-whiteboard.expanded .board { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
html.board-expanded { overflow: hidden; }
@media (max-width: 760px) {
  cm-whiteboard.expanded { inset: 0; }
  cm-whiteboard.expanded .board { border-radius: 0; border: 0; }
}
button.board-active { color: var(--accent); border-color: var(--accent); }

@media (max-width: 1000px) {
  .chat-room-main { grid-template-columns: 1fr; }
  .chat-room-members { display: none; }
  .chat-room-main.with-board { grid-template-columns: 1fr; grid-template-rows: minmax(0, 3fr) minmax(0, 2fr); }
  .chat-room-main.with-board .chat-room-messages { border-left: 0; border-top: 1px solid var(--border); }
  .board-stage { padding: 6px; }
}
@media (max-width: 760px) {
  .container:has(cm-chat-view:not([hidden])) { padding: 0; }
  .chat-layout { grid-template-columns: 1fr; height: calc(100dvh - 57px); border-radius: 0; border: 0; }
  .chat-layout.has-room cm-room-list, .chat-layout:not(.has-room) .chat-main { display: none; }
  .back-link { display: block; }
}

/* ---- Chat: pins, seen by, search, moderation ---- */
.pins-anchor { position: relative; }
.pins-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: min(360px, 80vw);
  max-height: 60vh;
  overflow-y: auto;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 30;
}
.pins-panel h3 { font-size: 13px; margin: 0 0 8px; }
.pins-panel ul { list-style: none; margin: 0; padding: 0; }
.pins-panel li { display: flex; align-items: flex-start; gap: 4px; border-top: 1px solid var(--border); }
.pins-panel li:first-child { border-top: 0; }
.pin-item, .search-hit {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  white-space: normal;
}
.pin-item:hover:not(:disabled), .search-hit:hover:not(:disabled) { background: var(--panel-2); }
.pin-text, .search-text { overflow-wrap: anywhere; }
.pins-panel li .icon-button { margin-top: 8px; }
.msg.pinned { box-shadow: inset 3px 0 0 var(--accent); }
.pinned-mark { font-size: 11px; font-weight: 600; color: var(--accent); }
.seen-by { font-size: 11px; color: var(--muted); margin: 2px 0 0; }

.chat-search { padding: 10px 12px 0; }
.chat-search input { padding: 6px 10px; font-size: 13px; }
.search-results { display: flex; flex-direction: column; height: 100%; }
.search-list { list-style: none; margin: 0; padding: 8px 12px; overflow-y: auto; flex: 1; }
.search-list li { border-top: 1px solid var(--border); }
.search-list li:first-child { border-top: 0; }
mark { background: var(--warn-soft); color: inherit; border-radius: 3px; padding: 0 1px; }
.button-link { text-decoration: none; color: var(--text); border: 1px solid var(--border); border-radius: 8px; }
.button-link:hover { background: var(--panel-2); }

.muted-mark { font-size: 13px; }
.room-members li .member-action { margin-left: auto; opacity: 0; }
.room-members li:hover .member-action, .room-members li .member-action:focus-visible { opacity: 1; }
.chat-room-head h2 .chip { font-weight: 500; margin-left: 4px; }
.composer textarea:disabled { background: var(--panel-2); cursor: not-allowed; }

/* ---- Admin: archive ---- */
.archive h2 { margin: 20px 0 8px; display: flex; align-items: center; gap: 8px; }
.archive h2:first-of-type { margin-top: 4px; }
.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-list li { display: flex; align-items: center; gap: 8px; padding: 10px 4px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.archive-list li:first-child { border-top: 0; }
.archive-foot { margin-top: 20px; }
.backup-actions { gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.backup-actions input { width: auto; }
.backup-running { margin: 0 0 8px; }

/* Admin → Storage: one bar per area (scaled to the largest), the disk as a meter */
.storage-disk { margin-bottom: 20px; }
.storage-meter { height: 8px; margin-top: 6px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.storage-meter span { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.storage-table { width: 100%; border-collapse: collapse; }
.storage-table caption { text-align: left; padding-bottom: 6px; }
.storage-table th, .storage-table td { padding: 8px 6px; border-top: 1px solid var(--border); text-align: left; vertical-align: middle; font-weight: normal; }
.storage-table thead th { border-top: 0; font-size: 12px; color: var(--muted); }
.storage-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.storage-bar-cell { width: 40%; }
.storage-bar { display: block; height: 8px; border-radius: 0 4px 4px 0; background: var(--accent); }
@media (max-width: 600px) {
  .storage-bar-cell { width: 25%; }
  .storage-table .muted.small { display: none; }
}
dialog.wide-dialog { width: min(760px, calc(100vw - 32px)); }
.archive-messages { max-height: 65vh; overflow-y: auto; }
.archive-msg { padding: 10px 4px; border-top: 1px solid var(--border); }
.archive-msg:first-child { border-top: 0; }
.archive-msg .row { gap: 8px; }
.archive-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.archive-actions { margin-top: 6px; }
.versions { margin: 6px 0 0; padding-left: 20px; }
.versions li { margin-bottom: 6px; }

/* ---- Voice chat ---- */
:root { --voice-dock-h: 64px; }
body.in-voice { padding-bottom: var(--voice-dock-h); }
body.in-voice .chat-layout { height: calc(100dvh - 110px - var(--voice-dock-h)); }
body.in-voice .toast { bottom: calc(var(--voice-dock-h) + 16px); }
.voice-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--voice-dock-h);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.voice-room { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 260px; color: var(--text); text-decoration: none; }
.voice-room strong, .voice-room .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-live { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--warn); }
.voice-live.on { background: var(--ok); }
.voice-people { flex: 1; min-width: 0; display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; overflow-x: auto; }
.voice-people li { display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px; background: var(--panel-2); white-space: nowrap; }
.voice-people .avatar { box-shadow: 0 0 0 2px transparent; transition: box-shadow .12s; }
.voice-people li.speaking .avatar { box-shadow: 0 0 0 2px var(--ok); }
.voice-people li.connecting { opacity: .55; }
.voice-name { font-size: 13px; }
.voice-muted { font-size: 12px; }
.voice-controls { display: flex; align-items: center; gap: 8px; position: relative; }
.voice-controls .icon-button.is-muted { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-soft); }
.voice-controls details { position: relative; }
.voice-controls .menu-panel { top: auto; bottom: calc(100% + 10px); width: 260px; padding: 10px; }
.voice-controls .menu-panel select { margin-top: 4px; }
button.voice-active { color: var(--ok); border-color: var(--ok); }
.voice-controls .icon-button.is-sharing { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* A screen shared in the voice chat (cm-screen-view) */
.screen-view { position: fixed; right: 16px; bottom: calc(var(--voice-dock-h) + 16px); z-index: 900; width: min(480px, calc(100vw - 32px));
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.screen-view-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.screen-view-head strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen-view-head select { width: auto; max-width: 140px; padding: 2px 6px; font-size: 12px; }
.screen-view-head .icon-button { padding: 4px 8px; font-size: 13px; }
.screen-view-body { position: relative; aspect-ratio: 16 / 9; background: #000; }
.screen-view-body video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.screen-view-wait { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: #aab; }
.screen-view.folded .screen-view-body { display: none; }
.screen-view.expanded { inset: 16px; width: auto; bottom: 16px; z-index: 1000; box-shadow: 0 0 0 100vmax rgb(10 12 20 / .55), var(--shadow); }
.screen-view.expanded .screen-view-body { flex: 1; aspect-ratio: auto; }
html.screen-expanded { overflow: hidden; }
@media (max-width: 760px) {
  .screen-view.expanded { inset: 0; border-radius: 0; }
}
.voice-count { font-size: 12px; color: var(--ok); white-space: nowrap; }
.voice-mark { font-size: 13px; }

@media (max-width: 600px) {
  .voice-dock { gap: 10px; padding: 0 10px; }
  .voice-room { max-width: 40vw; }
  .voice-name, .voice-room .small { display: none; }
  .voice-people li { padding: 2px; }
}

/* ---- Watch together ---- */
.container:has(cm-watch-view:not([hidden])) { max-width: 1680px; }
.watch-layout { display: grid; grid-template-columns: 250px 1fr; height: calc(100dvh - 110px); min-height: 420px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
body.in-voice .watch-layout { height: calc(100dvh - 110px - var(--voice-dock-h)); }
.watch-rooms .watch-hint { margin: 6px 12px 10px; }
.watch-main { min-width: 0; min-height: 0; height: 100%; }
.watch-big { font-size: 42px; margin: 0; }
.watch-room { display: flex; flex-direction: column; height: 100%; }
.watch-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.watch-stage { min-width: 0; padding: 16px; overflow-y: auto; }
.watch-player { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 8px; overflow: hidden; }
.watch-player:fullscreen { border-radius: 0; }
.watch-frame, .watch-frame iframe, .watch-cover { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.watch-cover { cursor: pointer; }
/* The hidden player that reads a YouTube playlist (players/youtube.js) */
.watch-offscreen { position: fixed; left: -10000px; top: 0; width: 320px; height: 180px; overflow: hidden; pointer-events: none; }
.watch-offscreen iframe { width: 320px; height: 180px; border: 0; }
.watch-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #aab; font-size: 14px; }
.watch-join { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 10px 18px; }
.watch-controls { display: flex; align-items: center; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.watch-controls .small-button { min-width: 34px; }
.watch-controls [aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.watch-time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 38px; text-align: center; }
.watch-seek { flex: 1; min-width: 120px; accent-color: var(--accent); }
.watch-volume { width: 90px; accent-color: var(--accent); }
.watch-subtitles { width: auto; max-width: 160px; padding: 3px 6px; font-size: 12px; }
.watch-status { margin: 8px 0 0; }
/* ⤢: the player and its controls fill the window; the video keeps its proportions inside */
.watch-stage.expanded { position: fixed; inset: 16px; z-index: 1000; display: flex; flex-direction: column; overflow: hidden; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 0 0 100vmax rgb(10 12 20 / .55), var(--shadow); }
.watch-stage.expanded .watch-player { flex: 1; min-height: 0; aspect-ratio: auto; }
.watch-stage.expanded .watch-frame video { object-fit: contain; }
html.watch-expanded { overflow: hidden; }
.watch-side { min-height: 0; display: flex; flex-direction: column; border-left: 1px solid var(--border); background: var(--panel-2); }
.watch-add { display: flex; gap: 6px; padding: 12px; border-bottom: 1px solid var(--border); }
.watch-add input { flex: 1; min-width: 0; }
.watch-tabs { margin: 8px 12px 0; }
.watch-tabs button { flex: 1; }
.watch-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.watch-chat > cm-message-list { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.watch-chat .messages { padding: 8px 10px 4px; }
.watch-chat .typing { padding: 0 10px; }
.watch-chat .composer { padding: 6px 10px 10px; }
.watch-tabs .unread { margin-left: 4px; }
.watch-history { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.watch-history[hidden] { display: none; }
.watch-history-search { width: auto; margin: 8px 12px 0; }
.watch-history-item { grid-template-columns: 72px minmax(0, 1fr); }
.watch-history-item .watch-item-actions { grid-column: 2; }
.watch-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; min-height: 0; }
.watch-list-empty { padding: 14px 8px; }
.watch-item { display: grid; grid-template-columns: 14px 72px minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 8px; align-items: center; padding: 6px; border-radius: 8px; border: 1px solid transparent; }
.watch-item:hover { background: var(--panel); }
.watch-item.current { background: var(--accent-soft); border-color: var(--accent); }
.watch-item.dragging { opacity: .45; }
.watch-item.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.watch-item.drop-after { box-shadow: 0 2px 0 var(--accent); }
.watch-handle { grid-row: 1 / 3; color: var(--muted); cursor: grab; user-select: none; }
.watch-item img, .watch-thumb { grid-row: 1 / 3; width: 72px; height: 40px; object-fit: cover; border-radius: 4px; background: #000; }
.watch-thumb { display: grid; place-items: center; font-size: 18px; background: var(--panel); border: 1px solid var(--border); }
.watch-frame video { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; }
.watch-pick { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; padding: 0; border: 0; background: none; text-align: left; white-space: normal; }
.watch-pick:hover:not(:disabled) { background: none; }
.watch-pick:hover .watch-item-title { color: var(--accent); }
.watch-item-title { font-size: 13px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.watch-pick .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.watch-item-actions { grid-column: 3; display: flex; gap: 4px; margin-top: 4px; }
.watch-item-actions .small-button { padding: 1px 7px; font-size: 11px; }

@media (max-width: 1000px) {
  .watch-body { grid-template-columns: 1fr; grid-template-rows: auto minmax(220px, 1fr); overflow-y: auto; }
  .watch-side { border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 760px) {
  .container:has(cm-watch-view:not([hidden])) { padding: 0; }
  .watch-layout { grid-template-columns: 1fr; height: calc(100dvh - 57px); border-radius: 0; border: 0; }
  .watch-layout.has-room .watch-rooms, .watch-layout:not(.has-room) .watch-main { display: none; }
  .watch-stage { padding: 10px; }
  .watch-stage.expanded { inset: 0; border: 0; border-radius: 0; }
  .watch-volume { display: none; }
}
