/* CSS Variables for Light Mode (Default) */
:root {
  /* Background Colors */
  --bg-primary: #f5f5f5;
  --bg-secondary: #ffffff;
  --bg-post-form: #ffffff;
  --bg-post-card: #ffffff;
  --bg-comment: #f8f9fa;
  --bg-button-primary: #007bff;
  --bg-button-primary-hover: #0056b3;
  --bg-button-secondary: #6c757d;
  --bg-button-success: #28a745;
  --bg-button-danger: #dc3545;
  --bg-avatar-buyer: #e3f2fd;
  --bg-avatar-seller: #f3e5f5;
  --bg-avatar-admin: #e8f5e9;
  --bg-loading: #f8f9fa;
  --bg-notification-success: #d4edda;
  --bg-notification-error: #f8d7da;
  --bg-role-badge: #6c757d;
  --bg-action-button: #f8f9fa;
  --bg-action-button-hover: #e9ecef;
  --bg-action-button-liked: #ffeef0;
  --bg-action-button-active: #e7f3ff;
  
  /* Text Colors */
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --text-button: #ffffff;
  --text-placeholder: #adb5bd;
  --text-post-content: #333333;
  --text-comment: #333333;
  --text-author: #2c3e50;
  --text-stats: #666666;
  --text-action: #666666;
  --text-action-liked: #e74c3c;
  --text-action-active: #007bff;
  --text-notification-success: #155724;
  --text-notification-error: #721c24;
  --text-role-badge: #ffffff;
  
  /* Border Colors */
  --border-light: #e0e0e0;
  --border-medium: #ddd;
  --border-input: #ddd;
  --border-post-card: #e0e0e0;
  --border-comment: #e9ecef;
  --border-avatar: #ffffff;
  --border-action-button: #e9ecef;
  --border-focus: #007bff;
  
  /* Shadow Colors */
  --shadow-light: rgba(0, 0, 0, 0.1);
  --shadow-medium: rgba(0, 0, 0, 0.15);
  --shadow-heavy: rgba(0, 0, 0, 0.2);
  
  /* Icon Colors */
  --icon-default: #666666;
  --icon-action: #666666;
  --icon-liked: #e74c3c;
  --icon-active: #007bff;
  
  /* Misc */
  --scrollbar-track: #f5f5f5;
  --scrollbar-thumb: #888;
  --scrollbar-thumb-hover: #555;
  
  /* Role Colors */
  --role-buyer: #2196f3;
  --role-seller: #9c27b0;
  --role-admin: #4caf50;
}

/* Dark Mode Variables */
.darkmode {
  /* Background Colors */
  --bg-primary: #0f1419;
  --bg-secondary: #1e2932;
  --bg-post-form: #1e2932;
  --bg-post-card: #1e2932;
  --bg-comment: #2a3745;
  --bg-button-primary: #007bff;
  --bg-button-primary-hover: #0056b3;
  --bg-button-secondary: #6c757d;
  --bg-button-success: #28a745;
  --bg-button-danger: #dc3545;
  --bg-avatar-buyer: #2a3745;
  --bg-avatar-seller: #3a2a45;
  --bg-avatar-admin: #2a453a;
  --bg-loading: #2a3745;
  --bg-notification-success: #1a472a;
  --bg-notification-error: #4a1a1a;
  --bg-role-badge: #4a5568;
  --bg-action-button: #2a3745;
  --bg-action-button-hover: #3a4755;
  --bg-action-button-liked: #4a2a2a;
  --bg-action-button-active: #2a3a55;
  
  /* Text Colors */
  --text-primary: #e6e6e6;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --text-button: #ffffff;
  --text-placeholder: #718096;
  --text-post-content: #e6e6e6;
  --text-comment: #e6e6e6;
  --text-author: #ffffff;
  --text-stats: #a0aec0;
  --text-action: #a0aec0;
  --text-action-liked: #ff6b6b;
  --text-action-active: #64b5f6;
  --text-notification-success: #a3d9b1;
  --text-notification-error: #f5a9a9;
  --text-role-badge: #ffffff;
  
  /* Border Colors */
  --border-light: #2d3748;
  --border-medium: #4a5568;
  --border-input: #4a5568;
  --border-post-card: #2d3748;
  --border-comment: #2d3748;
  --border-avatar: #1e2932;
  --border-action-button: #2d3748;
  --border-focus: #007bff;
  
  /* Shadow Colors */
  --shadow-light: rgba(0, 0, 0, 0.3);
  --shadow-medium: rgba(0, 0, 0, 0.4);
  --shadow-heavy: rgba(0, 0, 0, 0.5);
  
  /* Icon Colors */
  --icon-default: #a0aec0;
  --icon-action: #a0aec0;
  --icon-liked: #ff6b6b;
  --icon-active: #64b5f6;
  
  /* Misc */
  --scrollbar-track: #1e2932;
  --scrollbar-thumb: #4a5568;
  --scrollbar-thumb-hover: #718096;
  
  /* Role Colors */
  --role-buyer: #64b5f6;
  --role-seller: #ba68c8;
  --role-admin: #81c784;
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Main Container */
.blog-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
  padding-top: 80px; /* Space for fixed header */
}

