/* styles.css — GB_AI. Визуал в стиле gbmarketing.online:
   тёмно-зелёный фон, тёплое золото, кремовый текст, Manrope + Cormorant Garamond. */

:root {
  --bg: #0C1813;
  --band: #0A1510;
  --bg-soft: #0F1E17;
  --card: #12221A;
  --card-2: #0F1E17;
  --surface: #11201A;
  --menu-hover: #1A2F24;
  --line: #20372B;
  --line-2: #2D4A3A;
  --text: #F2ECDF;
  --muted: #B7B2A1;
  --muted-2: #8F8C7D;
  --accent: #D4A93E;
  --accent-hover: #E2B94F;
  --on-accent: #17130A;
  --ac-soft: rgba(212, 169, 62, .13);
  --ac-line: rgba(212, 169, 62, .45);
  --ok: #7BC99A;
  --warn: #E2B94F;
  --err: #E0707A;
  --err-soft: rgba(224, 112, 122, .07);
  --radius: 12px;
  --radius-sm: 10px;
  --header-bg: rgba(12, 24, 19, .94);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(900px 520px at 12% -12%, rgba(212, 169, 62, .10), transparent 62%),
    radial-gradient(760px 480px at 92% -6%, rgba(45, 74, 58, .45), transparent 58%),
    var(--bg);
}

#app { height: 100%; }

.hidden { display: none !important; }

.panel { height: 100%; }

/* ---------- экраны входа ---------- */

.panel.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px 26px;
}

.auth-card.wide { max-width: 590px; }

.logo {
  margin: 0 0 8px;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 700;
  font-size: 33px;
  line-height: 1.12;
  letter-spacing: .2px;
  color: var(--text);
}

.logo .ac { color: var(--accent); }

.logo.small {
  font-family: Manrope, system-ui, sans-serif;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: .01em;
  margin: 0;
}

.sub {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13.5px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 14px 0 6px;
}

input[type="email"],
input[type="password"],
input[type="text"],
textarea {
  width: 100%;
  background: var(--band);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font-size: 14.5px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input::placeholder, textarea::placeholder { color: var(--muted-2); }

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ac-soft);
}

textarea { resize: none; }

button {
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background .2s, border-color .2s, color .2s;
}

button.primary {
  width: 100%;
  min-height: 48px;
  margin-top: 18px;
  padding: 0 22px;
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.primary:disabled { opacity: .6; cursor: default; background: var(--accent); }

button.ghost {
  background: none;
  color: var(--text);
  border-color: var(--line-2);
  padding: 11px 16px;
  min-height: 44px;
}

button.ghost:hover { background: var(--menu-hover); border-color: var(--accent); }
button.ghost.full { width: 100%; }
button.small-btn { min-height: 36px; padding: 6px 12px; font-size: 13px; }

.link {
  display: block;
  margin-top: 12px;
  font-size: 13.5px;
  color: var(--accent);
  text-decoration: none;
}

.link:hover { color: var(--accent-hover); text-decoration: underline; }

.cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 18px 0 12px;
  min-height: 48px;
  padding: 0 22px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  color: var(--on-accent);
  text-decoration: none;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
}

.cta:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.hint { color: var(--muted); font-size: 13.5px; margin: 10px 0; }
.hint.small { font-size: 12.5px; color: var(--muted-2); }

.rules { color: var(--muted); font-size: 13.5px; padding-left: 20px; margin: 10px 0 4px; }
.rules li { margin: 8px 0; }
.rules a, .hint a { color: var(--accent); text-decoration: none; }
.rules a:hover, .hint a:hover { text-decoration: underline; }

/* каталог моделей на панели «Правила» */
.rules-title {
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin: 22px 0 0;
  font-weight: 600;
}

.model-catalog { margin-top: 4px; }

.model-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--card-2);
}

.model-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 10px 13px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.4;
}

.model-list li:first-child { border-top: 0; }
.model-list li > b { font-weight: 600; color: var(--text); }

