/* ===== Social tab ===== */
.social-layout {
  display: flex;
  /* The app header stays visible on every page including Social (per
     explicit request) - height must account for it. */
  height: calc(100vh - var(--header-height) - 32px);
  gap: 0;
}

.social-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.social-sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
}
.social-sidebar-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.social-sidebar-tab.active {
  color: var(--text-main);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.social-search-row { padding: 10px; border-bottom: 1px solid var(--border-color); }
.social-search-results { max-height: 160px; overflow-y: auto; }

.social-panel-body { display: none; flex: 1; overflow-y: auto; padding: 6px; }
.social-panel-body.active { display: block; }

.social-list-subtitle {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  padding: 8px 8px 4px;
}

.social-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius-md);
}
.social-list-item:hover { background: var(--bg-panel); }

.social-list-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--bg-panel); flex-shrink: 0; }
.social-list-text { flex: 1; min-width: 0; }
.social-list-name { font-size: 13px; font-weight: 600; color: var(--text-main); }
.social-list-preview { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.social-unread-pill { background: #e0424a; color: #fff; flex-shrink: 0; }
.social-empty-hint { padding: 16px 10px; font-size: 12.5px; color: var(--text-dim); text-align: center; }

.social-chat-area { flex: 1; display: flex; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
.social-chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-dim); gap: 8px; }
.social-chat-empty i { font-size: 32px; }

.social-chat-window { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.social-chat-header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border-color); }
.social-chat-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--bg-panel); }
.social-chat-username { font-size: 14px; font-weight: 700; color: var(--text-main); }
.social-chat-status { font-size: 11px; color: var(--text-muted); }

.social-chat-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }

.social-msg { display: flex; flex-direction: column; max-width: 65%; }
.social-msg.mine { align-self: flex-end; align-items: flex-end; }
.social-msg.theirs { align-self: flex-start; align-items: flex-start; }
.social-msg-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.4;
  word-break: break-word;
  background: var(--bg-panel);
  color: var(--text-main);
}
.social-msg.mine .social-msg-bubble { background: var(--accent); color: #0f0f0f; }
.social-msg-deleted { color: var(--text-dim); font-size: 12.5px; }
.social-msg-edited { color: var(--text-dim); font-size: 10.5px; }
.social-msg-image { max-width: 220px; border-radius: 8px; margin-top: 4px; display: block; }

.social-reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  font-size: 12px;
  color: var(--text-muted);
}
.social-reply-preview button { background: none; border: none; color: var(--text-dim); cursor: pointer; }

.social-mention-autocomplete {
  position: absolute;
  bottom: 56px;
  left: 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  z-index: 10;
}

.social-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-color);
}
.social-context-menu {
  position: fixed;
  z-index: 3000;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  flex-direction: column;
  min-width: 140px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  overflow: hidden;
}
.social-context-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.social-context-menu button:hover { background: var(--bg-card); }
.social-context-menu button[data-action="delete"] { color: #ff7777; }

.social-mention {
  color: #6db4ff;
  font-weight: 600;
  cursor: pointer;
}
.social-mention:hover { text-decoration: underline; }

.social-mention-autocomplete-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-main);
}
.social-mention-autocomplete-item:hover,
.social-mention-autocomplete-item.active { background: var(--bg-card); }
.social-mention-autocomplete-item img { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }

.social-list-avatar.clickable { cursor: pointer; }

#social-confirm-actions .btn { flex: 1; }
#social-confirm-actions .btn-danger { background: #e0424a; border-color: #e0424a; color: #fff; }

/* ===== Social tab: v2 refinements ===== */

/* Badges now blue instead of red, matching the reference notification style */
.social-unread-pill,
#social-unread-badge,
#social-requests-badge,
#social-chats-badge { background: #3b82f6 !important; color: #fff !important; }

