/* ============ Telecord — Discord x Telegram hybrid theme ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Discord Dark theme — exact tokens from the change spec (section 2.1) */
  --bg-darkest: #1e1f22;   /* server rail, user panel */
  --bg-dark: #2b2d31;      /* channel sidebar, member list */
  --bg-mid: #313338;       /* main chat */
  --bg-light: #383a40;     /* message input, search */
  --bg-hover: #393c41;     /* message row hover */
  --bg-active: #404249;    /* selected channel */
  --text: #dbdee1;         /* message text */
  --text-muted: #949ba4;   /* timestamps, inactive channels */
  --text-header: #f2f3f5;  /* usernames, headers, unread */
  --text-faint: #80848e;
  --blurple: #5865f2;
  --blurple-hover: #4752c4;
  --telegram: #00a8fc;     /* link color */
  --green: #23a559;
  --yellow: #f0b232;
  --red: #da373c;
  --red-hover: #a12829;
  --mention-bg: rgba(240,178,50,.1);
  --mention-border: #f0b232;
  --radius: 8px;
  /* gg sans → Noto Sans / Inter fallback stack (spec 2.2) */
  --font: "gg sans", "Noto Sans", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg-mid);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }

/* ---------------------------- scrollbars ---------------------------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #1a1b1e; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------- auth screen --------------------------- */
#startup-screen {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: var(--bg-darkest); padding: 24px;
}
.startup-content { width: 100%; max-width: 380px; text-align: center; }
.startup-logo { display: block; margin: 0 auto 24px; border-radius: 20px; }
#startup-title { font-size: 20px; line-height: 1.4; font-weight: 600; color: var(--text-header); }
#startup-detail { margin-top: 8px; color: var(--text); font-size: 16px; line-height: 1.5; }
#startup-progress { display: flex; justify-content: center; gap: 6px; margin-top: 24px; animation: message-loading-pulse 1.6s ease-in-out infinite; }
#startup-progress span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); }
#startup-retry { margin-top: 24px; min-height: 44px; }
#connection-banner { position: fixed; inset: 0 0 auto; z-index: 101; min-height: 56px; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 6px 12px; background: var(--bg-dark); }
#connection-detail { font-size: 14px; line-height: 20px; min-width: 0; }
#connection-retry { min-height: 44px; flex-shrink: 0; }
body.connection-lost #app { height: calc(100dvh - 56px); margin-top: 56px; }
@media (prefers-reduced-motion: reduce) { #startup-progress { animation: none; } }
#auth-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e1f22 0%, #2b2d4a 50%, #1e2a3a 100%);
  padding: 16px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--bg-dark);
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo-mark {
  display: block; width: 80px; height: 80px; margin: 0 auto 12px;
  border-radius: 20px; object-fit: contain;
}
.rail-brand { display: block; width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
/* Original artwork joins once on refresh; navigation remains immediate. */
#brand-intro {
  position: fixed; inset: 0; z-index: 1000; pointer-events: none;
  display: grid; place-items: center; background: #0b0722;
  animation: brand-dismiss 760ms ease-out both;
}
#brand-intro[hidden] { display: none; }
.brand-assembly { position: relative; width: min(200px, 48vw); aspect-ratio: 1; }
.brand-assembly img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 20%; }
.brand-piece { animation: brand-join 520ms cubic-bezier(.16, 1, .3, 1) both; }
.brand-piece-first { clip-path: polygon(0 0, 100% 0, 0 100%); --join-x: -18%; --join-y: -12%; --join-turn: -8deg; }
.brand-piece-second { clip-path: polygon(100% 0, 100% 100%, 0 100%); --join-x: 18%; --join-y: 12%; --join-turn: 8deg; }
.brand-complete { animation: brand-seal 520ms linear both; }
@keyframes brand-join {
  from { opacity: 0; transform: translate(var(--join-x), var(--join-y)) rotate(var(--join-turn)) scale(.96); }
  to { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
}
@keyframes brand-seal { 0%, 75% { opacity: 0; } 100% { opacity: 1; } }
@keyframes brand-dismiss { 0%, 74% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  #brand-intro { display: none; animation: none; }
  .brand-assembly img { animation: none; }
}
.auth-logo h1 { font-size: 26px; color: #fff; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.auth-tab {
  flex: 1; padding: 10px; border-radius: var(--radius);
  background: var(--bg-darkest); color: var(--text-muted); font-size: 14px; font-weight: 600;
}
.auth-tab.active { background: var(--blurple); color: #fff; }
#auth-form label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 14px; }
#auth-form input {
  display: block; width: 100%; margin-top: 6px;
  background: var(--bg-darkest); border: 1px solid transparent; border-radius: var(--radius);
  color: var(--text); padding: 11px 12px; font-size: 16px; outline: none; /* 16px stops iOS focus-zoom */
}
#auth-form input:focus { border-color: var(--telegram); }
.auth-error { background: rgba(218,55,60,.15); color: #f28b8e; border-radius: var(--radius); padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }

/* ------------------------------ buttons ----------------------------- */
.btn {
  padding: 10px 18px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; transition: background .15s;
}
.btn-primary { background: var(--blurple); color: #fff; }
.btn-primary:hover { background: var(--blurple-hover); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: var(--red-hover); }
.btn-ghost { background: var(--bg-light); color: var(--text); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-block { display: block; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 6px; color: var(--text-muted);
  cursor: default;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.shell-icon { display: block; flex: none; }
/* Native-style arrow on icon controls; inputs keep their text cursor. */
#scroll-bottom, .avatar, .emoji-tabs button, .emoji-grid button, .react-quick button {
  cursor: default;
}
button:focus-visible { outline: 2px solid var(--telegram); outline-offset: 2px; }

/* ------------------------------ layout ------------------------------ */
#app { display: flex; height: 100dvh; }
#left-wrap { display: flex; flex-shrink: 0; height: 100%; }

/* rail */
#rail {
  width: 72px; background: var(--bg-darkest);
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 12px 0; gap: 8px; overflow-y: auto; overflow-x: hidden; flex-shrink: 0;
}
/* Anchor icons to the rail's left edge, not its scrollbar-dependent content width. */
#rail > .rail-item, #rail-servers > .rail-item { margin-left: 12px; }
#rail > .rail-divider { margin-left: 20px; }
#rail-servers { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; width: 100%; flex-shrink: 0; }
.rail-item {
  cursor: default;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--bg-mid); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 17px;
  transition: border-radius .2s, background .2s;
  position: relative; flex-shrink: 0;
}
.rail-item:hover, .rail-item.active { border-radius: 16px; }
.rail-home { color: var(--telegram); }
.rail-home:hover, .rail-home.active { background: var(--telegram); color: #142533; }
.rail-add { color: var(--green); font-size: 26px; font-weight: 400; }
.rail-add:hover { background: var(--green); color: #fff; border-radius: 16px; }
.rail-item .pill {
  position: absolute; left: -12px; top: 50%;
  width: 4px; height: 40px; border-radius: 0 4px 4px 0; background: #fff; pointer-events: none;
  transform: translateY(-50%) scaleY(0); transition: transform .15s ease-out;
}
.rail-item.active .pill { transform: translateY(-50%) scaleY(1); }
.rail-item.unread:not(.active) .pill { transform: translateY(-50%) scaleY(.2); }
.rail-server-icon { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.unread-badge { background: #b72c36; color: #fff; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1; }
.rail-unread-count { position: absolute; right: -2px; bottom: -2px; z-index: 2; min-width: 20px; height: 20px; border: 2px solid var(--bg-darkest); pointer-events: none; }
.rail-folder-button .rail-unread-count { top: -2px; bottom: auto; }
.rail-divider { width: 32px; height: 2px; background: var(--bg-mid); border-radius: 1px; flex-shrink: 0; }
.rail-folder { display: flex; flex-direction: column; align-items: center; gap: 7px; width: 56px; margin-left: 8px; padding: 4px 0 7px; border-radius: 16px; flex-shrink: 0; }
.rail-folder.expanded { background: color-mix(in srgb, var(--folder-color) 14%, var(--bg-darkest)); }
.rail-folder-button { width: 48px; height: 48px; position: relative; display: grid; place-items: center; border-radius: 15px; background: color-mix(in srgb, var(--folder-color) 25%, var(--bg-darkest)); color: var(--text-header); flex-shrink: 0; touch-action: pan-y; }
.rail-folder-button:hover, .rail-folder-button.active { background: color-mix(in srgb, var(--folder-color) 38%, var(--bg-darkest)); }
.rail-folder-button:active { transform: scale(.96); }
.rail-folder.expanded .rail-folder-button { color: var(--folder-color); background: transparent; }
.rail-folder-mark { position: absolute; right: -2px; bottom: -2px; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 5px; background: var(--bg-darkest); color: var(--folder-color); }
.rail-folder-label { display: block; width: 56px; font-size: 10px; font-weight: 600; line-height: 1.3; text-align: center; color: #b5bac1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-folder-button .pill { position: absolute; left: -12px; top: 50%; width: 4px; height: 40px; border-radius: 0 4px 4px 0; background: #fff; pointer-events: none; transform: translateY(-50%) scaleY(0); }
.rail-folder-button.active .pill { transform: translateY(-50%) scaleY(1); }
.rail-folder-button.unread:not(.active) .pill { transform: translateY(-50%) scaleY(.2); }
.rail-folder-grid { display: grid; grid-template-columns: repeat(2, 17px); grid-template-rows: repeat(2, 17px); gap: 2px; }
.rail-folder-mini { display: grid; place-items: center; border-radius: 5px; overflow: hidden; font-size: 10px; font-weight: 700; color: #fff; background: var(--bg-active); }
.rail-folder-mini img { width: 100%; height: 100%; object-fit: cover; }
.rail-folder-children { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.rail-item[data-rail-id] { touch-action: pan-y; -webkit-touch-callout: none; user-select: none; }
.rail-folder-button { -webkit-touch-callout: none; user-select: none; }
.rail-drag-ghost { position: fixed; left: 0; top: 0; z-index: 400; pointer-events: none; opacity: .92; box-shadow: 0 8px 20px rgba(0,0,0,.35); }
.rail-drag-ghost .pill, .rail-drag-ghost .red-dot, .rail-drag-ghost .rail-unread-count { display: none; }
.rail-item[draggable=true], .rail-folder-button { cursor: default; }
.rail-dragging { opacity: .42; }
.rail-drop-target { outline: 2px solid var(--blurple); outline-offset: 3px; }
.rail-drop-target[data-drop-position=before]::before, .rail-drop-target[data-drop-position=after]::after { content: ''; position: absolute; left: 0; right: 0; height: 3px; background: var(--blurple); border-radius: 2px; }
.rail-drop-target[data-drop-position=before]::before { top: -7px; }
.rail-drop-target[data-drop-position=after]::after { bottom: -7px; }
.rail-drop-target[data-drop-position=before], .rail-drop-target[data-drop-position=after] { outline: none; }
.rail-context-title { padding: 7px 10px; color: var(--text-header); font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 230px; }
.rail-context-menu button { min-height: 40px; color: #b5bac1; }
.rail-context-menu hr { border: 0; border-top: 1px solid var(--bg-light); margin: 5px 6px; }
.folder-server-choices { max-height: min(48dvh, 360px); overflow-y: auto; margin: 12px 0; }
.folder-server-choice { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 4px; }
.folder-server-choice span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-color-control { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.folder-color-control input { width: 48px; height: 40px; padding: 3px; border: 0; border-radius: 6px; background: var(--bg-light); }
.modal.organize-dialog { max-width: 650px; }
.organize-create { display: inline-flex; align-items: center; gap: 7px; }
.organize-new-form { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.organize-new-form.hidden { display: none; }
.organize-new-form input, .organize-new-form select { min-width: 0; flex: 1; }
.organize-list { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.organize-row, .organize-folder-heading { display: flex; align-items: center; gap: 7px; min-height: 50px; padding: 6px 8px; border-radius: 8px; background: var(--bg-mid); }
.organize-folder { display: flex; flex-direction: column; gap: 5px; padding: 5px; border-radius: 10px; background: var(--bg-darkest); }
.organize-folder .organize-row { margin-left: 12px; }
.organize-folder-heading { background: transparent; }
.organize-avatar { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 10px; font-size: 11px; font-weight: 700; overflow: hidden; }
.organize-avatar img { width: 100%; height: 100%; object-fit: cover; }
.organize-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.organize-small { min-width: 35px; height: 34px; padding: 0 6px; border-radius: 6px; color: #d3d5da; background: var(--bg-active); font-size: 12px; }
.organize-small:hover:not(:disabled) { color: var(--text); background: var(--bg-hover); }
.organize-small:disabled { opacity: .4; cursor: default; }
.organize-row select, .organize-new-form select { max-width: 115px; min-height: 34px; border-radius: 6px; border: 1px solid var(--bg-active); background: var(--bg-darkest); color: var(--text); font: inherit; font-size: 12px; }
.organize-folder-heading input[type=text] { min-width: 0; flex: 1; margin: 0; padding: 7px; font-size: 13px; }
.organize-folder-heading input[type=color] { width: 30px; height: 30px; flex: none; border: 0; padding: 0; background: transparent; cursor: pointer; }
@media (max-width: 520px) {
  .organize-new-form { flex-wrap: wrap; }
  .organize-new-form > * { flex: 1 1 45%; }
  .organize-row, .organize-folder-heading { flex-wrap: wrap; }
  .organize-row .organize-name { flex: 1 1 calc(100% - 45px); }
  .organize-folder-heading input[type=text] { flex: 1 1 calc(100% - 45px); }
  .organize-row select { flex: 1 1 95px; max-width: none; min-height: 40px; }
  .organize-small { min-width: 44px; height: 40px; padding: 0 4px; }
}

/* sidebar */
#sidebar {
  width: 240px; background: var(--bg-dark);
  display: flex; flex-direction: column; flex-shrink: 0;
}
#sidebar-header {
  padding: 0; color: #fff;
  border-bottom: 1px solid rgba(0,0,0,.24);
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
  display: flex; align-items: center;
  min-height: 48px;
}
/* Discord-style clickable server header: name + chevron, full-width, hover tint */
.server-header-btn {
  min-width: 0;
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 0 16px; align-self: stretch; cursor: pointer;
  font-weight: 700; font-size: 16px; color: var(--text-header);
  transition: background .1s;
}
.server-header-btn:hover { background: var(--bg-hover); }
.server-invite-btn { flex: 0 0 40px; height: 44px; display: grid; place-items: center; color: var(--text-muted); }
.server-invite-btn:hover { color: var(--text-header); background: var(--bg-hover); }
.channel-draft { margin-left: auto; color: var(--yellow); font-size: 11px; font-weight: 600; }
.dm-item-name .dm-preview.has-draft { color: var(--yellow); }
.server-header-btn .shb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.header-chevron { color: var(--text-muted); display: inline-flex; align-items: center; flex-shrink: 0; }
.server-locked-icon { display: inline-flex; align-items: center; color: var(--text-muted); }
/* DM-home header: "Direct Messages" label (fills) + Explore chip on the right */
#sidebar-header > .sidebar-title { flex: 1; min-width: 0; padding: 14px 16px; font-weight: 700; font-size: 15px; }
.dm-mobile-menu, .server-mobile-menu { display: none; }
#sidebar-header .invite-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  background: var(--bg-darkest); padding: 4px 8px; border-radius: 6px; cursor: pointer;
  white-space: nowrap; margin-right: 12px; flex-shrink: 0;
}
#sidebar-header .invite-chip:hover { color: var(--text); }
#sidebar-content { flex: 1; overflow-y: auto; padding: 10px 8px; }
#sidebar-content.server-channel-list { padding-top: 12px; }
.sidebar-empty { padding: 12px 8px; font-size: 13px; line-height: 1.45; color: var(--text-muted); }

.sidebar-section {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-muted);
  padding: 8px 8px 4px;
}
.sidebar-section button { color: var(--text-muted); line-height: 1; }
.sidebar-section button:hover { color: var(--text); }
.section-actions { display: inline-flex; align-items: center; gap: 2px; }
.section-actions button { width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; border-radius: 5px; }
.section-actions button:hover { background: var(--bg-hover); }

.list-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 7px 8px; border-radius: 6px; margin-bottom: 1px;
  color: var(--text-muted); font-size: 15px; position: relative;
}
.list-item:hover { background: var(--bg-hover); color: var(--text); }
.list-item.active { background: var(--bg-active); color: #fff; }
.channel-row .list-item.unread { color: var(--text-header); font-weight: 600; }
.list-item .hash { display: inline-flex; align-items: center; color: var(--text-muted); flex-shrink: 0; }
.list-item.active .hash { color: var(--text-header); }
.channel-row { position: relative; margin-bottom: 2px; }
.channel-row .list-item { height: 34px; gap: 8px; padding: 5px 8px; margin: 0; }
.channel-row .channel-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-with-threads { position: relative; }
.channel-dragging { opacity: .45; }
.channel-drop-before::before, .channel-drop-after::after {
  content: ''; position: absolute; left: 4px; right: 4px; height: 2px;
  background: var(--blurple); border-radius: 1px; pointer-events: none; z-index: 2;
}
.channel-drop-before::before { top: -2px; }
.channel-drop-after::after { bottom: -2px; }
.channel-drop-category { outline: 2px solid var(--blurple); outline-offset: -2px; border-radius: 4px; }
.channel-move-page select {
  display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 44px;
  padding: 10px 12px; border: 1px solid var(--bg-active); border-radius: var(--radius);
  background: var(--bg-darkest); color: var(--text); color-scheme: dark; font: inherit; font-size: 16px;
}
.channel-move-page select:focus-visible { outline: 2px solid var(--telegram); outline-offset: 2px; }
.server-channel-list .list-item, .server-channel-list .category-header { -webkit-touch-callout: none; user-select: none; }
.list-item .del {
  margin-left: auto; opacity: 0; font-size: 13px; color: var(--text-muted); padding: 2px 4px;
}
.list-item:hover .del { opacity: 1; }
.list-item .del:hover { color: var(--red); }
.list-item .badge {
  margin-left: auto; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.list-item .unread-badge { background: #b72c36; flex-shrink: 0; }
.dm-item-name { flex: 1; min-width: 0; }
.dm-item-name .dm-username { display: flex; align-items: center; gap: 6px; color: inherit; }
.dm-username-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-username .bot-tag, .dm-item-name + .badge { flex-shrink: 0; }
.dm-item-name .dm-preview {
  display: block; font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px;
}

/* avatars */
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px; position: relative;
}
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.avatar.lg { width: 40px; height: 40px; font-size: 16px; }
.avatar.img { background-size: cover !important; background-position: center; }
.avatar .status-dot {
  position: absolute; bottom: -2px; right: -2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #80848e; border: 3px solid var(--bg-dark);
}
.avatar .status-dot.online { background: var(--green); }
.bot-tag {
  background: var(--blurple); color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 4px; text-transform: uppercase; flex-shrink: 0;
}

/* user panel */
#user-panel {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: #232428;
}
.user-panel-name { flex: 1; min-width: 0; }
#user-panel-username { font-size: 14px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-panel-status { font-size: 11px; color: var(--text-muted); }
.user-panel-status.reconnecting { color: var(--yellow); }

/* DM account access lives beside Explore; server/master footers stay intact. */
#app.dm-home #user-panel { display: none; }
.dm-profile-button { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; height: 44px; margin-right: 4px; border-radius: 8px; }
.dm-profile-button:hover { background: var(--bg-hover); }
.dm-profile-button:active { transform: scale(.97); }
#app.dm-home #sidebar-header > .sidebar-title { padding: 4px 8px; line-height: 1.2; }
#app.dm-home #sidebar-header .invite-chip { flex-shrink: 0; margin-right: 0; padding-left: 6px; padding-right: 6px; }
.account-logout { color: var(--red); margin-top: 16px; display: block; }

/* main chat */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-mid); }
#chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px; border-bottom: 1px solid var(--bg-darkest);
  min-height: 48px;
}
#chat-title { font-weight: 700; font-size: 16px; color: #fff; display: flex; align-items: center; gap: 8px; min-width: 0; }
#chat-title .hash { display: inline-flex; align-items: center; color: var(--text-muted); flex-shrink: 0; }
#chat-title .chat-title-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-title .sub { font-size: 12px; font-weight: 400; color: var(--text-muted); }
.header-spacer { flex: 1; }
.mobile-only { display: none !important; }
#btn-search.active, #btn-pins.active { background: var(--bg-active); color: var(--text-header); }
.chat-discovery { background: var(--bg-dark); border-bottom: 1px solid var(--bg-darkest); padding: 12px 16px 14px; }
.discovery-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.discovery-head h2 { font-size: 15px; font-weight: 700; color: var(--text-header); }
#discovery-form { display: flex; gap: 8px; }
#discovery-query { min-width: 0; flex: 1; background: var(--bg-light); border: 1px solid var(--bg-active); border-radius: 8px; color: var(--text); padding: 9px 11px; font-size: 16px; outline: none; }
#discovery-query:focus { border-color: var(--telegram); }
.discovery-results { max-height: min(36vh, 300px); overflow-y: auto; margin-top: 10px; }
.discovery-note { color: var(--text-muted); font-size: 13px; line-height: 1.45; padding: 10px 2px; }
.discovery-result { display: block; width: 100%; text-align: left; border-radius: 7px; padding: 9px 10px; border: 1px solid transparent; }
.discovery-result:hover, .discovery-result:focus-visible { background: var(--bg-hover); border-color: var(--bg-active); outline: none; }
.discovery-result-head { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.thread-result-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#discovery-title { min-width: 0; overflow-wrap: anywhere; }
.discovery-result-head > svg { flex-shrink: 0; }
.discovery-result-author { color: var(--text-header); font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.discovery-result-time { color: var(--text-muted); font-size: 11px; white-space: nowrap; margin-left: auto; }
.discovery-result-content { color: var(--text); font-size: 13px; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
@media (max-width: 600px) { .chat-discovery { padding: 10px 12px; } .discovery-results { max-height: 30vh; } .discovery-result { padding: 9px 6px; } }

.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; }
.chat-empty.admin-view { min-height: 0; align-items: stretch; overflow-y: auto; }
.chat-empty-inner { text-align: center; color: var(--text-muted); padding: 20px; }
.chat-empty-logo {
  display: block; width: 96px; height: 96px; margin: 0 auto 16px;
  border-radius: 24px; object-fit: contain;
}
.chat-empty-inner h2 { color: #fff; margin-bottom: 6px; }

#messages { flex: 1; overflow-y: auto; overscroll-behavior: contain; overflow-anchor: none; padding: 16px 0 8px; }
#messages:focus-visible { outline: 2px solid var(--telegram); outline-offset: -2px; }
#messages.empty-channel { display: flex; flex-direction: column; }
.channel-welcome { margin-top: auto; padding: 24px 24px 32px; flex-shrink: 0; }
.channel-welcome-icon { display: grid; place-items: center; width: 80px; height: 80px; border-radius: 50%; background: var(--bg-light); color: var(--text-header); margin-bottom: 20px; }
.channel-welcome h2 { color: var(--text-header); font-size: clamp(26px, 3vw, 36px); line-height: 1.2; font-weight: 800; overflow-wrap: anywhere; margin-bottom: 12px; }
.channel-welcome p { font-size: 16px; line-height: 1.5; overflow-wrap: anywhere; max-width: 65ch; }
.channel-welcome-actions, .channel-welcome-access { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.channel-welcome-actions .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; white-space: normal; }
.channel-welcome-member { display: grid; place-items: center; min-width: 44px; min-height: 44px; border-radius: var(--radius); }
.channel-welcome-member:hover { background: var(--bg-hover); }
.channel-welcome-role { display: inline-flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--bg-active); background: var(--bg-light); border-radius: var(--radius); max-width: 100%; font-size: 14px; }
.channel-welcome-role span:last-child { overflow-wrap: anywhere; min-width: 0; }
.channel-welcome-role-dot { width: 10px; height: 10px; flex-shrink: 0; border-radius: 50%; background: var(--text); }
.channel-welcome-more { font-size: 14px; }
@media (max-width: 820px) { .channel-welcome { padding: 20px 16px 24px; } .channel-welcome-icon { width: 68px; height: 68px; } }
.messages-status { margin: 16px; color: var(--text-muted); font-size: 14px; }
.messages-status .btn { margin-top: 12px; }
.messages-loading { height: 100%; overflow: hidden; pointer-events: none; }
.messages-skeleton { padding: 8px 16px; animation: message-loading-pulse 1.6s ease-in-out infinite; }
.skeleton-row { display: flex; gap: 16px; margin-bottom: 24px; }
.skeleton-avatar { width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%; background: var(--bg-active); }
.skeleton-body { flex: 1; min-width: 0; }
.skeleton-name, .skeleton-line { height: 16px; border-radius: var(--radius); background: var(--bg-active); }
.skeleton-name { width: 112px; max-width: 45%; margin: 2px 0 10px; }
.skeleton-line { width: 72%; max-width: 440px; margin-bottom: 8px; }
.skeleton-line-short { width: 42%; max-width: 240px; }
.skeleton-row:nth-child(even) .skeleton-line { width: 58%; }
.skeleton-row:nth-child(even) .skeleton-line-short { width: 34%; }
.skeleton-attachment { width: 100%; max-width: 360px; height: 160px; margin-top: 12px; border-radius: var(--radius); background: var(--bg-light); }
@keyframes message-loading-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
#app.hidden .messages-skeleton, #messages.hidden .messages-skeleton { animation-play-state: paused; }
@media (prefers-reduced-motion: reduce) { .messages-skeleton { animation: none; opacity: .8; } }
@media (max-width: 820px) {
  .messages-skeleton { padding: 8px 12px; }
  .skeleton-row { gap: 12px; }
  .skeleton-avatar { width: 36px; height: 36px; }
  .skeleton-attachment { height: 136px; }
}
#load-history, #load-newer-history {
  display: block; margin: 4px auto 12px; padding: 7px 14px;
  border-radius: 6px; color: var(--text-header); background: var(--bg-light);
  font-size: 13px; font-weight: 600; min-height: 44px;
}
#history-loading { height: 208px; overflow: hidden; }
.history-skeleton .skeleton-row:last-child { margin-bottom: 0; }
.history-loading-error { height: 100%; display: grid; place-items: center; padding: 16px; }
#load-history { margin: 0; white-space: normal; }
#load-history:hover { background: var(--bg-active); }
#load-history:focus-visible { outline: 2px solid var(--telegram); outline-offset: 2px; }
#load-history:disabled { opacity: .65; cursor: wait; }
#load-newer-history:hover { background: var(--bg-active); }
#load-newer-history:focus-visible { outline: 2px solid var(--telegram); outline-offset: 2px; }
#load-newer-history:disabled { opacity: .65; cursor: wait; }

/* ------------------- chat bubbles (Telegram-style) ------------------- */
/* Each day's messages live in their own .day-group so the divider sticks
   only while that day is on screen, then scrolls away as the next day starts. */
.day-group { position: relative; }
/* Discord-style date separator: a hairline rule across the width with the date
   centered. Inline boundary marker (scrolls with content); the floating pill
   (#float-date) is what stays pinned at the top while scrolling. */
.day-divider {
  display: flex; align-items: center; gap: 0;
  margin: 20px 16px 8px; pointer-events: none;
}
.day-divider::before, .day-divider::after {
  content: ''; flex: 1; height: 1px; background: rgba(255,255,255,.08);
}
.day-divider span {
  flex-shrink: 0; color: var(--text-muted);
  font-size: 12px; font-weight: 700; padding: 2px 16px; white-space: nowrap;
  background: var(--bg-mid); border-radius: 8px; letter-spacing: .2px;
}
/* ============ Flat Discord-style message rows (no bubbles) ============ */
.msg-row {
  position: relative; display: flex; gap: 16px;
  padding: 2px 48px 2px 16px;
}
.msg-row:hover { background: var(--bg-hover); }
.msg-row:not(.compact) { margin-top: 16px; }
.pinned-label { display: inline-block; color: var(--yellow); font-size: 11px; font-weight: 700; margin-bottom: 2px; }
.msg-row.flash { animation: flashHi 1.4s ease; }
@keyframes flashHi { 0%, 55% { background: rgba(88,101,242,.24); } 100% { background: transparent; } }

.msg-gutter { width: 40px; flex-shrink: 0; display: flex; justify-content: center; }
.msg-gutter .avatar { width: 40px; height: 40px; font-size: 16px; margin-top: 2px; cursor: default; }
.gutter-time { font-size: 10px; color: var(--text-faint); opacity: 0; margin-top: 5px; white-space: nowrap; user-select: none; }
.msg-row.compact:hover .gutter-time { opacity: 1; }

.msg-main { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-username { font-size: 16px; font-weight: 600; color: var(--text-header); cursor: pointer; }
.msg-username:hover { text-decoration: underline; }
.msg-ts { font-size: 12px; color: var(--text-faint); font-weight: 500; }
.msg-content { font-size: 16px; line-height: 1.375; color: var(--text); white-space: pre-wrap; word-wrap: break-word; }
.msg-content:empty { display: none; }
.msg-tick { font-size: 12px; color: var(--text-faint); margin-left: 6px; letter-spacing: -2px; }
.msg-tick.delivered { color: var(--telegram); }
.edited-tag { font-size: 10px; color: var(--text-faint); margin-left: 4px; }
.msg-image {
  max-width: min(100%, 440px); max-height: 350px; border-radius: 8px;
  display: block; cursor: pointer; margin: 4px 0 2px;
}

/* rich text */
.forward-head { font-size: 12.5px; color: var(--text-muted); font-style: italic; margin-bottom: 1px; }
.forward-head b { color: var(--text); font-style: normal; }
.msg-content.jumbo { font-size: 44px; line-height: 1.15; }
.msg-content a.msg-link { color: var(--telegram); text-decoration: none; word-break: break-word; }
.msg-content a.msg-link:hover { text-decoration: underline; }
.msg-content strong { font-weight: 700; }
.msg-content em { font-style: italic; }
.msg-content s { opacity: .75; }
.msg-content .code-inline {
  font-family: ui-monospace, Menlo, monospace; font-size: 13px;
  background: rgba(0,0,0,.28); border-radius: 4px; padding: 1px 5px;
}
.msg-content .code-block {
  font-family: ui-monospace, Menlo, monospace; font-size: 13px;
  background: rgba(0,0,0,.32); border-radius: 8px; padding: 8px 10px;
  margin: 4px 0; white-space: pre-wrap; word-break: break-word; overflow-x: auto;
}
.msg-content .mention {
  background: rgba(88,101,242,.28); color: #cdd2ff; border-radius: 4px;
  padding: 0 3px; font-weight: 600; cursor: pointer;
}
.msg-content .mention.mention-me { background: rgba(250,166,26,.28); color: #ffd891; }
.msg-content .spoiler {
  background: #1a1b1e; color: transparent; border-radius: 4px; padding: 0 4px;
  cursor: pointer; transition: color .15s; user-select: none;
}
.msg-content .spoiler.revealed { background: rgba(0,0,0,.28); color: inherit; user-select: text; }

/* Discord reply preview above the row (spine connecting to the avatar) */
.msg-row.has-reply {
  --reply-avatar-size: 40px; --reply-gap: 16px;
  display: grid; grid-template-columns: var(--reply-avatar-size) minmax(0, 1fr);
  column-gap: var(--reply-gap); row-gap: 0;
}
.msg-row.has-reply > .msg-gutter { grid-column: 1; grid-row: 2; }
.msg-row.has-reply > .msg-main { grid-column: 2; grid-row: 2; }
.reply-quote {
  display: flex; align-items: center; gap: 6px; position: relative;
  grid-column: 2; grid-row: 1; min-width: 0; width: 100%; max-width: 100%;
  margin: 0 0 4px; padding: 0; height: 20px; text-align: left;
  font-size: 12px; line-height: 20px; color: var(--text-muted); cursor: pointer;
}
.reply-quote::before {
  content: ''; position: absolute; top: 10px; bottom: -4px;
  left: calc(-.5 * var(--reply-avatar-size) - var(--reply-gap));
  width: calc(.5 * var(--reply-avatar-size) + var(--reply-gap) - 4px);
  border-left: 2px solid var(--text-faint); border-top: 2px solid var(--text-faint);
  border-top-left-radius: 6px; pointer-events: none;
}
.reply-quote .rq-avatar { width: 16px; height: 16px; flex-shrink: 0; font-size: 9px; }
.reply-quote .rq-author { font-weight: 600; flex-shrink: 0; max-width: 40%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-quote .rq-snippet { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-quote:hover .rq-snippet, .reply-quote:hover .rq-author { color: var(--text-header); }
.reply-quote:focus-visible { outline-offset: 1px; border-radius: 3px; }
.msg-row.has-reply .msg-toolbar { top: -34px; }

/* reactions (Discord pill chips) */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,.04); border: 1px solid transparent;
  border-radius: 8px; padding: 2px 8px; font-size: 15px; cursor: default; transition: .1s;
}
.reaction-chip .rcount { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.reaction-chip.mine { border-color: var(--blurple); background: rgba(88,101,242,.15); }
.reaction-chip.mine .rcount { color: #c9cdfb; }
.reaction-chip:hover { border-color: var(--text-faint); }
.reaction-tooltip {
  position: fixed; z-index: 1600; display: flex; align-items: center; gap: 14px;
  width: max-content; max-width: min(420px, calc(100vw - 16px));
  padding: 16px; background: var(--bg-light); color: var(--text);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.3);
  font-size: 15px; line-height: 1.4; overflow-wrap: anywhere;
}
.reaction-tooltip-emoji { flex: 0 0 auto; font-size: 40px; line-height: 1.2; }
.reaction-view {
  position: fixed; z-index: 1600; width: 360px; max-width: calc(100vw - 16px);
  max-height: min(560px, calc(100dvh - 16px)); display: flex; flex-direction: column;
  padding: 16px; background: var(--bg-dark); color: var(--text);
  border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.reaction-view-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reaction-view-header h2 { font-size: 18px; }
.reaction-view-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; max-height: 100px; overflow-y: auto; flex-shrink: 0; }
.reaction-view-tab { min-height: 44px; padding: 8px 12px; background: var(--bg-light); color: var(--text); border: 1px solid transparent; border-radius: 8px; font-size: 16px; }
.reaction-view-tab.active { border-color: var(--blurple); background: var(--bg-active); }
.reaction-view-count { margin-block: 12px 8px; font-size: 14px; color: var(--text-muted); }
.reaction-view-members { overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.reaction-view-member { display: flex; align-items: center; gap: 12px; min-height: 48px; padding-block: 6px; font-size: 16px; }
.reaction-view-member .avatar { flex: 0 0 auto; }
.reaction-view-member > span { min-width: 0; overflow-wrap: anywhere; }
@media (hover: none) { .reaction-chip { min-height: 44px; min-width: 44px; } }

/* floating hover toolbar — top-right of the row (Discord) */
.msg-toolbar {
  display: none; position: absolute; top: -16px; right: 12px; z-index: 3;
  background: var(--bg-dark); border: 1px solid rgba(0,0,0,.25); border-radius: 8px;
  padding: 1px; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
@media (hover: hover) and (pointer: fine) {
  /* One input mode owns the toolbar: pointer hover OR keyboard focus, never both.
     Keep focus-within for stable Tab traversal between toolbar buttons. */
  #messages:not(.keyboard-actions) .msg-row:hover .msg-toolbar,
  #messages.keyboard-actions .msg-row:focus-within .msg-toolbar { display: flex; visibility: visible; }
}
.msg-toolbar button { display: inline-flex; align-items: center; justify-content: center; width: 33px; height: 32px; border-radius: 5px; color: var(--text-muted); cursor: default; }
.msg-toolbar button:hover { background: var(--bg-hover); color: var(--text-header); }

/* Server conversations: reply spine above a flat, aligned message timeline. */
.channel-message { display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 16px; row-gap: 0; padding: 2px 20px 2px 16px; }
.channel-message > .msg-gutter { grid-column: 1; grid-row: 1; }
.channel-message > .msg-main { grid-column: 2; grid-row: 1; }
.channel-message .msg-head { min-height: 22px; gap: 7px; flex-wrap: wrap; }
.channel-message .msg-username { font-size: 15px; overflow-wrap: anywhere; }
.channel-message .msg-ts { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.channel-message .msg-content { font-size: 15px; line-height: 1.5; }
.channel-message .msg-content.jumbo { font-size: 44px; line-height: 1.15; }
.channel-message .msg-image { max-width: min(100%, 400px); max-height: 350px; object-fit: contain; object-position: left; border-radius: 6px; }
.channel-message.compact { min-height: 23px; }
.msg-row:focus-visible { outline: 2px solid var(--telegram); outline-offset: -2px; }
.channel-message .msg-toolbar { display: flex; visibility: hidden; top: -17px; right: 12px; padding: 2px; border-radius: 7px; }
.channel-message .msg-toolbar .delete-action { color: #f28b8e; }
.channel-message.compact:focus-within .gutter-time { opacity: 1; }
@media (max-width: 820px) {
  .msg-row.has-reply { --reply-gap: 12px; }
  .channel-message.has-reply { --reply-avatar-size: 36px; }
  .msg-row.channel-message { grid-template-columns: 36px minmax(0, 1fr); column-gap: 12px; padding: 2px 12px; }
  .channel-message .msg-gutter, .channel-message .msg-gutter .avatar { width: 36px; }
  .channel-message .msg-gutter .avatar { height: 36px; }
  .channel-message .msg-content { font-size: 16px; }
}
@media (hover: none), (pointer: coarse) {
  .msg-row .msg-toolbar { display: none; } /* long-press opens existing message actions */
}
.react-pop {
  position: absolute; top: -8px; right: 12px; z-index: 25;
  background: var(--bg-dark); border: 1px solid #1e1f22; border-radius: 10px;
  padding: 5px 8px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.react-pop.expanded { border-radius: 12px; }
.react-quick { display: flex; gap: 2px; }
.react-quick button { font-size: 20px; padding: 3px 5px; border-radius: 50%; transition: transform .1s; }
.react-quick button:hover { transform: scale(1.25); background: var(--bg-hover); }
.react-quick .react-expand { font-size: 16px; color: var(--text-muted); }

/* categorized emoji grid (reactions + composer picker) */
.react-full { width: 300px; margin-top: 6px; }
.emoji-tabs {
  display: flex; gap: 2px; padding-bottom: 6px; margin-bottom: 4px;
  border-bottom: 1px solid var(--bg-mid); overflow-x: auto;
}
.emoji-tabs::-webkit-scrollbar { height: 0; }
.emoji-tabs button {
  font-size: 17px; padding: 4px 6px; border-radius: 6px; flex-shrink: 0; opacity: .6;
}
.emoji-tabs button.active { opacity: 1; background: var(--bg-hover); }
.emoji-tabs button:hover { opacity: 1; }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 1px;
  max-height: 200px; overflow-y: auto;
}
.emoji-grid button { font-size: 21px; padding: 3px; border-radius: 6px; }
.emoji-grid button:hover { background: var(--bg-hover); transform: scale(1.15); }

/* red notification dots */
.red-dot {
  position: absolute; top: 2px; right: 2px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--red); border: 2px solid var(--bg-darkest); pointer-events: none;
}
#user-panel .icon-btn { position: relative; }
#user-panel .icon-btn .red-dot { border-color: #232428; }
.rail-item .red-dot, .rail-home .red-dot { border-color: var(--bg-darkest); }

/* image lightbox */
#lightbox {
  position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
#lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

/* server dropdown menu */
#sidebar-header { position: relative; }
.server-menu {
  position: absolute; top: calc(100% + 4px); left: 8px; right: 8px; z-index: 40;
  background: var(--bg-darkest); border-radius: 8px; padding: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.server-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 6px; font-size: 13.5px; color: var(--text-muted);
}
.server-menu button:hover { background: var(--blurple); color: #fff; }
.server-menu button .shell-icon { color: var(--text-muted); }
.server-menu button:hover .shell-icon { color: #fff; }
.server-menu button.danger:hover { background: var(--red); }
.server-menu hr { border: none; border-top: 1px solid var(--bg-mid); margin: 5px 6px; }
#typing-bar { min-height: 22px; padding: 0 18px; font-size: 12.5px; color: var(--text-muted); }
#typing-bar .dots { display: inline-block; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

#composer {
  display: flex; align-items: flex-end; gap: 6px;
  margin: 0 16px 20px; background: var(--bg-light); border-radius: 10px; padding: 4px 6px 4px 12px;
}
#composer-input {
  flex: 1; background: none; border: none; outline: none; resize: none;
  color: var(--text); font-size: 16px; padding: 10px 0; min-width: 0; /* 16px stops iOS focus-zoom */
  font-family: inherit; line-height: 1.4; max-height: 160px; overflow-y: auto;
}
.composer-send {
  cursor: default;
  width: 40px; height: 40px; border-radius: 8px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-size: 20px;
}
.composer-send:hover { background: var(--bg-hover); }
#composer-send { color: var(--telegram); }
#composer-send:disabled { color: var(--text-faint); opacity: .5; background: transparent; cursor: default; }
#composer-send:not(:disabled):active { transform: scale(.95); }

/* messages wrap + scroll-to-bottom FAB */
.photo-drafts { margin: 0 16px 8px; min-width: 0; }
.photo-drafts-status { color: var(--text-muted); font-size: 14px; margin: 0 0 6px; }
.photo-drafts-list { display: flex; gap: 10px; overflow-x: auto; padding: 0 0 4px; }
.photo-draft { position: relative; flex: 0 0 112px; min-width: 0; }
.photo-draft img { display: block; width: 112px; height: 88px; object-fit: contain; background: var(--bg-dark); border-radius: 8px; }
.photo-draft-name { display: block; margin-top: 4px; font-size: 14px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-draft-remove { position: absolute; top: 0; right: 0; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; color: var(--text); background: var(--bg-dark); border-radius: 8px; cursor: default; }
.photo-draft-remove:disabled { opacity: .5; }
.photo-draft-remove:active:not(:disabled) { transform: scale(.97); }
@media (max-width: 700px) { .photo-drafts { margin-inline: 10px; } }

#messages-wrap { flex: 1; position: relative; display: flex; flex-direction: column; min-height: 0; }
#messages-wrap #messages { flex: 1; }
.new-messages-bar { display: flex; align-items: center; gap: 4px; padding: 0 8px 0 12px; min-height: 44px; flex-shrink: 0; background: #442a30; color: #fff0f1; border-bottom: 1px solid #bd6974; }
.new-messages-jump { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 1; min-width: 0; min-height: 44px; color: inherit; text-align: left; font-size: 14px; font-weight: 600; }
.new-messages-jump > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-messages-action { font-weight: 400; text-decoration: underline; text-underline-offset: 3px; }
.new-mentions-jump { min-height: 44px; padding-inline: 10px; white-space: nowrap; color: #fff0f1; font-size: 14px; font-weight: 700; }
.new-messages-bar .icon-btn { flex-shrink: 0; width: 44px; height: 44px; color: #fff0f1; }
.new-messages-bar button:focus-visible { outline: 2px solid currentColor; outline-offset: -3px; border-radius: 4px; }
.new-messages-bar button:disabled { opacity: .7; }
.new-messages-divider { display: flex; align-items: center; gap: 8px; margin: 16px 16px 8px; color: #ffabb2; font-size: 12px; font-weight: 700; }
.new-messages-divider::before { content: ''; flex: 1; height: 1px; background: #d65d6b; }
@media (hover: hover) and (pointer: fine) { .new-messages-bar button:hover { background: rgba(255,255,255,.06); } }

/* Telegram-style floating date pill — always pinned at the top-center while scrolling */
#float-date {
  position: absolute; top: 8px; left: 0; right: 0; z-index: 6;
  display: flex; justify-content: center; pointer-events: none;
  opacity: 0; transition: opacity .25s;
}
#float-date.show { opacity: 1; }
.new-messages-bar:not(.hidden) ~ #float-date { top: 52px; }
#float-date span {
  background: rgba(20,21,24,.88); color: var(--text-header);
  font-size: 12px; font-weight: 700; padding: 4px 14px; border-radius: 12px;
  box-shadow: 0 1px 6px rgba(0,0,0,.4); letter-spacing: .2px; backdrop-filter: blur(4px);
}
#scroll-bottom {
  position: absolute; right: 20px; bottom: 12px; z-index: 8;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--bg-dark); color: var(--text); border: 1px solid #4e5058;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
#scroll-bottom:hover { background: var(--bg-hover); }
#scroll-bottom-badge {
  position: absolute; top: -6px; right: -4px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}

/* reply preview bar */
#reply-bar {
  display: flex; align-items: center; gap: 10px;
  margin: 0 16px 6px; padding: 8px 12px; background: var(--bg-light);
  border-radius: 8px;
}
#reply-bar .rb-body { flex: 1; min-width: 0; }
#reply-bar .rb-author { font-size: 12px; font-weight: 700; color: var(--telegram); }
#reply-bar .rb-snippet { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#reply-bar .rb-close { color: var(--text-muted); font-size: 16px; padding: 4px 8px; border-radius: 6px; }
#reply-bar .rb-close:hover { background: var(--bg-hover); color: var(--text); }

/* emoji picker */
#emoji-popup {
  position: absolute; right: 16px; bottom: 100%; margin-bottom: 8px; z-index: 22;
  background: var(--bg-dark); border: 1px solid #4e5058; border-radius: 12px; padding: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
#emoji-popup .react-full { margin-top: 0; }
#emoji-popup .emoji-grid { max-height: 220px; }

/* context menu */
.ctx-menu {
  position: fixed; z-index: 250; min-width: 170px;
  max-width: calc(100vw - 16px); max-height: calc(100dvh - 16px); overflow-y: auto;
  background: var(--bg-darkest); border-radius: 8px; padding: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.55);
}
.ctx-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 6px; font-size: 13.5px; color: var(--text-muted);
}
.ctx-menu button:hover { background: var(--blurple); color: #fff; }
.ctx-menu button.danger:hover { background: var(--red); }
.sidebar-context-menu { width: 240px; }
.sidebar-context-title { padding: 8px 10px; color: var(--text-header); font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.sidebar-context-menu button { min-height: 44px; color: var(--text); }
.sidebar-context-menu button:focus-visible { background: var(--bg-active); color: var(--text-header); outline: 2px solid var(--telegram); outline-offset: -2px; }
@media (hover: none), (pointer: coarse) {
  .ctx-menu button { min-height: 44px; }
}

/* Server-confirmed sends; local failures retain their text and recovery actions. */
.pending-message { margin-top: 12px; }
.pending-message .msg-content { color: #b5bac1; }
.pending-message .msg-image { opacity: .65; cursor: default; }
.pending-context, .pending-error { color: #b5bac1; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.pending-status { color: #b5bac1; font-size: 13px; margin-top: 5px; }
.pending-status.failed { color: #ff999d; }
.pending-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.pending-actions .btn { min-height: 44px; padding: 8px 12px; font-size: 13px; }
.pending-actions .btn:disabled { opacity: .5; cursor: not-allowed; }
#outbox-list .pending-message { padding: 12px 0; }
#outbox-list .msg-main { min-width: 0; }

/* profile popout */
#profile-pop:not(:empty) {
  position: fixed; inset: 0; z-index: 95; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6); padding: 16px;
}
.profile-card {
  width: 100%; max-width: 340px; background: var(--bg-dark); border-radius: 14px; overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,.6);
}
.profile-banner { height: 90px; background-size: cover; background-position: center; }
.profile-banner.img { background-size: cover; }
.profile-body { padding: 0 18px 18px; margin-top: -38px; }
.profile-avatar {
  width: 80px; height: 80px; border-radius: 50%; border: 6px solid var(--bg-dark);
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 30px;
  background-size: cover; background-position: center;
}
.profile-avatar.img { background-size: cover; }
.profile-name { font-size: 20px; font-weight: 800; color: #fff; margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.profile-status { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.profile-about { font-size: 13.5px; color: var(--text); background: var(--bg-darkest); border-radius: 8px; padding: 10px 12px; margin-top: 12px; white-space: pre-wrap; word-break: break-word; }
.profile-actions { margin-top: 14px; display: flex; gap: 8px; }

/* Profile editing keeps artwork separate from persistent pencil controls. */
.modal.profile-editor {
  display: flex; flex-direction: column; max-width: 480px;
  padding: 0; overflow: hidden; max-height: calc(100dvh - 24px);
  background: var(--bg-mid);
}
.profile-edit-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px 12px 24px; flex-shrink: 0; }
.profile-edit-header h2 { margin: 0; }
.profile-edit-header .icon-btn { width: 44px; height: 44px; }
.profile-edit-scroll { overflow-y: auto; min-height: 0; padding: 0 24px 24px; overscroll-behavior: contain; }
.profile-edit-card { background: var(--bg-active); border-radius: 12px; }
.profile-edit-banner { position: relative; height: 120px; border-radius: 12px 12px 0 0; background-size: cover; background-position: center; }
.profile-edit-body { position: relative; padding: 58px 16px 18px; }
.profile-edit-avatar { position: absolute; top: -48px; left: 16px; width: 96px; height: 96px; border: 6px solid var(--bg-active); border-radius: 50%; }
.profile-edit-artwork { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; border-radius: 50%; background-size: cover; background-position: center; color: #fff; font-size: 32px; font-weight: 700; }
.profile-edit-pencil { position: absolute; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.75); color: #fff; border-radius: 50%; cursor: default; }
.profile-edit-pencil:hover { background: #111; }
.profile-edit-pencil:active { transform: scale(.97); }
.profile-edit-pencil:disabled { opacity: .5; cursor: wait; }
.banner-pencil { top: 8px; right: 8px; border-radius: 8px; }
.avatar-pencil { right: -8px; bottom: -6px; }
.profile-edit-menu { position: absolute; z-index: 3; width: 196px; padding: 6px; border-radius: 8px; background: var(--bg-mid); box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.profile-edit-banner > .profile-edit-menu { top: 56px; right: 8px; }
.profile-edit-avatar > .profile-edit-menu { top: 82px; left: 0; }
.profile-edit-menu button { display: block; width: 100%; min-height: 44px; padding: 10px; border-radius: 4px; text-align: left; color: var(--text-header); font-size: 13px; font-weight: 600; }
.profile-edit-menu button:hover:not(:disabled), .profile-edit-menu button:focus-visible { background: var(--blurple); color: #fff; }
.profile-edit-menu button.danger { color: #ff999d; }
.profile-edit-menu button.danger:hover:not(:disabled) { background: var(--red); color: #fff; }
.profile-edit-menu button:disabled { opacity: .45; cursor: not-allowed; }
.profile-edit-name { font-size: 22px; line-height: 1.25; color: var(--text-header); font-weight: 700; overflow-wrap: anywhere; }
.profile-edit-handle { margin-top: 4px; color: var(--text); font-size: 13px; }
.profile-edit-bio-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 6px; }
.profile-editor .profile-edit-body label { color: var(--text); text-transform: none; }
.profile-edit-count { color: #b5bac1; font-size: 12px; font-variant-numeric: tabular-nums; }
.profile-edit-body .field-hint { color: #b5bac1; }
.profile-edit-body textarea { display: block; width: 100%; min-height: 88px; background: var(--bg-dark); color: var(--text); border: 1px solid var(--bg-hover); border-radius: 6px; padding: 10px 12px; font: inherit; font-size: 16px; line-height: 1.4; resize: vertical; }
.profile-edit-body textarea::placeholder { color: #b5bac1; }
.profile-edit-colors.swatches { gap: 8px; }
.profile-edit-colors .swatch { position: relative; flex-shrink: 0; width: 32px; height: 32px; border: 2px solid transparent; }
.profile-edit-colors .swatch[aria-pressed=true] { border-color: #fff; box-shadow: inset 0 0 0 2px var(--bg-dark); }
.profile-edit-colors .swatch::after { content: ''; position: absolute; inset: -5px; }
.profile-edit-footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 14px 24px; background: var(--bg-dark); flex-shrink: 0; }
.profile-edit-footer .btn { min-height: 44px; }
.profile-edit-status { margin-right: auto; font-size: 12px; color: var(--text-muted); }
@media (max-width: 480px) {
  .profile-edit-header { padding-left: 16px; }
  .profile-edit-scroll { padding: 0 12px 16px; }
  .profile-edit-footer { padding: 12px 16px; }
  .profile-edit-body { padding-left: 12px; padding-right: 12px; }
  .profile-edit-banner { height: 108px; }
}

/* members panel */
#members {
  width: 240px; background: var(--bg-dark); overflow-y: auto;
  padding: 16px 10px; flex-shrink: 0;
}
.members-heading { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); padding: 6px 8px; }
.member-row {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 8px; border-radius: 6px; font-size: 15px; color: var(--text-muted);
}
.member-row:hover { background: var(--bg-hover); color: var(--text); }
.member-row.offline { opacity: .45; }
.member-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; min-width: 0; }
.crown { color: var(--yellow); display: inline-flex; align-items: center; }
.manage-members { display: inline-flex; align-items: center; justify-content: center; gap: 7px; margin-bottom: 12px; font-size: 13px; }

/* ------------------------------ modals ------------------------------ */
#modal-root:not(:empty) {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 460px; max-height: 85dvh; overflow-y: auto;
  background: var(--bg-dark); border-radius: 12px; padding: 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  min-width: 0; overscroll-behavior: contain; overflow-wrap: anywhere;
}
.modal h2 { color: #fff; font-size: 19px; margin-bottom: 4px; }
.modal .modal-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }
.modal label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin: 14px 0 6px; }
.modal input[type=text], .modal input[type=password] {
  display: block; width: 100%;
  background: var(--bg-darkest); border: 1px solid transparent; border-radius: var(--radius);
  color: var(--text); padding: 11px 12px; font-size: 16px; outline: none; /* 16px stops iOS focus-zoom */
}
.modal input:focus { border-color: var(--telegram); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.modal-actions > * { min-width: 0; }
.invite-copy-row { display: flex; align-items: center; gap: 8px; }
.invite-copy-row input { min-width: 0; flex: 1; }
.invite-copy-row button { flex-shrink: 0; }
.invite-code-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; color: var(--text-muted); font-size: 13px; }
.channel-type-option { display: flex; align-items: center; gap: 16px; padding: 18px 14px; margin: 20px 0; border: 1px solid var(--blurple); border-radius: 8px; background: var(--bg-mid); }
.channel-type-option strong { font-size: 17px; color: var(--text-header); }
.channel-type-option p, .field-hint { color: var(--text-muted); font-size: 13px; line-height: 1.5; margin-top: 5px; }
.modal.settings-dialog {
  position: relative; display: grid; grid-template-columns: 236px minmax(0, 1fr);
  width: min(1100px, 100%); max-width: 1100px; height: min(820px, 92dvh); max-height: 92dvh;
  padding: 0; overflow: hidden; background: var(--bg-mid); border: 1px solid var(--bg-active);
}
.settings-nav { min-width: 0; overflow-y: auto; background: var(--bg-dark); padding: 28px 12px; }
.settings-nav-heading { color: var(--text-muted); padding: 0 12px 20px; font-size: 12px; font-weight: 700; text-transform: uppercase; }
.settings-nav-item { display: flex; gap: 8px; align-items: center; justify-content: space-between; width: 100%; padding: 12px; border-radius: 6px; text-align: left; font-size: 14px; color: var(--text-muted); min-height: 44px; }
.settings-nav-item:hover { background: var(--bg-hover); color: var(--text-header); }
.settings-nav-item.active { color: var(--text-header); background: var(--bg-active); }
.settings-nav-item .shell-icon { display: none; }
.settings-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.settings-page-header { flex-shrink: 0; display: flex; align-items: center; min-height: 72px; padding: 16px 64px 16px 32px; border-bottom: 1px solid var(--bg-active); }
.settings-page-header h2 { margin: 0; font-size: 20px; line-height: 1.35; }
.settings-page-header h2[tabindex="-1"]:focus { outline: none; }
.settings-content { overflow-y: auto; overscroll-behavior: contain; min-width: 0; min-height: 0; padding: 32px; }
.settings-content > * { max-width: 100%; }
.settings-content .btn-block { margin-top: 20px; }
.settings-back { display: none; }
.settings-close { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; }
.settings-account { display: flex; align-items: center; gap: 16px; padding-bottom: 24px; }
.settings-account h3 { color: var(--text-header); font-size: 22px; overflow-wrap: anywhere; }
.settings-account p.modal-sub { margin: 4px 0 0; }
.settings-info-row { display: flex; gap: 16px; justify-content: space-between; align-items: start; padding: 22px 0; margin-bottom: 20px; border-top: 1px solid var(--bg-active); border-bottom: 1px solid var(--bg-active); }
.settings-info-row strong { text-align: right; min-width: 0; }
/* Task surfaces share the existing neutral palette and one navigation rhythm. */
#modal-root:has(.settings-dialog), #modal-root:has(.app-page-dialog) { z-index: 102; }
.settings-action-list { margin: 0 0 24px; border-block: 1px solid var(--bg-active); }
.settings-action-row { display: flex; align-items: center; gap: 16px; width: 100%; min-height: 72px; padding: 16px 0; text-align: left; }
.settings-action-list .settings-action-row + .settings-action-row { border-top: 1px solid var(--bg-active); }
.settings-action-row > .shell-icon { flex-shrink: 0; color: var(--text-muted); }
.settings-action-copy { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.settings-action-title { color: var(--text-header); font-size: 16px; font-weight: 600; }
.settings-action-description { color: #b6bcc5; font-size: 14px; line-height: 1.4; }
.settings-action-row.account-logout { min-height: 56px; margin-top: 24px; border-top: 1px solid var(--bg-active); }
.account-logout .settings-action-title, .account-logout > .shell-icon { color: #f28b8e; }
.account-page .settings-account { padding: 0 0 24px; }
.account-page .settings-account .avatar { width: 56px; height: 56px; flex: 0 0 56px; }
.account-page .settings-info-row { border-bottom: 0; margin: 0; padding: 20px 0; font-size: 14px; color: #b6bcc5; }
.account-page .settings-info-row strong { color: var(--text-header); }
.account-page .iphone-install-help { margin-top: 0; font-size: 14px; color: #b6bcc5; line-height: 1.5; }
.security-intro { color: #b6bcc5; font-size: 14px; line-height: 1.6; margin-bottom: 24px; max-width: 55ch; }
.security-page label { margin-top: 24px; }
.security-page .master-action { margin-top: 24px; min-height: 44px; }
.security-page .modal-divider { display: none; }
.modal.app-page-dialog {
  display: flex; flex-direction: column; width: min(600px, 100%); max-width: 600px;
  max-height: calc(100dvh - 48px); padding: 0; overflow: hidden; background: var(--bg-mid);
}
.app-page-header { display: flex; align-items: center; gap: 12px; min-height: 72px; padding: 12px 24px 12px 16px; border-bottom: 1px solid var(--bg-active); flex-shrink: 0; }
.app-page-header h2 { margin: 0; font-size: 20px; font-weight: 650; line-height: 1.35; outline: none; }
.app-page-back { flex: 0 0 44px; width: 44px; height: 44px; color: var(--text-header); }
.app-page-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 24px; }
.app-page-dialog > .modal-actions { padding: 16px 24px; margin: 0; border-top: 1px solid var(--bg-active); flex-shrink: 0; background: var(--bg-mid); }
.app-page-dialog .btn { min-height: 44px; }
.app-page-dialog .modal-sub { font-size: 14px; color: #b6bcc5; line-height: 1.5; }
.app-page-dialog .permission-scroll { padding: 8px 24px 24px; }
.app-page-dialog input::placeholder, .security-page input::placeholder, .page-search::placeholder { color: #aeb5bf; }
.app-page-dialog input[type=text], .app-page-dialog input[type=password], .app-page-dialog select, .security-page input { min-height: 44px; }
.app-page-dialog.permissions-modal .field-hint { font-size: 14px; color: #b6bcc5; }
.page-danger-zone { border-top: 1px solid var(--bg-active); margin-top: 32px; padding-top: 16px; }
.page-danger-zone .btn-danger, .danger-action { background: transparent; color: #f28b8e; padding: 10px 0; }
.page-danger-zone .btn-danger:hover, .danger-action:hover { background: var(--bg-hover); color: #ffaaa9; }
.page-search { display: block; width: 100%; min-height: 44px; border: 1px solid var(--bg-active); border-radius: var(--radius); padding: 10px 12px; background: var(--bg-darkest); color: var(--text-header); font: inherit; font-size: 16px; }
.page-search:focus-visible { outline: 2px solid var(--telegram); outline-offset: 2px; }
.page-list-status { color: #b6bcc5; font-size: 14px; line-height: 1.5; margin: 16px 0; }
.member-management-list .mm-row { padding: 16px 0; gap: 12px; border-bottom: 1px solid var(--bg-active); border-radius: 0; align-items: flex-start; }
.member-management-list .mm-row[hidden] { display: none; }
.member-management-list .mm-row:hover { background: transparent; }
.member-management-list .mm-row > .avatar { width: 40px; height: 40px; flex: 0 0 40px; }
.member-management-list .mm-name { font-size: 16px; overflow-wrap: anywhere; }
.member-management-list .mm-roles { gap: 6px; margin-top: 8px; }
.member-role-chip { font-size: 12px; font-weight: 500; padding: 4px 8px; border: 1px solid var(--bg-active); color: var(--text-header); background: transparent; border-radius: 6px; overflow-wrap: anywhere; }
.member-role-chip .role-dot { width: 8px; height: 8px; }
.member-no-roles { font-size: 13px; color: #b6bcc5; }
.member-manage { min-height: 44px; padding: 8px 10px; flex-shrink: 0; font-size: 13px; }
.member-role-option { display: flex !important; align-items: center; gap: 12px; min-height: 64px; margin: 0 !important; border-bottom: 1px solid var(--bg-active); text-transform: none !important; font-size: 16px !important; font-weight: 500 !important; color: var(--text-header) !important; }
.member-role-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.member-role-option .switch { flex-shrink: 0; }
.member-detail-page .settings-account { padding-bottom: 8px; }
.member-detail-page .settings-account h3 { font-size: 20px; }
.explore-page .explore-sections { margin: 0 0 24px; padding: 4px; gap: 4px; border-radius: 8px; background: var(--bg-darkest); }
.explore-page .explore-sections .btn { border-radius: 6px; font-size: 15px; background: transparent; color: #b6bcc5; }
.explore-page .explore-sections .btn-primary { background: var(--bg-active); color: var(--text-header); }
.explore-page .explore-status { color: #b6bcc5; font-size: 14px; }
.explore-page .explore-results { min-height: 160px; }
.chat-folder-entry { border-bottom: 1px solid var(--bg-active); padding-bottom: 8px; }
.chat-folder-entry summary { display: flex; align-items: center; min-height: 72px; gap: 12px; cursor: pointer; list-style: none; }
.chat-folder-entry summary::-webkit-details-marker { display: none; }
.chat-folder-entry summary > .shell-icon { flex-shrink: 0; color: var(--text-muted); }
.chat-folder-entry summary:focus-visible { outline: 2px solid var(--telegram); outline-offset: 2px; }
.chat-folder-title { display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 4px; font-size: 16px; }
.chat-folder-title > span { font-size: 14px; color: #b6bcc5; }
.chat-folder-choice { display: flex !important; align-items: center; gap: 12px; min-height: 52px; margin: 0 !important; font-size: 16px !important; font-weight: 400 !important; text-transform: none !important; color: var(--text) !important; }
.chat-folder-choice input { width: 20px; height: 20px; accent-color: var(--blurple); flex-shrink: 0; }
.chat-folder-create { border-top: 1px solid var(--bg-active); margin-top: 24px; padding-top: 8px; }
.chat-folder-create > .btn { margin-top: 16px; width: 100%; }
.folder-empty { padding: 24px 0; display: flex; flex-direction: column; gap: 12px; color: #b6bcc5; }
.folder-empty .shell-icon { color: var(--text-header); }
.folder-empty strong { font-size: 18px; font-weight: 600; color: var(--text-header); }
.folder-empty p { font-size: 14px; line-height: 1.5; max-width: 42ch; }
@media (hover: hover) and (pointer: fine) {
  .settings-action-row:hover { background: var(--bg-hover); }
  .member-management-list .mm-row:hover { background: var(--bg-darkest); }
}
@media (max-width: 700px) {
  #modal-root:has(.app-page-dialog) { padding: 0; }
  .modal.app-page-dialog { position: fixed; top: var(--dialog-top, 0px); left: 0; width: 100%; height: var(--dialog-height, 100dvh); max-height: var(--dialog-height, 100dvh); border-radius: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); box-shadow: none; }
  .app-page-header { min-height: 64px; padding: 10px 16px 10px 8px; gap: 8px; }
  .app-page-header h2 { font-size: 18px; }
  .app-page-body { padding: 24px 20px; }
  .app-page-dialog .permission-scroll { padding: 8px 20px 24px; }
  .app-page-dialog > .modal-actions { padding: 12px 20px; gap: 12px; }
  .app-page-dialog > .modal-actions > .btn-primary { flex: 1; }
  .rename-account-page .app-page-body { flex: 1; }
  .security-page .master-action { width: 100%; }
  .member-management-list .mm-row { gap: 10px; }
}
.settings-content .switch-row > div { min-width: 0; }
.settings-content .switch { flex-shrink: 0; }
.notification-server { border-top: 1px solid var(--bg-active); padding: 2px 0; }
.notification-server:last-of-type { border-bottom: 1px solid var(--bg-active); }
.notification-server-name { min-height: 48px; display: flex; align-items: center; gap: 10px; cursor: pointer; color: var(--text-header); font-weight: 650; overflow-wrap: anywhere; list-style: none; }
.notification-server-name::-webkit-details-marker { display: none; }
.notification-server-name .shell-icon { flex: 0 0 auto; color: var(--text-muted); }
.notification-server[open] .notification-server-name .shell-icon { transform: rotate(90deg); }
.notification-server-name:hover { color: #fff; }
.notification-server-name:focus-visible, .notification-level-select:focus-visible { outline: 2px solid var(--telegram); outline-offset: 2px; }
.notification-rule-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 48px; padding: 5px 0; }
.notification-rule-child { padding-left: 18px; }
.notification-rule-name { min-width: 0; overflow-wrap: anywhere; font-size: 14px; color: var(--text); }
.notification-rule-label { display: flex; flex-direction: column; min-width: 0; }
.notification-rule-context { margin-top: 2px; color: var(--text-muted); font-size: 12px; }
.notification-rule-group { margin: 14px 0 4px; color: var(--text-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.notification-level-select { flex: 0 0 min(195px, 46%); min-width: 0; min-height: 44px; border: 1px solid var(--bg-active); border-radius: 6px; background: var(--bg-dark); color: var(--text-header); padding: 8px; font: inherit; font-size: 13px; }
.notification-level-select:disabled { opacity: .6; }
.notification-rule-status { min-height: 18px; margin: 4px 0 10px; color: var(--text-muted); font-size: 12px; }
.notification-server-link { display: flex; align-items: center; width: 100%; min-height: 48px; gap: 12px; padding: 10px 0; text-align: left; border-bottom: 1px solid var(--bg-active); }
.notification-server-link span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.notification-server-link:hover { background: var(--bg-hover); }
.notification-scoped-modal { display: flex; flex-direction: column; width: 680px; max-width: 100%; overflow: hidden; }
#modal-root:has(.notification-scoped-modal) { z-index: 102; }
.notification-scoped-modal > h2, .notification-scoped-modal > p, .notification-scoped-modal > .modal-actions { flex-shrink: 0; }
.notification-scope-name { color: var(--text-header); overflow-wrap: anywhere; margin: 4px 0 20px; }
.notification-scoped-body { overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
.notification-scoped-body h3 { color: var(--text-header); font-size: 16px; margin: 24px 0 8px; }
.notification-defaults { border: 0; min-width: 0; }
.notification-defaults legend { color: var(--text-header); font-weight: 600; margin-bottom: 8px; }
.notification-scoped-modal .notification-default-option { display: flex; align-items: center; min-height: 44px; gap: 12px; margin: 0; color: var(--text); font-size: 15px; font-weight: 400; text-transform: none; }
.notification-default-option input { width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--blurple); }
.notification-scoped-body .notification-rule-row { flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid var(--bg-active); }
.notification-scoped-body .notification-rule-label { flex: 1; }
.notification-remove { flex-shrink: 0; width: 44px; height: 44px; }
.notification-add-override { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.notification-add-override input, .notification-override-picker { min-height: 44px; background: var(--bg-darkest); color: var(--text); border: 1px solid var(--bg-active); border-radius: var(--radius); padding: 10px 12px; font: inherit; font-size: 16px; }
.notification-add-override input { width: 100%; }
.notification-add-override input::placeholder { color: var(--text-muted); }
.notification-add-override input:focus-visible, .notification-override-picker:focus-visible { outline: 2px solid var(--telegram); outline-offset: -2px; }
.notification-override-picker { flex: 1 1 240px; min-width: 0; width: 100%; }
.notification-add-override .btn { min-height: 44px; }
.notification-overrides-empty { font-size: 14px; line-height: 1.5; margin-top: 16px; }
@media (max-width: 480px) {
  .notification-rule-row { align-items: stretch; flex-direction: column; gap: 4px; padding: 7px 0; }
  .notification-level-select { width: 100%; flex-basis: auto; }
  .notification-rule-child { padding-left: 12px; }
  .notification-scoped-body .notification-rule-row { flex-direction: row; }
  .notification-scoped-body .notification-rule-label { flex-basis: 100%; }
  .notification-scoped-body .notification-level-select { flex: 1; width: auto; }
}

@media (max-width: 700px) {
  #modal-root:not(:empty) { padding: 12px; }
  .modal { max-height: calc(100dvh - 24px); padding: 24px 18px; }
  .modal .btn { min-height: 44px; }
  #modal-root:has(.settings-dialog) { padding: 0; }
  .modal.settings-dialog { display: block; position: fixed; top: var(--dialog-top, 0px); left: 0; width: 100%; height: var(--dialog-height, 100dvh); max-height: var(--dialog-height, 100dvh); border: 0; border-radius: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .settings-nav { display: none; height: 100%; padding: 0 12px 24px; }
  .settings-list-open .settings-nav { display: block; }
  .settings-list-open .settings-main { display: none; }
  .settings-nav-heading { display: flex; align-items: center; min-height: 64px; padding: 16px 52px 16px 8px; color: var(--text-header); font-size: 20px; text-transform: none; }
  .settings-nav-item { min-height: 54px; font-size: 16px; margin-top: 4px; }
  .settings-nav-item .shell-icon { display: block; }
  .settings-main { height: 100%; }
  .settings-page-header { min-height: 64px; padding: 10px 58px 10px 10px; gap: 8px; }
  .settings-page-header h2 { font-size: 18px; }
  .settings-back { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; height: 44px; border-radius: 6px; color: var(--text-header); }
  .settings-back span { display: none; }
  .settings-close { top: calc(10px + env(safe-area-inset-top)); right: 8px; }
  .settings-content { padding: 24px 18px 32px; }
  .settings-content .role-row { flex-wrap: wrap; }
  .settings-content .role-row-info { flex-basis: calc(100% - 32px); }
  .settings-content .bot-row { align-items: flex-start; }
  .invite-copy-row { flex-wrap: wrap; }
  .invite-copy-row input { flex-basis: 100%; }
  .invite-copy-row button { width: 100%; }
}
.modal .error { color: #f28b8e; font-size: 13px; margin-top: 10px; }
.modal-divider { border: none; border-top: 1px solid var(--bg-darkest); margin: 18px 0; }

/* settings: bots list */
.bot-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-darkest); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px;
}
.bot-row-info { flex: 1; min-width: 0; }
.bot-row-name { font-weight: 600; color: #fff; font-size: 14px; display: flex; gap: 6px; align-items: center; }
.bot-row-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.bot-token {
  font-family: ui-monospace, Menlo, monospace; font-size: 11px;
  background: #111214; color: #7ee0a3; border-radius: 6px; padding: 8px 10px;
  margin-top: 8px; word-break: break-all; cursor: pointer; display: none;
}
.bot-row.show-token .bot-token { display: block; }

/* request cards (approve/decline) */
.request-card {
  background: var(--bg-darkest); border: 1px solid #4e5058; border-radius: 10px;
  padding: 14px; margin-bottom: 10px;
}
.request-card .req-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.request-card .req-title { font-weight: 600; color: #fff; font-size: 14px; }
.request-card .req-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.request-card .req-note { font-size: 13px; color: var(--text); background: var(--bg-mid); border-radius: 6px; padding: 8px 10px; margin: 8px 0; }
.request-card .req-actions { display: flex; gap: 8px; }
.request-card .req-actions .btn { flex: 1; padding: 8px; font-size: 13px; }

/* ------------------------------ toasts ------------------------------ */
#toast-root {
  position: fixed; top: 14px; right: 14px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px; max-width: 380px; width: calc(100% - 28px);
  margin-left: auto;
  pointer-events: none; /* let clicks pass through the gaps to the app underneath */
}
.toast {
  position: relative;
  background: var(--bg-dark); border: 1px solid #4e5058; border-radius: 10px;
  padding: 14px 34px 14px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
  animation: slideIn .25s ease;
  pointer-events: auto;
}
.toast-close {
  position: absolute; top: 8px; right: 8px;
  width: 24px; height: 24px; border-radius: 6px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.toast-close:hover { background: var(--bg-hover); color: var(--text); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }
.toast-title { font-weight: 700; color: #fff; font-size: 14px; margin-bottom: 4px; }
.toast-body { font-size: 13px; color: var(--text-muted); }

/* ------------------- roles, settings tabs, folders, explore ------------------- */

/* tabbed modal (server settings) */
.server-profile-image-row { display: flex; align-items: center; gap: 16px; margin: 8px 0 20px; min-width: 0; }
.server-profile-icon { position: relative; width: 80px; height: 80px; flex: 0 0 80px; display: grid; place-items: center; overflow: hidden; border-radius: 24px; color: #fff; font-size: 24px; font-weight: 700; }
.server-profile-icon img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.server-profile-image-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; min-width: 0; }
.server-profile-image-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.server-profile-image-buttons .btn { min-height: 44px; }
.server-profile-image-actions .field-hint { margin: 0; line-height: 1.4; }
@media (max-width: 480px) { .server-profile-image-row { align-items: flex-start; } .server-profile-icon { width: 64px; height: 64px; flex-basis: 64px; border-radius: 18px; } }
.modal-tabs { display: flex; gap: 6px; margin: 4px 0 18px; flex-wrap: wrap; }
.modal-tab {
  padding: 7px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;
  background: var(--bg-darkest); color: var(--text-muted);
}
.modal-tab.active { background: var(--blurple); color: #fff; }
.modal-tab:hover:not(.active) { color: var(--text); }

.master-console { width: min(100%, 1020px); min-width: 0; margin: 0 auto; padding: 32px 36px 48px; color: var(--text); }
.master-console h2 { color: #fff; font-size: 26px; margin: 0 0 6px; }
.master-console h3 { color: #fff; font-size: 17px; margin: 0 0 16px; }
.master-intro, .master-note { color: var(--text-muted); font-size: 13px; line-height: 1.45; }
.master-intro { margin: 0; }
.master-note { margin: 0 0 18px; }
.master-tabs { display: flex; gap: 24px; margin: 28px 0 24px; border-bottom: 1px solid var(--bg-darkest); overflow-x: auto; }
.master-tab { flex: none; color: var(--text-muted); font-size: 14px; font-weight: 600; padding: 0 0 12px; border-bottom: 2px solid transparent; }
.master-tab:hover { color: var(--text); }
.master-tab.active { color: #fff; border-color: var(--blurple); }
.master-tab:focus-visible, .master-side-link:focus-visible { outline: 2px solid var(--telegram); outline-offset: 2px; }
.master-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(290px, 330px); gap: 24px; align-items: start; }
.master-account-list { min-width: 0; }
.channel-access-empty { margin: 16px; color: var(--text-muted); font-size: 14px; line-height: 1.5; }
.permissions-modal { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.permission-scroll { min-height: 0; overflow-y: auto; padding: 2px 4px; }
.permission-scroll > label { display: block; margin: 16px 0 8px; }
.permission-scroll > select { width: 100%; padding: 10px; border-radius: 8px; background: var(--bg-darkest); color: var(--text); font: inherit; }
.permissions-modal .modal-actions { flex-shrink: 0; flex-wrap: wrap; }
.access-picker { margin-top: 16px; }
.access-toggle { display: flex !important; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 15px; }
.access-toggle input, .access-list input[type="checkbox"] { width: 18px; height: 18px; flex: 0 0 18px; accent-color: var(--blurple); margin: 0; }
.access-choices fieldset { border: 0; margin-top: 16px; min-width: 0; }
.access-choices legend { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.access-list { max-height: 144px; overflow-y: auto; margin-top: 6px; }
.access-list .role-select-item { min-height: 44px; overflow-wrap: anywhere; }
.access-list [hidden] { display: none; }
.category-sync-section { margin-top: 20px; }
.permissions-modal .field-hint { color: var(--text); font-size: 13px; line-height: 1.5; }
#mention-popup { position: absolute; bottom: 100%; left: 16px; right: 16px; z-index: 20; padding: 6px; max-height: min(280px, 40dvh); overflow-y: auto; border-radius: 8px; background: var(--bg-dark); box-shadow: 0 8px 24px #0005; }
.mention-option { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; border: 0; border-radius: 4px; padding: 8px 12px; background: transparent; color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.mention-option.active, .mention-option:hover { background: var(--bg-active); }
.mention-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mention-kind { font-size: 12px; color: var(--text); }
.permissions-modal .access-toggle, .permissions-modal .role-select-item { text-transform: none; font-size: 14px; color: var(--text); font-weight: 500; }
.permissions-modal .role-select-item { display: flex; align-items: center; gap: 10px; margin: 4px 0; }
.permissions-modal input[type="search"] { width: 100%; min-height: 40px; background: var(--bg-darkest); border: 1px solid var(--bg-active); border-radius: 6px; color: var(--text); padding: 8px; font: inherit; }
.master-account-list .bot-row { background: var(--bg-dark); }
.master-account-row { flex-wrap: wrap; }
.master-account-row .bot-row-info { min-width: 0; }
.master-account-row .bot-row-name { overflow-wrap: anywhere; }
.master-account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.master-account-actions .btn { min-height: 44px; }
.reset-password-dialog h2 { overflow-wrap: anywhere; }
.rename-account-page .field-hint { color: #b6bcc5; font-size: 14px; line-height: 1.5; margin-top: 12px; }
@media (max-width: 600px) {
  .master-account-actions { flex-basis: 100%; }
  .master-account-actions .btn:first-child { flex: 1; }
}
.master-create, .master-grant { background: var(--bg-dark); border-radius: var(--radius); padding: 20px; }
.master-grant { max-width: 620px; margin-bottom: 26px; }
.master-console label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin: 14px 0 6px; }
.master-console input[type=text], .master-console input[type=password] { display: block; width: 100%; background: var(--bg-darkest);
  border: 1px solid transparent; border-radius: var(--radius); color: var(--text); padding: 11px 12px; font-size: 16px; outline: none; }
.master-console input:focus { border-color: var(--telegram); }
.master-error { color: #f28b8e; font-size: 13px; margin-top: 10px; }
.master-side-label { padding: 18px 16px 8px; color: var(--text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.master-side-link { display: block; width: calc(100% - 16px); margin: 2px 8px; padding: 10px 12px; border-radius: var(--radius);
  color: var(--text-muted); text-align: left; font-size: 14px; font-weight: 600; }
.master-side-link:hover { color: var(--text); background: var(--bg-active); }
.master-side-link.active { color: #fff; background: var(--bg-active); }
.master-pair { display: flex; gap: 8px; }
.master-select { min-width: 0; width: 50%; padding: 10px; color: var(--text); background: var(--bg-darkest);
  border: 1px solid var(--bg-darkest); border-radius: var(--radius); font-size: 14px; }
.master-select:focus-visible { outline: 2px solid var(--telegram); }
.master-action { margin-top: 18px; }
.master-audit { padding: 10px 0; border-bottom: 1px solid var(--bg-darkest); font-size: 13px; display: grid; gap: 3px; }
.master-audit time { font-size: 11px; color: var(--text-muted); }
@media (max-width: 900px) { .master-columns { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .master-console { padding: 24px 16px 36px; } .master-tabs { gap: 18px; }
  .master-pair { flex-direction: column; } .master-select { width: 100%; } }

/* color swatch picker */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: transform .1s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--bg-dark) inset; }

/* role rows */
.role-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-darkest); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px;
}
.role-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.role-row-info { flex: 1; min-width: 0; }
.role-row-name { font-weight: 600; color: #fff; font-size: 14px; }
.role-row-perms { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.perm-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.perm-check input { width: 16px; height: 16px; accent-color: var(--blurple); }

/* member management rows */
.mm-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 6px; }
.mm-row:hover { background: var(--bg-darkest); }
.mm-info { flex: 1; min-width: 0; }
.mm-name { font-weight: 600; color: #fff; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.mm-roles { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.role-chip {
  font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 10px;
  color: #fff; display: inline-flex; align-items: center; gap: 4px;
}
.role-chip .x { cursor: pointer; opacity: .8; }
.role-chip .x:hover { opacity: 1; }
.role-add-btn {
  font-size: 11px; color: var(--text-muted); background: var(--bg-mid);
  border-radius: 10px; padding: 2px 8px; cursor: pointer;
}
.role-add-btn:hover { color: var(--text); }

/* username colored by top role */
.msg-author.roled, .member-name.roled { }

/* compact channel/category hierarchy */
.category-row {
  display: flex; align-items: center; min-height: 28px;
  margin-top: 12px;
}
.category-header {
  display: flex; align-items: center; gap: 5px; min-width: 0; flex: 1;
  font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-muted);
  text-align: left; padding: 4px; border-radius: 4px; user-select: none;
}
.category-header:hover { color: var(--text); }
.category-header.unread { color: var(--text-header); }
.category-header .caret { display: inline-flex; align-items: center; width: 12px; flex-shrink: 0; }
.category-header .cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-locked-badge { font-size: 10px; background: var(--bg-mid); color: var(--text-muted); padding: 2px 6px; border-radius: 6px; }

/* toggle switch */
.channel-member-access h3 { font-size: 16px; margin: 20px 0 8px; }
.channel-member-list { max-height: 240px; overflow-y: auto; margin-top: 8px; }
.channel-member-row { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.channel-member-row[hidden] { display: none; }
.channel-member-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.channel-member-row .field-hint { margin: 0; flex-shrink: 0; }
.channel-member-row .switch input:disabled + .track { opacity: .55; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.switch-row .switch-label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); }
.switch-row .switch-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.switch, .modal .switch { position: relative; width: 44px; height: 44px; flex-shrink: 0; margin: 0; }
.switch input { position: absolute; inset: 0; z-index: 1; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 10px 0; pointer-events: none; background: var(--bg-darkest); border-radius: 12px; transition: background .15s; }
.switch input:focus-visible + .track { outline: 2px solid var(--telegram); outline-offset: 3px; }
.switch .track::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::before { transform: translateX(20px); }
.role-select-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; max-height: 180px; overflow-y: auto; }
.role-select-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--bg-darkest); border-radius: 6px; cursor: pointer; }
.role-select-item input { width: 16px; height: 16px; accent-color: var(--blurple); }
.role-select-item .role-dot { width: 12px; height: 12px; border-radius: 50%; }

/* chat folders bar */
#folder-bar {
  display: flex; gap: 4px; padding: 8px 8px 0; overflow-x: auto; flex-shrink: 0;
}
#folder-bar::-webkit-scrollbar { height: 0; }
.folder-tab {
  padding: 5px 12px; border-radius: 14px; font-size: 13px; font-weight: 600;
  background: var(--bg-darkest); color: var(--text-muted); white-space: nowrap; flex-shrink: 0;
}
.folder-tab.active { background: var(--blurple); color: #fff; }
.folder-tab:hover:not(.active) { color: var(--text); }
.folder-tab.add { color: var(--text-faint); }

/* People and bot discovery preserves the compact, motion-free dialog. */
.explore-sections { display: flex; gap: 8px; margin: 16px 0; }
.explore-sections .btn { min-height: 44px; flex: 1; }
.explore-status { color: var(--text-muted); font-size: 14px; line-height: 1.5; margin: 12px 0; }
.explore-person { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--bg-hover); }
.explore-person .avatar { flex-shrink: 0; }
.explore-person-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.explore-person .btn { min-height: 44px; flex-shrink: 0; padding: 8px 12px; }
.explore-dialog .explore-search { font-size: 16px; }
@media (max-width: 380px) {
  .explore-person { gap: 8px; flex-wrap: wrap; }
  .explore-person-name { font-size: 14px; }
}

/* explore-bots directory */
.explore-search {
  width: 100%; background: var(--bg-darkest); border: 1px solid transparent; border-radius: var(--radius);
  color: var(--text); padding: 10px 12px; font-size: 15px; outline: none; margin-bottom: 12px;
}
.explore-search:focus { border-color: var(--telegram); }
.explore-bot {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-darkest); border-radius: 10px; padding: 12px; margin-bottom: 8px;
}
.explore-bot-info { flex: 1; min-width: 0; }
.explore-bot-name { font-weight: 700; color: #fff; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.explore-bot-desc { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.explore-bot-meta { font-size: 11px; color: var(--text-faint); margin-top: 3px; }

/* slash-command autocomplete */
#cmd-popup {
  position: absolute; left: 16px; right: 16px; bottom: 100%;
  background: var(--bg-dark); border: 1px solid #4e5058; border-radius: 10px;
  margin-bottom: 8px; max-height: 240px; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.45); z-index: 20;
}
.cmd-item { display: flex; align-items: baseline; gap: 10px; padding: 10px 12px; cursor: pointer; }
.cmd-item.active, .cmd-item:hover { background: var(--bg-hover); }
.cmd-name { font-weight: 700; color: var(--telegram); font-size: 14px; }
.cmd-name .slash { color: var(--text-muted); }
.cmd-desc { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-wrap { position: relative; }

/* command hint bar under bot chats */
#composer { position: relative; }

/* settings section titles */
.settings-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted);
  margin: 18px 0 8px;
}

#members.collapsed { display: none; } /* desktop toggle */

/* ---------------------------- responsive ---------------------------- */
#drawer-backdrop {
  display: none; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.6);
}

@media (max-width: 1100px) {
  #members { display: none; position: fixed; right: 0; top: 0; bottom: 0; z-index: 50; box-shadow: -8px 0 24px rgba(0,0,0,.4); }
  #members.open { display: block; }
  #app.members-open #drawer-backdrop { display: block; } /* tap outside to close */
}

@media (max-width: 820px) {
  .mobile-only { display: inline-flex !important; }
  #left-wrap {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,.4);
  }
  #app.drawer-open #left-wrap { transform: translateX(0); }
  #app.drawer-open #drawer-backdrop { display: block; }
  #sidebar { width: min(260px, calc(100vw - 72px - 40px)); }
  /* Direct Messages is a phone page, not a partial drawer over an empty chat. */
  #app.dm-home #left-wrap { transition: none; }
  #app.dm-home:not(.dm-list-open) #left-wrap { display: none; }
  #app.dm-home.dm-list-open #left-wrap {
    position: relative; inset: auto; width: 100%; min-width: 0;
    transform: none; transition: none; box-shadow: none;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-dark);
  }
  #app.dm-home.dm-list-open #rail { display: none; }
  #app.dm-home.dm-list-open.dm-rail-open #rail { display: flex; }
  #app.dm-home.dm-list-open #sidebar { width: 100%; min-width: 0; flex: 1; }
  #app.dm-home.dm-list-open #main, #app.dm-home.dm-list-open #drawer-backdrop { display: none; }
  #app.dm-home .dm-mobile-menu { display: inline-flex; flex-shrink: 0; margin-left: 6px; }
  #app.dm-home #sidebar-header > .sidebar-title { padding-left: 8px; padding-right: 8px; }
  #app.dm-home #sidebar-header .invite-chip { margin-right: 8px; }
  #app.dm-home #chat-header { gap: 6px; padding: 0 8px; }
  #app.dm-home #chat-header > .icon-btn { flex-shrink: 0; }
  #app.dm-home #chat-title { flex: 1; overflow: hidden; }
  #app.dm-home #chat-title .avatar { flex-shrink: 0; }
  #app.dm-home #chat-title .sub { display: none; }
  #app.dm-home #chat-header .header-spacer { display: none; }
  /* Server channels use the same full-page list/detail flow as DMs. */
  #app.server-home #left-wrap { transition: none; }
  #app.server-home:not(.channel-list-open) #left-wrap { display: none; }
  #app.server-home.channel-list-open #left-wrap {
    position: relative; inset: auto; width: 100%; min-width: 0;
    transform: none; box-shadow: none;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-dark);
  }
  #app.server-home.channel-list-open #rail { display: flex; }
  #app.server-home.channel-list-open #sidebar { width: 100%; min-width: 0; flex: 1; }
  /* Installed iOS can soften the first strip below its status bar even when
     safe-area-inset-top is zero. Keep interactive header content below it;
     this gutter is additional to the existing device safe-area, not a notch guess. */
  .apple-home-screen #app.server-home #sidebar-header {
    padding-top: 16px; min-height: 64px; flex-shrink: 0;
    background: var(--bg-dark);
  }
  .apple-home-screen #app.server-home #rail { padding-top: 28px; }
  #app.server-home.channel-list-open #main, #app.server-home.channel-list-open #drawer-backdrop { display: none; }
  #app.server-home .server-mobile-menu { display: inline-flex; flex-shrink: 0; margin-left: 6px; }
  #app.server-home .server-header-btn { padding-left: 8px; }
  #app.server-home #chat-header { gap: 6px; padding: 0 8px; }
  #app.server-home #chat-header > .icon-btn { flex-shrink: 0; }
  #app.server-home #chat-title { flex: 1; overflow: hidden; }
  #app.server-home #chat-header .header-spacer { display: none; }
  #app.server-home { position: relative; overflow: hidden; }
  #app.server-home.server-swiping #left-wrap {
    display: flex; position: absolute; inset: 0; width: 100%; height: 100%;
    transform: none; transition: none; box-shadow: none;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  }
  #app.server-home.server-swiping #rail { display: flex; }
  #app.server-home.server-swiping #sidebar { width: 100%; min-width: 0; flex: 1; }
  #app.server-home.server-swiping #main { display: flex; position: absolute; inset: 0; width: 100%; height: 100%; }
  #app.server-home.server-swiping #drawer-backdrop { display: none; }
  #app.server-home #messages, #app.server-home #sidebar-content { touch-action: pan-y; }
  .msg-row { padding: 2px 12px; gap: 12px; }
  #composer { margin: 0 10px 12px; }
  #messages { padding-top: 8px; }
  .list-item, .member-row { padding-top: 10px; padding-bottom: 10px; } /* bigger touch targets */
  .channel-row .list-item { min-height: 44px; height: auto; }
  .category-row { min-height: 44px; }
  .category-header { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  /* keep toasts clear of the fixed header + drawer button */
  #toast-root { top: 60px; }
  /* enlarge small tap targets to ~44px without shifting layout */
  .sidebar-section .section-actions button { width: 44px; height: 44px; padding: 0; margin: 0; }
  #sidebar-header .invite-chip { padding: 12px 8px; margin: -8px 0; }
}

/* touch devices: reveal hover-only sidebar controls. Message actions are NOT
   force-shown here — they'd squish every bubble; long-press opens the context menu instead. */
@media (hover: none), (pointer: coarse) {
  .list-item .del, .list-item .cog { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .rail-item, .rail-folder-button, .rail-item .pill, #left-wrap { transition: none; }
}

@media (max-width: 820px) {
  .msg-row { padding: 2px 10px; }
  .msg-content { font-size: 15px; }
}
/* Notification actions wrap into touch-sized rows on narrow settings pages. */
.push-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 16px; }
.push-actions .btn { min-height: 44px; white-space: normal; }
/* Threads are channel conversations, not a second heavyweight message renderer. */
.thread-context { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; background: var(--bg-dark); }
.thread-parent { display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 55%; min-height: 44px; padding: 0; border: 0; background: none; color: var(--text-normal, #dcddde); }
.thread-parent span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.thread-status { flex: 1; min-width: 0; font-size: 12px; color: #c2c5cb; }
.thread-row { margin-left: 22px; }
.thread-row .list-item { min-width: 0; }
.thread-form { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.thread-form > label:not(.thread-private-choice) { display: flex; flex-direction: column; gap: 8px; }
.thread-form input:not([type=checkbox]), .thread-form select { width: 100%; min-width: 0; min-height: 44px; }
.thread-form input[type=number], .thread-form select { padding: 10px 12px; border: 1px solid var(--bg-darkest); border-radius: 4px; background: var(--bg-darkest); color: var(--text); font: inherit; }
.modal .thread-form > label { margin: 0; color: #c2c5cb; }
.modal .thread-private-choice, .modal .thread-member-picker label { display: flex; text-transform: none; font-size: 14px; font-weight: 400; }
.thread-form .form-error { color: #f28b8e; font-size: 13px; }
.thread-form input:disabled, .thread-form select:disabled { opacity: .65; }
.thread-private-choice { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.thread-member-picker { max-height: 180px; overflow-y: auto; }
.thread-member-picker label { display: flex; align-items: center; gap: 10px; min-height: 44px; overflow-wrap: anywhere; }
.thread-source { margin: 0; padding: 8px 12px; background: var(--bg-darkest); max-height: 90px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: #c2c5cb; }
.thread-tabs, .thread-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.thread-tabs .active { background: var(--bg-active); color: #fff; }
.message-thread-link { display: flex; align-items: center; gap: 8px; max-width: 100%; min-height: 44px; padding: 6px 10px; margin-top: 6px; background: var(--bg-dark); border: 0; border-radius: 6px; color: #d2d6ff; text-align: left; }
.message-thread-link span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-thread-link span:last-child { flex: none; color: #c2c5cb; font-size: 12px; }
.thread-context button, .message-thread-link, .thread-tabs button, .thread-actions button { cursor: default; }
