/* ============================================
   PYRAMID · Component styles
   ============================================ */

/* ==== Spaces Rail ==== */
.rail {
  background: var(--bg-0);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

.rail-home {
  width: 48px; height: 48px;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--accent) 0%, hsl(calc(var(--accent-h) + 20) var(--accent-s) calc(var(--accent-l) - 10%)) 100%);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.25s var(--spring-bounce);
  position: relative;
  box-shadow: 0 4px 16px -4px var(--accent-glow);
}
.rail-home:hover { transform: translateY(calc(-2px * var(--motion))) rotate(calc(-3deg * var(--motion))); }
.rail-home:active { transform: scale(0.94); }

.rail-divider {
  width: 32px; height: 2px;
  background: var(--border);
  border-radius: 2px;
  margin: 4px 0;
}

.rail-item {
  width: 48px; height: 48px;
  border-radius: var(--r-lg);
  background: var(--bg-2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  position: relative;
  transition: border-radius 0.28s var(--spring-bounce),
              background 0.2s var(--spring-soft),
              transform 0.2s var(--spring-bounce);
  font-weight: 600;
  font-size: 15px;
  color: var(--fg);
  overflow: visible;
}
.rail-item:hover {
  border-radius: calc(var(--r-lg) * 0.7);
  background: var(--bg-3);
  transform: scale(calc(1 + 0.04 * var(--motion)));
}
.rail-item.active {
  border-radius: calc(var(--r-lg) * 0.6);
}
.rail-item.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 28px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  animation: slide-right 0.3s var(--spring-bounce);
}

/* Pyramid space icon: triangular shape */
.rail-item .pyramid-shape {
  width: 30px; height: 28px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rail-item.unread::after {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 8px;
  background: var(--fg);
  border-radius: 0 2px 2px 0;
}

.rail-badge {
  position: absolute;
  bottom: -2px; right: -4px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  background: var(--danger);
  color: white;
  border-radius: var(--r-pill);
  font-size: 10px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg-0);
  animation: bounce-in 0.4s var(--spring-bounce);
}

.rail-add {
  width: 48px; height: 48px;
  border-radius: var(--r-lg);
  background: var(--bg-2);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 22px;
  transition: all 0.25s var(--spring-bounce);
  border: 1.5px dashed var(--border-strong);
}
.rail-add:hover {
  border-radius: calc(var(--r-lg) * 0.7);
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: scale(calc(1 + 0.06 * var(--motion))) rotate(calc(90deg * var(--motion)));
}

/* Tooltip on rail items */
.rail-tooltip {
  position: absolute;
  left: 64px;
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  background: var(--bg-0);
  color: var(--fg);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s var(--spring-bounce);
  z-index: 100;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.rail-item:hover .rail-tooltip,
.rail-home:hover .rail-tooltip,
.rail-add:hover .rail-tooltip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* ==== Rooms panel ==== */
.rooms {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.rooms-header {
  height: 52px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.rooms-header-title {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rooms-header-icon {
  width: 24px; height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), hsl(calc(var(--accent-h) + 30) var(--accent-s) calc(var(--accent-l) - 8%)));
  flex-shrink: 0;
}

.rooms-search {
  padding: 10px 12px;
  position: relative;
}
.rooms-search input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border-radius: var(--r-sm);
  background: var(--bg-2);
  border: 1px solid transparent;
  color: var(--fg);
  font-size: 13px;
  outline: none;
  transition: all 0.2s var(--spring-soft);
}
.rooms-search input:focus {
  background: var(--bg-0);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.rooms-search-icon {
  position: absolute;
  left: 21px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-dim);
  pointer-events: none;
}

.rooms-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.rooms-section {
  margin-top: 8px;
}
.rooms-section-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
  cursor: pointer;
  user-select: none;
}
.rooms-section-head:hover { color: var(--fg-muted); }
.rooms-section-head .chevron {
  transition: transform 0.25s var(--spring-bounce);
}
.rooms-section-head.collapsed .chevron { transform: rotate(-90deg); }
.rooms-section-head .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-dim);
  font-weight: 500;
}
.rooms-section-head .add-btn {
  opacity: 0;
  transition: opacity 0.15s;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  color: var(--fg-muted);
}
.rooms-section-head:hover .add-btn { opacity: 1; }
.rooms-section-head .add-btn:hover { background: var(--bg-hover); color: var(--accent); }

