/* ─────────── ROOT / RESET ─────────── */
:root {
  --bg:           #0a0a0a;
  --bg-sidebar:   #141414;
  --bg-elev:      #1a1a1a;
  --bg-input:     #1f1f1f;
  --bg-hover:     #222;
  --bg-active:    #2a2a2a;
  --bd:           #2a2a2a;
  --bd-strong:    #3a3a3a;
  --tx:           #ededed;
  --tx-muted:     #999;
  --tx-faint:     #6a6a6a;
  --accent:       #aaa;
  --danger:       #b94a4a;
  --ok:           #4a9d6e;
  --radius:       8px;
  --sidebar-w:    280px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--tx);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--tx); text-decoration: none; }
a:hover { color: #fff; }
button { font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; background: transparent; border: 0; outline: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* ─────────── APP LAYOUT ─────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  width: 100vw;
}

/* ─────────── SIDEBAR ─────────── */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--bd);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.sb-head {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--bd);
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 16px; letter-spacing: 0.4px;
  margin-bottom: 12px;
  color: var(--tx);
}
.sb-brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.sb-newchat {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px;
  border: 1px solid var(--bd-strong);
  border-radius: var(--radius);
  color: var(--tx);
  background: transparent;
  transition: background 0.12s, border-color 0.12s;
  font-size: 14px;
}
.sb-newchat:hover { background: var(--bg-hover); border-color: #555; }
.sb-newchat .plus { font-size: 18px; line-height: 1; }

.sb-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 16px;
}
.sb-list-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--tx-faint);
  padding: 12px 8px 6px;
}
.sb-conv {
  display: block;
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: 6px;
  color: var(--tx);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s;
  position: relative;
}
.sb-conv:hover { background: var(--bg-hover); }
.sb-conv.active { background: var(--bg-active); }
.sb-conv-title { display: block; }
.sb-conv-meta {
  font-size: 11px;
  color: var(--tx-faint);
  margin-top: 2px;
}
.sb-empty {
  padding: 20px 12px;
  font-size: 13px;
  color: var(--tx-muted);
  text-align: center;
}

/* ─────────── SIDEBAR FOOTER (account) ─────────── */
.sb-foot {
  border-top: 1px solid var(--bd);
  padding: 10px;
  position: relative;
}
.sb-account {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.sb-account:hover { background: var(--bg-hover); }
.sb-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bd-strong);
  color: var(--tx);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
  flex-shrink: 0;
}
.sb-account-name {
  flex: 1;
  font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-account-arrow { color: var(--tx-faint); font-size: 12px; }

.sb-menu {
  position: absolute;
  bottom: calc(100% + 0px);
  left: 10px; right: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 6px;
  display: none;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.3);
}
.sb-menu.open { display: block; }
.sb-menu a, .sb-menu button {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--tx);
  border-radius: 5px;
  width: 100%;
  text-align: left;
}
.sb-menu a:hover, .sb-menu button:hover { background: var(--bg-hover); }
.sb-menu hr { border: 0; border-top: 1px solid var(--bd); margin: 4px 0; }

/* ─────────── MAIN ─────────── */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}
.main-head {
  padding: 14px 24px;
  border-bottom: 1px solid var(--bd);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.main-title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.main-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  color: var(--tx-muted);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--tx); }
.icon-btn.danger:hover { color: var(--danger); }