.mc-off {
  display: inline-block;
  font-size: 10.5px;
  color: var(--err);
  border: 1px solid rgba(224, 112, 122, .5);
  border-radius: 999px;
  padding: 0 7px;
  margin-left: 7px;
  vertical-align: 1px;
}

.mc-caps { grid-column: 1; color: var(--muted-2); font-size: 11.5px; }

.mc-price {
  grid-column: 2;
  grid-row: 1;
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  text-align: right;
}

.mc-note { grid-column: 1 / -1; color: var(--muted-2); font-size: 11.5px; }

@media (max-width: 520px) {
  .model-list li { grid-template-columns: 1fr; }
  .mc-price { grid-column: 1; grid-row: auto; text-align: left; }
}

code {
  background: var(--ac-soft);
  color: var(--accent);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* инструкция «как получить ключ» */
.howto {
  counter-reset: step;
  list-style: none;
  padding: 0;
  margin: 14px 0 6px;
}

.howto li {
  counter-increment: step;
  position: relative;
  padding: 0 0 14px 40px;
  color: var(--muted);
  font-size: 13.5px;
}

.howto li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -2px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  background: var(--ac-soft);
  border: 1px solid var(--ac-line);
  border-radius: 50%;
}

.howto li + li::after {
  content: "";
  position: absolute;
  left: 13px;
  top: 28px;
  bottom: 4px;
  width: 1px;
  background: var(--line);
}

.howto li:last-child { padding-bottom: 4px; }
.howto li:last-child::after { display: none; }
.howto b { color: var(--text); font-weight: 700; }
.howto a { color: var(--accent); text-decoration: none; }
.howto a:hover { text-decoration: underline; }

.ico { display: block; }

.video-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 6px;
  padding: 16px;
  font-size: 12.5px;
  color: var(--muted-2);
  text-align: center;
  border: 1px dashed var(--ac-line);
  border-radius: var(--radius-sm);
  background: rgba(10, 21, 16, .5);
}

.video-slot .play { display: inline-flex; align-items: center; color: var(--accent); }

/* ---------- приложение ---------- */

.panel.app { display: flex; overflow: hidden; }

/* сайдбар */
.sidebar {
  width: 272px;
  flex: 0 0 272px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
  min-height: 0;
}

.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.side-top .ghost { min-height: 34px; padding: 4px 10px; }

.chat-list {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 13.5px;
  border: 1px solid transparent;
  transition: background .15s, color .15s;
}

.chat-item:hover { background: var(--menu-hover); color: var(--text); }

.chat-item.active {
  background: var(--ac-soft);
  border-color: var(--ac-line);
  color: var(--text);
}

.chat-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-del {
  opacity: 0;
  color: var(--muted-2);
  padding: 0 3px;
  font-size: 16px;
  line-height: 1;
}

.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--err); }

.side-bottom { display: flex; flex-direction: column; gap: 8px; }

/* основная область */
.chat-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
}

.who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  overflow: hidden;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: 0 0 auto;
}

#key-area { padding: 12px 18px 0; }

#key-area input { font-size: 13.5px; }

.key-status { font-size: 12px; margin-top: 7px; }
.key-status.warn { color: var(--warn); }
.key-status.ok { color: var(--ok); }

/* ссылка «Нет ключа? Как получить» под статусом ключа */
.key-get { display: inline-block; margin: 4px 0 0 2px; font-size: 13px; }

/* сообщения */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  padding: 18px 18px 34px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Прокрученная лента: верхняя кромка растворяется, а не режет сообщение по линейке.
   Класс ставит chatSettle() — на непрокрученной ленте затемнения нет. */
.messages.is-scrolled {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
}

.msg { display: flex; flex-direction: column; }
.msg.you { align-items: flex-end; }
.msg.bot, .msg.error { align-items: flex-start; }

.msg .bubble {
  max-width: min(680px, 82%);
  padding: 11px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
}

.msg.you .bubble {
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--accent);
  border-bottom-right-radius: 5px;
  font-weight: 500;
}

.msg.bot .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

.msg.error .bubble {
  background: var(--err-soft);
  border: 1px solid rgba(224, 112, 122, .45);
  color: #F0B4BA;
}

