/* BRS Community Chat — styles
   Theme variables mirror the parent biohybrid-robotics-website index.html
   so dark/light mode stays consistent with the main site. */

:root {
  color-scheme: light;
  --page-bg: #fffaf8;          /* warm off-white base */
  --surface: #ffffff;
  --surface-2: #fbf4f5;        /* faint rose-tinted hover */
  --surface-3: #f3e2e4;
  --text-color: #1a1416;
  --text-muted: #6b5f62;
  --border-color: #ecdcde;
  --shadow-color: rgba(113, 0, 13, 0.09);
  --accent: #8a0210;           /* Takeuchi Lab primary red */
  --accent-2: #71000d;          /* deeper wine, used in gradients / active */
  --accent-soft: #fdf0f2;       /* very pale rose — tints */
  --on-accent: #ffffff;
  --danger: #c94f2d;            /* orange-red, distinct from brand */
  --danger-bg: #fdf0e8;
  --unread: #b71c2c;            /* brighter red for visibility */
  --own-msg-bg: #fdf0f2;        /* pale rose for own messages */
  --link-color: #8a0210;
}

[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #120b0d;           /* near-black with wine tint */
  --surface: #1c1114;
  --surface-2: #15090c;
  --surface-3: #2a1619;
  --text-color: #f1ecee;
  --text-muted: #a89ba0;
  --border-color: #3a2229;
  --shadow-color: rgba(0, 0, 0, 0.55);
  --accent: #ef6b70;            /* lifted red for dark contrast */
  --accent-2: #b91c1c;
  --accent-soft: #2a1317;
  --on-accent: #ffffff;
  --danger: #f09060;
  --danger-bg: #3b1e15;
  --unread: #ff7b85;
  --own-msg-bg: #2a1317;
  --link-color: #f28b8b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { color-scheme: dark; }
}

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

html, body {
  height: 100%;
  height: 100dvh;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               Arial, "Noto Sans JP", sans-serif;
  background: var(--page-bg);
  color: var(--text-color);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Instant full-screen loader shown until the first screen renders. Styled with
   theme vars (chat.css is render-blocking, so this paints before chat.js runs). */
.app-loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--page-bg);
  color: var(--text-muted);
}
.app-loading-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  animation: app-loading-spin 0.8s linear infinite;
}
.app-loading p { margin: 0; font-size: 0.95rem; }
@keyframes app-loading-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .app-loading-spinner { animation-duration: 2.4s; }
}

a { color: var(--link-color); }
a:hover { text-decoration: underline; }

/* ==== Screens ==== */
.screen {
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
}

.screen[hidden] { display: none !important; }

/* ==== Sign-in / profile cards ==== */
#signin-screen, #profile-screen, #invite-screen {
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(135deg, var(--surface-2), var(--page-bg));
}

/* Invite gate — stack the input + button + hint with consistent spacing
   so the card looks the same shape as the sign-in card. */
#form-invite {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}
#form-invite .hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 0;
}

/* Terms-of-use box on the invite gate — wider card so the bulleted list
   is readable, with an internal scroll if the screen is short. */
.invite-card { max-width: 560px; }
.terms-box {
  background: var(--surface-2);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 0.85rem;
  line-height: 1.55;
  max-height: 38vh;
  overflow-y: auto;
  margin-bottom: 14px;
}
.terms-box p { margin-bottom: 6px; }
.terms-box ul {
  margin: 4px 0 0 18px;
  padding: 0;
}
.terms-box li { margin-bottom: 6px; }
.terms-box li:last-child { margin-bottom: 0; }

.terms-agree {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}
.terms-agree input[type="checkbox"] {
  margin-top: 3px;
  flex: 0 0 auto;
}

.signin-card {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: 0 8px 32px var(--shadow-color);
  width: 100%;
  max-width: 420px;
}

.signin-card h1 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.signin-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.signin-header h1 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}
.signin-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  flex: 0 0 auto;
}

