:root {
  --bg: #0e1013;
  --bg-2: #15181d;
  --bg-3: #1c2027;
  --line: #272c34;
  --fg: #e6e9ef;
  --fg-dim: #949cab;
  --fg-faint: #656d7b;
  --accent: #6ea8fe;
  --accent-dim: #2b4a7d;
  --ok: #5ec26a;
  --warn: #e0a63c;
  --err: #e2606a;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ── Вход ─────────────────────────────────────────────────────────────────── */
.login-wrap {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p.sub { margin: 0 0 22px; color: var(--fg-dim); font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--fg-dim); margin: 14px 0 6px; }
.login-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent-dim); }
.login-card button {
  width: 100%;
  margin-top: 20px;
  background: var(--accent);
  color: #0b1220;
  font-weight: 600;
  border: 0;
  border-radius: var(--radius);
  padding: 11px;
}
.login-card button:disabled { opacity: .6; cursor: default; }
.login-err { margin-top: 14px; color: var(--err); font-size: 13px; min-height: 18px; }

/* ── Каркас ───────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 250px 1fr 320px; height: 100%; }

.side, .rail {
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side { border-right: 1px solid var(--line); }
.rail { border-left: 1px solid var(--line); }

.side-head, .rail-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand { font-weight: 650; font-size: 14px; letter-spacing: .2px; }
.brand small { display: block; font-weight: 400; color: var(--fg-faint); font-size: 11px; }

.btn {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 13px;
  color: var(--fg);
}
.btn:hover { border-color: var(--accent-dim); }
.btn-accent { background: var(--accent); color: #0b1220; border-color: transparent; font-weight: 600; }

.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item {
  padding: 9px 11px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--fg-dim);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.chat-item:hover { background: var(--bg-3); color: var(--fg); }
.chat-item.active { background: var(--accent-dim); color: #fff; }
.chat-item .x { opacity: 0; font-size: 15px; line-height: 1; color: var(--fg-faint); }
.chat-item:hover .x { opacity: 1; }
.chat-item .x:hover { color: var(--err); }
.chat-item span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-foot { border-top: 1px solid var(--line); padding: 12px 16px; font-size: 12px; color: var(--fg-faint); }
.side-foot .who { color: var(--fg-dim); margin-bottom: 6px; }
.side-foot a { color: var(--fg-faint); text-decoration: none; }
.side-foot a:hover { color: var(--fg-dim); }

/* ── Центр: диалог ────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-height: 0; }
.stream { flex: 1; overflow-y: auto; padding: 24px 28px 8px; }
.stream-inner { max-width: 780px; margin: 0 auto; }

.msg { margin-bottom: 22px; }
.msg .who {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--fg-faint);
  margin-bottom: 6px;
}
.msg.user .bubble {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  white-space: pre-wrap;
}
.msg.bot .bubble { white-space: pre-wrap; }
.msg .thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.msg .thumbs img { height: 74px; border-radius: 8px; border: 1px solid var(--line); }

/* лог работы агента */
.trace {
  border-left: 2px solid var(--line);
  padding: 2px 0 2px 12px;
  margin: 10px 0;
  font-size: 13px;
  color: var(--fg-dim);
}
.trace .row { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; }
.trace .dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--fg-faint); margin-top: 7px; }
.trace .dot.run { background: var(--accent); animation: pulse 1.1s infinite; }
.trace .dot.ok { background: var(--ok); }
.trace .dot.err { background: var(--err); }
.trace .txt { white-space: pre-wrap; }
.trace code { font-family: var(--mono); font-size: 12px; color: var(--fg); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* результаты */
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-top: 12px; }
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.card img, .card video { width: 100%; display: block; background: #000; }
.card .meta {
  padding: 7px 9px;
  font-size: 11px;
  color: var(--fg-faint);
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: center;
}
.card .acts { display: flex; gap: 6px; }
.card .acts a, .card .acts button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--fg-faint);
  font-size: 12px;
  text-decoration: none;
}
.card .acts a:hover, .card .acts button:hover { color: var(--accent); }
.card .acts button.on { color: var(--warn); }

/* ── Ввод ─────────────────────────────────────────────────────────────────── */
.composer { border-top: 1px solid var(--line); padding: 14px 28px 18px; background: var(--bg); }
.composer-inner { max-width: 780px; margin: 0 auto; }
.attach-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chip {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--fg-dim);
  display: flex;
  gap: 7px;
  align-items: center;
}
.chip button { background: none; border: 0; color: var(--fg-faint); padding: 0; font-size: 14px; line-height: 1; }
.chip button:hover { color: var(--err); }

.input-box {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 10px 9px 14px;
}
.input-box:focus-within { border-color: var(--accent-dim); }
.input-box textarea {
  flex: 1;
  background: none;
  border: 0;
  outline: none;
  resize: none;
  max-height: 200px;
  line-height: 1.5;
  padding: 3px 0;
}
.icon-btn {
  background: none;
  border: 0;
  color: var(--fg-faint);
  font-size: 18px;
  padding: 4px 6px;
  border-radius: 7px;
}
.icon-btn:hover { color: var(--fg); background: var(--bg-3); }
.send-btn {
  background: var(--accent);
  color: #0b1220;
  border: 0;
  border-radius: 8px;
  padding: 7px 14px;
  font-weight: 600;
}
.send-btn:disabled { opacity: .45; cursor: default; }
.hint { margin-top: 7px; font-size: 11.5px; color: var(--fg-faint); }

/* ── Правая колонка ───────────────────────────────────────────────────────── */
.rail-body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.stat {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 11px;
}
.stat .n { font-size: 19px; font-weight: 650; }
.stat .l { font-size: 11px; color: var(--fg-faint); margin-top: 1px; }

.rail h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--fg-faint);
  margin: 18px 0 9px;
  font-weight: 600;
}
.gal { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.gal a { display: block; border-radius: 7px; overflow: hidden; border: 1px solid var(--line); position: relative; }
.gal img, .gal video { width: 100%; height: 84px; object-fit: cover; display: block; background: #000; }
.gal .tag {
  position: absolute; right: 3px; bottom: 3px;
  background: rgba(0,0,0,.72);
  font-size: 9px; padding: 1px 5px; border-radius: 4px; color: #fff;
}

.notice {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--fg-dim);
  margin-bottom: 14px;
}
.notice.err { border-left-color: var(--err); }
.notice b { color: var(--fg); }

.empty { color: var(--fg-faint); font-size: 13px; text-align: center; padding: 40px 20px; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #2b313a; border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 210px 1fr; }
  .rail { display: none; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .stream, .composer { padding-left: 14px; padding-right: 14px; }
}
