* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0f0f12;
  color: #e4e4e7;
  height: 100vh;
  overflow: hidden;
}

/* Auth — космос */
#auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  position: relative;
  z-index: 10;
  overflow: hidden;
  background: radial-gradient(ellipse at 30% 20%, rgba(88, 28, 135, 0.15) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 80%, rgba(30, 58, 138, 0.12) 0%, transparent 50%),
              radial-gradient(ellipse at 50% 50%, rgba(15, 23, 42, 0.3) 0%, transparent 70%),
              linear-gradient(180deg, #030714 0%, #0c0f1a 30%, #050810 100%);
}
#auth-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,0.4), transparent),
                    radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.3), transparent),
                    radial-gradient(1px 1px at 90px 40px, rgba(255,255,255,0.5), transparent),
                    radial-gradient(2px 2px at 130px 80px, rgba(255,255,255,0.35), transparent),
                    radial-gradient(1px 1px at 160px 120px, rgba(255,255,255,0.4), transparent),
                    radial-gradient(2px 2px at 200px 50px, rgba(255,255,255,0.3), transparent),
                    radial-gradient(1px 1px at 250px 180px, rgba(255,255,255,0.45), transparent),
                    radial-gradient(2px 2px at 80px 150px, rgba(255,255,255,0.35), transparent);
  background-size: 280px 200px;
  animation: stars 120s linear infinite;
  pointer-events: none;
}
@keyframes stars {
  from { transform: translateY(0); }
  to { transform: translateY(-200px); }
}
.auth-box * {
  pointer-events: auto;
}

.auth-box {
  position: relative;
  z-index: 1;
  background: rgba(24, 24, 27, 0.85);
  backdrop-filter: blur(12px);
  padding: 1.75rem;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
  width: 100%;
  max-width: 320px;
}

.auth-box h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  line-height: 1.3;
  text-align: center;
}
.auth-box h1 .auth-subtitle {
  font-size: 0.95rem;
  font-weight: 500;
  color: #a1a1aa;
  display: block;
  margin-top: 0.25rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tab {
  flex: 1;
  padding: 0.6rem;
  border: none;
  background: #27272a;
  color: #a1a1aa;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
  z-index: 1;
}

.tab:hover {
  background: #3f3f46;
  color: #fff;
}

.tab.active {
  background: #3b82f6;
  color: #fff;
}

.auth-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  background: #27272a;
  color: #fff;
  font-size: 1rem;
}

.auth-form input::placeholder {
  color: #71717a;
}

.auth-form input:focus {
  outline: none;
  border-color: #3b82f6;
}

.auth-form button {
  width: 100%;
  padding: 0.75rem;
  margin-top: 0.5rem;
  border: none;
  border-radius: 8px;
  background: #3b82f6;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.auth-form button:hover {
  background: #2563eb;
}

.error {
  color: #f87171;
  font-size: 0.875rem;
  margin-top: 1rem;
  text-align: center;
}

.hidden {
  display: none !important;
}

/* Chat screen */
#chat-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at 30% 20%, rgba(88, 28, 135, 0.15) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 80%, rgba(30, 58, 138, 0.12) 0%, transparent 50%),
              radial-gradient(ellipse at 50% 50%, rgba(15, 23, 42, 0.3) 0%, transparent 70%),
              linear-gradient(180deg, #030714 0%, #0c0f1a 30%, #050810 100%);
}
#chat-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,0.4), transparent),
                    radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.3), transparent),
                    radial-gradient(1px 1px at 90px 40px, rgba(255,255,255,0.5), transparent),
                    radial-gradient(2px 2px at 130px 80px, rgba(255,255,255,0.35), transparent),
                    radial-gradient(1px 1px at 160px 120px, rgba(255,255,255,0.4), transparent),
                    radial-gradient(2px 2px at 200px 50px, rgba(255,255,255,0.3), transparent),
                    radial-gradient(1px 1px at 250px 180px, rgba(255,255,255,0.45), transparent),
                    radial-gradient(2px 2px at 80px 150px, rgba(255,255,255,0.35), transparent);
  background-size: 280px 200px;
  animation: stars 120s linear infinite;
  pointer-events: none;
}

