:root {
  --bg:        #0f1117;
  --panel:     #171922;
  --panel-2:   #1d202b;
  --border:    #262a37;
  --border-hi: #343a4d;
  --text:      #e6e8ee;
  --muted:     #888ea3;
  --muted-2:   #5c6178;
  --accent:    #6366f1;
  --accent-2:  #8b5cf6;
  --accent-dim:#312e6b;
  --danger:    #e5484d;
  --ok:        #3dd68c;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Боковая панель ─────────────────────────────────────────── */
#sidebar {
  width: 280px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}

.sidebar-head {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 650; font-size: 15px; letter-spacing: -0.01em;
  margin-bottom: 14px;
}
.brand .dot {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 16px -2px var(--accent);
}
.brand small { color: var(--muted-2); font-weight: 500; font-size: 11px; }

#new-chat {
  width: 100%; padding: 10px 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 9px;
  font-weight: 600; font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  transition: filter .15s, transform .05s;
}
#new-chat:hover { filter: brightness(1.08); }
#new-chat:active { transform: translateY(1px); }

.chat-list { flex: 1; overflow-y: auto; padding: 8px; }

.chat-item {
  padding: 10px 11px; border-radius: 9px; cursor: pointer;
  margin-bottom: 3px; position: relative;
  border: 1px solid transparent;
  transition: background .12s, border-color .12s;
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); border-color: var(--border-hi); }

.chat-item .title {
  font-size: 13px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding-right: 20px;
}
.chat-item .meta {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 3px; font-size: 11px; color: var(--muted-2);
}
.chat-item .cost { font-family: var(--mono); color: var(--muted); }

.chat-del {
  position: absolute; top: 8px; right: 8px;
  width: 18px; height: 18px; border-radius: 5px;
  border: none; background: transparent; color: var(--muted-2);
  cursor: pointer; opacity: 0; font-size: 13px; line-height: 1;
  transition: opacity .12s, color .12s, background .12s;
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { background: var(--danger); color: #fff; }

/* ── Основная зона ─────────────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 52px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
}
.topbar .chat-name {
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cost-badge {
  font-family: var(--mono); font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px;
  display: flex; align-items: center; gap: 7px; flex-shrink: 0;
}
.cost-badge b { color: var(--ok); font-weight: 600; }
.cost-badge span { color: var(--muted-2); }

/* ── Лента сообщений ───────────────────────────────────────── */
.messages { flex: 1; overflow-y: auto; padding: 24px 20px 8px; }
.msg-wrap { max-width: 780px; margin: 0 auto; }

.msg { display: flex; gap: 12px; margin-bottom: 22px; }
.msg .avatar {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.msg.user .avatar   { background: var(--panel-2); border: 1px solid var(--border-hi); }
.msg.bot  .avatar   { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color:#fff; }

.msg .body { flex: 1; min-width: 0; padding-top: 3px; }
.msg .who  { font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.msg .text { line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }

.msg-images { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.msg-images img {
  max-width: 320px; max-height: 320px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--panel);
  cursor: zoom-in; display: block;
}
.msg .attach-thumb {
  width: 68px; height: 68px; object-fit: cover; border-radius: 9px;
  border: 1px solid var(--border-hi);
}
.msg .cost-tag {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 9px; font-family: var(--mono); font-size: 11px;
  color: var(--muted-2);
}
.badge-action {
  font-family: var(--sans); font-size: 10px; font-weight: 600;
  padding: 2px 7px; border-radius: 5px; text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-action.edit     { background: var(--accent-dim); color: #c4b5fd; }
.badge-action.generate { background: #1e3a2f; color: #86efac; }

/* ── Пустое состояние ──────────────────────────────────────── */
.empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  color: var(--muted); gap: 6px; padding: 40px;
}
.empty .big { font-size: 20px; font-weight: 650; color: var(--text); }
.empty .hint { max-width: 380px; line-height: 1.6; font-size: 13px; }

/* ── Композер (поле ввода) ─────────────────────────────────── */
.composer-wrap { border-top: 1px solid var(--border); padding: 14px 20px 18px; }
.composer {
  max-width: 780px; margin: 0 auto;
  background: var(--panel); border: 1px solid var(--border-hi);
  border-radius: 16px; padding: 10px 12px;
  transition: border-color .15s;
}
.composer.drag { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.attach-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attach-row:empty { display: none; }
.attach-chip { position: relative; }
.attach-chip img {
  width: 56px; height: 56px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border-hi);
}
.attach-chip button {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--danger); color: #fff; border: 2px solid var(--panel);
  font-size: 11px; line-height: 1; cursor: pointer; padding: 0;
}

.composer textarea {
  width: 100%; border: none; background: transparent; resize: none;
  color: var(--text); font-family: var(--sans); font-size: 14.5px;
  line-height: 1.5; outline: none; max-height: 200px; padding: 4px 2px;
}
.composer textarea::placeholder { color: var(--muted-2); }

.composer-bar {
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
}
.tool-btn {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: color .12s, border-color .12s;
}
.tool-btn:hover { color: var(--text); border-color: var(--border-hi); }

select.opt {
  height: 34px; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 0 8px; font-size: 12px; font-family: var(--sans); cursor: pointer;
  outline: none;
}
select.opt:hover { border-color: var(--border-hi); }

.spacer { flex: 1; }

#send {
  height: 34px; padding: 0 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 9px;
  font-weight: 600; font-size: 13px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: filter .15s, opacity .15s;
}
#send:hover { filter: brightness(1.08); }
#send:disabled { opacity: .5; cursor: default; filter: none; }

.hint-line {
  max-width: 780px; margin: 8px auto 0; text-align: center;
  font-size: 11px; color: var(--muted-2);
}
.hint-line kbd {
  font-family: var(--mono); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; font-size: 10px;
}

/* ── Лоадер генерации ──────────────────────────────────────── */
.gen-loading {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 13px;
}
.gen-loading .spin {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border-hi); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Просмотр картинки на весь экран ───────────────────────── */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.85);
  display: none; align-items: center; justify-content: center; z-index: 50;
  cursor: zoom-out; padding: 40px;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 12px; }

/* ── Скроллбары ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 6px; border: 2px solid var(--panel); }
::-webkit-scrollbar-track { background: transparent; }

/* ── Мобильная адаптация ───────────────────────────────────── */
@media (max-width: 720px) {
  #sidebar { position: absolute; z-index: 20; height: 100%;
             transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: translateX(0); }
  .menu-toggle { display: flex !important; }
  .msg-images img { max-width: 100%; }
}
.menu-toggle { display: none; }
