* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #f7f7f8;
  --panel: #202123;
  --panel-hover: #2b2c2f;
  --accent: #10a37f;
  --accent-hover: #0e8f70;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e7eb;
  --user-bubble: #dcf3ec;
}
html, body { height: 100%; }
body {
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ---------- Логин ---------- */
.login-body { display: flex; align-items: center; justify-content: center; }
.login-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 36px 32px; width: 340px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.06);
}
.login-card h1 { text-align: center; font-size: 28px; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 8px; }
.login-card input {
  padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px;
}
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-card button {
  padding: 11px; background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  font-size: 15px; cursor: pointer; margin-top: 4px;
}
.login-card button:hover { background: var(--accent-hover); }
.login-error {
  background: #fde8e8; color: #b42318; border-radius: 8px; padding: 9px 12px; font-size: 14px;
}

/* ---------- Каркас ---------- */
.layout { display: flex; height: 100vh; }
.sidebar {
  width: 260px; min-width: 260px; background: var(--panel); color: #ececf1;
  display: flex; flex-direction: column; padding: 10px;
}
.btn-new {
  padding: 11px; background: transparent; color: #ececf1; border: 1px solid #565869;
  border-radius: 8px; cursor: pointer; font-size: 14px; text-align: left;
}
.btn-new:hover { background: var(--panel-hover); }
.chat-list { flex: 1; overflow-y: auto; margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 8px;
  cursor: pointer; font-size: 14px; color: #ececf1;
}
.chat-item:hover { background: var(--panel-hover); }
.chat-item.active { background: #343541; }
.chat-item .title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .actions { display: none; gap: 2px; }
.chat-item:hover .actions { display: flex; }
.chat-item .actions button {
  background: none; border: 0; color: #9ca3af; cursor: pointer; font-size: 13px; padding: 2px 4px;
}
.chat-item .actions button:hover { color: #fff; }
.sidebar-footer { border-top: 1px solid #565869; padding-top: 8px; display: flex; flex-direction: column; gap: 2px; }
.btn-ghost {
  width: 100%; text-align: left; padding: 9px 10px; background: none; border: 0;
  color: #ececf1; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn-ghost:hover { background: var(--panel-hover); }

/* ---------- Чат ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 24px 0; }
.empty-hint { text-align: center; color: var(--muted); margin-top: 18vh; padding: 0 20px; }
.empty-hint h2 { font-size: 32px; color: var(--text); margin-bottom: 10px; }
.msg { padding: 6px 20px; display: flex; }
.msg .bubble {
  max-width: 780px; margin: 0 auto; width: 100%; padding: 12px 16px; border-radius: 12px;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .bubble { background: var(--user-bubble); }
.msg.assistant .bubble { background: #fff; border: 1px solid var(--border); }
.msg .bubble code {
  background: #f0f0f2; border-radius: 4px; padding: 1px 5px;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.msg .bubble pre {
  background: #0d1117; color: #e6edf3; padding: 12px 14px; border-radius: 8px;
  overflow-x: auto; margin: 8px 0;
}
.msg .bubble pre code { background: none; color: inherit; padding: 0; }
.msg.memory-note .bubble {
  background: #fef9e7; border: 1px solid #f7e8b0; color: #7a6215; font-size: 13.5px;
}
.typing { color: var(--muted); animation: blink 1.1s infinite; }
@keyframes blink { 50% { opacity: .35; } }

.composer {
  display: flex; gap: 10px; padding: 14px 20px 22px; max-width: 820px; margin: 0 auto; width: 100%;
}
.composer textarea {
  flex: 1; resize: none; padding: 13px 14px; border: 1px solid var(--border); border-radius: 12px;
  font: inherit; max-height: 200px; box-shadow: 0 2px 10px rgba(0,0,0,.04);
}
.composer textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.composer button {
  width: 48px; border: 0; border-radius: 12px; background: var(--accent); color: #fff;
  font-size: 17px; cursor: pointer;
}
.composer button:disabled { background: #c7cdd4; cursor: default; }
.composer button:not(:disabled):hover { background: var(--accent-hover); }

/* ---------- Модалка памяти ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: #fff; border-radius: 14px; width: 560px; max-width: calc(100vw - 40px);
  max-height: 80vh; display: flex; flex-direction: column; padding: 20px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head .btn-ghost { width: auto; color: var(--muted); }
.modal-head .btn-ghost:hover { background: #f0f0f2; color: var(--text); }
.memory-add { display: flex; gap: 8px; margin-bottom: 14px; }
.memory-add input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font: inherit;
}
.memory-add button {
  padding: 10px 16px; background: var(--accent); color: #fff; border: 0; border-radius: 8px; cursor: pointer;
}
.memory-list { list-style: none; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.memory-list li {
  display: flex; align-items: baseline; gap: 10px; padding: 9px 12px;
  background: var(--bg); border-radius: 8px; font-size: 14px;
}
.memory-list li .fact { flex: 1; }
.memory-list li .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.memory-list li button { background: none; border: 0; color: #b42318; cursor: pointer; }
.memory-empty { color: var(--muted); text-align: center; padding: 20px; }

@media (max-width: 720px) {
  .sidebar { position: fixed; z-index: 5; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
}
