/* App shell: full viewport with sidebar + main */
.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

/* Sidebar: collapsible from the left – Agentic Node black */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: var(--color-header);
  color: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 32px rgba(0, 0, 0, 0.2);
  transform: translateX(-100%);
  transition: transform var(--layout-transition), box-shadow var(--layout-transition);
}

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

.sidebar-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-title {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.92;
}

.sidebar-nav {
  flex: 1;
  padding: 0.875rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-item:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.sidebar-item:active {
  background: rgba(255, 255, 255, 0.18);
}

.sidebar-item svg {
  flex-shrink: 0;
  opacity: 0.95;
}

/* Scrollable list of chat sessions (from PostgreSQL) */
.sidebar-session-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.75rem 0.5rem 0.5rem;
  margin: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Scrollbar for session list */
.sidebar-session-list::-webkit-scrollbar {
  width: 6px;
}

.sidebar-session-list::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-session-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
}

.sidebar-session-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* Empty state when no sessions */
.sidebar-session-list:empty::before {
  content: "No chats yet. Click + New chat to start.";
  display: block;
  padding: 1rem 0.75rem;
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  line-height: 1.4;
}

/* Chat session row: same visual language as .sidebar-item */
.sidebar-session-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6875rem 1rem;
  border-radius: var(--radius-md);
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  width: 100%;
  min-height: 44px;
  font-family: inherit;
  box-sizing: border-box;
}

.sidebar-session-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.08);
}

.sidebar-session-item:active {
  background: rgba(255, 255, 255, 0.16);
}

.sidebar-session-item:focus {
  outline: none;
}

.sidebar-session-item:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
  border-color: transparent;
}

.sidebar-session-item.active {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.sidebar-session-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

/* Delete: visible on hover of row, always tappable */
.sidebar-session-item-delete {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
  opacity: 0.85;
}

.sidebar-session-item:hover .sidebar-session-item-delete,
.sidebar-session-item-delete:hover,
.sidebar-session-item-delete:focus {
  color: rgba(255, 255, 255, 0.9);
  opacity: 1;
}

.sidebar-session-item-delete:hover {
  background: rgba(220, 38, 38, 0.3);
  color: #fecaca;
}

.sidebar-session-item-delete:focus {
  outline: none;
}

.sidebar-session-item-delete:focus-visible {
  outline: 2px solid rgba(254, 202, 202, 0.9);
  outline-offset: 1px;
}

.sidebar-session-item-delete svg {
  width: 16px;
  height: 16px;
  display: block;
}

.sidebar-item-logout {
  color: rgba(255, 255, 255, 0.88);
  margin-top: auto;
}

.sidebar-item-logout:hover {
  color: #fecaca;
  background: rgba(220, 38, 38, 0.2);
}

/* Main content: resizes when sidebar opens/closes so chat sits beside sidebar */
.main-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  margin-left: 0;
  transition: margin-left var(--layout-transition);
}

/* Desktop: when sidebar is open, shift chat right so it sits beside sidebar */
@media (min-width: 768px) {
  .app-shell.sidebar-open .main-content {
    margin-left: var(--sidebar-width);
  }
}

/* Overlay when sidebar is open (mobile only: tap outside to close) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity var(--layout-transition);
}

.app-shell.sidebar-open .sidebar-overlay {
  display: block;
  opacity: 1;
}

@media (min-width: 768px) {
  .app-shell.sidebar-open .sidebar-overlay {
    display: none;
  }
}