/* ─────────── CHAT ─────────── */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-stream {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
}
.chat-stream-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.msg {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  background: var(--bd-strong);
  color: var(--tx);
  margin-top: 2px;
}
.msg-avatar.user { background: #2a3a4a; }
.msg-avatar.assistant { background: #2a2a2a; }
.msg-body { flex: 1; min-width: 0; }
.msg-role {
  font-size: 12px;
  color: var(--tx-faint);
  margin-bottom: 4px;
}
.msg-content {
  font-size: 15px;
  color: var(--tx);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-content code {
  background: var(--bg-elev);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.msg-content pre {
  background: var(--bg-elev);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-content pre code { background: transparent; padding: 0; }

.msg-typing .msg-content {
  display: inline-flex; gap: 4px; align-items: center;
}
.msg-typing .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--tx-muted);
  animation: typ 1.4s infinite;
}
.msg-typing .dot:nth-child(2) { animation-delay: 0.18s; }
.msg-typing .dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes typ { 0%, 60%, 100% { opacity: 0.3 } 30% { opacity: 1 } }

/* ─────────── EMPTY STATE ─────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
}
.empty-state h1 {
  font-size: 28px;
  font-weight: 500;
  margin-bottom: 12px;
  color: var(--tx);
}
.empty-state p {
  color: var(--tx-muted);
  font-size: 15px;
  max-width: 440px;
  margin-bottom: 24px;
}

/* ─────────── INPUT ─────────── */
.composer {
  flex-shrink: 0;
  padding: 16px 24px 24px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer-inner {
  max-width: 900px;
  margin: 0 auto;
}
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--bd);
  border-radius: 12px;
  padding: 10px 12px;
  transition: border-color 0.12s;
}
.composer-box:focus-within { border-color: var(--bd-strong); }
.composer-box textarea {
  flex: 1;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  max-height: 200px;
  min-height: 24px;
  background: transparent;
  color: var(--tx);
  padding: 4px 0;
}
.composer-box textarea::placeholder { color: var(--tx-muted); }
.composer-action {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  color: var(--tx-muted);
  flex-shrink: 0;
}
.composer-action:hover { background: var(--bg-hover); color: var(--tx); }
.composer-send {
  width: 32px; height: 32px;
  border-radius: 6px;
  background: var(--tx);
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s;
}
.composer-send:disabled { background: var(--bd-strong); color: var(--tx-faint); cursor: not-allowed; }
.composer-send:not(:disabled):hover { background: #fff; }
.composer-help {
  font-size: 11px;
  color: var(--tx-faint);
  text-align: center;
  margin-top: 8px;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 900px;
  margin: 0 auto 12px;
  padding: 0 24px;
}
.qr-btn {
  padding: 5px 12px;
  border: 1px solid var(--bd);
  border-radius: 14px;
  font-size: 12px;
  color: var(--tx-muted);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.qr-btn:hover { background: var(--bg-hover); color: var(--tx); border-color: var(--bd-strong); }

/* ─────────── FLASH MESSAGES ─────────── */
.flash-wrap {
  position: fixed; top: 16px; right: 16px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 360px;
}
.flash {
  background: var(--bg-elev);
  border: 1px solid var(--bd-strong);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  display: flex; align-items: center; gap: 10px;
  animation: flash-in 0.2s ease-out;
}
.flash.success { border-left: 3px solid var(--ok); }
.flash.danger, .flash.error { border-left: 3px solid var(--danger); }
.flash.warning { border-left: 3px solid #b88c4a; }
.flash.info { border-left: 3px solid #4a7db8; }
.flash-close { color: var(--tx-faint); margin-left: auto; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ─────────── AUTH FORMS (login/register, без сайдбара) ─────────── */
.simple-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
  overflow-y: auto;
}
.auth-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 400px;
}
.auth-card h1 {
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 6px;
}
.auth-card .sub {
  color: var(--tx-muted);
  font-size: 14px;
  margin-bottom: 24px;
}
.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--tx-muted);
  margin-bottom: 6px;
}
.field input[type=text], .field input[type=email], .field input[type=password] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--bd);
  border-radius: 6px;
  color: var(--tx);
  font-size: 14px;
}
.field input:focus { border-color: var(--bd-strong); }
.field-check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--tx-muted); margin-bottom: 16px; }
.btn {
  padding: 10px 16px;
  background: var(--tx);
  color: var(--bg);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.12s;
}
.btn:hover { background: #fff; }
.btn.full { width: 100%; justify-content: center; }
.btn-secondary {
  background: transparent;
  color: var(--tx);
  border: 1px solid var(--bd-strong);
}
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger {
  background: var(--danger); color: #fff;
}
.btn-danger:hover { background: #c95a5a; }
.auth-foot {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--tx-muted);
}
.auth-foot a { color: var(--tx); border-bottom: 1px solid var(--bd-strong); }
.auth-foot a:hover { border-color: var(--tx); }

/* ─────────── SETTINGS PAGE ─────────── */
.settings-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 24px;
  overflow-y: auto;
  height: 100vh;
}
.settings-wrap h1 { font-size: 22px; margin-bottom: 18px; font-weight: 500; }
.settings-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
}
.settings-card h2 { font-size: 15px; font-weight: 500; margin-bottom: 14px; color: var(--tx-muted); }

/* ─────────── MODAL ─────────── */
.modal-back {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--bg-sidebar);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%; max-width: 420px;
}
.modal h2 { font-size: 16px; margin-bottom: 8px; font-weight: 500; }
.modal p { color: var(--tx-muted); margin-bottom: 16px; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ─────────── RESPONSIVE ─────────── */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 80%; max-width: 320px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .sidebar.open { transform: translateX(0); }
  .main-head { padding-left: 56px; }
  .menu-toggle { display: flex !important; }
}
.menu-toggle {
  display: none;
  position: absolute; left: 14px; top: 11px;
  width: 32px; height: 32px;
  align-items: center; justify-content: center;
  z-index: 60;
  color: var(--tx);
}

/* ─────────── MARKDOWN inside .msg-content ─────────── */
/* Очень плотный rhythm — как в Claude/ChatGPT: списки без зазоров,
   параграф вплотную к списку под ним. */
.msg-content > * { margin: 0; }
.msg-content > * + * { margin-top: 4px; }
.msg-content > p + ul, .msg-content > p + ol,
.msg-content > h1 + ul, .msg-content > h1 + ol,
.msg-content > h2 + ul, .msg-content > h2 + ol,
.msg-content > h3 + ul, .msg-content > h3 + ol,
.msg-content > h4 + ul, .msg-content > h4 + ol { margin-top: 2px; }
.msg-content > ul + p, .msg-content > ol + p,
.msg-content > p  + p { margin-top: 8px; }

.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--tx);
}
.msg-content h1 { font-size: 22px; }
.msg-content h2 { font-size: 19px; }
.msg-content h3 { font-size: 17px; }
.msg-content h4 { font-size: 15px; }

.msg-content p { line-height: 1.55; }
.msg-content strong { font-weight: 600; color: #fff; }
.msg-content em { font-style: italic; }
.msg-content a {
  color: #9ec1ff;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg-content a:hover { color: #c0d6ff; }

.msg-content ul, .msg-content ol { padding-left: 22px; }
.msg-content ul { list-style: disc; }
.msg-content ol { list-style: decimal; }
.msg-content ul li, .msg-content ol li { margin: 0; line-height: 1.55; }
.msg-content ul li + li, .msg-content ol li + li { margin-top: 0; }
.msg-content li > p { margin: 0; }

.msg-content blockquote {
  border-left: 3px solid var(--bd-strong);
  padding: 4px 12px;
  color: var(--tx-muted);
}
/* Вложенные списки (внутри <li>) — без зазора сверху */
.msg-content li > ul, .msg-content li > ol {
  margin-top: 2px;
  padding-left: 22px;
}
.msg-content li > ul li, .msg-content li > ol li { margin: 0; }