/* Status dot overlay on any avatar */
.social-avatar-wrap { position: relative; display: inline-block; flex-shrink: 0; }
.social-status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
  background: #747f8d;
}
.social-status-dot.online { background: #3ba55d; }

/* Discord-style message rows: avatar + name/time + content, everyone left-aligned */
.social-msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: socialMsgIn 0.18s ease-out;
}
@keyframes socialMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.social-msg-row .social-msg-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--bg-panel); margin-top: 2px; }
.social-msg-col { flex: 1; min-width: 0; }
.social-msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.social-msg-name { font-size: 13.5px; font-weight: 700; color: var(--text-main); }
.social-msg-name.own { color: #6db4ff; }
.social-msg-time { font-size: 10.5px; color: var(--text-dim); }
.social-msg-row .social-msg-bubble {
  display: inline-block;
  max-width: 100%;
  background: var(--bg-panel);
  padding: 7px 11px;
  border-radius: 8px;
}
.social-msg-row.own .social-msg-bubble { background: #223049; }
.social-msg-row.pending { opacity: 0.55; }

.social-msg-reply-ref {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 0 0 2px 44px;
  position: relative;
  max-width: calc(100% - 44px);
  /* No overflow/truncation here - this element positions the connector
     arrow OUTSIDE its own box (left: -18px), so overflow:hidden on it
     would clip the arrow. Truncation belongs on .social-reply-text only. */
}
.social-reply-connector {
  position: absolute;
  left: -18px;
  bottom: 4px;
  width: 14px;
  height: 12px;
  border-left: 2px solid var(--border-light);
  border-top: 2px solid var(--border-light);
  border-top-left-radius: 6px;
}
.social-reply-avatar { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.social-reply-name { font-weight: 600; color: var(--text-main); flex-shrink: 0; }
.social-reply-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0; /* flex items default to min-width:auto, which silently breaks text-overflow:ellipsis inside a flex row */
}

.social-day-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  margin: 10px 0;
}
.social-day-divider::before,
.social-day-divider::after { content: ""; flex: 1; height: 1px; background: var(--border-color); }

.social-typing-indicator {
  padding: 2px 14px;
  font-size: 11.5px;
  color: var(--text-dim);
  font-style: italic;
}

.social-attachment-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
}
.social-attachment-preview img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.social-attachment-preview .social-attachment-name { font-size: 12px; color: var(--text-main); flex: 1; }
.social-attachment-preview .social-attachment-status { font-size: 11px; color: var(--text-dim); }
.social-attachment-preview button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 14px; }

.social-list-item.active-chat {
  background: var(--bg-panel);
  box-shadow: inset 3px 0 0 #3b82f6;
}

/* Live @mention highlighting while typing - overlay technique (see js/social.js
   updateTypingHighlight). Colors match Ren's .social-mention styling in
   style.css for visual consistency with sent-message mentions. */
.social-input-wrap {
  position: relative;
  flex: 1;
}
/* Height math must exactly match the REAL current .form-control values
   (Ren's redesign uses padding:9px 11px, border:1px - see style.css line
   ~2198) - height:42px comes from Ren's own .social-chat-input-row
   .form-control rule. 42 - 2(border) - 18(padding) = 22px exactly for
   line-height, with zero leftover slack for either layer to drift into. */
.social-input-wrap #social-message-input {
  position: relative;
  background: transparent;
  color: transparent;
  caret-color: var(--text-main);
  width: 100%;
  height: 42px;
  padding: 9px 11px;
  border: 1px solid transparent;
  font-size: 14px;
  font-family: inherit;
  font-weight: 400;
  letter-spacing: normal;
  line-height: 22px;
  box-sizing: border-box;
  resize: none;
  white-space: pre;
  overflow-x: auto;
  overflow-y: hidden;
}
.social-message-highlight {
  position: absolute;
  inset: 0;
  height: 42px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 400;
  letter-spacing: normal;
  line-height: 22px;
  color: var(--text-main);
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
  box-sizing: border-box;
}
.social-message-highlight span { line-height: inherit; }
.social-message-highlight .social-mention-typing {
  color: #9ec5ff;
  background: rgba(95, 149, 239, 0.09);
  border-radius: 4px;
  /* never change glyph width here: the textarea underneath is plain weight,
     so any bold/size change would push the caret out of line with the text */
  font-weight: 400;
}

/* Mobile: show ONE pane at a time (list, or the open chat) instead of
   squeezing both side by side, which forced horizontal scrolling. */
.social-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  margin-right: 2px;
}

@media(max-width:650px) {
  .social-layout { position: relative; overflow: hidden; }
  .social-sidebar { width: 100%; }
  .social-chat-area { display: none; position: absolute; inset: 0; width: 100%; z-index: 5; }
  body.social-chat-open .social-sidebar { display: none; }
  body.social-chat-open .social-chat-area { display: flex; }
  .social-back-btn { display: inline-flex; align-items: center; }
}