.msg-model {
  align-self: flex-end;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  margin: 4px 4px 0;
}

/* имя модели из каталога: наведение показывает, что она умеет и сколько стоит */
.model-name {
  color: var(--muted);
  border-bottom: 1px dotted var(--line-2);
  cursor: help;
}

.model-price {
  font-size: 11.5px;
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 0 6px;
  white-space: nowrap;
}

.msg.bot .msg-model { align-self: flex-start; }

/* Кадр генерации → строка модели: чуть больше воздуха, чем у текстовых ответов. */
.msg:has(> .bubble > .msg-img) .msg-model {
  margin-top: 8px;
}

.msg-img {
  display: block;
  margin-top: 10px;
  max-width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.msg-thumb {
  display: block;
  margin: 8px 0 0;
  max-width: 220px;
  max-height: 220px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(23, 19, 10, .25);
}

/* Честная заглушка вместо картинки, которую браузер не сохранил.
   Раньше в такой ситуации в текст сообщения дописывался служебный маркер. */
.msg-lost {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px dashed rgba(242, 236, 223, .28);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1.4;
  color: rgba(242, 236, 223, .74);
  background: rgba(242, 236, 223, .05);
  max-width: 320px;
}

/* в жёлтом пузыре пользователя фон светлый — там текст тёмный */
.msg.you .msg-lost {
  border-color: rgba(23, 19, 10, .32);
  color: rgba(23, 19, 10, .82);
  background: rgba(23, 19, 10, .06);
}

/* Подпись прикреплённого документа в истории: строка-чип внутри пузыря,
   чтобы после перезагрузки было видно, какой файл разбирали. Сам файл
   целиком лежит в «Моих файлах», поэтому имя и размер — по делу. */
.msg-attach {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 8px;
  padding: 8px 11px;
  max-width: 360px;
  border: 0;
  border-radius: var(--radius-sm);
  background: rgba(242, 236, 223, .1);
  font-size: 12.5px;
  line-height: 1.35;
  font-weight: 500;
  white-space: normal;
  text-align: left;
}
.msg-attach-ico { flex: 0 0 auto; }
.msg-attach-txt { overflow-wrap: anywhere; }
.msg.you .msg-attach {
  background: rgba(23, 19, 10, .14);
  color: inherit;
}

/* ===== разметка ответа модели: заголовки, списки, таблицы, код ===== */
.msg .bubble .md-body { white-space: normal; }
.md-body > *:first-child { margin-top: 0; }
.md-body > *:last-child { margin-bottom: 0; }
.md-body p { margin: 0 0 9px; line-height: 1.55; }
.md-h1, .md-h2, .md-h3, .md-h4 { margin: 14px 0 7px; font-weight: 700; line-height: 1.25; }
.md-h1 { font-size: 18px; }
.md-h2 { font-size: 16.5px; }
.md-h3 { font-size: 15.5px; }
.md-h4 { font-size: 14.5px; }
.md-body ul, .md-body ol { margin: 0 0 10px; padding-left: 21px; }
.md-body li { margin: 0 0 4px; line-height: 1.5; }
.md-body li::marker { color: var(--accent); }
.md-body blockquote {
  margin: 0 0 10px; padding: 7px 12px; border-left: 3px solid var(--accent);
  background: var(--ac-soft); border-radius: 0 8px 8px 0; color: var(--muted);
}
.md-body hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.md-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md-body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.8px;
  background: rgba(0, 0, 0, .3); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}
