/**
 * Craft Custom Posts Block Styles
 * Designed for Viettime Craft (B2B Handicrafts)
 * Modern Card Grid on Desktop, Smooth Horizontal Snap-Scroll on Mobile
 * Features: Zero CLS, View All Header Link, Reading Time, Branded Fallback
 */

.craft-posts-wrapper {
  margin: 30px 0 40px 0;
  position: relative;
  width: 100%;
  content-visibility: auto;
  contain-intrinsic-size: 1px 450px;
}

/* Header (Title & "View All" Action) */
.craft-posts-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 24px;
}

.craft-posts-header.align-center {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.craft-posts-header.align-left {
  text-align: left;
}

.craft-posts-title {
  font-size: 26px;
  font-weight: 700;
  color: #1b441e;
  margin: 0;
  line-height: 1.3;
}

/* "View All" Link */
.craft-posts-viewall {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 700;
  color: #1b441e !important;
  text-decoration: none !important;
  padding-bottom: 3px;
  border-bottom: 1.5px solid transparent;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.craft-posts-viewall svg {
  transition: transform 0.25s ease;
}

.craft-posts-viewall:hover {
  color: #2e7d32 !important;
  border-bottom-color: #2e7d32;
  gap: 9px;
}

.craft-posts-viewall:hover svg {
  transform: translateX(3px);
}

/* Grid Layout (Desktop & Tablet) */
.craft-posts-grid {
  display: grid;
  gap: 24px;
  width: 100%;
}
.craft-posts-wrapper.cols-2 .craft-posts-grid {
  grid-template-columns: repeat(2, 1fr);
}
.craft-posts-wrapper.cols-3 .craft-posts-grid {
  grid-template-columns: repeat(3, 1fr);
}
.craft-posts-wrapper.cols-4 .craft-posts-grid {
  grid-template-columns: repeat(4, 1fr);
}

/* Post Card */
.craft-post-card {
  height: 100%;
  display: flex;
}
.craft-post-card-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  background: #ffffff;
  border: 1px solid #e8ede8;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.04);
}

/* Thumbnail - Zero CLS */
.craft-post-thumb-wrap {
  position: relative;
  aspect-ratio: 16 / 10;
  width: 100%;
  overflow: hidden;
  background: #eef3ee;
  contain: paint;
}
.craft-post-thumb-link {
  display: block;
  width: 100%;
  height: 100%;
}
.craft-post-img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1) !important;
  display: block;
}
.craft-post-card:hover .craft-post-img {
  transform: scale(1.045);
}

/* Branded Fallback Placeholder */
.craft-post-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eaf2ea 0%, #d8e5d8 100%);
  color: #3d5e34;
  gap: 8px;
}
.craft-post-placeholder svg {
  opacity: 0.65;
  stroke: #1b441e;
}
.craft-post-placeholder span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #1b441e;
}

/* Category Badge */
.craft-post-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  background: rgba(27, 68, 30, 0.9);
  color: #ffffff !important;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 4px 12px;
  border-radius: 99px;
  backdrop-filter: blur(4px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  max-width: calc(100% - 24px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Card Body */
.craft-post-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

/* Date & Reading Time Meta Row */
.craft-post-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 11px;
  font-size: 12px;
  line-height: 1.2;
  color: #6a796c;
  font-weight: 500;
  flex-wrap: wrap;
}

.craft-post-date,
.craft-post-readtime {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1;
}

.craft-post-meta svg {
  width: 14px !important;
  height: 14px !important;
  min-width: 14px;
  min-height: 14px;
  stroke: #3d5e34;
  fill: none;
  stroke-width: 2;
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
  position: relative;
  top: -0.5px; /* Optical balance with typography cap-height */
}

.craft-post-meta .craft-meta-text {
  display: inline-block;
  line-height: 1;
  font-size: 12px;
  font-weight: 500;
  color: #6a796c;
}

.craft-post-meta-dot {
  display: inline-block;
  width: 3.5px;
  height: 3.5px;
  background-color: #92a495;
  border-radius: 50%;
  flex-shrink: 0;
  margin: 0 1px;
}

/* Title */
.craft-post-heading {
  font-size: 17px;
  line-height: 1.45;
  font-weight: 700;
  margin: 0 0 10px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.craft-post-heading a {
  color: #1a2e1d !important;
  text-decoration: none !important;
  transition: color 0.2s ease;
}
.craft-post-card:hover .craft-post-heading a {
  color: #2e7d32 !important;
}

/* Excerpt */
.craft-post-excerpt {
  font-size: 13.5px;
  line-height: 1.6;
  color: #556357;
  margin: 0 0 16px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Footer & Read More */
.craft-post-footer {
  margin-top: auto;
  padding-top: 6px;
}
.craft-post-readmore {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #1b441e !important;
  text-decoration: none !important;
  transition: gap 0.2s ease, color 0.2s ease;
}
.craft-post-readmore svg {
  transition: transform 0.2s ease;
}
.craft-post-card:hover .craft-post-readmore {
  color: #2e7d32 !important;
  gap: 9px;
}
.craft-post-card:hover .craft-post-readmore svg {
  transform: translateX(3px);
}

/* Mobile Scroll Hint (Hidden on desktop) */
.craft-posts-mobile-hint {
  display: none;
}

/* Tablet (769px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
  .craft-posts-wrapper.cols-3 .craft-posts-grid,
  .craft-posts-wrapper.cols-4 .craft-posts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile (< 768px): Horizontal Snap-Scroll */
@media (max-width: 768px) {
  .craft-posts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
  }
  .craft-posts-title {
    font-size: 20px;
    line-height: 1.3;
  }
  .craft-posts-viewall {
    font-size: 12.5px;
    flex-shrink: 0;
  }
  .craft-posts-grid {
    display: flex !important;
    overflow-x: auto !important;
    scroll-snap-type: x mandatory;
    scroll-padding: 0 15px;
    -webkit-overflow-scrolling: touch;
    gap: 14px;
    padding: 6px 15px 18px 15px !important;
    margin-left: -15px !important;
    margin-right: -15px !important;
    scrollbar-width: none; /* Firefox */
  }
  .craft-posts-grid::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
  }
  .craft-post-card {
    flex: 0 0 82% !important;
    max-width: 320px !important;
    scroll-snap-align: start;
  }
  .craft-post-card-inner {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
  }
  .craft-post-body {
    padding: 16px 16px;
  }
  .craft-post-heading {
    font-size: 15.5px;
  }
  .craft-posts-mobile-hint {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    font-weight: 500;
    color: #839185;
    margin-top: -6px;
  }
}
