:root {
  --radius: 12px;
  --sidebar-w: 280px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-hover: #5ca0ff;
  --bubble-me: #1e3a5f;
  --bubble: #243044;
}

[data-chat-theme="ocean"] {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-hover: #5ca0ff;
  --bubble-me: #1e3a5f;
  --bubble: #243044;
}

[data-chat-theme="telegram"] {
  --bg: #17212b;
  --surface: #242f3d;
  --border: #3a4f63;
  --text: #f4f7fa;
  --muted: #8ca0b3;
  --accent: #5288c1;
  --accent-hover: #6ba3da;
  --bubble-me: #2b5278;
  --bubble: #2f3b4c;
}

[data-chat-theme="whatsapp"] {
  --bg: #0b141a;
  --surface: #202c33;
  --border: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-hover: #06cf9c;
  --bubble-me: #005c4b;
  --bubble: #202c33;
}

[data-chat-theme="max"] {
  --bg: #14151f;
  --surface: #1f2029;
  --border: #353747;
  --text: #f2f3f7;
  --muted: #9aa0b5;
  --accent: #4986e7;
  --accent-hover: #6b9ef0;
  --bubble-me: #2a3d6b;
  --bubble: #2a2b38;
}

[data-chat-theme="modern"] {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #f0f6fc;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --bubble-me: #1f3a5f;
  --bubble: #21262d;
}

[data-chat-theme="day"] {
  --bg: #ffffff;
  --surface: #f0f2f5;
  --border: #d1d7db;
  --text: #111b21;
  --muted: #667781;
  --accent: #008069;
  --accent-hover: #00a884;
  --bubble-me: #d9fdd3;
  --bubble: #ffffff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  min-height: 0;
  /* Electron/Windows (Chromium) может некорректно трактовать dvh; даём надёжный fallback */
  height: 100vh;
  max-height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
}

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.top h1 {
  margin: 0;
  font-size: 1.35rem;
  flex: 1;
}

.status {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.status.online {
  color: #7dffb3;
  border-color: #2a5c45;
}

.btn-text {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 400px;
}

#auth {
  flex: 0 0 auto;
  width: 100%;
  max-width: 420px;
  margin: 40px auto 0;
  max-height: calc(100dvh - 140px);
  overflow-y: auto;
}

.panel h2 {
  margin: 16px 0 0;
  font-size: 1rem;
  color: var(--muted);
}

.panel h2:first-child {
  margin-top: 0;
}

.panel label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"] {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  min-height: 44px;
}

.panel button {
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.auth-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.auth-link {
  padding: 0;
  background: transparent !important;
  border: none !important;
  color: var(--accent) !important;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.auth-link:hover {
  color: var(--accent-hover) !important;
}

.auth-subpanel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.auth-login-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.auth-otp-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-otp-block:not(.hidden) {
  margin-top: 4px;
}

.auth-otp-lead {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.auth-otp-back {
  align-self: flex-start;
  margin-top: 4px;
}

.hidden {
  display: none !important;
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-block {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  overflow-y: auto;
  max-height: 45vh;
}

/* Единое "окно": беседы + пользователи в одной прокрутке */
.sidebar-block--main {
  overflow: hidden;
  max-height: none;
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 52%, transparent) transparent;
}

body.drag-drop-active #sideList button[data-conv-id].drop-target {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 40%, transparent);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.drop-overlay-inner {
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px dashed color-mix(in srgb, var(--accent) 70%, var(--border));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 14px 48px rgba(0, 0, 0, 0.35);
  text-align: center;
  max-width: min(420px, 92vw);
}

.drop-overlay-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--text);
}

.drop-overlay-sub {
  font-size: 0.9rem;
}

body.drag-drop-active .drop-overlay {
  display: flex;
}

.sidebar-block h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.sidebar-search-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 10px;
}

.user-search.user-search--sidebar {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.user-search.user-search--sidebar .user-search-input {
  width: 100%;
  min-height: 44px;
}

.sidebar-search-row .btn-group-plus {
  width: 44px;
  min-width: 44px;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-search-row .btn-group-plus.btn-small {
  margin-bottom: 0;
}

.user-search {
  margin-bottom: 10px;
  position: relative;
  z-index: 3;
}

.user-search-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.user-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 50vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 52%, transparent) transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  z-index: 100;
}

