/* Post List - Tufte CSS Integration */
.postlist {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100% !important; /* Override section width constraint */
  max-width: 90%; /* Match Tufte's fullwidth max-width */
  clear: both; /* Match Tufte's fullwidth clear */
}

/* Match Tufte's mobile width patterns */
@media (max-width: 760px) {
  .postlist {
    width: 100% !important;
    max-width: 100%; /* Match regular text content width on mobile */
  }
}

.postlist-item {
  position: relative;
  padding: 1.5rem 0;
  border-bottom: 1px solid #ccc;
  width: 100%; /* Full width for the border */
}

.postlist-item:first-child {
  border-top: 1px solid #ccc;
}

/* Text content constrained to Tufte's text column (55% width) */
.postlist-content {
  width: 55%; /* Match Tufte's text column width */
  margin: 0;
  margin-left: auto; /* Push text to the right, leaving space for image on left */
}

.postlist-content h3,
.postlist-content p,
.post-tags {
  margin: 0;
}

.postlist-content h3 {
  margin-bottom: 1rem; /* Increased spacing between title and description */
}

.postlist-content p {
  margin-bottom: 0.5rem;
}

.post-tags {
  margin-top: 0.5rem;
}

.post-tags .text-small {
  font-size: 15px;
}

/* Image positioned on the left side */
.postlist-image {
  position: absolute;
  left: 0;
  top: 1.5rem;
  width: 40%; /* Increased width to fill space better */
  margin: 0;
}

.postlist-image img {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 4px;
}

.postlist-image-link {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  text-decoration: none;
  background: transparent;
}

/* Date positioning */
.postlist-date.desktop-date {
  display: none;
}

.postlist-date.mobile-date {
  font-size: 0.9em;
  color: #666;
  margin-bottom: 0.5rem;
}

/* Desktop Layout */
@media (min-width: 769px) {
  .postlist-item {
    padding: 2rem 0;
    min-height: 220px; /* Increased min-height for larger images */
  }

  .postlist-date.desktop-date {
    display: block;
    position: absolute;
    left: -12%; /* Position date to the left of text column */
    top: 2rem;
    width: 10%;
    text-align: right;
    font-size: 0.9em;
    color: #666;
    padding-right: 1rem;
  }

  .postlist-date.mobile-date {
    display: none;
  }

  .postlist-content {
    position: relative;
    z-index: 1;
    margin-left: 0; /* Reset margin for desktop */
    margin-left: auto; /* Keep text in its column */
  }

  .postlist-image {
    top: .5rem; /* Adjusted to align with title text top */
    width: 38%; /* Larger image width to fill space */
    left: 2%; /* Slight adjustment for better positioning */
  }

  .postlist-image img {
    height: 200px; /* Increased height */
    aspect-ratio: auto;
  }
}

/* Fix image positioning specifically for tag pages - move image down to align with title */
/* Use attribute selector to target tag pages by URL pattern */
[data-page-type="tag"] .postlist-image {
  top: 2rem; /* Move image down on tag pages to account for page heading */
}

/* Mobile Layout - Date, Image, Title, Description, Tags */
@media (max-width: 768px) {
  .postlist-item {
    display: grid;
    grid-template-areas: 
      "date"
      "image"
      "title"
      "description"
      "tags";
    gap: 0.15rem;
    padding: 1rem 0; /* Reduce padding from 1.5rem to 1rem */
  }

  /* Hide desktop date on mobile */
  .postlist-date.desktop-date {
    display: none;
  }

  /* Mobile date first */
  .postlist-date.mobile-date {
    grid-area: date;
    margin: 0;
  }

  .postlist-image {
    grid-area: image;
    position: static;
    width: 100%;
    margin: 0;
  }

  .postlist-image img {
    aspect-ratio: 16 / 9;
    height: auto;
  }

  .postlist-content {
    width: 100%;
    margin-left: 0;
    display: contents; /* Let children participate in parent grid */
  }

  .postlist-content h3 {
    grid-area: title;
    margin: 0;
    margin-bottom: 1rem; /* Increased spacing between title and description on mobile */
  }

  .post-tags {
    grid-area: tags;
    margin: 0;
    margin-top: 0.5rem; /* Add spacing above tags on mobile */
  }

  .post-tags .text-small {
    font-size: 15px;
  }

  .postlist-content p {
    grid-area: description;
    margin: 0;
    margin-bottom: -0.25rem; /* Reduce space before separator */
  }
}

/* Archive Navigation Styling */
.archive-navigation {
  margin-top: 2rem;
  margin-bottom: 1rem;
  padding-top: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  align-items: center;
}

.archive-link {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text-color);
  text-decoration: none;
  background-color: transparent;
  border: 1px solid var(--text-color-secondary);
  border-radius: 25px;
  transition: all 0.3s ease;
  position: relative;
  text-align: center;
  min-width: 150px;
}

.archive-link:hover {
  background-color: var(--text-color-secondary);
  color: var(--bg-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.archive-link:focus {
  outline: 2px solid var(--text-color-secondary);
  outline-offset: 2px;
}

.archive-link:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Dark theme adjustments */
html[data-theme="dark"] .archive-link {
  border-color: var(--text-color-secondary);
  color: var(--text-color);
}

html[data-theme="dark"] .archive-link:hover {
  background-color: var(--text-color-secondary);
  color: var(--bg-color);
  box-shadow: 0 4px 8px rgba(255, 255, 255, 0.1);
}

/* Mobile/Tablet - Follow Tufte's mobile breakpoint */
@media (max-width: 760px) {
  .archive-navigation {
    margin-top: 1.5rem;
    flex-direction: column;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 100%;
    padding: 0;
  }
  
  .archive-link {
    width: auto;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    min-width: 140px;
  }
}

@media (max-width: 480px) {
  .archive-navigation {
    gap: 0.5rem;
  }
  
  .archive-link {
    padding: 0.75rem 1.25rem;
    font-size: 0.95rem;
    min-width: 120px;
  }
}

@media (max-width: 375px) {
  .archive-link {
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    min-width: 110px;
  }
}

/* Animation for better UX */
@media (prefers-reduced-motion: reduce) {
  .archive-link {
    transition: none;
  }
  
  .archive-link:hover {
    transform: none;
  }
  
  .archive-link:active {
    transform: none;
  }
}

/* Ensure proper spacing after postlist */
.postlist + .archive-navigation {
  margin-top: 2.5rem;
}

/* Match postlist width on mobile */
@media (max-width: 760px) {
  .postlist + .archive-navigation {
    margin-top: 2rem;
  }
}

/* Alternative layout for wide screens */
@media (min-width: 1200px) {
  .archive-navigation {
    justify-content: center;
    gap: 1.5rem;
  }
  
  .archive-link {
    min-width: 160px;
  }
}