:root {
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17212b;
  background: #d9e7f0;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.svg-icon {
  display: block;
  flex: 0 0 auto;
}

.app-shell {
  --accent: #229ed9;
  --app-bg: #d7e5ee;
  --panel: #ffffff;
  --panel-strong: #f5f8fb;
  --sidebar: #ffffff;
  --line: #dbe4ea;
  --text: #17212b;
  --muted: #6b7b88;
  --soft: #eef5fa;
  --hover: #eef6fc;
  --bubble-theirs: #ffffff;
  --bubble-mine: #effdde;
  --bubble-mine-line: #d5edc3;
  --composer: rgba(245, 248, 251, 0.92);
  --shadow: 0 10px 30px rgba(31, 60, 84, 0.11);
  display: grid;
  grid-template-columns: 365px minmax(0, 1fr);
  height: 100dvh;
  min-height: 520px;
  color: var(--text);
  background: var(--app-bg);
}

.app-shell[data-theme="dark"] {
  --app-bg: #0f1d27;
  --panel: #182733;
  --panel-strong: #14222d;
  --sidebar: #111f2a;
  --line: #263844;
  --text: #eef5f9;
  --muted: #9dafbd;
  --soft: #203340;
  --hover: #203748;
  --bubble-theirs: #1f303c;
  --bubble-mine: #2c4f3f;
  --bubble-mine-line: #34624c;
  --composer: rgba(20, 34, 45, 0.94);
  --shadow: 0 10px 32px rgba(0, 0, 0, 0.3);
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  z-index: 2;
}

.sidebar__top {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 64px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.sidebar__top h1 {
  flex: 1;
  margin: 0;
  font-size: 20px;
  font-weight: 720;
}

.icon-button {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  transition:
    color 140ms ease,
    background-color 140ms ease,
    transform 140ms ease;
}

.icon-button:hover,
.icon-button--active {
  color: var(--accent);
  background: var(--hover);
}

.icon-button:active {
  transform: scale(0.96);
}

.icon-button--ghost {
  background: var(--soft);
}

.icon-button--inline {
  width: 28px;
  height: 28px;
}

.icon-button--mini {
  width: 28px;
  height: 28px;
  color: var(--text);
}

.search-field {
  min-height: 42px;
  margin: 12px 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  background: var(--panel-strong);
  border: 1px solid transparent;
  border-radius: 22px;
  padding: 0 13px;
}

.search-field:focus-within {
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  background: var(--panel);
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.search-field--header {
  width: min(340px, 42vw);
  margin: 0 8px 0 auto;
  min-height: 40px;
}

.chat-list {
  flex: 1;
  min-height: 0;
  padding: 4px 8px 12px;
  overflow: auto;
}

.chat-row {
  position: relative;
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  min-height: 72px;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.chat-row:hover {
  background: var(--hover);
}

.chat-row--active {
  color: #ffffff;
  background: var(--accent);
}

.chat-row--active:hover {
  background: var(--accent);
}

.avatar {
  position: relative;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  display: block;
  border-radius: 50%;
  padding: 2px;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.32);
}

.avatar--small {
  width: 44px;
  height: 44px;
}

.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
  object-fit: cover;
}

.avatar__status {
  position: absolute;
  right: 1px;
  bottom: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: #31c96b;
}

.chat-row__main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.chat-row__title,
.chat-row__preview {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-row__title strong,
.chat-row__preview span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-row__title strong {
  flex: 1;
  font-size: 15px;
  font-weight: 680;
}

.chat-row__title span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.chat-row__preview {
  color: var(--muted);
  font-size: 14px;
}

.chat-row--active .chat-row__title span,
.chat-row--active .chat-row__preview {
  color: rgba(255, 255, 255, 0.78);
}

.badge {
  min-width: 23px;
  height: 23px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  padding: 0 7px;
  color: #ffffff;
  background: #37b7e8;
  font-size: 12px;
  font-weight: 720;
}

.chat-row--active .badge {
  color: var(--accent);
  background: #ffffff;
}

.chat-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0.24)),
    url("./wallpaper.png") center / cover,
    var(--app-bg);
}

.app-shell[data-theme="dark"] .chat-panel {
  background:
    linear-gradient(rgba(15, 29, 39, 0.62), rgba(15, 29, 39, 0.62)),
    url("./wallpaper.png") center / cover,
    var(--app-bg);
}

