:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #edf1f5;
  --text: #17202a;
  --muted: #647080;
  --line: #d9e0e8;
  --accent: #0f8b8d;
  --accent-strong: #0b6f70;
  --notice: #d63b61;
  --danger: #c53d37;
  --danger-soft: #fce7e5;
  --shadow: 0 20px 50px rgba(32, 45, 58, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --surface: #1d232a;
    --surface-soft: #252d35;
    --text: #edf2f7;
    --muted: #9aa7b5;
    --line: #34404d;
    --accent: #38bdb8;
    --accent-strong: #66d4cf;
    --notice: #ff7a95;
    --danger: #ff716a;
    --danger-soft: #3a2425;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #edf1f5;
  --text: #17202a;
  --muted: #647080;
  --line: #d9e0e8;
  --accent: #0f8b8d;
  --accent-strong: #0b6f70;
  --notice: #d63b61;
  --danger: #c53d37;
  --danger-soft: #fce7e5;
  --shadow: 0 20px 50px rgba(32, 45, 58, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14181d;
  --surface: #1d232a;
  --surface-soft: #252d35;
  --text: #edf2f7;
  --muted: #9aa7b5;
  --line: #34404d;
  --accent: #38bdb8;
  --accent-strong: #66d4cf;
  --notice: #ff7a95;
  --danger: #ff716a;
  --danger-soft: #3a2425;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
}

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

html {
  min-width: 330px;
}

body {
  min-height: 100vh;
  min-width: 330px;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(15, 139, 141, 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,
select,
textarea {
  font: inherit;
}

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

button {
  cursor: pointer;
}

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

@keyframes bayati-spin {
  to {
    transform: rotate(1turn);
  }
}

.loading-spinner {
  display: inline-block;
  width: 34px;
  height: 34px;
  border: 3px solid color-mix(in srgb, var(--accent) 18%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: bayati-spin 0.8s linear infinite;
}

.topbar {
  position: relative;
  z-index: 11000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 72px;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(14px);
}

.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: var(--accent-strong);
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.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: 8px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.icon-button {
  width: 38px;
  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);
}

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

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

.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;
}

.panel,
.login-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  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,
select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  width: 100%;
  min-height: 44px;
  max-height: 44px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  line-height: 1.35;
}

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: 10000;
  display: grid;
  min-width: 168px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.floating-menu button {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  text-align: left;
}

.floating-menu button::before {
  width: 22px;
  color: var(--accent-strong);
  content: attr(data-icon);
  font-size: 1rem;
  line-height: 1;
  text-align: center;
}

.floating-menu button[data-icon="🗑"]::before {
  color: var(--danger);
}

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

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 48px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 5px;
  display: grid;
  width: 34px;
  height: 34px;
  transform: translateY(-50%);
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
}

.password-toggle:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.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: 8px;
  background: 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;
}

.chat-avatar-button {
  cursor: pointer;
}

.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::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: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.46);
}

.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(100vh - 72px);
  place-items: center;
  padding: 28px;
}

.startup-loader {
  display: grid;
  justify-items: center;
  gap: 10px;
  color: var(--text);
}

.startup-loader strong {
  font-size: 1.4rem;
}

.startup-loader small {
  color: var(--muted);
  font-weight: 700;
}

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

body.is-booting .login-panel,
body.is-booting .messenger-shell {
  display: none !important;
}

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;
}

body.is-authenticated.is-booting {
  display: block;
  height: auto;
  min-height: 100vh;
  overflow: auto;
}

body.is-authenticated.is-booting .login-shell {
  display: grid;
  height: auto;
  min-height: calc(100vh - 72px);
  place-items: center;
  padding: 28px;
  overflow: visible;
}

.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 {
  position: relative;
  z-index: 0;
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  width: 100%;
  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 {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.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: 8px;
  padding: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  touch-action: manipulation;
}

.chat-item:hover,
.chat-item.active {
  border-color: var(--line);
  background: var(--surface);
}

.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;
  gap: 8px;
  padding: 28px;
  text-align: center;
}

