/* ============================================================================
   chat.css — рабочий экран чата (сайдбар + лента + композер + выбор модели).
   Дополняет app.css: токены, .btn, .badge, .pill, .model-row, .balance-widget,
   .trust-line, .scroll-area берём оттуда и не переопределяем.

   Раскладка: страница сама не скроллится, прокручивается только лента.
   Иначе на мобиле композер уезжает под адресную строку.
   ========================================================================== */

/* Атрибут hidden обязан побеждать: у кнопок прописан display:inline-flex,
   а он сильнее браузерного display:none. */

/* --------------------------------------------------------------- каркас */

body.chat-page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.chat-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
}

/* ------------------------------------------------------------- сайдбар */

.chat-side {
  flex: none;
  width: 260px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-2);
  border-right: 1px solid #EAE9E6;
}

/* макет: обёртка 10px 8px 6px + строка 6px 8px внутри → суммарно 16/16/12 */
.chat-side__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 12px;
}
.chat-side__brand .logo { flex: 1 1 auto; min-width: 0; line-height: 1.2; }
.side-hide { display: none; }

.chat-side__menu {
  padding: 2px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* строка поиска в стиле пункта меню: рамки нет, пока не навели */
.side-search {
  position: relative;
  display: flex;
  align-items: center;
}
.side-search__icon {
  position: absolute;
  left: 8px;
  display: inline-flex;
  color: #91918E;
  pointer-events: none;
}
.side-search__input {
  width: 100%;
  height: 29px;          /* макет: строка меню = 6px паддинга + 17px текста */
  padding: 0 10px 0 33px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.side-search__input::placeholder { color: var(--text-2); }
.side-search__input:hover { background: rgba(55, 53, 47, .05); }
.side-search__input:focus {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.side-search__input::-webkit-search-cancel-button { -webkit-appearance: none; }

.side-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 14px;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  transition: background-color .14s var(--ease);
}
.side-item:hover { background: rgba(55, 53, 47, .05); }
.side-item--accent { color: var(--accent); font-weight: 500; }
.side-item--accent:hover { background: rgba(35, 131, 226, .1); }

.chat-side__list {
  flex: 1 1 auto;
  min-height: 0;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-group {
  padding: 8px 8px 4px;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 600;
  color: var(--faint);
}

.chat-item {
  position: relative;
  display: flex;
  /* в макете кнопки стоят в одной строке с заголовком, а не по центру блока */
  align-items: flex-start;
  gap: 4px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color .14s var(--ease);
}
.chat-item:hover { background: rgba(55, 53, 47, .05); }
.chat-item.is-active { background: rgba(55, 53, 47, .08); }

.chat-item__btn {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.chat-item__title {
  display: block;
  font-size: 14px;
  line-height: 1.2;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item.is-active .chat-item__title { font-weight: 500; }
.chat-item__meta {
  display: block;
  margin-top: 1px;
  font-size: 12px;
  line-height: 1.2;
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item__acts {
  flex: none;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .14s var(--ease);
}
.chat-item:hover .chat-item__acts,
.chat-item:focus-within .chat-item__acts { opacity: 1; }
/* на тач-устройствах ховера нет — кнопки должны быть видны всегда */
@media (pointer: coarse) { .chat-item__acts { opacity: 1; } }

.chat-item__rename {
  width: 100%;
  padding: 5px 8px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  outline: none;
}

/* общая пустая плашка в узком сайдбаре должна быть скромнее */
.chat-side__list .empty-state { padding: 18px 8px; gap: 6px; }
.chat-side__list .empty-state__title { font-size: 14px; }

.chat-side__foot {
  flex: none;
  border-top: 1px solid #EAE9E6;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-side__foot .balance-widget { border-top: 0; padding-top: 0; }
/* в макете «Пополнить» с радиусом 6, а не базовым 8 */
.chat-side__foot .btn { border-radius: var(--radius-sm); }
.side-links {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--faint);
}
.side-links a { color: var(--muted); }
.side-links a:hover { color: var(--text); }

/* мобильный сайдбар — выезжает поверх ленты */
.chat-side__backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(15, 15, 15, .32);
  border: 0;
  padding: 0;
  animation: gw-fade .18s var(--ease);
}

@media (max-width: 900px) {
  .chat-side {
    position: fixed;
    z-index: 56;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(320px, 88vw);
    transform: translateX(-102%);
    transition: transform .22s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .chat-side.is-open { transform: none; }
  /* мобильная шторка: свои размеры из артборда Mobile / Sidebar */
  .chat-side__brand {
    padding: 8px 12px 6px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .chat-side__brand .logo { font-size: 19px; }
  .side-hide { display: inline-flex; width: 40px; height: 40px; }
  .chat-side__menu { padding: 6px 12px 8px; gap: 8px; }
  .chat-side__list { padding: 4px 12px; gap: 2px; }
  .chat-group { padding: 10px 4px 6px; }
  .chat-item { padding: 11px 12px; border-radius: var(--radius-md); }
  .chat-item.is-active { background: var(--surface); box-shadow: var(--shadow-sm); }
  .chat-item__title { font-size: 15px; }
  .chat-item.is-active .chat-item__title { font-weight: 600; }
  .chat-item__meta { font-size: 13px; }
  .side-search__icon { left: 14px; }
  .side-search__input {
    height: 44px;
    padding: 0 14px 0 40px;
    font-size: 15px;
    border-radius: var(--radius-md);
  }
  .side-item { height: 46px; font-size: 15px; border-radius: var(--radius-md); }
  .side-search__input { border-color: var(--border); background: var(--surface); }
  .side-item--accent {
    background: var(--accent);
    color: #fff;
    justify-content: center;
    font-weight: 600;
  }
  .side-item--accent:hover { background: var(--accent-hover); }
  .chat-side__foot {
    background: var(--surface);
    padding: 14px 16px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  /* баланс встаёт в строку: слева подпись+сумма, справа кнопка */
  .chat-side__foot .balance-widget {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }
  .chat-side__foot .balance-widget__row { flex-direction: column; align-items: flex-start; gap: 0; }
  .chat-side__foot .balance-widget__label { font-size: 12px; }
  .chat-side__foot .balance-widget__value { font-size: 18px; font-weight: 700; }
  .chat-side__foot .balance-widget .btn {
    --btn-h: 40px;
    width: auto;
    flex: none;
    padding: 0 18px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
  }
}
@media (min-width: 901px) {
  .chat-side__backdrop { display: none; }
}

/* --------------------------------------------------- центральная часть */

.chat-main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.chat-topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 45px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-2);
  background: var(--surface);
}
.chat-topbar__sep {
  flex: none;
  width: 1px;
  height: 16px;
  background: var(--border-2);
}
.chat-topbar__title {
  min-width: 0;
  font-size: 14px;
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* баланс в топбаре нужен только на узком экране: на десктопе он в сайдбаре */
.chat-topbar__balance { height: 32px; font-size: 13px; }
@media (min-width: 901px) { .chat-topbar__balance { display: none; } }

@media (max-width: 720px) {
  .chat-topbar { height: 52px; gap: 10px; padding: 0 12px; }
  .chat-topbar__sep, .chat-topbar__title { display: none; }
  .chat-topbar [data-sys-toggle], .chat-topbar [data-delete-chat] { display: none; }
  /* пилюля баланса в мобильном топбаре — серая, без рамки */
  .chat-topbar__balance {
    height: 34px;
    padding: 0 10px;
    border-color: transparent;
    background: var(--surface-3);
    font-size: 13px;
    font-weight: 600;
  }
}

.burger { display: none; }
@media (max-width: 900px) { .burger { display: inline-flex; } }
@media (max-width: 720px) {
  .burger { width: 40px; height: 40px; border-radius: var(--radius); }
}

/* иконочная кнопка топбара и строк списка */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: #7B7A76;
  cursor: pointer;
  transition: color .14s var(--ease), background-color .14s var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--surface-3); }
.icon-btn--danger:hover { color: var(--danger); background: var(--danger-tint); }
.icon-btn svg { display: block; }
.chat-item__acts .icon-btn { width: 18px; height: 18px; border-radius: 4px; color: #91918E; }
@media (pointer: coarse) {
  .icon-btn { width: 34px; height: 34px; }
  .chat-item__acts .icon-btn { width: 28px; height: 28px; border-radius: var(--radius-sm); }
}

/* кнопка выбора модели */
.model-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  max-width: min(340px, 56vw);
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .14s var(--ease), border-color .14s var(--ease);
}
.model-btn:hover { background: var(--surface-2); }
.model-btn__mono {
  width: 18px;
  height: 18px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--muted);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
}
.model-btn__name {
  flex: 0 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-btn__price {
  flex: none;
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--faint);
}
.model-btn__chev { display: inline-flex; color: #91918E; }
@media (max-width: 720px) {
  .model-btn {
    flex: 1 1 auto;
    max-width: none;
    height: 38px;
    gap: 6px;
    padding: 0 10px;
    border-radius: var(--radius);
  }
  .model-btn__price { font-size: 11px; }
}
@media (max-width: 400px) { .model-btn__price { display: none; } }

/* ------------------------------------------------------------------ лента */

.feed {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  padding: 40px 0;
}
.feed__inner {
  width: 100%;
  max-width: 792px;      /* 760 колонка + поля */
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.messages { display: flex; flex-direction: column; gap: 34px; }
@media (max-width: 720px) {
  .feed { padding: 20px 0 8px; }
  .messages { gap: 22px; }
}

.msg { display: flex; flex-direction: column; gap: 12px; }

/* вопрос человека — пузырь справа */
.msg--user { align-items: flex-end; }
.msg__bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-3);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ответ модели — без пузыря, во всю колонку */
.msg__head { display: flex; align-items: center; gap: 8px; }
.msg__mono {
  width: 20px;
  height: 20px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--muted);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}
.msg__author { font-size: 13px; font-weight: 500; color: var(--text-2); }
.msg__time { font-size: 12px; color: var(--faint); }

.msg__body {
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  letter-spacing: -.1px;
  text-wrap: pretty;
}

/* мобильный артборд: пузырь мягче и уже, интерлиньяж плотнее */
@media (max-width: 720px) {
  .msg { gap: 10px; }
  .msg__bubble { padding: 11px 14px; border-radius: var(--radius-lg); line-height: 1.55; }
  .msg__body { line-height: 1.65; }
  .msg__body .md-p, .msg__body .md-ul, .msg__body .md-ol { margin-bottom: 12px; }
  .msg__body .md-h1 { font-size: 18px; }
  .msg__body .md-h2 { font-size: 17px; }
}

/* мигающая каретка, пока идёт стрим */
.msg__body.is-streaming > :last-child::after,
.msg__body.is-streaming:empty::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--text);
  animation: gw-blink 1s step-end infinite;
}

/* блок размышлений — вертикальная линия слева, как в макете */
.reason {
  border-left: 2px solid var(--hair);
  padding: 4px 0 4px 14px;
}
.reason > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  user-select: none;
}
.reason > summary::-webkit-details-marker { display: none; }
.reason > summary::before {
  content: '';
  width: 0;
  height: 0;
  border-left: 5px solid #91918E;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .15s var(--ease);
}
.reason[open] > summary::before { transform: rotate(90deg); }
.reason__body {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--faint);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 320px;
  overflow-y: auto;
}

