/* ==========================================================================
   IRONITT v2 — Communication (first slice: the conversation frame)
   --------------------------------------------------------------------------
   Owns the frame every conversation shares — the channel / whisper header,
   the chat column and the composer — and, on desktop, hands navigation to
   the shell's chats column (css/v2/shell.css, js/shell.js).

   Flat, like the v3 design: the header is a bar with a hairline under it,
   not a card floating over the messages, and the composer is one round
   field. Messages, voice, friends and posts keep their legacy styling for
   now (later slices).
   ========================================================================== */

/* ---- Desktop: the chats column is the navigator ----------------------- */
/* While the chats column is open it lists every whisper, Notes and the
   nest's channels, and the rail lists the nests; the view's own strips
   would only repeat them. Collapsed (or too narrow for the column) they
   come back, and so does the section bar. */
@media (min-width: 1001px) {
  #app:not(.chats-collapsed) :is(.server-diamond-strip, .channel-sidebar, .dm-avatar-strip) { display: none; }
  #app:not(.chats-collapsed)[data-tab="communication"] .comm-bar { display: none; }
  #app:not(.chats-collapsed)[data-tab="communication"] .main-content { padding-top: 0; }
}

/* ---- Conversation column ---------------------------------------------- */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header,
.dm-thread-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
  min-height: 64px;
  padding: 0 var(--space-lg);
  border-bottom: 1px solid var(--border-color);
}
.chat-header { justify-content: space-between; }
.dm-thread-header.dm-thread-header--mobile-only { display: none; }

/* ---- Composer: one round field ---------------------------------------- */
.chat-input-area {
  position: relative;
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-lg) var(--space-lg);
}
.chat-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: var(--field-h);
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  transition: border-color var(--transition-fast);
}
.chat-input-wrapper:focus-within { border-color: var(--border-strong); }
.chat-input-wrapper input {
  flex: 1;
  min-width: 0;
  padding: var(--space-xs) var(--space-sm);
  background: none;
  border: none;
  font-size: var(--font-size-md);
}
.chat-input-wrapper input:focus { border: none; }
.chat-input-wrapper button {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-round);
  color: var(--text-muted);
  font-size: 18px;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.chat-input-wrapper button:hover { color: var(--text-primary); background: var(--bg-hover); }
.thread-input-area .chat-input-wrapper { width: 100%; }

/* ---- Phones ------------------------------------------------------------ */
@media (max-width: 768px) {
  .dm-thread-header.dm-thread-header--mobile-only { display: flex; }
}
@media (max-width: 640px) {
  .chat-header,
  .dm-thread-header { min-height: 56px; padding: 0 var(--space-md); }
  .chat-input-area { padding: var(--space-xs) var(--space-md) var(--space-md); }
}
@media (max-width: 380px) {
  .chat-input-area { padding: var(--space-xs) var(--space-sm) var(--space-sm); }
}

/* ==========================================================================
   Friends — one list of people, like Home's feed rows
   ========================================================================== */
.friends-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
  padding: var(--space-lg) var(--space-lg) var(--space-md);
}
.friends-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-stretch: 125%;
  font-size: var(--font-size-title);
  line-height: 30px;
}

.friends-sub-tabs {
  position: relative;
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
}
.friends-sub-indicator {
  position: absolute;
  top: 4px;
  left: 0;
  height: calc(100% - 8px);
  border-radius: var(--radius-pill);
  background: var(--bg-hover);
  pointer-events: none;
  /* Slides and resizes together; it is one small pill, so the width step
     costs next to nothing. */
  transition: transform var(--transition-normal), width var(--transition-normal);
}
.friends-sub-tab {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  transition: color var(--transition-fast);
}
.friends-sub-tab:not(.active):hover { color: var(--text-primary); }
.friends-sub-tab.active {
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
  cursor: default;
  pointer-events: none;
}
.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-light);
  color: var(--accent-color);
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-bold);
}
.light-mode .tab-count { color: var(--accent-solid); }