.social-sidebar-tab { position: relative; transition: color .18s, background-color .18s, box-shadow .25s; }
.social-sidebar-tab.active { box-shadow: inset 0 -2px 0 var(--accent); }

.social-panel-body.active { animation: socialPanelIn .28s cubic-bezier(.22, 1, .36, 1); }
@keyframes socialPanelIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.social-list-item { transition: background-color .15s, transform .18s cubic-bezier(.22, 1, .36, 1); cursor: pointer; animation: socialListIn .32s cubic-bezier(.22, 1, .36, 1) both; }
.social-list-item:hover { transform: translateX(2px); }
.social-list-item:active { transform: scale(.985); }
.social-list-item:nth-child(2) { animation-delay: .03s; }
.social-list-item:nth-child(3) { animation-delay: .06s; }
.social-list-item:nth-child(4) { animation-delay: .09s; }
.social-list-item:nth-child(5) { animation-delay: .12s; }
.social-list-item:nth-child(n+6) { animation-delay: .15s; }
@keyframes socialListIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: none; }
}

.social-list-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.social-list-avatar, .social-msg-avatar, .social-chat-avatar { box-shadow: 0 0 0 1px var(--border-color); }

.social-unread-pill, #social-unread-badge { animation: socialPulse 2.4s ease-in-out infinite; }
@keyframes socialPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 158, 255, .5); }
  50% { box-shadow: 0 0 0 5px rgba(74, 158, 255, 0); }
}

.social-status-dot.online { box-shadow: 0 0 0 0 rgba(63, 191, 106, .6); animation: socialOnline 2.6s ease-out infinite; }
@keyframes socialOnline {
  0% { box-shadow: 0 0 0 0 rgba(63, 191, 106, .55); }
  70%, 100% { box-shadow: 0 0 0 6px rgba(63, 191, 106, 0); }
}

.social-chat-window { animation: socialChatIn .3s cubic-bezier(.22, 1, .36, 1); }
@keyframes socialChatIn {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: none; }
}

.social-chat-empty i { animation: socialFloat 3.6s ease-in-out infinite; }
@keyframes socialFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.social-msg-row { position: relative; border-radius: 8px; padding: 2px 6px; margin: 0 -6px; transition: background-color .12s; animation: socialMsgIn .3s cubic-bezier(.22, 1, .36, 1); }
.social-msg-row:hover { background: rgba(255, 255, 255, .03); }
.social-msg-row.grouped { margin-top: -6px; }
.social-msg-row.grouped .social-msg-avatar { visibility: hidden; height: 0; }
.social-msg-row.grouped .social-msg-meta { display: none; }
.social-msg-hovertime { display: none; position: absolute; left: 6px; top: 6px; width: 34px; text-align: center; font-size: 9.5px; color: var(--text-dim); }
.social-msg-row.grouped:hover .social-msg-hovertime { display: block; }
.social-msg-row .social-msg-bubble { border-radius: 4px 12px 12px 12px; transform-origin: left top; }
.social-msg-row.own .social-msg-bubble { border-radius: 12px 4px 12px 12px; transform-origin: right top; }
.social-msg-row.pending .social-msg-bubble { filter: saturate(.6); }
.social-msg-row.pending .social-msg-time::after { content: " · sending"; }

