/* Pllato Chat — стили */

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

:root {
  --bg-0: #0e0e12;
  --bg-1: #16161d;
  --bg-2: #1f1f2a;
  --bg-3: #27273a;
  --border: rgba(255, 255, 255, 0.08);
  --text-1: #f0eefc;
  --text-2: #c5c2db;
  --text-3: #9896b0;
  --accent: #a87fff;
  --accent-2: #7c5cfc;
  --success: #3fd88e;
  --danger: #f05975;
  --warn: #f5c14b;
  
  --header-h: 60px;
  --sidebar-w: 280px;
  
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Manrope, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
}

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

.accent { color: var(--accent); }

/* ============ LOGIN ============ */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}

.login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}

.login-card h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-3);
  margin-bottom: 24px;
  font-size: 14px;
}

.login-error {
  background: rgba(240, 89, 117, 0.1);
  border: 1px solid rgba(240, 89, 117, 0.3);
  color: var(--danger);
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 12px;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s, background 0.15s;
}

.btn-primary {
  background: var(--accent-2);
  color: white;
  width: 100%;
}

.btn-primary:hover { background: var(--accent); }

.btn-secondary {
  background: var(--bg-3);
  color: var(--text-1);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg-2); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--bg-3);
  color: var(--text-1);
}

/* ============ APP LAYOUT ============ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-1);
  z-index: 5;
}

.logo {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sidebar-user {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-2);
}

.sidebar-user .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-weight: 600;
  color: var(--text-1);
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-section {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.sidebar-section:last-child { border-bottom: none; }

.sidebar-section-title {
  padding: 0 16px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 600;
}

.channels-list {
  display: flex;
  flex-direction: column;
}

.channel-item {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}

.channel-item:hover { background: var(--bg-2); }
.channel-item.active { background: var(--bg-3); }

.channel-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  color: var(--text-2);
}

.channel-item.active .channel-icon { color: var(--accent); }

.channel-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}

.channel-unread {
  background: var(--accent-2);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.channel-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ============ MAIN ============ */
.main {
  display: flex;
  flex-direction: column;
  background: var(--bg-0);
  overflow: hidden;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-3);
  gap: 12px;
}

.chat-empty-icon { font-size: 48px; opacity: 0.5; }

.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 20px 12px;
  border-bottom: 1px solid var(--border);
  min-height: var(--header-h);
  flex-shrink: 0;
  background: var(--bg-1);
}

.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info.clickable {
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 8px;
  margin: -4px -8px;
  transition: background 0.15s;
}
.chat-header-info.clickable:hover {
  background: var(--bg-2);
}
.chat-title { font-weight: 600; font-size: 16px; }
.chat-subtitle { font-size: 12px; color: var(--text-3); }

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.online-count {
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.online-count::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.messages-loading {
  text-align: center;
  color: var(--text-3);
  padding: 20px;
  font-size: 13px;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message {
  display: flex;
  gap: 12px;
  padding: 6px 0;
  /* Отключаем нативное iOS выделение текста и callout-меню при longpress
     чтобы наше контекстное меню работало корректно */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Внутри редактируемого textarea и инпутов выделение НУЖНО оставить */
.message-edit-input,
.message textarea,
.message input {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}

.message + .message { margin-top: 0; }

.message.grouped {
  padding-top: 0;
  margin-top: -4px;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.message.grouped .message-avatar { visibility: hidden; height: 0; }

.message-body { flex: 1; min-width: 0; }

.message-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.message-author { font-weight: 600; font-size: 14px; }
.message-time { font-size: 11px; color: var(--text-3); }

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-1);
  font-size: 14px;
}

.message-day-divider {
  text-align: center;
  margin: 16px 0;
  position: relative;
  font-size: 12px;
  color: var(--text-3);
}

.message-day-divider::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: var(--border);
  z-index: 0;
}

.message-day-divider span {
  background: var(--bg-0);
  padding: 0 12px;
  position: relative;
  z-index: 1;
}

/* ============ COMPOSER ============ */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
  box-sizing: border-box;
}

.message-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-1);
  padding: 10px 14px;
  /* font-size 16px — критично для iOS PWA: при меньшем размере Safari зумит страницу при фокусе */
  font-size: 16px;
  resize: none;
  max-height: 200px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.message-input:focus { border-color: var(--accent-2); }