.chat-workspace {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 37.5vw;
  height: 90vh;
  max-height: 1080px;
  min-height: 720px;
  background: rgba(24, 24, 27, 0.9);
  backdrop-filter: blur(12px);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
  overflow: hidden;
}

.chat-header {
  padding: 0.75rem 1.5rem;
  background: #18181b;
  border-bottom: 1px solid #27272a;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-header-brand {
  justify-self: center;
  font-weight: 600;
  font-size: 1rem;
  color: #e4e4e7;
}

.chat-header-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-btn {
  padding: 0.5rem;
  font-size: 1.1rem;
  background: #3b82f6;
  border: none;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.header-btn:hover {
  background: #2563eb;
  color: #fff;
}

.header-settings-wrap {
  position: relative;
}
.settings-panel {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.35rem;
  padding: 1rem;
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 50;
}
.settings-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.settings-row span {
  font-size: 0.875rem;
  color: #a1a1aa;
}
.speed-options {
  display: flex;
  gap: 0.35rem;
}
.speed-btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.875rem;
  background: #27272a;
  border: 1px solid #3f3f46;
  color: #e4e4e7;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.speed-btn:hover {
  background: #3f3f46;
}
.speed-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

.logout-left {
  flex-shrink: 0;
}
#logout-btn {
  padding: 0.5rem 1rem;
  border: none;
  background: #3b82f6;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
}

#logout-btn:hover,
.sidebar-logout:hover,
#change-server-btn:hover {
  background: #2563eb;
  color: #fff;
}

#change-server-btn {
  padding: 0.5rem 1rem;
  border: 1px solid #3f3f46;
  background: transparent;
  color: #a1a1aa;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  margin-right: 0.5rem;
}

.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.contacts {
  width: 220px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  background: #18181b;
  border-right: 1px solid #27272a;
  overflow: hidden;
}

.contacts .rooms-header {
  flex-shrink: 0;
  border-bottom: 1px solid #27272a;
}

.contacts #rooms-list {
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 180px;
}

.contacts .room-members {
  flex-shrink: 0;
}

.sidebar-logout {
  flex-shrink: 0;
  margin-top: auto;
  margin-left: 1.25rem;
  margin-right: 1.25rem;
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  border: none;
  background: #3b82f6;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
}

.sidebar-logout:hover {
  background: #2563eb;
}

.is-app .sidebar-logout {
  align-self: flex-start;
  max-width: 85px;
  margin-bottom: 1.5rem;
}

/* Мобильная вёрстка: на весь экран, без космоса */
@media (max-width: 768px) {
  #chat-screen {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    background: #0f0f12;
  }
  #chat-screen::before {
    display: none;
  }
  .chat-workspace {
    max-width: none;
    width: 100%;
    height: 100vh;
    max-height: none;
    min-height: 0;
    border-radius: 0;
  }
  .chat-layout:not(.in-chat) .chat-main {
    display: none;
  }
  .chat-layout:not(.in-chat) .contacts {
    width: 100%;
    min-width: 0;
    flex: 1;
  }
  .chat-layout.in-chat .contacts {
    display: none;
  }
  .chat-layout.in-chat .chat-main {
    flex: 1;
    width: 100%;
    min-width: 0;
  }
  .back-btn.hidden {
    display: none !important;
  }
  .back-btn:not(.hidden) {
    display: flex !important;
  }
  .message {
    max-width: 90%;
  }
  .send-form-top .record-btn,
  .send-form-top .emoji-wrap {
    flex: 1;
    min-width: 0;
  }
  .send-form-top .record-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .send-form-bottom button[type="submit"] {
    flex: 0 0 auto;
  }
}

.back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-right: 0.5rem;
  padding: 0;
  font-size: 1.5rem;
  background: #3b82f6;
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.back-btn:hover {
  background: #2563eb;
}

.rooms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  gap: 0.5rem;
}

.rooms-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #e4e4e7;
  letter-spacing: 0.02em;
  flex: 1;
}

.create-room-plus {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  background: #3b82f6;
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.create-room-plus:hover {
  background: #2563eb;
}

#rooms-list {
  list-style: none;
}

