:root {
  --bg: #0b0a10;
  --bg-soft: #12111a;
  --card: #171522;
  --card-2: #1e1b2b;
  --line: #262134;
  --text: #ece9f5;
  --muted: #9a92b3;
  --dim: #6d6683;
  --accent: #a970ff;
  --accent-2: #7b3ff2;
  --ok: #3ddc84;
  --warn: #ffb020;
  --err: #ff5c72;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .55);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(169, 112, 255, .18), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(123, 63, 242, .14), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.45 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
input, textarea { border: 0; outline: 0; background: none; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #322a45; border-radius: 9px; }
::-webkit-scrollbar-track { background: transparent; }

.app {
  display: grid;
  grid-template: 62px 1fr / 268px minmax(0, 1fr) 330px;
  height: 100vh;
}

/* ---------- topbar ---------- */

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 11, 18, .82);
  backdrop-filter: blur(14px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: .4px;
  white-space: nowrap;
}

.brand .mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 22px rgba(169, 112, 255, .5);
  font-size: 17px;
}

.brand small {
  display: block;
  font-weight: 500;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0;
}

.live-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
}

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  white-space: nowrap;
}

.pill.on { background: rgba(255, 71, 96, .14); color: #ff7186; }
.pill.off { background: #241f31; color: var(--dim); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.on .dot { animation: pulse 1.6s infinite; }

@keyframes pulse { 50% { opacity: .25; } }

.live-title {
  font-size: 13px;
  color: var(--muted);
  max-width: 30vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spacer { flex: 1; }

.channel-form {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 4px 4px 12px;
  transition: border-color .15s;
}
.channel-form:focus-within { border-color: var(--accent); }
.channel-form span { color: var(--dim); }

.channel-form input {
  width: 150px;
  padding: 4px 0;
}

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  transition: transform .12s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--card-2); border-color: #3a3151; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  border-color: transparent;
  box-shadow: 0 8px 22px rgba(123, 63, 242, .35);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: #ffb3bd; border-color: #48283a; background: #241721; }
.btn.danger:hover { background: #2e1d2a; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.icon { padding: 7px 9px; }

/* ---------- rail ---------- */

.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: rgba(14, 13, 20, .6);
}

.rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 13px 8px;
  font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--dim); font-weight: 700;
}

.rail-count {
  padding: 1px 8px;
  border-radius: 999px;
  background: #241f31;
  color: var(--muted);
  letter-spacing: 0;
}

.bots {
  list-style: none;
  margin: 0; padding: 0 9px 12px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 7px;
}

.bot {
  position: relative;
  display: grid;
  grid-template: auto / 40px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  padding: 8px 9px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--card);
  transition: border-color .15s, background .15s;
}
.bot:hover { background: var(--card-2); }
.bot.active {
  border-color: rgba(169, 112, 255, .55);
  background: linear-gradient(120deg, rgba(169, 112, 255, .16), rgba(123, 63, 242, .07));
  box-shadow: inset 0 0 0 1px rgba(169, 112, 255, .08);
}

.bot-ava {
  position: relative;
  width: 40px; height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: #221d2f;
  flex: none;
}
.bot-ava img { width: 100%; height: 100%; object-fit: cover; display: block; }

.bot-ava .ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid var(--dim);
}
.bot[data-status="live"] .ring, .bot[data-status="offline"] .ring { border-color: var(--ok); }
.bot[data-status="starting"] .ring,
.bot[data-status="reloading"] .ring { border-color: var(--warn); animation: spin 2.4s linear infinite; }
.bot[data-status="error"] .ring,
.bot[data-status="manual"] .ring { border-color: var(--err); }
@keyframes spin { to { transform: rotate(360deg); } }

.bot-name {
  font-weight: 650;
  font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.bot-sub {
  font-size: 11.5px;
  color: var(--dim);
  display: flex; align-items: center; gap: 6px;
  overflow: hidden; white-space: nowrap;
}
.bot-sub .sep { opacity: .5; }

.bot-actions { display: flex; gap: 3px; opacity: .35; transition: opacity .15s; }
.bot:hover .bot-actions, .bot.active .bot-actions { opacity: 1; }
.bot-actions button {
  width: 26px; height: 26px;
  border-radius: 7px;
  display: grid; place-items: center;
  color: var(--muted);
  background: rgba(0, 0, 0, .25);
}
.bot-actions button:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.bot-actions svg { width: 13px; height: 13px; }

.rail-foot {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid var(--line);
}

/* ---------- chat ---------- */

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

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px 6px;
  display: flex; flex-direction: column; gap: 4px;
  scroll-behavior: smooth;
}

