/* ============================================
   SIDEBAR — Claude-inspired unified nav + conversations
   ============================================ */

/* ---- CSS Variables (sidebar-specific) ---- */
.chat-sidebar {
  --sb-bg: #f7f7f4;
  --sb-hover: rgba(0, 0, 0, 0.04);
  --sb-active: rgba(0, 0, 0, 0.07);
  --sb-text: rgb(19, 19, 19);
  --sb-text-secondary: rgb(60, 60, 58);
  --sb-text-muted: rgb(115, 113, 108);
  --sb-text-faint: rgb(143, 142, 138);
  --sb-border: rgba(31, 31, 30, 0.15);
  --sb-radius: 8px;
  --sb-transition: 300ms cubic-bezier(0.165, 0.85, 0.45, 1);

  width: 288px;
  height: 100%;
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  z-index: 10;
  border-right: 0.5px solid var(--sb-border);
  color: var(--sb-text);
  -webkit-font-smoothing: antialiased;
  scrollbar-color: rgba(31, 31, 30, 0.35) transparent;
  scrollbar-width: thin;
  transition-property: width, background-color, border-color;
  transition-duration: 300ms, 35ms, 35ms;
  transition-timing-function: cubic-bezier(0.165, 0.85, 0.45, 1), cubic-bezier(0.4, 0, 0.2, 1), cubic-bezier(0.4, 0, 0.2, 1);
  contain: layout;
}

/* ---- Strip global anchor colors inside sidebar ---- */
/* reset.css sets a { color: var(--color-primary) } which bleeds red
   into <a> based nav items and conversation links.
   :where() gives 0 specificity so element rules (.s-nav-item etc.) win. */
.chat-sidebar :where(a, a:link, a:visited, a:hover, a:active) {
  color: inherit;
  text-decoration: none;
}

/* ---- Header: wordmark + toggle ---- */
.s-header {
  padding: 16px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.s-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-width: 0;
  color: var(--sb-text);
}
.s-logo:hover { color: var(--sb-text); }

.s-logo-text {
  font-size: 17px;
  font-weight: 650;
  color: var(--sb-text);
  letter-spacing: -0.4px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--sb-transition), width var(--sb-transition);
}

.s-header-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  transition: opacity var(--sb-transition);
}

.s-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--sb-radius);
  border: none;
  background: transparent;
  color: var(--sb-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 180ms ease, color 180ms ease;
  flex-shrink: 0;
}
.s-icon-btn:hover {
  background: var(--sb-hover);
  color: var(--sb-text);
}
.s-icon-btn svg { width: 20px; height: 20px; }

/* ---- New chat button ---- */
.s-new-chat {
  margin: 2px 8px 6px;
  padding: 0 10px;
  border-radius: var(--sb-radius);
  border: none;
  background: transparent;
  color: var(--sb-text-secondary);
  font-size: 13.5px;
  font-weight: 420;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  transition: background 180ms ease;
  font-family: inherit;
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
  text-decoration: none;
}
.s-new-chat:hover { color: var(--sb-text); }
.s-new-chat:hover .s-new-chat-icon { background: rgba(0, 0, 0, 0.10); }
.s-new-chat:active .s-new-chat-icon { background: rgba(0, 0, 0, 0.14); }

.s-new-chat-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
}
.s-new-chat-icon svg { width: 14px; height: 14px; stroke-width: 2; }

.s-new-chat-label {
  transition: opacity var(--sb-transition), width var(--sb-transition);
  overflow: hidden;
}

/* ---- Nav items ---- */
.s-nav {
  padding: 0 8px 4px;
  flex-shrink: 0;
  border-bottom: 0.5px solid rgba(0,0,0,0.08);
  margin-bottom: 4px;
}

.s-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-radius: var(--sb-radius);
  cursor: pointer;
  transition: background 180ms ease;
  text-decoration: none;
  height: 36px;
  margin-bottom: 1px;
  color: var(--sb-text-secondary);
  position: relative;
  overflow: hidden;
}
.s-nav-item:hover { background: var(--sb-hover); color: var(--sb-text-secondary); }
.s-nav-item:hover .s-nav-label { color: var(--sb-text); }
.s-nav-item.active {
  background: var(--sb-active);
  color: var(--sb-text);
}
.s-nav-item.active .s-nav-label {
  color: var(--sb-text);
  font-weight: 500;
}