.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-x: hidden;
  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%;
  min-width: 0;
}

.message-row.own {
  justify-content: flex-end;
  padding-right: 6px;
}

.message-row.incoming {
  justify-content: flex-start;
  padding-left: 6px;
}

.message-bubble {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  width: fit-content;
  max-width: min(70%, calc(100% - 12px));
  min-width: min(52px, 100%);
  overflow: visible;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 22px rgba(32, 45, 58, 0.08);
}

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

.message-bubble > * {
  max-width: 100%;
  min-width: 0;
}

.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: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  width: 100%;
  min-width: 0;
  justify-self: end;
  font-size: 0.68rem;
  line-height: 1.2;
  white-space: nowrap;
}

.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 {
  position: relative;
  display: block;
  width: var(--message-image-width, 360px);
  aspect-ratio: var(--message-image-ratio, 4 / 3);
  max-width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: var(--surface-soft);
}

.message-image-button.is-error::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
  content: "Не удалось загрузить";
}

.message-video-wrap.is-error::after {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 12px;
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
  content: "Не удалось загрузить";
  background: var(--surface-soft);
}

.media-load-overlay,
.media-upload-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
  background: color-mix(in srgb, #000 24%, transparent);
  color: #fff;
}

.media-load-overlay {
  background:
    radial-gradient(circle, color-mix(in srgb, var(--surface) 88%, transparent) 0 34px, transparent 35px),
    color-mix(in srgb, var(--surface-soft) 88%, transparent);
  color: var(--text);
}

.media-load-overlay .loading-spinner,
.media-upload-overlay .loading-spinner {
  width: 32px;
  height: 32px;
}

.media-load-overlay .loading-spinner {
  border-color: color-mix(in srgb, var(--accent) 18%, transparent);
  border-top-color: var(--accent);
}

.media-upload-overlay .loading-spinner {
  border-color: rgba(255, 255, 255, 0.32);
  border-top-color: #fff;
}

.media-load-overlay small,
.media-upload-overlay small {
  min-width: 48px;
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
}

.media-load-overlay small {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--text);
}

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

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

.message-video-wrap {
  position: relative;
  width: var(--message-video-width, 360px);
  aspect-ratio: var(--message-video-ratio, 4 / 3);
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
  background: #000;
}

.message-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.audio-player {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 280px;
  max-width: 100%;
  min-width: 0;
  padding: 4px 0;
}

.audio-play {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #39a8f5;
  color: #fff;
  font-weight: 900;
}

.audio-range {
  min-height: 28px;
  padding: 0;
  accent-color: var(--accent);
}

.audio-duration {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.document-file {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 280px;
  max-width: 100%;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.document-icon {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-weight: 900;
}

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

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

.upload-progress {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.upload-progress::before {
  grid-column: 1;
  grid-row: 1;
  height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 20%, transparent);
  content: "";
}

.upload-progress span {
  grid-column: 1;
  grid-row: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
}

.upload-progress small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.bot-commands-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.bot-commands-bar.hidden {
  display: none;
}

.bot-command-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  background: var(--surface);
  color: var(--accent-strong);
  cursor: pointer;
  white-space: nowrap;
}

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

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

.message-form.is-recording textarea {
  display: none;
}

.recording-indicator {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface-soft);
  color: var(--text);
}

.recording-indicator strong {
  flex: 0 0 auto;
  color: var(--danger);
}

.recording-wave {
  width: min(180px, 40vw);
  height: 32px;
  min-width: 70px;
  flex: 1 1 auto;
}

.recording-indicator small {
  margin-left: auto;
  flex: 0 0 auto;
  color: var(--muted);
  font-weight: 900;
}

.recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 42%, transparent);
  animation: record-pulse 1.1s ease-in-out infinite;
}

