/* ═══════════════════════════════════════════════════════════════
   Comments — Reddit-style threaded layout with gutter collapse
   Grid: [28px gutter] [1fr body]
   Gutter = collapse circle + vertical thread line
   Body = avatar-in-header + text + actions + nested children
   ═══════════════════════════════════════════════════════════════ */

/* ─── Comment Grid ─────────────────────────────────────────── */

.comment {
  display: grid !important;
  grid-template-columns: 28px 1fr !important;
  gap: 10px !important;
  padding: 8px 0 4px !important;
  position: relative;
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  overflow: visible !important;
}

.comment:not(:last-child) {
  border-bottom: none !important;
}

/* ─── Gutter: collapse circle + thread line ────────────────── */

.comment-gutter {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.collapse-toggle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--color-border-primary, #d0d7de);
  background: var(--color-bg-primary, #fff);
  color: var(--color-text-tertiary, #8b949e);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 0;
  z-index: 2;
  transition: border-color .12s, color .12s;
}

.collapse-toggle:hover {
  border-color: var(--color-text-primary, #24292f);
  color: var(--color-text-primary, #24292f);
}

.comment-thread-line {
  flex: 1;
  width: 2px;
  background: var(--color-border-primary, #d0d7de);
  margin-top: 4px;
  border-radius: 1px;
  cursor: pointer;
  transition: background .12s;
  min-height: 4px;
}

.comment-thread-line:hover {
  background: var(--color-accent, #5A7A6A);
}

/* Hide thread line when collapsed or no children */
.comment.collapsed .comment-thread-line { display: none; }
.comment.no-children .comment-thread-line { display: none; }

/* ─── Comment Body ─────────────────────────────────────────── */

.comment-body-wrap {
  min-width: 0;
  padding-bottom: 4px;
}

/* Header row: avatar + name + badges + points + time */
.comment-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  flex-wrap: nowrap;
  cursor: pointer;
  user-select: none;
  padding: 3px 6px;
  margin: 0 -6px 1px;
  border-radius: 4px;
  transition: background .12s;
  font-size: 0.8125rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.comment-head:hover {
  background: var(--color-bg-secondary, #f6f8fa);
}

/* Avatar inside header */
.comment-ava {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm, 4px);
  object-fit: cover;
  flex-shrink: 0;
}

.comment-ava-initials {
  display: grid;
  place-items: center;
  background: var(--color-text-tertiary, #8b949e);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
}

/* Name link */
.comment-name {
  font-weight: 600;
  color: var(--color-text-primary, #24292f);
  text-decoration: none;
  white-space: nowrap;
  font-size: 0.8125rem;
}

.comment-name:hover {
  text-decoration: underline;
}

/* Override user-mention styling on comment names */
.comment .comment-name.user-mention,
.comments-list .comment-name.user-mention {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  color: var(--color-text-primary, #24292f) !important;
}

.comment-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--color-surface-muted, #F0EEEA);
  color: var(--color-text-secondary, #5A5A5A);
}

.comment-meta-sep {
  color: var(--color-text-tertiary, #8b949e);
}

.comment-meta {
  font-size: 0.75rem;
  color: var(--color-text-tertiary, #8b949e);
}

.comment-meta.points {
  font-weight: 500;
  color: var(--color-text-secondary, #57606a);
}

.comment-edited {
  font-size: 0.75rem;
  color: var(--color-text-tertiary, #8b949e);
  font-style: italic;
}

/* Collapsed meta — "(N children)" shown inline when collapsed */
.collapsed-meta {
  display: none;
  font-size: 11.5px;
  color: var(--color-text-tertiary, #8b949e);
  margin-left: 4px;
}

.comment.collapsed .collapsed-meta {
  display: inline;
}

/* ─── Comment Text ─────────────────────────────────────────── */

.comment-text {
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--color-text-primary, #24292f);
  margin-bottom: 0.375rem;
}

.comment-text p {
  margin: 0 0 0.5rem 0;
}

.comment-text p:last-child {
  margin-bottom: 0;
}

.comment-text img {
  max-width: 100%;
  border-radius: 6px;
  margin: 0.375rem 0;
}

/* ─── Comment Actions ──────────────────────────────────────── */

.comment-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.375rem;
}

.comment-votes-inline {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.comment-vote-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--color-text-tertiary, #8b949e);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s ease;
  padding: 0;
}

.comment-vote-btn:hover {
  color: var(--color-text-secondary, #57606a);
}

.comment-vote-btn.upvoted {
  color: #2da44e;
}

.comment-vote-btn.downvoted {
  color: #cf222e;
}

.comment-vote-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-secondary, #57606a);
  min-width: 1rem;
  text-align: center;
}

.comment-action {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0;
  color: var(--color-text-tertiary, #8b949e);
  font-size: 0.75rem;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.comment-action:hover {
  color: var(--color-text-secondary, #57606a);
}

.comment-action.delete-comment-btn:hover {
  color: #cf222e;
}

/* ─── Reactions ────────────────────────────────────────────── */

.comment-reactions-inline {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.reaction-bubble-sm {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.125rem 0.375rem;
  background: var(--color-bg-secondary, #f6f8fa);
  border: none;
  border-radius: 10px;
  font-size: 0.6875rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.reaction-bubble-sm:hover {
  background: var(--color-bg-tertiary, #eaeef2);
}

.reaction-bubble-sm.user-reacted {
  background: var(--color-accent-subtle, rgba(90, 122, 106, 0.08));
  border-color: var(--color-accent, rgba(90, 122, 106, 0.3));
}

.reaction-bubble-sm .reaction-emoji { font-size: 0.75rem; }
.reaction-bubble-sm .reaction-count { font-weight: 500; color: var(--color-text-secondary, #57606a); }

.add-reaction-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--color-text-tertiary, #8b949e);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s ease;
}

.add-reaction-btn-sm:hover {
  color: var(--color-text-secondary, #57606a);
  background: var(--color-bg-secondary, #f6f8fa);
}

/* Full-size reaction styles (used in some views) */
.comment-reactions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; margin-bottom: 0.5rem; }
.reaction-bubble { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.125rem 0.5rem; background: var(--color-bg-secondary, #f6f8fa); border: 1px solid var(--color-border-primary, #d0d7de); border-radius: 999px; font-size: 0.8125rem; cursor: pointer; transition: all 0.15s ease; }
.reaction-bubble:hover { background: var(--color-bg-tertiary, #eaeef2); border-color: var(--color-border-secondary, #b3b8bf); }
.reaction-bubble.user-reacted { background: #ddf4ff; border-color: #54aeff; }
.reaction-emoji { font-size: 0.9375rem; }
.reaction-count { font-weight: 500; color: var(--color-text-secondary, #57606a); }
.add-reaction-btn { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0; background: transparent; border: 1px dashed var(--color-border-primary, #d0d7de); border-radius: 999px; color: var(--color-text-tertiary, #8b949e); cursor: pointer; transition: all 0.15s ease; }
.add-reaction-btn:hover { background: var(--color-bg-secondary, #f6f8fa); border-color: var(--color-border-secondary, #b3b8bf); color: var(--color-text-secondary, #57606a); }

/* Reaction Picker Popup */
.reaction-picker { position: absolute; background: white; border: 1px solid var(--color-border-primary, #d0d7de); border-radius: 8px; box-shadow: 0 8px 24px rgba(140, 149, 159, 0.2); padding: 0.5rem; z-index: 1000; display: none; }
.reaction-picker.visible { display: flex; gap: 0.25rem; }
.reaction-picker-btn { padding: 0.375rem; background: transparent; border: none; border-radius: 6px; font-size: 1.125rem; cursor: pointer; transition: all 0.15s ease; }
.reaction-picker-btn:hover { background: var(--color-bg-secondary, #f6f8fa); transform: scale(1.1); }

/* ─── Collapsed State ──────────────────────────────────────── */

.comment.collapsed .comment-text,
.comment.collapsed .comment-actions,
.comment.collapsed .comment-replies,
.comment.collapsed .comment-continue-thread,
.comment.collapsed .reply-form-container {
  display: none !important;
}

.comment.collapsed .comment-head {
  color: var(--color-text-tertiary, #8b949e);
}

.comment.collapsed .collapse-toggle {
  background: var(--color-bg-secondary, #f6f8fa);
}

.comment.collapsed {
  padding-bottom: 2px;
}

/* ─── Continue This Thread ─────────────────────────────────── */

.comment-continue-thread { margin-top: 0.375rem; }
.continue-thread-link {
  display: inline-block;
  padding: 0.25rem 0;
  color: var(--color-accent, #5A7A6A);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s ease;
}

.continue-thread-link:hover {
  color: var(--color-text-primary, #24292f);
  text-decoration: underline;
}

/* Fallback: keep inline expand for JS-loaded threads */
.continue-thread-content { display: none; }
.continue-thread-content.expanded { display: block; }

/* Thread view header */
.thread-view-header {
  padding: 0.75rem 0;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border-tertiary, #e8e8ed);
}

.thread-back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--color-accent, #5A7A6A);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  margin-bottom: 0.5rem;
}

.thread-back-link:hover {
  text-decoration: underline;
}

.thread-context {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--color-text-tertiary, #8b949e);
  padding: 6px 10px;
  background: var(--color-bg-secondary, #f6f8fa);
  border-radius: 6px;
  margin-top: 6px;
}

.thread-context-label {
  color: var(--color-text-tertiary, #8b949e);
  flex-shrink: 0;
}

.thread-context-author {
  font-weight: 600;
  color: var(--color-text-secondary, #57606a);
  flex-shrink: 0;
}

.thread-context-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Nested Comments (tree-root connectors) ──────────────── */
/* !important overrides duplicate inline styles in view templates */

.comment-replies {
  margin-left: 0 !important;
  margin-top: 4px !important;
  padding-left: 0 !important;
  border-left: none !important;
  background: transparent;
}

.comment-replies .comment {
  padding: 6px 0 4px;
  background: transparent;
  border-bottom: none;
}

.comment-replies .comment:not(:last-child) {
  border-bottom: none;
}

/* L-curve elbow connector from parent's thread line to each child.
   Geometry: child's grid col 1 starts at (parent gutter 28px + 10px gap) = 38px
   from parent's left edge. Parent's thread line is centered in gutter at x=14.
   So elbow left ≈ -(38 - 14) = -24. Width extends into child gutter center (14px). */
.comment-replies > .comment {
  position: relative;
  overflow: visible !important;
}

.comment-replies > .comment::before {
  content: '';
  position: absolute;
  left: -25px;
  top: 0;
  width: 36px;
  height: 19px;
  border-left: 2px solid var(--color-border-primary, #d0d7de);
  border-bottom: 2px solid var(--color-border-primary, #d0d7de);
  border-bottom-left-radius: 8px;
  border-right: none;
  border-top: none;
  pointer-events: none;
}

/* Hide connectors on collapsed children */
.comment.collapsed > .comment-body-wrap > .comment-replies > .comment::before {
  display: none;
}

/* Cover parent's trailing thread line below the last child's connector */
.comment-replies > .comment:last-child::after {
  content: '';
  position: absolute;
  left: -26px;
  top: 19px;
  bottom: -8px;
  width: 4px;
  background: var(--color-bg-primary, #fff);
  pointer-events: none;
  z-index: 1;
}

/* ─── Deleted Comment ──────────────────────────────────────── */
/* Uses same grid layout as normal comments */

.comment-ava-deleted {
  background: #5a544c !important;
}

.comment-name-deleted {
  color: var(--color-text-tertiary, #8b949e) !important;
  font-style: italic;
  font-weight: 400 !important;
}

.comment-text-deleted {
  color: var(--color-text-tertiary, #8b949e) !important;
  font-style: italic;
}

/* ─── Reply Form ───────────────────────────────────────────── */

.reply-form-container {
  margin-top: 0.75rem;
  display: none;
}

.reply-form-container.active {
  display: block;
}

.reply-form {
  background: var(--color-bg-secondary, #f6f8fa);
  border-radius: 8px;
  overflow: visible;
}

.reply-textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem;
  border: none;
  background: white;
  resize: vertical;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.5;
}

.reply-textarea:focus { outline: none; }

.reply-form-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.5rem;
}

.cancel-reply-btn {
  padding: 0.375rem 0.75rem;
  background: transparent;
  color: var(--color-text-secondary, #57606a);
  border: none;
  border-radius: 6px;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cancel-reply-btn:hover { background: var(--color-bg-tertiary, #eaeef2); }

.submit-reply-btn {
  padding: 0.375rem 0.75rem;
  background: #333;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.submit-reply-btn:hover { background: #000; }

/* ─── Edit Comment Modal ───────────────────────────────────── */

.edit-comment-modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; z-index: 10000; }
.edit-comment-modal.visible { display: flex; }
.edit-comment-dialog { background: white; border-radius: 12px; width: 90%; max-width: 600px; max-height: 80vh; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,0.2); }
.edit-comment-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border-primary, #d0d7de); display: flex; justify-content: space-between; align-items: center; }
.edit-comment-header h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.edit-comment-close { background: transparent; border: none; padding: 0.25rem; cursor: pointer; color: var(--color-text-secondary, #57606a); }
.edit-comment-body { padding: 1.25rem; }
.edit-comment-textarea { width: 100%; min-height: 150px; padding: 0.75rem; border: 1px solid var(--color-border-primary, #d0d7de); border-radius: 8px; font-size: 0.9375rem; font-family: inherit; line-height: 1.5; resize: vertical; }
.edit-comment-textarea:focus { outline: none; border-color: var(--accent-color, #0969da); box-shadow: 0 0 0 3px rgba(9,105,218,0.1); }
.edit-comment-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--color-border-primary, #d0d7de); display: flex; justify-content: flex-end; gap: 0.75rem; }
.edit-comment-cancel { padding: 0.5rem 1rem; background: transparent; border: 1px solid var(--color-border-primary, #d0d7de); border-radius: 6px; font-size: 0.875rem; cursor: pointer; }
.edit-comment-cancel:hover { background: var(--color-bg-secondary, #f6f8fa); }
.edit-comment-save { padding: 0.5rem 1rem; background: var(--accent-color, #238636); color: white; border: none; border-radius: 6px; font-size: 0.875rem; font-weight: 500; cursor: pointer; }
.edit-comment-save:hover { background: #2ea043; }

/* ─── Pinned Comment ───────────────────────────────────────── */

.comment-pinned {
  background: var(--color-bg-accent-subtle, rgba(92, 107, 90, 0.04)) !important;
  border-radius: 6px;
  padding-left: 8px !important;
  padding-right: 8px !important;
  border-left: 3px solid var(--color-accent, #5c6b5a) !important;
}

.comment-badge-pinned {
  display: inline-flex !important;
  background: var(--color-accent, #5c6b5a) !important;
  color: #fff !important;
}

.pin-comment-btn {
  color: var(--color-text-tertiary, #8b949e);
}

.pin-comment-btn:hover {
  color: var(--color-accent, #5c6b5a);
}

/* ─── Empty Comments ───────────────────────────────────────── */

.no-comments {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--color-text-secondary, #57606a);
}

/* ─── Mobile Responsive ────────────────────────────────────── */

@media (max-width: 640px) {
  /* Narrower gutter on mobile */
  .comment {
    grid-template-columns: 22px 1fr !important;
    gap: 6px !important;
    padding: 6px 0 3px !important;
  }

  .collapse-toggle {
    width: 18px;
    height: 18px;
    font-size: 10px;
  }

  .comment-ava {
    width: 20px;
    height: 20px;
  }

  .comment-ava-initials {
    font-size: 8px;
  }

  .comment-head {
    gap: 4px;
    font-size: 0.75rem;
  }

  .comment-text {
    font-size: 0.8125rem;
  }

  .comment-actions {
    gap: 0.5rem;
    font-size: 0.6875rem;
  }

  .comment-vote-btn {
    width: 18px;
    height: 16px;
  }

  /* Tighter nesting indentation on mobile */
  .comment-replies > .comment::before {
    left: -17px;
    width: 24px;
    height: 15px;
    border-bottom-left-radius: 6px;
  }

  .comment-replies > .comment:last-child::after {
    left: -18px;
    top: 15px;
  }

  /* Hide comments deeper than depth 3 on mobile — show "Continue this thread" instead */
  .comment[data-depth="4"],
  .comment[data-depth="5"],
  .comment[data-depth="6"] {
    display: none !important;
  }

  /* Hide depth 3 replies on mobile — JS injects real "Continue this thread" links */
  .comment[data-depth="3"] > .comment-body-wrap > .comment-replies {
    display: none !important;
  }
}

/* ─── Delete Confirm Modal ─────────────────────────────────── */

.delete-confirm-modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; z-index: 10000; }
.delete-confirm-modal.visible { display: flex; }
.delete-confirm-dialog { background: white; border-radius: 12px; width: 90%; max-width: 400px; box-shadow: 0 16px 48px rgba(0,0,0,0.2); }
.delete-confirm-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border-primary, #d0d7de); display: flex; justify-content: space-between; align-items: center; }
.delete-confirm-header h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.delete-confirm-close { background: transparent; border: none; padding: 0.25rem; cursor: pointer; color: var(--color-text-secondary); }
.delete-confirm-body { padding: 1.25rem; }
.delete-confirm-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--color-border-primary, #d0d7de); display: flex; justify-content: flex-end; gap: 0.75rem; }
.delete-confirm-cancel { padding: 0.5rem 1rem; background: transparent; border: 1px solid var(--color-border-primary, #d0d7de); border-radius: 6px; font-size: 0.875rem; cursor: pointer; }
.delete-confirm-delete { padding: 0.5rem 1rem; background: #cf222e; color: white; border: none; border-radius: 6px; font-size: 0.875rem; font-weight: 500; cursor: pointer; }