.chat-header {
  height: 64px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.chat-header__back {
  display: none;
}

.chat-header__identity {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.chat-header__identity strong {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 16px;
  font-weight: 720;
}

.chat-header__identity span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 13px;
}

.chat-header__actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.pinned-bar {
  min-height: 42px;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 91%, var(--accent));
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.pinned-bar span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.message-date {
  align-self: center;
  margin-top: 14px;
  padding: 5px 12px;
  border-radius: 999px;
  color: #ffffff;
  background: rgba(87, 111, 126, 0.52);
  font-size: 12px;
  font-weight: 640;
  z-index: 1;
}

.messages {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 14px 24px 22px;
  overflow: auto;
}

.message {
  position: relative;
  max-width: min(680px, 78%);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.message--mine {
  align-self: flex-end;
  align-items: flex-end;
}

.message--theirs {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  position: relative;
  min-width: 122px;
  padding: 8px 10px 19px;
  border-radius: 8px 8px 8px 3px;
  color: var(--text);
  background: var(--bubble-theirs);
  box-shadow: var(--shadow);
}

.message--mine .bubble {
  border-radius: 8px 8px 3px 8px;
  background: var(--bubble-mine);
  box-shadow:
    0 1px 0 var(--bubble-mine-line),
    var(--shadow);
}

.message-author {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 720;
}

.bubble p {
  max-width: 62ch;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.42;
  font-size: 15px;
}

.reply-ref {
  margin: 0 0 7px;
  padding: 5px 8px;
  display: grid;
  gap: 2px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: rgba(34, 158, 217, 0.1);
  font-size: 13px;
}

.reply-ref strong,
.reply-ref span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.message-meta {
  position: absolute;
  right: 8px;
  bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.message-meta svg {
  color: #8ea0ac;
}

.message-meta svg.read {
  color: #2ca5e0;
}

.attachment {
  margin-bottom: 8px;
}

.attachment--image {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: var(--soft);
}

.attachment--image img {
  width: min(420px, 64vw);
  max-height: 300px;
  aspect-ratio: 16 / 10;
  display: block;
  object-fit: cover;
}

.attachment--image figcaption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 7px 9px;
  overflow: hidden;
  color: #ffffff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.62));
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.attachment--file {
  width: min(360px, 58vw);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line));
  border-radius: 8px;
  background: rgba(34, 158, 217, 0.08);
}

.file-icon,
.voice-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--accent);
}

.file-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.file-copy strong,
.file-copy span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.file-copy strong {
  font-size: 14px;
}

.file-copy span {
  color: var(--muted);
  font-size: 12px;
}

.attachment--voice {
  width: min(330px, 56vw);
  min-height: 54px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.voice-wave {
  min-width: 0;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.voice-wave span {
  width: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 72%, var(--muted));
}

.voice-duration {
  color: var(--muted);
  font-size: 12px;
}

.message-tools {
  position: absolute;
  left: calc(100% + 8px);
  top: 3px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.message--mine .message-tools {
  right: calc(100% + 8px);
  left: auto;
}

.bubble:hover .message-tools,
.message-tools:focus-within {
  opacity: 1;
  pointer-events: auto;
}

.reaction-pick {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 14px;
}

.reaction-pick:hover {
  background: var(--soft);
}

.reaction-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 4px;
}

.reaction-chip {
  height: 25px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 5px 14px rgba(31, 60, 84, 0.08);
  font-size: 12px;
}

.reaction-chip--active {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}

.empty-state {
  align-self: center;
  margin: auto 0;
  padding: 10px 14px;
  border-radius: 999px;
  color: #ffffff;
  background: rgba(87, 111, 126, 0.52);
  font-size: 14px;
}

.composer {
  flex: 0 0 auto;
  padding: 10px 18px 14px;
  background: var(--composer);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.composer--dragging {
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
}

.composer__row {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer__input {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 23px;
  color: var(--muted);
  background: var(--panel);
}

.composer__input:focus-within {
  border-color: color-mix(in srgb, var(--accent) 44%, var(--line));
}

.composer__input textarea {
  width: 100%;
  min-height: 24px;
  max-height: 116px;
  border: 0;
  outline: 0;
  resize: none;
  overflow: auto;
  color: var(--text);
  background: transparent;
  line-height: 1.45;
}

.send-button {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 12px 24px rgba(34, 158, 217, 0.28);
}

.composer__reply,
.pending-list {
  max-width: 980px;
  margin: 0 auto 8px;
}

.composer__reply {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

.composer__reply span {
  min-width: 0;
  display: grid;
  gap: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.composer__reply strong {
  color: var(--text);
}

.pending-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.pending-item {
  max-width: min(270px, 86vw);
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
}

.pending-item > span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
}

@media (max-width: 1020px) {
  .app-shell {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .chat-header__actions .icon-button[title="Видео"] {
    display: none;
  }
}

@media (max-width: 780px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-open .chat-panel {
    pointer-events: none;
  }

  .chat-header {
    padding: 0 10px;
    gap: 8px;
  }

  .chat-header__back {
    display: inline-grid;
  }

  .chat-header__actions {
    gap: 0;
  }

  .chat-header__actions .icon-button[title="Звонок"],
  .chat-header__actions .icon-button[title="Видео"],
  .chat-header__actions .icon-button[title="Закреп"] {
    display: none;
  }

  .search-field--header {
    position: absolute;
    left: 10px;
    right: 10px;
    width: auto;
    z-index: 3;
  }

  .pinned-bar {
    padding: 8px 12px;
  }

  .messages {
    padding: 12px 10px 18px;
  }

  .message {
    max-width: 88%;
  }

  .message-tools {
    display: none;
  }

  .attachment--image img {
    width: min(340px, 72vw);
  }

  .attachment--file,
  .attachment--voice {
    width: min(330px, 74vw);
  }

  .composer {
    padding: 9px 8px 10px;
  }

  .composer__row {
    gap: 5px;
  }

  .composer__heart {
    display: none;
  }

  .composer__input {
    padding: 10px 11px;
  }
}