.md-code {
  margin: 0 0 10px; padding: 10px 12px; background: #08120E;
  border: 1px solid var(--line); border-radius: 9px; overflow-x: auto;
}
.md-code code { background: none; border: 0; padding: 0; line-height: 1.5; white-space: pre; }
.md-table { margin: 0 0 11px; overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; }
.md-table table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md-table th, .md-table td {
  padding: 7px 10px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
  text-align: left; vertical-align: top;
}
.md-table th:last-child, .md-table td:last-child { border-right: 0; }
.md-table tbody tr:last-child td { border-bottom: 0; }
.md-table thead th { background: var(--ac-soft); font-weight: 700; white-space: nowrap; }
.md-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, .022); }
.md-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ===== карточки готовых файлов со кнопкой «Скачать» ===== */
.files { display: flex; flex-direction: column; gap: 8px; margin-top: 11px; }
.file-card {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  background: var(--ac-soft); border: 1px solid var(--line); border-radius: 11px;
  text-decoration: none; color: var(--text);
  transition: border-color .15s, background .15s, transform .15s;
}
.file-card:hover { border-color: var(--accent); background: rgba(212, 169, 62, .19); transform: translateY(-1px); }
.file-card.off { opacity: .6; }
.file-ico {
  flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 9px; background: rgba(0, 0, 0, .3); border: 1px solid var(--line);
  color: var(--accent); font-size: 15px;
}
.file-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { font-size: 11.5px; color: var(--muted); }
.file-dl {
  flex: 0 0 auto; padding: 6px 12px; border-radius: 8px;
  background: var(--accent); color: var(--on-accent); font-size: 12.5px; font-weight: 700;
}
.file-card:hover .file-dl { background: var(--text); }
.file-tip, .empty-hint { line-height: 1.5; }
.empty-more { display: block; margin-top: 7px; font-size: 12.5px; }

.empty-hint { color: var(--muted); font-size: 13.5px; text-align: center; margin: auto 0; }
.empty-hint.small { font-size: 12.5px; margin: 10px 0; }

/* точки «думаю» */
.dots { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: middle; }
.dots i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  animation: blink 1.1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }

@keyframes blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* поле ввода */
#input-area {
  border-top: 1px solid var(--line);
  padding: 12px 18px 16px;
  background: var(--bg-soft);
}

.input-row { display: flex; align-items: flex-end; gap: 9px; }

.attach {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: none;
  cursor: pointer;
  margin: 0;
  transition: background .2s, border-color .2s;
}

.attach:hover { background: var(--menu-hover); border-color: var(--accent); }

#msg-input {
  flex: 1 1 auto;
  max-height: 160px;
  min-height: 44px;
  padding: 11px 13px;
  line-height: 1.4;
}

#send-btn {
  flex: 0 0 auto;
  width: auto;
  margin: 0;
  padding: 0 20px;
  height: 44px;
  min-height: 44px;
}

.file-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  padding: 7px 11px;
  font-size: 12.5px;
  color: var(--text);
  background: var(--ac-soft);
  border: 1px solid var(--ac-line);
  border-radius: var(--radius-sm);
  width: fit-content;
  max-width: 100%;
}

.chip-x {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}

.chip-x:hover { color: var(--err); }

.file-tip { font-size: 12.5px; color: var(--muted); margin-top: 7px; }

/* тост */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--toast-lift, 0px));
  transform: translateX(-50%);
  max-width: min(460px, calc(100% - 24px));
  padding: 12px 16px;
  font-size: 13px;
  text-align: center;
  pointer-events: none;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--ac-line);
  color: var(--text);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .6);
  z-index: 50;
}

/* ---------- «Мои файлы» ---------- */

.top-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.who { flex: 1 1 auto; min-width: 0; }
#user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.files-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  margin-left: 7px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11.5px;
  font-weight: 800;
  line-height: 1;
  vertical-align: 1px;
}

.files-card { max-width: 780px; }
/* Длинный архив прокручиваем от верха, а не «с середины» из-за центрирования. */
#files-panel { align-items: flex-start; }

.files-note {
  position: relative;
  margin: 14px 0 0;
  padding: 12px 14px 12px 16px;
  background: var(--ac-soft);
  border: 1px solid var(--ac-line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.files-note::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}

.files-note b { color: var(--text); font-weight: 700; }

.files-warn {
  margin: 10px 0 0;
  padding: 11px 14px;
  background: var(--err-soft);
  border: 1px solid rgba(224, 112, 122, .38);
  border-left: 3px solid var(--err);
  border-radius: var(--radius-sm);
  color: #F0B9BE;
  font-size: 13px;
  line-height: 1.5;
}

.files-warn b { color: #FFD6D9; font-weight: 700; }

#files-removed { background: rgba(143, 140, 125, .1); border-color: var(--line-2); }
#files-removed::before { background: var(--muted-2); }

.files-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0 12px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--line);
}