.signin-card .muted {
  color: var(--text-muted);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.primary-btn, .secondary-btn, button {
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 16px;
  transition: background 0.15s, border-color 0.15s;
}

.primary-btn {
  background: var(--accent);
  color: var(--on-accent);
  width: 100%;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.primary-btn:hover { background: var(--accent-2); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary-btn {
  background: transparent;
  color: var(--text-color);
  border-color: var(--border-color);
  width: 100%;
}
.secondary-btn:hover { background: var(--surface-2); }

.icon-btn {
  background: transparent;
  border: 0;
  padding: 6px 10px;
  color: var(--text-color);
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }

.g-icon {
  width: 18px; height: 18px;
  background: conic-gradient(from 0deg, #ea4335 0deg 90deg, #fbbc05 90deg 180deg, #34a853 180deg 270deg, #4285f4 270deg 360deg);
  border-radius: 50%;
  display: inline-block;
}

.alt-signin {
  margin-top: 20px;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}
.alt-signin summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  user-select: none;
}
.alt-signin form { display: grid; gap: 10px; margin-top: 12px; }
.alt-signin .hint { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }

input[type="text"], input[type="email"], input[type="password"], textarea {
  background: var(--surface);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  width: 100%;
}
input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
label input { margin-top: 4px; }
label small { display: block; color: var(--text-muted); font-size: 0.75rem; margin-top: 2px; }

.error {
  color: var(--danger);
  background: var(--danger-bg);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-top: 12px;
}

.status {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ==== Chat layout ==== */
.chat-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
}

.chat-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--surface);
  min-height: 48px;
}

.chat-header .chat-title {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
.channel-hash { color: var(--text-muted); font-weight: 400; }

.brand {
  font-weight: 700;
  font-size: 1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  user-select: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  cursor: pointer;
}
a.brand:hover { opacity: 0.8; }
a.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.brand-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 6px;
  flex: 0 0 auto;
}
.brand-short { display: none; }
.brand-sep {
  color: var(--text-muted);
  font-weight: 300;
  opacity: 0.6;
}

@media (max-width: 560px) {
  .brand-full { display: none; }
  .brand-short { display: inline; }
}

.chat-header-spacer { flex: 1; }
#btn-toggle-sidebar { display: none; }

.user-menu { position: relative; }
.user-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 3px 10px 3px 3px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-color);
}
.user-btn .avatar { width: 28px; height: 28px; font-size: 0.8rem; }
.user-btn #user-menu-name { display: inline-flex; align-items: center; gap: 8px; line-height: 1; }
.user-btn:hover { background: var(--surface-2); }

.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  min-width: 140px;
  box-shadow: 0 4px 16px var(--shadow-color);
  padding: 4px;
  z-index: 20;
}
.dropdown button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 12px;
  border-radius: 4px;
  color: var(--text-color);
}
.dropdown button:hover { background: var(--surface-2); }

.chat-sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--border-color);
  background: var(--surface-2);
  overflow-y: auto;
  padding: 12px 8px;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 8px;
}
.sidebar-section-header h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.channel-list { list-style: none; }
.channel-list li {
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-color);
  font-size: 0.9rem;
  user-select: none;
}
.channel-list li:hover { background: var(--surface-3); }
.channel-list li.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.channel-list li.active .channel-hash,
.channel-list li.active .unread-badge { color: var(--on-accent); }
.channel-list .unread-badge {
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--unread);
}
.channel-list .unread-badge[hidden] { display: none; }

.chat-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--page-bg);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  min-height: 0;
}

.notification-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}
.notification-banner span { flex: 1; }
.notification-banner .secondary-btn { width: auto; padding: 6px 12px; }
.notification-banner[hidden] { display: none !important; }
.messages-loading, .messages-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
}

.messages-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.message {
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}
.message.own { background: var(--own-msg-bg); }
.message.deleted { color: var(--text-muted); font-style: italic; }
/* Admin viewing a hidden message — strike through the original text so it
   reads as "hidden but recoverable". The (hidden by admin) note above stays
   readable (no strikethrough). */
.message.deleted .message-text,
.message.deleted .yt-embed,
.message.deleted .arxiv-card,
.message.deleted .poll-card { text-decoration: line-through; opacity: 0.55; }
.deleted-stub { color: var(--text-muted); font-style: italic; font-size: 0.85em; }
.message-body { flex: 1; min-width: 0; }

.avatar {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.95rem;
  color: #fff;
  overflow: hidden;
  user-select: none;
}
.avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.avatar.avatar-sm { width: 28px; height: 28px; font-size: 0.8rem; }
.avatar.avatar-xs { width: 22px; height: 22px; font-size: 0.7rem; }
.avatar.avatar-lg { width: 80px; height: 80px; font-size: 2rem; }
.avatar.clickable { cursor: pointer; transition: transform 0.1s ease; }
.avatar.clickable:hover { transform: scale(1.05); }
.message-author.clickable { cursor: pointer; }
.message-author.clickable:hover { text-decoration: underline; }