.send-btn {
  background: var(--accent-2);
  color: white;
  border: none;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  min-width: 40px;
  font-size: 16px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.send-btn:hover { background: var(--accent); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 16px; font-weight: 700; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.modal-footer .btn { flex: 0 1 auto; min-width: 100px; padding: 10px 20px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus { border-color: var(--accent-2); }

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.radio:hover { background: var(--bg-3); }

.radio input { margin-top: 2px; }

/* ============ MOBILE ============ */
.mobile-only { display: none; }

@media (max-width: 768px) {
  :root { --sidebar-w: 100%; }
  
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 100%;
  }
  
  .sidebar {
    grid-column: 1;
    grid-row: 1;
    z-index: 10;
  }
  
  .main {
    grid-column: 1;
    grid-row: 1;
    z-index: 5;
    display: none;
  }
  
  .app.in-chat .sidebar { display: none; }
  .app.in-chat .main { display: flex; }
  
  .mobile-only { display: inline-flex; }
}

/* ============ EXTENSIONS for v2 (auth, user mgmt) ============ */

.form-group { margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

.form-hint {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
}

.login-success {
  background: rgba(63, 216, 142, 0.1);
  border: 1px solid rgba(63, 216, 142, 0.3);
  color: var(--success);
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
}

.btn-icon {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-1);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--bg-2); }

.btn-sm {
  padding: 6px 12px !important;
  font-size: 12px !important;
  min-width: 0 !important;
}

.btn-danger {
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
}
.btn-danger:hover { opacity: 0.85; }

.modal-wide { max-width: 640px; }

.users-mgmt-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.users-mgmt-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  gap: 12px;
}

.users-mgmt-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.users-mgmt-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.users-mgmt-name {
  font-weight: 600;
  font-size: 14px;
}

.users-mgmt-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.users-mgmt-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  align-items: stretch;
  /* Фиксированная ширина блока кнопок, чтобы все строки выглядели одинаково */
  width: 360px;
  flex-shrink: 0;
}

.users-mgmt-actions .btn {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 8px 10px;
  font-size: 13px;
}

.credentials-box {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: text;
}

@media (max-width: 700px) {
  .users-mgmt-item {
    flex-direction: column;
    align-items: flex-start;
  }
  .users-mgmt-actions {
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }
}

/* ============ Mini user card on click ============ */
.user-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 16px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.user-card-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-card-name {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.user-card-meta {
  font-size: 13px;
  color: var(--text-3);
}

.user-card-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.user-card-actions .btn {
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
}

.message-author {
  cursor: pointer;
  border-radius: 4px;
  padding: 0 2px;
  margin: 0 -2px;
  transition: background 0.1s;
}

.message-author:hover {
  background: rgba(168, 127, 255, 0.15);
}

/* Когда показывается модалка с данными созданного юзера или сброшенным паролем —
   она должна быть НАД остальными модалками (управление сотрудниками, новый сотрудник) */
#modal-user-created {
  z-index: 200;
}

.chat-header-info.clickable {
  border-radius: 8px;
  padding: 4px 10px;
  margin: -4px -10px;
  transition: background 0.15s;
  cursor: pointer;
}
.chat-header-info.clickable:hover {
  background: rgba(168, 127, 255, 0.12);
}

.channel-members-add-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 4px;
}

.channel-members-add-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Одинаковая ширина для кнопок Добавить/Удалить в списках участников */
.channel-members-add-item .btn,
#channel-members-list .users-mgmt-actions .btn {
  min-width: 96px;
  flex-shrink: 0;
}

/* ============================================================
   ITERATION 2 — Files, Voice, Search, Lightbox
   ============================================================ */

/* === Sidebar search === */
.sidebar-search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.search-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-1);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}
.search-input:focus { border-color: var(--accent-2); }

.search-results {
  position: absolute;
  left: 12px;
  right: 12px;
  top: calc(100% - 1px);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 4px;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-3); }