@keyframes record-pulse {
  50% {
    box-shadow: 0 0 0 7px color-mix(in srgb, var(--danger) 0%, transparent);
    opacity: 0.62;
  }
}

.attach-button {
  height: 44px;
  font-size: 1.2rem;
}

.send-button {
  position: relative;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 900;
  touch-action: none;
}

.send-icon {
  transform: translateX(-1px);
}

.mic-icon {
  position: absolute;
  right: 5px;
  bottom: 4px;
  display: grid;
  width: 14px;
  height: 14px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent-strong) 70%, var(--accent));
  color: #fff;
  font-size: 0.58rem;
  line-height: 1;
}

.mic-settings-field {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.mic-settings-field span,
.mic-settings-field input {
  grid-column: 1 / -1;
}

.mic-settings-field input {
  padding: 0;
  accent-color: var(--accent);
}

.mic-settings-field strong {
  justify-self: end;
  color: var(--accent-strong);
  font-size: 0.95rem;
}

.mic-levels {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.mic-meter {
  position: relative;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 70%, transparent);
}

.mic-meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 80ms linear;
}

.mic-meter-peak {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0%;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--surface) 70%, transparent);
  transition: left 120ms ease;
}

.mic-level-values {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.mic-level-values strong {
  color: var(--text);
}

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

.send-button.is-recording {
  border-color: var(--danger);
  background: var(--danger);
}

.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 {
  position: relative;
  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-loader {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1;
  display: none;
  justify-items: center;
  gap: 10px;
  transform: translate(-50%, -50%);
  color: #fff;
}

.image-viewer-loader small {
  color: rgba(255, 255, 255, 0.78);
  font-weight: 800;
}

.image-viewer.is-loading .image-viewer-loader {
  display: grid;
}

.image-viewer.is-loading .image-viewer-stage img,
.image-viewer.is-error .image-viewer-stage img {
  opacity: 0;
}

.image-viewer.is-error .image-viewer-loader {
  display: grid;
}

.image-viewer.is-error .image-viewer-loader .loading-spinner {
  display: none;
}

.image-viewer.is-error .image-viewer-loader small {
  color: #fff;
  font-size: 0.9rem;
}

.image-viewer-tools {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2;
  display: flex;
  gap: 8px;
  align-items: center;
  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);
}

.image-zoom-icon {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 900;
}

#zoomRange {
  width: min(210px, 38vw);
  min-height: 30px;
  padding: 0;
  accent-color: var(--accent);
}

.profile-view {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
}

.profile-photo {
  display: grid;
  width: 160px;
  height: 160px;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 2.5rem;
  font-weight: 900;
}

.profile-photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.camera-dialog {
  width: min(720px, calc(100vw - 28px));
  max-width: none;
}

.camera-dialog.square {
  width: min(500px, calc(100vw - 28px));
}

.camera-dialog .modal-body {
  display: grid;
  justify-items: stretch;
  gap: 18px;
  width: 100%;
  max-height: calc(100dvh - 28px);
  overflow: auto;
}

.camera-select-field {
  width: min(100%, 640px);
  justify-self: center;
}

.camera-dialog h3 {
  width: min(100%, 640px);
  justify-self: center;
}

.camera-preview {
  display: block;
  width: 100%;
  justify-self: center;
  max-height: min(62dvh, 520px);
  border-radius: 8px;
  background: #000;
  object-fit: contain;
}

.camera-dialog.square .camera-preview {
  width: min(100%, calc(100dvh - 220px), calc(100vw - 72px));
  max-height: none;
  aspect-ratio: 1;
  object-fit: cover;
}

.camera-dialog.square h3,
.camera-dialog.square .modal-actions {
  width: min(100%, calc(100dvh - 220px), calc(100vw - 72px));
  justify-self: center;
}

.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;
  }

  .profile-view {
    grid-template-columns: 1fr;
  }

  .profile-photo {
    width: min(260px, 100%);
    height: min(260px, 70vw);
  }
}

@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%;
  }
}
