:root {
  --bg: #0e1621;
  --bg-2: #17212b;
  --bg-3: #202b36;
  --bg-hover: #2b5278;
  --bg-active: #2b5278;
  --text: #e9edef;
  --text-muted: #708499;
  --accent: #5288c1;
  --accent-2: #3390ec;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --divider: #0b131c;
  --danger: #e53935;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 72px 320px 1fr;
  height: 100vh;
}

/* ─── bots rail ─────────────────────────── */
.bots-rail {
  background: #0a121a;
  border-right: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  overflow-y: auto;
}
.bot-tab {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--bg-3);
  border: none;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: border-radius 0.18s, background 0.18s;
  text-transform: uppercase;
  user-select: none;
}
.bot-tab:hover { border-radius: 18px; }
.bot-tab.active {
  background: var(--accent-2);
  border-radius: 18px;
}
.bot-tab.active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 8px;
  bottom: 8px;
  width: 4px;
  background: var(--text);
  border-radius: 0 4px 4px 0;
}
.add-tab {
  background: transparent;
  color: var(--accent);
  border: 2px dashed #2b3a4a;
  font-size: 26px;
  font-weight: 300;
  margin-top: auto;
}
.add-tab:hover { background: rgba(82,136,193,0.1); }
.bot-tab .badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: var(--accent-2);
  color: #fff;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  font-size: 11px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #0a121a;
}

/* ─── chats pane ────────────────────────── */
.chats-pane {
  background: var(--bg-2);
  border-right: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chats-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--divider);
}
.chats-header .title { font-weight: 600; font-size: 16px; }
.chats-header .subtitle { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.search-box { padding: 8px 12px; }
.search-box input {
  width: 100%;
  background: var(--bg-3);
  border: none;
  border-radius: 20px;
  padding: 9px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.search-box input:focus { background: #283642; }

.chat-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; }
.chat-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  align-items: center;
  border-radius: 10px;
  margin: 1px 6px;
}
.chat-item:hover { background: #202b36; }
.chat-item.active { background: var(--accent-2); }
.chat-item.active .preview,
.chat-item.active .when { color: rgba(255,255,255,0.85); }
.chat-item .avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 18px;
  flex-shrink: 0;
}
.chat-item .info { flex: 1; min-width: 0; }
.chat-item .row1 { display: flex; justify-content: space-between; gap: 8px; }
.chat-item .name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .when { color: var(--text-muted); font-size: 11px; flex-shrink: 0; }
.chat-item .row2 { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }
.chat-item .preview {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.chat-item .unread {
  background: var(--accent-2);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
  font-weight: 600;
}
.chat-item.active .unread { background: #fff; color: var(--accent-2); }

.empty-hint { padding: 24px 16px; color: var(--text-muted); text-align: center; font-size: 13px; }

/* ─── messages pane ─────────────────────── */
.messages-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(82,136,193,0.06), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(82,136,193,0.05), transparent 50%),
    var(--bg);
}
.messages-header {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--divider);
  background: var(--bg-2);
}
.messages-header .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: #fff;
}
.messages-header .title { font-weight: 600; }
.messages-header .subtitle { color: var(--text-muted); font-size: 12px; }

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14% 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.placeholder {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
}
.placeholder .logo { font-size: 56px; margin-bottom: 8px; }

.msg-day {
  align-self: center;
  background: rgba(0,0,0,0.4);
  color: #fff;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  margin: 14px 0 6px;
}

.msg {
  max-width: 70%;
  padding: 6px 10px 18px;
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.35;
}
.msg.in {
  background: var(--bubble-in);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg.out {
  background: var(--bubble-out);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg .from {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 2px;
}
.msg.out .from { color: #91c1ff; }
.msg .media-tag {
  display: inline-block;
  background: rgba(255,255,255,0.08);
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 12px;
  margin-bottom: 4px;
  color: var(--text-muted);
}
.msg .time {
  position: absolute;
  right: 8px;
  bottom: 4px;
  font-size: 10px;
  color: var(--text-muted);
}
.msg.out .time { color: rgba(255,255,255,0.6); }

/* ─── composer ──────────────────────────── */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-2);
  border-top: 1px solid var(--divider);
}
.composer textarea {
  flex: 1;
  background: var(--bg-3);
  color: var(--text);
  border: none;
  outline: none;
  border-radius: 18px;
  padding: 10px 14px;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  max-height: 160px;
}
.send-btn {
  background: var(--accent-2);
  color: #fff;
  border: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.send-btn:hover { background: #4ca0f5; }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── modal ─────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--bg-2);
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.modal-card h3 { margin: 0 0 6px; }
.modal-card .muted { color: var(--text-muted); margin: 0 0 14px; font-size: 13px; }
.modal-card input {
  width: 100%;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid #2b3a4a;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  font-family: monospace;
}
.modal-card input:focus { border-color: var(--accent-2); }
.modal-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.btn.primary { background: var(--accent-2); color: #fff; }
.btn.primary:hover { background: #4ca0f5; }
.btn.ghost { background: transparent; color: var(--text-muted); }
.btn.ghost:hover { color: var(--text); }

/* ─── context menu ──────────────────────── */
.ctx-menu {
  position: fixed;
  background: var(--bg-3);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  z-index: 200;
  min-width: 180px;
}
.ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.ctx-menu button:hover { background: var(--bg-hover); }
.ctx-menu button[data-act="remove"] { color: var(--danger); }

/* avatar palette colors set inline via JS */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #2b3a4a; border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }
