/* Thread page — multi-employee chat thread */

/* ── Layout ───────────────────────────────────────────────── */

.thread-layout {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--cream);
}

.thread-body {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */

.thread-sidebar {
  width: 240px;
  min-width: 240px;
  height: 100vh;
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.ts-top {
  padding: 14px 12px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ts-new-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: var(--navy);
  color: var(--cream);
  border: none;
  border-radius: 3px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: opacity 0.15s;
}
.ts-new-btn:hover { opacity: 0.85; }
.ts-new-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.ts-threads {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}
.ts-threads::-webkit-scrollbar { width: 4px; }
.ts-threads::-webkit-scrollbar-track { background: transparent; }
.ts-threads::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.ts-thread-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.12s;
}
.ts-thread-item:hover { background: var(--cream); }
.ts-thread-item.active {
  background: var(--cream);
  border-left: 2px solid var(--navy);
}
.ts-thread-item.active .ts-thread-label { color: var(--navy); font-weight: 500; padding-left: 12px; }

.ts-thread-label {
  flex: 1;
  min-width: 0;
  padding: 9px 6px 9px 14px;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  background: none;
  border: none;
}

.ts-thread-del {
  padding: 6px 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
  flex-shrink: 0;
}
.ts-thread-item:hover .ts-thread-del { opacity: 1; }
.ts-thread-del:hover { color: #dc2626; }
.ts-thread-del svg { width: 13px; height: 13px; display: block; }

.ts-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ts-footer-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  border-radius: 3px;
  transition: background 0.12s, color 0.12s;
}
.ts-footer-link:hover { background: var(--cream); color: var(--text); }
.ts-footer-link svg { width: 16px; height: 16px; flex-shrink: 0; }

.ts-footer-user {
  padding: 4px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.ts-footer-user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ts-footer-user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-add-members-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
  margin-left: 6px;
}
.thread-add-members-btn:hover { background: var(--cream); color: var(--navy); }
.thread-add-members-btn svg { width: 12px; height: 12px; }

/* ── Main area ────────────────────────────────────────────── */

.thread-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.thread-main header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
  flex-shrink: 0;
}

.thread-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.thread-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-participants {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.thread-participant-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 5px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}

.thread-participant-chip .chip-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--cream);
  font-size: 9px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.thread-participant-chip .chip-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Chat container ───────────────────────────────────────── */

#thread-chat-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
}

#thread-chat-container::-webkit-scrollbar { width: 5px; }
#thread-chat-container::-webkit-scrollbar-track { background: transparent; }
#thread-chat-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.thread-welcome {
  margin: auto;
  text-align: center;
  padding: 48px 24px;
  max-width: 480px;
}

.thread-welcome h2 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 28px;
  font-weight: 400;
  color: var(--navy);
  margin: 0 0 8px;
}

.thread-welcome p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}

/* ── Messages ─────────────────────────────────────────────── */

.thread-message {
  display: flex;
  gap: 12px;
  padding: 10px 24px;
  max-width: 900px;
  width: 100%;
  align-self: flex-start;
}

.thread-message.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.thread-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--cream);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.thread-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-message .thread-msg-avatar {
  background: var(--border);
  color: var(--text-muted);
  font-size: 10px;
}

.thread-msg-content {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  max-width: 600px;
}

.thread-msg-name {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.user-message .thread-msg-name {
  text-align: right;
}

.thread-msg-bubble {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}

.user-message .thread-msg-bubble {
  background: var(--navy);
  color: var(--cream);
  border-color: var(--navy);
}

.thread-msg-bubble p { margin: 0 0 10px; }
.thread-msg-bubble p:last-child { margin-bottom: 0; }

.msg-text p { margin: 0 0 10px; }
.msg-text p:last-child { margin-bottom: 0; }

/* Thinking indicator */
.thread-thinking {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px;
  min-width: 80px;
}

.thread-thinking-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.thread-thinking span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--navy);
  animation: thread-pulse 1.4s ease-in-out infinite;
  opacity: 0.25;
}

.thread-thinking span:nth-child(2) { animation-delay: 0.2s; }
.thread-thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thread-pulse {
  0%, 60%, 100% { transform: scale(1); opacity: 0.25; }
  30% { transform: scale(1.5); opacity: 1; box-shadow: 0 0 6px rgba(47, 59, 82, 0.5); }
}

.thread-thinking-status {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  animation: thread-status-fade 0.4s ease-in;
}

.thread-thinking-long {
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 2px;
  animation: thread-status-fade 0.5s ease-in;
}

@keyframes thread-status-fade {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Target employee selector ─────────────────────────────── */

.thread-target-bar {
  padding: 8px 24px 4px;
  border-top: 1px solid var(--border);
  background: var(--white);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.thread-target-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.thread-target-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 6px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.thread-target-btn.selected {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--cream);
}

.thread-target-btn .btn-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 8px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.thread-target-btn.selected .btn-avatar {
  background: rgba(255,255,255,0.2);
  color: var(--cream);
}

.thread-target-btn .btn-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Input bar ────────────────────────────────────────────── */

.thread-footer {
  padding: 12px 24px 16px;
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.thread-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s;
}

.thread-input-row:focus-within { border-color: var(--navy); }

#thread-message-input {
  flex: 1;
  border: none;
  background: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--text);
  resize: none;
  outline: none;
  min-height: 22px;
  max-height: 160px;
  line-height: 1.5;
}

#thread-message-input::placeholder { color: var(--text-muted); }

#thread-send-btn,
#thread-stop-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 4px;
  background: var(--navy);
  color: var(--cream);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

#thread-send-btn:hover,
#thread-stop-btn:hover { opacity: 0.85; }

#thread-send-btn svg,
#thread-stop-btn svg { width: 16px; height: 16px; }

.thread-footer-note {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* ── New thread modal ─────────────────────────────────────── */

.thread-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.thread-modal {
  background: var(--white);
  border-radius: 8px;
  padding: 28px;
  width: 420px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
}

.thread-modal h3 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 22px;
  font-weight: 400;
  color: var(--navy);
  margin: 0 0 20px;
}

.thread-modal-field {
  margin-bottom: 16px;
}

.thread-modal-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.thread-modal-field input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--cream);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.thread-modal-field input:focus { border-color: var(--navy); }

.thread-emp-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.thread-emp-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 8px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s;
}

.thread-emp-toggle.selected {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--cream);
}

.thread-emp-toggle .emp-av {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.thread-emp-toggle.selected .emp-av {
  background: rgba(255,255,255,0.2);
  color: var(--cream);
}

.thread-emp-toggle .emp-av img { width: 100%; height: 100%; object-fit: cover; }

.thread-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  justify-content: flex-end;
}

.thread-modal-cancel {
  padding: 9px 18px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s;
}

.thread-modal-cancel:hover { background: var(--cream); }

.thread-modal-create {
  padding: 9px 20px;
  background: var(--navy);
  color: var(--cream);
  border: none;
  border-radius: 4px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.thread-modal-create:hover { opacity: 0.85; }
.thread-modal-create:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Back button ──────────────────────────────────────────── */

.thread-back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.12s;
}

.thread-back-btn:hover { color: var(--text); }
.thread-back-btn svg { width: 16px; height: 16px; }