.room-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: var(--row-pad-y) var(--row-pad-x);
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--fg-muted);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.18s var(--spring-soft);
  position: relative;
  min-height: 32px;
}
.room-item:hover {
  background: var(--bg-hover);
  color: var(--fg);
}
.room-item.active {
  background: var(--accent-soft);
  color: var(--fg);
  font-weight: 600;
}
.room-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.room-item.unread { color: var(--fg); font-weight: 600; }
.room-item.unread .room-icon { color: var(--fg); }

.room-icon {
  width: 16px; height: 16px;
  color: var(--fg-dim);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.room-item.active .room-icon { color: var(--accent); }
.room-item:hover .room-icon { color: var(--fg); }

.room-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.room-badge {
  min-width: 18px; height: 18px;
  padding: 0 5px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--r-pill);
  font-size: 10px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.room-badge.mention { background: var(--danger); color: white; }

.room-item .hover-actions {
  display: none;
  gap: 2px;
}
.room-item:hover .hover-actions { display: flex; }
.room-item:hover .room-badge { display: none; }

.room-item .hover-action {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  color: var(--fg-dim);
  border-radius: 4px;
}
.room-item .hover-action:hover { background: var(--bg-active); color: var(--fg); }

/* DM avatar in rooms list */
.room-item .dm-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 10px;
  position: relative;
}
.room-item .dm-avatar .presence-dot {
  width: 8px; height: 8px;
  border-width: 2px;
  bottom: -1px; right: -1px;
}

/* ==== User panel at bottom of rooms ==== */
.user-panel {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.user-panel .avatar {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, #ff6b9d, #c471f5);
  font-size: 13px;
  position: relative;
}
.user-info { flex: 1; min-width: 0; cursor: pointer; }
.user-info:hover .user-name { color: var(--accent); }
.user-name {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: color 0.15s;
}
.user-status {
  font-size: 11px;
  color: var(--fg-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; gap: 4px;
}

.user-actions { display: flex; gap: 2px; }

/* ==== Chat main ==== */
.chat {
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  min-width: 0;
  overflow: hidden;
}

.chat-header {
  height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-1);
  z-index: 2;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  min-width: 0;
}
.chat-header-title .room-icon { color: var(--fg-dim); }

.chat-header-topic {
  color: var(--fg-muted);
  font-size: 13px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.chat-header-actions { display: flex; gap: 2px; margin-left: auto; }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}

.date-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.msg-group {
  padding: 4px 20px;
  display: flex;
  gap: 14px;
  position: relative;
  transition: background 0.1s;
}
.msg-group:hover { background: var(--bg-2); }

.msg-group + .msg-group { margin-top: 2px; }
.msg-group.has-avatar { margin-top: var(--msg-gap); }

.msg-avatar-col {
  width: 38px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding-top: 2px;
}

.msg-avatar {
  width: 38px; height: 38px;
  border-radius: var(--r-base);
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.2s var(--spring-bounce);
}
.msg-avatar:hover { transform: scale(calc(1 + 0.06 * var(--motion))); }

.msg-timestamp-col {
  width: 38px;
  font-size: 10px;
  color: var(--fg-dim);
  text-align: center;
  padding-top: 4px;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg-group:hover .msg-timestamp-col { opacity: 1; }

.msg-body { flex: 1; min-width: 0; }

.msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.msg-author {
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.msg-author:hover { text-decoration: underline; }
.msg-time {
  font-size: 11px;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
}

.msg-text {
  font-size: 14px;
  color: var(--fg);
  word-wrap: break-word;
  line-height: 1.55;
}
.msg-text code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.msg-text a { color: var(--accent); text-decoration: none; }
.msg-text a:hover { text-decoration: underline; }
.msg-text .mention {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 500;
  cursor: pointer;
}
.msg-text .mention:hover {
  background: var(--accent);
  color: var(--accent-fg);
}

.msg-image {
  margin-top: 6px;
  border-radius: var(--r-base);
  overflow: hidden;
  max-width: 420px;
  height: 220px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-in;
  transition: transform 0.2s var(--spring-soft);
}
.msg-image:hover { transform: translateY(calc(-2px * var(--motion))); }
.msg-image-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
  background: rgba(0,0,0,0.5);
  padding: 3px 8px;
  border-radius: 4px;
  position: absolute;
  bottom: 10px; left: 10px;
}

/* Reactions */
.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  cursor: pointer;
  transition: all 0.2s var(--spring-bounce);
  user-select: none;
}
.reaction:hover {
  transform: translateY(calc(-1px * var(--motion))) scale(calc(1 + 0.04 * var(--motion)));
  border-color: var(--accent);
}
.reaction.mine {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.reaction .emoji { font-size: 14px; }
.reaction .count { font-variant-numeric: tabular-nums; }

.reaction-add {
  width: 24px; height: 22px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-pill);
  color: var(--fg-dim);
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s var(--spring-bounce);
}
.msg-group:hover .reaction-add { opacity: 1; }
.reaction-add:hover { color: var(--accent); border-color: var(--accent); transform: rotate(calc(90deg * var(--motion))); }

/* Hover actions popup on message */
.msg-actions {
  position: absolute;
  top: -14px;
  right: 32px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--r-base);
  padding: 2px;
  display: none;
  gap: 1px;
  box-shadow: var(--shadow-lg);
  z-index: 3;
}
.msg-group:hover .msg-actions {
  display: flex;
  animation: pop-in 0.18s var(--spring-bounce);
}
.msg-action {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  transition: all 0.15s;
  position: relative;
}
.msg-action:hover { background: var(--bg-hover); color: var(--fg); }
.msg-action.emoji-btn:hover { color: var(--accent); }

