/* ==========================================================================
   CHAT-FREE — SIDEBAR & RAIL MODE (sidebar.css)
   ========================================================================== */

.sidebar {
  width: 260px;
  min-width: 60px;
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: width 0.28s cubic-bezier(0.2, 0, 0, 1), transform 0.28s cubic-bezier(0.2, 0, 0, 1);
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
}

/* Sidebar Top Header (Matching Grok: Logo on left, Search + Toggle on right) */
.sidebar-top {
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  transition: padding 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
  transition: opacity 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.brand-logo {
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  white-space: nowrap;
}

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

.sidebar-toggle, .sidebar-search-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.2, 0, 0, 1);
  flex-shrink: 0;
}

.sidebar-toggle:hover, .sidebar-search-btn:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.sidebar-toggle:active, .sidebar-search-btn:active {
  transform: scale(0.95);
}

/* Sidebar Nav */
.sidebar-nav {
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 38px;
  padding: 0 12px;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.18s cubic-bezier(0.2, 0, 0, 1);
  white-space: nowrap;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
  transform: translateX(2px);
}

.nav-item:active {
  transform: scale(0.97);
}

.nav-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .nav-item.active {
  background: #1f1f23;
  color: #ffffff;
}

.nav-item svg {
  flex-shrink: 0;
}

.nav-label {
  transition: opacity 0.2s cubic-bezier(0.2, 0, 0, 1);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Middle Scrollable Container (Takes remaining height in expanded mode) */
.sidebar-scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 8px;
  transition: opacity 0.2s ease;
}

/* Rail shortcuts (Directory & History) - Hidden in expanded mode */
.sidebar-rail-shortcuts {
  display: none;
}

/* Rail Spacer - Hidden in expanded mode */
.sidebar-rail-spacer {
  display: none;
}

/* ==========================================================================
   RAIL MODE (Collapsed 60px Desktop Sidebar matching Grok Images 3 & 4)
   ========================================================================== */
.sidebar.rail-mode {
  width: 60px;
  min-width: 60px;
  overflow: visible;
}

/* Hide expanded text elements smoothly */
.sidebar.rail-mode .brand-title,
.sidebar.rail-mode .nav-label,
.sidebar.rail-mode .footer-label,
.sidebar.rail-mode .user-info,
.sidebar.rail-mode .chevron-up,
.sidebar.rail-mode .sidebar-scroll-area {
  display: none !important;
}

.sidebar.rail-mode .sidebar-brand {
  display: none;
}

/* Top header stacks Toggle on top, Search right beneath it (Grok Image 4) */
.sidebar.rail-mode .sidebar-top {
  padding: 12px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.sidebar.rail-mode .sidebar-top-actions {
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  width: 100%;
}

.sidebar.rail-mode .sidebar-toggle,
.sidebar.rail-mode .sidebar-search-btn {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border-radius: 10px;
}

.sidebar.rail-mode .sidebar-toggle:hover,
.sidebar.rail-mode .sidebar-search-btn:hover {
  transform: scale(1.05);
}

/* Rail Nav items */
.sidebar.rail-mode .sidebar-nav {
  padding: 4px 0;
  align-items: center;
  gap: 6px;
}

.sidebar.rail-mode .nav-item {
  width: 38px;
  height: 38px;
  padding: 0;
  margin: 0 auto;
  justify-content: center;
  border-radius: 10px;
}

.sidebar.rail-mode .nav-item:hover {
  transform: scale(1.05);
}

/* Rail middle shortcut buttons (Folder & Clock - Grok Image 4) */
.sidebar.rail-mode .sidebar-rail-shortcuts {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border-top: 1px solid var(--border-subtle);
  margin: 6px 10px 0;
}

.sidebar.rail-mode .rail-shortcut-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.2, 0, 0, 1);
}

.sidebar.rail-mode .rail-shortcut-btn:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
  transform: scale(1.05);
}

.sidebar.rail-mode .rail-shortcut-btn:active {
  transform: scale(0.95);
}

/* Rail spacer ensures footer is ALWAYS pushed to the very bottom */
.sidebar.rail-mode .sidebar-rail-spacer {
  display: block;
  flex: 1;
  min-height: 20px;
}