.s-nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.s-nav-icon svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.8;
  vector-effect: non-scaling-stroke;
}

.s-nav-label {
  font-size: 13.5px;
  font-weight: 420;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--sb-transition);
}

.s-nav-badge {
  margin-left: auto;
  background: rgb(55, 55, 52);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
  transition: opacity var(--sb-transition);
}

/* ---- More tools toggle ---- */
.s-more-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-radius: var(--sb-radius);
  cursor: pointer;
  transition: background 180ms ease;
  height: 34px;
  margin-bottom: 1px;
  user-select: none;
  color: var(--sb-text-muted);
}
.s-more-toggle:hover { background: var(--sb-hover); }

.s-more-toggle-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.s-more-toggle-icon svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.8;
}

.s-more-toggle-label {
  font-size: 13px;
  font-weight: 420;
  white-space: nowrap;
  transition: opacity var(--sb-transition);
}

.s-more-arrow {
  margin-left: auto;
  width: 14px;
  height: 14px;
  color: var(--sb-text-faint);
  transition: transform 0.25s ease, opacity var(--sb-transition);
  flex-shrink: 0;
}

.s-more-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.s-more-items.open {
  max-height: 200px;
}

/* ---- Conversations (scrollable middle) ---- */
.chat-contacts {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.08) transparent;
  transition: opacity var(--sb-transition);
  min-height: 0;
}
.chat-contacts::-webkit-scrollbar { width: 3px; }
.chat-contacts::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 3px; }

/* Conversation list container — matches shared sidebar #convoList */
.s-convos {
  padding: 4px 8px;
}

