/* my_gpt — оформление интерфейса.
   Цвета заданы переменными: тёмная тема по умолчанию, светлая — если так настроена система. */

:root {
  color-scheme: dark;
  --bg: #212121;
  --bg-sidebar: #171717;
  --bg-hover: #2a2a2a;
  --bg-active: #2f2f2f;
  --bg-bubble: #303030;
  --bg-composer: #303030;
  --bg-menu: #353535;
  --bg-code: #0d0d0d;
  --bg-code-header: #2f2f2f;
  --text: #ececec;
  --text-2: #b4b4b4;
  --text-3: #8f8f8f;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #ffffff;
  --accent-text: #000000;
  --link: #7ab7ff;
  --danger: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --focus: #3b82f6;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --composer-shadow: 0 0 0 1px var(--border);
  --sidebar-w: 260px;
  --content-w: 768px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-family: ui-sans-serif, -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #ffffff;
    --bg-sidebar: #f9f9f9;
    --bg-hover: #ececec;
    --bg-active: #e3e3e3;
    --bg-bubble: #f4f4f4;
    --bg-composer: #ffffff;
    --bg-menu: #ffffff;
    --text: #0d0d0d;
    --text-2: #5d5d5d;
    --text-3: #8f8f8f;
    --border: rgba(0, 0, 0, 0.1);
    --accent: #000000;
    --accent-text: #ffffff;
    --link: #2563eb;
    --danger: #dc2626;
    --danger-bg: rgba(220, 38, 38, 0.08);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    --composer-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1), 0 4px 16px rgba(0, 0, 0, 0.06);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { display: block; flex-shrink: 0; }

.app { display: flex; height: 100dvh; }

/* ---------- Боковая панель ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 2px;
  transition: margin-left 0.2s ease;
}
.app.sidebar-collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
.sidebar-top { display: flex; justify-content: space-between; align-items: center; height: 44px; padding: 0 2px; margin-bottom: 4px; }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  text-align: left;
}
.sidebar-item:hover { background: var(--bg-hover); }

.search-box {
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--text-2);
}
.search-box:focus-within { background: var(--bg-hover); }
.search-box input {
  flex: 1; min-width: 0;
  background: none; border: 0; outline: none;
  padding: 8px 0;
  font-size: 14px;
}
.search-box input::placeholder { color: var(--text-2); }

.chat-list { flex: 1; overflow-y: auto; margin-top: 8px; }
.chat-group-title { font-size: 12px; font-weight: 600; color: var(--text-3); padding: 14px 10px 6px; }
.chat-item {
  display: flex; align-items: center;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
}
.chat-item:hover, .chat-item.menu-open { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-item .title { flex: 1; min-width: 0; padding: 8px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .dots {
  width: 28px; height: 28px; margin-right: 4px;
  border-radius: 6px;
  display: grid; place-items: center;
  color: var(--text-2);
  opacity: 0;
}
.chat-item:hover .dots, .chat-item.active .dots, .chat-item.menu-open .dots { opacity: 1; }
.chat-item .dots:hover { color: var(--text); }
.chat-item input.rename {
  flex: 1; min-width: 0;
  margin: 3px; padding: 5px 7px;
  border-radius: 6px;
  border: 1px solid var(--focus);
  background: var(--bg);
  outline: none;
  font-size: 14px;
}
.search-result { display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text); font-size: 14px; }
.search-result:hover { background: var(--bg-hover); }
.search-result .snippet {
  font-size: 12px; color: var(--text-2); margin-top: 2px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.search-result mark { background: rgba(250, 204, 21, 0.35); color: inherit; border-radius: 2px; }
.list-empty { padding: 10px; font-size: 13px; color: var(--text-3); }

.sidebar-bottom { position: relative; border-top: 1px solid var(--border); padding-top: 8px; }
.account-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 8px; font-size: 14px; text-align: left; }
.account-btn:hover { background: var(--bg-hover); }
.account-btn #account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #5b6ee1; color: #fff;
  display: grid; place-items: center;
  font-weight: 600; font-size: 13px;
  flex-shrink: 0;
}

/* ---------- Всплывающие меню ---------- */
.menu {
  background: var(--bg-menu);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 180px;
  z-index: 50;
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; font-size: 14px; text-align: left; }
.menu button:hover { background: var(--bg-hover); }
.menu button.danger { color: var(--danger); }
.menu.floating { position: fixed; }
#account-menu { position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; }

