/* Chat internal window layout: separate scroll for room list and messages, composer inside thread. */

.bk-chat-room-card {
  display: block;
  min-height: 0;
  overflow: hidden;
}

.bk-chat-layout {
  display: grid;
  grid-template-columns: minmax(176px, 220px) minmax(0, 1fr);
  gap: 12px;
  height: min(70vh, 760px);
  min-height: 520px;
  max-height: 760px;
  overflow: hidden;
  align-items: stretch;
}

.bk-chat-layout > .bk-list {
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.bk-chat-layout > .bk-list::-webkit-scrollbar,
.bk-chat-thread::-webkit-scrollbar {
  width: 8px;
}

.bk-chat-layout > .bk-list::-webkit-scrollbar-thumb,
.bk-chat-thread::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(148, 163, 184, .24);
}

.bk-chat-thread {
  display: block;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding-bottom: 0;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.bk-chat-composer-inside-thread {
  position: sticky;
  bottom: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 8px;
  margin: 10px -8px -12px;
  padding: 8px 10px 10px;
  border: 0;
  border-top: 1px solid rgba(148, 163, 184, .12);
  border-radius: 0 0 16px 16px;
  background: rgba(8, 14, 24, .94);
  backdrop-filter: blur(14px);
  box-shadow: none;
}

.bk-chat-composer-inside-thread .bk-label {
  display: none;
}

.bk-chat-composer-inside-thread .bk-field {
  position: relative;
  grid-column: 2;
  align-self: center;
  min-width: 0;
  margin: 0;
}

.bk-chat-composer-inside-thread .bk-textarea {
  box-sizing: border-box;
  min-height: 40px;
  height: auto;
  max-height: min(10lh, 220px);
  padding: 9px 38px 9px 15px;
  border-radius: 20px;
  border-color: rgba(148, 163, 184, .17);
  background: rgba(31, 36, 46, .86);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
  color: var(--bk-text);
  font-size: .94rem;
  line-height: 22px;
  resize: none;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  field-sizing: content;
}

.bk-chat-composer-inside-thread .bk-textarea:focus,
.bk-chat-composer-inside-thread .bk-textarea:focus-visible {
  border-color: rgba(96, 165, 250, .42);
  outline: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04), 0 0 0 1px rgba(96, 165, 250, .13);
}

.bk-chat-composer-inside-thread .bk-field::after {
  content: '';
  position: absolute;
  right: 13px;
  bottom: 11px;
  z-index: 1;
  width: 18px;
  height: 18px;
  background-color: rgba(226, 232, 240, .62);
  pointer-events: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l4 2'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l4 2'/%3E%3C/svg%3E") center / contain no-repeat;
}

.bk-chat-composer-inside-thread .bk-blocked-link {
  display: none;
}

.bk-chat-composer-inside-thread .bk-action-row {
  display: contents;
  margin: 0;
}

.bk-chat-composer-inside-thread .bk-button {
  position: relative;
  display: block;
  align-self: center;
  justify-self: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  border-color: rgba(148, 163, 184, .18);
  background: rgba(31, 36, 46, .82);
  box-shadow: none;
  color: rgba(226, 232, 240, .88);
  font-size: 0;
  line-height: 0;
}

.bk-chat-composer-inside-thread .bk-button:hover {
  border-color: rgba(96, 165, 250, .32);
  background: rgba(37, 43, 56, .92);
}

.bk-chat-composer-inside-thread .bk-button::before {
  content: '';
  position: absolute;
  inset: 0;
  display: block;
  width: 18px;
  height: 18px;
  margin: auto;
  background-color: currentColor;
  opacity: .94;
  transform: none;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  -webkit-mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  mask-size: contain;
}

.bk-chat-composer-inside-thread .bk-button-primary {
  grid-column: 3;
  background: rgba(31, 36, 46, .82);
}

.bk-chat-composer-inside-thread .bk-button-primary::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.15' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 2 11 13'/%3E%3Cpath d='M22 2 15 22 11 13 2 9 22 2z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.15' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 2 11 13'/%3E%3Cpath d='M22 2 15 22 11 13 2 9 22 2z'/%3E%3C/svg%3E");
}

.bk-chat-composer-inside-thread .bk-button-secondary {
  grid-column: 1;
  grid-row: 1;
}

.bk-chat-composer-inside-thread .bk-button-secondary::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.15' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.44 11.05 12.25 20.24a6 6 0 1 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.2a2 2 0 0 1-2.82-2.83l8.48-8.48'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.15' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.44 11.05 12.25 20.24a6 6 0 1 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.2a2 2 0 0 1-2.82-2.83l8.48-8.48'/%3E%3C/svg%3E");
}

.bk-chat-reply-context {
  grid-column: 2 / 3;
  width: 100%;
  max-height: 58px;
  min-height: 44px;
  margin: 0 0 3px;
  padding: 7px 34px 7px 10px;
  border-radius: 12px;
  border-left: 2px solid var(--bk-primary);
  background: rgba(31, 36, 46, .72);
  overflow: hidden;
}

