/* ========== ПОИСК ПО ЧАТАМ ========== */
.search-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding: 12px 16px;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-l1);
  animation: slideDown 0.2s ease;
}
.search-overlay.show { display: flex; align-items: center; gap: 8px; }

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.search-overlay-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-l2);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: var(--font-family);
  outline: none;
}
.search-overlay-input:focus { border-color: var(--accent); }
.search-overlay-input::placeholder { color: var(--text-caption); }

.search-overlay-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.search-overlay-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.search-results-inline {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-modal);
  border: 1px solid var(--border-l1);
  border-top: none;
  max-height: 300px;
  overflow-y: auto;
  z-index: 29;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.search-results-inline.show { display: block; }

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 0.5px solid var(--border-l1);
  transition: background 0.15s ease;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item:last-child { border-bottom: none; }
.search-result-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-date { font-size: 12px; color: var(--text-tertiary); flex-shrink: 0; }

.search-empty { text-align: center; padding: 20px; color: var(--text-secondary); font-size: 13px; }

/* ========== САЙДБАР ========== */
.sidebar {
  width: var(--sider-width);
  max-width: var(--sider-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border-l1);
  overflow: hidden;
  z-index: 50;
  padding: 6px 12px 10px;
  box-sizing: border-box;
  position: relative;
}

[data-theme="light"] .sidebar {
  -webkit-backdrop-filter: blur(40px);
  backdrop-filter: blur(40px);
}

.sidebar-close-btn {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.sidebar-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 40;
}

.sidebar-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 48px;
  padding: 15px 0 10px 4px;
  margin-bottom: 16px;
  box-sizing: border-box;
  gap: 4px;
}
.sidebar-top-row .logo { flex: 1; min-width: 0; }
.sidebar-top-row .btn-collapse-sidebar { flex-shrink: 0; }

.logo { display: flex; align-items: center; gap: 8px; cursor: pointer; flex-shrink: 0; }
.logo img {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  flex-shrink: 0;
  animation: logoPulse 3s ease-in-out infinite;
}

.logo-text { 
  font-size: 16px; 
  font-weight: 700; 
  line-height: 22px; 
  color: #409cff; 
  letter-spacing: -0.3px;
}

@keyframes logoPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.btn-collapse-sidebar {
  background: none; border: none; color: var(--text-tertiary); cursor: pointer;
  padding: 6px; border-radius: var(--radius-sm); width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-duration-fast) var(--ease-in-out); flex-shrink: 0;
}
.btn-collapse-sidebar:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-toggle-sidebar {
  display: none;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: transparent; border: none; color: var(--text-tertiary);
  font-size: 20px; cursor: pointer;
  align-items: center; justify-content: center;
  transition: all 0.2s ease;
}
.btn-toggle-sidebar:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-new-chat {
  width: 100%; height: var(--control-height-l); background: var(--bg-input); color: var(--text-primary);
  border: 1px solid var(--border-l2-thin); padding: 0 16px; border-radius: var(--radius-round);
  cursor: pointer; font-size: 14px; font-weight: 500; line-height: 22px;
  display: flex; align-items: center; gap: 6px; font-family: var(--font-family);
  margin-bottom: 8px; outline: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: all 0.3s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.btn-new-chat:hover {
  background: var(--bg-hover); border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0, 113, 227, 0.15);
  transform: translateY(-1px); color: var(--accent);
}

.btn-new-chat-header {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1.5px solid var(--border-l2);
  color: var(--text-secondary);
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font-family);
  transition: all 0.2s ease;
}
.btn-new-chat-header span { display: none; }
.btn-new-chat-header:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-hover);
  transform: scale(1.08);
}

.chat-section {
  flex: 1; overflow-y: auto; margin: 0 -2px; padding: 0 2px;
  position: relative; min-height: 0;
}
.chat-section-title {
  font-size: 12px; font-weight: 500; line-height: 18px; color: var(--text-tertiary);
  padding: 6px 10px 0; position: sticky; top: 0; background: var(--bg-sidebar); z-index: 2;
}
.chat-list { display: flex; flex-direction: column; }

