/* ============================================================
   Чат с ИИ — layout поверх общей темы style.css
   ============================================================ */

.chat-app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* SVG-иконки вместо эмодзи */
.icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  vertical-align: -2px;
}
.icon.big { width: 34px; height: 34px; }
.spin { display: inline-block; animation: starSpin 1.6s linear infinite; }

/* ---------- sidebar ---------- */

.chat-sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 8px;
  transition: width 0.28s var(--ease), padding 0.28s var(--ease), transform 0.28s var(--ease);
  overflow: hidden;
}

/* свёрнутый сайдбар: плашка с чатами прячется, наверху появляется кнопка */
.chat-app.collapsed .chat-sidebar {
  width: 0;
  padding: 12px 0;
  border-right: none;
}

.sidebar-head {
  padding: 2px 4px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-soft);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.15s var(--ease);
}
.back-link:hover { color: var(--accent); }

.new-chat-btn {
  appearance: none;
  font: inherit;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-weight: 600;
  transition: background 0.18s var(--ease), transform 0.12s var(--ease);
}
.new-chat-btn:hover { background: rgba(217, 119, 87, 0.2); }
.new-chat-btn:active { transform: scale(0.98); }

.chat-list { flex: 1; overflow-y: auto; margin: 4px -4px 0; padding: 0 4px; }

.chat-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-soft);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
  animation: itemIn 0.22s var(--ease);
}
@keyframes itemIn { from { opacity: 0; transform: translateY(3px); } }
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-hover); color: var(--text); }
.chat-item .ci-mode { width: 13px; height: 13px; color: var(--amber); }
.chat-item .ci-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}
.chat-item .ci-vis { width: 12px; height: 12px; opacity: 0.6; }
.chat-item .ci-here {
  font-size: 10px;
  font-weight: 600;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-item .ci-del {
  appearance: none;
  border: none;
  background: none;
  color: var(--text-faint);
  width: 18px; height: 18px;
  border-radius: 4px;
  cursor: pointer;
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.chat-item .ci-del .icon { width: 11px; height: 11px; }
.chat-item:hover .ci-del { display: inline-flex; }
.chat-item .ci-del:hover { background: var(--red-soft); color: var(--red); }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }

.key-row { display: flex; gap: 6px; }
.key-row select {
  flex: 1;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 12px;
  padding: 6px 8px;
}

.allowance { margin-top: 7px; }
.allowance-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--bg-inset);
  overflow: hidden;
}
.allowance-fill {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: var(--green);
  transition: width 0.4s var(--ease), background 0.4s var(--ease);
}
.allowance-fill.warn { background: var(--amber); }
.allowance-fill.low { background: var(--red); }
.allowance-text { font-size: 11px; color: var(--text-faint); margin-top: 5px; line-height: 1.45; }

/* настройки слева снизу + ник */
.sidebar-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.settings-btn {
  appearance: none;
  font: inherit;
  font-size: 12.5px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  transition: background 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease);
}
.settings-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }
.settings-btn .icon { transition: transform 0.4s var(--ease); }
.settings-btn:hover .icon { transform: rotate(60deg); }

.sidebar-user {
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- main pane ---------- */

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}
.burger { display: none; }
.chat-title-wrap { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-title {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
}
.chat-vis-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--bg-inset);
  color: var(--text-faint);
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chat-vis-badge .icon { width: 11px; height: 11px; }

/* «кто сейчас в чате» в топбаре */
.chat-here {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid transparent;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
  animation: fadeIn 0.25s var(--ease);
}
.chat-here .icon { width: 11px; height: 11px; }

/* кнопки-действия справа сверху: иконка + подпись, всё читаемо */
.chat-topbar-side { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.top-act {
  appearance: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  transition: background 0.18s var(--ease), color 0.18s var(--ease),
              border-color 0.18s var(--ease), transform 0.12s var(--ease);
}
.top-act:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }
.top-act:active { transform: scale(0.97); }
.top-act .icon { width: 14px; height: 14px; }
.top-act#newProjectBtn:hover { color: var(--amber); border-color: var(--amber); }
.top-act#anonChatBtn:hover { color: var(--accent); border-color: var(--accent-border); }
.top-act.danger:hover { color: var(--red); border-color: var(--red); background: var(--red-soft); }
.top-act.on { color: var(--accent); border-color: var(--accent-border); background: var(--accent-soft); }
.expand-btn { animation: fadeIn 0.25s var(--ease); }