.btn-small {
  width: 100%;
  margin-bottom: 8px;
  padding: 8px;
  font-size: 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.btn-group-plus {
  font-size: 1.5rem;
  line-height: 1;
  padding: 10px 0;
}

.group-plus-menu {
  position: fixed;
  z-index: 120;
  min-width: 220px;
  padding: 6px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}

.group-plus-menu-row {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
}

.group-plus-menu-row:hover {
  background: var(--bubble);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-list li {
  margin: 0;
}

.nav-list button {
  width: 100%;
  text-align: left;
  padding: 10px 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.nav-list button:hover,
.nav-list button.active {
  background: var(--bubble);
}

.nav-list button.flash {
  animation: conv-flash 0.9s ease;
}

@keyframes conv-flash {
  0%,
  100% {
    background: transparent;
  }
  40% {
    background: rgba(61, 139, 253, 0.2);
  }
}

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.user-row .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--border);
  transition: background 0.25s ease;
}

.user-row .dot.online {
  background: #3ecf8e;
  box-shadow: 0 0 6px rgba(62, 207, 142, 0.5);
}

.user-row span.label {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-row-ticks {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
}

.user-row-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--bubble);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: var(--muted);
}

.user-row-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-row-avatar--letter {
  border: 1px solid var(--border);
}

.nav-list button.user-row-btn {
  display: flex;
  align-items: stretch;
}

.conv-row-btn {
  display: block;
  padding: 10px 8px !important;
}

.conv-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  text-align: left;
}

.conv-row-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
}

.avatar-presence-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #3ecf8e;
  box-shadow: 0 0 0 2px var(--panel, var(--bg));
  pointer-events: none;
}

.conv-row-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--bubble);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--muted);
  border: 1px solid var(--border);
}

.conv-row-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.conv-row-mid {
  flex: 1;
  min-width: 0;
}

.conv-row-title {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.95rem;
}

.conv-row-preview {
  font-size: 0.8rem;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-row-right {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  max-width: 44%;
}

.conv-row-time {
  font-size: 0.75rem;
  white-space: nowrap;
}

.conv-row-time-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  width: 100%;
  flex-wrap: nowrap;
}

.sidebar-pin-ico {
  font-size: 0.8rem;
  line-height: 1;
  color: var(--muted);
  flex-shrink: 0;
}