.bk-chat-reply-context span {
  display: none;
}

.bk-chat-reply-context strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--bk-primary);
  font-size: .72rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bk-chat-reply-context strong::before {
  content: 'Ответ ';
  color: var(--bk-muted);
}

.bk-chat-reply-context p {
  display: -webkit-box;
  margin: 2px 0 0;
  color: var(--bk-muted);
  font-size: .72rem;
  line-height: 1.2;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.bk-chat-reply-context button {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.bk-chat-thread > .bk-chat-message-card:last-of-type {
  margin-bottom: 8px;
}

@media (max-width: 900px) {
  .bk-chat-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 92px minmax(0, 1fr);
    height: min(74vh, 780px);
    min-height: 560px;
    max-height: 780px;
  }

  .bk-chat-layout > .bk-list {
    display: flex;
    gap: 8px;
    height: 92px;
    min-height: 92px;
    max-height: 92px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
  }

  .bk-chat-layout > .bk-list .bk-chat-nav-row {
    flex: 0 0 220px;
  }

  .bk-chat-thread {
    height: 100%;
    min-height: 0;
    max-height: 100%;
  }
}

@media (max-width: 767px) {
  .bk-chat-layout {
    grid-template-rows: 84px minmax(0, 1fr);
    height: min(76vh, 760px);
    min-height: 540px;
    max-height: 760px;
  }

  .bk-chat-layout > .bk-list {
    height: 84px;
    min-height: 84px;
    max-height: 84px;
  }

  .bk-chat-layout > .bk-list .bk-chat-nav-row {
    flex-basis: 196px;
  }

  .bk-chat-composer-inside-thread {
    gap: 7px;
    margin: 10px -4px -7px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    border-top: 0;
    border-radius: 0;
    background: linear-gradient(180deg, rgba(5, 9, 16, 0), rgba(5, 9, 16, .72) 42%, rgba(5, 9, 16, .86));
    backdrop-filter: blur(12px);
  }
}

/* Real chat message bubbles: own messages right-aligned and highlighted
   (VK/Telegram style), others left. Bubble hugs its content. */
.bk-chat-thread .bk-real-msg {
  position: relative;
  width: fit-content;
  max-width: 82%;
  margin: 10px auto 0 0;
  padding: 6px 11px;
}
/* Tight, chat-sized spacing (the base .bk-social-card is feed-sized). */
.bk-chat-thread .bk-real-msg .bk-card-header {
  margin: 0 0 1px;
}
.bk-chat-thread .bk-real-msg .bk-card-body {
  margin: 0;
}
/* Consecutive messages from the same author sit closer together. */
.bk-chat-thread .bk-real-msg.is-grouped {
  margin-top: 3px;
}
.bk-chat-thread .bk-real-msg.is-own {
  margin-left: auto;
  margin-right: 0;
  background: var(--bk-control-bg-strong);
  border-color: var(--bk-border-strong);
}
.bk-chat-thread .bk-real-msg.is-own .bk-card-title {
  color: var(--bk-primary-strong);
}
/* Own messages: pin name + time to the right edge of the bubble. */
.bk-chat-thread .bk-real-msg.is-own .bk-list-row-main {
  text-align: right;
}
/* These messages have no avatar, so drop the avatar-alignment left indent:
   text starts at the bubble edge and fills its width. */
.bk-chat-thread .bk-real-msg .bk-card-header,
.bk-chat-thread .bk-real-msg .bk-card-body {
  padding-left: 0;
}
.bk-chat-thread .bk-real-msg .bk-card-body {
  text-align: left;
}
/* Actions live in a popup menu (⋮ / long-press), so nothing clutters the
   bubble. The ⋮ trigger sits opposite the header text and shows on hover. */
.bk-real-msg-menu {
  position: absolute;
  top: 2px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--bk-muted);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0;
  transition: opacity .14s ease, background .14s ease;
}
.bk-real-msg:not(.is-own) .bk-real-msg-menu { inset-inline-end: 2px; }
.bk-real-msg.is-own .bk-real-msg-menu { inset-inline-start: 2px; }
.bk-real-msg:hover .bk-real-msg-menu,
.bk-real-msg:focus-within .bk-real-msg-menu { opacity: .85; }
.bk-real-msg-menu:hover,
.bk-real-msg-menu:focus-visible { opacity: 1; color: var(--bk-text); background: var(--bk-surface-soft); }

