﻿/* â”€â”€â”€ Channel sidebar â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface0);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--surface1);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 0.5rem 0 0;
  border-bottom: 1px solid var(--surface1);
  gap: 0.25rem;
  min-width: 0;
  flex-shrink: 0;
}

.server-name-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  padding: 0.6rem 0.5rem 0.6rem 0.75rem;
  border-radius: var(--radius);
  transition: background 0.1s;
  text-align: left;
}
.server-name-btn:hover:not(:disabled) { background: var(--surface1); }
.server-name-btn:disabled { cursor: default; opacity: 0.5; }

#server-name-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.server-name-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.6;
  transition: transform 0.15s;
}
.server-name-btn[data-open="true"] .server-name-chevron {
  transform: rotate(180deg);
}

.sidebar-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  margin: 4px 8px 8px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--surface1);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  gap: 0.25rem;
  z-index: 10;
}

#channel-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 0.5rem 0 72px;
  user-select: none;
}

.channel-section-label {
  display: flex;
  align-items: center;
  padding: 0.6rem 0.5rem 0.2rem 0.75rem;
  max-height: 2.2rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--subtext0);
  overflow: visible;
}

.channel-section-label-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.cat-add-channel-btn {
  visibility: hidden;
  background: none;
  border: none;
  color: var(--subtext0);
  font-size: 1rem;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.1s, background 0.1s;
}
.cat-add-channel-btn:hover { color: var(--text); background: var(--surface2); }
#channel-list li.channel-section-label:hover .cat-add-channel-btn { visibility: visible; }

#channel-list li {
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 0.35rem;
  color: var(--subtext1);
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#channel-list li::before { content: '# '; color: var(--overlay0); opacity: 0.7; }
#channel-list li.channel-section-label::before { content: none; }
#channel-list li:hover  { background: var(--surface1); color: var(--text); }
#channel-list li.channel-section-label:hover { background: none; color: var(--subtext0); cursor: default; }
#channel-list li.active { background: var(--primary); color: #fff; font-weight: 700; }
#channel-list li.active::before { color: rgba(255,255,255,0.7); opacity: 1; }

/* â”€â”€â”€ Channel drag-to-reorder (admin only) â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€ */
#channel-list li[draggable="true"] { cursor: grab; }
#channel-list li[draggable="true"]:active { cursor: grabbing; }
#channel-list li.ch-dragging { opacity: 0.35; }
#channel-list li.ch-drop-line {
  height: 2px;
  background: var(--primary);
  border-radius: 2px;
  margin: 1px 0.35rem;
  padding: 0;
  min-height: unset;
  pointer-events: none;
  cursor: default;
}
#channel-list li.ch-drop-line::before { content: none; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
  flex: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.1s;
  user-select: none;
}
.sidebar-user:hover { background: var(--surface1); }

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  overflow: hidden;
}
.sidebar-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#current-user-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* Main pane */
#chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#no-channel-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--subtext0);
  gap: 0.5rem;
  overflow: hidden;
}
#no-channel-placeholder > #placeholder-default,
#no-channel-placeholder > #placeholder-home {
  flex-shrink: 0;
}
/* Home panel mobile header — mirrors #channel-header */
#home-panel-header {
  display: flex;
  align-items: center;
  height: 48px;
  padding: 0 1rem;
  border-bottom: 1px solid var(--surface1);
  background: var(--bg);
  flex-shrink: 0;
  align-self: stretch;
  user-select: none;
}
#home-panel-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}
/* Panels fill all available height inside the placeholder */
#no-channel-placeholder > .home-panel {
  align-self: stretch;
  flex: 1;
  justify-content: flex-start;
}
#no-channel-placeholder p {
  font-size: 1rem;
  font-weight: 600;
}
.home-wordmark {
  width: min(260px, 60%);
  opacity: 0.18;
  user-select: none;
  pointer-events: none;
  filter: grayscale(1);
}

/* ── Homepage sidebar nav items ──────────────────────────── */
#channel-list li.home-nav-item {
  padding: 0;
  margin: 1px 0.35rem;
  border-radius: 6px;
  cursor: default;
  overflow: visible;
}
#channel-list li.home-nav-item::before { content: none; }
#channel-list li.home-nav-item:hover { background: none; }

.home-nav-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--subtext1);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s, color 0.1s;
}
.home-nav-btn svg { flex-shrink: 0; opacity: 0.75; }
.home-nav-btn:hover {
  background: var(--surface1);
  color: var(--text);
}
.home-nav-btn:hover svg { opacity: 1; }
.home-nav-btn.active {
  background: var(--primary);
  color: #fff;
}
.home-nav-btn.active svg { opacity: 1; }

#channel-list li.home-nav-divider-item {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 0.4rem 0.75rem;
  padding: 0;
  border-radius: 1px;
  cursor: default;
  pointer-events: none;
}
#channel-list li.home-nav-divider-item::before { content: none; }
#channel-list li.home-nav-divider-item:hover { background: rgba(255,255,255,0.06); }

