:root {
  --brand: #2AABEE;
  --brand-dark: #1c8ed6;
  --brand-gradient: linear-gradient(135deg, #2AABEE 0%, #229ED9 100%);
  --sidebar-bg: #10182B;
  --sidebar-bg-active: #1a2540;
  --sidebar-text: #aab4cc;
  --sidebar-text-active: #ffffff;
  --page-bg: #f2f4f9;
  --card-bg: #ffffff;
  --border-color: #e6e9f0;
  --text-main: #1f2430;
  --text-muted: #6b7385;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 14px;
  --shadow-soft: 0 2px 10px rgba(20, 30, 60, 0.06);
  --shadow-card: 0 4px 18px rgba(20, 30, 60, 0.08);
}

* { box-sizing: border-box; }

body {
  background: var(--page-bg);
  color: var(--text-main);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
}

a { text-decoration: none; }

/* ---------------- App shell ---------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 8px 10px 26px 10px;
}
.sidebar-brand i { color: var(--brand); font-size: 1.3rem; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--sidebar-text);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: .93rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.side-link i { width: 18px; text-align: center; font-size: 1.05rem; }
.side-link:hover { background: var(--sidebar-bg-active); color: #fff; }
.side-link.active { background: var(--brand-gradient); color: #fff; }

.sidebar-footer { display: flex; flex-direction: column; gap: 4px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 10px; }

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

.topbar {
  height: 68px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title { font-size: 1.2rem; font-weight: 700; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.admin-name { color: var(--text-muted); font-size: .9rem; }
.admin-name i { margin-right: 5px; }

.content-area { padding: 26px; flex: 1; min-width: 0; }

/* ---------------- Status pill ---------------- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  background: #eef0f5;
  color: var(--text-muted);
}
.status-pill i { font-size: .55rem; }
.status-connected { background: #e7f9ee; color: #15803d; }
.status-connecting { background: #fff7e6; color: #b45309; }
.status-error { background: #fdecec; color: #b91c1c; }
.status-disconnected { background: #eef0f5; color: var(--text-muted); }
.status-unknown { background: #eef0f5; color: var(--text-muted); }

/* ---------------- Cards / stat grid (Dashboard) ---------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-icon {
  width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.2rem; flex-shrink: 0;
}
.bg-blue { background: linear-gradient(135deg,#2AABEE,#1c8ed6); }
.bg-green { background: linear-gradient(135deg,#34d399,#059669); }
.bg-purple { background: linear-gradient(135deg,#a78bfa,#7c3aed); }
.bg-orange { background: linear-gradient(135deg,#fbbf24,#d97706); }
.stat-value { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.stat-label { color: var(--text-muted); font-size: .85rem; margin-top: 2px; }

.dash-row { display: grid; grid-template-columns: 1fr 1.3fr; gap: 18px; align-items: start; }

.card-panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 22px;
}
.panel-title { font-size: 1.02rem; font-weight: 700; margin: 0 0 14px 0; }

.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.recent-list li { display: flex; align-items: center; gap: 10px; padding: 10px 6px; border-radius: 8px; font-size: .88rem; }
.recent-list li:hover { background: var(--page-bg); }
.recent-name { font-weight: 600; color: var(--text-main); white-space: nowrap; }
.recent-preview { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.recent-time { color: var(--text-muted); font-size: .78rem; white-space: nowrap; }

/* ---------------- Bot status table ---------------- */
.bot-status-table { margin: 18px 0; font-size: .88rem; }
.bot-status-table th { color: var(--text-muted); font-weight: 600; width: 45%; white-space: nowrap; padding-right: 14px; }
.bot-status-table td { word-break: break-all; }

/* ---------------- Login page ---------------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-gradient);
}
.login-card {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}
.login-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 1.2rem; margin-bottom: 4px;
}
.login-brand i { color: var(--brand); font-size: 1.5rem; }
.login-sub { color: var(--text-muted); font-size: .88rem; margin-bottom: 22px; }
.login-hint { color: var(--text-muted); font-size: .78rem; margin-top: 18px; margin-bottom: 0; text-align: center; }

/* ---------------- Chat layout ---------------- */
.chat-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  height: calc(100vh - 68px - 52px);
}