.social-typing-indicator { display: flex; align-items: center; gap: 8px; font-style: normal; animation: socialPanelIn .2s ease-out; }
.social-typing-indicator[style*="display: none"] { display: none !important; }
.social-typing-dots { display: inline-flex; align-items: center; gap: 3px; padding: 5px 8px; border-radius: 9999px; background: var(--bg-panel); }
.social-typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: socialDots 1.2s ease-in-out infinite; }
.social-typing-dots i:nth-child(2) { animation-delay: .15s; }
.social-typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes socialDots {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.social-scroll-bottom { position: absolute; left: 50%; bottom: 76px; z-index: 6; display: inline-flex; align-items: center; gap: 7px; padding: 6px 14px; border: 0; border-radius: 9999px; background: var(--accent); color: #fff; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); opacity: 0; visibility: hidden; transform: translate(-50%, 10px); transition: opacity .2s, transform .25s cubic-bezier(.22, 1, .36, 1), visibility .2s; }
.social-scroll-bottom.visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.social-scroll-bottom:hover { background: #6aaeff; }

.social-chat-input-row { gap: 10px; }
.social-chat-input-row .btn { transition: transform .12s, background-color .15s, border-color .15s; }
.social-chat-input-row .btn:hover { transform: translateY(-1px); }
.social-chat-input-row .btn:active { transform: scale(.92); }
#social-send-btn { width: 42px; padding: 0; display: grid; place-items: center; border-radius: 9999px; }
#social-send-btn i { transition: transform .2s cubic-bezier(.22, 1, .36, 1); }
#social-send-btn:hover i { transform: translate(2px, -2px) rotate(8deg); }
#social-attach-btn { width: 42px; padding: 0; display: grid; place-items: center; border-radius: 9999px; }
.social-input-wrap:focus-within .social-message-highlight { color: #fff; }

.social-context-menu { animation: socialMenuIn .14s ease-out; transform-origin: top left; }
@keyframes socialMenuIn {
  from { opacity: 0; transform: scale(.94); }
  to { opacity: 1; transform: none; }
}

.social-reply-preview, .social-attachment-preview { animation: socialPanelIn .2s ease-out; }
.social-day-divider { text-transform: uppercase; letter-spacing: .06em; font-size: 10.5px; }

@media (prefers-reduced-motion: reduce) {
  .social-list-item, .social-msg-row, .social-chat-window, .social-panel-body.active, .social-unread-pill, #social-unread-badge,
  .social-status-dot.online, .social-chat-empty i, .social-typing-dots i { animation: none !important; }
}

/* ===== Notification trail: sidebar badge -> tab -> conversation -> message ===== */
.social-list-item.has-unread { box-shadow: inset 3px 0 0 #3b82f6; background: rgba(59, 130, 246, 0.07); }
.social-list-item.has-unread .social-list-name { color: #fff; font-weight: 700; }
.social-list-item.has-unread .social-list-preview { color: var(--text-main); }
.social-list-item.is-muted { opacity: 0.65; }
.social-muted-pill { background: var(--bg-panel) !important; color: var(--text-dim) !important; flex-shrink: 0; border: 1px solid var(--border-color); }
.social-mention-pill { margin-right: 4px; }
.social-row-mute { opacity: 0; transition: opacity .15s; }
.social-list-item:hover .social-row-mute, .social-list-item.is-muted .social-row-mute, .social-row-mute:focus { opacity: 1; }
@media (hover: none) { .social-row-mute { opacity: 1; } }
#social-chat-mute-btn.is-muted { color: var(--text-dim); }

.social-new-divider { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: #6db4ff; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.social-new-divider::before, .social-new-divider::after { content: ""; flex: 1; height: 1px; background: rgba(59, 130, 246, 0.5); }
.social-msg-row.new-msg { background: rgba(59, 130, 246, 0.08); box-shadow: inset 3px 0 0 #3b82f6; transition: background 1.2s ease, box-shadow 1.2s ease; }
.social-msg-row.new-msg.seen { background: transparent; box-shadow: inset 0 0 0 transparent; }

.social-notif-btn { margin-left: auto; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.social-notif-btn:hover { color: #fff; background: var(--bg-panel); }
.social-notif-menu { position: fixed; z-index: 3000; width: 260px; background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 10px; padding: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.4); font-size: 13px; }
.social-notif-title { font-weight: 700; color: #fff; margin-bottom: 8px; }
.social-notif-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; color: var(--text-main); }
.social-notif-row select { background: var(--bg-main, #111); color: var(--text-main); border: 1px solid var(--border-color); border-radius: 6px; padding: 4px 6px; font-size: 12.5px; }
.social-notif-hint { margin-top: 6px; font-size: 11.5px; color: var(--text-dim); }

/* Calm: lists re-render often (new messages, presence), so nothing here may
   replay an entrance animation, and the status dot must not pulse. */
.social-list-item, .social-panel-body.active { animation: none !important; }
.social-status-dot.online { animation: none !important; box-shadow: none !important; }
.social-unread-pill, #social-unread-badge { animation: none !important; }

.social-msg-failed { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 12px; color: #ff8f8f; }
.social-msg-failed button { background: none; border: 0; padding: 0; color: #fff; font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
.social-msg-row.failed .social-msg-bubble { border: 1px solid rgba(255, 107, 107, .45); }