/* ---------- messages ---------- */

.messages-scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.messages { max-width: 780px; margin: 0 auto; padding: 24px 20px 12px; }

.chat-empty { text-align: center; padding: 90px 20px; color: var(--text-faint); animation: fadeIn 0.3s var(--ease); }
.chat-empty-mark { font-size: 42px; color: var(--accent); margin-bottom: 14px; }
.chat-empty h2 { font-family: var(--serif); color: var(--text-soft); margin-bottom: 6px; }

.msg { display: flex; gap: 12px; margin-bottom: 22px; animation: msgIn 0.25s var(--ease); }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
.msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
  margin-top: 2px;
}
.msg.user .msg-avatar { background: var(--bg-hover); color: var(--text-soft); }
.msg.assistant .msg-avatar { background: var(--accent-soft); color: var(--accent); }

.msg-body { flex: 1; min-width: 0; }
.msg-meta { font-size: 12px; color: var(--text-faint); margin-bottom: 4px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.msg-author { font-weight: 600; color: var(--text-soft); }
.msg.assistant .msg-author { color: var(--accent); }
.msg-think { font-style: italic; }

.msg-content { line-height: 1.65; word-wrap: break-word; overflow-wrap: break-word; white-space: pre-wrap; }
.msg-content code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
.msg-content pre {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
  white-space: pre;
}
.msg-content pre code { background: none; border: none; padding: 0; }
.msg-content img.msg-image {
  max-width: 320px;
  max-height: 320px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
  margin: 6px 0;
  cursor: zoom-in;
  transition: transform 0.18s var(--ease);
}
.msg-content img.msg-image:hover { transform: scale(1.015); }

/* streaming cursor */
.msg-content .stream-cursor {
  display: inline-block;
  width: 7px; height: 15px;
  background: var(--accent);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: cursorBlink 0.9s steps(2) infinite;
}
@keyframes cursorBlink { 50% { opacity: 0; } }

/* thinking line: ✻ Вынашивает мысль… 8s */
.thinking-row { display: flex; gap: 12px; margin-bottom: 22px; animation: msgIn 0.25s var(--ease); }
.thinking-inner {
  display: flex; align-items: baseline; gap: 8px;
  color: var(--accent);
  font-size: 13.5px;
}
.thinking-star { display: inline-block; animation: starSpin 1.6s linear infinite; transform-origin: 50% 52%; }
@keyframes starSpin { to { transform: rotate(360deg); } }
.thinking-verb { font-style: italic; }
.thinking-secs { color: var(--text-faint); font-family: var(--mono); font-size: 12px; }

/* ---------- typing indicator ---------- */

.typing-line {
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
  padding: 0 20px 4px;
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  animation: fadeIn 0.2s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } }

/* ---------- composer ---------- */

.composer-wrap { max-width: 780px; margin: 0 auto; width: 100%; padding: 6px 20px 18px; }

.attach-previews { display: flex; gap: 8px; padding-bottom: 8px; flex-wrap: wrap; }
.attach-preview { position: relative; animation: msgIn 0.2s var(--ease); }
.attach-preview img {
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
}
.attach-preview .rm {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  border: none;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.attach-preview.file {
  display: flex; align-items: center; gap: 6px;
  max-width: 200px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-hover);
  font-size: 12px;
}
.attach-preview.file .icon { width: 15px; height: 15px; flex-shrink: 0; color: var(--text-faint); }
.attach-preview.file .ap-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 8px 10px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.composer:focus-within {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  max-height: 180px;
  padding: 4px 2px;
  transition: height 0.12s var(--ease);
}
.attach-btn, .send-btn {
  appearance: none;
  border: none;
  width: 32px; height: 32px;
  border-radius: 9px;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s var(--ease), opacity 0.18s var(--ease), transform 0.12s var(--ease);
}
.attach-btn .icon, .send-btn .icon { width: 16px; height: 16px; }
.attach-btn { background: none; color: var(--text-faint); }
.attach-btn:hover { background: var(--bg-hover); color: var(--text-soft); }
.send-btn { background: var(--accent); color: #fff; }
.send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* one-off (одноразовый) mode tint */
.chat-app.anon .chat-topbar { background: rgba(125, 110, 155, 0.08); }

/* ---------- модалки: память · скиллы, настройки ---------- */

.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 95;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn 0.18s var(--ease);
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: min(520px, 100%);
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  animation: modalIn 0.22s var(--ease);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.modal-body {
  padding: 14px 16px 18px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-body .field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  margin-top: 6px;
}
.modal-body textarea, .modal-body input[type="text"] {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  resize: vertical;
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.modal-body textarea:focus, .modal-body input[type="text"]:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-hint { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; }

.skills-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.skill-chip {
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 18px;
  border: 1px solid var(--border);
  color: var(--text-soft);
  cursor: pointer;
  user-select: none;
  transition: background 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease);
}
.skill-chip input { display: none; }
.skill-chip:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.skill-chip.on { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); font-weight: 500; }