/* User profile (view) dialog */
.user-profile-dialog .user-profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 8px 4px 16px;
}
.user-profile-dialog .user-profile-avatar { margin-bottom: 8px; }
.user-profile-dialog #user-profile-name { margin: 4px 0 0; }
.user-profile-dialog .user-profile-presence {
  margin: 0; font-size: 0.85rem; color: var(--text-muted);
}
.user-profile-dialog .user-profile-presence.online { color: #2ecc71; }
.user-profile-dialog .user-profile-affiliation {
  margin: 4px 0 0; font-size: 0.95rem;
}
.user-profile-dialog .user-profile-email {
  margin: 2px 0 0; font-size: 0.85rem; color: var(--text-muted);
}
/* Override the global width:100% on .primary-btn / .secondary-btn so multiple
   action buttons can sit side by side in the user profile dialog. */
.user-profile-dialog .dialog-actions { justify-content: center; }
.user-profile-dialog .dialog-actions .primary-btn,
.user-profile-dialog .dialog-actions .secondary-btn { width: auto; padding: 8px 22px; }

.message-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 2px;
}
.message-author { font-weight: 600; color: var(--text-color); }
.message-affiliation { color: var(--text-muted); font-size: 0.8rem; }
.message-time { color: var(--text-muted); font-size: 0.75rem; }
.message-edited { color: var(--text-muted); font-size: 0.75rem; font-style: italic; }

.message-text { white-space: pre-wrap; }
.message-text a { word-break: break-all; }
.message-text u { text-decoration: underline; }
.message-text s { text-decoration: line-through; opacity: 0.75; }

.message-image {
  margin-top: 6px;
  cursor: zoom-in;
  max-width: 300px;
  max-height: 300px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--surface-3);
}

/* Image grid for multi-attach messages.
   - 1 image  → use the legacy .message-image styling (max 300×300).
   - 2 images → 2-column row.
   - 3+ images → 3-column grid (rows wrap). */
.message-images {
  margin-top: 6px;
  display: grid;
  gap: 4px;
  max-width: 480px;
}
.message-images.cols-2 { grid-template-columns: repeat(2, 1fr); }
.message-images.cols-3 { grid-template-columns: repeat(3, 1fr); }
.message-images img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--surface-3);
  cursor: zoom-in;
}

/* File attachments inside messages — icon + name + size + download. */
.message-files {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.message-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface-2);
  text-decoration: none;
  color: var(--text-color);
  max-width: 360px;
  font-size: 0.85rem;
}
.message-file:hover { background: var(--surface-3); }
.message-file .file-icon { font-size: 1.2rem; flex: 0 0 auto; }
.message-file .file-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message-file .file-size {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.message-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  display: none;
  box-shadow: 0 2px 6px var(--shadow-color);
}
.message:hover .message-actions,
.message:focus-within .message-actions { display: flex; }
.message-actions button {
  background: transparent;
  border: 0;
  padding: 4px 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
}
.message-actions button:hover { background: var(--surface-2); color: var(--text-color); }

/* Reactions */
.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid var(--border-color);
  background: var(--surface-2);
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.85rem;
  user-select: none;
  transition: background 0.1s, border-color 0.1s;
}
.reaction-pill:hover { background: var(--surface-3); }
.reaction-pill.mine {
  background: var(--own-msg-bg);
  border-color: var(--accent);
}
.reaction-pill .reaction-count { color: var(--text-muted); font-size: 0.75rem; }
.reaction-pill.mine .reaction-count { color: var(--accent); }

.reaction-pill.reaction-badge {
  background: var(--badge-color, var(--accent));
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}
.reaction-pill.reaction-badge .reaction-count { color: rgba(255,255,255,0.85); }
.reaction-pill.reaction-badge.mine { box-shadow: 0 0 0 2px var(--accent); }

.emoji-picker {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow-color);
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 4px;
  z-index: 15;
  max-width: 320px;
}
.emoji-picker button {
  background: transparent;
  border: 0;
  padding: 4px 6px;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
}
.emoji-picker button:hover { background: var(--surface-2); }
.emoji-picker button.badge-swatch {
  color: #fff;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 4px 8px;
  grid-column: span 2;
}
.emoji-picker button.badge-swatch:hover { filter: brightness(1.1); }
.emoji-picker button.add-stamp {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border-color);
  margin-top: 2px;
  padding-top: 6px;
  border-radius: 0;
}
.emoji-picker button.add-stamp:hover { color: var(--accent); }

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border-color);
  background: var(--surface);
}

