/* ─── App Shell ─── */

.app-shell {

  display: grid;

  grid-template-columns: var(--sidebar-active-w) minmax(0, 1fr);

  width: 100%;

  max-width: 100vw;

  height: 100dvh;

  overflow: hidden;

  transition: grid-template-columns 220ms ease;

}

body.sidebar-expanded {

  --sidebar-active-w: var(--sidebar-w-expanded);

}

body:not(.sidebar-expanded):not(.guest-mode) .app-shell,
body:not(.sidebar-expanded):not(.guest-mode) .sidebar {

  transition-duration: 260ms;

}

body.guest-mode {

  --sidebar-active-w: var(--sidebar-w-expanded);

}

body.document-viewer-open .app-shell {

  grid-template-columns: var(--sidebar-active-w) minmax(0, 1fr) minmax(300px, var(--document-viewer-w));

}

/* ─── Sidebar ─── */

.sidebar {

  display: flex;

  flex-direction: column;

  background: var(--bg);

  border-right: 1px solid var(--border-light);

  padding: 8px 0;

  z-index: 20;

  overflow: visible;

  width: var(--sidebar-active-w);

  height: 100%;

  max-height: 100dvh;

  min-height: 0;

  transition: width 220ms ease;

}

body.sidebar-expanded .sidebar {

  width: var(--sidebar-active-w);

}

body.guest-mode .app-shell {

  grid-template-columns: var(--sidebar-active-w) minmax(0, 1fr);

}

body.guest-mode .sidebar {

  width: var(--sidebar-active-w);

}

@media (min-width: 901px) {
  body:not(.sidebar-expanded):not(.guest-mode) .sidebar {
    align-self: start;
    height: auto;
    min-height: 0;
    max-height: none;
    padding: 0;
    border-bottom: 1px solid var(--border-light);
    border-radius: 0 14px 14px 0;
  }

  body:not(.sidebar-expanded):not(.guest-mode) .sidebar-top {
    padding: 12px 8px;
  }

  body:not(.sidebar-expanded):not(.guest-mode) .sidebar-mid {
    display: none;
  }

  body:not(.sidebar-expanded):not(.guest-mode) .sidebar-bottom {
    position: fixed;
    inset: auto auto 10px 0;
    display: block;
    box-sizing: border-box;
    width: 56px;
    height: 52px;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
    border-left: 0;
    border-radius: 0 14px 14px 0;
    background: var(--bg);
    z-index: 21;
  }

  body:not(.sidebar-expanded):not(.guest-mode) .sidebar-profile-btn {
    border-radius: 9px;
  }

  body:not(.sidebar-expanded):not(.guest-mode) .sidebar-profile-avatar,
  body:not(.sidebar-expanded):not(.guest-mode) .sidebar-profile-btn[aria-expanded="true"] .sidebar-profile-avatar {
    border-radius: 8px;
    box-shadow: none;
  }
}

.sidebar-top {

  display: flex;

  flex-direction: column;

  align-items: flex-start;

  gap: 4px;

  padding: 4px 8px;

  flex-shrink: 0;

}

.sidebar-header {

  display: flex;

  align-items: center;

  justify-content: flex-start;

  width: 100%;

  min-height: 36px;

  margin-bottom: 2px;

}

body.sidebar-expanded .sidebar-header {

  justify-content: space-between;

  padding: 0 2px 0 4px;

}

.sidebar-close {
  display: none;
}

.sidebar-brand {

  display: none;

  font-size: 19px;

  font-weight: 650;

  letter-spacing: -0.02em;

  color: var(--text);

  line-height: 1;

  white-space: nowrap;

}

body.sidebar-expanded .sidebar-brand {

  display: block;

}

.sidebar-nav {

  display: flex;

  flex-direction: column;

  align-items: flex-start;

  gap: 2px;

  width: 100%;

}

.sidebar-quick {

  display: flex;

  flex-direction: column;

  align-items: flex-start;

  gap: 2px;

  width: 100%;

}

/* Expanded header stays clear when no wallpaper is selected. */
body.sidebar-expanded .sidebar-header,
body.guest-mode .sidebar-header,
body.sidebar-open .sidebar-header {
  min-height: 64px;
  margin: 0 0 8px;
  padding: 10px 8px 10px 10px;
  border-radius: 14px;
  color: var(--text);
  background: transparent;
}

