/* Цвета и формы — по мотивам интерфейса MAX. */
:root {
  --bg: #e9edf1;
  --header: rgba(233, 237, 241, 0.85);
  /* Фон чата MAX: --chat-background-background-step-* и --chat-background-pattern-gradient-step-*.
     Для светлой темы значения подобраны на глаз, для тёмной — сняты с web.max.ru (тема space). */
  --chat-bg-1: #e9edf1;
  --chat-bg-2: #e9edf1;
  --chat-pattern-1: rgba(80, 91, 199, 0.16);
  --chat-pattern-2: rgba(80, 91, 199, 0.16);
  --bubble: #ffffff;
  --text: #0f1114;
  --muted: #7c838f;
  --line: #c9cfd8;
  --accent: #2d7cf6;
  --highlight: rgba(45, 124, 246, 0.14);
  --chip: #eef1f5;
  --radius: 18px;
  /* «Свой» пузырь MAX (тема space, [data-bubbles-variant=outgoing]):
     --bubbles-background-bubble-gradient-step-1/2/3, --bubbles-text-body/author/time. */
  --own-step-1: #8849b4;
  --own-step-2: #735acd;
  --own-step-3: #5d6ae5;
  --own-text: #ffffff;
  --own-author: #ffffff;
  --own-time: #ffffffa3;
  --indent: 12px;

  --tone-0: #d14d82;
  --tone-1: #2f7be0;
  --tone-2: #d9822b;
  --tone-3: #7a5ae0;
  --tone-4: #23a17d;
  --tone-5: #c49a12;
  --tone-6: #1f9ec4;
  --tone-7: #d6524f;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --header: rgba(20, 20, 20, 0.85);
    --chat-bg-1: rgb(20, 20, 20);
    --chat-bg-2: rgb(20, 20, 20);
    --chat-pattern-1: rgba(80, 91, 199, 0.3);
    --chat-pattern-2: rgba(80, 91, 199, 0.3);
    --bubble: #26272e;
    --text: #f2f3f5;
    --muted: #8e93a0;
    --line: #34363f;
    --accent: #5b9cf6;
    --highlight: rgba(91, 156, 246, 0.2);
    --chip: #33353e;

    --tone-0: #f2709c;
    --tone-1: #5b9cf6;
    --tone-2: #f5a35c;
    --tone-3: #a98bf7;
    --tone-4: #4fc3a1;
    --tone-5: #e5c158;
    --tone-6: #5fc6e8;
    --tone-7: #f27a77;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.38 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* Фон как в чате MAX: основа (layer-base) и поверх неё узор pattern_space.svg,
   вырезанный маской из градиента (layer-pattern). Закреплён и не прокручивается. */
body::before,
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

body::before {
  background: linear-gradient(28deg, var(--chat-bg-1) 8.03%, var(--chat-bg-2) 91.51%);
}

body::after {
  background: linear-gradient(28deg, var(--chat-pattern-1) 8.03%, var(--chat-pattern-2) 91.51%);
  -webkit-mask-image: url('pattern-space.svg');
  mask-image: url('pattern-space.svg');
  -webkit-mask-position: 50% center;
  mask-position: 50% center;
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
}

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 16px;
  background: var(--header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.top[hidden] {
  display: none;
}

.top__title {
  font-weight: 600;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top__meta {
  color: var(--muted);
  font-size: 13px;
}

.thread {
  padding: 12px 12px 32px;
}

.notice {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bubble);
  color: var(--muted);
  font-size: 14px;
}

.notice--error {
  color: var(--tone-7);
}

/* Дерево: ответы сдвинуты вправо, линия слева показывает ветку. */
.node + .node {
  margin-top: 10px;
}

.replies {
  margin: 10px 0 0 var(--indent);
  padding-left: 8px;
  border-left: 2px solid var(--line);
}

.replies--flat {
  margin-left: 0;
  padding-left: 0;
  border-left: 0;
}

.replies[hidden] {
  display: none;
}

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

.msg__column {
  min-width: 0;
  flex: 1;
}

.avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  background: var(--line);
}

div.avatar.tone-0 { background: var(--tone-0); }
div.avatar.tone-1 { background: var(--tone-1); }
div.avatar.tone-2 { background: var(--tone-2); }
div.avatar.tone-3 { background: var(--tone-3); }
div.avatar.tone-4 { background: var(--tone-4); }
div.avatar.tone-5 { background: var(--tone-5); }
div.avatar.tone-6 { background: var(--tone-6); }
div.avatar.tone-7 { background: var(--tone-7); }

.bubble {
  display: inline-block;
  max-width: 100%;
  min-width: 120px;
  padding: 7px 12px 6px;
  border-radius: var(--radius);
  border-top-left-radius: 6px;
  background: var(--bubble);
}

/* Пересланное сообщение — как своё сообщение в MAX. */
.bubble--link {
  cursor: pointer;
  transition: filter 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.bubble--link:active {
  filter: brightness(0.9);
}

.msg--highlight .bubble {
  background: linear-gradient(239deg, var(--own-step-1) 0%, var(--own-step-2) 50%, var(--own-step-3) 100%);
  color: var(--own-text);
}

.msg--highlight .bubble__author {
  color: var(--own-author) !important;
}

.msg--highlight .bubble__meta {
  color: var(--own-time);
}

.msg--highlight .chip {
  background: #ffffff1f;
  color: var(--own-text);
}

.bubble__author {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bubble__author.tone-0 { color: var(--tone-0); }
.bubble__author.tone-1 { color: var(--tone-1); }
.bubble__author.tone-2 { color: var(--tone-2); }
.bubble__author.tone-3 { color: var(--tone-3); }
.bubble__author.tone-4 { color: var(--tone-4); }
.bubble__author.tone-5 { color: var(--tone-5); }
.bubble__author.tone-6 { color: var(--tone-6); }
.bubble__author.tone-7 { color: var(--tone-7); }

.bubble__text {
  margin-top: 2px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg--deleted .bubble__text {
  color: var(--muted);
  font-style: italic;
}

.bubble__meta {
  margin-top: 2px;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
}

.bubble__time {
  color: inherit;
  text-decoration: none;
}

a.bubble__time:hover,
a.bubble__time:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}

.msg__actions {
  display: flex;
  gap: 14px;
  margin: 4px 0 0 4px;
  font-size: 13px;
}

.link-btn {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

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

/* Фото — квадратные превью, по нажатию открываются целиком. */
.attachments img {
  display: block;
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 12px;
  cursor: zoom-in;
  background: var(--line);
}

.attachments--single img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 220px;
}

.attachments .sticker {
  width: auto;
  height: auto;
  max-height: 110px;
  object-fit: contain;
  cursor: default;
  background: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--chip);
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.video {
  position: relative;
  display: block;
}

.video::after {
  content: '▶';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 28px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.88);
}

.viewer[hidden] {
  display: none;
}

.viewer img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}
