:root {
  --bg: #0e1621;
  --bg-2: #17212b;
  --bg-3: #202b36;
  --bg-hover: #232e3c;
  --bg-active: #2b5278;
  --line: #0b1219;
  --text: #e9eef3;
  --muted: #7f8b97;
  --accent: #5eb5f7;
  --in: #182533;
  --out: #2b5278;
  --danger: #e5484d;
  --ok: #4fbf67;
  --warn: #f5a142;
  --radius: 12px;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }

/* ───── Вход ───── */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 30% 20%, #1c3550 0, transparent 50%), var(--bg); }
.login-card { width: 100%; max-width: 360px; background: var(--bg-2); padding: 32px 28px; border-radius: 16px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.login-logo { width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 30px;
  display: grid; place-items: center; margin: 0 auto 4px; }
.login-card h1 { margin: 0; text-align: center; font-size: 22px; }
.login-card p { margin: 0 0 6px; text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input { background: var(--bg); border: 1px solid #2a3947; border-radius: 10px; padding: 11px 12px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; text-align: center; }
.btn-primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 12px; font-weight: 600; cursor: pointer; }
.btn-primary:disabled { opacity: .6; cursor: default; }

/* ───── Каркас ───── */
.app { display: grid; grid-template-columns: 360px 1fr 340px; height: 100vh; height: 100dvh; }
.app.no-info { grid-template-columns: 360px 1fr 0; }
.app.no-info .pane-info { display: none; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane-list { background: var(--bg-2); border-right: 1px solid var(--line); }
.pane-info { background: var(--bg-2); border-left: 1px solid var(--line); overflow-y: auto; }

.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; width: 36px; height: 36px; border-radius: 50%;
  cursor: pointer; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ───── Список чатов ───── */
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; }
.brand-mark { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 14px; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.conn.on { background: var(--ok); }
.search { padding: 4px 12px; }
.search input { width: 100%; background: var(--bg); border: 1px solid transparent; border-radius: 20px; padding: 9px 14px; outline: none; }
.search input:focus { border-color: var(--accent); }
.filters { display: flex; gap: 8px; align-items: center; padding: 8px 12px 4px; }
.filters select { flex: 1; min-width: 0; background: var(--bg); border: 1px solid #2a3947; border-radius: 8px; padding: 7px 8px; }
.toggle { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; white-space: nowrap; cursor: pointer; }

.bot-strip { display: flex; gap: 6px; overflow-x: auto; padding: 6px 12px 10px; scrollbar-width: thin; border-bottom: 1px solid var(--line); }
.bot-chip { flex: none; display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border-radius: 14px; background: var(--bg);
  border: 1px solid transparent; cursor: pointer; font-size: 12px; white-space: nowrap; }
.bot-chip.active { border-color: var(--bot, var(--accent)); background: var(--bg-3); }
.bot-chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bot); position: relative; }
.bot-chip .dot.err::after { content: ""; position: absolute; inset: -3px; border: 2px solid var(--danger); border-radius: 50%; }
.bot-chip .n { background: var(--accent); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; font-weight: 600; }

.chat-list { list-style: none; margin: 0; padding: 4px 6px; overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; align-items: center; }
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-item .body { flex: 1; min-width: 0; }
.chat-item .row { display: flex; gap: 6px; align-items: center; }
.chat-item .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { color: var(--muted); font-size: 12px; flex: none; }
.chat-item .last { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.active .last, .chat-item.active .time { color: #c5d7e8; }
.chat-item .badge { background: var(--accent); color: #fff; border-radius: 11px; min-width: 20px; padding: 1px 6px; font-size: 12px; text-align: center; font-weight: 600; }
.chat-item.active .badge { background: #fff; color: var(--bg-active); }
.chat-list .empty { color: var(--muted); padding: 30px 10px; text-align: center; }

.bot-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 1px 7px; border-radius: 8px;
  background: color-mix(in srgb, var(--bot) 22%, transparent); color: var(--bot); white-space: nowrap; font-weight: 600;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; flex: none; }
.chat-item.active .bot-tag { background: rgba(255,255,255,.14); color: #fff; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--bg-3); color: var(--muted); }
.tag.danger { background: rgba(229,72,77,.18); color: #ff8b8e; }
.tag.premium { background: rgba(179,140,245,.18); color: #c6a8ff; }

/* ───── Аватары ───── */
.avatar { width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 600; color: #fff;
  background: var(--av, #5a6b7b); background-size: cover; background-position: center; font-size: 17px; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 40px; height: 40px; font-size: 15px; }
.avatar.lg { width: 110px; height: 110px; font-size: 40px; }

/* ───── Переписка ───── */
.pane-chat { background: var(--bg); }
.empty-state { margin: auto; text-align: center; color: var(--muted); }
.empty-icon { font-size: 48px; opacity: .6; }
.chat-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.chat-head-text { flex: 1; min-width: 0; }
.chat-head-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-sub { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.messages { flex: 1; overflow-y: auto; padding: 12px 6% 8px; display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; background: rgba(0,0,0,.35); color: #cfd8e0; font-size: 12px; padding: 3px 10px; border-radius: 10px; margin: 10px 0 6px; }
.sys-msg { align-self: center; color: var(--warn); font-size: 12px; background: rgba(245,161,66,.1); padding: 4px 12px; border-radius: 10px; margin: 6px 0; }
.load-more { align-self: center; background: var(--bg-3); border: 0; border-radius: 12px; padding: 5px 14px; color: var(--muted); cursor: pointer; margin-bottom: 6px; }

.msg { max-width: min(560px, 78%); padding: 6px 10px 5px; border-radius: var(--radius); position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.in { align-self: flex-start; background: var(--in); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--out); border-bottom-right-radius: 4px; }
.msg.pending { opacity: .6; }
.msg .text { white-space: pre-wrap; line-height: 1.4; }
.msg .meta { float: right; margin: 6px 0 -2px 10px; font-size: 11px; color: rgba(255,255,255,.5); white-space: nowrap; }
.msg .fwd { font-size: 12px; color: var(--accent); margin-bottom: 3px; }
.msg .quote { border-left: 2px solid var(--accent); padding: 2px 8px; margin-bottom: 4px; font-size: 13px; color: #b9c6d2;
  background: rgba(255,255,255,.05); border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .reply-btn { position: absolute; top: 50%; transform: translateY(-50%); opacity: 0; background: var(--bg-3); border: 0; color: var(--muted);
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer; transition: opacity .15s; }
.msg.in .reply-btn { right: -36px; }
.msg.out .reply-btn { left: -36px; }
.msg:hover .reply-btn { opacity: 1; }
.msg .media { margin: -2px -6px 4px; }
.msg .media img, .msg .media video { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; cursor: pointer; background: rgba(0,0,0,.2); }
.msg .media img.sticker { max-width: 180px; background: none; cursor: default; }
.msg .media video.round { width: 220px; height: 220px; border-radius: 50%; object-fit: cover; }
.msg .media audio { width: 280px; max-width: 100%; }
.msg .file { display: flex; align-items: center; gap: 10px; padding: 4px 6px; text-decoration: none; color: var(--text); }
.msg .file .ic { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; flex: none; }
.msg .card { background: rgba(0,0,0,.15); border-radius: 8px; padding: 8px 10px; margin: 0 -4px 4px; }
.msg .note { color: var(--muted); font-style: italic; }

.composer { background: var(--bg-2); border-top: 1px solid var(--line); padding: 6px 10px 8px; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea { flex: 1; resize: none; background: var(--bg); border: 1px solid transparent; border-radius: 18px; padding: 9px 14px;
  outline: none; max-height: 180px; line-height: 1.4; }
.composer textarea:focus { border-color: #2a3947; }
.btn-send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; cursor: pointer; font-size: 16px; flex: none; }
.btn-send:disabled { opacity: .5; cursor: default; }
.reply-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-left: 3px solid var(--accent);
  padding: 2px 4px 2px 10px; margin: 2px 0 6px; font-size: 13px; }
.reply-bar > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blocked-note { color: #ff8b8e; font-size: 12px; padding: 4px 4px 6px; }
.send-as { font-size: 12px; color: var(--muted); padding: 4px 4px 0 46px; }
.send-as b { color: var(--bot); }

/* ───── Информация ───── */
.info-head { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 22px 16px 14px; text-align: center; border-bottom: 1px solid var(--line); }
.info-head .name { font-size: 18px; font-weight: 600; }
.info-head .tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.info-close { align-self: flex-end; margin: -12px -6px -30px 0; }
.info-sec { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.info-sec h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.copy { cursor: pointer; border-bottom: 1px dashed var(--muted); }
.copy:hover { color: var(--accent); }
.bot-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.bot-row:hover { background: var(--bg-hover); }
.bot-row.current { background: var(--bg-3); cursor: default; }
.bot-row .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bot); flex: none; }
.bot-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist { font-size: 12px; color: var(--muted); padding: 3px 0; }
.hist b { color: var(--text); font-weight: 500; }
.raw { background: var(--bg); border-radius: 8px; padding: 10px; font-size: 11px; overflow-x: auto; white-space: pre; max-height: 320px; margin: 8px 0 0; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.btn-ghost { background: var(--bg-3); border: 0; border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px; }
.btn-ghost:hover { background: var(--bg-hover); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b3a4a; padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); z-index: 50; max-width: calc(100% - 32px); }
.toast.error { background: #5a2226; }

.only-mobile { display: none; }

@media (max-width: 1200px) {
  .app, .app.no-info { grid-template-columns: 320px 1fr; }
  .pane-info { position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 100%); z-index: 20; box-shadow: -10px 0 40px rgba(0,0,0,.5); }
  .app.no-info .pane-info { display: none; }
}

@media (max-width: 760px) {
  .app, .app.no-info { grid-template-columns: 1fr; }
  .pane-chat { display: none; }
  .app.chat-open .pane-list { display: none; }
  .app.chat-open .pane-chat { display: flex; }
  .only-mobile { display: grid; }
  .messages { padding: 10px 8px; }
  .msg { max-width: 88%; }
  .msg .reply-btn { display: none; }
  .send-as { padding-left: 4px; }
}