#channel-list li.home-dm-header {
  margin-top: 0.4rem;
}

#channel-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Back arrow: hidden everywhere; mobile.css un-hides it inside ≤480px */
.mobile-back-arrow {
  display: none;
}

#channel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 1rem;
  border-bottom: 1px solid var(--surface1);
  background: var(--bg);
  flex-shrink: 0;
  user-select: none;
}

#channel-name-label {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}
#channel-name-label::before { content: '# '; color: var(--primary-text); }

/* Messages */
#message-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0 80px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
/* Spacer that fills free space above messages, pushing them to the bottom
   when history is short. Collapses to 0 when content overflows (many msgs). */
#message-list::before {
  content: '';
  flex: 1;
  min-height: 0;
}

.load-more-btn {
  align-self: center;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: var(--radius);
  color: var(--subtext0);
  padding: 0.4rem 1rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 600;
  margin-bottom: 0.5rem;
  transition: background 0.15s;
}
.load-more-btn:hover { background: var(--surface1); }

.message {
  display: flex;
  gap: 0.6rem;
  padding: 0.2rem 1rem;
  margin-top: 0.75rem;
  position: relative;
  z-index: 0;
}
.message:first-child { margin-top: 0; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
  text-transform: uppercase;
}

.message-body {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  flex: 1;
  min-width: 0;
}

.message-meta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.message-author {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--primary-text);
}
.message-time {
  font-size: 0.72rem;
  color: var(--overlay0);
}
.message-content {
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}
.message-body > .message-content + .message-content {
  margin-top: 3px;
}

/* ── Markdown rendered elements ─────────────────────────────────────────── */
.message-content a {
  color: var(--primary);
  text-decoration: underline;
  word-break: break-all;
}
.message-content a:hover { opacity: 0.85; }

.message-content code.msg-code {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--surface1);
  color: var(--text);
}

.message-content pre.msg-pre {
  margin: 0.4rem 0;
  padding: 0.65rem 0.85rem;
  border-radius: 6px;
  background: var(--surface1);
  overflow-x: auto;
  white-space: pre;
}
.message-content pre.msg-pre code.msg-code {
  background: none;
  padding: 0;
  font-size: 0.83em;
  border-radius: 0;
}

.message-content blockquote.msg-blockquote {
  margin: 0.2rem 0;
  padding: 0.2rem 0.75rem;
  border-left: 3px solid var(--primary);
  color: var(--subtext0);
}

.message-body > .msg-row + .msg-row {
  margin-top: 3px;
}

/* Hover timestamp shown on continuation messages (not the first in a block) */
.msg-hover-time {
  position: absolute;
  right: 100%;
  top: 5px;
  padding-right: 0.6rem;
  font-size: 0.62rem;
  color: var(--subtext0);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.1s;
}
.msg-row + .msg-row:hover .msg-hover-time {
  opacity: 0.65;
}

/* Full-width square row hover */
/* First row: highlight meta (username) and first msg-row as two separate full-width bands */
.message:has(.message-meta + .msg-row:hover) > .message-body > .message-meta {
  position: relative;
  z-index: 0;
}
.message:has(.message-meta + .msg-row:hover) > .message-body > .message-meta::before,
.message-meta + .msg-row:hover::before {
  content: '';
  position: absolute;
  top: 0; bottom: -0.1rem;
  left: calc(-1rem - 34px - 0.6rem);
  right: -1rem;
  background: var(--msg-hover);
  z-index: -1;
  pointer-events: none;
}
/* Continuation rows: extend full width behind just that row */
.msg-row + .msg-row:hover::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: calc(-1rem - 34px - 0.6rem);
  right: -1rem;
  background: var(--msg-hover);
  z-index: -1;
  pointer-events: none;
}

/* ── Message action buttons (edit / delete on hover) ── */
.msg-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  z-index: 0;
}
.msg-row > .message-content {
  flex: 1;
  min-width: 0;
}

.msg-actions {
  position: absolute;
  right: 4px;
  top: -2px;
  display: none;
  gap: 2px;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: 6px;
  padding: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  z-index: 10;
}
@media (hover: hover) and (pointer: fine) {
  .msg-row:hover .msg-actions { display: flex; }
}

