:root {
  --bg-primary: #1a1c20;
  --bg-secondary: #242629;
  --bg-tertiary: #3f4147;
  --text-primary: #ffffff;
  --text-secondary: #b9bbbe;
  --text-muted: #72767d;
  --accent-primary: #5865F2;
  --accent-hover: #4752c4;
  --accent-success: #3ba55d;
  --accent-warning: #faa61a;
  --accent-danger: #ed4245;
  --accent-info: #1788c9;
  --border-color: #3f4147;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.4);
  --radius-small: 4px;
  --radius-medium: 8px;
  --radius-large: 12px;
  --radius-xlarge: 16px;
  --sidebar-width: 320px;
  --header-height: 60px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
}

[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #ebedef;
  --text-primary: #1c1e21;
  --text-secondary: #606770;
  --text-muted: #9599a1;
  --border-color: #d8dadf;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-tertiary); }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

.auth-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, var(--accent-primary), #6a11cb);
}

.auth-screen:not(.active) { display: none; }

.auth-container {
  width: 100%;
  max-width: 420px;
  padding: 2.5rem;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-xlarge);
  box-shadow: var(--shadow-lg);
}

.logo {
  text-align: center;
  margin-bottom: 2rem;
  color: var(--accent-primary);
  font-size: 2rem;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.auth-tabs { display: flex; gap: 1rem; margin-bottom: 1.5rem; }

.tab-btn {
  flex: 1;
  padding: 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 600;
  position: relative;
}

.tab-btn.active { color: var(--accent-primary); }

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 0;
  right: 0;
  height: 3px;
  background-color: var(--accent-primary);
  border-radius: 2px;
}

.auth-form { display: none; }
.auth-form.active { display: block; }

.input-group { margin-bottom: 1.25rem; }

.input-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.input-group input,
.input-group textarea,
.input-group select {
  width: 100%;
  padding: 12px 16px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
}

.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(88, 101, 242, 0.2);
}

.btn {
  width: 100%;
  padding: 0.875rem;
  border: none;
  border-radius: var(--radius-medium);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary { background-color: var(--accent-primary); color: white; }
.btn-primary:hover { background-color: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background-color: var(--bg-tertiary); color: var(--text-primary); }
.btn-danger { background-color: var(--accent-danger); color: white; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.main-app { display: flex; height: 100vh; }
.main-app:not(.active) { display: none; }

.sidebar-toggle { display: none !important; }

/* ===== САЙДБАР - СТАТИЧНЫЙ ===== */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
  flex-shrink: 0;
  margin-left: 0 !important;
}

.sidebar.hidden { margin-left: 0 !important; }

.sidebar-header {
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  gap: 0.5rem;
}

.sidebar-header .user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.sidebar-header .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background-color: var(--bg-tertiary);
}

.sidebar-header .user-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}

.sidebar-header .user-info span:first-child {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-header .status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-success);
  display: inline-block;
}

.sidebar-header .status-indicator.offline { background-color: var(--text-muted); }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-small);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-tab {
  flex: 1;
  padding: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  transition: all var(--transition-fast);
}

.sidebar-tab i { font-size: 1.25rem; }
.sidebar-tab.active { color: var(--accent-primary); background-color: var(--bg-tertiary); }
.sidebar-tab:hover { background-color: var(--bg-tertiary); }

.search-container {
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.search-container i { color: var(--text-muted); }

.search-container input {
  flex: 1;
  padding: 0.5rem 0.5rem 0.5rem 2.5rem;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  color: var(--text-primary);
}

.chats-list { flex: 1; overflow-y: auto; }

/* ===== ЧАТЫ В САЙДБАРЕ - ИСПРАВЛЕНО ===== */
.chat-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  position: relative;
}

.chat-item:hover { background-color: var(--bg-tertiary); }

.chat-item.active { background-color: var(--accent-primary); color: white; }
.chat-item.active .chat-info p { color: var(--text-secondary); }

.chat-item .chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background-color: var(--bg-tertiary);
}

