/* Community: global chat, groups, direct messages, friends. Built only from the design tokens in styles.css, so themes and palettes apply. */

/* ---------- Navigation ---------- */
/* Let the page column shrink below the width of a scrolling tab strip, otherwise a phone gets sideways scrolling. */
.shell > .main, .community, .community-body { min-width: 0; }
.ctabs { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: thin; }
.ctabs .tab { text-decoration: none; white-space: nowrap; gap: 0.4rem; }
.ctabs .tab[aria-current='page'] { color: var(--accent-strong); border-bottom-color: var(--accent-strong); }
.nav-badge, .tab-badge, .tab-dot, .count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-grid; place-items: center; flex: none;
  background: var(--accent-strong); color: var(--surface); font-size: 0.7rem; font-weight: 700; line-height: 1;
}
.nav a .nav-badge { margin-left: auto; }
.tab-badge { margin-left: 0.15rem; }
.tabbar a { position: relative; }
.tab-dot { position: absolute; top: 5px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px; font-size: 0.62rem; }

/* ---------- Chat thread (global, group and direct) ---------- */
.chat-card { overflow: hidden; }
.chat-head { padding: 1rem 1.25rem 0.75rem; border-bottom: 1px solid var(--border); align-items: flex-start; }
.chat-head h2 { margin: 0; }
.chat-head p { margin: 0.15rem 0 0; }
.chat { position: relative; display: flex; flex-direction: column; height: clamp(360px, calc(100vh - 330px), 720px); min-height: 0; }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0.5rem 0.5rem 0.75rem; overscroll-behavior: contain; }
.chat-scroll:focus-visible { outline-offset: -3px; }
.chat-list { display: grid; gap: 1px; }
.chat-older { display: flex; margin: 0.25rem auto 0.5rem; }
.chat-empty { text-align: center; padding: 2.5rem 1rem; margin: 0; }
.chat-day { display: flex; align-items: center; gap: 0.75rem; margin: 0.9rem 0.5rem 0.3rem; color: var(--muted); font-size: 0.74rem; font-weight: 650; }
.chat-day::before, .chat-day::after { content: ''; height: 1px; background: var(--border); flex: 1; }
.msg { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 0.7rem; padding: 0.3rem 0.5rem; border-radius: var(--radius-sm); align-items: start; }
.msg:hover, .msg:focus-within { background: var(--surface-2); }
.msg.mine { background: var(--accent-wash); }
.msg.mine:hover, .msg.mine:focus-within { background: var(--accent-soft); }
.msg.compact { padding-top: 0; padding-bottom: 0.05rem; }
.msg-gutter { display: grid; place-items: start center; }
.msg-time-only { opacity: 0; font-size: 0.66rem; padding-top: 0.2rem; }
.msg:hover .msg-time-only, .msg:focus-within .msg-time-only { opacity: 1; }
.msg-body { min-width: 0; }
.msg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem; font-size: 0.9rem; }
.msg-head time { color: var(--muted); font-size: 0.74rem; }
.msg-name { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: var(--text); cursor: pointer; }
.msg-name:hover { text-decoration: underline; }
.msg-text { margin: 0.05rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; line-height: 1.45; }
.msg-deleted { color: var(--muted); font-style: italic; }
.msg-edited { margin-left: 0.4rem; }
.msg-seen { display: block; text-align: right; }
.msg-actions { display: flex; gap: 0.1rem; opacity: 0; transition: opacity 0.12s; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: 1; } .msg-time-only { opacity: 1; } }
.msg-action { min-height: 30px; min-width: 30px; padding: 0 0.35rem; color: var(--muted); }
.msg-edit { display: grid; gap: 0.4rem; }
.msg-edit textarea { min-height: 64px; }
.chat-typing { padding: 0 1.1rem 0.35rem; min-height: 1.3em; }
.chat-pill { position: absolute; left: 50%; bottom: 4.6rem; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.35rem 0.8rem; border: 0; border-radius: 999px; background: var(--accent-strong); color: var(--surface); font: inherit; font-size: 0.8rem; font-weight: 650; box-shadow: var(--shadow-pop); cursor: pointer; }
.chat-pill .icon { transform: rotate(90deg); }
.chat-notice { padding: 0.75rem 1rem; border-top: 1px solid var(--border); background: var(--warn-soft); color: var(--warn); font-size: 0.88rem; }
.chat-composer { display: flex; align-items: flex-end; gap: 0.5rem; padding: 0.65rem; border-top: 1px solid var(--border); background: var(--surface); }
.chat-composer textarea { flex: 1; resize: none; min-height: 40px; max-height: 140px; line-height: 1.4; }
.chat-count { align-self: center; white-space: nowrap; }
.chat-send { padding: 0 0.85rem; }