/* строка доверия под ответом */
.msg .trust-line { margin-top: 2px; flex-wrap: wrap; }
.msg__acts { display: flex; gap: 2px; margin-left: auto; }
.msg__acts .icon-btn { width: 22px; height: 22px; border-radius: 5px; color: #91918E; }

.dots { display: inline-flex; gap: 4px; align-items: center; height: 16px; }
.dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--hair);
  animation: gw-bounce 1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes gw-bounce { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }

/* кнопка «вниз» — над композером, у правого края колонки */
.to-bottom {
  position: absolute;
  right: 18px;
  top: -50px;
  z-index: 5;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: grid;
  place-items: center;
}
.to-bottom:hover { background: var(--surface-2); }

/* ------------------------------------------------------------- плашки */

.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 16px;
  border: 1px solid #E9E9E7;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.notice__icon { flex: none; margin-top: 1px; color: var(--muted); display: inline-flex; }
.notice__body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.notice__title { font-size: 15px; font-weight: 600; color: var(--text); }
.notice__text { font-size: 14px; line-height: 1.5; color: var(--text-2); margin-top: 3px; }
.notice__acts { display: flex; gap: 10px; flex-wrap: wrap; }
.notice__acts .btn { --btn-h: 34px; border-radius: var(--radius-sm); }