.files-stat { color: var(--muted); font-size: 13px; }
.files-stat b { color: var(--text); font-weight: 700; }

/* Список растёт целиком: прокручивается вся панель, поэтому нижний ряд
   карточек не подрезается и кнопка «Назад в чат» не наезжает на «Скачать». */
.files-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(216px, 1fr));
  gap: 11px;
  padding: 2px 2px 6px;
  margin: 0 0 16px;
}

.file-item {
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.files-empty {
  grid-column: 1 / -1;
  padding: 26px 16px;
  text-align: center;
  color: var(--muted-2);
  font-size: 13.5px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-sm);
}

.fi-thumb {
  display: block;
  width: 100%;
  height: 108px;
  object-fit: cover;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.fi-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fi-thumb .file-ico { font-size: 30px; line-height: 1; }

.fi-thumb.doc {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .1em;
  background:
    linear-gradient(135deg, rgba(212, 169, 62, .10), transparent 60%),
    var(--surface);
}

.fi-meta { padding: 9px 11px 0; min-width: 0; }
.fi-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fi-sub { display: block; font-size: 11.5px; color: var(--muted-2); margin-top: 3px; }
.fi-sub.warn { color: var(--err); font-weight: 600; }

.fi-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px 11px;
  margin-top: auto;
}

.fi-dl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 5px 11px;
  border: 1px solid var(--ac-line);
  border-radius: 8px;
  background: var(--ac-soft);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 700;
  text-decoration: none;
}

.fi-dl:hover { background: rgba(212, 169, 62, .22); color: var(--accent-hover); }
.fi-dl:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.fi-del {
  margin-left: auto;
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: transparent;
  color: var(--muted-2);
  font-size: 12px;
}

.fi-del:hover { color: var(--err); border-color: rgba(224, 112, 122, .5); }

/* полоса прокрутки */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3B5748; }
::-webkit-scrollbar-track { background: transparent; }

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

@media (max-width: 760px) {
  .panel.app {
    flex-direction: column;
    height: 100%;
  }

  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
  }

  .side-top { order: 1; margin: 0; }
  .side-top .logo { display: none; }
  .sidebar > .primary.full { order: 2; width: auto; margin: 0; padding: 0 14px; min-height: 38px; white-space: nowrap; }
  .chat-list {
    order: 3;
    flex-direction: row;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .chat-item { white-space: nowrap; padding: 8px 10px; }
  .chat-del { opacity: 1; }
  .side-bottom { order: 4; flex-direction: row; flex: 0 0 auto; }
  .side-bottom .ghost { padding: 8px 10px; font-size: 12.5px; min-height: 38px; }

  .topbar { padding: 9px 13px; }
  .topbar .small-btn { white-space: nowrap; }

  .topbar .top-actions { gap: 6px; }
  .topbar .small-btn { padding: 6px 9px; font-size: 12.5px; }
  .files-badge { margin-left: 5px; }

  .files-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); max-height: none; }
  .fi-thumb { height: 96px; }

  #key-area { padding: 10px 13px 0; }
  .messages { padding: 13px; gap: 12px; }
  .msg .bubble { max-width: 92%; font-size: 14.5px; }

  #input-area { padding: 10px 13px 13px; }
  #msg-input { min-height: 42px; }
  #send-btn { padding: 0 15px; font-size: 14px; }
  .file-tip { display: none; }

  /* карточки файлов в чате: имя не обрезается, кнопка не зажимает */
  .file-card { flex-wrap: wrap; }
  .file-name { white-space: normal; overflow-wrap: anywhere; line-height: 1.35; max-width: none; }
  .file-meta { flex: 1 1 calc(100% - 70px); min-width: 120px; }
  .file-dl { flex: 0 0 auto; }

  .auth-card { padding: 24px 18px; }
  .logo { font-size: 28px; }
  .howto li { padding-left: 36px; }
}