.my-requests { display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow-y: auto; }
.req-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  border: 1px solid var(--border);
}
.req-text { flex: 1; font-size: 12px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tg-block { display: flex; flex-direction: column; gap: 8px; }
.tg-status { font-size: 12.5px; color: var(--text-faint); }
.tg-status.ok { color: var(--green); }
.tg-row { display: flex; gap: 6px; }
.tg-row input { flex: 1; }

/* ---------- project mode ---------- */

.project-panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.pp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.pp-title { font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.pp-title .icon { color: var(--amber); }
.pp-download { font-size: 12px; padding: 5px 10px; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.pp-download .icon { width: 13px; height: 13px; }

.pp-status {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--amber);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 7px;
}
.pp-status .thinking-star { color: var(--amber); }

.pp-files { flex: 1; overflow-y: auto; padding: 8px; }
.pp-empty { color: var(--text-faint); font-size: 12px; padding: 20px 10px; text-align: center; }

.pp-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-soft);
  transition: background 0.15s var(--ease);
  animation: itemIn 0.2s var(--ease);
}
.pp-file:hover { background: var(--bg-hover); }
.pp-file .ppf-icon { flex-shrink: 0; width: 13px; height: 13px; }
.pp-file .ppf-path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.pp-file .ppf-size { color: var(--text-faint); font-size: 11px; flex-shrink: 0; }
.pp-file.fresh { animation: fileFlash 1.2s var(--ease); }
@keyframes fileFlash { 0% { background: var(--accent-soft); } 100% { background: none; } }

/* карточка файла в сообщении вместо простыни кода */
.file-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  margin: 5px 0;
  cursor: pointer;
  font-size: 12.5px;
  transition: border-color 0.18s var(--ease), transform 0.12s var(--ease);
  max-width: 100%;
}
.file-card:hover { border-color: var(--accent-border); transform: translateY(-1px); }
.file-card .fc-icon { width: 13px; height: 13px; color: var(--text-faint); }
.file-card .fc-name { font-family: var(--mono); color: var(--accent); overflow: hidden; text-overflow: ellipsis; }
.file-card .fc-lines { color: var(--text-faint); font-size: 11px; flex-shrink: 0; }
.file-card.deleted .fc-name { text-decoration: line-through; color: var(--red); }

/* project preview */
.pv-card { width: min(1100px, 100%); height: 88vh; }
.pv-frame {
  flex: 1;
  border: none;
  background: #fff;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* file viewer overlay */
.file-viewer {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn 0.18s var(--ease);
}
.fv-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: min(860px, 100%);
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  animation: modalIn 0.22s var(--ease);
}
.fv-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.fv-name { flex: 1; font-size: 13px; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fv-head a { text-decoration: none; }
.fv-body {
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
}

@media (max-width: 1100px) {
  .project-panel {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 60;
    transform: translateX(100%);
    transition: transform 0.28s var(--ease);
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  .project-panel.open { transform: translateX(0); }
  .top-act span { display: none; }        /* на узких экранах — только иконки */
  .top-act { padding: 6px 9px; }
}

/* ---------- login overlay ---------- */

.login-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  text-align: center;
  padding: 40px;
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}
.login-card h2 { font-family: var(--serif); }
.login-card p { color: var(--text-faint); }

/* ---------- mobile ---------- */

@media (max-width: 760px) {
  .chat-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 264px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.28s var(--ease);
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  .chat-sidebar.open { transform: translateX(0); }
  .chat-app.collapsed .chat-sidebar { width: 264px; padding: 12px; }
  .burger { display: inline-flex; }
  .expand-btn { display: none !important; }
  .msg-content img.msg-image { max-width: 100%; }
  .chat-here { display: none; }
}