.msg-action-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  font-size: 0.88rem;
  line-height: 1;
  color: var(--subtext0);
  transition: background 0.12s, color 0.12s;
}
.msg-action-btn:hover { background: var(--surface2); color: var(--text); }
.msg-action-delete { color: var(--red); }
.msg-action-delete:hover { background: var(--red); color: #fff; }

.message-edited-tag {
  font-size: 0.7rem;
  color: var(--overlay0);
  margin-left: 0.3rem;
  font-style: italic;
}

.msg-edit-input {
  flex: 1;
  min-width: 0;
  background: var(--surface1);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  color: var(--text);
  font-size: inherit;
  font-family: inherit;
  line-height: 1.5;
  padding: 1px 6px;
  outline: none;
  box-shadow: 0 0 0 3px rgba(79,70,229,0.18);
}

.msg-edit-hint {
  font-size: 0.7rem;
  color: var(--subtext0);
  margin-left: 0.5rem;
  white-space: nowrap;
  align-self: center;
}

/* Typing bar */
#typing-bar {
  min-height: 1.4rem;
  padding: 0.15rem 1.75rem;
  font-size: 0.8rem;
  color: var(--subtext0);
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 0;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-right: 7px;
  flex-shrink: 0;
}
.typing-dots span {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--subtext0);
  animation: typing-pulse 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-pulse {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.35; }
  30%            { transform: translateY(-4px); opacity: 1;    }
}

.typing-avatars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-right: 6px;
  flex-shrink: 0;
}
.typing-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 0.48rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
  text-transform: uppercase;
}
.typing-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Message panel (floating over message list) */
#message-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
}

#message-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  margin: 4px 12px 8px 8px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--surface1);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

#message-input {
  flex: 1;
  border: none;
  outline: none;
  box-shadow: none;
  background: transparent;
  resize: none;
  overflow: hidden;
  line-height: 2;
  min-height: 2.2rem;
  max-height: 200px;
  overflow-y: auto;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  padding: 0;
}
#message-input:focus { border: none; box-shadow: none; }

#no-send-notice {
  margin: 4px 8px 8px;
  padding: 0.6rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--surface1);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}



@keyframes pop-in {
  from { opacity: 0; transform: scale(0.88) translateY(4px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

/* ── DM channel-name-label: suppress '# ' in DM mode ──────────────────── */
#channel-name-label[data-dm="true"]::before { content: none; }

/* ── Home nav active state for parent <li> ─────────────────────────────── */
#channel-list li.home-nav-item.active { background: var(--surface1); }
#channel-list li.home-nav-item.active:hover { background: var(--surface1); }
#channel-list li.home-nav-item.active .home-nav-btn {
  background: var(--primary);
  color: #fff;
}

/* ── Notification badge on Requests button ─────────────────────────────── */
.home-nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--red, #e3342f);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  margin-left: auto;
  flex-shrink: 0;
}

/* ── DM conversation items ─────────────────────────────────────────────── */
#channel-list li.home-dm-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  margin: 1px 0.35rem;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  overflow: hidden;
  white-space: nowrap;
}
#channel-list li.home-dm-item::before { content: none; }
#channel-list li.home-dm-item:hover { background: var(--surface1); }
#channel-list li.home-dm-item.active { background: var(--primary); }
#channel-list li.home-dm-item.active .dm-item-name { color: #fff; }
#channel-list li.home-dm-item.active .dm-item-preview { color: rgba(255,255,255,0.65); }

.dm-item-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  overflow: hidden;
  background: var(--surface2);
}
.dm-item-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dm-item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.dm-item-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dm-item-preview {
  font-size: 0.75rem;
  color: var(--subtext0);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#channel-list li.home-dm-empty {
  padding: 0.5rem 0.75rem;
  color: var(--subtext0);
  font-size: 0.82rem;
  font-style: italic;
  cursor: default;
}
#channel-list li.home-dm-empty::before { content: none; }
#channel-list li.home-dm-empty:hover { background: none; }

/* ── Home panels (Friends / Requests) ───────────────────────────────────── */
.home-panel {
  width: 100%;
  padding: 1.5rem 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-sizing: border-box;
}

.home-panel-heading {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--surface1);
}

.home-panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--surface1);
  flex-shrink: 0;
}
.home-panel-header-row .home-panel-heading {
  border-bottom: none;
  padding-bottom: 0;
  margin: 0;
}

/* ── Add Friend inline bar ─────────────────────────────────────────────── */
.add-friend-bar {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex-shrink: 0;
}

.add-friend-input {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--surface2);
  background: var(--surface1);
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.add-friend-input:focus { border-color: var(--primary); }

.add-friend-results {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
}

.add-friend-result-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  transition: background 0.1s;
}
.add-friend-result-item:hover { background: var(--surface1); }
.add-friend-searching,
.add-friend-no-results {
  color: var(--subtext0);
  font-size: 0.82rem;
  justify-content: center;
  font-style: italic;
}

.home-panel-empty,
.home-panel-loading {
  color: var(--subtext0);
  font-size: 0.9rem;
  text-align: center;
  margin-top: 2rem;
}

.home-panel-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* ── Friend / Request rows ─────────────────────────────────────────────── */
.home-friend-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  transition: background 0.1s;
}
.home-friend-row:hover { background: var(--surface1); }

.home-friend-name {
  flex: 1;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-friend-action {
  flex-shrink: 0;
}

/* Smaller action button variant */
.btn-sm {
  padding: 0.25rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 5px;
}