.notice--danger { border-color: var(--danger-border); background: var(--danger-tint); }
.notice--danger .notice__icon { color: var(--danger); }
.notice--danger .notice__title { color: #991B1B; }
.notice--danger .notice__text { color: #7F1D1D; }

.notice--warn { border-color: var(--warn-border); background: var(--warn-tint); }
.notice--warn .notice__icon { color: var(--warn); }
.notice--warn .notice__title { color: #8A5A12; }
.notice--warn .notice__text { color: #8A5A12; }

/* -------------------------------------------------- пустой чат (starter) */

.starter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: clamp(8px, 6vh, 56px) 0 8px;
  text-align: center;
}
.starter__top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.starter__word {
  font-size: clamp(28px, 6vw, 40px);
  font-weight: 800;
  letter-spacing: -.4px;
  color: #111111;
  line-height: 1.1;
  margin-bottom: 6px;
}
.starter__hi {
  font-size: clamp(21px, 4vw, 28px);
  font-weight: 700;
  letter-spacing: -.4px;
}
.starter__sub { font-size: 15px; color: var(--muted); }

.starter__trust {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.starter__faces { display: flex; }
.starter__face {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.starter__face + .starter__face { margin-left: -8px; }
.starter__count { font-size: 13px; color: var(--faint); }

.starter__grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
}
@media (max-width: 620px) { .starter__grid { grid-template-columns: minmax(0, 1fr); } }

.starter__card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  border: 1px solid #E9E9E7;
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 15, 15, .03);
  cursor: pointer;
  text-align: left;
  transition: border-color .14s var(--ease), background-color .14s var(--ease);
}
.starter__card:hover { border-color: var(--hair); background: var(--surface-2); }
.starter__ic {
  width: 32px;
  height: 32px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--text-2);
}
.starter__card b { display: block; font-size: 14px; font-weight: 600; }
.starter__card span { display: block; margin-top: 3px; font-size: 13px; line-height: 1.45; color: var(--faint); }

.chat-skeleton { display: flex; flex-direction: column; gap: 10px; }
.chat-skeleton .skeleton { height: 44px; border-radius: var(--radius-md); }

/* -------------------------------------------------------------- композер */

.composer {
  flex: none;
  background: var(--surface);
  padding: 0 0 max(24px, env(safe-area-inset-bottom));
}
.composer__inner {
  position: relative;
  width: 100%;
  max-width: 792px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sys-panel {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.sys-panel .textarea { min-height: 88px; font-size: 14px; background: var(--surface); }

.composer__box {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 12px 12px 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 15, 15, .04), 0 10px 26px rgba(15, 15, 15, .07);
  transition: border-color .14s var(--ease);
}
.composer__box:focus-within { border-color: var(--accent); }

.composer__input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 26px;
  max-height: 38vh;
  padding: 6px 0;
  border: 0;
  background: none;
  resize: none;
  outline: none;
  color: var(--text);
  font: inherit;
  font-size: 16px;      /* меньше 16px — iOS зумит страницу при фокусе */
  line-height: 1.6;
  overflow-y: auto;
}
.composer__input::placeholder { color: var(--faint); }

.composer__send {
  flex: none;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background-color .14s var(--ease), opacity .14s var(--ease);
}
.composer__send:hover { background: var(--accent-hover); }
.composer__send[disabled] { opacity: .45; cursor: not-allowed; }
.composer__send--stop { background: var(--danger); }
.composer__send--stop:hover { background: #B91C1C; }

.composer__foot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 4px;
  font-size: 12px;
  color: var(--faint);
}
.composer__hint { display: none; align-items: center; gap: 6px; }
@media (min-width: 721px) { .composer__hint { display: inline-flex; } }
.composer__dot { color: var(--hair); }
.composer__counter { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.composer__counter.is-over { color: var(--danger); font-weight: 600; }
.composer__live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.composer__live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: gw-blink 1.2s step-end infinite;
}

/* мобильный композер: капсула 22px, круглые кнопки, отбивка от ленты */
@media (max-width: 720px) {
  .composer {
    padding: 8px 0 max(14px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-2);
  }
  .composer__inner { padding: 0 14px; }
  .composer__box {
    align-items: center;
    gap: 10px;
    padding: 6px 6px 6px 16px;
    border-radius: 22px;
    box-shadow: 0 1px 2px rgba(15, 15, 15, .04), 0 8px 22px rgba(15, 15, 15, .07);
  }
  .composer__input { padding: 0; }
  .composer__send { width: 40px; height: 40px; border-radius: var(--radius-pill); }
}

kbd {
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
}

/* ------------------------------------------------------- выбор модели */

.picker {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.picker__backdrop { position: absolute; inset: 0; background: rgba(15, 15, 15, .32); }

.picker__panel {
  position: relative;
  width: 560px;
  max-width: 100%;
  height: 640px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 1px rgba(15, 15, 15, .04), 0 8px 18px rgba(15, 15, 15, .08), 0 28px 60px rgba(15, 15, 15, .18);
  overflow: hidden;
  animation: gw-pop .16s var(--ease);
}

.picker__head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
}
.picker__title { flex: 1 1 auto; font-size: 15px; font-weight: 600; }
.picker__count { font-size: 12px; color: var(--faint); }
/* в макете крестик в шапке пикера меньше топбарного — 26px */
.picker__head .icon-btn { width: 26px; height: 26px; color: var(--text-2); }

.picker__search {
  flex: none;
  position: relative;
  margin: 0 16px 8px;
  display: flex;
  align-items: center;
}
.picker__search-icon {
  position: absolute;
  left: 13px;
  display: inline-flex;
  color: var(--faint);
  pointer-events: none;
}
.picker__search-input {
  width: 100%;
  height: 44px;
  padding: 0 38px 0 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease);
}
.picker__search-input::placeholder { color: var(--faint); }
.picker__search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(35, 131, 226, .12); }
.picker__search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.picker__search-clear {
  position: absolute;
  right: 12px;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: #E9E9E7;
  color: #6B6A66;
  cursor: pointer;
}
.picker__note { flex: none; padding: 0 18px 12px; font-size: 12px; color: var(--faint); }

