:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --side: #f7f8fa;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --accent-soft: #e8effd;
  --bubble-in: #f2f4f7;
  --danger: #c2410c;
  --rec: #e5484d;
  --radius: 18px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --panel: #171a20;
    --side: #13161b;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --line: #262a32;
    --accent: #4b83f5;
    --accent-soft: #1d2a44;
    --bubble-in: #20242c;
    --danger: #f08a5d;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); display: flex; justify-content: center; }
[hidden] { display: none !important; }
button { font: inherit; }

.app { width: 100%; max-width: 1120px; height: 100dvh; display: flex; position: relative; }
@media (min-width: 900px) {
  body { align-items: center; }
  .app { height: min(880px, 94dvh); border-radius: 22px; box-shadow: 0 10px 40px rgb(0 0 0 / .08); overflow: hidden; }
}

/* ---------- боковая панель ---------- */

.side {
  width: 300px; flex: none; display: flex; flex-direction: column;
  background: var(--side); border-right: 1px solid var(--line);
}
.side__top { display: flex; align-items: center; gap: 8px; padding: 16px 14px 10px; }
.side__title { font-weight: 600; font-size: 17px; }
.side__new {
  margin-left: auto; display: inline-flex; align-items: center; gap: 4px;
  border: 0; border-radius: 10px; padding: 7px 12px; font-size: 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
}
.side__list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.side__empty { color: var(--muted); font-size: 14px; padding: 12px 8px; line-height: 1.45; }

.item {
  position: relative; display: block; width: 100%; text-align: left; cursor: pointer;
  border: 0; border-radius: 12px; padding: 10px 36px 10px 12px; margin-bottom: 2px;
  background: none; color: inherit;
}
.item:hover { background: var(--bubble-in); }
.item.on { background: var(--accent-soft); }
.item__row { display: flex; gap: 8px; align-items: baseline; }
.item__title { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item__time { font-size: 12px; color: var(--muted); flex: none; }
.item__last { font-size: 13px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item__del {
  position: absolute; right: 6px; top: 50%; translate: 0 -50%;
  width: 28px; height: 28px; border-radius: 8px; border: 0; background: none; color: var(--muted);
  display: grid; place-items: center; cursor: pointer; opacity: 0;
}
.item:hover .item__del, .item:focus-within .item__del { opacity: 1; }
.item__del:hover { background: var(--line); color: var(--danger); }
@media (hover: none) { .item__del { opacity: 1; } }
.confirm { display: flex; align-items: center; gap: 6px; padding: 10px 12px; font-size: 14px; border-radius: 12px; background: var(--bubble-in); margin-bottom: 2px; }
.confirm span { flex: 1; }
.confirm button { border: 0; border-radius: 8px; padding: 5px 10px; cursor: pointer; font-size: 13px; background: var(--line); color: var(--text); }
.confirm .yes { background: var(--danger); color: #fff; }

.scrim { display: none; }
.chat__head .burger { display: none; }

@media (max-width: 760px) {
  .side {
    position: absolute; inset: 0 auto 0 0; width: min(320px, 86vw); z-index: 20;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 30px rgb(0 0 0 / .18);
  }
  .app.drawer .side { transform: none; }
  .scrim { display: block; position: absolute; inset: 0; z-index: 10; background: rgb(0 0 0 / .35); opacity: 0; pointer-events: none; transition: opacity .22s; }
  .app.drawer .scrim { opacity: 1; pointer-events: auto; }
  .chat__head .burger { display: grid; }
}

/* ---------- чат ---------- */

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); position: relative; }

.chat__head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.chat__name { font-weight: 600; }
.chat__status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }

.icon-btn {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; background: none; color: var(--muted);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--bubble-in); }
.burger { margin-left: -8px; }

.feed { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }

.msg { max-width: 82%; display: flex; flex-direction: column; gap: 6px; animation: rise .18s ease-out; }
.msg--user { align-self: flex-end; align-items: flex-end; }
.msg--assistant { align-self: flex-start; }
.msg--user + .msg--assistant, .msg--assistant + .msg--user { margin-top: 8px; }
.feed.still .msg { animation: none; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
/* Уже показанное (черновик → готовый ответ, принятое сообщение) — без повторного появления. */
.msg.settled { animation: none; }
/* Расшифровка голосового — под плеером, мельче. */
.voice__text { font-size: 13px; line-height: 1.4; opacity: .85; padding: 0 4px; max-width: 100%; overflow-wrap: anywhere; }

.bubble {
  padding: 10px 14px; border-radius: var(--radius); line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg--user .bubble { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.msg--assistant .bubble { background: var(--bubble-in); border-bottom-left-radius: 6px; }
.time { font-size: 11px; color: var(--muted); padding: 0 6px; }

.photo { margin: 0; max-width: 340px; }
.photo a { display: block; }
.photo img { display: block; max-width: 100%; max-height: 360px; border-radius: 14px; background: var(--bubble-in); }
.photo figcaption { font-size: 13px; color: var(--muted); padding: 4px 6px 0; }

.product {
  display: flex; gap: 12px; width: 320px; max-width: 100%; padding: 10px;
  border: 1px solid var(--line); border-radius: 14px; color: inherit; text-decoration: none;
}
a.product:hover { border-color: var(--accent); }
.product img { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; flex: none; background: var(--bubble-in); }
.product__title { font-weight: 600; line-height: 1.3; }
.product__price { margin-top: 4px; font-weight: 600; }
.product__old { margin-left: 6px; color: var(--muted); text-decoration: line-through; font-weight: 400; font-size: 13px; }
.product__note { font-size: 13px; color: var(--muted); margin-top: 2px; }

.doc {
  display: flex; align-items: center; gap: 10px; width: 280px; max-width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 14px; color: inherit; text-decoration: none; background: var(--panel);
}
a.doc:hover { border-color: var(--accent); }
.doc__icon { width: 38px; height: 38px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.doc__name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc__size { font-size: 12px; color: var(--muted); }
.doc > div { min-width: 0; }

.voice {
  display: flex; align-items: center; gap: 10px; width: 260px; max-width: 70vw;
  padding: 8px 14px 8px 8px; border-radius: var(--radius); background: var(--bubble-in);
}
.msg--user .voice { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.voice__play {
  width: 36px; height: 36px; flex: none; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-text);
}
.msg--user .voice__play { background: var(--accent-text); color: var(--accent); }
.voice__track { flex: 1; height: 4px; border-radius: 2px; background: color-mix(in srgb, currentColor 25%, transparent); cursor: pointer; position: relative; }
.voice__track::before { content: ""; position: absolute; inset: -10px 0; }
.voice__fill { height: 100%; width: 0; border-radius: 2px; background: currentColor; }
.voice__time { font-size: 12px; font-variant-numeric: tabular-nums; min-width: 32px; text-align: right; }
.voice audio { display: none; }

.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.error { align-self: center; font-size: 13px; color: var(--danger); display: flex; gap: 8px; align-items: center; margin: 6px 0; text-align: center; }
.error button { color: var(--accent); background: none; border: 0; cursor: pointer; text-decoration: underline; }

.empty { margin: auto; text-align: center; color: var(--muted); max-width: 340px; line-height: 1.5; }

.hints { display: flex; gap: 8px; padding: 0 16px 10px; flex-wrap: wrap; }
.hints button {
  border: 1px solid var(--line); background: none; color: var(--text); font-size: 14px;
  padding: 7px 12px; border-radius: 999px; cursor: pointer;
}
.hints button:hover { border-color: var(--accent); }

/* ---------- вложения перед отправкой ---------- */

.tray { display: flex; gap: 8px; padding: 10px 12px 0; overflow-x: auto; border-top: 1px solid var(--line); }
.chip {
  position: relative; flex: none; width: 72px; height: 72px; border-radius: 12px; overflow: hidden;
  background: var(--bubble-in); border: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px; padding: 4px;
}
.chip img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.chip__name { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip__x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; z-index: 2;
  background: rgb(0 0 0 / .55); color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 14px; line-height: 1;
}
.chip__bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); z-index: 1; transition: width .15s; }
.chip.err { border-color: var(--danger); }
.chip.err .chip__name { color: var(--danger); }

/* ---------- ввод ---------- */

.composer, .recbar {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
}
.tray:not([hidden]) + .composer { border-top: 0; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; max-height: 160px; font: inherit; font-size: 16px; line-height: 1.4;
  padding: 9px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.round {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); cursor: pointer; display: grid; place-items: center;
}
.round:disabled { opacity: .45; cursor: default; }

.recbar { align-items: center; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: blink 1s infinite; margin-left: 4px; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-hint { flex: 1; color: var(--muted); font-size: 14px; }

.drop {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent); border: 2px dashed var(--accent);
  color: var(--accent); font-weight: 600; pointer-events: none;
}

/* Черновик ответа при живой печати — те же пузыри, без отдельной обёртки. */
.draft { display: flex; flex-direction: column; gap: 6px; }

/* Служебная строка в ленте: «Диалог переведён на менеджера». */
.notice { align-self: center; margin: 6px 0; padding: 4px 12px; border-radius: 999px; font-size: 12px; color: var(--muted, #6b7280); background: var(--soft, rgba(127, 127, 127, .12)); }

/* Цена чата в шапке и цена хода у времени — мелко, для разработки. */
.chat__cost { margin-left: auto; max-width: 55%; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Режим хода ядра у чата: v1 — прежний, v2 — новый. */
.mode { flex: none; display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.chat__cost + .mode, .chat__cost[hidden] + .mode { margin-left: 8px; }
.chat__cost[hidden] + .mode { margin-left: auto; }
.mode button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 6px 10px; min-width: 36px; cursor: pointer; }
.mode button + button { border-left: 1px solid var(--line); }
.mode button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.mode button:disabled { opacity: .6; cursor: default; }
.chat__mode-note { margin-left: 4px; white-space: nowrap; }
.chat__mode-note::before { content: '· '; }
.chat__mode-note:empty { display: none; }