/* ---------- People ---------- */
.people .person, .person { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.person-main { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; padding: 0.15rem; border: 0; border-radius: var(--radius-sm); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.person-main:hover { background: var(--surface-2); }
.person-text { display: grid; gap: 0.1rem; min-width: 0; }
.person-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-meta { display: inline-flex; align-items: center; gap: 0.3rem; }
.reasons { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.15rem; }
.reason { padding: 0.05rem 0.5rem; border-radius: 999px; background: var(--accent-wash); color: var(--accent-strong); font-size: 0.72rem; font-weight: 600; }
.person-actions { flex: none; }
.find-form { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; align-items: center; }
.find-form .topsearch { flex: 1; max-width: none; }
.suggest h2 { margin: 0 0 0.5rem; }
.suggest .list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.25rem 1rem; }
.profile-card { display: grid; gap: 0.6rem; min-width: min(420px, 80vw); }
.profile-head { display: flex; align-items: center; gap: 1rem; }
.profile-head h3, .profile-head p { margin: 0; }
.profile-bio { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

/* ---------- Groups ---------- */
.groups.card { padding: 0.25rem 1.25rem; }
.group-item { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.group-main { display: flex; align-items: center; gap: 0.85rem; flex: 1; min-width: 0; color: inherit; text-decoration: none; padding: 0.15rem; border-radius: var(--radius-sm); }
.group-main:hover { background: var(--surface-2); }
.group-text { display: grid; gap: 0.1rem; min-width: 0; }
.group-title { font-weight: 650; }
.group-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.group-actions { flex: none; }
.group-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.group-head h1 { margin: 0; }
.group-head p { margin: 0.25rem 0 0; }
.group-about { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Direct messages ---------- */
.dm-layout { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 1rem; height: clamp(420px, calc(100vh - 290px), 760px); }
.dm-list, .dm-thread { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.dm-list-head { padding: 0.9rem 1rem; border-bottom: 1px solid var(--border); }
.dm-list-head h2 { margin: 0; font-size: 1.05rem; }
.dm-items { list-style: none; margin: 0; padding: 0.25rem; overflow-y: auto; flex: 1; }
.dm-empty { padding: 1rem; }
.dm-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem; border-radius: var(--radius-sm); color: inherit; text-decoration: none; }
.dm-item:hover { background: var(--surface-2); }
.dm-item[aria-current='page'] { background: var(--accent-wash); }
.dm-item-text { display: grid; min-width: 0; flex: 1; }
.dm-item-text strong, .dm-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-preview.unread { color: var(--text); font-weight: 650; }
.dm-item-meta { display: grid; justify-items: end; gap: 0.25rem; flex: none; }
.dm-head { padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border); }
.dm-who { display: inline-flex; align-items: center; gap: 0.6rem; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; padding: 0.1rem; border-radius: var(--radius-sm); }
.dm-who:hover { background: var(--surface-2); }
.dm-back { display: none; }
.dm-thread .chat { flex: 1; height: auto; }
.dm-thread .empty { margin: auto; }

/* ---------- Moderation ---------- */
.mod-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.9rem; }
.mod-report { display: grid; gap: 0.6rem; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.mod-report p { margin: 0; }
.mod-quote { margin: 0; padding: 0.5rem 0.9rem; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.mod-context { margin: 0.4rem 0 0; padding-left: 1.1rem; font-size: 0.88rem; color: var(--muted); }

/* ---------- Small screens ---------- */
@media (max-width: 800px) {
  /* Fit the chat panels between the header and the bottom tab bar so the message box is always reachable. */
  .community > .page-head p { display: none; }
  .community > .page-head { margin-bottom: 0.5rem; }
  .chat { height: clamp(300px, calc(100dvh - 300px), 640px); }
  .chat-card { display: flex; flex-direction: column; height: max(340px, calc(100dvh - 285px)); }
  .chat-card .chat { flex: 1; height: auto; }
  .chat-head { padding: 0.75rem 1rem 0.6rem; }
  .msg { grid-template-columns: 32px minmax(0, 1fr) auto; gap: 0.55rem; }
  .dm-layout { grid-template-columns: 1fr; height: max(340px, calc(100dvh - 285px)); }
  .dm-layout.has-thread .dm-list { display: none; }
  .dm-layout:not(.has-thread) .dm-thread { display: none; }
  .dm-back { display: inline-flex; }
  .person, .group-item { flex-wrap: wrap; }
  .person-actions, .group-actions { width: 100%; justify-content: flex-end; }
  .find-form { flex-wrap: wrap; }
}