.picker__filters {
  flex: none;
  display: flex;
  gap: 7px;
  padding: 0 16px 12px;
  flex-wrap: wrap;
}
@media (max-width: 560px) {
  .picker__filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .picker__filters::-webkit-scrollbar { display: none; }
}

.picker__list {
  flex: 1 1 auto;
  min-height: 0;
  border-top: 1px solid var(--border-2);
  padding: 0 8px 8px;
}
.picker__group {
  padding: 12px 8px 4px;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 600;
  color: var(--faint);
}
.picker__list .model-row { border-radius: var(--radius); }
/* кружок-монограмма в макете крупнее базового — 32px */
.picker__list .model-row__mono { width: 32px; height: 32px; font-size: 13px; }
/* бейджи не должны сжиматься: длинное имя модели ужимается само */
.picker__list .badge { flex: none; }
.picker__list .model-row.is-cursor { background: var(--surface-2); }
.picker__list .model-row.is-selected.is-cursor { background: rgba(35, 131, 226, .12); }

/* синяя галочка у выбранной модели: рисуем рамкой, отдельной иконки-галки в
   наборе нет, а изобретать свой SVG запрещено */
.model-row__check {
  position: relative;
  flex: none;
  width: 16px;
  height: 16px;
}
.model-row__check::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: 2px solid var(--accent);
  border-top: 0;
  border-left: 0;
  border-radius: 1px;
  transform: rotate(42deg);
}
.model-row__fav:hover { background: var(--surface-3); color: var(--muted); }
.model-row__fav.is-on:hover { color: #E0A82E; }

.picker__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 0 40px 40px;
  min-height: 100%;
  text-align: center;
}
.picker__empty-ic {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-3);
  color: #B9B8B4;
  display: grid;
  place-items: center;
}
.picker__empty-title { font-size: 16px; font-weight: 600; }
.picker__empty-text { margin-top: 6px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.picker__empty-tips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.picker__empty-tips .pill { padding: 6px 12px; }

.picker__foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-top: 1px solid var(--border-2);
  font-size: 12px;
  color: var(--faint);
}
.picker__keys { display: inline-flex; align-items: center; gap: 14px; }
.picker__key { display: inline-flex; align-items: center; gap: 6px; }
.picker__all { font-size: 13px; font-weight: 500; color: var(--accent); }