.search-result-channel {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.search-result-text {
  font-size: 13px;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}
.search-results .empty,
.search-results .loading {
  padding: 14px;
  font-size: 13px;
  color: var(--text-3);
  text-align: center;
}
.search-highlight {
  background: rgba(168, 127, 255, 0.3);
  padding: 0 2px;
  border-radius: 2px;
}

/* === Composer buttons === */
.composer-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  width: 36px;
  height: 36px;
  min-width: 36px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.composer-btn:hover { opacity: 0.8; }
.composer-btn:active { transform: scale(0.92); }

.voice-btn { display: none !important; } /* отключено в этой итерации */

/* === Attachment preview (выше composer-а) === */
.attachment-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}
.attachment-preview-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 22px;
  overflow: hidden;
}
.attachment-preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.attachment-preview-info {
  flex: 1;
  min-width: 0;
  font-size: 13px;
}
.attachment-preview-info .name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-preview-info .size {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
}
.attachment-preview-info .progress {
  height: 3px;
  background: var(--bg-3);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.attachment-preview-info .progress-bar {
  height: 100%;
  background: var(--accent-2);
  width: 0%;
  transition: width 0.2s;
}

/* === Message attachments (картинки/видео/аудио/документы в сообщениях) === */
.message-image {
  max-width: 360px;
  max-height: 360px;
  border-radius: 12px;
  margin-top: 4px;
  cursor: pointer;
  display: block;
  background: var(--bg-3);
}
.message-video {
  max-width: 360px;
  max-height: 360px;
  border-radius: 12px;
  margin-top: 4px;
  display: block;
  background: black;
}
.message-audio {
  margin-top: 4px;
  max-width: 360px;
}
.message-audio audio { width: 100%; height: 36px; }

.message-doc {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-top: 4px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  max-width: 360px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.message-doc:hover { background: var(--bg-3); }
.message-doc:active { transform: scale(0.99); }
.message-doc-icon {
  width: 40px;
  height: 40px;
  background: var(--accent-2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
  flex-shrink: 0;
}
.message-doc-info { min-width: 0; flex: 1; }
.message-doc-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-doc-size { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* === Lightbox === */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
}
.lightbox-close,
.lightbox-download {
  position: absolute;
  top: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.lightbox-close { right: 20px; }
.lightbox-download { right: 76px; font-size: 20px; }
.lightbox-close:hover,
.lightbox-download:hover { background: rgba(255,255,255,0.2); }

@media (max-width: 600px) {
  .lightbox-close,
  .lightbox-download {
    top: calc(env(safe-area-inset-top, 0px) + 20px);
  }
  .message-image,
  .message-video,
  .message-audio,
  .message-doc { max-width: 100%; }
}

/* === Drag and drop overlay === */
.dnd-overlay {
  position: absolute;
  inset: 0;
  background: rgba(168, 127, 255, 0.15);
  border: 3px dashed var(--accent-2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--accent-2);
  font-weight: 600;
  z-index: 100;
  pointer-events: none;
}

/* ============================================================
   ITERATION 3 — Reactions, Reply, Mentions, Pinned, Edit, Delete, Typing
   ============================================================ */

/* === Reactions bar под сообщением === */
.reactions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.reaction-chip:hover { background: var(--bg-3); }
.reaction-chip.mine { 
  background: rgba(168, 127, 255, 0.15);
  border-color: var(--accent-2);
}
.reaction-chip .count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
}
.reaction-chip.mine .count { color: var(--accent-2); }

/* === Emoji picker (popup) === */
.emoji-picker {
  position: fixed;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  gap: 2px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 1100;
}
.emoji-btn {
  background: transparent;
  border: none;
  font-size: 22px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
}
.emoji-btn:hover { background: var(--bg-3); }

/* === Message context menu === */
.message-menu {
  position: fixed;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  min-width: 180px;
  z-index: 1100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.msg-menu-item {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-1);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.msg-menu-item:hover { background: var(--bg-3); }
.msg-menu-item.danger { color: var(--danger); }

/* === Reply preview (в композере) === */
.reply-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}
.reply-preview-bar {
  width: 3px;
  height: 36px;
  background: var(--accent-2);
  border-radius: 2px;
  flex-shrink: 0;
}
.reply-preview-info { flex: 1; min-width: 0; font-size: 13px; }
.reply-preview-author { font-weight: 600; color: var(--accent-2); }
.reply-preview-text {
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  margin-top: 2px;
}

/* === Reply quote в сообщении (когда сообщение это ответ) === */
.message-reply-quote {
  display: flex;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(168, 127, 255, 0.08);
  border-left: 3px solid var(--accent-2);
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12px;
  max-width: 100%;
}
.message-reply-quote:hover { background: rgba(168, 127, 255, 0.15); }
.message-reply-quote .author { font-weight: 600; color: var(--accent-2); }
.message-reply-quote .preview {
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Mentions (@username) в тексте === */
.mention {
  color: var(--accent-2);
  background: rgba(168, 127, 255, 0.12);
  padding: 0 4px;
  border-radius: 4px;
  font-weight: 500;
}
.mention.self {
  background: rgba(168, 127, 255, 0.25);
  font-weight: 600;
}

/* === Mentions autocomplete popup === */
.mentions-popup {
  position: absolute;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 80;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  min-width: 240px;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.mention-item:last-child { border-bottom: none; }
.mention-item:hover, .mention-item.active { background: var(--bg-3); }
.mention-item .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.mention-item .info { flex: 1; min-width: 0; }
.mention-item .name { font-size: 13px; font-weight: 500; }
.mention-item .username { font-size: 11px; color: var(--text-3); }

/* === Pinned bar === */
.pinned-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: rgba(168, 127, 255, 0.08);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
}
.pinned-bar:hover { background: rgba(168, 127, 255, 0.12); }
.pinned-icon { color: var(--accent-2); font-size: 14px; }
.pinned-content {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pinned-content .pinned-author { font-weight: 600; color: var(--text-1); margin-right: 6px; }
.pinned-nav {
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

/* === Edited / Deleted === */
.edited-mark {
  font-size: 11px;
  color: var(--text-3);
  margin-left: 6px;
  font-style: italic;
  user-select: none;
}
.message-deleted {
  color: var(--text-3);
  font-style: italic;
  font-size: 13px;
}
.message-deleted-show-original {
  color: var(--accent-2);
  cursor: pointer;
  font-size: 11px;
  margin-left: 6px;
  text-decoration: underline;
}

/* === Edit inline === */
.message-edit-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--accent-2);
  border-radius: 8px;
  color: var(--text-1);
  padding: 6px 10px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 32px;
}
.message-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-3);
}
.message-edit-actions a {
  color: var(--accent-2);
  cursor: pointer;
  text-decoration: underline;
}

/* === Typing indicator === */
.typing-indicator {
  font-size: 12px;
  color: var(--accent-2);
  font-style: italic;
}
.typing-dots::after {
  content: '';
  display: inline-block;
  animation: typing-dots 1.2s steps(4) infinite;
  width: 18px;
  text-align: left;
  letter-spacing: 1px;
}
@keyframes typing-dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* === Message hover — кнопка меню ⋯ === */
.message {
  position: relative;
}
.message-actions {
  position: absolute;
  top: 6px;
  right: 8px;
  display: none;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  z-index: 5;
}
.message:hover .message-actions { display: flex; }
.message-actions button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--text-2);
  font-size: 14px;
}
.message-actions button:hover { background: var(--bg-3); color: var(--text-1); }

