/* Comments System V3 - Professional Design */
:root {
  --comment-primary: #2196F3;
  --comment-primary-hover: #1976D2;
  --comment-primary-light: #e3f2fd;
  --comment-bg: #f8f9fa;
  --comment-bg-hover: #f5f6f7;
  --comment-reply-bg: #ffffff;
  --comment-border: #e9ecef;
  --comment-text-primary: #212529;
  --comment-text-secondary: #6c757d;
  --comment-text-muted: #868e96;
  --comment-like-color: #e74c3c;
  --comment-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  --comment-shadow-hover: 0 2px 8px rgba(0, 0, 0, 0.08);
  --comment-radius: 12px;
  --comment-spacing: 1rem;
}

/* Main Container */
.comments-section {
  max-width: 800px;
  margin: 3rem auto;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

/* Header Section */
.comments-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--comment-border);
  flex-wrap: wrap;
  gap: 1rem;
  position: relative;
}

.comments-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: #5888f0;
  margin: 0;
}

/* Sort Controls */
.comments-controls {
  display: flex;
  gap: 0.5rem;
}

.sort-select {
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--comment-border);
  background: white;
  border-radius: 24px;
  font-size: 0.875rem;
  color: var(--comment-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236c757d' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.75rem center;
  padding-left: 2.5rem;
}

.sort-select:hover {
  border-color: var(--comment-primary);
  color: var(--comment-primary);
}

.sort-select:focus {
  outline: none;
  border-color: var(--comment-primary);
  box-shadow: 0 0 0 3px var(--comment-primary-light);
}

/* Comments Container */
.comments-container {
  background: white;
  border-radius: var(--comment-radius);
  box-shadow: var(--comment-shadow);
  overflow: hidden;
}

/* Add Comment Form - Positioned at top */
.comment-form-wrapper {
  padding: 1.5rem;
  background: var(--comment-bg);
  border-bottom: 1px solid var(--comment-border);
}

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

.form-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.form-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid white;
  box-shadow: var(--comment-shadow);
}

.form-username {
  font-weight: 600;
  color: var(--comment-text-primary);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  justify-content: space-between;
}

.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: transparent;
  border: 1px solid var(--comment-border);
  color: var(--comment-text-muted);
  font-size: 0.8rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.logout-btn:hover {
  background: #fff5f5;
  border-color: #dc3545;
  color: #dc3545;
  transform: translateY(-1px);
}

.logout-btn svg {
  transition: transform 0.2s ease;
}

.logout-btn:hover svg {
  transform: translateX(-2px);
}

.comment-textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem 1rem;
  border: 2px solid var(--comment-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  transition: all 0.2s ease;
  background: white;
}

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

.form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.submit-btn {
  padding: 0.5rem 1.5rem;
  background: var(--comment-primary);
  color: white;
  border: none;
  border-radius: 24px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
}

.submit-btn:hover:not(:disabled) {
  background: var(--comment-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(33, 150, 243, 0.3);
}

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

.cancel-btn {
  padding: 0.5rem 1.5rem;
  background: #6c757d;
  color: white;
  border: none;
  border-radius: 24px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  margin-left: 0.5rem;
}

.cancel-btn:hover:not(:disabled) {
  background: #5a6268;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(108, 117, 125, 0.3);
}

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

/* Reply Form */
.reply-form {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--comment-bg);
  border-radius: 8px;
  border: 1px solid var(--comment-border);
  animation: slideDown 0.3s ease;
}

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

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


/* Comments List */
.comments-list {
  max-height: 600px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.comments-list::-webkit-scrollbar {
  width: 6px;
}

.comments-list::-webkit-scrollbar-track {
  background: transparent;
}

.comments-list::-webkit-scrollbar-thumb {
  background: var(--comment-border);
  border-radius: 3px;
}

.comments-list::-webkit-scrollbar-thumb:hover {
  background: var(--comment-text-muted);
}

/* Individual Comment */
.comment {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--comment-border);
  transition: all 0.2s ease;
  position: relative;
}

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

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

/* Reply Comments */
.comment-reply {
  margin-right: 3rem;
  padding-right: 1rem;
  border-right: 3px solid var(--comment-primary);
  background: var(--comment-reply-bg);
}

/* Comment Header */
.comment-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.comment-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.comment-meta {
  flex: 1;
}

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

.comment-date {
  font-size: 0.8rem;
  color: var(--comment-text-muted);
  margin-top: 0.125rem;
}

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

/* Comment Content */
.comment-content {
  margin-bottom: 0.75rem;
  line-height: 1.6;
  color: var(--comment-text-secondary);
  font-size: 0.95rem;
  word-wrap: break-word;
}

/* Comment Actions */
.comment-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  flex-wrap: wrap;
}

.comment-actions button {
  padding: 0.375rem 0.75rem;
  background: transparent;
  border: 1px solid transparent;
  color: var(--comment-text-muted);
  font-size: 0.8rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 500;
}

.comment-actions button:hover:not(:disabled) {
  background: var(--comment-bg);
  border-color: var(--comment-border);
  color: var(--comment-text-primary);
}

/* Like Button */
.comment-like {
  padding-left: 0 !important;
}

.comment-like.liked {
  color: var(--comment-like-color);
}

.comment-like.liked .like-icon {
  animation: likeAnimation 0.3s ease;
}

