﻿/* Стили публичного чата в формате chat-first: минималистичная шапка и composer как в референсе. */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #f8f8f9;
  --surface: #ffffff;
  --surface-muted: #f4f4f5;
  --border: #e7e8eb;
  --text: #141414;
  --text-muted: #6f7480;
  --assistant-bg: #ffffff;
  --user-bg: #f0edff;
  --user-text: #2d2942;
  --icon: #4b5563;
  --accent: #7a61f8;
  --accent-hover: #6d54e7;
  --ring: rgba(122, 97, 248, 0.2);
}

body {
  font-family: 'Segoe UI', 'Inter', 'Arial', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.48;
  min-height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
}

.layout {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
}

/* Шапка */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
}

.header__bar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  margin: 0 10px;
}

.header__crumbs {
  display: inline-flex;
  align-items: center;
  gap: 0;
  min-width: 0;
  font-size: 23px;
}

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

/* Чат */
.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 0 10px;
}

.chat__messages {
  flex: 1;
  min-height: 0;
  overflow: visible;
  padding: 18px 0 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Сообщения */
.message {
  display: flex;
  flex-direction: column;
  max-width: min(84%, 740px);
}

.message--assistant {
  align-self: stretch;
  align-items: flex-start;
  max-width: none;
  width: 100%;
}

/* Последний ответ ассистента занимает остаток экрана — держит сообщение пользователя у верха.
   130px = шапка (56px) + типичный пузырь пользователя (~60px) + gap (14px). */
.message--assistant:last-child {
  min-height: calc(100dvh - 130px);
}

.message--user {
  align-self: flex-end;
  align-items: flex-end;
  scroll-margin-top: 68px; /* высота шапки + небольшой отступ */
}

.message__bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message--assistant .message__bubble {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0 8px 0 10px;
  color: var(--text);
}

.message--user .message__bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 8px;
}

/* Фидбек */
.message__feedback {
  margin-top: 7px;
  display: flex;
  gap: 6px;
}

.feedback-btn {
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.feedback-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
}

.feedback-btn:hover {
  background: #f0f1f3;
  border-color: #e0e3e8;
  color: #3f4650;
}

.feedback-btn--sent {
  opacity: 0.6;
  pointer-events: none;
}

/* Индикатор набора */
.chat__typing {
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 8px 0 10px;
  margin-top: 2px;
  align-self: flex-start;
  font-size: 14px;
  font-weight: 500;
  background: linear-gradient(90deg, #d1d5db 0%, var(--accent) 50%, #d1d5db 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 1s linear infinite;
}

@keyframes shimmer {
  from {
    background-position: 200% center;
  }
  to {
    background-position: 0% center;
  }
}

/* Composer */
.chat__form {
  position: sticky;
  bottom: 22px;
  z-index: 15;
  margin: auto 10px 0;
  min-height: 54px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 1px 6px rgba(17, 24, 39, 0.05);
  padding: 6px 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 6px;
}

.chat__disclaimer {
  position: sticky;
  bottom: 0;
  z-index: 14;
  margin: 0;
  min-height: 18px;
  padding: 2px 10px 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12px;
  line-height: 1.35;
  color: #838995;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(4px);
}

.chat__form:focus-within {
  border-color: #dfdafd;
  box-shadow:
    0 1px 6px rgba(17, 24, 39, 0.06),
    0 0 0 1px var(--ring);
}

.chat__input {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  resize: none;
  max-height: 180px;
  min-height: 40px;
  padding: 9px 8px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.35;
}

.chat__input::placeholder {
  color: #8e94a0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat__send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  align-self: center;
  background: color-mix(in srgb, var(--accent) 24%, #ffffff);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    background 0.15s ease,
    color 0.15s ease,
    opacity 0.15s ease;
}

.chat__send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.chat__send:hover {
  background: var(--accent-hover);
  color: #ffffff;
  transform: translateY(-1px);
}

.chat__send:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

@media (max-width: 900px) {
  .header__title {
    font-size: 15px;
  }

  .chat__messages {
    padding-bottom: 10px;
  }

  .message {
    max-width: 92%;
  }
}

/* Markdown-рендер в пузыре ассистента */
.markdown p {
  margin: 0 0 6px;
}
.markdown p:last-child {
  margin-bottom: 0;
}
.markdown li > p {
  margin: 0;
} /* marked оборачивает li в p — убираем лишний отступ */
.markdown strong {
  font-weight: 600;
}
.markdown em {
  font-style: italic;
}
.markdown h1,
.markdown h2,
.markdown h3 {
  font-weight: 600;
  margin: 10px 0 4px;
  line-height: 1.3;
}
.markdown h1:first-child,
.markdown h2:first-child,
.markdown h3:first-child {
  margin-top: 0;
}
.markdown h1 {
  font-size: 1.15em;
}
.markdown h2 {
  font-size: 1.05em;
}
.markdown h3 {
  font-size: 1em;
}
.markdown ul,
.markdown ol {
  margin: 4px 0 6px;
  padding-left: 20px;
}
.markdown li {
  margin-bottom: 3px;
}
.markdown code {
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 0.88em;
  background: #f0f1f3;
  border-radius: 4px;
  padding: 1px 5px;
}
.markdown pre {
  background: #f0f1f3;
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
}
.markdown pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
}
.markdown a {
  color: var(--accent);
  text-decoration: underline;
}

/* Cookie consent banner */
.consent {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: 0 -2px 8px rgba(17, 24, 39, 0.07);
}

.consent__text {
  flex: 1;
  min-width: 200px;
  font-size: 13px;
  color: var(--text-muted);
}

.consent__btn {
  flex-shrink: 0;
  padding: 7px 18px;
  border: none;
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.consent__btn:hover {
  background: var(--accent-hover);
}

@media (max-width: 560px) {
  .header__bar {
    height: 52px;
    padding: 0 10px;
    margin: 0 10px;
  }

  .header__title {
    font-size: 20px;
  }

  .chat__messages {
    padding: 12px 0 8px;
    gap: 12px;
  }

  .chat {
    padding: 0 10px;
  }

  .message {
    max-width: 96%;
  }

  .message__bubble {
    font-size: 14px;
    padding: 10px 11px;
  }

  .chat__form {
    margin: 0 10px;
    bottom: 18px;
    min-height: 50px;
    border-radius: 24px;
    padding: 5px 7px;
  }

  .chat__disclaimer {
    min-height: 16px;
    padding: 2px 6px 2px;
    font-size: 11px;
  }

  .chat__input {
    min-height: 36px;
    font-size: 14px;
    padding: 8px 6px;
  }

  .chat__send {
    width: 32px;
    height: 32px;
  }

  .chat__send svg {
    width: 17px;
    height: 17px;
  }
}