.add-friend-island {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  max-width: 560px;
  min-height: var(--field-h);
  margin: 0 var(--space-lg) var(--space-md);
  padding: 0 7px 0 18px;
  border-radius: var(--radius-pill);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  transition: border-color var(--transition-fast);
}
.add-friend-island:focus-within { border-color: var(--border-strong); }
.add-friend-island input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  font-size: var(--font-size-md);
}
.btn-add-friend {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-round);
  background: var(--accent-color);
  color: var(--accent-text);
  transition: background-color var(--transition-fast);
}
.btn-add-friend:hover { background: var(--accent-hover); }

.friends-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--space-lg) var(--space-lg);
}
.friends-grid-inner,
.pending-list { display: flex; flex-direction: column; max-width: 720px; }

.friend-card,
.pending-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "avatar name actions" "avatar status actions";
  column-gap: 14px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}
.friend-card:last-child,
.pending-card:last-child { border-bottom: 0; }
.friend-card-avatar,
.friend-avatar { grid-area: avatar; position: relative; width: 44px; height: 44px; }
.friend-card-avatar.offline-desaturated { opacity: 0.55; }
.friend-card-name {
  grid-area: name;
  align-self: end;
  font-weight: var(--font-weight-semibold);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.friend-card-status {
  grid-area: status;
  align-self: start;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}
.friend-card-status .status-emoji { font-size: 14px; line-height: 1; }
.friend-card-status .status-text { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }
/* The presence word is drawn from a data-* attribute the renderer already
   localised (CSS cannot reach I18n). Presence.apply() keeps this element's
   status class live (it matches [data-presence-dot]), so the word and its
   colour follow a status change without the store touching the text. */
.friend-card-presence.online::after { content: attr(data-online); }
.friend-card-presence.idle::after { content: attr(data-idle); }
.friend-card-presence.dnd::after { content: attr(data-dnd); }
.friend-card-presence.offline::after { content: attr(data-offline); }
.friend-card-presence.online { color: var(--color-online); }
.friend-card-presence.idle { color: var(--color-idle); }
.friend-card-presence.dnd { color: var(--color-dnd); }
.friend-card-presence.offline { color: var(--text-muted); }
.friend-card-presence + .status-text:not(:empty)::before { content: ' · '; }
.friend-card-divider { display: none; }

.pending-card .friend-info { grid-area: name / name / status / status; min-width: 0; }
.pending-card .friend-name { font-weight: var(--font-weight-semibold); }
.friend-status-text { font-size: var(--font-size-xs); color: var(--text-muted); }

.friend-card-actions,
.friend-actions { grid-area: actions; display: flex; gap: 4px; }
.friend-action-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-round);
  color: var(--text-muted);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.friend-action-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.friend-action-btn.accept { background: var(--accent-color); color: var(--accent-text); }
.friend-action-btn.accept:hover { background: var(--accent-hover); }
.friend-action-btn.decline:hover { color: var(--color-danger); }

.pending-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 4px;
  font-family: var(--font-display);
  font-stretch: 125%;
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.pending-section-header:first-child { margin-top: 0; }

/* Quiet empty state: an icon and a sentence. */
.friends-empty {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--space-md) 0;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}
.friends-empty p { margin: 0; }

@media (max-width: 640px) {
  .friends-header { padding: var(--space-md) var(--space-md) var(--space-sm); }
  .add-friend-island { margin: 0 var(--space-md) var(--space-md); }
  .friends-grid { padding: 0 var(--space-md) var(--space-md); }
  .friend-card-actions .friend-action-btn { width: 32px; height: 32px; }
}

/* ==========================================================================
   Phones — the section menu Communication opens on: a short list, not four
   screen-filling cards
   ========================================================================== */