/* Formatting toolbar above the composer */
.compose-toolbar {
  display: flex;
  gap: 2px;
  padding: 6px 12px 0;
  background: var(--surface);
}
.compose-toolbar button {
  min-width: 30px;
  height: 28px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}
.compose-toolbar button:hover { background: var(--surface-2); color: var(--text-color); }
.compose-toolbar button .u { text-decoration: underline; }
.composer textarea {
  flex: 1 1 0;
  min-width: 0; /* without this the textarea refuses to shrink below ~200px, pushing Send offscreen on mobile */
  resize: none;
  max-height: 160px;
  line-height: 1.4;
  padding: 8px 10px;
}
.composer .primary-btn { width: auto; padding: 10px 20px; }

/* Composer-area thumbnail strip — one chip per pending attachment, with × to
   remove. Up to 10 chips total (image + file mixed). */
.attachments-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--border-color);
}
.attachments-strip[hidden] { display: none !important; }
.attachment-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 24px 4px 4px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.8rem;
  max-width: 220px;
}
.attachment-chip img {
  width: 40px; height: 40px;
  object-fit: cover;
  border-radius: 4px;
  flex: 0 0 auto;
}
.attachment-chip .chip-icon {
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: var(--surface-3);
  border-radius: 4px;
  flex: 0 0 auto;
}
.attachment-chip .chip-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}
.attachment-chip .chip-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 0;
  background: rgba(0,0,0,0.45);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.upload-status {
  padding: 0 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

/* Mentions sidebar button + counts */
.sidebar-mentions-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 16px);
  margin: 8px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-color);
  font-size: 0.9rem;
  font-weight: 600;
}
.sidebar-mentions-btn:hover { background: var(--surface); }
.sidebar-mentions-btn .mention-pill-count { margin-left: auto; }

.mention-pill-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
}
.mention-pill-count[hidden] { display: none; }
.channel-list li .mention-pill-count { margin-left: auto; }

/* Pinned bar */
.pinned-bar { border-bottom: 1px solid var(--border-color); background: var(--surface-2); }
.pinned-bar[hidden] { display: none !important; }
.pinned-toggle {
  width: 100%; text-align: left;
  padding: 8px 16px;
  background: transparent; border: 0;
  font-size: 0.85rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.pinned-toggle:hover { background: var(--surface-3); }
.pinned-chevron { margin-left: auto; transition: transform 0.15s; }
.pinned-bar.open .pinned-chevron { transform: rotate(180deg); }
.pinned-list { list-style: none; padding: 4px 16px 8px; max-height: 200px; overflow-y: auto; border-top: 1px solid var(--border-color); }
.pinned-item { display: flex; gap: 8px; padding: 6px 0; cursor: pointer; font-size: 0.85rem; border-radius: 4px; }
.pinned-item:hover { background: var(--surface); }
.pinned-item-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pinned-item-author { color: var(--text-muted); font-size: 0.75rem; }

/* Header search — Slack-style channel search to the left of the user menu. */
.header-search {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 1 280px;
  min-width: 0;
}
.header-search .header-search-icon {
  position: absolute;
  left: 8px;
  color: var(--text-muted);
  pointer-events: none;
}
.header-search input[type="search"] {
  width: 100%;
  padding: 6px 10px 6px 28px;
  font-size: 0.85rem;
  border-radius: 6px;
  background: var(--surface-2);
}
.search-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 6px;
  white-space: nowrap;
  flex: 0 0 auto;
}

/* Typing indicator */
.typing-indicator {
  padding: 4px 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  min-height: 0;
}
.typing-indicator[hidden] { display: none !important; }

/* Thread panel */
.thread-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 400px;
  max-width: 90vw;
  background: var(--page-bg);
  border-left: 1px solid var(--border-color);
  box-shadow: -4px 0 16px var(--shadow-color);
  display: flex;
  flex-direction: column;
  z-index: 40;
}
.thread-panel[hidden] { display: none !important; }
.thread-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px 8px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--surface);
}
.thread-header h2 { font-size: 1rem; }
.thread-scroll { flex: 1; overflow-y: auto; padding: 12px; }
.thread-parent { padding-bottom: 10px; border-bottom: 1px dashed var(--border-color); margin-bottom: 10px; }
.thread-composer { border-top: 1px solid var(--border-color); padding: 8px 12px; gap: 6px; }
.thread-composer textarea { min-height: 36px; }
.thread-composer .primary-btn { width: auto; padding: 8px 16px; }

