/* ============================================
   GurgelHub Comments System Styles
   ============================================
   Confluence-style inline comments +
   Traditional threaded comments
   ============================================ */

/* ---------- CSS Variables for Comments ---------- */
:root {
  --comment-highlight: rgba(245, 158, 11, 0.2);
  --comment-highlight-active: rgba(245, 158, 11, 0.35);
  --comment-highlight-hover: rgba(245, 158, 11, 0.25);
  --comment-border: rgba(245, 158, 11, 0.5);
  --comment-resolved: rgba(16, 185, 129, 0.15);
  --comment-resolved-border: rgba(16, 185, 129, 0.4);
}

/* ============================================
   Inline Comment Highlights
   ============================================ */

.comment-highlight {
  background-color: var(--comment-highlight);
  border-bottom: 2px solid var(--comment-border);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  position: relative;
}

.comment-highlight:hover {
  background-color: var(--comment-highlight-hover);
}

.comment-highlight.active {
  background-color: var(--comment-highlight-active);
}

.comment-highlight.resolved {
  background-color: var(--comment-resolved);
  border-bottom-color: var(--comment-resolved-border);
}

/* Comment indicator badge */
.comment-highlight::after {
  content: attr(data-comment-count);
  position: absolute;
  top: -8px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
  color: var(--text-inverse);
  background: var(--accent-primary);
  border-radius: 8px;
  opacity: 0;
  transform: scale(0.8);
  transition: all var(--transition-fast);
  pointer-events: none;
}

.comment-highlight:hover::after,
.comment-highlight.active::after {
  opacity: 1;
  transform: scale(1);
}

/* ============================================
   Selection Tooltip
   ============================================ */

.comment-tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--bg-elevated);
  border: 1px solid var(--border-accent);
  border-radius: 8px;
  padding: 4px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  animation: tooltipFadeIn 0.15s ease;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.comment-tooltip-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--accent-primary);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.comment-tooltip-btn:hover {
  background: var(--accent-muted);
  color: var(--accent-secondary);
}

.comment-tooltip-btn svg {
  width: 16px;
  height: 16px;
}

/* ============================================
   Inline Comments Sidebar
   ============================================ */

.inline-comments-sidebar {
  position: fixed;
  top: 0;
  right: -400px;
  width: 400px;
  height: 100vh;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-subtle);
  z-index: 200;
  transition: right var(--transition-base);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
}

.inline-comments-sidebar.open {
  right: 0;
}

.inline-comments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.inline-comments-header h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.inline-comments-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.inline-comments-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.inline-comments-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

/* Inline comment thread in sidebar */
.inline-thread {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.inline-thread.resolved {
  opacity: 0.7;
}

.inline-thread-header {
  padding: 0.875rem 1rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.inline-thread-selection {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-style: italic;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.inline-thread-selection::before {
  content: '"';
  color: var(--accent-primary);
}

.inline-thread-selection::after {
  content: '"';
  color: var(--accent-primary);
}

.inline-thread-body {
  padding: 0.75rem 1rem;
}

.inline-thread-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.resolve-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.resolve-btn:hover {
  color: var(--success);
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.1);
}

.resolve-btn.resolved {
  color: var(--success);
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.1);
}

/* ============================================
   General Comments Section
   ============================================ */

.comments-section {
  padding: 4rem 1.5rem;
  background: var(--bg-deep);
  border-top: 1px solid var(--border-subtle);
  margin-top: 4rem;
}

.comments-container {
  max-width: var(--content-width);
  margin: 0 auto;
}

.comments-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.comments-header h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.comments-header h2 svg {
  color: var(--accent-primary);
}

.comments-count {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 1.25rem;
}

.comments-subtitle {
  color: var(--text-muted);
  margin: 0;
  font-size: 1rem;
}

/* ============================================
   Comment Form
   ============================================ */

.comment-form-wrapper {
  margin-bottom: 2.5rem;
}

.comment-form {
  display: flex;
  gap: 1rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 1.25rem;
}

.comment-form-avatar {
  flex-shrink: 0;
}

.comment-form-content {
  flex: 1;
  min-width: 0;
}

.comment-form-identity {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.comment-name-input {
  flex: 1;
  max-width: 240px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  outline: none;
  transition: all var(--transition-fast);
}

.comment-name-input::placeholder {
  color: var(--text-muted);
}

.comment-name-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.remember-name-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.remember-name-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.comment-textarea {
  width: 100%;
  padding: 0.875rem 1rem;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 10px;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: all var(--transition-fast);
}

.comment-textarea::placeholder {
  color: var(--text-muted);
}

.comment-textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.comment-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
}

.comment-char-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  outline: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  color: var(--text-inverse);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.btn-secondary {
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
}

.btn-secondary:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: var(--accent-primary);
  background: var(--accent-muted);
}