/* With a wallpaper, the header is its own unfiltered window onto that artwork. */
body.sidebar-expanded:not([data-wallpaper="none"]) .sidebar-header,
body.guest-mode:not([data-wallpaper="none"]) .sidebar-header,
body.sidebar-open:not([data-wallpaper="none"]) .sidebar-header {
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--text) 16%, transparent);
  background-color: transparent;
  background-image: var(--home-wallpaper-image), var(--home-wallpaper-base, none);
  background-position: center bottom;
  background-size: cover;
  background-repeat: no-repeat;
  box-shadow: 0 1px 2px color-mix(in srgb, #000 12%, transparent);
}

body.sidebar-expanded .sidebar-brand,
body.guest-mode .sidebar-brand,
body.sidebar-open .sidebar-brand {
  color: var(--text);
  font-family: "Korataki", "Orbitron", sans-serif;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: none;
  padding: 2px 5px;
  margin: -2px -2px -2px -4px;
}

body.sidebar-expanded .sidebar-header .sidebar-toggle,
body.guest-mode .sidebar-header .sidebar-toggle,
body.sidebar-open .sidebar-header .sidebar-toggle {
  color: var(--text);
  background: transparent;
  opacity: 0.95;
  transition: opacity var(--transition), background var(--transition);
}

body.sidebar-expanded .sidebar-header .sidebar-toggle:hover,
body.guest-mode .sidebar-header .sidebar-toggle:hover,
body.sidebar-open .sidebar-header .sidebar-toggle:hover {
  background: var(--hover);
  opacity: 1;
}

@media (min-width: 861px) {
  body.guest-mode .sidebar-header .sidebar-toggle {
    display: none;
  }
}

/* White brand + toggle only when the header shows the home wallpaper. */
body.sidebar-expanded:not([data-wallpaper="none"]) .sidebar-brand,
body.guest-mode:not([data-wallpaper="none"]) .sidebar-brand,
body.sidebar-open:not([data-wallpaper="none"]) .sidebar-brand,
body.sidebar-expanded:not([data-wallpaper="none"]) .sidebar-header .sidebar-toggle,
body.guest-mode:not([data-wallpaper="none"]) .sidebar-header .sidebar-toggle,
body.sidebar-open:not([data-wallpaper="none"]) .sidebar-header .sidebar-toggle {
  color: #fff;
}

body.sidebar-expanded .sidebar-quick,
body.guest-mode .sidebar-quick,
body.sidebar-open .sidebar-quick {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
  margin-bottom: 4px;
}

body.sidebar-expanded .sidebar-search-item,
body.guest-mode .sidebar-search-item,
body.sidebar-open .sidebar-search-item {
  order: 1;
  flex: 1 1 0;
  width: auto !important;
  min-width: 0;
  max-width: none;
  height: 34px;
  padding: 0 10px 0 4px !important;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--bg-secondary);
  gap: 6px;
}

body.sidebar-expanded .sidebar-search-item .sidebar-nav-icon,
body.guest-mode .sidebar-search-item .sidebar-nav-icon,
body.sidebar-open .sidebar-search-item .sidebar-nav-icon {
  width: 28px;
  height: 28px;
  color: var(--text-secondary);
}

body.sidebar-expanded .sidebar-search-item .sidebar-nav-label,
body.guest-mode .sidebar-search-item .sidebar-nav-label,
body.sidebar-open .sidebar-search-item .sidebar-nav-label {
  opacity: 1;
  width: auto;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

body.sidebar-expanded .sidebar-search-item:hover,
body.guest-mode .sidebar-search-item:hover,
body.sidebar-open .sidebar-search-item:hover {
  background: transparent;
}

body.sidebar-expanded .sidebar-new-item,
body.guest-mode .sidebar-new-item,
body.sidebar-open .sidebar-new-item {
  order: 2;
  flex: 0 0 34px;
  width: 34px !important;
  min-width: 34px;
  max-width: 34px;
  height: 34px;
  padding: 0 !important;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--bg-secondary);
  justify-content: center;
  gap: 0;
}

body.sidebar-expanded .sidebar-new-item .sidebar-nav-label,
body.guest-mode .sidebar-new-item .sidebar-nav-label,
body.sidebar-open .sidebar-new-item .sidebar-nav-label {
  display: none;
}

body.sidebar-expanded .sidebar-new-item .sidebar-nav-icon,
body.guest-mode .sidebar-new-item .sidebar-nav-icon,
body.sidebar-open .sidebar-new-item .sidebar-nav-icon {
  width: 34px;
  height: 34px;
}