#rooms-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.15s;
}

#rooms-list li .room-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  flex-shrink: 0;
  min-width: 1.25rem;
  padding: 0.15rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  background: #3b82f6;
  color: #fff;
  border-radius: 10px;
}

.room-enter-btn {
  flex-shrink: 0;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 500;
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.room-enter-btn:hover {
  background: #2563eb;
}

#rooms-list li:hover {
  background: #27272a;
}

#rooms-list li.active {
  background: #27272a;
  border-left-color: #3b82f6;
}

#rooms-list li.room-loading {
  padding: 1rem;
  color: #a1a1aa;
  font-size: 0.9rem;
}

#rooms-list li.room-error {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  color: #f87171;
  cursor: default;
}

#rooms-list li.room-error:hover {
  background: transparent;
}

.retry-rooms-btn {
  padding: 0.5rem 1rem;
  background: #3b82f6;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-start;
  -webkit-tap-highlight-color: transparent;
}

.retry-rooms-btn:hover {
  background: #2563eb;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal.hidden {
  display: none !important;
}

.modal-box {
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-box h3 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
  color: #e4e4e7;
}

.leave-room-text {
  margin: 0 0 1rem 0;
  font-size: 0.95rem;
  color: #a1a1aa;
  line-height: 1.5;
}

.leave-confirm-btn {
  background: #3b82f6;
  border: none;
  color: #fff;
  font-weight: 600;
}

.leave-confirm-btn:hover {
  background: #2563eb;
}

.modal-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  background: #27272a;
  color: #fff;
  font-size: 1rem;
}

.modal-box input:focus {
  outline: none;
  border-color: #3b82f6;
}

.modal-buttons {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.modal-buttons button {
  flex: 1;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.modal-cancel {
  background: #27272a;
  border: 1px solid #3f3f46;
  color: #a1a1aa;
}

.modal-cancel:hover {
  background: #3f3f46;
  color: #fff;
}

.modal-buttons button[type="submit"],
.modal-buttons .modal-primary {
  background: #3b82f6;
  border: none;
  color: #fff;
  font-weight: 600;
}

.modal-buttons button[type="submit"]:hover,
.modal-buttons .modal-primary:hover {
  background: #2563eb;
}

.room-start-text {
  margin: 0 0 1rem 0;
  font-size: 0.95rem;
  color: #a1a1aa;
  line-height: 1.5;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.empty-chat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #71717a;
  font-size: 1rem;
}

#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages-container {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.messages::-webkit-scrollbar,
.contacts::-webkit-scrollbar,
.send-form textarea::-webkit-scrollbar,
.emoji-picker::-webkit-scrollbar,
#emoji-picker::-webkit-scrollbar {
  width: 10px;
}

.messages::-webkit-scrollbar-track,
.contacts::-webkit-scrollbar-track,
.send-form textarea::-webkit-scrollbar-track,
.emoji-picker::-webkit-scrollbar-track,
#emoji-picker::-webkit-scrollbar-track {
  background: #27272a;
  border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb,
.contacts::-webkit-scrollbar-thumb,
.send-form textarea::-webkit-scrollbar-thumb,
.emoji-picker::-webkit-scrollbar-thumb,
#emoji-picker::-webkit-scrollbar-thumb {
  background: #52525b;
  border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover,
.contacts::-webkit-scrollbar-thumb:hover,
.send-form textarea::-webkit-scrollbar-thumb:hover,
.emoji-picker::-webkit-scrollbar-thumb:hover,
#emoji-picker::-webkit-scrollbar-thumb:hover {
  background: #71717a;
}

.messages::-webkit-scrollbar-button,
.contacts::-webkit-scrollbar-button,
.emoji-picker::-webkit-scrollbar-button,
#emoji-picker::-webkit-scrollbar-button {
  background: #27272a;
  border: none;
}

.messages::-webkit-scrollbar-corner,
.contacts::-webkit-scrollbar-corner,
.send-form textarea::-webkit-scrollbar-corner,
.emoji-picker::-webkit-scrollbar-corner,
#emoji-picker::-webkit-scrollbar-corner {
  background: #27272a;
}

