/* Wolf Den: one responsive layout for channels, voice, forums and settings. */
body.den-page {
  --den-rail: 64px;
  --den-sidebar: 248px;
  --den-line: var(--line-soft);
  --den-surface: var(--bg-secondary);
  overflow: hidden;
}
body.den-page .chat-app {
  display: grid;
  grid-template-columns: var(--den-rail) var(--den-sidebar) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  height: var(--den-height, 100dvh);
  min-height: 0;
  padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
}
body.den-page .chat-app > .server-rail { grid-area: 1 / 1; }
body.den-page .chat-app > .channel-sidebar { grid-area: 1 / 2; }
body.den-page .chat-app > .conversation-column {
  grid-area: 1 / 3;
  min-width: 0;
  min-height: 0;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
body.den-page .server-rail {
  display: flex;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 7px;
  gap: 10px;
  border-right: 1px solid var(--den-line);
}
body.den-page .server-orb, body.den-page .brand-server { width: 46px; height: 46px; flex: 0 0 46px; }
body.den-page .server-orb.active { box-shadow: 0 0 0 2px var(--accent-main); border-radius: 15px; }
body.den-page .channel-sidebar { min-height: 0; border-right: 1px solid var(--den-line); }
body.den-page .server-title { position: relative; min-height: 60px; padding-right: 8px; }
body.den-page .server-title-main { min-width: 0; }
body.den-page .server-title-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.den-page .channel-list { min-height: 0; overflow-y: auto; padding: 12px 8px; }
body.den-page .channel-category { margin-bottom: 16px; }
body.den-page .channel-category > header { padding: 6px 8px; }
body.den-page .channel-link { min-height: 40px; border-radius: 8px; padding: 8px 10px; gap: 9px; }
body.den-page .channel-link b { font-size: 14px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.den-page .channel-link.active { background: var(--accent-soft, rgba(61,224,196,.1)); color: var(--text-primary); box-shadow: inset 3px 0 var(--accent-main); }
body.den-page .channel-edit-link { border-radius: 6px; }
body.den-page .conversation-header { min-height: 60px; gap: 10px; padding: 8px 16px; z-index: 35; }
body.den-page .conversation-header .channel-symbol { flex: 0 0 30px; }
body.den-page .den-channel-identity { flex: 1; min-width: 0; }
body.den-page .den-channel-identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
body.den-page .channel-header-edit { font-size: 11px; }
body.den-page .connection-badge { flex: 0 0 auto; }
.den-tools { position: relative; flex: 0 0 auto; }
.den-tools > summary { display: grid; place-items: center; list-style: none; cursor: pointer; width: 44px; height: 40px; border: 1px solid var(--den-line); border-radius: 10px; color: var(--text-secondary); letter-spacing: 2px; }
.den-tools > summary::-webkit-details-marker { display: none; }
.den-tools[open] > summary { background: var(--den-surface); color: var(--accent-main); }
.den-tools-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: min(340px, calc(100vw - 28px)); max-height: min(480px, 75dvh); overflow: auto; padding: 12px; border: 1px solid var(--den-line); border-radius: 12px; background: var(--bg-secondary); box-shadow: 0 14px 40px #0006; }
.den-tools-panel > button { display: grid; place-items: center; min-width: 44px; min-height: 44px; border-radius: 8px; background: var(--bg-primary); }
.den-tools-panel .channel-searchbox { width: 100%; max-width: none; flex: 1 0 100%; }
.den-tools-panel .channel-searchbox input { display: block; font-size: 16px; }
.den-tools-panel .channel-searchbox > button { min-width: 36px; min-height: 36px; }
.den-tools-panel .channel-search-menu { position: static; width: 100%; box-shadow: none; }
.den-tools-panel .channel-searchbox:has(.channel-search-menu:not([hidden])) { flex-wrap: wrap; }
body.den-page .conversation-scroll { min-height: 0; padding: 0 12px 12px; overflow-y: auto; }
body.den-page .channel-welcome { padding: 28px 16px 20px; }
body.den-page .channel-welcome h1 { font-size: clamp(22px, 3vw, 28px); }
body.den-page .channel-welcome small { font-size: 11px; }
body.den-page .message-list { padding: 8px 0 24px; }
body.den-page .chat-message { grid-template-columns: 36px minmax(0, 1fr); gap: 12px; padding: 8px 12px; margin: 0; border-radius: 8px; }
body.den-page .message-avatar-button { align-self: start; }
body.den-page .message-avatar { width: 36px; height: 36px; border-radius: 12px; overflow: hidden; }
body.den-page .message-avatar img, body.den-page .avatar img,
body.den-page .thread-message-avatar img, body.den-page .search-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
body.den-page .chat-message header { flex-wrap: wrap; min-width: 0; gap: 4px 8px; }
body.den-page .chat-message header strong { overflow-wrap: anywhere; }
body.den-page .chat-message p { font-size: 15px; line-height: 1.55; }
body.den-page .message-actions { width: auto; margin: 0; opacity: 0; pointer-events: none; }
body.den-page .chat-message:hover .message-actions,
body.den-page .chat-message:focus-within .message-actions { opacity: 1; pointer-events: auto; }
body.den-page .message-attachments, body.den-page .message-embed, body.den-page .poll-card { min-width: 0; max-width: 100%; }
body.den-page .attachment-image img { max-width: 100%; height: auto; object-fit: contain; }
body.den-page .message-embed { border-radius: 10px; padding: 12px; }
body.den-page .message-embed-description { font-size: 13px; line-height: 1.5; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
body.den-page .message-embed-thumb { flex: 0 0 auto; }
body.den-page .poll-card { border-radius: 12px; }
body.den-page .poll-option { min-height: 44px; }
body.den-page .poll-footer { flex-wrap: wrap; gap: 8px; }
body.den-page .composer-wrap { min-width: 0; padding: 8px 16px max(10px, env(safe-area-inset-bottom, 0px)); background: var(--bg-primary); }
body.den-page .composer { min-width: 0; border: 1px solid var(--den-line); border-radius: 14px; padding: 6px; }
body.den-page .composer textarea { min-width: 0; font-size: 16px; min-height: 44px; max-height: min(160px, 30dvh); overflow-y: auto; }
body.den-page .composer-wrap > p:not(.typing-status) { display: none; }
body.den-page .account-dock { padding: 10px 8px; gap: 6px; border-top: 1px solid var(--den-line); }
body.den-page .account-dock-main { min-width: 0; }
body.den-page .account-dock-main strong, body.den-page .account-dock-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.den-page .dock-icon-btn { font-size: 10px; min-width: 32px; }
body.den-page .member-sidebar { z-index: 90; background: var(--bg-secondary); }
body.den-page .member-open { min-width: 0; }
body.den-page .member-copy { min-width: 0; }
body.den-page .member-open strong { overflow: hidden; text-overflow: ellipsis; }
body.den-page .den-drawer-close { display: none; }
body.den-page .mobile-scrim.open { z-index: 80; }
body.den-page .pins-sidebar, body.den-page .thread-sidebar { max-width: 100vw; max-height: var(--den-height, 100dvh); }
body.den-page .conversation-column > .threadlist-panel { position: absolute; top: 60px; right: 16px; z-index: 40; max-width: calc(100vw - 32px); max-height: 65dvh; overflow: auto; }
body.den-page .voice-conversation-column { grid-template-rows: auto minmax(0, 1fr) auto; }
body.den-page .call-stage { min-width: 0; min-height: 0; overflow-y: auto; }
body.den-page .call-controls { flex-wrap: wrap; }
body.den-page .voice-privacy { font-size: 11px; }
body.den-page .forum-post-card { min-width: 0; }
/* Active-call UI stays separate from the browsing sidebar. */
body.den-page .voice-panel { z-index: 65; border: 1px solid var(--den-line); border-radius: 14px; }
body.den-page .voice-panel-controls { gap: 4px; }
body.den-page .voice-panel-people { max-height: 120px; overflow-y: auto; }
body.den-page:has(.voice-panel:not([hidden])) .chat-app { padding-bottom: var(--den-call-space, 0px); }
/* Server settings: fluid forms and a stable section navigator. */
body.den-settings .settings-modal { min-width: 0; grid-template-columns: 216px minmax(0, 1fr) 280px; height: auto; min-height: 100dvh; align-items: start; }
body.den-settings .settings-nav-vertical { position: sticky; top: 0; height: 100dvh; padding: 24px 12px; gap: 24px; }
body.den-settings .settings-nav-kicker { font-size: 10px; letter-spacing: .12em; padding: 0 10px; }
body.den-settings .settings-nav-vertical a { border-radius: 8px; min-height: 40px; padding: 10px; }
body.den-settings .settings-nav-vertical a.active { background: rgba(61,224,196,.12); color: var(--accent-main); box-shadow: inset 3px 0 var(--accent-main); }
body.den-settings .settings-main { min-width: 0; padding: 32px clamp(16px, 3vw, 40px); overflow: visible; }
body.den-settings .settings-main h1 { font-size: 26px; letter-spacing: -.03em; padding-right: 36px; }
body.den-settings .settings-note { font-size: 13px; line-height: 1.6; }
body.den-settings .settings-panel { min-width: 0; border-radius: 14px; }
body.den-settings .settings-panel[hidden] { display: none; }
body.den-settings .settings-form { grid-template-columns: minmax(0, 1fr); }
body.den-settings .settings-form > * { min-width: 0; grid-column: 1; }
body.den-settings input:not([type=checkbox]):not([type=radio]), body.den-settings select, body.den-settings textarea { max-width: 100%; min-width: 0; font-size: 16px; }
body.den-settings input[type=file] { width: 100%; }
body.den-settings .inline-create-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
body.den-settings .inline-create-form > label { flex: 1 1 180px; min-width: 0; }
body.den-settings .management-row { display: flex; flex-wrap: wrap; gap: 10px; border-radius: 10px; padding: 12px; }
body.den-settings .management-row > div { min-width: 0; flex: 1 1 160px; }
body.den-settings .management-row form { min-width: 0; max-width: 100%; flex-wrap: wrap; }
body.den-settings .management-row strong { overflow-wrap: anywhere; }
body.den-settings .member-controls { display: flex; flex-wrap: wrap; gap: 8px; padding-left: 0; }
body.den-settings .invite-row { min-width: 0; flex-wrap: wrap; }
body.den-settings .permission-grid { min-width: 0; }
body.den-settings .settings-preview { min-width: 0; padding: 24px 16px; position: sticky; top: 0; }
body.den-settings .settings-close { width: 40px; height: 40px; border-radius: 10px; }
body.den-settings .den-settings-return { display: none; }
body.den-settings table { width: 100%; table-layout: fixed; overflow-wrap: anywhere; }
body.den-settings button, body.den-settings .primary-button, body.den-settings .secondary-button { min-height: 40px; }
@media (max-width: 1200px) {
  body.den-settings .settings-modal { grid-template-columns: 200px minmax(0, 1fr); }
  body.den-settings .settings-preview { grid-column: 2; position: static; margin: 0 24px 24px; border-radius: 12px; }
}
/* Same compact shell in portrait and short landscape. No user-agent sniffing. */
@media (max-width: 900px), (pointer: coarse) and (max-height: 600px) and (max-width: 1200px) {
  body.den-page .chat-app { grid-template-columns: minmax(0, 1fr); }
  body.den-page .chat-app > .conversation-column { grid-area: 1 / 1; }
  body.den-page .chat-app > .server-rail {
    display: none;
    position: fixed; top: 0; bottom: 0; left: env(safe-area-inset-left, 0px);
    width: 60px; height: var(--den-height, 100dvh); z-index: 95;
  }
  body.den-page.den-navigation-open .chat-app > .server-rail { display: flex; }
  body.den-page .channel-sidebar {
    position: fixed; top: 0; bottom: 0; left: calc(60px + env(safe-area-inset-left, 0px));
    z-index: 95; width: min(284px, calc(100vw - 80px - env(safe-area-inset-left, 0px)));
    height: var(--den-height, 100dvh); transform: translateX(calc(-100% - 80px));
    visibility: hidden; transition: transform .18s ease;
    box-shadow: 16px 0 45px #0005;
  }
  body.den-page .channel-sidebar.open { transform: none; visibility: visible; }
  body.den-page .channel-sidebar .server-title { padding-right: 38px; }
  body.den-page .den-drawer-close { display: grid; place-items: center; width: 36px; height: 36px; position: absolute; right: 2px; top: 12px; z-index: 1; font-size: 24px; background: transparent; color: var(--text-secondary); cursor: pointer; }
  body.den-page .member-sidebar { visibility: hidden; width: min(320px, calc(100vw - 24px)); }
  body.den-page .member-sidebar.open { visibility: visible; }
  body.den-page .member-sidebar[hidden] { display: none; }
  body.den-page .mobile-menu { display: grid; min-width: 44px; min-height: 44px; }
  body.den-page .conversation-header { min-height: 56px; padding: 4px 8px; gap: 6px; }
  body.den-page .connection-badge b { display: none; }
  body.den-page .channel-symbol { display: none; }
  body.den-page .connection-badge { padding: 6px; border: 0; background: transparent; }
  body.den-page .conversation-scroll { padding: 0 4px 8px; }
  body.den-page .channel-welcome { padding: 20px 12px 12px; }
  body.den-page .chat-message { gap: 8px; padding: 8px; }
  body.den-page .chat-message header { padding-right: 0; }
  /* In-flow compact tools cannot overlap neighbouring messages. */
  body.den-page .message-actions { position: relative; inset: auto; width: max-content; max-width: 100%; flex-wrap: wrap; flex-basis: auto; opacity: 1; pointer-events: auto; margin: 4px 0; padding: 0; border: 0; background: transparent; box-shadow: none; }
  body.den-page .message-actions > button { display: grid; place-items: center; min-width: 44px; min-height: 40px; padding: 4px; }
  body.den-page .message-context-menu { max-width: calc(100vw - 76px); right: 0; top: 100%; z-index: 45; }
  body.den-page .composer-wrap { padding: 6px 8px max(6px, env(safe-area-inset-bottom, 0px)); }
  body.den-page .composer { gap: 2px; flex-wrap: wrap; }
  body.den-page .composer textarea { flex: 1 1 120px; }
  body.den-page .composer button { min-width: 36px; min-height: 40px; }
  body.den-page .message-embed-thumb img { width: 56px; height: 56px; }
  body.den-page .voice-privacy { display: none; }
  body.den-page .voice-panel { left: 8px; right: 8px; bottom: max(4px, env(safe-area-inset-bottom, 0px)); width: auto; }
  body.den-page .voice-panel-head { padding: 4px 8px; }
  body.den-page .voice-panel-controls { padding: 4px 8px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  body.den-page .voice-panel-btn { min-height: 36px; }
  body.den-page .voice-panel-people { display: none; }
  body.den-settings .settings-modal { grid-template-columns: minmax(0, 1fr); display: grid; }
  body.den-settings .den-settings-return { display: block; padding: 14px 16px; color: var(--accent-main); background: var(--bg-primary); font-size: 14px; }
  body.den-settings .settings-nav-vertical { position: static; height: auto; display: flex; flex-direction: row; flex-wrap: wrap; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
  body.den-settings .settings-nav-group { display: contents; }
  body.den-settings .settings-nav-kicker { display: none; }
  body.den-settings .settings-nav-vertical a { min-height: 44px; padding: 12px; border: 1px solid var(--line-soft); }
  body.den-settings .settings-main { padding: 20px 12px; }
  body.den-settings .settings-preview { grid-column: 1; margin: 0 12px 20px; }
  body.den-settings .settings-close { display: none; }
}
@media (hover: none) and (min-width: 901px) {
  body.den-page .message-actions { position: static; opacity: 1; pointer-events: auto; width: auto; background: transparent; border: 0; box-shadow: none; }
}
@media (max-height: 500px) {
  body.den-page .channel-welcome { padding-block: 8px; }
  body.den-page .channel-welcome .welcome-symbol { display: none; }
  body.den-page .composer textarea { max-height: 80px; }
}

/* Section picker keeps settings navigation compact on a phone. */
.den-settings-mobile { display: none; }
@media (max-width: 900px) {
  body.den-settings.settings-enhanced .settings-nav-vertical { display: none; }
  body.den-settings .den-settings-mobile { display: grid; gap: 6px; padding: 12px; background: var(--bg-secondary); }
  body.den-settings .den-settings-mobile span { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
  body.den-settings .den-settings-mobile select { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--bg-primary); color: var(--text-primary); }
}
body.den-management .settings-shell { min-width: 0; width: min(1200px, calc(100% - 24px)); margin-inline: auto; }
body.den-management .settings-panel { min-width: 0; border-radius: 14px; }
body.den-management .settings-panel input, body.den-management .settings-panel select { max-width: 100%; min-width: 0; }
body.den-management .management-row { min-width: 0; flex-wrap: wrap; }
body.den-management .management-row form { min-width: 0; max-width: 100%; flex-wrap: wrap; }
body.den-management .management-row strong { overflow-wrap: anywhere; }
body.den-management .avatar img, body.den-settings .avatar img,
body.den-page .member-card .avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
@media (max-width: 900px) {
  body.den-management .settings-shell { display: block; }
  body.den-management .settings-nav { display: flex; flex-wrap: wrap; gap: 8px; }
  body.den-management input:not([type=checkbox]):not([type=radio]), body.den-management select, body.den-management textarea { font-size: 16px; }
}

.den-message-close { display: none; }
@media (max-width: 900px), (pointer: coarse) and (max-height: 600px) and (max-width: 1200px) {
  body.den-page .message-actions { margin: 0 0 0 auto; flex-shrink: 0; }
  body.den-page .message-actions > button:not([data-message-more]) { display: none; }
  body.den-page .message-actions > [data-message-more] { min-width: 36px; min-height: 36px; }
  body.den-page .message-context-menu { position: fixed; inset: auto 8px max(8px, env(safe-area-inset-bottom, 0px)); width: auto; min-width: 0; max-width: none; max-height: 65dvh; overflow-y: auto; border-radius: 16px; padding: 10px; z-index: 150; }
  body.den-page .message-context-menu button { min-height: 44px; }
  body.den-page .den-message-close { display: block; color: var(--accent-main); }
}
body.den-page .den-tools-panel .bell-dropdown {
  position: fixed;
  top: 64px;
  right: 12px;
  max-height: calc(var(--den-height, 100dvh) - 80px);
  overflow-y: auto;
}

/* Personal conversations and Friends share the Den's compact breakpoint. */
.chat-app.direct-app {
  --direct-rail-width: 56px;
  grid-template-rows: minmax(0, 1fr);
  height: var(--direct-height, 100dvh);
  padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
}
.direct-app > .server-rail { grid-area: 1 / 1; min-height: 0; overflow-y: auto; }
.direct-app > .direct-sidebar { grid-area: 1 / 2; }
.direct-app > :is(.direct-conversation-column, .friends-main, .direct-home) { grid-area: 1 / 3; min-width: 0; min-height: 0; }
.direct-app > :is(.direct-profile-panel, .friends-active) { grid-area: 1 / 4; }
.direct-app .direct-drawer-close { display: none; }
.direct-app .direct-conversation-header { gap: 6px; padding-inline: 10px; }
.direct-app .direct-identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.direct-app .direct-tools { position: relative; flex: none; }
.direct-tools > summary {
  display: grid; place-items: center; width: 40px; min-height: 40px;
  cursor: pointer; list-style: none; border: 1px solid var(--line-soft); border-radius: 8px;
}
.direct-tools > summary::-webkit-details-marker { display: none; }
.direct-tools-panel {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 40;
  width: min(290px, calc(100vw - 70px)); max-height: 60dvh; overflow: auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px;
  border: 1px solid var(--line-soft); border-radius: 10px; background: var(--bg-secondary);
}
.direct-tools-panel .channel-searchbox { width: 100%; min-width: 0; max-width: none; }
.direct-tools-panel .channel-searchbox input { display: block; width: 100%; min-width: 0; font-size: 16px; }
.direct-tools-panel .direct-header-actions { flex-wrap: wrap; }
.direct-app .direct-tools-panel .direct-header-action { display: block; }
.direct-app .group-header-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.direct-app .active-card > div { display: grid; min-width: 0; gap: 3px; overflow-wrap: anywhere; }
.direct-app .active-card small { color: var(--text-secondary); }

.direct-app .direct-conversation-column {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  position: relative;
}
.direct-app .direct-conversation-column > .call-stage {
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: clamp(220px, 52dvh, 530px);
  margin: 6px 8px 0;
  border-radius: 10px;
}
.direct-app .call-stage-header {
  position: relative; inset: auto; width: fit-content; max-width: 100%;
  flex-wrap: wrap; padding: 6px 10px;
}
.direct-app .call-stage-status {
  display: block; height: auto; min-width: 0; max-width: 100%;
  overflow-wrap: anywhere; white-space: normal; font-size: 12px;
}
.direct-app .call-participant-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  align-content: safe center;
}
.direct-app .call-participant.screen-sharing { grid-column: 1 / -1; }
.direct-app .call-participant { max-width: 680px; }
.direct-app .call-participant-media {
  aspect-ratio: auto; min-height: 0; height: clamp(76px, 31dvh, 300px);
}
.direct-app .call-participant-avatar {
  width: clamp(32px, 12dvh, 72px); height: clamp(32px, 12dvh, 72px);
  font-size: clamp(16px, 4dvh, 28px);
}
.direct-app .call-participant footer { opacity: 1; transform: none; padding: 10px 6px 4px; }
.direct-app .call-participant footer small { font-size: 11px; }
.direct-app .call-controls { flex-wrap: wrap; justify-content: center; gap: 4px; overflow: visible; padding: 5px; }
.direct-app .call-control { width: 42px; min-width: 38px; height: 40px; }
.direct-app .call-control.primary { width: auto; min-width: 44px; }
.direct-app .call-control[hidden] { display: none; }
.direct-app .call-settings {
  position: absolute; inset: 0; z-index: 6; min-height: 0;
  overflow: auto; background: var(--bg-secondary);
}
.direct-app .call-help { font-size: 10px; padding-block: 4px 6px; }
.direct-app .call-empty { min-height: 0; padding: 6px; gap: 4px; }
.direct-app .call-empty > span { width: 40px; height: 40px; font-size: 18px; }
.direct-app .call-return-notice { position: absolute; inset: 52px 8px auto; z-index: 5; }

@media (min-width: 901px) and (max-width: 1150px) {
  .chat-app.direct-app:has(.direct-profile-panel), .chat-app.friends-app { grid-template-columns: 64px 200px minmax(0, 1fr); }
  .direct-app > :is(.direct-profile-panel, .friends-active) { display: none; }
}

@media (max-width: 900px), (pointer: coarse) and (max-height: 600px) and (max-width: 1200px) {
  .chat-app.direct-app, .chat-app.direct-app:has(.direct-profile-panel) { grid-template-columns: minmax(0, 1fr); overflow: hidden; }
  .direct-app > :is(.direct-conversation-column, .friends-main, .direct-home) { grid-area: 1 / 1; }
  .direct-app > :is(.direct-profile-panel, .friends-active) { display: none; }
  .direct-app > :is(.server-rail, .direct-sidebar) { position: fixed; inset-block: 0; height: var(--direct-height, 100dvh); z-index: 95; visibility: hidden; }
  .direct-app > .server-rail { inset-inline-start: env(safe-area-inset-left, 0px); width: var(--direct-rail-width); display: flex; }
  .direct-app > .direct-sidebar {
    inset-inline-start: calc(var(--direct-rail-width) + env(safe-area-inset-left, 0px));
    width: min(280px, calc(100vw - var(--direct-rail-width) - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    transform: none;
  }
  .direct-app.direct-navigation-open > :is(.server-rail, .direct-sidebar) { visibility: visible; }
  .direct-app .mobile-menu, .direct-app .direct-drawer-close { display: grid; place-items: center; min-width: 38px; min-height: 40px; }
  .direct-app .direct-drawer-close { cursor: pointer; font-size: 20px; color: var(--text-primary); }
  .direct-app > .mobile-scrim.open { position: fixed; inset: 0; display: block; z-index: 85; background: rgba(0, 0, 0, .58); }
  .direct-app .friends-top { flex-wrap: wrap; gap: 4px; padding: 4px 8px; }
  .direct-app .friends-top-left { display: flex; align-items: center; gap: 6px; }
  .direct-app .friends-top-tabs { flex-wrap: wrap; }
  .direct-app .friends-top-tabs a { padding-inline: 6px; }
  .direct-app .friends-search-wrap input { min-width: 0; }
  .direct-app .direct-conversation-header { min-height: 46px; }
  .direct-app .direct-conversation-header > .avatar { width: 30px; height: 30px; flex: none; }
  .direct-app .connection-badge { padding: 0; border: 0; }
  .direct-app .connection-badge b { display: none; }
  .direct-app .message-composer { padding: 4px 6px; gap: 4px; }
  .direct-app .message-composer textarea { font-size: 16px; }
  .direct-app .composer-wrap { padding: 5px 8px max(5px, env(safe-area-inset-bottom, 0px)); }
  .direct-app .call-help { display: none; }
  .direct-app .direct-conversation-column > .call-stage {
    height: clamp(160px, calc(var(--direct-height, 100dvh) * .58), 420px);
  }
  .direct-app .call-participant-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(132px, 100%), 1fr));
    padding: 6px;
  }
  .direct-app .call-participant-media { height: clamp(66px, calc(var(--direct-height, 100dvh) * .30), 210px); }
}
@media (max-width: 360px) {
  .direct-app .direct-conversation-header > .avatar { display: none; }
}
@media (max-height: 430px) {
  body.den-page .conversation-header { min-height: 48px; }
  .direct-app .call-empty > span { display: none; }
  .direct-app .call-empty p { font-size: 12px; }
}

/* Keep group call labels readable on touch screens and between speech events. */
[data-group-root] .call-participant footer {
  opacity: 1;
  transform: none;
}
[data-group-root] .call-stage-header:has([data-state="connected"]) .call-stage-signal::before {
  background: var(--green);
}

/* Center compact participant tiles and keep screen shares widescreen. */
.direct-app[data-group-root] .call-participant-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: safe center;
  justify-content: center;
  gap: 8px;
  container-type: size;
}
.direct-app[data-group-root] .call-participant {
  flex: none;
  width: min(280px, calc(50% - 4px), 33dvh);
  width: min(280px, calc(50% - 4px), max(64px, calc(100cqh - 16px)));
  max-width: none;
  border-radius: 10px;
}
.direct-app[data-group-root] .call-participant-media {
  height: auto;
  aspect-ratio: 1;
}
.direct-app[data-group-root] .call-participant.screen-sharing {
  width: 100%;
  order: -1;
  background: none;
  box-shadow: none;
}
.direct-app[data-group-root] .screen-sharing .call-participant-media {
  width: min(100%, 680px, 59dvh);
  width: min(100%, 680px, max(114px, calc((100cqh - 16px) * 16 / 9)));
  margin-inline: auto;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
}
.direct-app[data-group-root] .screen-sharing footer {
  width: min(100%, 680px, 59dvh);
  width: min(100%, 680px, max(114px, calc((100cqh - 16px) * 16 / 9)));
  margin-inline: auto;
}

.group-create-dialog {
  width: min(480px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  overflow: auto;
  border: 1px solid color-mix(in srgb, var(--accent-main) 25%, transparent);
  border-radius: 16px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-shadow: 0 16px 52px rgb(0 0 0 / .45);
}
.group-create-dialog::backdrop { background: rgb(0 0 0 / .64); }
.group-create-dialog form, .group-create-name { display: grid; gap: 10px; }
.group-create-dialog h2 { margin: 0 0 4px; font-size: 1.25rem; }
.group-create-name input {
  min-width: 0;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 1rem;
}
.group-create-members {
  min-width: 0;
  max-height: min(32dvh, 250px);
  margin: 0;
  padding: 4px 8px;
  overflow: auto;
  border: 1px solid color-mix(in srgb, var(--text-secondary) 28%, transparent);
  border-radius: 8px;
}
.group-create-member {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.group-create-member input { flex: none; accent-color: var(--accent-main); }
.group-create-member small { color: var(--text-secondary); }
.group-create-dialog footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.group-create-dialog [role="alert"] { margin: 0; color: var(--alert); }

body.den-page :is(.pin-avatar, .thread-root-avatar, .mention-avatar, .call-participant-avatar) img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

/* Personal conversations and Friends share the Den's compact breakpoint. */
.chat-app.direct-app {
  --direct-rail-width: 56px;
  grid-template-rows: minmax(0, 1fr);
  height: var(--direct-height, 100dvh);
  padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
}
.direct-app > .server-rail { grid-area: 1 / 1; min-height: 0; overflow-y: auto; }
.direct-app > .direct-sidebar { grid-area: 1 / 2; }
.direct-app > :is(.direct-conversation-column, .friends-main, .direct-home) { grid-area: 1 / 3; min-width: 0; min-height: 0; }
.direct-app > :is(.direct-profile-panel, .friends-active) { grid-area: 1 / 4; }
.direct-app .direct-drawer-close { display: none; }
.direct-app .direct-conversation-header { gap: 6px; padding-inline: 10px; }
.direct-app .direct-identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.direct-app .direct-tools { position: relative; flex: none; }
.direct-tools > summary {
  display: grid; place-items: center; width: 40px; min-height: 40px;
  cursor: pointer; list-style: none; border: 1px solid var(--line-soft); border-radius: 8px;
}
.direct-tools > summary::-webkit-details-marker { display: none; }
.direct-tools-panel {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 40;
  width: min(290px, calc(100vw - 70px)); max-height: 60dvh; overflow: auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px;
  border: 1px solid var(--line-soft); border-radius: 10px; background: var(--bg-secondary);
}
.direct-tools-panel .channel-searchbox { width: 100%; min-width: 0; max-width: none; }
.direct-tools-panel .channel-searchbox input { display: block; width: 100%; min-width: 0; font-size: 16px; }
.direct-tools-panel .direct-header-actions { flex-wrap: wrap; }
.direct-app .direct-tools-panel .direct-header-action { display: block; }
.direct-app .group-header-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.direct-app .active-card > div { display: grid; min-width: 0; gap: 3px; overflow-wrap: anywhere; }
.direct-app .active-card small { color: var(--text-secondary); }

.direct-app .direct-conversation-column {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  position: relative;
}
.direct-app .direct-conversation-column > .call-stage {
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: clamp(220px, 52dvh, 530px);
  margin: 6px 8px 0;
  border-radius: 10px;
}
.direct-app .call-stage-header {
  position: relative; inset: auto; width: fit-content; max-width: 100%;
  flex-wrap: wrap; padding: 6px 10px;
}
.direct-app .call-stage-status {
  display: block; height: auto; min-width: 0; max-width: 100%;
  overflow-wrap: anywhere; white-space: normal; font-size: 12px;
}
.direct-app .call-participant-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  align-content: safe center;
}
.direct-app .call-participant.screen-sharing { grid-column: 1 / -1; }
.direct-app .call-participant { max-width: 680px; }
.direct-app .call-participant-media {
  aspect-ratio: auto; min-height: 0; height: clamp(76px, 31dvh, 300px);
}
.direct-app .call-participant-avatar {
  width: clamp(32px, 12dvh, 72px); height: clamp(32px, 12dvh, 72px);
  font-size: clamp(16px, 4dvh, 28px);
}
.direct-app .call-participant footer { opacity: 1; transform: none; padding: 10px 6px 4px; }
.direct-app .call-participant footer small { font-size: 11px; }
.direct-app .call-controls { flex-wrap: wrap; justify-content: center; gap: 4px; overflow: visible; padding: 5px; }
.direct-app .call-control { width: 42px; min-width: 38px; height: 40px; }
.direct-app .call-control.primary { width: auto; min-width: 44px; }
.direct-app .call-control[hidden] { display: none; }
.direct-app .call-settings {
  position: absolute; inset: 0; z-index: 6; min-height: 0;
  overflow: auto; background: var(--bg-secondary);
}
.direct-app .call-help { font-size: 10px; padding-block: 4px 6px; }
.direct-app .call-empty { min-height: 0; padding: 6px; gap: 4px; }
.direct-app .call-empty > span { width: 40px; height: 40px; font-size: 18px; }
.direct-app .call-return-notice { position: absolute; inset: 52px 8px auto; z-index: 5; }

@media (min-width: 901px) and (max-width: 1150px) {
  .chat-app.direct-app:has(.direct-profile-panel), .chat-app.friends-app { grid-template-columns: 64px 200px minmax(0, 1fr); }
  .direct-app > :is(.direct-profile-panel, .friends-active) { display: none; }
}

@media (max-width: 900px), (pointer: coarse) and (max-height: 600px) and (max-width: 1200px) {
  .chat-app.direct-app, .chat-app.direct-app:has(.direct-profile-panel) { grid-template-columns: minmax(0, 1fr); overflow: hidden; }
  .direct-app > :is(.direct-conversation-column, .friends-main, .direct-home) { grid-area: 1 / 1; }
  .direct-app > :is(.direct-profile-panel, .friends-active) { display: none; }
  .direct-app > :is(.server-rail, .direct-sidebar) { position: fixed; inset-block: 0; height: var(--direct-height, 100dvh); z-index: 95; visibility: hidden; }
  .direct-app > .server-rail { inset-inline-start: env(safe-area-inset-left, 0px); width: var(--direct-rail-width); display: flex; }
  .direct-app > .direct-sidebar {
    inset-inline-start: calc(var(--direct-rail-width) + env(safe-area-inset-left, 0px));
    width: min(280px, calc(100vw - var(--direct-rail-width) - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    transform: none;
  }
  .direct-app.direct-navigation-open > :is(.server-rail, .direct-sidebar) { visibility: visible; }
  .direct-app .mobile-menu, .direct-app .direct-drawer-close { display: grid; place-items: center; min-width: 38px; min-height: 40px; }
  .direct-app .direct-drawer-close { cursor: pointer; font-size: 20px; color: var(--text-primary); }
  .direct-app > .mobile-scrim.open { position: fixed; inset: 0; display: block; z-index: 85; background: rgba(0, 0, 0, .58); }
  .direct-app .friends-top { flex-wrap: wrap; gap: 4px; padding: 4px 8px; }
  .direct-app .friends-top-left { display: flex; align-items: center; gap: 6px; }
  .direct-app .friends-top-tabs { flex-wrap: wrap; }
  .direct-app .friends-top-tabs a { padding-inline: 6px; }
  .direct-app .friends-search-wrap input { min-width: 0; }
  .direct-app .direct-conversation-header { min-height: 46px; }
  .direct-app .direct-conversation-header > .avatar { width: 30px; height: 30px; flex: none; }
  .direct-app .connection-badge { padding: 0; border: 0; }
  .direct-app .connection-badge b { display: none; }
  .direct-app .message-composer { padding: 4px 6px; gap: 4px; }
  .direct-app .message-composer textarea { font-size: 16px; }
  .direct-app .composer-wrap { padding: 5px 8px max(5px, env(safe-area-inset-bottom, 0px)); }
  .direct-app .call-help { display: none; }
  .direct-app .direct-conversation-column > .call-stage {
    height: clamp(160px, calc(var(--direct-height, 100dvh) * .58), 420px);
  }
  .direct-app .call-participant-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(132px, 100%), 1fr));
    padding: 6px;
  }
  .direct-app .call-participant-media { height: clamp(66px, calc(var(--direct-height, 100dvh) * .30), 210px); }
}
@media (max-width: 360px) {
  .direct-app .direct-conversation-header > .avatar { display: none; }
}
@media (max-height: 430px) {
  body.den-page .conversation-header { min-height: 48px; }
  .direct-app .call-empty > span { display: none; }
  .direct-app .call-empty p { font-size: 12px; }
}