/* Conversation group labels (I dag, I går, etc.) — matches .s-group */
.s-group {
  padding: 14px 8px 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--sb-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Conversation items — matches .s-conv from shared sidebar */
.chat-sidebar .s-conv {
  display: block;
  padding: 7px 10px;
  border-radius: var(--sb-radius);
  cursor: pointer;
  transition: background 180ms ease;
  margin-bottom: 1px;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--sb-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  text-decoration: none;
}
.chat-sidebar .s-conv:visited,
.chat-sidebar .s-conv:link {
  color: var(--sb-text);
  text-decoration: none;
}
.chat-sidebar .s-conv:hover {
  background: var(--sb-hover);
  color: var(--sb-text);
}
.chat-sidebar .s-conv.active {
  background: var(--sb-active);
  color: var(--sb-text);
  font-weight: 500;
}

/* Search in conversations */
.chat-conv-search-wrap {
  padding: 0 2px 6px;
}
.chat-conv-search {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 0.5px solid rgba(0,0,0,0.12);
  border-radius: var(--sb-radius);
  background: rgba(255,255,255,0.5);
  color: var(--sb-text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 180ms ease;
}
.chat-conv-search:focus {
  border-color: rgba(0,0,0,0.25);
}
.chat-conv-search::placeholder {
  color: var(--sb-text-faint);
}

/* Show more / fewer toggle */
.chat-conv-show-more {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  height: 36px;
  border-radius: var(--sb-radius);
  cursor: pointer;
  transition: background 180ms ease;
  text-decoration: none;
  color: var(--sb-text-muted);
  font-size: 13px;
  font-weight: 420;
  margin: 4px 0 8px;
  border: none;
  background: none;
  font-family: inherit;
  width: 100%;
  text-align: left;
}
.chat-conv-show-more:hover { background: var(--sb-hover); color: var(--sb-text); }

/* ---- User footer ---- */
.s-user {
  width: 100%;
  padding: 10px 12px 14px;
  border-top: 0.5px solid rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  overflow: hidden;
  background: transparent;
  border-left: none;
  border-right: none;
  border-bottom: none;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--sb-transition);
  position: relative;
  text-align: left;
}
.s-user:hover { background: var(--sb-hover); }

.s-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: var(--sb-text-secondary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
  line-height: 1;
  letter-spacing: 0.02em;
  text-align: center;
  border: 0.5px solid transparent;
  transition: border-color 180ms ease, opacity 180ms ease;
}
.s-user:hover .s-avatar { border-color: rgba(0,0,0,0.12); opacity: 0.9; }

.s-user-info {
  flex: 1;
  min-width: 0;
  transition: opacity var(--sb-transition);
}
.s-user-name { font-size: 13px; font-weight: 500; color: var(--sb-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s-user-plan { font-size: 11px; color: var(--sb-text-muted); }

.s-user-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--sb-text-faint);
  transition: opacity var(--sb-transition);
}

/* ---- Settings dropdown ---- */
.s-dropdown {
  position: fixed;
  bottom: 60px;
  left: 8px;
  width: 272px;
  max-height: 640px;
  min-width: 128px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 0.5px solid rgba(31, 31, 30, 0.2);
  border-radius: 12px;
  box-shadow: rgba(0, 0, 0, 0.08) 0px 2px 8px 0px;
  padding: 6px;
  z-index: 50;
  overflow-x: hidden;
  overflow-y: auto;
  color: rgb(55, 55, 52);
  font-size: 14px;
  font-weight: 430;
  line-height: 19.6px;
  -webkit-font-smoothing: antialiased;
  scrollbar-width: thin;
  scrollbar-color: rgba(31, 31, 30, 0.35) transparent;
  display: none;
  opacity: 0;
  transform: translateY(4px) scale(0.98);
  transition: opacity 120ms cubic-bezier(0.16, 1, 0.3, 1), transform 120ms cubic-bezier(0.16, 1, 0.3, 1);
}
.s-dropdown.open {
  display: block;
  opacity: 1;
  transform: translateY(0) scale(1);
}
.s-dropdown.s-closing {
  display: block;
  opacity: 0;
  transform: translateY(4px) scale(0.98);
}

.s-dropdown-email {
  padding: 10px 12px 8px;
  font-size: 13px;
  color: var(--sb-text-muted);
  margin-bottom: 2px;
}
.s-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 75ms ease;
  color: rgb(55, 55, 52);
  font-size: 14px;
  font-weight: 430;
  text-decoration: none;
}
.s-dropdown-item:hover { background: rgba(0, 0, 0, 0.04); color: rgb(55, 55, 52); }
.s-dropdown-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--sb-text-muted); stroke-width: 1.8; }
.s-dropdown-item span { flex: 1; }
.s-dropdown-sep { height: 0.5px; background: rgba(0, 0, 0, 0.08); margin: 4px 6px; }

/* ============================================
   COLLAPSED STATE
   ============================================ */
.chat-sidebar.collapsed {
  width: 3.05rem;
  background-color: rgb(248, 248, 246);
  background-image: linear-gradient(to top, rgba(244, 244, 241, 0.05), rgba(244, 244, 241, 0.3));
  border-right-width: 1px;
  align-items: center;
  padding: 0;
  overflow: visible;
  min-width: 3.05rem;
  opacity: 1;
  pointer-events: auto;
}

/* Hide text elements in collapsed */
.chat-sidebar.collapsed .s-logo-text,
.chat-sidebar.collapsed .s-logo,
.chat-sidebar.collapsed .s-new-chat-label,
.chat-sidebar.collapsed .s-nav-label,
.chat-sidebar.collapsed .s-nav-badge,
.chat-sidebar.collapsed .chat-contacts,
.chat-sidebar.collapsed .s-more-toggle-label,
.chat-sidebar.collapsed .s-more-arrow,
.chat-sidebar.collapsed .s-more-items,
.chat-sidebar.collapsed .s-user-info,
.chat-sidebar.collapsed .s-user-chevron {
  display: none;
}

/* Bolder icons in collapsed rail */
.chat-sidebar.collapsed .s-nav-icon svg,
.chat-sidebar.collapsed .s-new-chat-icon svg,
.chat-sidebar.collapsed .s-more-toggle-icon svg {
  stroke-width: 2;
}

/* Header: just toggle */
.chat-sidebar.collapsed .s-header {
  padding: 14px 0 2px;
  justify-content: center;
}
.chat-sidebar.collapsed .s-header-actions {
  margin: 0 auto;
}

