/* =====================================================================
   chat.css — task-based messaging widget (WhatsApp-style). Self-contained,
   hard-coded colours so it renders identically on every page. Injected and
   driven by JS/chat.js; only shown to signed-in users.
   ===================================================================== */

/* ── Launcher badge (added to the trigger button/icon) ── */
.tp-chat-badge {
  position: absolute;
  top: -5px; right: -5px;
  box-sizing: border-box;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.64rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  pointer-events: none;
}
.tp-chat-trigger { position: relative; }

/* A launcher injected into the console topbar (left side). */
.tp-chat-launch {
  position: relative;
  width: 38px; height: 38px;
  border: 1.5px solid #c4cfe3;
  border-radius: 50%;
  background: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--chat-muted, #64748b); cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  flex-shrink: 0;
}
.tp-chat-launch:hover { border-color: #3b82f6; color: #3b82f6; }

/* ── Overlay + panel ── */
.tp-chat-overlay {
  position: fixed; inset: 0;
  background: transparent;
  z-index: 999;
}
.tp-chat {
  position: fixed;
  top: 72px; left: 22px;
  width: 640px;
  height: 520px;
  max-height: calc(100vh - 96px);
  background: var(--chat-surface, #fff);
  border: 1px solid var(--chat-border, #e8edf6);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(2,12,69,0.22);
  display: flex;
  overflow: hidden;
  z-index: 1000;
  font-family: 'DM Sans', sans-serif;
  animation: tpChatIn 0.16s ease;
}
@keyframes tpChatIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Contacts list (left pane) ── */
.tp-chat-list {
  width: 244px;
  flex-shrink: 0;
  border-right: 1px solid var(--chat-border, #e8edf6);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.tp-chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
}
.tp-chat-head h3 { font-family: 'Sora', sans-serif; font-size: 1.05rem; color: var(--chat-text, #020C45); margin: 0; }
.tp-chat-close {
  border: none; background: none; cursor: pointer;
  color: var(--chat-muted, #64748b); font-size: 1.4rem; line-height: 1; padding: 0 2px;
}
.tp-chat-close:hover { color: var(--chat-text, #020C45); }
.tp-chat-search { padding: 0 12px 10px; }
.tp-chat-search input {
  width: 100%;
  border: 1.5px solid var(--chat-border, #e8edf6);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: inherit; font-size: 0.85rem; color: var(--chat-text, #0f1f4b);
  background: var(--chat-bg2, #f8faff); outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.tp-chat-search input:focus { border-color: #3b82f6; background: var(--chat-surface, #fff); box-shadow: 0 0 0 3px rgba(80,162,255,0.15); }
.tp-chat-contacts { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.tp-chat-contact {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  transition: background 0.12s;
}
.tp-chat-contact:hover { background: var(--chat-bg2, #f8faff); }
.tp-chat-contact.active { background: rgba(59,130,246,0.10); }
.tp-chat-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 0.8rem;
  /* default fill (JS may override per-user); gradient matches the jobs-page .nav-avatar */
  background: linear-gradient(135deg, #3b82f6, #020C45);
}
.tp-chat-c-body { min-width: 0; flex: 1; }
.tp-chat-c-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.tp-chat-c-name { font-weight: 600; font-size: 0.86rem; color: var(--chat-text, #020C45); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-chat-c-time { font-size: 0.68rem; color: var(--chat-muted, #64748b); flex-shrink: 0; }
.tp-chat-c-task { font-size: 0.72rem; color: #3b82f6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-chat-c-last { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tp-chat-c-preview { font-size: 0.78rem; color: var(--chat-muted, #64748b); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-chat-c-unread {
  box-sizing: border-box;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: #00c27a; color: #fff; font-size: 0.66rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* ── Conversation (right pane) ── */
.tp-chat-convo { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg2, #f8faff); position: relative; /* anchors .tp-chat-newpill */ }
.tp-chat-convo-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--chat-surface, #fff); border-bottom: 1px solid var(--chat-border, #e8edf6);
}
.tp-chat-back { display: none; border: none; background: none; cursor: pointer; color: var(--chat-muted, #64748b); font-size: 1.4rem; line-height: 1; padding: 0 4px 0 0; }
.tp-chat-convo-meta { min-width: 0; }
.tp-chat-convo-name { font-weight: 600; font-size: 0.9rem; color: var(--chat-text, #020C45); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── QA dark-mode: console pages need the chat panel vars too (public pages set these in styles.css) ── */
body.console.dark {
  --chat-surface: #111a38; --chat-bg2: #0b1226; --chat-border: #26325c;
  --chat-text: #dbe4f8; --chat-muted: #93a3c8; --chat-chip: rgba(255,255,255,0.08);
}
.tp-chat-convo-task { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; font-size: 0.74rem; color: #3b82f6; text-decoration: none; }
.tp-chat-convo-task .tp-chat-convo-task-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-chat-convo-task:hover { text-decoration: underline; }
.tp-chat-task-arrow { flex-shrink: 0; }
.tp-chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.tp-chat-msg { max-width: 74%; padding: 8px 12px; border-radius: 12px; font-size: 0.84rem; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; /* multi-line messages keep their line breaks */ }
.tp-chat-msg.them { align-self: flex-start; background: var(--chat-surface, #fff); border: 1px solid var(--chat-border, #e8edf6); color: var(--chat-text, #0f1f4b); border-bottom-left-radius: 4px; }
.tp-chat-msg.me { align-self: flex-end; background: #3b82f6; color: #fff; border-bottom-right-radius: 4px; }
.tp-chat-msg-time { display: block; font-size: 0.64rem; margin-top: 3px; opacity: 0.7; }
.tp-chat-day { align-self: center; font-size: 0.68rem; color: var(--chat-muted, #64748b); background: var(--chat-chip, #eef2fb); padding: 3px 10px; border-radius: 10px; margin: 4px 0; }
.tp-chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--chat-muted, #64748b); font-size: 0.88rem; padding: 24px; }

.tp-chat-compose { display: flex; gap: 8px; padding: 12px 16px; background: var(--chat-surface, #fff); border-top: 1px solid var(--chat-border, #e8edf6); align-items: flex-end; }
.tp-chat-compose input,
.tp-chat-compose textarea {
  flex: 1; border: 1.5px solid var(--chat-border, #e8edf6); border-radius: 20px;
  padding: 9px 14px; font-family: inherit; font-size: 0.85rem; color: var(--chat-text, #0f1f4b);
  background: var(--chat-bg2, #f8faff); outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  /* Auto-growing composer (chat.js caps growth at ~4 rows / 96px). */
  resize: none; max-height: 96px; line-height: 1.4; overflow-y: auto;
}
.tp-chat-compose input:focus,
.tp-chat-compose textarea:focus { border-color: #3b82f6; background: var(--chat-surface, #fff); box-shadow: 0 0 0 3px rgba(80,162,255,0.15); }

/* "New messages ↓" pill: floats above the composer while the user is reading
   history and unseen messages arrive (chat.js showNewPill). */
.tp-chat-newpill {
  position: absolute;
  bottom: 74px; left: 50%; transform: translateX(-50%);
  border: none; border-radius: 999px;
  background: #3b82f6; color: #fff;
  font-family: inherit; font-size: 0.78rem; font-weight: 600;
  padding: 7px 14px; cursor: pointer;
  box-shadow: 0 6px 18px rgba(2,12,69,0.28);
}
.tp-chat-newpill:hover { background: #1d4ed8; }
.tp-chat-send {
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: #3b82f6; color: #fff; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.tp-chat-send:hover { background: #1d4ed8; }

/* ── Mobile: single pane, full screen ── */
@media (max-width: 680px) {
  /* dvh tracks the visual viewport, so the composer stays above the software
     keyboard on iOS Safari; plain % is the fallback for older engines. */
  .tp-chat { inset: 0; top: 0; right: 0; width: 100%; height: 100%; height: 100dvh; max-height: none; border-radius: 0; border: none; }
  .tp-chat-list { width: 100%; }
  .tp-chat-convo { display: none; }
  .tp-chat.show-convo .tp-chat-list { display: none; }
  .tp-chat.show-convo .tp-chat-convo { display: flex; }
  .tp-chat-back { display: block; }
}