/* на мобиле — шторка снизу на 92% высоты */
@media (max-width: 720px) {
  .picker { padding: 0; align-items: flex-end; }
  .picker__panel {
    width: 100%;
    height: 92%;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 32px rgba(15, 15, 15, .2);
    animation: gw-slide-up .2s var(--ease);
  }
  .picker__panel::before {
    content: '';
    width: 38px;
    height: 5px;
    margin: 10px auto 4px;
    border-radius: var(--radius-pill);
    background: var(--hair);
    flex: none;
  }
  .picker__head { padding: 8px 18px 10px; }
  .picker__title { font-size: 17px; }
  .picker__count { font-size: 13px; }
  .picker__note { display: none; }
  .picker__foot { display: none; }
  .picker__search { margin: 0 16px 10px; }
  .picker__search-input {
    height: 44px;
    font-size: 15px;
    border-radius: var(--radius-md);
    background: var(--surface-2);
  }
  .picker__filters { padding: 0 16px 10px; }
  .picker__filters .pill { padding: 6px 14px; }
  .picker__list { padding: 0 8px; }
}

/* ------------------------------------------------- markdown внутри ответа */

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }

.md-p { margin: 0 0 14px; }
.md-h { margin: 22px 0 8px; font-weight: 700; letter-spacing: -.2px; line-height: 1.3; }
.md-h1 { font-size: 20px; }
.md-h2 { font-size: 18px; }
.md-h3 { font-size: 16px; }
.md-h4, .md-h5, .md-h6 { font-size: 15px; }