/* New chat: subtle accent circle */
.chat-sidebar.collapsed .s-new-chat {
  margin: 4px auto 6px;
  padding: 0;
  width: 34px;
  height: 34px;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  color: var(--sb-text-secondary);
  position: relative;
  overflow: visible;
}
.chat-sidebar.collapsed .s-new-chat:hover {
  background: transparent;
  color: var(--sb-text);
}
.chat-sidebar.collapsed .s-new-chat-icon {
  width: 24px;
  height: 24px;
}

/* Nav: full-width, centered icons */
.chat-sidebar.collapsed .s-nav {
  padding: 4px 0;
  border-bottom: none;
  margin-bottom: 0;
  width: 100%;
}
.chat-sidebar.collapsed .s-nav-item {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  margin: 2px auto;
  border-radius: 8px;
  color: var(--sb-text-muted);
  overflow: visible;
  position: relative;
}
.chat-sidebar.collapsed .s-nav-item:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--sb-text);
}
.chat-sidebar.collapsed .s-nav-item.active {
  background: rgba(0, 0, 0, 0.08);
  color: var(--sb-text);
}

/* Hide more toggle in collapsed */
.chat-sidebar.collapsed .s-more-toggle,
.chat-sidebar.collapsed .s-more-items {
  display: none;
}

/* User: compact avatar */
.chat-sidebar.collapsed .s-user {
  padding: 0;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-top: none;
  margin: auto auto 16px;
  cursor: pointer;
  position: relative;
  border-radius: 8px;
  transition: background 180ms ease;
}
.chat-sidebar.collapsed .s-user:hover {
  background: rgba(0, 0, 0, 0.06);
}
.chat-sidebar.collapsed .s-avatar {
  width: 30px;
  height: 30px;
  min-width: 30px;
  font-size: 12px;
  background: var(--sb-text);
  cursor: pointer;
}

/* Tooltips in collapsed rail */
.chat-sidebar.collapsed .s-nav-item[data-tooltip]:hover::after,
.chat-sidebar.collapsed .s-new-chat[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--sb-text);
  color: #fff;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  letter-spacing: 0.01em;
}

/* Dropdown position in collapsed state */
.chat-sidebar.collapsed ~ .chat-main .s-dropdown,
.chat-sidebar.collapsed .s-dropdown {
  left: calc(3.05rem + 4px);
  bottom: 8px;
}

/* ============================================
   SIDEBAR TOGGLE (desktop)
   ============================================ */
.chat-sidebar-toggle { display: none; }

/* ============================================
   CONV TITLE in header area
   ============================================ */
.chat-conv-title { display: none; }
.v-voksen .chat-conv-title {
  display: block;
  min-width: 0;
  max-width: 60%;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
  padding: 4px 8px;
  transition: background 0.15s;
}
.v-voksen .chat-conv-title:hover { background: rgba(0, 0, 0, 0.04); }
[data-theme="dark"] .v-voksen .chat-conv-title:hover { background: rgba(255, 255, 255, 0.06); }