.replies-summary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--accent);
  cursor: pointer;
  font-size: 0.8rem;
  border: 1px solid var(--border-color);
}
.replies-summary:hover { background: var(--surface-3); }

/* Channel switcher */
.channel-switcher-dialog { padding: 8px; max-width: 520px; }
.channel-switcher-dialog input[type=text] { font-size: 1rem; margin-bottom: 8px; }
.switcher-results { max-height: 320px; overflow-y: auto; }
.switcher-result {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; cursor: pointer; border-radius: 4px;
  font-size: 0.9rem;
}
.switcher-result:hover,
.switcher-result.active { background: var(--surface-2); }
.switcher-result .switcher-hash { color: var(--text-muted); }

/* Bookmarks */
.bookmarks-dialog { max-width: 560px; }
.bookmarks-list { max-height: 420px; overflow-y: auto; }
.bookmark-item {
  display: flex; gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  font-size: 0.9rem;
}
.bookmark-item:hover { background: var(--surface-2); }
.bookmark-item:last-child { border-bottom: 0; }
.bookmark-item-body { flex: 1; min-width: 0; }
.bookmark-item-meta { font-size: 0.75rem; color: var(--text-muted); }

/* Polls */
.poll-card {
  margin-top: 6px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
}
.poll-question { font-weight: 600; margin-bottom: 8px; }
.poll-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.poll-option:hover { background: var(--surface-2); }
.poll-option.voted {
  border-color: var(--accent);
  background: var(--own-msg-bg);
  font-weight: 600;
}
.poll-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: rgba(102, 126, 234, 0.15);
  z-index: 0;
  transition: width 0.3s;
}
.poll-option > span { position: relative; z-index: 1; }
.poll-option .poll-count { color: var(--text-muted); font-size: 0.8rem; float: right; }
.poll-total { font-size: 0.75rem; color: var(--text-muted); text-align: right; }

/* Markdown formatting */
.md-code {
  background: var(--surface-2);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 0 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
}
.md-pre {
  background: var(--surface-2);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
  margin: 4px 0;
  white-space: pre;
}

/* YouTube embed */
.yt-embed {
  margin-top: 6px;
  max-width: 400px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}
.yt-embed iframe { width: 100%; height: 100%; border: 0; display: block; }

/* arXiv link */
.arxiv-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #b31b1b;
  color: #fff !important;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none !important;
}
.arxiv-link:hover { filter: brightness(1.1); }

/* Online presence dot */
.avatar.online::after {
  content: "";
  position: absolute;
  width: 10px; height: 10px;
  background: #4ade80;
  border: 2px solid var(--surface);
  border-radius: 50%;
  right: -1px; bottom: -1px;
}
.avatar { position: relative; }

/* Highlighted message (permalink / scroll-to) */
.message.highlight {
  animation: highlightPulse 2s ease-out;
}
@keyframes highlightPulse {
  0% { background: rgba(102, 126, 234, 0.3); }
  100% { background: transparent; }
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: var(--text-color);
  font-size: 0.9rem;
}
.checkbox-row input[type=checkbox] { flex: 0 0 auto; width: auto; margin: 0; }

.notif-group {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.notif-group legend {
  padding: 0 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.notif-group[disabled] { opacity: 0.55; }
.notif-group[disabled] .checkbox-row { cursor: not-allowed; }

@media (max-width: 720px) {
  .thread-panel { width: 100%; max-width: 100%; }
}

/* @mentions */
.mention-dropdown {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 60px;
  max-width: 320px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow-color);
  z-index: 20;
}
.mention-dropdown .mention-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.9rem;
}
.mention-dropdown .mention-row:hover,
.mention-dropdown .mention-row.active { background: var(--surface-2); }
.mention-dropdown .mention-row .mention-handle { color: var(--text-muted); font-size: 0.8rem; }
.mention-dropdown .mention-row.broadcast {
  font-weight: 600;
  color: var(--danger);
}

.mention-pill {
  display: inline-block;
  padding: 0 6px;
  border-radius: 4px;
  background: rgba(102, 126, 234, 0.18);
  color: var(--accent);
  font-weight: 600;
}
.mention-pill.broadcast {
  background: rgba(192, 57, 43, 0.15);
  color: var(--danger);
}