@keyframes likeAnimation {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.like-icon {
  font-size: 1rem;
}

.like-count {
  font-weight: 600;
}

/* Toggle Replies Button */
.toggle-replies-btn {
  color: var(--comment-primary);
}

.toggle-replies-btn:hover {
  background: var(--comment-primary-light) !important;
  border-color: var(--comment-primary-light) !important;
  color: var(--comment-primary);
}

.toggle-icon {
  font-size: 0.7rem;
  transition: transform 0.2s ease;
}

.toggle-replies-btn[data-expanded="true"] .toggle-icon {
  transform: rotate(180deg);
}

/* Replies Container */
.comment-replies {
  margin-top: 1rem;
  animation: slideDown 0.3s ease-out;
}

.comment-replies.collapsed {
  display: none;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.replies-loading {
  text-align: center;
  padding: 1rem;
  color: var(--comment-text-muted);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

/* Load More Section */
.load-more-container {
  padding: 2rem;
  text-align: center;
  background: var(--comment-bg);
  border-top: 1px solid var(--comment-border);
}

.load-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 2rem;
  background: var(--comment-primary);
  color: white;
  border: none;
  border-radius: 24px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.95rem;
}

.load-more-btn:hover {
  background: var(--comment-primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.comments-count {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: var(--comment-text-muted);
}

/* Loading States */
.comments-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: var(--comment-text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--comment-border);
  border-top-color: var(--comment-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner-small {
  width: 16px;
  height: 16px;
  border: 2px solid var(--comment-border);
  border-top-color: var(--comment-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

/* No Comments State */
.no-comments {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--comment-text-muted);
}

/* Auth Prompt */
.auth-prompt {
  padding: 2rem;
  text-align: center;
  background: var(--comment-bg);
}

.auth-prompt p {
  margin-bottom: 1.5rem;
  color: var(--comment-text-secondary);
}

.auth-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.auth-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: 24px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  border: 1px solid var(--comment-border);
}

.auth-button.google {
  background: white;
  color: var(--comment-text-primary);
}

.auth-button.google:hover {
  background: var(--comment-bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.auth-button.github {
  background: #24292e;
  color: white;
  border-color: #24292e;
}

.auth-button.github:hover {
  background: #1a1e22;
  border-color: #1a1e22;
}

/* Highlight New Comment */
.highlight-new {
  animation: highlightFade 3s ease;
}

@keyframes highlightFade {
  0% {
    background-color: var(--comment-primary-light);
  }
  100% {
    background-color: transparent;
  }
}

/* RTL Support */
[dir="rtl"] .comment-reply {
  margin-right: 0;
  margin-left: 3rem;
  padding-right: 0;
  padding-left: 1rem;
  border-right: none;
  border-left: 3px solid var(--comment-primary);
}

[dir="rtl"] .sort-select {
  background-position: right 0.75rem center;
  padding-left: 1.25rem;
  padding-right: 2.5rem;
}

[dir="rtl"] .cancel-btn {
  margin-left: 0;
  margin-right: 0.5rem;
}

[dir="rtl"] .form-footer {
  flex-direction: row-reverse;
}

[dir="rtl"] .reply-form::before,
[dir="rtl"] .reply-form::after {
  left: auto;
  right: 20px;
}

[dir="rtl"] .comment {
  transform-origin: right center;
}

[dir="rtl"] .comment[style*="translateX(-20px)"] {
  transform: translateX(20px) !important;
}

/* Reply form button improvements */
.comment-reply-form {
  margin-top: 0.75rem;
}

.reply-form {
  position: relative;
}

.reply-form::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 20px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--comment-border);
}

.reply-form::after {
  content: '';
  position: absolute;
  top: -7px;
  left: 20px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--comment-bg);
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --comment-primary: #4a9eff;
    --comment-primary-hover: #2684ff;
    --comment-primary-light: rgba(74, 158, 255, 0.1);
    --comment-bg: #1a1a1a;
    --comment-bg-hover: #252525;
    --comment-reply-bg: #202020;
    --comment-border: #333;
    --comment-text-primary: #e0e0e0;
    --comment-text-secondary: #b0b0b0;
    --comment-text-muted: #808080;
    --comment-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --comment-shadow-hover: 0 2px 8px rgba(0, 0, 0, 0.4);
  }
  
  .comments-container {
    background: #1a1a1a;
  }
  
  .comment-textarea {
    background: #252525;
    color: #e0e0e0;
  }
  
  .auth-button.google {
    background: #2a2a2a;
    color: #e0e0e0;
    border-color: #444;
  }
  
  .reply-form {
    background: #252525;
    border-color: #404040;
  }
  
  .reply-form .comment-textarea {
    background: #1a1a1a;
    border-color: #404040;
  }
  
  .cancel-btn {
    background: #495057;
  }
  
  .cancel-btn:hover:not(:disabled) {
    background: #3d4147;
    box-shadow: 0 4px 8px rgba(73, 80, 87, 0.3);
  }
  
  .logout-btn {
    border-color: #404040;
    color: #b0b0b0;
  }
  
  .logout-btn:hover {
    background: #3a2a2a;
    border-color: #dc3545;
    color: #dc3545;
  }
}

/* New Comments Notification */
.new-comments-notification {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--comment-primary);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 24px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3);
  animation: slideDown 0.3s ease;
}

.new-comments-notification button {
  background: white;
  color: var(--comment-primary);
  border: none;
  padding: 0.25rem 0.75rem;
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.new-comments-notification button:hover {
  background: rgba(255, 255, 255, 0.9);
  transform: scale(1.05);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .comments-section {
    margin: 2rem 0;
  }
  
  .comments-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .comment {
    padding: 1rem;
  }
  
  .comment-reply {
    margin-right: 2rem;
  }
  
  .comment-actions {
    gap: 0.125rem;
  }
  
  .comment-actions button {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }
  
  .auth-buttons {
    flex-direction: column;
    width: 100%;
  }
  
  .auth-button {
    width: 100%;
    justify-content: center;
  }
  
  .user-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  
  .logout-btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }
}