:root {
  --bg: #0b0c12;
  --panel: #111219;
  --panel-2: #161824;
  --card: #191b27;
  --line: rgba(255, 255, 255, .08);
  --text: #eceef6;
  --muted: #969ab0;
  --brand: #6c5ce7;
  --brand-2: #4a7dff;
  --brand-3: #a066ff;
  --ok: #35c88a;
  --danger: #ff6b81;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: #9db4ff; }

/* ------------------------------------------------------------- каркас */
.app { display: flex; height: 100vh; height: 100dvh; }

.sidebar {
  width: 286px;
  flex: 0 0 286px;
  background: linear-gradient(180deg, #12131c 0%, #0e0f16 100%);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 12px 12px;
  gap: 12px;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 4px 6px; }

.logo {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-3) 55%, var(--brand-2));
  display: grid; place-items: center;
  font-weight: 800; font-size: 19px; color: #fff;
  box-shadow: 0 8px 22px rgba(108, 92, 231, .45);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text b { font-size: 16px; letter-spacing: .2px; }
.brand-text span { font-size: 12px; color: var(--muted); }

.new-chat {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 10px 26px rgba(74, 125, 255, .28);
  transition: transform .12s ease, filter .2s ease;
}
.new-chat:hover { filter: brightness(1.08); transform: translateY(-1px); }
.new-chat span.plus { font-size: 18px; line-height: 1; }

.chats {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 2px;
  scrollbar-width: thin;
  scrollbar-color: #2a2d3d transparent;
}
.chats::-webkit-scrollbar { width: 8px; }
.chats::-webkit-scrollbar-thumb { background: #2a2d3d; border-radius: 8px; }

.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 10px;
  border-radius: 12px;
  color: #d7dae8;
  border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: linear-gradient(135deg, rgba(108,92,231,.24), rgba(74,125,255,.16)); border-color: rgba(140,150,255,.35); }
.chat-item .ci-text { flex: 1; min-width: 0; }
.chat-item .ci-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .ci-sub { font-size: 11px; color: var(--muted); }
.chat-item .ci-actions { display: none; gap: 2px; }
.chat-item:hover .ci-actions { display: flex; }

.icon-btn {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  color: var(--muted);
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.09); color: #fff; }

.empty-hint { color: var(--muted); font-size: 13px; padding: 10px 12px; }

.side-foot {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.side-foot .me { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; font-size: 13px; color: var(--muted); }
.side-foot .ava {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #2b2f45, #1c1f2e);
  display: grid; place-items: center; font-size: 12px; color: #cfd4ea; font-weight: 700;
  border: 1px solid var(--line);
}

/* -------------------------------------------------------------- главное */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 12, 18, .72);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 10;
}
.chat-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  font-size: 12px; font-weight: 600; color: #cfd6ff;
  padding: 5px 11px; border-radius: 999px;
  background: linear-gradient(135deg, rgba(108,92,231,.3), rgba(74,125,255,.22));
  border: 1px solid rgba(140,150,255,.28);
}
.open-side { display: none; }