/* Floating action menu. */
.bk-real-menu {
  position: fixed;
  z-index: 60;
  min-width: 190px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  border: 1px solid var(--bk-border-strong);
  border-radius: 14px;
  background: var(--bk-surface-raised);
  box-shadow: var(--bk-shadow);
  backdrop-filter: blur(18px);
}
.bk-real-menu[hidden] { display: none; }
.bk-real-menu button {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: var(--bk-space-2);
  padding: 0 var(--bk-space-3);
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--bk-text);
  cursor: pointer;
  font: inherit;
  font-weight: 640;
  text-align: left;
}
.bk-real-menu button:hover,
.bk-real-menu button:focus-visible { background: var(--bk-surface-soft); outline: none; }
.bk-real-menu button.is-danger { color: var(--bk-danger); }
/* The composer is a sticky bar (~83px) overlaying the bottom of the thread.
   Reserve space so the last real message is never hidden behind it. Scoped via
   :has to threads showing real messages, so the mock chat is untouched. */
.bk-chat-thread:has(.bk-real-msg) {
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

/* Others' messages get a neutral bubble (own stay highlighted). */
.bk-chat-thread .bk-real-msg:not(.is-own) {
  background: var(--bk-panel-2);
  border-color: var(--bk-border);
}

/* Initials avatars (no photos in the schema) — a fixed palette picked by hash. */
.bk-real-ava {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  flex: 0 0 auto;
}
.bk-real-ava-lg { width: 40px; height: 40px; font-size: .9rem; }
.bk-ava-0 { background: #6366f1; }
.bk-ava-1 { background: #0ea5e9; }
.bk-ava-2 { background: #10b981; }
.bk-ava-3 { background: #f59e0b; }
.bk-ava-4 { background: #ec4899; }
.bk-ava-5 { background: #8b5cf6; }
.bk-ava-6 { background: #ef4444; }
.bk-ava-7 { background: #14b8a6; }

/* Group chats: reserve an avatar column for others so bubbles align; the avatar
   itself shows only on the first message of a run. */
.bk-chat-thread .bk-real-msg.has-avatar { margin-left: 42px; }
.bk-chat-thread .bk-real-msg .bk-real-ava {
  position: absolute;
  left: -38px;
  bottom: 4px;
}

/* Pinned marker. */
.bk-real-pin { margin-left: 6px; font-size: .82rem; vertical-align: middle; }
.bk-chat-thread .bk-real-msg.is-pinned { box-shadow: inset 2px 0 0 var(--bk-gold); }

/* Chat header: who/what this room is. */
.bk-real-chat-header {
  display: flex;
  align-items: center;
  gap: var(--bk-space-3);
  padding: var(--bk-space-2) var(--bk-space-3);
  margin-bottom: var(--bk-space-3);
  border: 1px solid var(--bk-border);
  border-radius: var(--bk-radius-control);
  background: var(--bk-card-bg-soft);
}
.bk-real-chat-header-title { font-weight: 800; line-height: 1.2; }

/* Reply reference inside a bubble. */
.bk-chat-thread .bk-real-reply {
  margin: 0 0 4px;
  padding: 3px 8px;
  border-left: 2px solid var(--bk-primary);
  border-radius: 6px;
  background: var(--bk-surface-soft);
  color: var(--bk-muted);
  font-size: .8rem;
  line-height: 1.3;
  overflow: hidden;
}
.bk-real-reply-author { display: block; color: var(--bk-primary-strong); font-weight: 700; font-size: .74rem; }
.bk-real-edited { color: var(--bk-muted-2); font-size: .72rem; }

/* Composer context banner (reply / editing). */
.bk-real-ctx {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--bk-space-2);
  margin: 0 0 6px;
  padding: 6px 8px 6px 10px;
  border-left: 2px solid var(--bk-primary);
  border-radius: 10px;
  background: var(--bk-surface-soft);
}
.bk-real-ctx-main { flex: 1; min-width: 0; color: var(--bk-muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bk-real-ctx-label { display: block; color: var(--bk-primary-strong); font-weight: 700; font-size: .72rem; }
.bk-real-ctx-clear { flex: 0 0 auto; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--bk-muted); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.bk-real-ctx-clear:hover, .bk-real-ctx-clear:focus-visible { color: var(--bk-text); background: var(--bk-surface-soft); outline: none; }

/* Pinned-message bar under the header. */
.bk-real-pinned-bar {
  display: flex;
  align-items: center;
  gap: var(--bk-space-2);
  width: 100%;
  margin: -4px 0 var(--bk-space-3);
  padding: 7px var(--bk-space-3);
  border: 1px solid var(--bk-border);
  border-left: 3px solid var(--bk-gold);
  border-radius: var(--bk-radius-control);
  background: var(--bk-card-bg-soft);
  color: var(--bk-text);
  cursor: pointer;
  text-align: left;
}
.bk-real-pinned-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; color: var(--bk-muted); }
.bk-real-pinned-bar:hover { border-color: var(--bk-border-strong); }

/* Flash a message when jumped to from the pinned bar. */
.bk-chat-thread .bk-real-msg.is-flash { animation: bk-real-flash 1.2s ease; }
@keyframes bk-real-flash {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: 0 0 0 2px var(--bk-primary-strong); }
}