@media (max-width: 400px) {
  #send-btn { padding: 0 12px; }
  .topbar .small-btn { padding: 6px 8px; font-size: 12px; }
  .files-list { grid-template-columns: 1fr; gap: 10px; }
  .fi-thumb { height: 190px; }
  .fi-name { white-space: normal; overflow-wrap: anywhere; line-height: 1.35; }
  .fi-actions { gap: 10px; }
  .fi-dl, .fi-del { min-height: 44px; padding: 10px 14px; font-size: 13.5px; }

  /* карточки файлов в чате: имя на всю ширину, «Скачать» под ним */
  .file-card { padding: 10px; }
  .file-meta { flex: 1 1 100%; margin-bottom: 6px; }
  .file-dl { width: 100%; text-align: center; }
}

/* ===== Выбор формата картинки перед генерацией (:root-переменные выше) ===== */
/* Панель без рамок: карточки и кнопки отделены тоном фона, а не обводками. */
.fmt-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(6, 14, 11, .74);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.fmt-card {
  width: 100%;
  max-width: 470px;
  max-height: 94vh;
  overflow: auto;
  padding: 24px 24px 20px;
  background: var(--card);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: 0 26px 70px rgba(0, 0, 0, .58);
}

.fmt-card .logo.small { margin: 0 0 8px; }

.fmt-hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  text-wrap: pretty;
}

/* Гибкая сетка: неполный последний ряд центрируется, дыры в углу не остаётся. */
.fmt-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.fmt-item {
  flex: 0 1 calc((100% - 20px) / 3);
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 13px 8px 11px;
  background: rgba(242, 236, 223, .055);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .12s ease;
}

.fmt-item:hover { background: rgba(242, 236, 223, .11); }
.fmt-item:active { transform: scale(.985); }
.fmt-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fmt-item.sel { background: var(--ac-soft); border-color: var(--accent); }

.fmt-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

/* Рамка-превью показывает реальную пропорцию кадра. */
.fmt-frame {
  height: 46px;
  width: auto;
  flex: 0 0 auto;
  background: rgba(242, 236, 223, .1);
  border: 1px solid rgba(242, 236, 223, .22);
  border-radius: 4px;
}

.fmt-item.sel .fmt-frame { background: rgba(212, 169, 62, .18); border-color: var(--ac-line); }

/* Слот под превью одной ширины: подписи во всех карточках встают по общей линии. */
.fmt-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.fmt-auto {
  width: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.fmt-auto svg { width: 21px; height: 21px; }

.fmt-label { font-size: 13.5px; font-weight: 600; line-height: 1.2; text-align: center; }
.fmt-sub2 { font-size: 13px; color: var(--muted); line-height: 1.15; text-align: center; }

/* «Отмена» — тонкая подложка вместо обводки */
.fmt-cancel {
  width: auto;
  min-width: 168px;
  margin: 16px auto 0;
  background: rgba(242, 236, 223, .06);
  border-color: transparent;
}
.fmt-cancel:hover { background: rgba(242, 236, 223, .12); border-color: transparent; }

/* Мобильная версия — отдельная раскладка: список строками, тач-зона ≥54px. */
@media (max-width: 420px) {
  .fmt-overlay { padding: 10px; }
  .fmt-card { padding: 26px 16px 18px; max-height: 96vh; }
  .fmt-hint { font-size: 13.5px; margin-bottom: 14px; }
  .fmt-grid { flex-direction: column; gap: 6px; }
  .fmt-item {
    flex: 0 0 auto;
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 14px;
    min-height: 54px;
    padding: 10px 14px;
  }
  .fmt-slot { width: 62px; flex-basis: 62px; }
  .fmt-frame { height: 34px; }
  .fmt-auto { width: 34px; }
  .fmt-auto svg { width: 19px; height: 19px; }
  .fmt-text { align-items: flex-start; gap: 3px; }
  .fmt-label { font-size: 14.5px; text-align: left; }
  .fmt-sub2 { font-size: 12.5px; text-align: left; }
  .fmt-cancel { width: 100%; margin-top: 14px; }
}