.channel-list .mention-badge {
  margin-left: 4px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.channel-list .mention-badge[hidden] { display: none; }
.channel-list li.active .mention-badge { background: #fff; color: var(--accent); }

/* ==== Dialogs ==== */
.dialog {
  padding: 24px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-color);
  max-width: 420px;
  width: calc(100vw - 32px);
  box-shadow: 0 16px 48px var(--shadow-color);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog h2 { margin-bottom: 16px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.dialog-actions button { flex: 0 0 auto; padding: 8px 16px; }
/* Make non-primary dialog buttons clearly visible. */
.dialog-actions button:not(.primary-btn):not(.secondary-btn):not(.icon-btn):not(.remove-btn) {
  background: var(--surface-2);
  border: 1px solid var(--border-color);
  color: var(--text-color);
}
.dialog-actions button:not(.primary-btn):hover { background: var(--surface-3); }

.dialog-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: 0;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
}
.dialog-close:hover { background: var(--surface-2); color: var(--text-color); }
.dialog { position: relative; }

/* Help button in the header + embedded quick-start guide */
.help-btn { gap: 6px; width: auto; padding: 0 10px; }
.help-btn .help-label { font-size: 0.9rem; font-weight: 500; }
@media (max-width: 640px) { .help-btn .help-label { display: none; } }

.help-dialog {
  max-width: 960px;
  width: calc(100vw - 32px);
  height: min(88vh, 900px);
  padding: 0;
  overflow: hidden;
  border-radius: 14px;
}
.help-frame { display: block; width: 100%; height: 100%; border: 0; background: var(--surface); }
.help-dialog .help-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  font-size: 1.3rem;
  line-height: 1;
  background: var(--surface);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  box-shadow: 0 2px 8px var(--shadow-color);
}
.help-dialog .help-close:hover { background: var(--surface-2); }

.profile-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.profile-preview .avatar { width: 72px; height: 72px; font-size: 1.6rem; }

.avatar-input-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.avatar-upload-btn { flex: 0 1 auto; width: auto; padding: 6px 14px; }
.avatar-input-row .icon-btn { font-size: 0.85rem; }

.members-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.members-btn:hover { color: var(--text-color); }

.member-picker-sub {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin: 16px 0 6px;
}
.member-picker-list .remove-btn {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.member-picker-list .remove-btn:hover { background: var(--danger-bg); color: var(--danger); }
.member-picker-list .remove-btn:disabled { opacity: 0.3; cursor: not-allowed; }
/* Ban button: extra-emphasized danger styling so admins don't confuse it with Remove. */
.member-picker-list .ban-btn {
  border: 1px solid var(--danger, #c53030);
  color: var(--danger, #c53030);
}
.member-picker-list .ban-btn:hover {
  background: var(--danger, #c53030);
  color: #fff;
}
.member-picker-list .add-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
}
.member-picker-list .add-btn:hover { background: var(--accent); color: var(--on-accent); }

.member-picker { border: 1px solid var(--border-color); border-radius: 6px; padding: 8px; margin-bottom: 12px; }
.member-picker legend { padding: 0 6px; font-size: 0.85rem; color: var(--text-muted); }
.member-picker .hint { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; }

.member-picker-list {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 260px; overflow-y: auto;
}
.member-picker-list .member-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 4px; cursor: pointer; user-select: none;
}
.member-picker-list .member-row:hover { background: var(--surface-2); }
.member-picker-list .member-row.self { opacity: 0.6; cursor: default; }
.member-picker-list .member-row input[type="checkbox"] { flex: 0 0 auto; width: auto; }
.member-picker-list .avatar { flex: 0 0 auto; }
.member-picker-list .member-info { display: flex; flex-direction: column; min-width: 0; }
.member-picker-list .member-name { font-weight: 600; font-size: 0.9rem; }
.member-picker-list .member-sub { font-size: 0.75rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.channel-list .dm-name {
  display: flex; align-items: center; gap: 6px; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.channel-list .lock-icon { font-size: 0.75rem; color: var(--text-muted); }
.channel-list li.active .lock-icon { color: var(--on-accent); }

/* DM hide × button — hover-only on desktop, always visible on touch. */
.channel-list .dm-hide-btn {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 6px;
  font-size: 1.1rem;
  line-height: 1;
  border-radius: 4px;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.1s, background 0.1s;
}
.channel-list li:hover .dm-hide-btn { visibility: visible; opacity: 0.8; }
.channel-list .dm-hide-btn:hover { background: var(--surface-3); opacity: 1; color: var(--text-color); }
.channel-list li.active .dm-hide-btn { color: var(--on-accent); }
.channel-list li.active .dm-hide-btn:hover { background: rgba(255,255,255,0.18); }
@media (hover: none) {
  .channel-list .dm-hide-btn { visibility: visible; opacity: 0.7; }
}

/* Webhook setup help — collapsible step-by-step inside the notification dialog. */
.webhook-help {
  background: var(--surface-2);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 0.88rem;
}
.webhook-help summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  user-select: none;
}
.webhook-help summary::-webkit-details-marker { display: none; }
.webhook-help summary::before {
  content: "▸ ";
  color: var(--text-muted);
  display: inline-block;
  width: 1em;
  transition: transform 0.15s ease;
}
.webhook-help[open] summary::before { content: "▾ "; }
.webhook-help-steps {
  margin: 8px 0 0 0;
  padding-left: 22px;
  line-height: 1.55;
}
.webhook-help-steps li { margin: 4px 0; }
.webhook-help code {
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}

/* Search field at the top of the member picker (New DM / New Team dialogs).
   Auto-appears when the candidate list is 5+ people. Sticky so it stays
   visible while the candidate list below scrolls. */
.member-picker-search {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 9px 14px 9px 32px;
  font: inherit;
  font-size: 0.95rem;
  background: var(--surface-2)
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.35-4.35'/></svg>") 10px center / 14px no-repeat;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-color);
  box-sizing: border-box;
  position: sticky;
  top: 0;
  z-index: 2;
}
.member-picker-search:focus { outline: none; border-color: var(--accent); }
.member-picker-search::placeholder { color: var(--text-muted); }

/* DM filter input above the DM list. Auto-shown when 5+ DMs exist. */
.dm-filter {
  display: block;
  width: 100%;
  margin: 4px 0 6px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-color);
  box-sizing: border-box;
}
.dm-filter:focus { outline: none; border-color: var(--accent); }
.dm-filter::placeholder { color: var(--text-muted); }

/* "Show N hidden" / "Hide N hidden" toggle row at the bottom of DMs. */
.channel-list li.hidden-dms-toggle {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 4px 8px;
}
.channel-list li.hidden-dms-toggle:hover { background: var(--surface-3); }
.channel-list li.hidden-dm { opacity: 0.6; }
.channel-list li.hidden-dm:hover { opacity: 1; }

.message-email { color: var(--text-muted); font-size: 0.75rem; }

/* ==== Lightbox ==== */
.lightbox {
  border: 0;
  background: transparent;
  padding: 0;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
}
.lightbox[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox::backdrop { background: rgba(0, 0, 0, 0.9); }
.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  display: block;
}
.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.5rem;
  width: 40px; height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.lightbox-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  width: 48px; height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.lightbox-nav[hidden] { display: none; }
.lightbox-nav:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }

.lightbox-counter {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  z-index: 10;
}
.lightbox-counter[hidden] { display: none; }

/* ==== Fatal error banner ==== */
.fatal-error {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow-color);
  max-width: 90vw;
  z-index: 100;
}

/* ==== Mobile ==== */
@media (max-width: 720px) {
  .chat-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main";
  }
  .chat-sidebar {
    position: fixed;
    top: 48px;
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s;
    box-shadow: 4px 0 16px var(--shadow-color);
  }
  .chat-sidebar.open { transform: translateX(0); }
  #btn-toggle-sidebar { display: inline-flex; }
  .message-image { max-width: 75vw; }

  /* --- Header compaction: prevent right-edge overflow on narrow screens --- */
  .chat-header {
    gap: 4px;
    padding: 8px 6px;
    overflow: hidden; /* safety net — nothing should bleed past viewport */
  }
  .brand-sep { display: none; }
  .brand { font-size: 0.9rem; flex: 0 0 auto; }
  .brand-logo { width: 22px; height: 22px; }

  /* Title takes remaining space, ellipsis when too long, replaces old spacer */
  .chat-header .chat-title {
    font-size: 0.95rem;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
  }
  .chat-header .chat-title #current-channel-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .chat-header-spacer { display: none; }
  /* Hide channel search on mobile (header has no room). Use /search slash
     command from the composer instead. */
  .header-search { display: none; }

  /* Member count: icon only (drop the number), tighter padding */
  .members-btn { padding: 6px 6px; }
  .members-btn #member-count { display: none; }

  /* User button collapses to avatar + chevron only — display name is hidden.
     Tapping it still opens the dropdown; name is shown in the dropdown. */
  .user-btn {
    padding: 2px 4px 2px 2px;
    flex: 0 0 auto;
    min-width: 0;
  }
  .user-btn #user-menu-name { gap: 0; }
  .user-btn #user-menu-name > span:not(.avatar) { display: none; }
  .user-btn .avatar { width: 28px; height: 28px; font-size: 0.75rem; }

  /* Header has overflow:hidden as a safety net, which would clip an
     absolutely-positioned dropdown. Pin it to the viewport instead. */
  .dropdown {
    position: fixed;
    top: 52px;
    right: 8px;
    z-index: 200;
  }

  /* --- Composer compaction: narrower Send, tighter icon buttons --- */
  .composer { padding: 8px 6px 10px; gap: 6px; }
  .composer .primary-btn { padding: 10px 14px; font-size: 0.9rem; }
  .composer .icon-btn { padding: 6px 6px; }
  #sidebar-backdrop {
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 25;
  }
}
#sidebar-backdrop { display: none; }
@media (max-width: 720px) {
  #sidebar-backdrop:not([hidden]) { display: block; }
}