body.sidebar-expanded .sidebar-new-item:hover,
body.guest-mode .sidebar-new-item:hover,
body.sidebar-open .sidebar-new-item:hover {
  background: transparent;
}

.sidebar-nav-item {

  display: inline-flex;

  align-items: center;

  gap: 12px;

  width: 36px;

  height: 36px;

  padding: 0;

  border: none;

  border-radius: 10px;

  background: transparent;

  color: var(--text);

  cursor: pointer;

  transition: background var(--transition), width 220ms ease;

  flex-shrink: 0;

  overflow: hidden;

}

body.sidebar-expanded .sidebar-nav > .sidebar-nav-item,
body.sidebar-expanded .sidebar-nav .sidebar-pin-trigger,
body.guest-mode .sidebar-nav > .sidebar-nav-item,
body.guest-mode .sidebar-nav .sidebar-pin-trigger,
body.sidebar-open .sidebar-nav > .sidebar-nav-item,
body.sidebar-open .sidebar-nav .sidebar-pin-trigger {

  width: 100%;

  padding-right: 8px;

  background: var(--bg-secondary);

}

body.sidebar-expanded .sidebar-nav > .sidebar-nav-item:hover,
body.sidebar-expanded .sidebar-nav .sidebar-pin-trigger:hover,
body.guest-mode .sidebar-nav > .sidebar-nav-item:hover,
body.guest-mode .sidebar-nav .sidebar-pin-trigger:hover,
body.sidebar-open .sidebar-nav > .sidebar-nav-item:hover,
body.sidebar-open .sidebar-nav .sidebar-pin-trigger:hover {

  background: transparent;

}

.sidebar-nav-item:hover {

  background: var(--bg-secondary);

}

.sidebar-nav-icon {

  display: inline-flex;

  align-items: center;

  justify-content: center;

  width: 36px;

  height: 36px;

  flex-shrink: 0;

}

.sidebar-nav-label {

  font-size: 14px;

  font-weight: 500;

  white-space: nowrap;

  opacity: 0;

  width: 0;

  overflow: hidden;

  transition: opacity 180ms ease, width 220ms ease;

}

body.sidebar-expanded .sidebar-nav-label {

  opacity: 1;

  width: auto;

}

.sidebar-pin-wrap {

  position: relative;

  width: 100%;

}

body.sidebar-expanded .sidebar-pin-trigger {

  display: none;

}

.pinned-popup {

  position: absolute;

  left: calc(100% + 10px);

  top: 0;

  z-index: 45;

  width: min(280px, calc(100vw - 80px));

  padding: 8px;

  background: var(--bg);

  border: 1px solid var(--border);

  border-radius: 14px;

  box-shadow: var(--shadow-lg);

}

.pinned-popup.hidden {

  display: none;

}

.pinned-popup-title {

  padding: 8px 10px 6px;

  font-size: 13px;

  font-weight: 650;

  color: var(--text);

}

.pinned-popup-list {

  display: flex;

  flex-direction: column;

  gap: 2px;

  max-height: min(320px, 50dvh);

  overflow-y: auto;

}

.pinned-popup-item {

  display: flex;

  align-items: center;

  gap: 10px;

  width: 100%;

  min-height: 38px;

  padding: 0 10px;

  border: none;

  border-radius: 10px;

  background: transparent;

  color: var(--text);

  font-size: 13px;

  font-weight: 500;

  text-align: left;

  cursor: pointer;

  transition: background var(--transition);

}

.pinned-popup-item:hover {

  background: var(--bg-secondary);

}

.pinned-popup-item span {

  min-width: 0;

  overflow: hidden;

  text-overflow: ellipsis;

  white-space: nowrap;

}

.pinned-popup-empty {

  padding: 10px 12px 12px;

  color: var(--text-secondary);

  font-size: 13px;

}

.sidebar-section {

  display: flex;

  flex-direction: column;

  gap: 2px;

}

.sidebar-section + .sidebar-section {

  margin-top: 12px;

}

.sidebar-section-label {

  display: none;

  padding: 4px 10px 6px;

  font-size: 13px;

  font-weight: 700;

  color: var(--text-secondary);

  letter-spacing: 0.02em;

}

body.sidebar-expanded .sidebar-section-label {

  display: block;

}

.pinned-section.hidden {

  display: none;

}

