/* ============================================================
   CHIRP — App Layout
   ============================================================ */

/* ── App shell ── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Server Rail (far left) ── */
.server-rail {
  width: 72px;
  flex-shrink: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}
.server-rail::-webkit-scrollbar { display: none; }

.rail-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: border-radius 0.2s cubic-bezier(.22,.68,0,1.2), background 0.2s;
  flex-shrink: 0;
  overflow: hidden;
  border: none;
  outline: none;
}
.rail-btn:hover,
.rail-btn.active {
  border-radius: 16px;
}
.rail-btn:hover { background: var(--brand); }
.rail-btn.active { background: var(--brand); border-radius: 16px; }
.rail-btn svg { width: 26px; height: 26px; fill: #fff; transition: transform 0.15s; }
.rail-btn:hover svg { transform: scale(1.1); }

.rail-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Active indicator (pill on the left) */
.rail-btn::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 4px;
  height: 20px;
  background: #fff;
  border-radius: 0 2px 2px 0;
  transition: transform 0.2s cubic-bezier(.22,.68,0,1.2), height 0.2s;
}
.rail-btn:hover::before { transform: translateY(-50%) scaleY(1); height: 8px; }
.rail-btn.active::before { transform: translateY(-50%) scaleY(1); height: 40px; }

.rail-separator {
  width: 32px;
  height: 2px;
  background: var(--divider);
  border-radius: 1px;
  flex-shrink: 0;
}

/* DM button special */
.rail-dm-btn {
  background: var(--bg-secondary);
  color: var(--brand);
}
.rail-dm-btn svg { fill: var(--brand); }
.rail-dm-btn:hover { background: var(--brand); color: #fff; }
.rail-dm-btn:hover svg { fill: #fff; }

/* Unread badge */
.rail-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: var(--text-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  border: 2px solid var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ── Sidebar (second column) ── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  height: 48px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s;
}
.sidebar-header:hover { background: var(--bg-modifier-hover); }
.sidebar-header svg { width: 16px; height: 16px; fill: var(--text-muted); }

/* Server banner at top of channel sidebar */
.server-banner {
  width: 100%;
  height: 80px;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

.sidebar-search {
  margin: 8px 8px 0;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: text;
  flex-shrink: 0;
}
.sidebar-search svg { width: 14px; height: 14px; fill: var(--text-muted); flex-shrink: 0; }

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 8px;
}

/* Nav items (DM panel) */
.nav-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 15px;
  gap: 10px;
  margin-bottom: 2px;
  transition: background 0.1s, color 0.1s;
  position: relative;
}
.nav-item:hover { background: var(--bg-modifier-hover); color: var(--text-normal); }
.nav-item.active { background: var(--bg-modifier-selected); color: var(--channel-selected); }
.nav-item svg { width: 22px; height: 22px; fill: currentColor; flex-shrink: 0; }
.nav-item .badge {
  margin-left: auto;
  background: var(--text-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* DM Section header */
.dm-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.dm-section-header .icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
  display: flex;
  align-items: center;
}
.dm-section-header .icon-btn:hover { color: var(--text-normal); }
.dm-section-header .icon-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* DM user items */
.dm-item {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  gap: 10px;
  transition: background 0.1s;
  position: relative;
  margin-bottom: 1px;
}
.dm-item:hover { background: var(--bg-modifier-hover); }
.dm-item.active { background: var(--bg-modifier-selected); }
.dm-item:hover .dm-close-btn { opacity: 1; }

.dm-close-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  padding: 2px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  transition: opacity 0.15s, color 0.15s;
}
.dm-close-btn:hover { color: var(--text-normal); }
.dm-close-btn svg { width: 14px; height: 14px; fill: currentColor; }

.dm-info { min-width: 0; flex: 1; }
.dm-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.dm-item.active .dm-name,
.dm-item:hover .dm-name { color: var(--text-normal); }
.dm-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

/* Channel category */
.category-header {
  display: flex;
  align-items: center;
  padding: 16px 6px 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  gap: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
  position: relative;
}
.category-header:hover { color: var(--text-normal); }
.category-header .caret {
  width: 12px;
  height: 12px;
  fill: currentColor;
  flex-shrink: 0;
  transition: transform 0.2s;
}
.category-header.collapsed .caret { transform: rotate(-90deg); }
.category-header .add-btn {
  margin-left: auto;
  opacity: 0;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  display: flex;
}
.category-header:hover .add-btn { opacity: 1; }
.category-header .add-btn svg { width: 14px; height: 14px; fill: currentColor; }

/* Channel item */
.channel-item {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  gap: 6px;
  color: var(--channel-default);
  font-weight: 500;
  font-size: 15px;
  transition: background 0.1s, color 0.1s;
  margin-bottom: 1px;
  position: relative;
}
.channel-item:hover { background: var(--bg-modifier-hover); color: var(--channel-hover); }
.channel-item.active { background: var(--bg-modifier-selected); color: var(--channel-selected); }
.channel-item svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.channel-item .channel-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-item .channel-actions {
  display: none;
  gap: 2px;
  align-items: center;
  margin-left: auto;
}
.channel-item:hover .channel-actions { display: flex; }
.channel-item .channel-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
  display: flex;
}
.channel-item .channel-actions button:hover { color: var(--text-normal); }
.channel-item .channel-actions svg { width: 14px; height: 14px; fill: currentColor; }
.channel-unread { font-weight: 700; color: var(--text-normal); }
.channel-unread-dot {
  position: absolute;
  left: -2px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 8px;
  background: var(--text-normal);
  border-radius: 2px;
}

