/* ---------------------------------------------------------------
   Sidebar
--------------------------------------------------------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow: hidden;
}

/* ---------------------------------------------------------------
   Sidebar header — logo + close button
--------------------------------------------------------------- */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
}

.sidebar-logo svg {
  flex-shrink: 0;
}

.sidebar-wordmark {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  line-height: 1;
}

.sidebar-close:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* ---------------------------------------------------------------
   New chat button
--------------------------------------------------------------- */
.new-chat-btn {
  margin: 8px 12px 12px;
  padding: 10px 14px;
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.new-chat-btn:hover {
  background: var(--color-border);
  border-color: var(--color-primary);
}

/* ---------------------------------------------------------------
   Chat list
--------------------------------------------------------------- */
.chat-list-label {
  padding: 4px 16px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

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

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-list::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 7px 6px 7px 10px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  color: var(--color-text-muted);
  transition: background 0.12s, color 0.12s;
}

.chat-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.chat-item.active {
  background: var(--color-surface-2);
  color: var(--color-text);
  font-weight: 500;
}

/* Drag handle for pinned chats */
.drag-handle {
  cursor: grab;
  color: var(--color-text-muted);
  font-size: 14px;
  padding: 0 2px;
  flex-shrink: 0;
  user-select: none;
  opacity: 0.7;
}
.drag-handle:hover { opacity: 1; color: var(--color-text); }
.chat-item.dragging { opacity: 0.4; }
.chat-item.drag-over { border-top: 2px solid var(--color-primary); }

/* Three-dot menu in sidebar */
.chat-dot-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0.45;
  transition: opacity 0.12s, background 0.12s;
}
.chat-item:hover .chat-dot-btn,
.chat-dot-btn:focus { opacity: 1; }
.chat-dot-btn:hover { background: var(--color-surface-2); color: var(--color-text); opacity: 1; }

/* Section labels */
.chat-list-section {
  padding: 10px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-list-section:first-child { padding-top: 4px; }

.section-toggle {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
}
.section-toggle:hover { color: var(--color-text); }

/* Dropdown menu */
.sidebar-menu {
  position: fixed;
  z-index: 200;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 4px 0;
  min-width: 160px;
}

.sidebar-menu-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--color-text);
  transition: background 0.12s;
}
.sidebar-menu-item:hover { background: var(--color-surface-2); }
.sidebar-menu-danger { color: var(--color-danger); }
.sidebar-menu-danger:hover { background: rgba(255, 77, 109, 0.1); }

/* Apps nav link (styled as a button so middle-click works) */
.sidebar-apps-btn {
  display: block;
  margin: 0 12px 8px;
  padding: 8px 14px;
  background: none;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sidebar-apps-btn:hover { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-primary); }

/* Shared-with-me items */
.shared-item {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 7px 6px 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text-muted);
  transition: background 0.12s, color 0.12s;
}
.shared-item:hover,
.shared-item.active { background: var(--color-surface-2); color: var(--color-text); }
.shared-item.active { font-weight: 500; }
.shared-item-owner {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-left: auto;
  flex-shrink: 0;
  white-space: nowrap;
  padding-right: 2px;
}
.shared-item:hover .chat-dot-btn { opacity: 1; }
.shared-item:hover .shared-item-owner { display: none; }

/* ---------------------------------------------------------------
   Sidebar footer — username + logout
--------------------------------------------------------------- */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sidebar-username {
  font-size: 13px;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 12px;
  font-family: inherit;
  padding: 5px 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.logout-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

/* ---------------------------------------------------------------
   Mobile overlay
--------------------------------------------------------------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
}

@media (max-width: 639px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .sidebar-close {
    display: block;
  }
}