/* ---------- Основная область ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 52px; display: flex; align-items: center; gap: 4px; padding: 0 8px; flex-shrink: 0; }
.topbar .collapsed-only { display: none; }
.app.sidebar-collapsed .topbar .collapsed-only { display: grid; }
.model-picker { position: relative; min-width: 0; }
.model-btn { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 8px; min-width: 0; color: var(--text); }
.model-btn:hover { background: var(--bg-hover); }
.model-btn svg { color: var(--text-2); }
.model-name { font-size: 18px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-menu { position: absolute; top: calc(100% + 4px); left: 0; min-width: 260px; }
.model-menu button { justify-content: space-between; }
.model-menu .meta { display: block; font-size: 12px; color: var(--text-2); }
.model-menu .check { color: var(--text); }

.scroll { flex: 1; overflow-y: auto; }
.messages {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 16px 24px 32px;
  display: flex; flex-direction: column; gap: 28px;
}

.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .msg-actions { margin-left: 0; margin-right: -4px; }
.msg.user:hover .msg-actions { opacity: 1; }
.msg.user.editing { align-items: stretch; }
.edit-box { background: var(--bg-bubble); border-radius: 22px; padding: 12px 16px; }
.edit-box textarea {
  width: 100%;
  border: 0; outline: none; background: none; resize: none;
  font-size: 16px; line-height: 1.5;
  max-height: 300px;
}
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.msg.user .bubble {
  max-width: 70%;
  background: var(--bg-bubble);
  padding: 10px 18px;
  border-radius: 22px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-actions { display: flex; gap: 2px; margin-top: 4px; margin-left: -8px; opacity: 0; transition: opacity 0.15s; }
.msg.assistant:hover .msg-actions, .msg.assistant:last-child .msg-actions { opacity: 1; }
.msg.generating .msg-actions { display: none; }
/* Пока модель отвечает, действия над сообщениями недоступны. */
.app.is-generating .msg-actions { visibility: hidden; }
.msg-actions .icon-btn { width: 32px; height: 32px; }
.msg.assistant:not(:last-child) .regen { display: none; }
.msg-error {
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 14px;
}

/* Индикатор генерации: пульсирующая точка */
.typing {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--text);
  vertical-align: middle;
  animation: pulse 1.2s ease-in-out infinite;
}
.typing-hint { margin-left: 10px; font-size: 14px; color: var(--text-2); vertical-align: middle; }
@keyframes pulse {
  0%, 100% { transform: scale(0.7); opacity: 0.5; }
  50% { transform: scale(1); opacity: 1; }
}

/* ---------- Markdown в ответах ---------- */
.markdown { overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 1em; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 1.4em 0 0.6em; line-height: 1.3; font-weight: 600; }
.markdown h1 { font-size: 1.5em; }
.markdown h2 { font-size: 1.3em; }
.markdown h3 { font-size: 1.15em; }
.markdown ul, .markdown ol { padding-left: 1.6em; margin: 0 0 1em; }
.markdown li { margin: 0.3em 0; }
.markdown li > p { margin: 0; }
.markdown a { color: var(--link); }
.markdown strong { font-weight: 600; }
.markdown blockquote { border-left: 3px solid var(--border); margin: 0 0 1em; padding-left: 1em; color: var(--text-2); }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.markdown table { border-collapse: collapse; margin: 0 0 1em; display: block; overflow-x: auto; font-size: 14px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
.markdown th { background: var(--bg-hover); font-weight: 600; }
.markdown :not(pre) > code {
  background: var(--bg-hover);
  padding: 0.15em 0.4em;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.875em;
}
.code-block { margin: 0 0 1em; border-radius: 12px; overflow: hidden; background: var(--bg-code); }
.code-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px;
  font-size: 12px;
  color: #b4b4b4;
  background: var(--bg-code-header);
}
.code-header button { display: flex; align-items: center; gap: 4px; font-size: 12px; color: inherit; }
.code-header button:hover { color: #fff; }
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code-block code {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
  color: #e6e6e6;
  background: none !important;
  padding: 0 !important;
}

/* ---------- Поле ввода ---------- */
.composer-wrap { position: relative; flex-shrink: 0; padding: 0 24px 8px; }
.composer-wrap > * { max-width: var(--content-w); margin-left: auto; margin-right: auto; }
.welcome { display: none; text-align: center; font-size: 28px; font-weight: 500; margin-top: 0; margin-bottom: 28px; }
.composer {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg-composer);
  border-radius: 28px;
  padding: 10px;
  box-shadow: var(--composer-shadow);
  transition: box-shadow 0.15s;
}
.composer.dragover { box-shadow: 0 0 0 2px var(--focus); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.attach-btn { flex-shrink: 0; border-radius: 50%; }

/* Вложения перед отправкой */
.attachments { display: flex; flex-wrap: wrap; gap: 10px; padding: 6px 6px 0; }
.attachment {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font-size: 13px;
  max-width: 220px;
}
.attachment.file { padding: 8px 14px 8px 10px; }
.attachment.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment.image img { width: 56px; height: 56px; object-fit: cover; border-radius: 11px; display: block; }
.attachment .remove-att {
  position: absolute; top: -7px; right: -7px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--text); color: var(--bg);
  display: grid; place-items: center;
}

