/* ========== THREAD PANEL ========== */

/* Panel Container */
.thread-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100%;
  background: var(--bg-paper);
  border-left: 1px dashed var(--divider);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s;
  box-shadow: var(--shadow-dialog);
}

.thread-panel.active {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

/* Panel Header */
.thread-panel-header {
  padding: 16px 24px;
  border-bottom: 1px dashed var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-height);
  background: var(--bg-paper);
}

.thread-panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.thread-panel-title i { color: var(--primary); }

.thread-reply-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Panel Body */
.thread-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Parent Message */
.thread-parent {
  padding: 16px;
  background: var(--bg-neutral);
  border-radius: calc(var(--radius) * 2);
  border-left: 3px solid var(--primary);
}

.thread-parent-sender {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.thread-parent-sender img {
  width: 24px;
  height: 24px;
  border-radius: var(--radius);
  object-fit: cover;
}

.thread-parent-text {
  font-size: 0.875rem;
  color: var(--text-primary);
  line-height: 1.6;
  word-break: break-word;
}

.thread-parent-time {
  font-size: 0.6875rem;
  color: var(--text-disabled);
  margin-top: 8px;
}

.thread-starred-indicator {
  color: var(--warning);
  margin-left: 6px;
}

/* Thread Divider */
.thread-divider {
  text-align: center;
  padding: 4px 0;
}

.thread-divider span {
  background: var(--bg-paper);
  color: var(--text-disabled);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 16px;
  box-shadow: var(--shadow-z1);
}

/* Thread Replies */
.thread-replies {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.thread-reply {
  display: flex;
  gap: 10px;
}

.thread-reply.thread-new {
  animation: msgIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.thread-reply.sent { flex-direction: row-reverse; }

.thread-reply-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  flex-shrink: 0;
  overflow: hidden;
}

.thread-reply-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
}

.thread-reply-bubble {
  padding: 10px 14px;
  border-radius: calc(var(--radius) * 2);
  font-size: 0.8125rem;
  line-height: 1.6;
  max-width: 75%;
}

.thread-reply:not(.sent) .thread-reply-bubble {
  background: var(--bg-neutral);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius);
}

.thread-reply.sent .thread-reply-bubble {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border-bottom-right-radius: var(--radius);
  box-shadow: var(--shadow-primary);
}

/* Same-sender grouping */
.thread-reply.same-sender {
  margin-top: -8px;
}

.thread-reply-avatar-spacer {
  width: 32px;
  flex-shrink: 0;
}

.thread-reply.same-sender:not(.sent) .thread-reply-bubble {
  border-top-left-radius: var(--radius);
}

.thread-reply.same-sender.sent .thread-reply-bubble {
  border-top-right-radius: var(--radius);
}

.thread-reply-sender {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 4px;
}

.thread-reply-text { word-break: break-word; }

.thread-reply-time {
  font-size: 0.625rem;
  opacity: 0.7;
  margin-top: 4px;
}

.thread-edited {
  font-style: italic;
  margin-left: 4px;
}

.thread-reply.sent .msg-inline-edit-input {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.3);
  color: white;
}

.thread-reply.sent .msg-inline-edit-input::placeholder {
  color: rgba(255,255,255,0.8);
}

.thread-reply.sent .msg-inline-edit-btn {
  background: rgba(255,255,255,0.2);
  color: white;
}

.thread-reply.sent .msg-inline-edit-btn:hover {
  background: rgba(255,255,255,0.3);
}

.thread-reply.sent .msg-inline-edit-btn.primary {
  background: white;
  color: var(--primary-dark);
}

.thread-reply.sent .thread-reply-time { text-align: right; }

/* Thread Reply Media */
.thread-reply-media {
  border-radius: var(--radius);
  max-width: 200px;
  margin-bottom: 6px;
  overflow: hidden;
}

.thread-reply-media img,
.thread-reply-media video {
  width: 100%;
  display: block;
  border-radius: var(--radius);
}

.thread-media-clickable { cursor: pointer; }

.thread-reply-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(145, 158, 171, 0.12);
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
  margin-bottom: 6px;
}

.thread-reply.sent .thread-reply-file {
  background: rgba(255, 255, 255, 0.15);
}

/* Thread Media Preview */
.thread-media-preview {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 8px 24px;
  background: var(--bg-paper);
  border-top: 1px dashed var(--divider);
}

.thread-media-preview.active { display: flex; }

.thread-media-thumb {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.thread-media-thumb img {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  object-fit: cover;
}

.thread-media-thumb video {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  object-fit: cover;
}

.thread-media-thumb span {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Thread Input Actions */
.thread-input-actions {
  display: flex;
  gap: 2px;
}

/* Thread Input Area */
.thread-input-area {
  padding: 12px 24px 16px;
  background: var(--bg-paper);
  border-top: 1px dashed var(--divider);
}

.thread-input-area .input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-neutral);
  padding: 8px 12px;
  border-radius: calc(var(--radius) * 2);
  transition: var(--transition);
}

.thread-input-area .input-wrapper:focus-within {
  background: var(--bg-paper);
  box-shadow: 0 0 0 2px var(--primary);
}

.thread-input-area .send-btn {
  width: 36px;
  height: 36px;
}

/* Thread Reply Count on Messages (main chat) */
.msg-thread-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 4px 10px;
  background: rgba(0, 167, 111, 0.08);
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  transition: var(--transition);
  border: none;
  font-family: inherit;
}

.msg-thread-link:hover {
  background: rgba(0, 167, 111, 0.16);
  transform: translateY(-1px);
}

.msg-thread-link i { font-size: 0.625rem; }

.message-wrapper.sent .msg-thread-link {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.message-wrapper.sent .msg-thread-link:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* chatView needs relative positioning for the absolute thread panel */
#chatView {
  position: relative;
  overflow: hidden;
  min-height: 0;
}

/* Responsive: Thread Panel on Mobile */
@media (max-width: 768px) {
  .thread-panel {
    width: 100%;
    border-left: none;
  }
}