.chat-item .chat-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chat-item .chat-info h4 {
  font-size: 0.95rem;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item .chat-info p {
  font-size: 0.8rem;
  margin: 0;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item .chat-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  min-width: 50px;
  flex-shrink: 0;
}

.chat-item .chat-meta .time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.chat-item.active .chat-meta .time {
  color: var(--text-secondary);
}

.chat-type-icon {
  position: absolute;
  bottom: 0;
  right: 0;
  background-color: var(--accent-primary);
  color: white;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
}

/* ===== КОНТАКТЫ ===== */
.contacts-list { flex: 1; overflow-y: auto; }

.contacts-header {
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.contacts-header h3 { margin: 0; font-size: 1rem; }

.contact-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.contact-item:hover { background-color: var(--bg-tertiary); }

.contact-item .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background-color: var(--bg-tertiary);
}

.contact-info {
  flex: 1;
  min-width: 0;
}

.contact-info h4 {
  font-size: 0.95rem;
  margin-bottom: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-info .custom-name { font-size: 0.75rem; color: var(--text-muted); }
.contact-info p { font-size: 0.8rem; color: var(--text-muted); }

.fab {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--accent-primary);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-size: 1.25rem;
  z-index: 100;
  transition: transform var(--transition-fast);
}

.fab:hover { transform: scale(1.1); }

/* ===== ШАПКА ЧАТА - ИСПРАВЛЕНО ===== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.chat-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  gap: 1rem;
}

.chat-header:hover { background-color: var(--bg-tertiary); }

.chat-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background-color: var(--bg-tertiary);
}

.chat-details {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}

.chat-details h3 {
  font-size: 1rem;
  margin: 0;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-details p {
  font-size: 0.8rem;
  margin: 0;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.pinned-message-bar {
  background-color: var(--bg-tertiary);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.pinned-message-bar i { color: var(--accent-warning); }

.pinned-message-bar span {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  position: relative;
}

.messages-list { display: flex; flex-direction: column; gap: 0.5rem; }

.message {
  display: flex;
  gap: 0.75rem;
  max-width: 70%;
  animation: messagePop 0.3s ease;
  position: relative;
  padding: 0.25rem;
  border-radius: var(--radius-medium);
}

.message:hover { background-color: var(--bg-tertiary); }

@keyframes messagePop {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.message.own { align-self: flex-end; flex-direction: row-reverse; }

.message-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.message-content { flex: 1; min-width: 0; }

.message-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.sender-name { font-weight: 600; color: var(--text-secondary); font-size: 0.85rem; }
.timestamp { color: var(--text-muted); font-size: 0.75rem; }

.message-text {
  background-color: var(--bg-tertiary);
  padding: 0.75rem;
  border-radius: var(--radius-medium);
  border-top-left-radius: 0;
  line-height: 1.5;
  word-wrap: break-word;
}

.message.own .message-text {
  background-color: var(--accent-primary);
  color: white;
  border-top-left-radius: var(--radius-medium);
  border-top-right-radius: 0;
}

.message-edited { font-size: 0.7rem; color: var(--text-muted); margin-left: 0.25rem; }

.message-reply {
  background-color: rgba(0, 0, 0, 0.1);
  padding: 0.5rem;
  border-radius: var(--radius-small);
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--accent-primary);
}

.message-reply .reply-author { font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); }

.message-reply .reply-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.attachment {
  position: relative;
  border-radius: var(--radius-medium);
  overflow: hidden;
  max-width: 300px;
}

.attachment img,
.attachment video {
  max-width: 100%;
  max-height: 300px;
  display: block;
}

.attachment-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-medium);
  max-width: 300px;
}

.attachment-info i { font-size: 1.5rem; color: var(--accent-primary); }

.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.reaction {
  background-color: var(--bg-tertiary);
  border-radius: 12px;
  padding: 0.15rem 0.5rem;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.reaction:hover { transform: scale(1.2); background-color: var(--accent-primary); }
.reaction.own { background-color: var(--accent-primary); color: white; }

.read-status { display: flex; justify-content: flex-end; margin-top: 0.25rem; gap: 0.15rem; }
.read-status i { color: var(--text-muted); font-size: 0.7rem; }
.read-status.read i { color: var(--accent-primary); }

.scroll-to-bottom {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: 40px;
  height: 40px;
  background-color: var(--accent-primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.typing-indicators { padding: 0 1rem 0.5rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg-tertiary);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-medium);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.typing-animation { display: flex; gap: 0.25rem; }

.typing-animation span {
  width: 6px;
  height: 6px;
  background-color: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-animation span:nth-child(2) { animation-delay: 0.2s; }
.typing-animation span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

.input-area {
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
}

.reply-preview,
.edit-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background-color: var(--bg-tertiary);
  border-left: 3px solid var(--accent-primary);
}

.reply-content { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.reply-author { font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); }
.reply-text { font-size: 0.9rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.format-toolbar {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  background-color: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
}

.format-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-small);
  transition: all var(--transition-fast);
}

.format-btn:hover { background-color: var(--bg-secondary); color: var(--text-primary); }

.input-container {
  display: flex;
  align-items: center;
  padding: 0.75rem;
  gap: 0.5rem;
}

.input-container textarea {
  flex: 1;
  padding: 0.75rem;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  resize: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  min-height: 40px;
  max-height: 150px;
}

.input-container textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.send-btn { background-color: var(--accent-primary); color: white; }
.send-btn:hover { background-color: var(--accent-hover); }

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active { display: flex; }

.modal-content {
  background-color: var(--bg-primary);
  border-radius: var(--radius-xlarge);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.call-modal-content {
  background: linear-gradient(135deg, var(--accent-primary), #6a11cb);
  max-width: 400px;
  text-align: center;
}

.call-container { padding: 2rem; display: flex; flex-direction: column; align-items: center; gap: 2rem; }
.caller-info h3 { margin: 0; font-size: 1.5rem; }
.caller-info p { color: var(--text-secondary); }
#call-timer { font-size: 1.2rem; font-weight: 600; margin-top: 0.5rem; }
.call-controls { display: flex; gap: 1rem; justify-content: center; }

.call-control-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background-color: white;
  color: var(--text-primary);
  font-size: 1.25rem;
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.call-control-btn:hover { transform: scale(1.1); }
.call-control-btn.danger { background-color: var(--accent-danger); color: white; }

.modal-header {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover { background-color: var(--bg-tertiary); color: var(--text-primary); }
.modal-close { position: absolute; top: 1rem; right: 1rem; z-index: 10; }
.modal-body { padding: 1.5rem; }

.modal-footer {
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  border-top: 1px solid var(--border-color);
}

.chat-type-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.chat-type-tabs .tab-btn {
  padding: 0.75rem 1rem;
  border-bottom: 2px solid transparent;
  border-radius: 0;
}

.chat-type-tabs .tab-btn.active { border-bottom-color: var(--accent-primary); }
.chat-type-content { display: none; }
.chat-type-content.active { display: block; }

.search-results {
  margin-top: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-medium);
}

.result-item {
  padding: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.result-item:hover { background-color: var(--bg-secondary); }
.result-item.selected { background-color: var(--accent-primary); }

.profile-section { margin-bottom: 2rem; }

.avatar-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.5rem;
  position: relative;
}

.upload-label {
  background-color: var(--accent-primary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  cursor: pointer;
  margin-top: -1.5rem;
  position: relative;
  z-index: 10;
}

#avatar-upload { display: none; }

.theme-settings,
.notification-settings { margin: 1.5rem 0; }
.theme-settings h3,
.notification-settings h3 { margin-bottom: 1rem; color: var(--text-secondary); }

.theme-options { display: flex; gap: 1rem; margin-bottom: 1.5rem; }

.theme-btn {
  padding: 0.5rem 1rem;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  cursor: pointer;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-btn:hover { background-color: var(--bg-tertiary); }

.accent-colors { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.color-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  background-color: var(--accent-color);
}

.color-btn.active { border-color: white; }

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
}

.toggle {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-tertiary);
  border-radius: 26px;
  transition: var(--transition-fast);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: var(--transition-fast);
}

.toggle input:checked + .toggle-slider { background-color: var(--accent-primary); }
.toggle input:checked + .toggle-slider:before { transform: translateX(24px); }

.profile-modal-content { max-width: 400px; padding: 0; overflow: hidden; }

.profile-header {
  background: linear-gradient(135deg, var(--accent-primary), #6a11cb);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}

.profile-header-info h3 { margin: 0; font-size: 1.5rem; color: white; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  background-color: rgba(255,255,255,0.2);
  border-radius: 20px;
  font-size: 0.85rem;
  color: white;
}

.status-badge.online::before {
  content: '';
  width: 8px;
  height: 8px;
  background-color: var(--accent-success);
  border-radius: 50%;
}

.status-badge.offline { background-color: rgba(0,0,0,0.2); }
.status-badge.offline::before { background-color: var(--text-muted); }

.profile-body { padding: 1.5rem; }
.profile-section h4 { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.profile-bio { color: var(--text-primary); line-height: 1.6; white-space: pre-wrap; }

.profile-detail {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.profile-detail i { width: 20px; color: var(--accent-primary); }
.profile-detail strong { color: var(--text-primary); }

.profile-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.profile-actions .btn { flex: 1; }

.chat-settings-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.chat-settings-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.chat-settings-section h3 { margin-bottom: 1rem; color: var(--text-secondary); font-size: 0.9rem; }

.blocked-user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-medium);
  margin-bottom: 0.5rem;
}

.blocked-user-info { display: flex; align-items: center; gap: 0.75rem; }

.unblock-btn {
  background-color: var(--accent-success);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-small);
  cursor: pointer;
  font-size: 0.85rem;
}

.unblock-btn:hover { background-color: var(--accent-success); opacity: 0.9; }

.emoji-picker {
  position: absolute;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-lg);
  padding: 1rem;
  z-index: 100;
  display: none;
  bottom: 80px;
  left: 10px;
  width: 320px;
}

.emoji-picker.active { display: block; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
  max-height: 200px;
  overflow-y: auto;
}

.emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: var(--radius-small);
  cursor: pointer;
  font-size: 1.2rem;
}

.emoji:hover { background-color: var(--bg-tertiary); }

.reaction-picker {
  position: absolute;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem;
  display: flex;
  gap: 0.25rem;
  z-index: 100;
}

.reaction-emoji {
  font-size: 1.2rem;
  padding: 0.25rem;
  border-radius: var(--radius-small);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.reaction-emoji:hover { transform: scale(1.3); background-color: var(--bg-tertiary); }

.reaction-more {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-small);
}

.context-menu {
  position: fixed;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  min-width: 180px;
  padding: 0.25rem 0;
  display: none;
}

.context-menu.active { display: block; }

.menu-item {
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.menu-item:hover { background-color: var(--bg-tertiary); }

.menu-divider { border: none; height: 1px; background-color: var(--border-color); margin: 0.25rem 0; }

.chat-select-list { max-height: 300px; overflow-y: auto; }

.chat-select-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  cursor: pointer;
  border-radius: var(--radius-medium);
}

.chat-select-item:hover { background-color: var(--bg-tertiary); }
.chat-select-item.selected { background-color: var(--accent-primary); }

.toast-container {
  position: fixed;
  top: 2rem;
  right: 2rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 1rem;
  border-radius: var(--radius-medium);
  color: white;
  box-shadow: var(--shadow);
  max-width: 300px;
  animation: slideIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast-success { background-color: var(--accent-success); }
.toast-error { background-color: var(--accent-danger); }
.toast-info { background-color: var(--accent-info); }

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

.loading-overlay.hidden { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background-color: var(--accent-warning);
  color: black;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 2000;
  animation: slideDown 0.3s ease;
}

.offline-banner.hidden { display: none; }

@keyframes slideDown {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

/* Видео для звонков */
#remote-video,
#local-video {
  width: 100%;
  max-height: 200px;
  border-radius: var(--radius-medium);
  background-color: var(--bg-tertiary);
  margin-top: 1rem;
  object-fit: cover;
}

#local-video {
  position: absolute;
  bottom: 100px;
  right: 20px;
  width: 150px;
  max-height: 150px;
  border: 2px solid var(--border-color);
}

@media (max-width: 768px) {
  .sidebar { width: 100%; position: absolute; z-index: 900; }
  .fab { bottom: 1rem; right: 1rem; }
}

@media (max-width: 480px) {
  .auth-container { margin: 1rem; padding: 1.5rem; }
  .message { max-width: 90%; }
  .emoji-picker { width: 280px; left: 0.5rem; }
}

@media print {
  .sidebar, .chat-header, .input-area, .fab, .modal, .toast-container, .offline-banner { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (prefers-contrast: high) {
  :root { --border-color: #000000; --shadow: 0 4px 6px rgba(0, 0, 0, 0.5); }
}