:root {
  color-scheme: light dark;
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-soft: #edeefa;
  --text: #1a1f36;
  --muted: #6b7290;
  --line: #dfe1f0;
  --accent: #5b5fd6;
  --accent-strong: #4a4ec2;
  --notice: #e0507a;
  --danger: #d6454f;
  --danger-soft: #fbe9ea;
  --shadow: 0 20px 50px rgba(26, 31, 54, 0.12);

  /* фирменная тёмно-синяя шапка — не зависит от светлой/тёмной темы */
  --topbar-bg: #1a1f36;
  --topbar-text: #f4f5fb;
  --topbar-muted: #9599c2;
  --topbar-line: rgba(255, 255, 255, 0.09);
  --topbar-surface: rgba(255, 255, 255, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141f;
    --surface: #1b1e2e;
    --surface-soft: #242840;
    --text: #eef0fa;
    --muted: #9599b8;
    --line: #2f3350;
    --accent: #7c7ff2;
    --accent-strong: #9a9cf5;
    --notice: #ff6f95;
    --danger: #ff6b6f;
    --danger-soft: #3a2530;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-soft: #edeefa;
  --text: #1a1f36;
  --muted: #6b7290;
  --line: #dfe1f0;
  --accent: #5b5fd6;
  --accent-strong: #4a4ec2;
  --notice: #e0507a;
  --danger: #d6454f;
  --danger-soft: #fbe9ea;
  --shadow: 0 20px 50px rgba(26, 31, 54, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12141f;
  --surface: #1b1e2e;
  --surface-soft: #242840;
  --text: #eef0fa;
  --muted: #9599b8;
  --line: #2f3350;
  --accent: #7c7ff2;
  --accent-strong: #9a9cf5;
  --notice: #ff6f95;
  --danger: #ff6b6f;
  --danger-soft: #3a2530;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
}

html {
  min-width: 330px;
}

body {
  min-height: 100dvh;
  min-width: 330px;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(91, 95, 214, 0.12), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

button {
  cursor: pointer;
}

img {
  -webkit-user-drag: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 72px;
  padding: 0 32px;
  border-bottom: 1px solid var(--topbar-line);
  background: var(--topbar-bg);
  color: var(--topbar-text);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-decoration: none;
  text-align: left;
}

.profile-button {
  border-radius: 8px;
}

.profile-button:hover {
  color: #fff;
}

.topbar small {
  color: var(--topbar-muted);
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  overflow: hidden;
  border-radius: 11px;
  background: #14161f;
  color: #fff;
  font-weight: 800;
}

.topbar .theme-button.icon-button,
.topbar > .toolbar > .icon-button {
  border-color: var(--topbar-line);
  background: var(--topbar-surface);
  color: var(--topbar-text);
}

.topbar .theme-button.icon-button:hover,
.topbar > .toolbar > .icon-button:hover {
  border-color: #7c7ff2;
  background: color-mix(in srgb, #7c7ff2 22%, var(--topbar-surface));
  color: #fff;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
}

.toolbar,
.list-tools,
.modal-actions,
.user-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-button,
.icon-button,
.ghost-button,
.primary-button,
.danger-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 100ms ease;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  place-items: center;
  padding: 0;
  font-size: 1.05rem;
}

.theme-button.icon-button {
  font-size: 1.1rem;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

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

.ghost-button:hover,
.theme-button:hover,
.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.primary-button:active,
.ghost-button:active,
.icon-button:active,
.send-button:active {
  transform: scale(0.94);
}

.danger-button {
  border-color: color-mix(in srgb, var(--danger) 36%, var(--line));
  color: var(--danger);
}

.danger-button:hover {
  background: var(--danger-soft);
}

body[data-page="admin"] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.admin-shell {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 20px;
  width: min(1180px, calc(100% - 40px));
  min-width: 0;
  margin: 28px auto;
  overflow-y: auto;
  min-height: 0;
}

.panel,
.login-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.create-panel,
.users-panel {
  padding: 22px;
}

.section-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 4vw, 2.4rem);
  line-height: 1.05;
}

h2,
h3 {
  font-size: 1.2rem;
}

p,
small {
  color: var(--muted);
}

.create-form,
.login-form,
.modal-body {
  display: grid;
  gap: 14px;
}

label,
.form-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

textarea {
  width: 100%;
  min-height: 44px;
  max-height: 44px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 10px 16px;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  line-height: 1.35;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input.field-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 16%, transparent);
}

.field-error {
  display: none;
  min-height: 1em;
  color: var(--danger);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.15;
}

.field-error.visible {
  display: block;
}

input[type="file"] {
  padding: 9px 12px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.floating-menu {
  position: fixed;
  z-index: 30;
  display: grid;
  min-width: 190px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: menu-pop 120ms ease;
}

@keyframes menu-pop {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.floating-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  text-align: left;
  transition: background-color 120ms ease;
}

.floating-menu button .icon {
  color: var(--muted);
}

.floating-menu button:hover {
  background: var(--surface-soft);
}

.floating-menu button:hover .icon {
  color: var(--accent-strong);
}

.profile-menu {
  top: 66px;
  left: 32px;
}

.list-tools {
  width: min(320px, 100%);
}

.search-input {
  max-width: 260px;
}

.list-tools .search-input {
  max-width: none;
}

.avatar-picker {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 88px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  color: var(--text);
}

.avatar-picker:hover,
.avatar-picker.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

.avatar-picker strong,
.avatar-picker small {
  display: block;
}

.avatar-picker-preview {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 1.6rem;
  font-weight: 800;
}

.avatar-picker-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.secret-box {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.secret-box strong {
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.users-list {
  display: grid;
  gap: 10px;
}

.user-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 14px;
  min-height: 78px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.avatar {
  display: grid;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  overflow: hidden;
  border-radius: 999px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 24%, var(--surface-soft)), var(--surface-soft));
  color: var(--accent-strong);
  font-weight: 800;
}

.avatar.large {
  width: 64px;
  height: 64px;
  font-size: 1.35rem;
}

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

.user-identity,
.user-main {
  min-width: 0;
}

.user-meta {
  display: flex;
  align-items: start;
  gap: 12px;
  min-width: 0;
}

.user-meta-text {
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 6px;
  min-width: 0;
}

.user-meta small,
.user-main small {
  display: block;
  max-width: 100%;
}

.user-title {
  display: block;
  margin-bottom: 8px;
}

.user-title strong {
  overflow-wrap: anywhere;
}

.user-actions {
  position: relative;
  justify-content: flex-end;
  flex-wrap: nowrap;
  width: max-content;
  max-width: 100%;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.action-button {
  position: relative;
  flex: 0 0 auto;
  min-height: 34px;
  width: 34px;
  border-color: transparent;
  background: transparent;
  font-size: 1.05rem;
  line-height: 1;
}

.action-button:hover {
  border-color: var(--line);
  background: var(--surface);
}

.danger-action {
  color: var(--danger);
}

.action-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.action-button:disabled:hover {
  border-color: transparent;
  background: transparent;
}

.action-button::after {
  position: absolute;
  right: 50%;
  bottom: calc(100% + 8px);
  z-index: 5;
  display: none;
  width: max-content;
  max-width: 180px;
  transform: translateX(50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  content: attr(data-tooltip);
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.2;
  pointer-events: none;
}

.action-button:hover::after,
.action-button:focus-visible::after {
  display: block;
}

.status {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.status.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.empty-state {
  display: grid;
  min-height: 160px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.modal {
  width: min(440px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  animation: modal-pop 160ms ease;
}

@keyframes modal-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.46);
  animation: backdrop-fade 160ms ease;
}

@keyframes backdrop-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-body {
  padding: 22px;
}

.crop-modal {
  width: min(560px, calc(100% - 28px));
}

.crop-canvas {
  width: 100%;
  max-width: 512px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  cursor: move;
  touch-action: none;
}

.login-shell {
  display: grid;
  min-height: calc(100dvh - 72px);
  place-items: center;
  padding: 28px;
}

body.is-authenticated .login-shell {
  display: block;
  height: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

body.is-authenticated {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.login-panel {
  display: grid;
  gap: 22px;
  width: min(440px, 100%);
  padding: 26px;
}

.login-copy {
  display: grid;
  gap: 8px;
}

.profile-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.form-error {
  min-height: 1.35em;
  color: var(--danger);
  font-weight: 700;
}

.messenger-shell {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  width: 100vw;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

.chat-sidebar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-soft) 54%, var(--surface));
}

.chat-search {
  position: relative;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.chat-search-icon {
  position: absolute;
  top: 50%;
  left: 32px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.chat-search input {
  padding-left: 38px;
}

.chat-list {
  display: grid;
  align-content: start;
  gap: 6px;
  overflow-y: auto;
  padding: 10px;
}

.chat-list-label {
  padding: 8px 8px 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.chat-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.chat-item:hover {
  background: var(--surface-soft);
}

.chat-item.active {
  border-color: var(--line);
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(32, 45, 58, 0.06);
}

.chat-item .avatar {
  width: 42px;
  height: 42px;
  flex-basis: 42px;
}

.chat-item-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.chat-item-text strong,
.chat-item-text small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-badge {
  display: grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  padding: 0 7px;
  background: var(--notice);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
}

.chat-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.chat-empty {
  display: grid;
  height: 100%;
  min-height: 0;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 28px;
  text-align: center;
}

.chat-empty-icon {
  width: 56px;
  height: 56px;
  margin-bottom: 6px;
  color: var(--line);
}

.chat-room {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  border-bottom: 1px solid var(--line);
  padding: 10px 18px;
  background: var(--surface);
}

.chat-back-button {
  display: none;
  flex: 0 0 38px;
  font-size: 1.35rem;
}

.chat-header strong,
.chat-header small {
  display: block;
}

#chatStatus.unread {
  color: var(--notice);
  font-weight: 900;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
}

.messages-list.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -10px;
  background: color-mix(in srgb, var(--accent) 7%, var(--bg));
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.own {
  justify-content: flex-end;
}

.message-row.incoming {
  justify-content: flex-start;
}

.message-bubble {
  position: relative;
  display: grid;
  gap: 6px;
  max-width: 70%;
  min-width: 52px;
  border-radius: 16px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 22px rgba(32, 45, 58, 0.08);
  animation: bubble-in 160ms ease;
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.message-row.own .message-bubble {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
}

.message-bubble::after {
  position: absolute;
  bottom: 0;
  width: 12px;
  height: 12px;
  background: inherit;
  content: "";
}

.message-row.incoming .message-bubble::after {
  left: -5px;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.message-row.own .message-bubble::after {
  right: -5px;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.message-text {
  -webkit-user-select: text;
  user-select: text;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-time {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-self: end;
  font-size: 0.68rem;
}

.message-status {
  display: inline-flex;
  align-items: center;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
}

.message-status.pending {
  color: var(--muted);
}

.message-status.unread,
.message-status.sent {
  color: var(--muted);
}

.message-status.read {
  color: var(--accent-strong);
}

.message-status.double .check + .check {
  margin-left: -3px;
}

.message-image-button {
  display: block;
  max-width: min(360px, 100%);
  border: 0;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  background: var(--surface-soft);
}

.message-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-image.is-lazy {
  opacity: 0;
}

.message-form {
  position: relative;
  display: grid;
  grid-template-columns: 44px 44px minmax(0, 1fr) 44px;
  align-items: end;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 12px;
  background: var(--surface);
}

.attach-button,
.emoji-button,
.mic-button {
  height: 44px;
  border-radius: 999px;
  font-size: 1.2rem;
}

.message-input-wrap {
  position: relative;
  min-width: 0;
}

.recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 0 16px;
  background: var(--surface);
}

.recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--danger);
  animation: recording-pulse 1s ease-in-out infinite;
}

@keyframes recording-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

#recordingTimer {
  flex: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.send-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 900;
  transition: background-color 140ms ease, transform 100ms ease;
}

.send-button:hover {
  background: var(--accent-strong);
}

.mic-button.recording {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.attach-menu {
  display: flex;
  flex-direction: row;
  gap: 6px;
  min-width: 0;
  padding: 10px 8px;
}

.attach-menu .attach-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: auto;
  width: 68px;
  padding: 4px;
  border-radius: 12px;
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
}

.attach-option-icon {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 999px;
  color: #fff;
}

.attach-option-icon .icon {
  width: 22px;
  height: 22px;
}

.attach-icon-photo {
  background: linear-gradient(160deg, #5b5fd6, #4a4ec2);
}

.attach-icon-camera {
  background: linear-gradient(160deg, #e0507a, #c53e64);
}

.attach-icon-file {
  background: linear-gradient(160deg, #3a9ee0, #2f83bd);
}

.emoji-menu {
  padding: 8px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  width: min(280px, 80vw);
}

.emoji-grid button {
  display: grid;
  place-items: center;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: var(--surface-soft);
  font-size: 1.2rem;
}

.emoji-grid button:hover {
  background: var(--line);
}

.avatar-source-actions {
  margin-bottom: 8px;
}

.avatar-source-actions .ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
}

.modal-actions.stacked {
  flex-direction: column;
  align-items: stretch;
}

.message-voice {
  display: flex;
  align-items: center;
  gap: 8px;
}

.message-voice audio {
  max-width: 240px;
  height: 36px;
}

.message-file {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
  padding: 6px 4px;
  color: inherit;
  text-decoration: none;
}

.message-file-icon {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 1.1rem;
}

.message-file-info {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.message-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.message-file-size {
  color: var(--muted);
  font-size: 0.75rem;
}

.consent-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.4);
}

.consent-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 91;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 18px 24px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.consent-text p {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 0.88rem;
}

.consent-text p:last-child {
  margin-bottom: 0;
}

.consent-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.consent-links {
  color: var(--muted);
  font-size: 0.82rem;
}

.consent-links a {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

.consent-links a:hover {
  text-decoration: underline;
}

.consent-accept {
  flex-shrink: 0;
  white-space: nowrap;
}

.doc-modal {
  width: min(640px, calc(100% - 28px));
}

.doc-content {
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}

.doc-content h4 {
  margin: 18px 0 8px;
  color: var(--accent-strong);
  font-size: 0.98rem;
}

.doc-content h4:first-child {
  margin-top: 0;
}

.doc-content p {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
}

.doc-content ul {
  margin: 0 0 8px;
  padding-left: 20px;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
}

@media (max-width: 640px) {
  .consent-banner {
    padding: 14px 16px;
  }

  .consent-footer {
    width: 100%;
    justify-content: space-between;
  }
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100% - 44px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.context-menu {
  min-width: 140px;
}

.image-viewer {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border: 0;
  padding: 0;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.86);
}

.image-viewer::backdrop {
  background: rgba(0, 0, 0, 0.74);
}

.image-viewer-body {
  width: 100%;
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

.image-viewer-stage {
  display: grid;
  min-width: 100%;
  min-height: 100%;
  place-items: center;
  padding: 72px 18px 24px;
}

.image-viewer-stage img {
  display: block;
  max-width: none;
  max-height: none;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.image-viewer-tools {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2;
  display: flex;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
}

.image-viewer-tools .icon-button {
  background: var(--surface);
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .user-card {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .user-actions {
    grid-column: 1;
    justify-self: start;
    margin-top: 2px;
  }
}

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

  .messenger-shell {
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .messenger-shell {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    display: none;
  }

  .messenger-shell.chat-open .chat-sidebar {
    display: none;
  }

  .messenger-shell.chat-open .chat-panel {
    display: block;
  }

  .chat-back-button {
    display: grid;
  }
}

@media (max-width: 420px) {
  .user-card {
    grid-template-columns: 1fr;
  }

  .user-meta {
    align-items: start;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 0 16px;
  }

  .admin-shell {
    width: min(100% - 24px, 1180px);
    margin: 18px auto;
  }

  .section-head {
    display: grid;
  }

  .search-input {
    max-width: none;
  }

  .list-tools {
    width: 100%;
  }

  .secret-box {
    grid-template-columns: 1fr;
  }

  .avatar-picker {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .avatar-picker-preview {
    width: 56px;
    height: 56px;
  }

  .chat-sidebar {
    min-height: 0;
    max-height: none;
    border-right: 0;
  }

  .message-bubble {
    max-width: 86%;
  }
}

/* Форум */

body[data-page="forum"] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.forum-shell {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  overflow-y: auto;
  min-height: 0;
}

.forum-shell h1 {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 20px;
  margin: 0 0 16px;
}

.forum-shell h1 .heading-icon {
  flex-shrink: 0;
}

.forum-back {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  font-size: 14px;
}

.forum-categories,
.forum-topics {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.forum-category,
.forum-topic-summary {
  display: block;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--text);
}

.forum-category strong,
.forum-topic-summary strong {
  display: block;
  font-size: 15px;
}

.forum-category span,
.forum-topic-summary span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.forum-empty {
  color: var(--muted);
  font-size: 14px;
}

.forum-new-topic {
  display: block;
  width: 100%;
  margin-top: 14px;
}

.forum-topic-form {
  margin-top: 16px;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.forum-topic-form label {
  display: block;
  margin-bottom: 12px;
}

.forum-topic-form label span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.forum-topic-form input,
.forum-topic-form textarea {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.forum-topic-form textarea {
  resize: vertical;
}

.forum-topic-form .form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.forum-topic-detail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

.forum-topic-detail strong {
  color: var(--accent);
  display: block;
  margin-bottom: 6px;
}

.forum-topic-author {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.forum-field {
  font-size: 14px;
  margin-bottom: 2px;
}

.forum-field b {
  color: var(--muted);
}

.forum-order-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.quick-accept-button,
.order-complete-button,
.order-cancel-button {
  display: block;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}

.quick-accept-button {
  background: var(--accent);
  color: #ffffff;
}

.order-complete-button {
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line);
}

.order-cancel-button {
  background: var(--danger-soft);
  color: var(--danger);
}

.forum-locked-banner {
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
  font-size: 14px;
}

.forum-admin-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.forum-admin-actions .ghost-button,
.forum-admin-actions .danger-button {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  font-weight: 600;
}

.forum-user-link {
  cursor: pointer;
  text-decoration: none;
}

.forum-user-link:hover {
  text-decoration: underline;
}

.forum-replies {
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.forum-reply {
  border-radius: 16px;
  padding: 8px 12px;
  max-width: 80%;
  width: fit-content;
}

.forum-reply strong {
  color: var(--accent-strong);
  font-size: 26px;
  font-weight: 800;
  display: block;
  margin-bottom: 2px;
}

.forum-reply p {
  margin: 2px 0 0;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
}

.forum-reply.theirs {
  background: var(--surface-soft);
}

.forum-reply.mine {
  background: color-mix(in srgb, var(--accent) 20%, var(--surface));
  color: var(--text);
  margin-left: auto;
}

.forum-reply.mine p {
  color: var(--text);
}

.forum-reply.mine strong {
  color: var(--accent-strong);
}

.forum-attachment-image {
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  margin-top: 4px;
  display: block;
}

.forum-attachment-link {
  display: inline-block;
  margin-top: 4px;
  color: inherit;
  text-decoration: underline;
}

.forum-reply-form {
  margin-top: 8px;
}

.forum-attachment-audio {
  display: block;
  max-width: 240px;
  height: 36px;
  margin-top: 4px;
}