/* Inline rename input */
.chat-conv-title-input {
  width: 100%;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary);
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--color-border, #e7e7e8);
  border-radius: 6px;
  padding: 2px 6px;
  outline: none;
  font-family: inherit;
}
.chat-conv-title-input:focus {
  border-color: rgba(0, 0, 0, 0.2);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .chat-conv-title-input {
  background: rgba(255, 255, 255, 0.08);
  color: #e8e8ed;
  border-color: rgba(255, 255, 255, 0.15);
}
[data-theme="dark"] .chat-conv-title-input:focus {
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

/* ============================================
   HIDDEN — kept for later reuse
   ============================================ */
.chat-sidebar-templates { display: none !important; }
#chat-template-chips { display: none !important; }

/* Hide old skole-only labels in voksen mode */
.chat-contacts-label { display: none; }
/* Keep skole labels visible for skole edition */
.v-skole .chat-contacts-label.v-skole-only { display: block; padding: 12px 10px 8px; font-size: 11px; font-weight: 600; color: var(--sb-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.chat-contacts-label-subjects { margin-top: 8px; padding-top: 0; }

/* ============================================
   MOBILE (<768px)
   ============================================ */
.s-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 9;
  opacity: 0;
  transition: opacity 200ms ease;
  -webkit-tap-highlight-color: transparent;
}
.s-backdrop.visible { opacity: 1; }

@media (max-width: 767px) {
  .chat-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform var(--sb-transition);
    width: 288px;
    max-width: calc(100vw - 60px);
    height: 100vh;
    height: 100dvh;
    box-shadow: none;
    border-right: none;
  }
  .chat-sidebar.drawer-open,
  .chat-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: rgba(0, 0, 0, 0.12) 4px 0 24px;
  }

  /* Safety: if collapsed class leaks to mobile, keep full width + hidden */
  .chat-sidebar.collapsed {
    width: 288px;
    max-width: calc(100vw - 60px);
    transform: translateX(-100%);
    background-color: var(--sb-bg);
    background-image: none;
    align-items: stretch;
    overflow: hidden;
    border-right: none;
    min-width: unset;
  }
  .chat-sidebar.collapsed.drawer-open,
  .chat-sidebar.collapsed.mobile-open {
    transform: translateX(0);
    box-shadow: rgba(0, 0, 0, 0.12) 4px 0 24px;
  }

  .s-backdrop.visible { display: block; }

  /* Bigger touch targets on mobile */
  .s-nav-item { height: 44px; }
  .s-conv { padding: 10px 10px; }
  .s-more-toggle { height: 44px; }
  .s-icon-btn { width: 44px; height: 44px; }
  .s-dropdown-item { padding: 12px 12px; }

  /* Hide desktop toggle, show mobile toggle in main */
  #chat-sidebar-toggle { display: none; }
  .chat-drawer-trigger { display: flex; }

  /* Dropdown: full-width on mobile */
  .s-dropdown {
    left: 8px;
    right: 8px;
    width: auto;
    max-width: calc(100vw - 16px);
  }

  /* Show collapsed items in mobile drawer */
  .chat-sidebar.collapsed .s-logo-text,
  .chat-sidebar.collapsed .s-logo,
  .chat-sidebar.collapsed .s-new-chat-label,
  .chat-sidebar.collapsed .s-nav-label,
  .chat-sidebar.collapsed .chat-contacts,
  .chat-sidebar.collapsed .s-user-info,
  .chat-sidebar.collapsed .s-user-chevron {
    display: unset;
  }
  .chat-sidebar.collapsed .chat-contacts {
    display: block;
  }
}

@media (min-width: 768px) {
  .chat-drawer-trigger { display: none; }
  .s-backdrop { display: none !important; }
}

/* Tablet: auto-collapse (768–1023) */
@media (min-width: 768px) and (max-width: 1023px) {
  .chat-sidebar:not(.force-expanded) {
    width: 3.05rem;
  }
  .chat-sidebar:not(.force-expanded) .s-logo-text,
  .chat-sidebar:not(.force-expanded) .s-new-chat-label,
  .chat-sidebar:not(.force-expanded) .s-nav-label,
  .chat-sidebar:not(.force-expanded) .s-nav-badge,
  .chat-sidebar:not(.force-expanded) .chat-contacts,
  .chat-sidebar:not(.force-expanded) .s-more-toggle-label,
  .chat-sidebar:not(.force-expanded) .s-more-arrow,
  .chat-sidebar:not(.force-expanded) .s-more-items,
  .chat-sidebar:not(.force-expanded) .s-user-info,
  .chat-sidebar:not(.force-expanded) .s-user-chevron {
    display: none;
  }
  .chat-sidebar:not(.force-expanded) .s-logo { display: none; }
  .chat-sidebar:not(.force-expanded) .s-header { padding: 14px 0 2px; justify-content: center; }
  .chat-sidebar:not(.force-expanded) .s-header-actions { margin: 0 auto; }
  .chat-sidebar:not(.force-expanded) .s-new-chat { margin: 4px auto 6px; padding: 0; width: 34px; height: 34px; justify-content: center; border-radius: 50%; background: transparent; }
  .chat-sidebar:not(.force-expanded) .s-nav { padding: 4px 0; border-bottom: none; margin-bottom: 0; width: 100%; }
  .chat-sidebar:not(.force-expanded) .s-nav-item { width: 34px; height: 34px; padding: 0; justify-content: center; margin: 2px auto; border-radius: 8px; color: var(--sb-text-muted); }
  .chat-sidebar:not(.force-expanded) .s-more-toggle,
  .chat-sidebar:not(.force-expanded) .s-more-items { display: none; }
  .chat-sidebar:not(.force-expanded) .s-user { padding: 12px 0 16px; justify-content: center; width: 100%; border-top: none; margin-top: auto; }
  .chat-sidebar:not(.force-expanded) .s-avatar { width: 30px; height: 30px; min-width: 30px; font-size: 12px; background: var(--sb-text); }
}

/* ============================================
   DRAWER TRIGGER (mobile hamburger in main)
   ============================================ */
.chat-drawer-trigger {
  display: none;
  position: absolute;
  top: 8px;
  left: 4px;
  z-index: 10;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--sb-text-muted);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.chat-drawer-trigger:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--sb-text);
}
.chat-drawer-backdrop {
  display: none;
}