.btn-ghost {
  color: var(--text-muted);
  background: transparent;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
}

.btn-icon {
  padding: 0.5rem;
}

/* ============================================
   Avatar
   ============================================ */

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-inverse);
  text-transform: uppercase;
  flex-shrink: 0;
}

.avatar-sm {
  width: 32px;
  height: 32px;
  font-size: 0.875rem;
}

.avatar-anon {
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 2px dashed var(--border-default);
}

/* ============================================
   Comments List
   ============================================ */

.comments-list {
  min-height: 100px;
}

.comments-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 3rem;
  color: var(--text-muted);
}

.comments-empty {
  text-align: center;
  padding: 4rem 2rem;
}

.comments-empty svg {
  color: var(--text-muted);
  opacity: 0.4;
  margin-bottom: 1rem;
}

.comments-empty h3 {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.comments-empty p {
  color: var(--text-muted);
  margin: 0;
}

/* ============================================
   Individual Comment
   ============================================ */

.comment {
  display: flex;
  gap: 0.875rem;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border-subtle);
  animation: commentFadeIn 0.3s ease;
}

@keyframes commentFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.comment:last-child {
  border-bottom: none;
}

.comment-body {
  flex: 1;
  min-width: 0;
}

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

.comment-author {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9375rem;
}

.comment-author.anonymous {
  color: var(--text-muted);
  font-style: italic;
}

.comment-time {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.comment-edited {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

.comment-content {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.comment-content.deleted {
  color: var(--text-muted);
  font-style: italic;
}

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

.comment-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.comment-action-btn:hover {
  color: var(--accent-primary);
  background: var(--accent-muted);
}

.comment-action-btn.danger:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.comment-action-btn svg {
  width: 14px;
  height: 14px;
}

/* ============================================
   Nested Replies
   ============================================ */

.comment-replies {
  margin-top: 1rem;
  margin-left: 1rem;
  padding-left: 1rem;
  border-left: 2px solid var(--border-subtle);
}

.comment-replies .comment {
  padding: 0.875rem 0;
}

.comment-replies .comment:first-child {
  padding-top: 0;
}

.comment-replies .avatar {
  width: 32px;
  height: 32px;
  font-size: 0.75rem;
}

/* Reply form inline */
.reply-form {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding: 0.875rem;
  background: var(--bg-elevated);
  border-radius: 10px;
  animation: replyFormSlide 0.2s ease;
}

@keyframes replyFormSlide {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 200px;
  }
}

.reply-form .comment-textarea {
  min-height: 60px;
  font-size: 0.875rem;
}

.reply-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* ============================================
   Pagination
   ============================================ */

.comments-pagination {
  text-align: center;
  margin-top: 2rem;
}

/* ============================================
   Modal
   ============================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 3rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalSlideIn 0.25s ease;
  box-shadow: var(--shadow-lg);
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-size: 1.125rem;
  margin: 0;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

/* Inline comment modal specific */
.inline-comment-selection {
  margin-bottom: 1.25rem;
}

.selection-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.selected-text-preview {
  padding: 0.875rem 1rem;
  background: var(--bg-elevated);
  border-left: 3px solid var(--accent-primary);
  border-radius: 0 8px 8px 0;
  font-size: 0.9375rem;
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.6;
  max-height: 150px;
  overflow-y: auto;
  margin: 0;
}

.inline-comment-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.inline-comment-form .comment-name-input {
  max-width: none;
}

/* ============================================
   Comment Count Indicator
   ============================================ */

.comment-count-indicator {
  cursor: pointer;
  transition: color var(--transition-fast);
}

.comment-count-indicator:hover {
  color: var(--accent-primary);
}

/* ============================================
   Responsive Design
   ============================================ */

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

  .comment-form {
    flex-direction: column;
    gap: 0.75rem;
  }

  .comment-form-avatar {
    display: none;
  }

  .comment-form-identity {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .comment-name-input {
    max-width: none;
  }

  .comment-replies {
    margin-left: 0.5rem;
    padding-left: 0.75rem;
  }

  .modal-content {
    max-width: none;
    margin: 1rem;
  }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  .comment-tooltip,
  .inline-comments-sidebar,
  .modal-overlay,
  .comment-form-wrapper,
  .comment-actions,
  .comments-pagination {
    display: none !important;
  }

  .comments-section {
    background: white;
  }
}

