:root .in[data-page="friends"] #center { grid-column:2/-1; min-width:0; }
:root .in[data-page="friends"] #right { display:none; }
.friends-page { display:grid; gap:14px; min-width:0; }
.friends-hero,.friends-panel {
  padding:14px;
  border:1px solid var(--line);
  border-radius:14px;
  background:var(--s1);
}
.friends-hero {
  display:flex;
  align-items:center;
  gap:12px;
  background:linear-gradient(105deg,var(--surface-tint),var(--s1));
}
.friends-hero-icon {
  display:grid;
  place-items:center;
  width:44px;
  height:44px;
  flex:none;
  border-radius:12px;
  background:var(--s1);
  color:var(--ind);
}
.friends-hero-icon .ico { width:26px; height:26px; }
:root .friends-hero h2 { margin:0 0 4px; font-size:clamp(24px,2.5vw,32px); line-height:1.2; }
.friends-hero p,.friends-panel p { margin:0; color:var(--mute); }
.friends-tabs { display:flex; flex-wrap:wrap; gap:7px; }
:root .friends-tabs button {
  display:inline-flex;
  align-items:center;
  gap:6px;
  min-height:44px;
  padding:7px 10px;
  color:var(--ink);
  background:var(--s1);
}
:root .friends-tabs button[aria-current="page"] { background:#155bb4; border-color:#155bb4; color:#fff; }
.friends-tabs .ico,.friends-panel h3 .ico,.friends-request .ico { width:17px; height:17px; flex:none; }
.friends-layout { display:grid; grid-template-columns:minmax(0,1fr) minmax(190px,235px); gap:12px; align-items:start; }
.friends-layout > .friend-tab-panel { min-width:0; margin:0; }
.friends-rail { display:grid; gap:10px; }
:root .friends-panel h3 { display:flex; gap:6px; align-items:center; margin:0; font-size:16px; }
.friends-panel h3 span:last-child:not(.ico) { margin-left:auto; color:var(--ind); }
.friends-rail p { margin:7px 0; font-size:13px; }
:root .friends-rail button { min-height:40px; padding:6px 8px; font-size:12px; }
.friends-avatar-stack { display:flex; gap:4px; flex-wrap:wrap; margin:9px 0; }
.friends-avatar,.friends-more {
  display:grid; place-items:center; flex:none;
  width:32px; height:32px; overflow:hidden; border-radius:50%;
  background:var(--surface-tint); color:var(--ind); font-weight:700; font-size:13px;
}
.friends-avatar img { width:100%; height:100%; object-fit:cover; }
.friends-request { display:grid; grid-template-columns:auto minmax(0,1fr) auto auto; align-items:center; gap:5px; margin:8px 0; font-size:12px; }
:root .friends-request button { width:29px; min-height:34px; padding:0; display:grid; place-items:center; }
.friends-chat { display:grid; grid-template-columns:minmax(160px,1fr) minmax(0,1.8fr); gap:8px; min-width:0; }
.friends-contacts,.friends-conversation { min-width:0; }
.friends-conversation-head,.friends-compose { flex:none; }
.friends-search input { width:100%; margin:0 0 8px; background:var(--s2); }
#friendsContacts { max-height:420px; overflow:auto; display:grid; gap:4px; }
#friendsContacts > p { padding:8px 0; font-size:13px; }
:root .friends-contact {
  display:grid; grid-template-columns:auto minmax(0,1fr) auto;
  align-items:center; text-align:left; width:100%; gap:7px; min-height:50px;
  padding:6px; border:1px solid transparent; color:var(--ink); background:transparent;
}
:root .friends-contact[aria-pressed="true"] { background:var(--surface-tint); border-color:var(--line2); }
.friends-contact b,.friends-contact small { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.friends-contact small { color:var(--mute); font-size:12px; font-weight:400; }
.friends-unread { font-size:11px; background:#155bb4; color:white; border-radius:999px; padding:2px 6px; }
.friends-conversation { display:flex; flex-direction:column; height:clamp(440px,calc(100dvh - 180px),820px); padding:0; overflow:hidden; }
.friends-empty { margin:auto!important; padding:12px; text-align:center; }
.friends-conversation-head { display:flex; gap:8px; align-items:center; padding:10px 12px; border-bottom:1px solid var(--line); }
.friends-conversation-head a { color:var(--ind); font-size:12px; }
:root .friends-chat-back { display:none; }
.friends-messages { flex:1; display:flex; flex-direction:column; gap:7px; min-height:0; overflow:auto; overscroll-behavior:contain; padding:12px; }
.friends-date { align-self:center; color:var(--mute); background:var(--s2); padding:2px 8px; border-radius:999px; font-size:11px; }
.friends-bubble { align-self:flex-start; min-width:0; max-width:min(90%,62ch); padding:7px 9px; background:var(--s2); border:1px solid var(--line); border-radius:10px 10px 10px 3px; }
.friends-bubble.is-mine { align-self:flex-end; background:#155bb4; color:#fff; border-color:#155bb4; border-radius:10px 10px 3px 10px; }
.friends-bubble p { color:inherit; white-space:pre-wrap; overflow-wrap:anywhere; font-size:14px; }
.friends-bubble > div { display:flex; gap:8px; align-items:center; justify-content:flex-end; margin-top:3px; color:var(--mute); font-size:11px; }
.friends-bubble.is-mine > div { color:#e4f0ff; }
:root .friends-bubble button { min-height:24px; padding:0 2px; color:var(--mute); border:0; background:none; font-size:11px; }
.friends-bubble.is-new { animation:friend-message-in .16s ease-out both; }
@keyframes friend-message-in { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:translateY(0); } }
@media(prefers-reduced-motion:reduce) { .friends-bubble.is-new { animation:none; } }
.friends-compose { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:6px; align-items:center; border-top:1px solid var(--line); padding:8px; }
.friends-compose textarea { margin:0; resize:vertical; min-width:0; }
.friends-compose button { min-height:44px; }
.friends-compose [role="status"] { grid-column:1/-1; font-size:12px; }
.friends-compose [role="status"]:empty { display:none; }
.friends-page :focus-visible { outline:2px solid var(--ind); outline-offset:1px; }
@media(max-width:1050px) {
 .friends-layout { grid-template-columns:minmax(0,1fr); }
 .friends-rail { grid-template-columns:repeat(3,minmax(0,1fr)); }
}
@media(max-width:620px) {
 .friends-tabs { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }
 .friends-chat,.friends-rail { grid-template-columns:minmax(0,1fr); }
 .friends-chat:not(.conversation-open) .friends-conversation,.friends-chat.conversation-open .friends-contacts { display:none; }
 :root .friends-chat-back { display:grid; place-items:center; min-width:38px; min-height:40px; padding:0; font-size:22px; }
 .friends-rail { display:none; }
 .friends-page { gap:10px; }
 .friends-hero { padding:10px 12px; }
 .friends-hero-icon { width:36px; height:36px; }
 .friends-hero p { display:none; }
 .friends-tabs { gap:5px; }
 :root .friends-tabs button { justify-content:flex-start; font-size:13px; }
 .friends-search input::placeholder,.friends-compose textarea::placeholder { color:var(--mute); opacity:1; }
 .friends-chat .friends-contacts { padding:10px; }
 .friends-chat.conversation-open .friends-conversation {
   position:fixed;
   inset:calc(var(--shell-header) + 6px) 6px calc(66px + env(safe-area-inset-bottom)) 6px;
   z-index:44;
   height:auto;
   min-height:0;
 }
 :root body.in[data-page="friends"]:has(.friends-chat.conversation-open) { overflow:hidden; }
 .friends-page:has(.conversation-open) :is(.friends-hero,.friends-tabs) { visibility:hidden; }
 .friends-conversation-head { padding:8px 10px; }
 .friends-messages { padding:10px; }
 .friends-compose textarea { font-size:16px; max-height:25dvh; }
}
.friends-messages > * { flex-shrink:0; }

/* Scroll through messages first, then let the page continue at either end. */
.friends-messages{overflow-x:hidden;overflow-y:auto;overscroll-behavior-y:auto;touch-action:pan-y}
.friends-compose textarea{font-size:max(16px,1em);max-height:22dvh;touch-action:auto}
.friends-conversation-head>div{min-width:0;overflow-wrap:anywhere}
@media(max-width:620px){
 .friends-chat.conversation-open .friends-conversation{
   bottom:max(calc(66px + env(safe-area-inset-bottom)),var(--friends-keyboard,0px));
 }
 .friends-compose textarea{resize:none}
}

/* Keep the composer above message effects and allow text selection and tapping. */
#mxChatPane .friends-compose{position:relative;z-index:2;isolation:isolate;background:var(--s1)}
#mxChatPane #friendsMessage{position:relative;pointer-events:auto;user-select:text;-webkit-user-select:text}
