:root {
  --bg: #0b0e14;
  --panel: #10141d;
  --panel-2: #141a26;
  --border: #1e2635;
  --text: #e8ebf2;
  --muted: #8a93a8;
  --accent: #7c9cff;
  --accent-strong: #4f6ef7;
  --bubble: #151b28;
  --user-bubble: #1c2b4d;
  --error: #ff8a80;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ------------------------------------------------------------------ логин */

.login-body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(79, 110, 247, .20), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .03), transparent), var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 36px 28px 28px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}

.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  font-size: 26px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(79, 110, 247, .35);
}

.login-card h1 { font-size: 20px; margin: 0 0 8px; letter-spacing: -.01em; }
.login-hint { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 24px; }

.code-input {
  width: 100%;
  padding: 15px 16px;
  text-align: center;
  font-size: 26px;
  letter-spacing: .32em;
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.code-input:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, .22);
}

#login-button {
  width: 100%;
  margin-top: 14px;
  padding: 13px 16px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-weight: 600;
  transition: transform .08s, opacity .15s;
}
#login-button:hover { opacity: .92; }
#login-button:active { transform: translateY(1px); }
#login-button:disabled { opacity: .55; cursor: default; }

.login-error { min-height: 20px; margin: 12px 0 0; color: var(--error); font-size: 13px; }

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

.app {
  display: grid;
  grid-template-columns: 286px 1fr;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 16px 12px;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 8px;
  font-weight: 650;
  letter-spacing: -.01em;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-size: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-radius: 10px;
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 12px;
  border: 1px dashed #2b3650;
  border-radius: 12px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  transition: background .15s, border-color .15s;
}
.new-chat:hover { background: rgba(124, 156, 255, .08); border-color: var(--accent-strong); }

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 2px;
}

.conv {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 10px;
}
.conv:hover { background: var(--panel-2); }
.conv.active { background: rgba(124, 156, 255, .13); }

.conv-open {
  flex: 1;
  min-width: 0;
  padding: 10px 10px;
  border: 0;
  background: transparent;
  text-align: left;
  font-size: 13.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv.active .conv-open { color: #c9d6ff; }

.conv-del {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  margin-right: 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: opacity .12s, color .12s, background .12s;
}
.conv:hover .conv-del, .conv-del:focus-visible { opacity: 1; }
.conv-del:hover { background: rgba(255, 138, 128, .14); color: var(--error); }

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 8px 2px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
}
.icon-button:hover { background: var(--panel-2); color: var(--text); }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(800px 400px at 70% -20%, rgba(79, 110, 247, .07), transparent 60%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 14, 20, .7);
  backdrop-filter: blur(8px);
}

.menu-button { display: none; }

.chat-title {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status { margin-left: auto; color: var(--muted); font-size: 12.5px; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 26px 20px 10px;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  max-width: 780px;
  margin: 0 auto 14px;
  animation: rise .18s ease-out;
}
.msg.user { justify-content: flex-end; }

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.bubble {
  position: relative;
  max-width: min(86%, 720px);
  padding: 12px 15px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bubble);
  font-size: 14.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border-color: #263a66;
  white-space: pre-wrap;
}
.msg.assistant .bubble { border-bottom-left-radius: 6px; }
.msg.user .bubble { border-bottom-right-radius: 6px; }

.msg-time {
  position: absolute;
  right: 10px;
  bottom: 5px;
  font-size: 10.5px;
  color: var(--muted);
  opacity: .75;
}

.error-bubble { border-color: rgba(255, 138, 128, .4); color: #ffd7d3; }

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

.bubble p { margin: 0 0 10px; }
.bubble p:last-of-type { margin-bottom: 0; }
.bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  margin: 16px 0 8px;
  line-height: 1.3;
}
.bubble h3 { font-size: 16px; }
.bubble h4 { font-size: 15px; }
.bubble ul, .bubble ol { margin: 8px 0 10px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble code {
  font-family: var(--mono);
  font-size: 12.8px;
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(124, 156, 255, .12);
  color: #c7d4ff;
}
.bubble pre {
  margin: 10px 0;
  padding: 12px 13px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0b101a;
}
.bubble pre code { padding: 0; background: none; color: #dbe4ff; font-size: 12.6px; line-height: 1.55; }
.bubble blockquote {
  margin: 10px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--accent-strong);
  color: #c3cada;
  background: rgba(124, 156, 255, .06);
  border-radius: 0 8px 8px 0;
}
.bubble a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(124, 156, 255, .35); }
.bubble a:hover { border-bottom-color: var(--accent); }
.bubble hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.bubble strong { color: #fff; }

.empty {
  height: 100%;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  line-height: 1.6;
}
.empty-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: #fff;
  background: linear-gradient(135deg, rgba(124, 156, 255, .5), rgba(79, 110, 247, .35));
  border-radius: 18px;
}

/* индикатор «печатает» */

.typing .bubble { display: flex; gap: 5px; padding: 15px 16px; }
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .35;
  animation: blink 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: .18s; }
.dot:nth-child(3) { animation-delay: .36s; }
@keyframes blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* поле ввода */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 20px 20px;
}

.composer textarea {
  flex: 1;
  min-height: 48px;
  max-height: 160px;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  resize: none;
  outline: none;
  font-size: 14.5px;
  line-height: 1.45;
  transition: border-color .15s, box-shadow .15s;
}
.composer textarea:focus {
  border-color: #33446b;
  box-shadow: 0 0 0 3px rgba(79, 110, 247, .12);
}
.composer textarea::placeholder { color: #66708a; }

.send-button {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-size: 19px;
  transition: opacity .15s, transform .08s;
}
.send-button:hover { opacity: .92; }
.send-button:active { transform: translateY(1px); }
.send-button:disabled { opacity: .45; cursor: default; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  max-width: min(90vw, 460px);
  padding: 11px 16px;
  border: 1px solid rgba(255, 138, 128, .35);
  border-radius: 12px;
  background: #241519;
  color: #ffd7d3;
  font-size: 13px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  z-index: 40;
}

/* скроллбары */

.messages::-webkit-scrollbar, .conversation-list::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb, .conversation-list::-webkit-scrollbar-thumb {
  background: #232c3e;
  border-radius: 8px;
}
.messages::-webkit-scrollbar-track, .conversation-list::-webkit-scrollbar-track { background: transparent; }

/* мобильная версия */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(82vw, 320px);
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 24px 0 60px rgba(0, 0, 0, .55);
  }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0, 0, 0, .45);
  }

  .menu-button { display: grid; }
  .messages { padding: 18px 12px 8px; }
  .composer { padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
  .bubble { max-width: 92%; font-size: 14px; }
  .topbar { padding: 10px 12px; }
}