/* Rail footer: Pinned to bottom, perfectly centered */
.sidebar.rail-mode .sidebar-footer {
  padding: 10px 0 14px;
  align-items: center;
  gap: 6px;
  margin-top: auto !important;
}

.sidebar.rail-mode .sidebar-footer-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  margin: 0 auto;
  justify-content: center;
  border-radius: 10px;
}

.sidebar.rail-mode .sidebar-footer-btn:hover {
  transform: scale(1.05);
}

.sidebar.rail-mode .user-profile-pill {
  width: 38px;
  height: 38px;
  padding: 0;
  margin: 0 auto;
  justify-content: center;
  border-radius: 50%;
}

.sidebar.rail-mode .user-profile-pill:hover {
  transform: scale(1.05);
}

.sidebar.rail-mode .user-avatar-sm {
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.sidebar.rail-mode .user-popover {
  left: 68px;
  bottom: 14px;
}

/* Floating Sleek Tooltips on Hover in Rail Mode */
.sidebar.rail-mode [data-tooltip] {
  position: relative;
}

.sidebar.rail-mode [data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) scale(0.92);
  background: var(--popover-bg);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.16s cubic-bezier(0.16, 1, 0.3, 1), transform 0.16s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--popover-shadow);
  z-index: 10000;
}

.sidebar.rail-mode [data-tooltip]:hover::after {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* ==========================================================================
   CHARACTERS SECTION (Grok Projects Architecture)
   ========================================================================== */
.character-section-header {
  padding: 14px 16px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-title-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.collapse-chevron {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.section-title-wrapper.collapsed .collapse-chevron {
  transform: rotate(-90deg);
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sidebar-action-icon {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
}

.sidebar-action-icon:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.character-tree-list {
  padding: 2px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 280px;
}

.character-group {
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  transition: background 0.15s ease;
}

.character-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.character-header-row:hover {
  background: var(--bg-sidebar-hover);
}

.character-header-row.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

.character-info-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.character-avatar-badge {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
}

.character-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.character-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.character-header-row:hover .character-actions,
.character-group.menu-open .character-actions {
  opacity: 1;
}

.char-action-btn {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  transition: all 0.15s ease;
}

.char-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Nested Conversations under a Character */
.character-nested-chats {
  margin-left: 20px;
  padding-left: 12px;
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
  margin-bottom: 4px;
}

.character-nested-chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.character-nested-chat-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.character-nested-chat-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 500;
}

.nested-chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.nested-chat-del {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.character-nested-chat-item:hover .nested-chat-del {
  opacity: 1;
}

.nested-chat-del:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
}

/* Chat History Section */
.sidebar-section-header {
  padding: 18px 16px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-section-header .section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.sidebar-action-btn:hover {
  color: var(--text-primary);
  background: var(--bg-sidebar-hover);
}

.chat-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-thread-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
}

.chat-thread-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.chat-thread-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 500;
}

[data-theme="dark"] .chat-thread-item.active {
  background: #1c1c20;
  color: #ffffff;
}

[data-theme="light"] .chat-thread-item.active {
  background: #e5e7eb;
  color: #111827;
}

.chat-thread-item.pinned {
  border-left: 2px solid var(--text-primary);
}

.chat-thread-title {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-thread-del {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.chat-thread-item:hover .chat-thread-del {
  opacity: 1;
}

.chat-thread-del:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
}

/* Sidebar Footer (Pinned strictly to the very bottom, Grok style) */
.sidebar-footer {
  margin-top: auto !important;
  padding: 6px 10px 12px;
  border-top: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  flex-shrink: 0;
  background: var(--bg-sidebar);
}

.user-profile-pill {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 11px;
  width: 100%;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
  position: relative;
  user-select: none;
}

.user-profile-pill:hover,
.user-profile-pill.active {
  background: var(--bg-sidebar-hover);
}

[data-theme="dark"] .user-profile-pill:hover,
[data-theme="dark"] .user-profile-pill.active {
  background: #222226;
}

.user-profile-pill:active {
  transform: scale(0.98);
}

.user-avatar-sm {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: #3b82f6;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.user-avatar-sm img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.user-info {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
}

.user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