.message {
  max-width: 70%;
  padding: 0.6rem 1rem;
  border-radius: 12px;
  font-size: 1.2rem;
  line-height: 1.4;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message.own {
  align-self: flex-end;
  background: #3b82f6;
  color: #fff;
}

.message.other {
  align-self: flex-start;
  background: #27272a;
  border: 1px solid #3f3f46;
}

.msg-author {
  display: block;
  font-size: 0.8rem;
  color: #3b82f6;
  margin-bottom: 0.2rem;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.message time {
  font-size: 0.875rem;
  opacity: 0.8;
}

.msg-status {
  font-size: 0.75rem;
  opacity: 0.9;
}

.msg-status.sent {
  color: rgba(255, 255, 255, 0.9);
}

.msg-status.read {
  color: #93c5fd;
}

/* Ошибка связи */
.connection-error {
  padding: 0.5rem 1rem;
  background: #7f1d1d;
  color: #fecaca;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.connection-error.hidden {
  display: none !important;
}
.connection-error button {
  padding: 0.25rem 0.75rem;
  background: #991b1b;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

/* Бейдж новых сообщений */
.new-messages-badge {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.5rem 1rem;
  background: #3b82f6;
  color: #fff;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: opacity 0.2s, transform 0.2s;
}
.new-messages-badge:hover {
  opacity: 0.95;
  transform: translateX(-50%) scale(1.02);
}
.new-messages-badge.hidden {
  display: none !important;
}

.empty-private-chat {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #71717a;
  font-size: 1rem;
  text-align: center;
  padding: 2rem;
  pointer-events: none;
}
.empty-private-chat.hidden {
  display: none !important;
}

.room-members {
  padding: 1rem 1.25rem;
  border-top: 1px solid #27272a;
}

.room-members.hidden {
  display: none !important;
}

.room-members h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #e4e4e7;
  letter-spacing: 0.02em;
  margin-bottom: 0.5rem;
}

#members-list,
#members-list-mobile {
  list-style: none;
}

#members-list li,
#members-list-mobile li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  margin-bottom: 0.35rem;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background 0.15s;
}

#members-list li:last-child,
#members-list-mobile li:last-child {
  margin-bottom: 0;
}

#members-list li .member-num,
#members-list-mobile li .member-num {
  flex-shrink: 0;
  min-width: 1.5em;
  color: #71717a;
  font-size: 0.9em;
}

#members-list li:hover,
#members-list-mobile li:hover {
  background: #27272a;
}

#members-list li.active,
#members-list-mobile li.active {
  background: rgba(59, 130, 246, 0.2);
}

#members-list li .member-name,
#members-list-mobile li .member-name {
  flex: 1;
  min-width: 0;
  color: #e4e4e7;
  overflow: hidden;
  text-overflow: ellipsis;
}

#members-list li.members-empty,
#members-list-mobile li.members-empty {
  color: #71717a;
  font-size: 0.95rem;
  cursor: default;
  padding: 0.875rem 1.25rem;
}

#members-list li.members-empty:hover,
#members-list-mobile li.members-empty:hover {
  background: transparent;
}

@media (max-width: 768px) {
  .contacts .room-members {
    display: none !important;
  }
  .is-app .contacts .room-members {
    display: block !important;
  }
}

.modal-chat {
  max-width: 400px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.private-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.private-chat-header h3 {
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  background: transparent;
  border: none;
  color: #a1a1aa;
  cursor: pointer;
  border-radius: 6px;
}

.modal-close:hover {
  background: #27272a;
  color: #fff;
}

.private-messages {
  flex: 1;
  min-height: 150px;
  max-height: 250px;
  overflow-y: auto;
  padding: 0.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.private-messages .message {
  max-width: 85%;
}

.private-send-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #3f3f46;
}

.private-send-form .send-form-top,
.private-send-form .send-form-bottom {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  min-width: 0;
}

.private-send-form .send-form-bottom {
  flex-wrap: nowrap;
}

.private-send-form textarea {
  flex: 1;
  min-width: 0;
  padding: 0.6rem;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  background: #27272a;
  color: #fff;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
}

.private-send-form textarea:focus {
  outline: none;
  border-color: #3b82f6;
}

.private-send-form button[type="submit"] {
  padding: 0.6rem 1rem;
  background: #3b82f6;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.private-send-form button[type="submit"]:hover {
  background: #2563eb;
}

.send-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  background: #18181b;
  border-top: 1px solid #27272a;
}