/* Post Creation Form */
.post-form {
  background: var(--bg-post-form);
  border: 1px solid var(--border-post-card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px var(--shadow-light);
  position: relative;
}

.post-textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  resize: vertical;
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.5;
  background: var(--bg-secondary);
  color: var(--text-primary);
  margin-bottom: 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.post-textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

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

.post-submit {
  float: right;
  padding: 8px 20px;
  background: var(--bg-button-primary);
  color: var(--text-button);
  border: none;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.post-submit:hover {
  background: var(--bg-button-primary-hover);
}

.post-submit:active {
  transform: translateY(1px);
}

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

/* Post Cards */
.post-card {
  background: var(--bg-post-card);
  border: 1px solid var(--border-post-card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px var(--shadow-light);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.post-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow-medium);
}

.post-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.post-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: bold;
  color: var(--text-button);
  border: 2px solid var(--border-avatar);
  flex-shrink: 0;
}

.post-avatar.buyer {
  background: var(--bg-avatar-buyer);
  color: var(--role-buyer);
}

.post-avatar.seller {
  background: var(--bg-avatar-seller);
  color: var(--role-seller);
}

.post-avatar.admin {
  background: var(--bg-avatar-admin);
  color: var(--role-admin);
}

.post-author {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-author);
  margin-bottom: 4px;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.role-badge {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  background: var(--bg-role-badge);
  color: var(--text-role-badge);
}

.role-badge.buyer {
  background: var(--role-buyer);
}

.role-badge.seller {
  background: var(--role-seller);
}

.role-badge.admin {
  background: var(--role-admin);
}

.post-content {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-post-content);
  margin-bottom: 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.post-stats {
  display: flex;
  gap: 16px;
  font-size: 0.8125rem;
  color: var(--text-stats);
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.post-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.post-action {
  padding: 8px;
  background: var(--bg-action-button);
  border: 1px solid var(--border-action-button);
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-action);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.post-action:hover {
  background: var(--bg-action-button-hover);
  transform: translateY(-1px);
}

.post-action:active {
  transform: translateY(0);
}

.post-action.liked {
  background: var(--bg-action-button-liked);
  border-color: var(--icon-liked);
  color: var(--text-action-liked);
}

.post-action.liked:hover {
  background: var(--bg-action-button-liked);
  opacity: 0.9;
}

/* Comments Section */
.comments-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.comment-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.comment-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border-input);
  border-radius: 20px;
  font-size: 0.875rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: border-color 0.2s ease;
}

.comment-input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.comment-submit {
  padding: 10px 16px;
  background: var(--bg-button-primary);
  color: var(--text-button);
  border: none;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

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

.comment-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.comment-item {
  background: var(--bg-comment);
  border: 1px solid var(--border-comment);
  border-radius: 8px;
  padding: 12px;
}

.comment-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

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

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

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

/* Load More Section */
.load-more {
  text-align: center;
  margin: 32px 0;
}

.load-more-btn {
  padding: 12px 24px;
  background: var(--bg-button-primary);
  color: var(--text-button);
  border: none;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.load-more-btn:hover:not(:disabled) {
  background: var(--bg-button-primary-hover);
  transform: translateY(-2px);
}

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

/* No Posts Message */
.no-posts {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 1.125rem;
}

/* Notifications */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 1000;
  animation: slideIn 0.3s ease;
  max-width: 300px;
  box-shadow: 0 4px 12px var(--shadow-heavy);
}

.notification.success {
  background: var(--bg-notification-success);
  color: var(--text-notification-success);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.notification.error {
  background: var(--bg-notification-error);
  color: var(--text-notification-error);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

.post-card {
  animation: fadeIn 0.3s ease;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* Responsive Design */
@media (max-width: 768px) {
  .blog-container {
    padding: 12px;
    padding-top: 70px;
  }
  
  .post-card {
    padding: 16px;
  }
  
  .post-header {
    gap: 8px;
  }
  
  .post-avatar {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
  
  .post-actions {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  
  .post-action {
    padding: 10px;
    justify-content: center;
  }
  
  .comment-form {
    flex-direction: column;
  }
  
  .comment-input {
    width: 100%;
  }
  
  .comment-submit {
    width: 100%;
  }
  
  .notification {
    left: 12px;
    right: 12px;
    max-width: none;
  }
}

@media (max-width: 480px) {
  .blog-container {
    padding: 8px;
    padding-top: 60px;
  }
  
  .post-form {
    padding: 12px;
  }
  
  .post-textarea {
    min-height: 80px;
    font-size: 0.875rem;
  }
  
  .post-submit {
    width: 100%;
    margin-top: 8px;
    float: none;
  }
  
  .post-meta {
    font-size: 0.75rem;
  }
  
  .role-badge {
    font-size: 0.6875rem;
    padding: 1px 6px;
  }
  
  .post-content {
    font-size: 0.875rem;
  }
  
  .load-more-btn {
    width: 100%;
  }
}

/* Touch-friendly enhancements */
@media (hover: none) and (pointer: coarse) {
  .post-action {
    min-height: 44px;
  }
  
  .post-submit,
  .load-more-btn,
  .comment-submit {
    min-height: 44px;
  }
  
  .post-textarea,
  .comment-input {
    font-size: 16px; /* Prevent iOS zoom on focus */
  }
}

/* Print Styles */
@media print {
  .post-form,
  .post-actions,
  .comment-form,
  .load-more {
    display: none !important;
  }
  
  .post-card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }
  
  body {
    background: white;
    color: black;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Loading States */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.skeleton {
  background: var(--bg-loading);
  border-radius: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --bg-primary: #000000;
    --bg-secondary: #000000;
    --text-primary: #ffffff;
    --border-light: #ffffff;
  }
  
  .post-card {
    border: 2px solid var(--border-post-card);
  }
  
  .post-action {
    border: 2px solid var(--border-action-button);
  }
}