.sidebar-unread-badge {
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 5px;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.conv-row-ticks {
  min-height: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.dm-receipt {
  display: inline-flex;
  align-items: center;
  line-height: 0;
}

.dm-receipt--read {
  color: #4ea4ff;
}

.dm-receipt--delivered {
  color: var(--muted);
  opacity: 0.88;
}

.dm-receipt--none {
  color: var(--muted);
  opacity: 0.55;
}

.msg-outgoing-receipt {
  display: inline-flex;
  align-items: center;
  line-height: 0;
  flex-shrink: 0;
}

/* В ленте чата: на тёмных/синих пузырях «мои» стандартный --muted почти не виден */
.msg.me .msg-time .msg-outgoing-receipt .dm-receipt--read {
  color: #7dd3fc;
  opacity: 1;
}

.msg.me .msg-time .msg-outgoing-receipt .dm-receipt--delivered,
.msg.me .msg-time .msg-outgoing-receipt .dm-receipt--none {
  color: rgba(255, 255, 255, 0.78);
  opacity: 1;
}

[data-chat-theme="day"] .msg.me .msg-time .msg-outgoing-receipt .dm-receipt--read {
  color: #1d4ed8;
}

[data-chat-theme="day"] .msg.me .msg-time .msg-outgoing-receipt .dm-receipt--delivered,
[data-chat-theme="day"] .msg.me .msg-time .msg-outgoing-receipt .dm-receipt--none {
  color: rgba(30, 70, 50, 0.58);
}

.dm-tick-double {
  display: inline-flex;
  align-items: center;
}

.dm-tick-shift {
  display: inline-flex;
  margin-left: -7px;
}

.dm-tick-svg {
  display: block;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.chat-header-wrap {
  position: relative;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-header {
  padding: 12px 16px;
  font-weight: 600;
}

.chat-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.chat-header-main {
  flex: 1;
  min-width: 0;
}

.chat-title {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-subtitle {
  display: block;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.btn-header-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-header-icon:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--bubble);
}

.btn-header-icon[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
}

.chat-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-search-bar.hidden {
  display: none !important;
}

.chat-search-input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

.chat-search-meta {
  font-size: 0.8rem;
  flex-shrink: 0;
  min-width: 3.5rem;
  text-align: center;
}

.btn-search-nav,
.btn-search-close {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.btn-search-close {
  font-size: 1.25rem;
  line-height: 1;
}

.btn-search-nav:hover,
.btn-search-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.msg-search-dim {
  opacity: 0.32;
  pointer-events: none;
}

.msg-search-hit {
  opacity: 1;
  pointer-events: auto;
}

.msg-search-current {
  box-shadow: 0 0 0 2px var(--accent);
  border-radius: var(--radius);
}

.btn-dots {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.btn-dots:hover {
  background: var(--bubble);
}

.conv-popover {
  position: absolute;
  right: 8px;
  top: calc(100% + 4px);
  z-index: 50;
  min-width: 260px;
  max-width: min(360px, 92vw);
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.conv-popover-heading {
  margin: 0 0 8px;
  font-size: 1rem;
}

.conv-popover-line {
  margin: 0 0 8px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.conv-popover .small {
  font-size: 0.8rem;
  margin: 0 0 6px;
}

.conv-members-list {
  margin: 0;
  padding: 0 0 0 18px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.conv-members-list--manage {
  list-style: none;
  padding-left: 0;
}

.conv-members-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  line-height: 1.45;
}

.conv-members-item-text {
  flex: 1 1 0;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: normal;
}

/* .btn-small глобально width:100% — в строке участника сжимает текст в «столбик» букв */
.conv-popover .conv-member-remove.btn-small {
  width: auto;
  min-width: fit-content;
  max-width: 100%;
  margin-bottom: 0;
  align-self: center;
  white-space: nowrap;
}

.conv-member-remove {
  flex-shrink: 0;
  padding: 2px 8px;
  font-size: 0.75rem;
}

.conv-info-add {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.conv-info-readonly {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.conv-info-avatar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.conv-info-avatar-img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bubble);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
}

.conv-info-avatar-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.conv-info-avatar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.conv-info-avatar-actions .btn-small {
  width: auto;
  margin-bottom: 0;
}

.conv-info-readonly-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.35;
}

.conv-info-readonly-hint {
  margin: 6px 0 0;
}

.conv-info-add #convInfoAddBtn {
  width: 100%;
  margin-bottom: 0;
}

.conv-info-add-list {
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 8px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(480px, 92vw);
  padding: 12px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 0.9rem;
  line-height: 1.4;
  text-align: center;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 52%, transparent) transparent;
}

.pinned-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.pinned-bar-body {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.pinned-bar-body .pinned-title {
  font-size: 0.78rem;
  color: var(--muted);
  display: block;
  margin-bottom: 2px;
}

.pinned-bar-body .pinned-text {
  font-size: 0.9rem;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pinned-bar-unpin {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  flex-shrink: 0;
}

.pinned-bar-unpin:hover {
  color: var(--text);
  background: var(--bubble);
}

.messages::-webkit-scrollbar,
.sidebar-list::-webkit-scrollbar,
.user-search-results::-webkit-scrollbar,
.admin-tab-panel::-webkit-scrollbar {
  width: 4px;
}

.messages::-webkit-scrollbar-track,
.sidebar-list::-webkit-scrollbar-track,
.user-search-results::-webkit-scrollbar-track,
.admin-tab-panel::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb,
.sidebar-list::-webkit-scrollbar-thumb,
.user-search-results::-webkit-scrollbar-thumb,
.admin-tab-panel::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 48%, transparent);
  border-radius: 100px;
}

.messages::-webkit-scrollbar-thumb:hover,
.sidebar-list::-webkit-scrollbar-thumb:hover,
.user-search-results::-webkit-scrollbar-thumb:hover,
.admin-tab-panel::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--accent) 38%, color-mix(in srgb, var(--muted) 40%, transparent));
}

.day-separator {
  align-self: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.2;
}

/* Внешний блок: без «пузыря», чтобы кнопки ответа/меню были снаружи */
.msg {
  max-width: min(92%, 100%);
  padding: 0;
  border: none;
  background: transparent;
  word-break: break-word;
  position: relative;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg.me {
  align-self: flex-end;
}

.msg-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Сам пузырь — только текст/время */
.msg-main {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bubble);
  border: 1px solid var(--border);
}

.msg.me .msg-main {
  background: var(--bubble-me);
}

/* Свои сообщения: кнопки между центром чата и пузырём */
.msg.me .msg-row {
  flex-direction: row-reverse;
}

.msg-side {
  flex-shrink: 0;
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
}

.msg-reply-btn {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition:
    opacity 0.15s ease,
    background 0.15s ease,
    transform 0.12s ease;
}

.msg:hover .msg-reply-btn,
.msg:focus-within .msg-reply-btn {
  opacity: 1;
}

.msg-reply-btn:hover {
  background: color-mix(in srgb, var(--accent) 32%, transparent);
  transform: scale(1.05);
}

@media (hover: none) {
  .msg-reply-btn {
    opacity: 0.55;
  }
}

.msg-reply-quote {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.msg-reply-quote--clickable {
  cursor: pointer;
  border-radius: 8px;
  margin: 0 0 8px;
  padding: 6px 8px 8px;
  transition: background 0.12s ease;
}

.msg-reply-quote--clickable:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.msg-reply-quote-bar {
  width: 3px;
  flex-shrink: 0;
  border-radius: 2px;
  background: var(--accent);
  align-self: stretch;
  min-height: 2.25rem;
}

.msg-reply-quote-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

.msg-reply-quote-snippet {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.msg-highlight-flash {
  animation: msg-flash-highlight 1s ease;
}

@keyframes msg-flash-highlight {
  0%,
  40% {
    box-shadow: 0 0 0 2px var(--accent);
  }
  100% {
    box-shadow: none;
  }
}

.msg-menu-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.msg:hover .msg-menu-btn,
.msg:focus-within .msg-menu-btn {
  opacity: 1;
}

.msg-menu-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

@media (hover: none) {
  .msg-menu-btn {
    opacity: 0.55;
  }
}

.msg-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  min-width: min(280px, calc(100vw - 48px));
  max-width: calc(100vw - 32px);
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  z-index: 50;
  overflow: hidden;
}

.msg-menu.open {
  display: block;
}

/* Не обрезается #messages (overflow); координаты задаёт app.js */
.msg-menu.msg-menu--fixed {
  position: fixed;
  margin-top: 0;
  right: auto !important;
  z-index: 240;
  max-height: min(75vh, calc(100dvh - 20px));
  overflow-x: hidden;
  overflow-y: auto;
}

.msg-menu-reactions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 2px;
  padding: 10px 8px 10px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.12);
}

.msg-menu-emoji-pick {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, transform 0.12s ease;
}

.msg-menu-emoji-pick:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.08);
}