.md-ul, .md-ol { margin: 0 0 14px; padding-left: 24px; }
.md-ul { list-style: disc; }
.md-ol { list-style: decimal; }
.md-ul li, .md-ol li { margin: 6px 0; }
.md-ul li::marker, .md-ol li::marker { color: var(--faint); }
.md-ul .md-ul, .md-ol .md-ol, .md-ul .md-ol, .md-ol .md-ul { margin: 6px 0 2px; }

.md-quote {
  margin: 0 0 14px;
  padding: 2px 0 2px 14px;
  border-left: 2px solid var(--hair);
  color: var(--text-2);
}

.md-hr { margin: 20px 0; height: 1px; border: 0; background: var(--border-2); }

.md-link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md-link:hover { color: var(--accent-hover); }

.md-code-inline {
  padding: 1px 5px;
  border-radius: 4px;
  background: #F1F1EF;
  color: #C0392B;
  font-family: var(--mono);
  font-size: .88em;
}

/* блок кода — шапка с языком и копированием, как в Notion */
.md-code {
  margin: 0 0 14px;
  border: 1px solid #E9E9E7;
  border-radius: var(--radius-sm);
  background: #F7F6F3;
  overflow: hidden;
}
.md-code__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid #E9E9E7;
}
.md-code__lang { flex: 1 1 auto; font-size: 12px; font-weight: 500; color: var(--faint); }
.md-code__copy {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.md-code__copy svg { color: #91918E; }
.md-code__copy:hover { color: var(--text); }
.md-code__copy.is-done { color: var(--ok); }
.md-code__copy.is-done svg { color: var(--ok); }

.md-code__pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  tab-size: 4;
}
.md-code__pre code { font-family: inherit; white-space: pre; }

.md-table-wrap {
  margin: 0 0 14px;
  overflow-x: auto;
  border: 1px solid #E9E9E7;
  border-radius: var(--radius-sm);
}
.md-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md-table th, .md-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-2);
  text-align: left;
  vertical-align: top;
}
.md-table th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.md-table tr:last-child td { border-bottom: 0; }

/* Прикидка стоимости запроса в композере: цифра моноширинная, чтобы не дёргалась
   при каждом набранном символе — иначе счётчик рядом прыгает по горизонтали. */
.composer__cost {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--faint);
  white-space: nowrap;
  cursor: help;
}
.composer__cost + .composer__counter { margin-left: 10px; }

/* Сообщения появляются мягко, а не «выстреливают». Только opacity/transform,
   и уважаем системную настройку уменьшенного движения. */
@media (prefers-reduced-motion: no-preference) {
  .msg { animation: gw-msg-in .18s var(--ease) both; }
  @keyframes gw-msg-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
  }
}