/* Composer */
.composer-wrap {
  padding: 0 16px 12px;
  flex-shrink: 0;
}
.composer {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: calc(var(--r-base) + 4px);
  transition: all 0.2s var(--spring-soft);
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer-input-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px 4px 4px;
  min-height: 40px;
}
.composer-input-row .composer-plus {
  width: 30px; height: 30px;
  flex-shrink: 0;
}
.composer-inline-tools {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
  padding-right: 2px;
  border-right: 1px solid var(--border);
  margin-right: 4px;
}
.composer-inline-tools .icon-btn {
  width: 26px; height: 26px;
}
.composer-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--fg);
  font-size: 14px;
  resize: none;
  min-height: 22px;
  max-height: 200px;
  padding: 4px 2px;
  line-height: 1.5;
}
.composer-input::placeholder { color: var(--fg-dim); }

.composer-send {
  width: 30px; height: 30px;
  border-radius: calc(var(--r-sm) - 2px);
  background: var(--bg-3);
  color: var(--fg-dim);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s var(--spring-bounce);
  flex-shrink: 0;
}
.composer-send.active {
  background: var(--accent);
  color: var(--accent-fg);
  transform: scale(calc(1 + 0.05 * var(--motion)));
}
.composer-send.active:hover {
  transform: scale(calc(1 + 0.1 * var(--motion))) rotate(calc(-15deg * var(--motion)));
  box-shadow: 0 4px 12px -2px var(--accent-glow);
}

.composer-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 10px 8px;
}
.composer-toolbar .icon-btn { width: 28px; height: 28px; }
.composer-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-dim);
  font-family: var(--font-mono);
}

/* ==== Members panel (right) ==== */
.members {
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.members-header {
  height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}
.members-header .count { color: var(--fg-dim); font-weight: 500; }
.members-list { flex: 1; overflow-y: auto; padding: 8px; }

.member-section-head {
  padding: 8px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.member-item:hover { background: var(--bg-hover); }
.member-item .avatar {
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  font-size: 11px;
  position: relative;
}
.member-info { flex: 1; min-width: 0; }
.member-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.member-note {
  font-size: 11px;
  color: var(--fg-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.member-item.offline .avatar { opacity: 0.5; }
.member-item.offline .member-name { color: var(--fg-muted); }

/* ==== Toolbar (top-right in chat) ==== */
.topic-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: var(--bg-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-muted);
}