/* Вложения в ленте */
.msg-attachments { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-bottom: 6px; max-width: 70%; }
.msg-attachments img { max-width: 240px; max-height: 240px; border-radius: 14px; display: block; object-fit: cover; cursor: zoom-in; }
.file-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bg-bubble);
  font-size: 13px;
  max-width: 260px;
}
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer textarea {
  flex: 1;
  margin-left: 4px;
  resize: none;
  border: 0; outline: none; background: none;
  max-height: 200px;
  line-height: 24px;
  padding: 6px 0;
  font-size: 16px;
}
.composer textarea::placeholder { color: var(--text-2); }
.send-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.3; cursor: default; }
.disclaimer { text-align: center; font-size: 12px; color: var(--text-2); margin-top: 8px; margin-bottom: 0; }

.scroll-down {
  position: absolute; top: -48px; left: 50%;
  transform: translateX(-50%);
  width: 36px; height: 36px; max-width: none;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: grid; place-items: center;
  color: var(--text);
}

/* Пустой чат: приветствие и поле ввода по центру экрана */
.main.empty .scroll { display: none; }
.main.empty .composer-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-bottom: 12vh; }
.main.empty .composer-wrap > * { width: 100%; }
.main.empty .welcome { display: block; }
.main.empty .scroll-down { display: none; }

/* ---------- Уведомления и диалоги ---------- */
.toast {
  position: fixed; top: 16px; left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #dc2626; color: #fff;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 100;
}
.toast.info { background: var(--bg-menu); color: var(--text); border: 1px solid var(--border); }

dialog {
  background: var(--bg-menu);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: min(460px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
dialog p { color: var(--text-2); margin: 0 0 20px; font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.btn { padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 500; border: 1px solid var(--border); }
.btn:hover { background: var(--bg-hover); }
a.btn { display: inline-block; color: var(--text); text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn-primary:hover { background: var(--accent); opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-danger { background: #ef4444; color: #fff; border-color: transparent; }
.btn-danger:hover { background: #dc2626; }

dialog.wide { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
dialog h3 { font-size: 14px; font-weight: 600; margin: 20px 0 10px; color: var(--text); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--text-2); flex: 1; min-width: 0; }
.field small { color: var(--text-3); }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { min-width: 130px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.field textarea { resize: vertical; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--focus); }
.hint { font-size: 12px !important; color: var(--text-3) !important; margin: 0 0 8px !important; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ok-text { color: #22c55e; font-size: 13px; }

.session-list { max-height: 50vh; overflow-y: auto; }

/* Память */
.memory-list { display: flex; flex-direction: column; gap: 6px; margin: 2px 0 10px; max-height: 200px; overflow-y: auto; }
.memory-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-hover);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.memory-item button { color: var(--text-3); flex-shrink: 0; }
.memory-item button:hover { color: var(--danger); }
.memory-input {
  flex: 1; min-width: 160px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.memory-input:focus { border-color: var(--focus); }
.web-check { margin-top: 16px; margin-bottom: 4px; }

/* Шаги инструментов в ответе: «Ищу в интернете…», «Читаю: …» */
.tool-steps { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.tool-step { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); min-width: 0; }
.tool-step .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-step .summary { color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-step.fail .summary { color: var(--danger); }
.tool-step.running .label {
  background: linear-gradient(90deg, var(--text-3) 0%, var(--text) 50%, var(--text-3) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.session-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.session-row .meta { color: var(--text-2); font-size: 12px; }
.session-row .agent { overflow-wrap: anywhere; }
.badge { font-size: 12px; color: #22c55e; white-space: nowrap; }
.badge.admin { color: #a78bfa; }
.badge.pending { color: #f59e0b; }
.auth-error.ok { color: #22c55e; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.check-field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); margin-bottom: 20px; white-space: nowrap; }
.new-user { align-items: flex-end; }
.new-user .btn { margin-bottom: 12px; }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.user-actions input {
  width: 150px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

/* ---------- Экран входа ---------- */
.auth-screen { height: 100dvh; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.auth-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { text-align: center; margin: 0; font-size: 30px; font-weight: 600; }
.auth-card p { text-align: center; margin: 0 0 12px; color: var(--text-2); }
.auth-card input {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  outline: none;
  font-size: 15px;
}
.auth-card input:focus { border-color: var(--focus); }
.auth-card .btn-primary { padding: 14px; font-size: 15px; }
.link-btn { color: var(--text-2); font-size: 14px; }
.link-btn:hover { color: var(--text); text-decoration: underline; }
.auth-error { color: var(--danger); font-size: 14px; text-align: center; }

/* ---------- Телефоны ---------- */
.backdrop { display: none; }
@media (max-width: 767px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    z-index: 40;
    width: min(280px, 85vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .app.sidebar-collapsed .sidebar { margin-left: 0; }
  .app.sidebar-open-mobile .sidebar { transform: none; }
  .app.sidebar-open-mobile .backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 30; }
  .topbar .collapsed-only { display: grid; }
  .messages { padding: 12px 16px 24px; }
  .composer-wrap { padding: 0 12px 8px; }
  .msg.user .bubble { max-width: 85%; }
  .welcome { font-size: 24px; }
}