.msg {
  display: grid;
  grid-template: auto / auto minmax(0, 1fr);
  gap: 8px;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 14px;
  animation: in .18s ease-out;
}
@keyframes in { from { opacity: 0; transform: translateY(4px); } }

.msg:hover { background: rgba(255, 255, 255, .03); }
.msg .who { font-weight: 700; white-space: nowrap; }
.msg .txt { word-break: break-word; }
.msg.mine { background: rgba(169, 112, 255, .1); }
.msg.mine .who::after {
  content: " · пишет";
  font-weight: 500;
  font-size: 10.5px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.msg .badge {
  font-size: 10px; padding: 0 5px; border-radius: 4px;
  background: #2b2440; color: var(--muted); margin-right: 4px;
}
.msg.sys { color: var(--dim); font-size: 12.5px; font-style: italic; }

.composer {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, transparent, rgba(10, 9, 15, .85) 40%);
}

.as-bot {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: var(--muted);
}
.as-bot b { color: var(--text); }
.as-bot img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
.as-bot .switch {
  margin-left: auto;
  font-size: 12px; color: var(--accent); font-weight: 600;
  border-bottom: 1px dashed rgba(169, 112, 255, .5);
}

.composer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 8px 8px 8px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(169, 112, 255, .12);
}

#input {
  resize: none;
  max-height: 120px;
  min-height: 24px;
  padding: 5px 0;
  width: 100%;
}

.chips {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 8px;
}
.chip {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #14121d;
}
.chip:hover { color: var(--text); border-color: #3a3151; }
.chip.emote { font-family: ui-monospace, monospace; }

/* ---------- side ---------- */

.side {
  border-left: 1px solid var(--line);
  background: rgba(14, 13, 20, .6);
  display: flex; flex-direction: column;
  min-height: 0;
}

.side-tabs { display: flex; gap: 4px; padding: 10px 10px 0; }
.side-tabs button {
  flex: 1;
  padding: 7px 4px;
  font-size: 12px; font-weight: 600;
  color: var(--dim);
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
}
.side-tabs button.on { color: var(--text); border-color: var(--accent); background: rgba(169, 112, 255, .07); }

.side-body { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.card h3 {
  margin: 0 0 9px;
  font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--dim);
}

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 9px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select {
  border: 1px solid var(--line);
  background: #100e18;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  width: 100%;
}
.field input:focus { border-color: var(--accent); }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 13px;
  padding: 6px 0;
}
.toggle {
  width: 42px; height: 24px; border-radius: 999px;
  background: #2b2538; position: relative; transition: background .15s;
  flex: none;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(18px); }

.log {
  font: 11.5px/1.5 ui-monospace, "Cascadia Mono", monospace;
  color: var(--muted);
  display: flex; flex-direction: column; gap: 3px;
  max-height: 34vh; overflow-y: auto;
}
.log .t { color: #4e4863; }
.log .warn { color: var(--warn); }
.log .error { color: var(--err); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: #120f1b; border: 1px solid var(--line); border-radius: 10px; padding: 9px; }
.stat b { display: block; font-size: 19px; }
.stat span { font-size: 11px; color: var(--dim); }

/* ---------- modal / toast ---------- */

.modal {
  position: fixed; inset: 0; z-index: 60;
  display: none; place-items: center;
  background: rgba(6, 5, 10, .78);
  backdrop-filter: blur(6px);
  padding: 20px;
}
.modal.on { display: grid; }
.modal .frame {
  max-width: min(960px, 94vw);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.modal img { max-width: 100%; border-radius: 10px; display: block; }
.modal .frame header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 2px 4px 10px; font-size: 13px; color: var(--muted);
}

.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 80;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 340px;
}
.toast {
  background: #1a1725;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: in .2s;
}
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }

.empty {
  margin: auto;
  text-align: center;
  color: var(--dim);
  font-size: 13.5px;
  padding: 30px;
}

@media (max-width: 1180px) {
  .app { grid-template: 62px 1fr / 84px minmax(0, 1fr); }
  .bot { grid-template: auto / 40px; justify-items: center; }
  .bot-name, .bot-sub, .bot-actions { display: none; }
  .rail-head span:first-child { display: none; }
  .side { display: none; }
  .side.open {
    display: flex; position: fixed; inset: 62px 0 0 auto;
    width: min(340px, 88vw); z-index: 40;
    box-shadow: -20px 0 40px rgba(0, 0, 0, .5);
  }
}