.msg-menu-emoji-pick:active {
  transform: scale(0.95);
}

.msg-menu-emoji-more {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin-left: 2px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.msg-menu-emoji-more:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
}

.msg-menu-chevron {
  display: block;
}

.msg-menu-reactions-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 10px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.08);
}

.msg-menu-reactions-extra.hidden {
  display: none !important;
}

.msg-menu-divider {
  display: none;
}

.msg-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.msg-menu-item-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
}

.msg-menu-item-row:hover {
  background: rgba(255, 255, 255, 0.06);
}

.msg-menu-ico {
  flex-shrink: 0;
  width: 28px;
  text-align: center;
  font-size: 1.15rem;
  line-height: 1;
}

.msg-menu-label {
  flex: 1;
  min-width: 0;
}

.msg-menu-item--danger,
.msg-menu-item--danger .msg-menu-label {
  color: #ff6b6b;
}

.msg-menu-item--danger:hover {
  background: rgba(255, 80, 80, 0.12);
}

.msg-menu-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.msg-menu-item:disabled:hover {
  background: transparent;
}

.msg-menu-del {
  position: relative;
  padding: 0;
}

.msg-menu-del-toggle {
  width: 100%;
  border: none;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.msg-submenu {
  display: none;
  padding: 0 0 6px;
  background: rgba(0, 0, 0, 0.15);
}

.msg-menu-del.open .msg-submenu {
  display: block;
}

.msg-submenu .msg-menu-item-row {
  padding-left: 24px;
  font-size: 0.88rem;
  color: var(--muted);
}

.msg-submenu .msg-menu-item-row:hover {
  color: var(--text);
}

.msg-reaction-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.msg-reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.msg-reaction-chip.me {
  border-color: var(--accent);
  background: rgba(61, 139, 253, 0.2);
}

.msg-edited-badge {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 400;
}

.msg-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.msg-time {
  align-self: flex-end;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.msg-body {
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-caption,
.msg-text-plain {
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-thumb {
  max-width: min(280px, 85vw);
  max-height: 200px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  display: block;
}

.msg-thumb + .msg-thumb,
.msg-thumb + .file-link,
.file-link + .msg-thumb,
.file-link + .file-link {
  margin-top: 8px;
}

.msg a.file-link {
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.composer-form {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.reply-preview-row {
  padding: 10px 14px 10px 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

.reply-preview-row.hidden {
  display: none !important;
}

.reply-preview-inner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.reply-preview-ico {
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1.2;
  flex-shrink: 0;
  margin-top: 2px;
}

.reply-preview-main {
  flex: 1;
  min-width: 0;
}

.reply-preview-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
}

.reply-preview-snippet {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview-cancel {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.reply-preview-cancel:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.composer-attach-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.composer-attach-menu {
  position: fixed;
  z-index: 130;
  min-width: 220px;
  padding: 6px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}

.composer-attach-menu-row {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
}

.composer-attach-menu-row:hover {
  background: var(--bubble);
}

.composer-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: flex-end;
  padding: 12px;
}

.composer-row #text {
  min-height: 44px;
  max-height: 200px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font: inherit;
  line-height: 1.35;
  width: 100%;
  box-sizing: border-box;
}

.composer-row.text-hidden #text {
  display: none;
}

.attachment-row {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--border);
  animation: attach-in 0.2s ease;
}

.attachment-row-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding-top: 10px;
}

.attachment-row-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

@keyframes attach-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.attachment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
}

.attachment-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 36px 6px 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.attachment-chip-preview {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bubble);
  border: 1px solid var(--border);
}

.attachment-chip-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-chip-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.attachment-chip-meta {
  min-width: 0;
  flex: 1;
}

.attachment-chip-name {
  display: block;
  font-size: 0.8rem;
  color: var(--text);
  word-break: break-word;
}

.attachment-chip-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: var(--bubble);
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.attachment-chip-remove:hover {
  background: var(--border);
  color: var(--text);
}

.attachment-caption-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.attachment-caption-label textarea {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.35;
  min-height: 44px;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
}

.btn-attachment-cancel {
  align-self: flex-start;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.btn-attachment-cancel:hover {
  color: var(--text);
}

.composer-field-ctx {
  position: fixed;
  z-index: 140;
  min-width: 180px;
  padding: 6px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 14px 48px rgba(0, 0, 0, 0.35);
}

.composer-field-ctx-item {
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.composer-field-ctx-item:hover {
  background: var(--bubble);
}

#file {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  cursor: zoom-out;
}

.lightbox.hidden {
  display: none;
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.btn-icon {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  width: 44px;
  padding: 0;
  border-radius: 10px;
  min-height: 44px;
  cursor: pointer;
  font-size: 1.2rem;
}

#btnSend {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  min-height: 44px;
  cursor: pointer;
  font: inherit;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.modal {
  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-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-box h3 {
  margin-top: 0;
}

.edit-msg-label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.edit-msg-label textarea {
  width: 100%;
  min-height: 120px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  resize: vertical;
}

.modal-members label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  cursor: pointer;
}

.forward-sections {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.forward-section {
  flex: 1;
  min-width: 0;
}

.forward-section-title {
  margin-bottom: 6px;
}

@media (max-width: 520px) {
  .forward-sections {
    flex-direction: column;
  }
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.modal-actions button {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.modal-actions button:last-child {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.modal-actions-delete button:last-child {
  background: #b83232;
  border-color: #b83232;
  color: #fff;
}

.modal-actions-delete button:last-child:hover {
  filter: brightness(1.08);
}

.modal-delete-account {
  z-index: 110;
}

.profile-delete-row {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.profile-logout-row {
  margin-top: 14px;
}

.btn-profile-logout {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
}

.btn-profile-logout:hover {
  background: var(--bubble);
}

.btn-profile-delete {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, #e57373 55%, var(--border));
  background: transparent;
  color: #e57373;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
}

.btn-profile-delete:hover {
  background: color-mix(in srgb, #e57373 12%, transparent);
}

.delete-account-heading {
  margin-top: 0;
  font-size: 1.1rem;
}

.delete-account-text {
  margin: 0 0 8px;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--text);
}

.modal-box-delete-account {
  max-width: 420px;
}

.top-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
}

.btn-gear {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-gear:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.user-menu-popover {
  position: fixed;
  z-index: 260;
  min-width: 220px;
  padding: 8px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.user-menu-popover.hidden {
  display: none !important;
}

.user-menu-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.user-menu-row:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.user-menu-ico {
  width: 28px;
  text-align: center;
  font-size: 1.1rem;
}

.modal-box-profile {
  max-width: 420px;
}

.modal-admin {
  z-index: 115;
}

.modal-admin-edit {
  z-index: 125;
}

.modal-box-admin {
  max-width: min(960px, 96vw);
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 16px;
}

.admin-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.admin-modal-head h3 {
  margin: 0;
  font-size: 1.2rem;
}

.btn-admin-close {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.btn-admin-close:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.admin-modal-lead {
  margin: 0 0 12px;
}

.admin-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 2px;
}

.admin-tab {
  padding: 8px 14px;
  border: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
}

.admin-tab:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 6%, transparent);
}

.admin-tab.active {
  color: var(--accent);
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.admin-tab-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 10px;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 52%, transparent) transparent;
}

.admin-tab-panel.hidden {
  display: none !important;
}

.admin-section-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
}

.admin-section-title-sub {
  margin: 22px 0 8px;
}

.admin-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--muted);
}

.admin-field input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  min-height: 44px;
}

.admin-field-row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.admin-field-row input[type="checkbox"] {
  min-height: auto;
  width: auto;
}

.admin-enc-hint {
  margin: -6px 0 14px;
}

.admin-enc-key-footnote {
  margin: -4px 0 16px;
}

.admin-smtp-test-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.admin-smtp-test-row .admin-field-inline {
  flex: 1 1 220px;
  margin-bottom: 0;
}

.admin-smtp-test-hint {
  margin: 8px 0 12px;
}

.admin-settings-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-admin-save {
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn-admin-save:hover {
  filter: brightness(1.06);
}

.admin-th-actions {
  width: 44px;
  text-align: center;
}

.btn-admin-dots {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.btn-admin-dots:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.admin-row-menu-popover {
  position: fixed;
  z-index: 270;
  min-width: 200px;
  padding: 6px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.admin-row-menu-popover.hidden {
  display: none !important;
}

.pin-menu-popover {
  position: fixed;
  z-index: 275;
  min-width: 200px;
  padding: 6px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.pin-menu-popover.hidden {
  display: none !important;
}

.pin-menu-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
}

.pin-menu-row:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.pin-menu-row--danger {
  color: #ff6b6b;
}

.pin-menu-row--danger:hover {
  background: rgba(255, 80, 80, 0.12);
}

.admin-row-menu-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
}

.admin-row-menu-row:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.admin-deleted-lead {
  margin: 0 0 10px;
}

.admin-deleted-wrap {
  max-height: min(420px, 55vh);
}

.admin-journal-wrap {
  max-height: min(520px, 60vh);
}

.admin-journal-table .admin-journal-ua {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
}

.modal-admin-msgs {
  z-index: 120;
}

.modal-box-admin-msgs {
  max-width: min(720px, 96vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.admin-user-msgs-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 0;
  font-size: 0.9rem;
  line-height: 1.45;
}

.admin-msg-line {
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
}

.admin-msg-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.admin-stat {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-stat-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.admin-stat-value {
  font-size: 1.25rem;
  font-weight: 600;
}

.admin-toolbar {
  margin-bottom: 10px;
}

.admin-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.admin-table th,
.admin-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
}

.admin-role-select {
  max-width: 10rem;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}

@media (max-width: 720px) {
  .admin-stats {
    grid-template-columns: 1fr;
  }
}

.profile-avatar-block {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.profile-avatar-wrap {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bubble);
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.profile-avatar-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.profile-avatar-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bubble);
}

.profile-avatar-placeholder.hidden {
  display: none;
}

.profile-avatar-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.profile-field input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  min-height: 44px;
}

.profile-notify {
  margin: 4px 0 16px;
  padding: 14px 0 4px;
  border-top: 1px solid var(--border);
}

.profile-notify-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 12px;
}

.profile-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.profile-switch-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-switch-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.profile-switch-hint {
  font-size: 0.78rem;
  line-height: 1.35;
}

.profile-switch {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 28px;
  cursor: pointer;
}

.profile-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.profile-switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 35%, var(--border));
  transition: background 0.2s ease;
}

.profile-switch-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease;
}

.profile-switch input:checked + .profile-switch-slider {
  background: color-mix(in srgb, var(--accent) 75%, var(--border));
}

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

.profile-switch input:focus-visible + .profile-switch-slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.modal-box-themes {
  max-width: 520px;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.theme-card {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.theme-card:hover {
  border-color: var(--accent);
}

.theme-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}

.theme-card-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.theme-card-swatches {
  display: flex;
  gap: 5px;
  height: 26px;
}

.theme-card-swatches span {
  flex: 1;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--text) 15%, transparent);
}

@media (max-width: 720px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    max-height: 40vh;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .theme-grid {
    grid-template-columns: 1fr;
  }
}