/* ============================================
   DARK MODE
   ============================================ */
[data-theme="dark"] .chat-sidebar {
  --sb-bg: #1e1e2e;
  --sb-hover: rgba(255, 255, 255, 0.06);
  --sb-active: rgba(255, 255, 255, 0.10);
  --sb-text: #e8ecf4;
  --sb-text-secondary: #b0b8c8;
  --sb-text-muted: #8a92a6;
  --sb-text-faint: #6e7582;
  --sb-border: rgba(255, 255, 255, 0.08);
  background: var(--sb-bg);
  border-right-color: var(--sb-border);
}
[data-theme="dark"] .chat-sidebar.collapsed {
  background-color: #1a1a2a;
  background-image: none;
}
[data-theme="dark"] .s-avatar { background: var(--sb-text-secondary); }
[data-theme="dark"] .chat-sidebar.collapsed .s-avatar { background: var(--sb-text); }
[data-theme="dark"] .chat-conv-search {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: var(--sb-text);
}
[data-theme="dark"] .chat-conv-search:focus {
  border-color: rgba(255,255,255,0.25);
}
[data-theme="dark"] .s-dropdown {
  background: rgba(30, 30, 46, 0.95);
  border-color: rgba(255, 255, 255, 0.1);
  color: #e8ecf4;
}
[data-theme="dark"] .s-dropdown-item { color: #e8ecf4; }
[data-theme="dark"] .s-dropdown-item:hover { background: rgba(255, 255, 255, 0.06); color: #e8ecf4; }
[data-theme="dark"] .s-dropdown-item svg { color: var(--sb-text-muted); }
[data-theme="dark"] .s-dropdown-sep { background: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .s-dropdown-email { color: var(--sb-text-muted); }
[data-theme="dark"] .chat-drawer-trigger:hover { background: rgba(255, 255, 255, 0.08); }

/* ============================================
   SAFE AREAS (notch phones)
   ============================================ */
@supports (padding-top: env(safe-area-inset-top)) {
  .chat-sidebar {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
  }
}

/* ============================================
   FOCUS VISIBLE (keyboard only)
   ============================================ */
.s-icon-btn:focus-visible,
.s-nav-item:focus-visible,
.s-new-chat:focus-visible,
.s-conv:focus-visible,
.s-more-toggle:focus-visible,
.s-dropdown-item:focus-visible {
  outline: 2px solid rgba(31, 31, 30, 0.3);
  outline-offset: -2px;
  border-radius: var(--sb-radius);
}

/* ============================================
   PREVENT LOAD FLASH
   ============================================ */
.chat-sidebar.no-transition {
  transition: none !important;
}
.chat-sidebar.no-transition * {
  transition: none !important;
}

/* ============================================
   PRINT
   ============================================ */
@media print {
  .chat-sidebar, .s-backdrop { display: none !important; }
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .chat-sidebar, .chat-sidebar * {
    transition-duration: 0.01ms !important;
  }
}