.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread::-webkit-scrollbar { width: 10px; }
.thread::-webkit-scrollbar-thumb { background: #23263a; border-radius: 10px; }

.wrap { max-width: 860px; margin: 0 auto; padding: 22px 20px 30px; }

/* -------------------------------------------------------- приветствие */
.welcome { padding: 6vh 20px 0; text-align: center; }
.welcome h1 {
  font-size: clamp(26px, 3.4vw, 40px);
  margin: 0 0 10px;
  background: linear-gradient(100deg, #ffffff, #b9c4ff 40%, #c79bff 75%, #7fa8ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.welcome p { color: var(--muted); margin: 0 auto 26px; max-width: 560px; }
.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-width: 640px; margin: 0 auto; }
.chip {
  text-align: left; padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.chip:hover { transform: translateY(-2px); border-color: rgba(140,150,255,.45); background: #1e2130; }
.chip b { display: block; font-size: 14px; margin-bottom: 3px; }
.chip span { color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------ сообщения */
.msg { display: flex; gap: 12px; margin: 18px 0; animation: rise .22s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg .avatar {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 11px; display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.msg.bot .avatar { background: linear-gradient(135deg, var(--brand), var(--brand-3) 60%, var(--brand-2)); color: #fff; box-shadow: 0 6px 18px rgba(108,92,231,.4); }
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: linear-gradient(135deg, #2b2f45, #1e2130); color: #dfe3f5; border: 1px solid var(--line); }

.bubble {
  max-width: min(680px, 82%);
  padding: 13px 16px;
  border-radius: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: linear-gradient(135deg, rgba(108,92,231,.34), rgba(74,125,255,.26)); border-color: rgba(140,150,255,.3); }
.msg.bot .bubble { background: var(--card); }

.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble h4 { margin: 14px 0 6px; font-size: 15px; }
.bubble code { background: rgba(255,255,255,.09); padding: 1px 6px; border-radius: 6px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.bubble a { text-decoration: underline; }

.code-wrap { position: relative; margin: 10px 0; }
.code-wrap pre {
  margin: 0; padding: 14px 14px;
  background: #0d0f17; border: 1px solid var(--line); border-radius: 12px;
  overflow-x: auto; font-size: 13px; line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.code-wrap pre code { background: none; padding: 0; }
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  font-size: 12px; color: var(--muted);
  padding: 4px 9px; border-radius: 8px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
}
.copy-btn:hover { color: #fff; background: rgba(255,255,255,.12); }

.typing { display: inline-flex; gap: 5px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #7d84a8; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 80%, 100% { opacity: .28; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.caret::after {
  content: "";
  display: inline-block; width: 7px; height: 15px; margin-left: 2px;
  background: #9aa6ff; vertical-align: -2px;
  animation: caret .9s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* ------------------------------------------------------------ поле ввода */
.composer { padding: 10px 20px 18px; background: linear-gradient(180deg, rgba(11,12,18,0), rgba(11,12,18,.92) 40%); }
.composer .inner { max-width: 860px; margin: 0 auto; }
.box {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 10px 10px 14px;
  box-shadow: var(--shadow);
  transition: border-color .15s ease;
}
.box:focus-within { border-color: rgba(140,150,255,.5); }
.box textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: none;
  max-height: 190px; padding: 7px 0; line-height: 1.5;
}
.box textarea::placeholder { color: #7d819a; }

.send, .stop {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 13px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 22px rgba(74,125,255,.3);
  transition: filter .15s ease, transform .12s ease;
}
.send:hover { filter: brightness(1.1); }
.send:disabled { opacity: .45; cursor: default; box-shadow: none; }
.stop { background: linear-gradient(135deg, #3a3f57, #2a2e42); box-shadow: none; }
.stop:hover { filter: brightness(1.15); }
.hint { text-align: center; color: #6d7188; font-size: 12px; margin-top: 9px; }

/* -------------------------------------------------------------- вход */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card .logo { margin: 0 auto 16px; width: 54px; height: 54px; border-radius: 16px; font-size: 26px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.login-card input[type=password] {
  width: 100%; padding: 14px 16px;
  background: #0e0f17; border: 1px solid var(--line); border-radius: 14px;
  outline: 0; margin-bottom: 14px;
}
.login-card input[type=password]:focus { border-color: rgba(140,150,255,.55); }
.login-card button {
  width: 100%; padding: 14px; border-radius: 14px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.login-card .err {
  margin: 0 0 14px; padding: 10px 12px; font-size: 13px;
  color: #ffd7de; background: rgba(255,107,129,.14);
  border: 1px solid rgba(255,107,129,.35); border-radius: 12px;
}
.login-card .foot { color: #6d7188; font-size: 12px; margin-top: 18px; }

/* -------------------------------------------------------------- мобилки */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 20;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    transform: translateX(-102%); transition: transform .24s ease;
    width: 82vw; max-width: 320px; flex-basis: auto;
  }
  .sidebar.open { transform: none; }
  .open-side { display: grid; }
  .close-side { display: grid; margin-left: auto; }
  .wrap { padding: 16px 14px 24px; }
  .chips { grid-template-columns: 1fr; }
  .bubble { max-width: 100%; }
  .composer { padding: 8px 12px 14px; }
}

@media (min-width: 861px) { .close-side { display: none; } }

/* системная тема «светлая» — оставляем тёмной для единообразия */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
