/* ---------------------------------------------------------------------------
   Agent Group — v5: task channels (Telegram-style chat list + threads, LIVE)
   ------------------------------------------------------------------------- */

:root {
  --bg: #0e1621;          /* chat background (Telegram dark) */
  --backdrop: #0a0f16;    /* subtle backdrop behind the phone column */
  --header: #17212b;      /* header / input bar / list rows */
  --pinned: #1c2a38;      /* pinned bar (slightly lighter than header) */
  --bubble-in: #182533;   /* incoming bubble */
  --bubble-out: #2b5278;  /* outgoing bubble */
  --accent: #3390ec;      /* accent blue */
  --muted: #7f91a4;       /* muted text */
  --text: #e7ecf2;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--backdrop);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
}

/* Phone column */
.phone {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  box-shadow: 0 0 48px rgba(0, 0, 0, 0.55);
}

/* Screens (list vs thread) — one visible at a time */
.screen {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.screen.hidden { display: none; }

/* -------------------------------------------------------------------------
   Header (shared)
   ------------------------------------------------------------------------- */
.chat-header,
.list-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  background: var(--header);
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.avatar-p {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #3390ec, #7b5cd6);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.header-text {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 4px;
}

.header-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-text p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* -------------------------------------------------------------------------
   Connection indicator (list header subtitle)
   ------------------------------------------------------------------------- */
.status-line {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #5a6b7c; /* gray: offline */
}

.status-dot.live {
  background: #3ddc84; /* green: live */
}

/* -------------------------------------------------------------------------
   Search field (decorative)
   ------------------------------------------------------------------------- */
.search-field {
  flex-shrink: 0;
  padding: 2px 12px 8px;
  background: var(--header);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 18px;
  background: var(--bg);
  color: var(--muted);
  font-size: 15px;
}

.search-box svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

/* -------------------------------------------------------------------------
   Channel list
   ------------------------------------------------------------------------- */
.channel-list {
  flex: 1 1 auto;
  overflow-y: auto;
  background: var(--header);
}

.channel-list::-webkit-scrollbar { width: 6px; }
.channel-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

.channel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  background: var(--header);
  color: inherit;
  border: 0;
  border-bottom: 1px solid var(--bg);
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.channel-row:hover {
  background: #1b2733;
}

.channel-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  flex: 0 0 auto;
}

.channel-avatar.lg { width: 54px; height: 54px; font-size: 26px; }
.channel-avatar.sm { width: 40px; height: 40px; font-size: 20px; }

.channel-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.channel-name {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-preview {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-sender { font-weight: 600; }

.channel-right {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.channel-time {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.unread-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.list-footer {
  flex-shrink: 0;
  padding: 10px 16px;
  background: var(--header);
  border-top: 1px solid var(--bg);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* -------------------------------------------------------------------------
   Pinned bar
   ------------------------------------------------------------------------- */
.pinned {
  flex-shrink: 0;
  padding: 6px 12px;
  background: var(--pinned);
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid rgba(0, 0, 0, 0.18);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* -------------------------------------------------------------------------
   Chat stream (thread)
   ------------------------------------------------------------------------- */
.chat-stream {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-stream::-webkit-scrollbar { width: 6px; }
.chat-stream::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

/* Date divider */
.date-divider {
  align-self: center;
  margin: 4px 0 10px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--muted);
  font-size: 12px;
}

/* System notice */
.system-pill {
  align-self: center;
  margin: 2px 0;
  padding: 4px 12px;
  max-width: 90%;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}

/* -------------------------------------------------------------------------
   Messages
   ------------------------------------------------------------------------- */
.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 88%;
}

.msg.incoming { align-self: flex-start; }
.msg.outgoing { align-self: flex-end; }

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  position: relative;
}

.avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.msg-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.name {
  padding-left: 4px;
  font-size: 13px;
  font-weight: 600;
}

.bubble {
  position: relative;
  padding: 7px 10px 19px;
  border-radius: 12px;
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg.incoming .bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 4px;
  color: #e7ecf2;
}

.msg.outgoing .bubble {
  background: var(--bubble-out);
  border-bottom-right-radius: 4px;
  color: #fff;
}

.bubble strong { font-weight: 600; }

.meta {
  position: absolute;
  right: 9px;
  bottom: 4px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.msg.outgoing .meta { color: rgba(255, 255, 255, 0.6); }

.read-mark { color: var(--accent); }

/* -------------------------------------------------------------------------
   "New messages" floating pill (thread view)
   ------------------------------------------------------------------------- */
.new-messages-pill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 64px; /* just above the input bar */
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  z-index: 2;
}

.new-messages-pill:hover {
  background: #2f8ae6;
}

/* -------------------------------------------------------------------------
   Input bar (decorative)
   ------------------------------------------------------------------------- */
.input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--header);
  flex-shrink: 0;
}

.input-field {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  background: var(--header);
  color: var(--muted);
  font-size: 15px;
}

.send-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.send-btn svg {
  width: 20px;
  height: 20px;
}