.sidebar-mid {

  flex: 1;

  overflow-y: auto;

  overflow-x: hidden;

  padding: 8px;

  display: flex;

  flex-direction: column;

  gap: 2px;

  min-height: 0;

}

.sidebar-bottom {

  padding: 12px 8px 4px;

  border-top: none;

  display: flex;

  flex-direction: column;

  align-items: flex-start;

  gap: 4px;

  margin-top: auto;

  flex-shrink: 0;

  position: relative;

  z-index: 6;

  overflow: visible;

}

.sidebar-profile-wrap {

  position: relative;

  display: flex;

  justify-content: flex-start;

  width: 100%;

}

.sidebar-profile-btn {

  display: inline-flex;

  align-items: center;

  justify-content: center;

  gap: 10px;

  width: 36px;

  height: 36px;

  padding: 0;

  border: none;

  background: transparent;

  border-radius: var(--radius-full);

  cursor: pointer;

  transition: transform var(--transition), width 220ms ease;

  min-width: 0;

}

body.sidebar-expanded .sidebar-profile-btn {

  width: 100%;

  justify-content: flex-start;

  border-radius: 10px;

  padding: 2px 0;

}

body.sidebar-expanded .sidebar-profile-btn:hover {

  background: var(--bg-secondary);

  transform: none;

}

.sidebar-profile-meta {

  display: none;

  flex-direction: column;

  align-items: flex-start;

  justify-content: center;

  gap: 1px;

  min-width: 0;

  flex: 1;

  text-align: left;

  line-height: 1.2;

}

body.sidebar-expanded .sidebar-profile-meta {

  display: flex;

}

.sidebar-profile-name {

  width: 100%;

  font-size: 13px;

  font-weight: 600;

  color: var(--text);

  overflow: hidden;

  text-overflow: ellipsis;

  white-space: nowrap;

}

.sidebar-profile-plan {

  width: 100%;

  font-size: 11px;

  font-weight: 500;

  color: var(--text-secondary);

  overflow: hidden;

  text-overflow: ellipsis;

  white-space: nowrap;

}

.sidebar-profile-btn:hover {

  transform: scale(1.04);

}

.sidebar-profile-btn[aria-expanded="true"] .sidebar-profile-avatar {

  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--accent);

}

.sidebar-profile-avatar {

  display: inline-flex;

  align-items: center;

  justify-content: center;

  width: 32px;

  height: 32px;

  flex-shrink: 0;

  border-radius: var(--radius-full);

  background: var(--accent);

  color: var(--accent-contrast);

  font-size: 11px;

  font-weight: 700;

  letter-spacing: 0.03em;

  text-transform: uppercase;

}

.profile-menu {

  position: absolute;

  bottom: calc(100% + 10px);

  left: -8px;

  z-index: 45;

  width: min(280px, calc(100vw - 24px));

  padding: 8px;

  background: var(--bg);

  border: 1px solid var(--border);

  border-radius: 16px;

  box-shadow: var(--shadow-lg);

}

.profile-menu.hidden {

  display: none;

}

.profile-menu-email {

  padding: 10px 12px 6px;

  font-size: 14px;

  font-weight: 600;

  color: var(--text);

  overflow: hidden;

  text-overflow: ellipsis;

  white-space: nowrap;

}

.profile-menu .account-usage {

  margin-top: 0;

  padding: 8px 12px 10px;

  border-top: none;

}

.profile-menu-actions {

  display: flex;

  flex-direction: column;

  gap: 2px;

  padding: 4px;

  border-top: 1px solid var(--border-light);

}

.profile-menu-item {

  display: flex;

  align-items: center;

  gap: 10px;

  width: 100%;

  min-height: 40px;

  padding: 0 12px;

  border: none;

  border-radius: 10px;

  background: transparent;

  color: var(--text);

  font-size: 14px;

  font-weight: 500;

  text-align: left;

  cursor: pointer;

  transition: background var(--transition);

}

.profile-menu-item svg {

  flex-shrink: 0;

  color: var(--text-secondary);

}

.profile-menu-item:hover {

  background: var(--bg-secondary);

}

.profile-menu-item.profile-menu-danger {

  color: var(--danger);

}

.profile-menu-item.profile-menu-danger svg {

  color: var(--danger);

}

body.sidebar-expanded .profile-menu {

  left: -8px;

  bottom: calc(100% + 10px);

  width: calc(100% + 16px);

}

.sidebar-icon {

  display: flex;

  align-items: center;

  justify-content: center;

  width: 36px;

  height: 36px;

  border-radius: 8px;

  color: var(--text);

  transition: background var(--transition);

  flex-shrink: 0;

}

.sidebar-icon:hover {

  background: var(--bg-secondary);

}

.guest-login-panel {

  margin: auto 12px 12px;

  padding: 16px 8px 8px;

}

body:not(.guest-mode) .guest-login-panel {

  display: none !important;

}

.guest-login-btn {

  width: 100%;

  min-height: 44px;

  border-radius: var(--radius-full);

  border: 1px solid var(--border);

  background: var(--text);

  color: var(--bg);

  font-size: 14px;

  font-weight: 650;

  transition: background var(--transition), transform var(--transition);

}

.guest-login-btn:hover {

  background: var(--accent-hover);

}

body.guest-mode .sidebar-bottom {

  display: none;

}

.conversation-row {

  display: flex;

  align-items: center;

  gap: 4px;

  width: 100%;

  border-radius: 8px;

  transition: background var(--transition), opacity 180ms ease;

  opacity: 0;

  pointer-events: none;

  position: relative;

}

body.sidebar-expanded .conversation-row {

  opacity: 1;

  pointer-events: auto;

  transition-delay: 70ms;

}

body:not(.sidebar-expanded) .conversation-row {

  transition-delay: 0ms;

}

.conversation-row:hover,

.conversation-row.active {

  background: var(--bg-secondary);

}

.conversation-item {

  display: flex;

  align-items: center;

  gap: 8px;

  flex: 1;

  min-width: 0;

  text-align: left;

  padding: 8px 10px;

  color: var(--text);

  font-size: 13px;

  white-space: nowrap;

  border: none;

  background: transparent;

  cursor: pointer;

}

.conversation-title {

  display: block;

  flex: 1;

  min-width: 0;

  overflow: hidden;

  text-overflow: ellipsis;

}

.conversation-activity {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.conversation-activity.is-running {
  width: 12px;
  height: 12px;
  border: 1.5px solid color-mix(in srgb, var(--text-tertiary) 55%, transparent);
  border-top-color: #3b82f6;
  background: transparent;
  animation: conversation-spin 0.7s linear infinite;
}

.conversation-activity.is-done {
  background: #3b82f6;
}

@keyframes conversation-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .conversation-activity.is-running { animation: none; }
}

.conversation-menu-wrap {

  position: relative;

  flex-shrink: 0;

}

.conversation-menu-btn {

  display: flex;

  align-items: center;

  justify-content: center;

  width: 30px;

  height: 30px;

  margin-right: 4px;

  border: none;

  border-radius: 8px;

  background: transparent;

  color: var(--text-tertiary);

  opacity: 0;

  cursor: pointer;

  transition: background var(--transition), color var(--transition), opacity var(--transition);

}

.conversation-row:hover .conversation-menu-btn,

.conversation-row.active .conversation-menu-btn,

.conversation-menu-btn[aria-expanded="true"] {

  opacity: 1;

}

.conversation-menu-btn:hover {

  background: var(--bg-secondary);

  color: var(--text);

}

.conversation-menu {

  position: absolute;

  top: calc(100% + 4px);

  right: 0;

  z-index: 40;

  min-width: 148px;

  padding: 4px;

  background: var(--bg);

  border: 1px solid var(--border);

  border-radius: 12px;

  box-shadow: var(--shadow-md);

}

.conversation-menu.conversation-menu--up {

  top: auto;

  bottom: calc(100% + 4px);

}

.conversation-menu.hidden {

  display: none;

}

.conversation-menu-item {

  display: flex;

  align-items: center;

  gap: 8px;

  width: 100%;

  min-height: 36px;

  padding: 0 10px;

  border: none;

  border-radius: 8px;

  background: transparent;

  color: var(--text);

  font-size: 13px;

  font-weight: 500;

  text-align: left;

  cursor: pointer;

  transition: background var(--transition);

}

.conversation-menu-item:hover {

  background: var(--bg-secondary);

}

.conversation-menu-item-icon {

  display: inline-flex;

  flex-shrink: 0;

  align-items: center;

  justify-content: center;

  color: inherit;

}

.conversation-menu-item.conversation-menu-danger {

  color: var(--danger);

}

/* Sections switched off for now (e.g. Projects) stay out of the rail. */
.sidebar-nav-item[hidden] {
  display: none;
}