/* ==== Lucide line icons ==== */
.icon {
  display: inline-block;
  vertical-align: middle;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  stroke-width: 2;
}
button > .icon { pointer-events: none; }
h2 > .icon, h3 > .icon { margin-right: 6px; }
.pinned-toggle { display: inline-flex; align-items: center; gap: 6px; }

/* ==== Long-press tooltip (mobile-friendly `title` replacement) ==== */
.longpress-tooltip {
  position: absolute;
  z-index: 400;
  max-width: min(80vw, 280px);
  padding: 6px 10px;
  background: color-mix(in srgb, var(--accent-2) 92%, #000);
  color: #fff;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  white-space: normal;
  word-break: break-word;
}

/* =====================================================================
   Modern polish — conservative: only hover/active feedback, focus rings,
   and softer dialog styling. No backdrop-filter, no global selectors,
   no message animations (those interfered with the dropdown layout).
   ===================================================================== */

/* Buttons: tactile press + glow on primary */
.primary-btn, .secondary-btn, .icon-btn, .reaction-pill {
  transition: background 0.18s ease, color 0.18s ease,
              border-color 0.18s ease, transform 0.08s ease,
              box-shadow 0.18s ease, opacity 0.18s ease;
}
.primary-btn:active, .secondary-btn:active,
.icon-btn:active, .reaction-pill:active { transform: scale(0.96); }

.primary-btn {
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 26%, transparent);
}
.primary-btn:hover {
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 36%, transparent);
  transform: translateY(-1px);
}

