/* Block Comments Panel Styles */

/* Push main content when comment panel is open (desktop only) */
@media (min-width: 769px) {
  body:has(.block-comments-panel.visible) .main-content {
    margin-right: 400px;
  }
}

/* Panel Container - slides in from right like block-history */
.block-comments-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  height: 100vh;
  background: var(--bs-body-bg, #fff);
  border-left: 1px solid var(--bs-border-color, #dee2e6);
  box-shadow: -4px 0 15px rgba(0, 0, 0, 0.1);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  /* Use transform instead of right position so panel fully hides regardless of width */
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow: hidden;
}

.block-comments-panel.visible {
  transform: translateX(0);
}

/* Resize Handle - left edge of panel */
.comments-panel-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
  background: transparent;
  z-index: 10;
  transition: background 0.2s ease;
}

.comments-panel-resize-handle:hover,
.comments-panel-resize-handle:active {
  background: var(--bs-primary, #0d6efd);
  opacity: 0.3;
}

/* Panel Header */
.comments-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--bs-tertiary-bg, #f8f9fa);
}

.comments-panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--bs-body-color, #212529);
}

.comments-panel-title i {
  color: var(--bs-primary, #0d6efd);
}

.comments-panel-close {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--bs-secondary, #6c757d);
  border-radius: 4px;
  transition: background-color 0.2s;
}

.comments-panel-close:hover {
  background: var(--bs-secondary-bg, #e9ecef);
  color: var(--bs-body-color, #212529);
}

/* Panel Content (scrollable comment list) */
.comments-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* Loading, Error, Empty States */
.comments-loading,
.comments-error,
.comments-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--bs-secondary, #6c757d);
  gap: 0.75rem;
  text-align: center;
}

.comments-loading i {
  font-size: 1.5rem;
  color: var(--bs-primary, #0d6efd);
}

.comments-empty i {
  font-size: 2.5rem;
  opacity: 0.5;
}

.comments-empty p {
  font-size: 0.85rem;
  margin: 0.5rem 0 0 0;
}

.comments-error {
  color: var(--bs-danger, #dc3545);
}

/* Comment List */
.comments-list {
  padding: 0.5rem 0;
}

/* Individual Comment */
.comment-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  transition: background-color 0.15s;
}

.comment-item:hover {
  background: var(--bs-tertiary-bg, #f8f9fa);
}

/* Avatar */
.comment-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.comment-avatar-initials {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bs-primary, #0d6efd);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.comment-avatar-emoji {
  font-size: 1.5rem;
  line-height: 1;
}

.comment-avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

/* Comment Body */
.comment-body {
  flex: 1;
  min-width: 0;
}

.comment-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.comment-author {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--bs-body-color, #212529);
}

.comment-author-persona {
  color: #6f42c1;
}

.comment-time {
  font-size: 0.75rem;
  color: var(--bs-secondary, #6c757d);
}

.comment-content {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--bs-body-color, #212529);
  word-break: break-word;
}

/* @Mention highlights in comments */
.comment-mention {
  background: #e7f1ff;
  color: var(--bs-primary, #0d6efd);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-weight: 500;
  font-size: 0.85em;
}

.comment-mention.mention-persona {
  background: #f3e8ff;
  color: #6f42c1;
}

/* Markdown styling in comments */
.comment-content strong {
  font-weight: 600;
}

.comment-content em {
  font-style: italic;
}

.comment-content code {
  background: var(--bs-tertiary-bg, #f8f9fa);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.85em;
  color: #d63384;
}

.comment-content .comment-list-item {
  display: block;
  padding-left: 0.5rem;
  margin: 0.25rem 0;
}

.comment-content .comment-list-item:first-of-type {
  margin-top: 0.5rem;
}

.comment-content .comment-list-item:last-of-type {
  margin-bottom: 0.5rem;
}

/* ─────────────────────────────────────────────────
   COMMENT ACTIONS (edit/delete)
   ───────────────────────────────────────────────── */

.comment-actions {
  display: none;
  margin-left: auto;
  gap: 2px;
}

.comment-item:hover .comment-actions {
  display: inline-flex;
}

.comment-action-btn {
  background: none;
  border: none;
  padding: 2px 5px;
  cursor: pointer;
  color: var(--bs-secondary, #6c757d);
  font-size: 0.75rem;
  border-radius: 3px;
  transition: color 0.15s, background-color 0.15s;
}

.comment-action-btn:hover {
  color: var(--bs-primary, #0d6efd);
  background: var(--bs-primary-bg-subtle, #e7f1ff);
}

.comment-action-delete:hover {
  color: var(--bs-danger, #dc3545);
  background: #fde8e8;
}

.comment-edited {
  font-size: 0.7rem;
  color: var(--bs-secondary, #6c757d);
  font-style: italic;
}

/* Edit inline */
.comment-edit-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.comment-edit-input {
  width: 100%;
  min-height: 60px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--bs-primary, #0d6efd);
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
  outline: none;
  font-family: inherit;
  background: var(--bs-body-bg, #fff);
  color: var(--bs-body-color, #212529);
}

.comment-edit-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}

.comment-edit-save,
.comment-edit-cancel {
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.comment-edit-save {
  background: var(--bs-primary, #0d6efd);
  color: #fff;
}

.comment-edit-save:hover {
  background: #0b5ed7;
}

.comment-edit-cancel {
  background: var(--bs-secondary-bg, #e9ecef);
  color: var(--bs-body-color, #212529);
}

.comment-edit-cancel:hover {
  background: #d3d4d5;
}

/* ─────────────────────────────────────────────────
   PERSONA TYPING INDICATOR
   ───────────────────────────────────────────────── */

.comment-typing {
  opacity: 0.7;
}

.comment-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0.4rem 0;
}

.comment-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6f42c1;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.comment-typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.comment-typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ─────────────────────────────────────────────────
   THINKING INDICATOR (Slack-style)
   ───────────────────────────────────────────────── */

.comments-thinking-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  color: var(--bs-secondary-color, #6c757d);
  font-size: 0.85rem;
}

.thinking-indicator-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.thinking-dots {
  display: inline-flex;
  gap: 3px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6f42c1;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }

.comments-stop-btn {
  background: none;
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.8rem;
  color: var(--bs-secondary-color, #6c757d);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s, border-color 0.15s;
}

.comments-stop-btn:hover {
  color: var(--bs-danger, #dc3545);
  border-color: var(--bs-danger, #dc3545);
}

/* ─────────────────────────────────────────────────
   COMPOSE BOX
   ───────────────────────────────────────────────── */

.comments-panel-compose {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--bs-border-color, #dee2e6);
  background: var(--bs-tertiary-bg, #f8f9fa);
}

.comments-compose-wrapper {
  flex: 1;
  position: relative;
}

.comments-compose-input {
  min-height: 38px;
  max-height: 120px;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 8px;
  background: var(--bs-body-bg, #fff);
  font-size: 0.9rem;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
  word-break: break-word;
}

.comments-compose-input:focus {
  border-color: var(--bs-primary, #0d6efd);
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.15);
}

.comments-compose-input:empty:before {
  content: attr(data-placeholder);
  color: var(--bs-secondary, #6c757d);
  pointer-events: none;
}

/* Mention tags in the compose input */
.mention-tag {
  display: inline;
  background: #e7f1ff;
  color: var(--bs-primary, #0d6efd);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-weight: 500;
  font-size: 0.9em;
  user-select: all;
  white-space: nowrap;
}

.mention-tag[data-mention-type="persona"] {
  background: #f3e8ff;
  color: #6f42c1;
}

.comments-send-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--bs-primary, #0d6efd);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, opacity 0.2s;
  flex-shrink: 0;
}

.comments-send-btn:hover:not(:disabled) {
  background: #0b5ed7;
}

.comments-send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ─────────────────────────────────────────────────
   @MENTION TYPEAHEAD DROPDOWN
   ───────────────────────────────────────────────── */

.comments-mention-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bs-body-bg, #fff);
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 8px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  margin-bottom: 4px;
  z-index: 1060;
}

.mention-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: background-color 0.1s;
}

.mention-item:hover,
.mention-item.active {
  background: var(--bs-primary-bg-subtle, #e7f1ff);
}

.mention-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bs-primary, #0d6efd);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mention-avatar-persona {
  background: #f3e8ff;
  font-size: 1rem;
}

.mention-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.mention-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--bs-body-color, #212529);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mention-subtitle {
  font-size: 0.75rem;
  color: var(--bs-secondary, #6c757d);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─────────────────────────────────────────────────
   COMMENT COUNT BADGE (shown on blocks)
   ───────────────────────────────────────────────── */

.comment-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  color: var(--bs-secondary, #6c757d);
  font-size: 0.85rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  transition: color 0.15s, background-color 0.15s;
}

.comment-btn:hover {
  color: var(--bs-primary, #0d6efd);
  background: var(--bs-primary-bg-subtle, #e7f1ff);
}

.comment-count-badge {
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bs-primary, #0d6efd);
  color: #fff;
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  line-height: 1.3;
}

/* Unread indicator dot */
.comment-btn.has-unread {
  position: relative;
}

.comment-btn.has-unread .bi-chat-dots {
  color: var(--bs-primary, #0d6efd);
}

.comment-btn .unread-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 8px;
  background: var(--bs-danger, #dc3545);
  border-radius: 50%;
  border: 2px solid var(--bs-body-bg, #fff);
}

/* ─────────────────────────────────────────────────
   DARK MODE
   ───────────────────────────────────────────────── */

[data-bs-theme="dark"] .block-comments-panel {
  background: #1e1e1e;
  border-color: #333;
}

[data-bs-theme="dark"] .comments-panel-header,
[data-bs-theme="dark"] .comments-panel-compose {
  background: #2d2d2d;
  border-color: #333;
}

[data-bs-theme="dark"] .comments-panel-title {
  color: #e9ecef;
}

[data-bs-theme="dark"] .comments-panel-close {
  color: #adb5bd;
}

[data-bs-theme="dark"] .comments-panel-close:hover {
  background: #3d3d3d;
  color: #fff;
}

[data-bs-theme="dark"] .comment-item:hover {
  background: #2d2d2d;
}

[data-bs-theme="dark"] .comment-author {
  color: #e9ecef;
}

[data-bs-theme="dark"] .comment-content {
  color: #e9ecef;
}

[data-bs-theme="dark"] .comment-time {
  color: #adb5bd;
}

[data-bs-theme="dark"] .comment-mention {
  background: #1a2a3a;
  color: #6db3f2;
}

[data-bs-theme="dark"] .comment-mention.mention-persona {
  background: #2a1a3a;
  color: #b388ff;
}

[data-bs-theme="dark"] .comments-compose-input {
  background: #1e1e1e;
  border-color: #444;
  color: #e9ecef;
}

[data-bs-theme="dark"] .comments-compose-input:focus {
  border-color: #4a90e2;
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

[data-bs-theme="dark"] .comments-compose-input:empty:before {
  color: #6c757d;
}

[data-bs-theme="dark"] .mention-tag {
  background: #1a2a3a;
  color: #6db3f2;
}

[data-bs-theme="dark"] .mention-tag[data-mention-type="persona"] {
  background: #2a1a3a;
  color: #b388ff;
}

[data-bs-theme="dark"] .comments-mention-dropdown {
  background: #2d2d2d;
  border-color: #444;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
}

[data-bs-theme="dark"] .mention-item:hover,
[data-bs-theme="dark"] .mention-item.active {
  background: #3d3d3d;
}

[data-bs-theme="dark"] .mention-name {
  color: #e9ecef;
}

[data-bs-theme="dark"] .mention-subtitle {
  color: #adb5bd;
}

[data-bs-theme="dark"] .comments-loading,
[data-bs-theme="dark"] .comments-empty {
  color: #adb5bd;
}

[data-bs-theme="dark"] .comment-avatar-initials {
  background: #4a90e2;
}

[data-bs-theme="dark"] .comment-btn:hover {
  color: #6db3f2;
  background: #1a2a3a;
}

[data-bs-theme="dark"] .comment-btn.has-unread .bi-chat-dots {
  color: #6db3f2;
}

[data-bs-theme="dark"] .comment-btn .unread-dot {
  background: #f77;
  border-color: #1e1e1e;
}

[data-bs-theme="dark"] .comment-action-btn {
  color: #adb5bd;
}

[data-bs-theme="dark"] .comment-action-btn:hover {
  color: #6db3f2;
  background: #1a2a3a;
}

[data-bs-theme="dark"] .comment-action-delete:hover {
  color: #f77;
  background: #3a1a1a;
}

[data-bs-theme="dark"] .comment-edit-input {
  background: #1e1e1e;
  border-color: #4a90e2;
  color: #e9ecef;
}

[data-bs-theme="dark"] .comment-edit-cancel {
  background: #3d3d3d;
  color: #e9ecef;
}

[data-bs-theme="dark"] .comment-edit-cancel:hover {
  background: #4d4d4d;
}

[data-bs-theme="dark"] .comment-edited {
  color: #adb5bd;
}

[data-bs-theme="dark"] .comment-content code {
  background: #2d2d2d;
  color: #f78c6c;
}

[data-bs-theme="dark"] .comments-thinking-indicator {
  color: #adb5bd;
}

[data-bs-theme="dark"] .comments-stop-btn {
  color: #adb5bd;
  border-color: #444;
}

[data-bs-theme="dark"] .comments-stop-btn:hover {
  color: #f77;
  border-color: #f77;
}

/* ─────────────────────────────────────────────────
   RESPONSIVE
   ───────────────────────────────────────────────── */

@media (max-width: 768px) {
  .block-comments-panel {
    width: 100%;
    right: -100%;
  }
}