.send-form-top {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.send-form-bottom {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  min-width: 0;
}

.file-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  background: #27272a;
  color: #e4e4e7;
  font-size: 0.9rem;
}

#file-preview-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-preview-remove {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: #3f3f46;
  color: #fff;
  cursor: pointer;
}

.file-preview-remove:hover {
  background: #52525b;
}

.emoji-wrap {
  position: relative;
  flex-shrink: 0;
}

.send-form input,
.send-form textarea {
  flex: 1;
  min-width: 0;
  max-width: 320px;
  padding: 0.75rem 1rem;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  background: #27272a;
  color: #fff;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
}

.send-form textarea {
  min-height: 2.5rem;
  max-height: 8rem;
  line-height: 1.4;
  overflow-y: auto;
}

.send-form input:focus,
.send-form textarea:focus {
  outline: none;
  border-color: #3b82f6;
}

.emoji-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.2rem;
  background: #3b82f6;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.emoji-btn img {
  width: 22px;
  height: 22px;
  display: block;
}
.emoji-btn:hover { opacity: 0.9; }

.emoji-picker {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  background: #18181b;
  border: 1px solid #3f3f46;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
  max-width: min(320px, calc(100vw - 2rem));
}

/* На мобильных и в приложении — панель в пределах экрана */
@media (max-width: 768px) {
  .emoji-picker {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 140px;
    margin: 0;
    max-width: none;
    width: auto;
    grid-template-columns: repeat(6, 1fr);
  }
}

.emoji-picker .emoji-item {
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.emoji-picker .emoji-item img {
  width: 22px;
  height: 22px;
  image-rendering: -webkit-optimize-contrast;
}
.emoji-picker .emoji-item:hover {
  background: #3f3f46;
}
.icq-emoji {
  width: 18px;
  height: 18px;
  vertical-align: text-bottom;
}

.send-form button[type="submit"] {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 8px;
  background: #3b82f6;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.send-form button[type="submit"]:hover {
  background: #2563eb;
}

.record-timer {
  display: inline-flex;
  align-items: center;
  padding: 0 0.75rem;
  font-size: 0.9rem;
  color: #dc2626;
  white-space: nowrap;
}
.record-timer::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #dc2626;
  border-radius: 50%;
  margin-right: 0.5rem;
  animation: record-blink 1s infinite;
}
@keyframes record-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.record-btn {
  flex-shrink: 0;
  padding: 0.75rem;
  font-size: 1.2rem;
  background: #27272a;
  border: 1px solid #3f3f46;
  border-radius: 8px;
  cursor: pointer;
}
.record-btn:hover { background: #3f3f46; }
.record-btn.recording {
  background: #dc2626;
  border-color: #dc2626;
  animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: 0.8; } }

.message audio {
  max-width: 100%;
  height: 36px;
  margin-top: 0.25rem;
}

.msg-file-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-file-size {
  opacity: 0.8;
  font-size: 0.82rem;
}

.msg-file-caption {
  margin-top: 0.35rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-image-link {
  display: inline-block;
  max-width: 300px;
  margin-top: 0.2rem;
}

.msg-image {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
}

#image-preview-modal {
  z-index: 500;
  background: rgba(0, 0, 0, 0.82);
}

.image-preview-box {
  position: relative;
  width: min(92vw, 980px);
  height: min(88vh, 820px);
  display: flex;
  align-items: center;
  justify-content: center;
}

#image-preview-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  transform-origin: center center;
  transition: transform 0.08s ease-out;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  cursor: zoom-in;
}

#image-preview-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 38px;
  height: 38px;
  font-size: 1.8rem;
  background: rgba(24, 24, 27, 0.8);
  border: 1px solid #3f3f46;
}
