:root {
  --bubble-radius: 14px;
}

.chat-body {
  background: #f4f6fb;
  overflow: hidden;            /* фиксируем страницу — скроллим только .chat-messages */
}
html, body { height: 100%; }
.chat-main {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100dvh - 72px);   /* dvh учитывает мобильный address bar/клавиатуру */
  min-height: 0;
}
@supports not (height: 100dvh) {
  .chat-main { height: calc(100vh - 72px); }
}
@media (max-width: 900px) {
  .chat-main { grid-template-columns: 1fr; }
  .chat-side { display: none; }
}

.chat-side {
  background: #fff;
  border-right: 1px solid #e5e7eb;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-side__new { align-self: flex-start; }
.chat-side__hint { font-size: 12px; color: #6b7280; line-height: 1.5; }

.chat-pane {
  display: flex;
  flex-direction: column;
  background: #fff;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-anchor: none;       /* отключаем браузерный scroll-anchor, мы сами держим bottom */
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--bubble-radius);
  font-size: 15px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble--user {
  align-self: flex-end;
  background: #1A3D7C;
  color: #fff;
  white-space: pre-wrap;
}
.bubble--assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: #111827;
  border: 1px solid #e5e7eb;
  white-space: normal;
}
.bubble--assistant p { margin: 0 0 6px; }
.bubble--assistant p:last-child { margin-bottom: 0; }
.bubble--assistant ul, .bubble--assistant ol { padding-left: 1.4em; margin: 4px 0; }
.bubble--assistant table { border-collapse: collapse; margin: 6px 0; font-size: 14px; }
.bubble--assistant th, .bubble--assistant td {
  border: 1px solid #d1d5db; padding: 4px 8px;
}
.bubble--assistant code {
  background: #fff; border: 1px solid #e5e7eb; padding: 0 4px;
  border-radius: 4px; font-size: 13px;
}
.bubble__source {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 6px;
}
.bubble__attachments {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.bubble__attachment {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #d1d5db; border-radius: 10px;
  padding: 4px 10px; font-size: 13px; text-decoration: none; color: #1A3D7C;
}
.bubble__attachment:hover { background: #eff6ff; }
.bubble__feedback {
  display: flex; gap: 6px; margin-top: 8px;
}
.bubble__feedback button {
  background: transparent; border: 1px solid #d1d5db; border-radius: 10px;
  padding: 2px 8px; font-size: 13px; cursor: pointer; color: #6b7280;
}
.bubble__feedback button:hover { background: #f9fafb; }
.bubble__feedback button.is-good { color: #16a34a; border-color: #86efac; background: #f0fdf4; }
.bubble__feedback button.is-bad  { color: #dc2626; border-color: #fca5a5; background: #fef2f2; }
.bubble__feedback button.is-meh  { color: #d97706; border-color: #fcd34d; background: #fffbeb; }

.chat-typing { padding: 6px 20px; color: #6b7280; font-size: 13px; font-style: italic; }

.chat-divider {
  text-align: center; color: #9ca3af; font-size: 13px; margin: 8px 0;
}

.chat-composer {
  flex: 0 0 auto;              /* не сжимается, не растягивается */
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  position: sticky;
  bottom: 0;
  z-index: 5;
}
.chat-attach-preview { flex: 0 0 auto; }
.chat-composer textarea {
  resize: none;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 160px;
  overflow-y: auto;
}
.chat-composer textarea:focus { outline: 2px solid #93c5fd; outline-offset: -1px; }
.chat-composer__attach {
  background: transparent; border: none; font-size: 20px; cursor: pointer;
  color: #6b7280; padding: 6px;
}
.chat-composer__toggle {
  display: flex; gap: 4px; align-items: center;
  font-size: 12px; color: #6b7280;
  white-space: nowrap; cursor: pointer;
}
.chat-composer__send { white-space: nowrap; }

.chat-attach-preview {
  padding: 6px 16px 12px;
  display: flex; gap: 8px; flex-wrap: wrap;
  background: #fff; border-top: 1px solid #f3f4f6;
}
.chat-attach-preview__item {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f3f4f6; border-radius: 10px; padding: 4px 10px;
  font-size: 13px;
}
.chat-attach-preview__remove {
  background: transparent; border: none; cursor: pointer; color: #6b7280;
  padding: 0 0 0 4px; font-size: 14px;
}

@media (max-width: 720px) {
  .bubble { max-width: 88%; font-size: 14px; }
  .chat-composer {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
  }
  .chat-composer textarea { grid-column: 1 / 4; grid-row: 1; }
  .chat-composer__attach { grid-column: 1; grid-row: 2; }
  .chat-composer__toggle { grid-column: 2; grid-row: 2; }
  .chat-composer__send { grid-column: 3; grid-row: 2; }
}