.chat-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 6px 9px 10px; border-radius: var(--radius-md);
  cursor: pointer; font-size: 14px; line-height: 22px; color: var(--text-primary);
  height: var(--control-height-l); text-decoration: none; position: relative;
  transition: background-color var(--transition-duration) var(--ease-in-out); box-sizing: border-box;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-chat-active); color: var(--accent); }
.chat-item.active .chat-item-title { color: var(--accent); font-weight: 500; }

.chat-item-info { flex: 1; min-width: 0; overflow: hidden; }
.chat-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; line-height: 22px; color: var(--text-primary); font-weight: 400; }
.chat-item-date { font-size: 12px; color: var(--text-tertiary); flex-shrink: 0; }

.chat-item-actions { 
  display: flex; position: absolute; right: 4px; top: 50%; transform: translateY(-50%); 
  opacity: 0.4; transition: opacity 0.2s ease;
}
.chat-item:hover .chat-item-actions { opacity: 1; }

.btn-chat-action {
  background: none; border: none; color: var(--text-tertiary); cursor: pointer;
  padding: 4px; border-radius: 50%; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-duration-fast) var(--ease-in-out);
}
.btn-chat-action:hover { background: rgba(255, 255, 255, 0.1); color: var(--text-primary); }

.chat-section-fade {
  position: sticky; bottom: 0; left: 0; right: 0; height: 68px;
  background: linear-gradient(180deg, transparent 0%, var(--bg-sidebar) 80.65%);
  pointer-events: none; flex-shrink: 0;
}

.sidebar-bottom { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border-l1); }
.sidebar-profile-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 2px 6px 6px; border-radius: var(--radius-md);
  cursor: pointer; transition: background-color var(--transition-duration-fast) var(--ease-in-out);
  box-sizing: border-box;
}
.sidebar-profile-row:hover { background: var(--bg-hover); }
.sidebar-profile-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #0071e3, #af52de); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 500; flex-shrink: 0;
}
.sidebar-profile-info { flex: 1; min-width: 0; overflow: hidden; }
.sidebar-profile-name { font-size: 14px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-profile-email { font-size: 12px; color: var(--text-tertiary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-profile-dots {
  width: 28px; height: 28px; border-radius: 50%; border: none;
  background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); font-size: 16px;
  transition: all var(--transition-duration-fast) var(--ease-in-out);
}
.sidebar-profile-dots:hover { background: var(--bg-hover); color: var(--text-primary); }

.floating-sidebar-btn {
  position: fixed; top: 16px; left: 16px; width: 40px; height: 40px;
  border-radius: 50%; background: rgba(44, 44, 46, 0.85);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(40px);
  border: 1px solid rgba(255, 255, 255, 0.1); color: var(--text-primary);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  z-index: 60; opacity: 0; transform: scale(0.8); pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.22, 0.61, 0.36, 1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.floating-sidebar-btn.visible { opacity: 1; transform: scale(1); pointer-events: auto; }
.floating-sidebar-btn:hover { background: rgba(60, 60, 62, 0.9); border-color: rgba(255, 255, 255, 0.2); transform: scale(1.08); }
[data-theme="light"] .floating-sidebar-btn { background: rgba(255, 255, 255, 0.85); border: 1px solid rgba(0, 0, 0, 0.1); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1); }
[data-theme="light"] .floating-sidebar-btn:hover { background: rgba(255, 255, 255, 0.95); border-color: rgba(0, 0, 0, 0.15); }

.sidebar.collapsed {
  transform: translateX(-100%); width: 0; max-width: 0; padding: 0; border: none; overflow: hidden;
  transition: transform 0.35s cubic-bezier(0.22, 0.61, 0.36, 1),
              width 0.35s cubic-bezier(0.22, 0.61, 0.36, 1),
              max-width 0.35s cubic-bezier(0.22, 0.61, 0.36, 1),
              padding 0.35s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.sidebar {
  transition: transform 0.35s cubic-bezier(0.22, 0.61, 0.36, 1),
              width 0.35s cubic-bezier(0.22, 0.61, 0.36, 1),
              max-width 0.35s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@media (max-width: 768px) {
  .floating-sidebar-btn { display: none !important; }
  .sidebar.collapsed {
    transform: translateX(-100%); width: var(--sider-width); max-width: 100vw;
    padding: 6px 12px 10px; border-right: 1px solid var(--border-l1);
  }
}