@media (max-width: 600px) {
  /* На мобиле hover меню скрываем — там longpress */
  .message-actions { display: none !important; }
}

/* === History modal === */
.history-entry {
  padding: 10px 12px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}
.history-entry .action {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.history-entry .action.edit { color: var(--accent-2); }
.history-entry .action.delete { color: var(--danger); }
.history-entry .meta { font-size: 11px; color: var(--text-3); margin-bottom: 6px; }
.history-entry .text {
  font-size: 13px;
  color: var(--text-1);
  white-space: pre-wrap;
  word-break: break-word;
}
.history-current {
  padding: 10px 12px;
  background: rgba(168, 127, 255, 0.08);
  border: 1px solid var(--accent-2);
  border-radius: 10px;
  margin-bottom: 16px;
}

/* === Mute indicator === */
.channel-mute-icon {
  font-size: 11px;
  opacity: 0.6;
  margin-right: 4px;
}
.channel-item.muted .channel-name {
  opacity: 0.7;
}
.channel-item.muted.active .channel-name {
  opacity: 1;
}

/* === Auto-add toggle в модалке участников === */
.channel-auto-add-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
  cursor: pointer;
  user-select: none;
}
.channel-auto-add-toggle:hover { background: var(--bg-3); }
.channel-auto-add-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 2px 0 0 0;
  flex-shrink: 0;
  accent-color: var(--accent-2);
  cursor: pointer;
}
.channel-auto-add-toggle .toggle-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-1);
}
.channel-auto-add-toggle .toggle-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}

/* iOS Safari зумит страницу при фокусе на input/textarea с font-size < 16px.
   Поднимаем размер шрифта на всех текстовых инпутах для мобильных устройств. */
@media (max-width: 768px) {
  input[type="text"],
  input[type="password"],
  input[type="email"],
  input[type="search"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  textarea,
  .form-input,
  .search-input {
    font-size: 16px !important;
  }
}

/* Фикс ширины кнопок "Добавить"/"Удалить" в списке участников канала */
.channel-members-add-item .btn {
  min-width: 110px;
  max-width: 110px;
  flex-shrink: 0;
}

/* ============================================================
   AVATARS WITH IMAGES (Iter 4)
   ============================================================ */

/* Аватарка может содержать <img> — стилизуем его внутри */
.avatar img,
.message-avatar img,
.users-mgmt-avatar img,
.channel-avatar img,
.profile-avatar img,
#user-card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}

/* Когда внутри img — убираем текст-инициалы */
.avatar:has(img),
.message-avatar:has(img),
.users-mgmt-avatar:has(img),
.channel-avatar:has(img),
.profile-avatar:has(img),
#user-card-avatar:has(img) {
  background: var(--bg-2);
  color: transparent;
  overflow: hidden;
}

/* Уменьшенная аватарка для списков добавления */
.avatar-sm {
  width: 32px !important;
  height: 32px !important;
  font-size: 12px !important;
}

/* Профиль — большая аватарка с камерой поверх */
.profile-avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.profile-avatar-wrapper {
  position: relative;
  width: 100px;
  height: 100px;
}

.profile-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 600;
  overflow: hidden;
}

.profile-avatar-camera {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  border: 2px solid var(--bg-1);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.profile-avatar-camera:hover { transform: scale(1.1); }
.profile-avatar-camera:active { transform: scale(0.95); }

.btn-link {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  text-decoration: underline;
}
.btn-link:hover { opacity: 0.8; }