.comm-mobile-menu { display: none; }
@media (max-width: 768px) {
  .communication-view.comm-menu-open .comm-mobile-menu {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    height: 100%;
    min-height: 0;
    padding: var(--space-sm) var(--space-xs) var(--space-md);
    overflow-y: auto;
    animation: v2-view-fade-in var(--view-fade) ease;
  }
  .comm-menu-title {
    margin: 0;
    font-family: var(--font-display);
    font-stretch: 125%;
    font-size: var(--font-size-title);
    line-height: 30px;
    letter-spacing: -0.02em;
  }
  .comm-menu-sub { margin: 6px 0 0; color: var(--text-secondary); font-size: var(--font-size-sub); }
  .comm-menu-grid { display: flex; flex-direction: column; }
  .comm-menu-btn {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "ico label chev" "ico desc chev";
    column-gap: 14px;
    align-items: center;
    padding: 14px 4px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    text-align: left;
    transition: background-color var(--transition-fast);
  }
  .comm-menu-btn:last-child { border-bottom: 0; }
  .comm-menu-btn:active { background: var(--bg-secondary); }
  .comm-menu-btn::after {
    grid-area: chev;
    content: '\f054';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 12px;
    color: var(--text-muted);
  }
  .comm-menu-ico {
    grid-area: ico;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: var(--accent-light);
    color: var(--accent-color);
    font-size: 18px;
  }
  .light-mode .comm-menu-ico { color: var(--accent-solid); }
  .comm-menu-label { grid-area: label; align-self: end; font-weight: var(--font-weight-semibold); }
  .comm-menu-desc { grid-area: desc; align-self: start; font-size: var(--font-size-xs); color: var(--text-muted); }
}

/* ==========================================================================
   Posts — a reading column of flat posts (rows with a hairline between
   them, like Home's feed), not a stack of floating cards
   ========================================================================== */
.posts-toolbar {
  display: flex;
  justify-content: center;
  flex-shrink: 0;
  padding: var(--space-md) 0 var(--space-sm);
}
.posts-filter-pills {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
}
.posts-filter-pills::-webkit-scrollbar { display: none; }
.posts-filter-indicator {
  position: absolute;
  top: 4px;
  left: 0;
  height: calc(100% - 8px);
  border-radius: var(--radius-pill);
  background: var(--bg-hover);
  pointer-events: none;
  opacity: 0;
}
.posts-filter-indicator.visible { opacity: 1; }
.posts-filter-btn {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  white-space: nowrap;
  transition: color var(--transition-fast);
}
.posts-filter-btn i { font-size: 13px; }
.posts-filter-btn:not(.active):hover { color: var(--text-primary); }
.posts-filter-btn.active {
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
  cursor: default;
  pointer-events: none;
}
.posts-filter-btn.active i { color: var(--accent-color); }

.posts-main {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.posts-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--space-md) var(--space-2xl);
}
.posts-masonry {
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
}

.post-card {
  border-bottom: 1px solid var(--border-color);
  /* Replaces .animate-card-enter's entrance (which starts at opacity 0). */
  opacity: 1;
  animation: v2-view-fade-in var(--view-fade) ease;
}
.post-card:last-child { border-bottom: 0; }
.post-card.post-card-highlight {
  border-radius: var(--radius-md);
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
  animation: post-card-highlight-pulse 1.2s ease-out 2;
}
.post-card-body { padding: 20px 0 14px; }

.post-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-sm);
}
.post-action-group { display: flex; align-items: center; gap: var(--space-md); }
.post-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  transition: color var(--transition-fast);
}
.post-action-btn i { font-size: 16px; }
.post-action-btn:hover { color: var(--text-primary); }
.post-action-btn.liked,
.post-action-btn[data-action="like"]:hover { color: var(--color-danger); }
.post-action-btn.liked i { animation: heartBounce 400ms ease; }

@media (max-width: 640px) {
  .posts-toolbar { padding: var(--space-sm) 0; }
  .posts-filter-btn { padding: 0 12px; font-size: var(--font-size-xs); }
  .posts-container { padding: 0 var(--space-xs) var(--space-xl); }
}

/* ==========================================================================
   Channel messages — one alignment for everyone. Your own groups were
   marked with a green rule and an indent, which pushed them off the column
   every other group sits on; your name is already green, that is enough.
   ========================================================================== */
.message-group {
  padding: 0;
  animation: messageIn 200ms ease forwards;
}
.servers-body.server-switching .chat-messages .message-group {
  opacity: 0;
  animation: slideUp 250ms ease forwards;
}
[data-message-display="compact"] .message-group { padding: 2px 0; margin-bottom: 2px; }

/* ---- Voice: the join button is the house button ----------------------- */
.voice-join-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  background: var(--accent-color);
  color: var(--accent-text);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}
.voice-join-btn:hover { background: var(--accent-hover); }
.voice-join-btn:active { transform: scale(0.97); }