.chat-list-pane, .chat-conversation-pane {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-list-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}
.search-form { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--page-bg); border-radius: 10px; padding: 8px 12px; }
.search-form i { color: var(--text-muted); }
.search-form input { border: none; background: transparent; outline: none; width: 100%; font-size: .88rem; }
.btn-new-chat {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  background: var(--brand-gradient); color: #fff; font-size: 1rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.chat-list { overflow-y: auto; flex: 1; padding: 8px; }
.chat-list-item {
  display: flex; gap: 12px; padding: 12px; border-radius: 12px; align-items: center;
  color: var(--text-main);
}
.chat-list-item:hover { background: var(--page-bg); }
.chat-list-item.active { background: #e8f4fd; }
.chat-list-item-body { min-width: 0; flex: 1; }
.chat-list-item-top { display: flex; justify-content: space-between; gap: 8px; }
.chat-name { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: .72rem; color: var(--text-muted); white-space: nowrap; }
.chat-preview { font-size: .82rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-blocked { background: var(--danger); color: #fff; font-size: .65rem; padding: 1px 6px; border-radius: 6px; margin-right: 5px; }

.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--brand-gradient); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1rem;
}

.conversation-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border-color);
}
.conversation-name { font-weight: 700; }
.conversation-sub { font-size: .78rem; color: var(--text-muted); display: flex; gap: 10px; }

.message-list {
  flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 2px;
  background: #f8f9fc;
}

.msg-row { display: flex; margin: 4px 0; }
.msg-row-in { justify-content: flex-start; }
.msg-row-out { justify-content: flex-end; }

.msg-bubble {
  max-width: 62%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: .89rem;
  line-height: 1.4;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.msg-in { background: #fff; border-bottom-left-radius: 4px; }
.msg-out { background: var(--brand-gradient); color: #fff; border-bottom-right-radius: 4px; }
.msg-failed { outline: 2px solid var(--danger); }

.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-text-muted { opacity: .8; font-style: italic; }
.msg-meta { display: flex; align-items: center; gap: 6px; justify-content: flex-end; font-size: .68rem; opacity: .75; margin-top: 4px; }
.msg-admin { font-weight: 600; }
.msg-status-failed { color: #ffe1e1; }

.msg-media-img { max-width: 260px; border-radius: 10px; display: block; margin-bottom: 4px; }
.msg-media-video { max-width: 260px; border-radius: 10px; display: block; margin-bottom: 4px; }
.msg-media-audio { display: block; margin-bottom: 4px; max-width: 240px; }
.msg-media-file { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: underline; }

.composer {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--border-color);
}
.composer input[type=text] {
  flex: 1; border: 1px solid var(--border-color); border-radius: 999px;
  padding: 11px 18px; font-size: .9rem; outline: none;
}
.composer input[type=text]:focus { border-color: var(--brand); }
.composer-attach, .composer-send {
  width: 42px; height: 42px; border-radius: 50%; border: none; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
}
.composer-attach { background: var(--page-bg); color: var(--text-muted); }
.composer-send { background: var(--brand-gradient); color: #fff; }
.composer-blocked { padding: 16px 18px; text-align: center; color: var(--danger); font-size: .88rem; border-top: 1px solid var(--border-color); }

.attach-preview {
  display: flex; align-items: center; gap: 8px; padding: 8px 18px;
  border-top: 1px solid var(--border-color); font-size: .85rem; color: var(--text-muted);
}

.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); gap: 10px; text-align: center; padding: 20px;
}
.empty-state i { font-size: 2.6rem; opacity: .4; }
.empty-state-small { padding: 24px; text-align: center; color: var(--text-muted); font-size: .85rem; }

/* ---------------- Toasts ---------------- */
#toastHost { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.zt-toast {
  background: #1f2430; color: #fff; padding: 12px 16px; border-radius: 10px;
  font-size: .85rem; box-shadow: 0 8px 24px rgba(0,0,0,.2); min-width: 220px;
}
.zt-toast.err { background: #b91c1c; }
.zt-toast.ok { background: #15803d; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .sidebar { width: 74px; padding: 16px 10px; }
  .sidebar-brand span, .side-link span { display: none; }
  .sidebar-brand { justify-content: center; padding: 8px 0 22px 0; }
  .side-link { justify-content: center; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-row { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .msg-bubble { max-width: 85%; }
}
