.sidebar {
  width: 250px;
  background: linear-gradient(180deg, rgba(252, 253, 250, 0.95), rgba(241, 248, 233, 0.95));
  backdrop-filter: blur(8px);
  border-right: 1px solid rgba(76, 175, 80, 0.1);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: visible;
  z-index: 20;
}

.sidebar.collapsed {
  width: 68px;
  padding: 12px 8px;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.sidebar.collapsed .sidebar-top {
  justify-content: center;
}

.brand-group {
  display: flex;
  flex-direction: column;
  transition: opacity 0.2s;
}

.sidebar.collapsed .brand-group,
.sidebar.collapsed .chat-list-title,
.sidebar.collapsed .chat-list,
.sidebar.collapsed .muted,
.sidebar.collapsed .full-text {
  display: none;
}

.toggle-btn {
  background: transparent;
  border: 0;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.toggle-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.toggle-btn svg {
  transition: width 0.3s, height 0.3s;
}

.sidebar.collapsed .toggle-btn svg {
  width: 20px;
  height: 20px;
}

.sidebar.collapsed .toggle-btn {
  padding: 0;
  width: 40px;
  height: 40px;
  margin: 0 auto;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  white-space: nowrap;
}

.sub {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.chat-list-title {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 10px;
  margin-bottom: 6px;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.chat-list-load-more {
  border: 1px dashed rgba(76, 175, 80, 0.42);
  background: rgba(255, 255, 255, 0.92);
  color: var(--green-dark);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.chat-list-load-more:hover {
  background: #f1f8e9;
}

.chat-item-row {
  position: relative;
  display: block;
}

.chat-item {
  width: 100%;
  background: #f5f9ff;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 38px 10px 11px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  min-width: 0;
}

.chat-item-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.chat-item-pin {
  flex-shrink: 0;
  display: inline-flex;
  color: #2e7d32;
  opacity: 0.9;
}

.chat-item-title-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.chat-item-row.active .chat-item {
  background: #dff1ff;
  border-color: rgba(1, 137, 232, 0.36);
}

.chat-item-menu-wrap {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
}

.chat-item-menu-trigger {
  width: 26px;
  height: 26px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  color: #5f6368;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.chat-item-menu-trigger:hover {
  background: rgba(0, 0, 0, 0.05);
}

.chat-item-menu-trigger svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.chat-item-menu {
  position: fixed;
  top: 0;
  left: 0;
  min-width: 210px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.12);
  padding: 6px;
  z-index: 4000;
}

.chat-item-menu-option {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: #334155;
  cursor: pointer;
}

.chat-item-menu-option:hover {
  background: #f1f5f9;
}

.new-chat {
  width: 100%;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
}

.icon-only {
  display: none;
}

.sidebar.collapsed .icon-only {
  display: flex;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-thread-label {
  padding-bottom: 2px;
}

.sidebar-user-shell {
  position: relative;
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(16, 35, 58, 0.08);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 24px rgba(140, 160, 120, 0.1);
}

.sidebar-user-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f39ac4, #e77ab0);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
}

.sidebar-user-copy {
  min-width: 0;
}

.sidebar-user-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.sidebar-user-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-settings {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #6d7280;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-user-settings:hover,
.sidebar-user-settings[aria-expanded="true"] {
  background: rgba(16, 35, 58, 0.06);
  color: var(--text);
}

.sidebar-settings-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 10px);
  border-radius: 16px;
  background: #fff;
  border: 1px solid rgba(16, 35, 58, 0.1);
  box-shadow: 0 18px 34px rgba(16, 35, 58, 0.16);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 50;
}

.sidebar-settings-menu[hidden] {
  display: none;
}

.sidebar-settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}

.sidebar-settings-copy {
  min-width: 0;
}

.sidebar-settings-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.sidebar-settings-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.sidebar-switch {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.sidebar-switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.sidebar-switch-slider {
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: #d8e1ec;
  position: relative;
  transition: background 0.2s ease;
}

.sidebar-switch-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(16, 35, 58, 0.2);
  transition: transform 0.2s ease;
}

.sidebar-switch input:checked + .sidebar-switch-slider {
  background: var(--green);
}

.sidebar-switch input:checked + .sidebar-switch-slider::after {
  transform: translateX(18px);
}

.sidebar-danger-btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: rgba(220, 38, 38, 0.08);
  color: #b42318;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-danger-btn:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.14);
}

.sidebar-danger-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.sidebar-secondary-btn {
  width: 100%;
  border: 1px solid rgba(16, 35, 58, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.sidebar-secondary-btn:hover {
  background: #f8fafc;
  border-color: rgba(46, 125, 50, 0.28);
}

.sidebar-secondary-btn[hidden] {
  display: none;
}

.sidebar.collapsed .new-chat {
  background: transparent;
  color: var(--text);
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  margin: 0 auto;
  border-radius: 10px;
}

.sidebar.collapsed .new-chat svg {
  width: 20px;
  height: 20px;
  transition: width 0.3s, height 0.3s;
}

.sidebar.collapsed .new-chat:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sidebar.collapsed .sidebar-footer {
  align-items: center;
}

.sidebar.collapsed .sidebar-user-copy,
.sidebar.collapsed .sidebar-settings-menu {
  display: none;
}

.sidebar.collapsed .sidebar-user-card {
  width: 50px;
  min-height: 50px;
  justify-content: center;
  padding: 8px;
}

.sidebar.collapsed .sidebar-user-main {
  justify-content: center;
  flex: 0 0 auto;
}

.sidebar.collapsed .sidebar-user-settings {
  display: none;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(82vw, 320px);
    max-width: 320px;
    padding: 14px 12px calc(14px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
    transform: translateX(0);
    transition:
      transform 0.28s ease,
      box-shadow 0.28s ease;
    visibility: hidden;
  }

  .sidebar.sidebar-ready {
    visibility: visible;
  }

  .sidebar.collapsed {
    width: min(82vw, 320px);
    padding: 14px 12px calc(14px + env(safe-area-inset-bottom, 0px));
    transform: translateX(calc(-100% - 12px));
    box-shadow: none;
  }

  .sidebar.collapsed .sidebar-top {
    justify-content: flex-start;
  }

  .sidebar.collapsed .toggle-btn {
    position: absolute;
    top: 14px;
    right: -56px;
    width: 40px;
    height: 40px;
    margin: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  }

  .sidebar.collapsed .toggle-btn:hover {
    background: #ffffff;
  }

  .sidebar.collapsed .new-chat {
    margin: 0;
  }

  .chat-list {
    padding-right: 2px;
  }

  .sidebar-settings-menu {
    left: 0;
    right: 0;
  }
}