/* ── User Panel (bottom left) ── */
.user-panel {
  height: 52px;
  flex-shrink: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  padding: 0 8px;
  justify-content: space-between;
  gap: 4px;
}
.user-panel-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.user-panel-info:hover { background: var(--bg-modifier-hover); }
.user-panel-details { min-width: 0; }
.user-panel-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-normal);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-panel-tag {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-panel-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-tertiary);
  overflow: hidden;
}

/* ── Top Bar ── */
.top-bar {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 16px;
  justify-content: space-between;
  border-bottom: 1px solid var(--divider);
  gap: 8px;
  z-index: 10;
}
.top-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.top-bar-channel-icon { width: 22px; height: 22px; fill: var(--text-muted); flex-shrink: 0; }
.top-bar-title {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-bar-divider {
  width: 1px;
  height: 20px;
  background: var(--divider);
  flex-shrink: 0;
}
.top-bar-topic {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Friend tabs in top bar */
.friend-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}
.friend-tab {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.friend-tab:hover { background: var(--bg-modifier-hover); color: var(--text-normal); }
.friend-tab.active { background: var(--bg-modifier-selected); color: var(--text-normal); }
.friend-tab.add-friend { background: var(--text-positive); color: #fff; }
.friend-tab.add-friend:hover { background: #1a7a40; }

/* ── Right Member Panel ── */
.member-panel {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  overflow-y: auto;
  padding: 16px 8px;
}
.member-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 8px 4px;
}
.member-item {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  gap: 10px;
  transition: background 0.1s;
}
.member-item:hover { background: var(--bg-modifier-hover); }
.member-name { font-size: 15px; font-weight: 500; color: var(--text-muted); }
.member-item:hover .member-name { color: var(--text-normal); }
.member-role { font-size: 12px; color: var(--text-muted); }

/* ── Avatar ── */
.avatar {
  position: relative;
  flex-shrink: 0;
}
.avatar img,
.avatar-img {
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.avatar-initials {
  border-radius: 50%;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0;
  flex-shrink: 0;
}
.status-indicator {
  position: absolute;
  bottom: -1px;
  right: -1px;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}
.status-online  { background: var(--status-online); }
.status-idle    { background: var(--status-idle); }
.status-dnd     { background: var(--status-dnd); }
.status-offline { background: var(--status-offline); }

/* Sizes */
.av-16 { width: 16px; height: 16px; font-size: 7px; }
.av-16 .status-indicator { width: 8px; height: 8px; bottom: -2px; right: -2px; }

.av-24 { width: 24px; height: 24px; font-size: 10px; }
.av-24 .status-indicator { width: 9px; height: 9px; }

.av-32 { width: 32px; height: 32px; font-size: 13px; }
.av-32 .status-indicator { width: 11px; height: 11px; }

.av-40 { width: 40px; height: 40px; font-size: 16px; }
.av-40 .status-indicator { width: 13px; height: 13px; }

.av-48 { width: 48px; height: 48px; font-size: 20px; }
.av-48 .status-indicator { width: 15px; height: 15px; }

.av-80 { width: 80px; height: 80px; font-size: 32px; }
.av-80 .status-indicator { width: 20px; height: 20px; border-width: 3px; }

.av-100 { width: 100px; height: 100px; font-size: 40px; }
.av-100 .status-indicator { width: 22px; height: 22px; border-width: 4px; }

/* Responsive */
@media (max-width: 900px) {
  .member-panel { display: none; }
}
@media (max-width: 700px) {
  .server-rail { width: 56px; }
  .rail-btn { width: 40px; height: 40px; }
  .sidebar { width: 200px; }
}
@media (max-width: 520px) {
  .sidebar { display: none; }
}