/* Focus rings — brand-colored, clearly visible but soft */
:where(button, a, input, textarea, summary, [role="button"]):focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 75%, transparent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Messages: gentle hover background (no animation — it broke dropdowns) */
.message { transition: background 0.16s ease; }
.message:hover {
  background: color-mix(in srgb, var(--accent-soft) 55%, transparent);
}

/* Dialog / modal: refined border + shadow (no backdrop-filter) */
dialog {
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: 0 24px 60px color-mix(in srgb, var(--accent-2) 18%, transparent),
              0 2px 8px var(--shadow-color);
}

/* Reduced motion — respect user preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* Maintenance banner — shown when config/maintenance.active is true.
   Stays in normal flow at the top of <body> so the screens (which use
   height:100dvh) need to shrink to make room. The sibling selector below
   reclaims that space. */
.maintenance-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(90deg, #ff9900, #ff6600);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  min-height: 40px;
}
.maintenance-banner[hidden] { display: none !important; }
.maintenance-banner .maintenance-icon {
  font-size: 18px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
}
/* When the banner is visible, every following screen loses its banner-height
   from the viewport so the composer at the bottom stays visible. */
.maintenance-banner:not([hidden]) ~ .screen {
  height: calc(100dvh - 44px);
}
.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  cursor: pointer;
  font-weight: 500;
}
.toggle-row input[type="checkbox"] {
  width: auto;
  margin: 0;
}
