/* ===== PRM Related Articles ===== */

/* ---- Root Variables ---- */
.prm-related {
  --prm-ra-gap: 24px;
  --prm-ra-blue: #0093BE;
  --prm-ra-title-normal: #939393;
  --prm-ra-overlay: var(--prm-ra-overlay-desktop);
  --prm-ra-aspect-ratio: 1.7778; /* 16:9 default */
  position: relative;
  width: 100%;
}

/* Responsive overlay gradients */
@media (max-width: 1024px) {
  .prm-related {
    --prm-ra-overlay: var(--prm-ra-overlay-tablet);
  }
}

@media (max-width: 767px) {
  .prm-related {
    --prm-ra-overlay: var(--prm-ra-overlay-mobile);
    --prm-ra-gap: 12px;
  }
}

/* ---- Header ---- */
.prm-related__header {
  margin-bottom: clamp(20px, 3vw, 32px);
}

.prm-related__title {
  font-family: 'Obvia', sans-serif;
  font-weight: 900;
  font-size: 40px;
  text-transform: capitalize;
  margin: 0;
  line-height: 1.2;
}

/* ---- Slider Container ---- */
.prm-related__slider {
  position: relative;
  width: 100%;
  overflow: hidden !important; /* Hide cards that are outside the viewport - critical for slider */
  min-height: 476px; /* Match card height - dots are positioned outside */
  padding-bottom: 0; /* Dots will be positioned outside slider */
}

/* Container for arrows - positioned relative to section */
.prm-related {
  position: relative;
  overflow: visible; /* Allow arrows to show outside */
}

/* Arrows positioned absolutely relative to .prm-related container */
/* JavaScript will set exact top position to align with slider center */
.prm-related__arrow {
  position: absolute;
  top: 50%; /* Fallback - will be overridden by JavaScript */
  transform: translateY(-50%);
  z-index: 30;
  pointer-events: auto;
  opacity: 1 !important;
  visibility: visible !important;
  /* Token .prm-nav-button provides core button styles */
}

.prm-related__arrow--prev {
  left: -60px;
}

.prm-related__arrow--next {
  right: -60px;
}

/* Swiper wrapper - use flex layout for proper slider behavior */
.prm-related__slider.swiper .swiper-wrapper,
.prm-related__slider .swiper-wrapper {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important; /* Critical: prevent wrapping to multiple rows */
  width: 100% !important;
  height: 476px !important;
  max-height: 476px !important;
  align-items: flex-start !important;
  margin: 0 !important;
  /* Swiper will add transform for sliding */
}

/* ---- Card ---- */
/* Responsive card width - automatically adjusts based on viewport */
/* With slidesPerView: 'auto', Swiper will show as many cards as fit */
.prm-related__card {
  /* Default mobile width - will be overridden by media queries */
  width: calc(100vw - 80px) !important; /* Full width minus padding for arrows */
  min-width: 280px !important;
  max-width: calc(100vw - 80px) !important;
  height: 476px !important;
  display: flex;
  flex-direction: column;
  border: 1px solid #0093BE;
  border-radius: 4px;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative; /* For absolute positioning of meta panel */
  box-sizing: border-box;
  flex-shrink: 0;
  background-color: #ffffff; /* White background so bottom area is white when meta panel slides up */
}

/* Swiper slides - width matches card width for 'auto' mode */
.prm-related__slider.swiper .swiper-slide {
  width: auto !important; /* Let card width determine slide width */
  height: 476px !important;
  flex-shrink: 0;
  box-sizing: border-box;
}

.prm-related__card:hover,
.prm-related__card:focus-within {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.prm-related__link {
  display: block;
  height: 100%;
  text-decoration: none;
  color: inherit;
  position: relative;
  background-color: #ffffff; /* Ensure link area has white background for bottom section */
}

/* ---- Media ---- */
.prm-related__media {
  position: relative;
  width: 100%;
  height: 280px; /* Fixed height for media area (card is 476px total, meta takes ~196px) */
  background-color: #e0e0e0;
  background-image: var(--bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  overflow: hidden;
  flex-shrink: 0;
}

.prm-related__overlay {
  position: absolute;
  inset: 0;
  background: var(--prm-ra-overlay);
  z-index: 1;
  pointer-events: none;
}

/* ---- Meta Panel ---- */
.prm-related__meta {
  --meta-pb: clamp(10px, 1.2vw, 14px);
  background-color: #ffffff;
  padding: clamp(16px, 2.5vw, 24px) clamp(16px, 2.5vw, 24px) var(--meta-pb) clamp(16px, 2.5vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2;
  transform: translateY(0);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  /* Meta panel contains all content but initially shows only bottom portion */
  /* Set a consistent minimum height to ensure labels align across all cards */
  min-height: 196px; /* Label (32px) + gap (10px) + title min (78px) + padding top (24px) + padding bottom (14px) + gap for excerpt space = ~196px */
  /* Ensure content aligns to top - label and title start at same position */
  align-items: flex-start;
  justify-content: flex-start;
  /* Use box-sizing to ensure padding is included in height calculations */
  box-sizing: border-box;
  height: auto;
}

/* Label */
.prm-related__label {
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: #000000;
  background-color: #FFFFFF;
  display: inline-block;
  padding: 4px 8px 4px 0; /* Remove left padding to align with excerpt */
  text-transform: uppercase;
  letter-spacing: 0.05em;
  align-self: flex-start;
  min-height: 24px; /* Ensure consistent height across cards */
  line-height: 1.5;
  margin: 0 0 4px 0; /* Small bottom margin for spacing */
}

/* Post Title */
.prm-related__post-title {
  font-family: 'Obvia', sans-serif;
  font-weight: 900;
  font-size: 24px;
  text-transform: uppercase;
  color: var(--prm-ra-title-normal);
  margin: 0;
  line-height: 1.3;
  transition: color 200ms ease;
  /* Limit title to 3 lines to ensure consistent alignment across cards */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Allow natural height but cap at 3 lines - ensures alignment while allowing short titles to be compact */
  max-height: 93.6px; /* Maximum height for 3 lines: 24px * 1.3 line-height * 3 lines = 93.6px */
}

.prm-related__title-arrow {
  display: inline-block;
  margin-left: 4px;
  transition: transform 0.2s ease;
}

.prm-related__card:hover .prm-related__title-arrow,
.prm-related__card:focus-within .prm-related__title-arrow {
  transform: translateX(4px);
}

/* Excerpt - hidden initially, revealed on hover */
.prm-related__excerpt {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 16px;
  color: #222222;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 10px 0 0 0; /* No bottom margin to minimize white space */
  max-height: 0;
  opacity: 0;
  transition: max-height 0.28s ease,
              opacity 0.28s ease,
              margin-top 0.28s ease;
}

/* On hover, slide meta panel up and reveal excerpt */
.prm-related__card:hover .prm-related__meta,
.prm-related__card:focus-within .prm-related__meta,
.prm-related__card--tapped .prm-related__meta {
  /* Tighter bottom space on hover */
  --meta-pb: clamp(6px, 0.8vw, 10px);
  /* Slide up to reveal excerpt - slightly less lift for tighter spacing */
  transform: translateY(-76px);
  /* Allow meta panel to shrink to fit content on hover (override min-height) */
  min-height: auto;
  /* Allow natural height growth */
  max-height: none;
  /* Ensure white background extends to cover the entire bottom area when sliding up */
  background-color: #ffffff;
}

.prm-related__card:hover .prm-related__excerpt,
.prm-related__card:focus-within .prm-related__excerpt,
.prm-related__card--tapped .prm-related__excerpt {
  max-height: 72px; /* ~3 lines of text @ ~16px font */
  opacity: 1;
  margin-top: 10px;
}

/* Mobile tap-to-reveal: First tap shows excerpt, second tap navigates */
@media (max-width: 767px) {
  /* When card is tapped, the link click handler in JS will handle navigation */
  /* The --tapped class triggers the same visual state as hover */
}

/* ---- Arrows ---- */
/* Base arrow styles - overridden above but kept for specificity */
/* Hover handled by .prm-nav-button token */
.prm-related__arrow svg {
  width: 24px;
  height: 24px;
  color: #0093BE;
  stroke: currentColor;
}

.prm-related__arrow:disabled {
  opacity: 0.4 !important;
}

.prm-related .swiper-button-next:hover,
.prm-related .swiper-button-prev:hover,
.prm-related .swiper-button-next:active,
.prm-related .swiper-button-prev:active,
.prm-related .swiper-button-next:focus,
.prm-related .swiper-button-prev:focus {
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: var(--prm-ra-blue, #0093BE) !important;
}

/* Arrow SVG icons are now rendered in the PHP widget */

/* ---- Dots ---- */
.prm-related__dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: clamp(16px, 2.5vw, 24px);
  position: relative;
  z-index: 10;
  width: 100%;
  padding-top: 0;
}

.prm-related__dots .swiper-pagination-bullet {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #C6C6C6;
  opacity: 1;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease;
  margin: 0;
}

.prm-related__dots .swiper-pagination-bullet:hover {
  transform: scale(1.2);
}

.prm-related__dots .swiper-pagination-bullet-active {
  background-color: var(--prm-ra-blue);
  transform: scale(1.2);
}

.prm-related__dots .swiper-pagination-bullet:focus-visible {
  outline: 2px solid var(--prm-ra-blue);
  outline-offset: 2px;
}

/* ---- Empty State ---- */
.prm-related__empty {
  text-align: center;
  padding: 40px 20px;
  color: #666;
}

/* ---- Responsive: Tablet ---- */
@media (min-width: 768px) and (max-width: 1024px) {
  .prm-related {
    --prm-ra-gap: 16px;
  }

  .prm-related__arrow {
    width: 45px;
    height: 45px;
  }

  .prm-related__arrow--prev {
    left: -55px;
  }

  .prm-related__arrow--next {
    right: -55px;
  }
  
  .prm-related__arrow svg {
    width: 22px;
    height: 22px;
  }
  
  .prm-related {
    padding-left: 40px;
    padding-right: 40px;
  }

  .prm-related__title {
    font-size: clamp(32px, 4vw, 40px);
  }

  .prm-related__post-title {
    font-size: clamp(20px, 2.5vw, 24px);
  }
}

/* ---- Responsive: Mobile ---- */
@media (max-width: 767px) {
  .prm-related {
    --prm-ra-gap: 12px;
  }

  .prm-related__header {
    margin-bottom: 20px;
  }

  .prm-related__title {
    font-size: clamp(24px, 5vw, 32px);
  }

  .prm-related__arrow {
    width: 40px;
    height: 40px;
  }

  .prm-related__arrow--prev {
    left: 8px;
  }

  .prm-related__arrow--next {
    right: 8px;
  }
  
  .prm-related__arrow svg {
    width: 20px;
    height: 20px;
  }

  .prm-related__meta {
    padding: 16px;
  }

  .prm-related__post-title {
    font-size: clamp(18px, 4vw, 22px);
  }

  .prm-related__excerpt {
    font-size: clamp(14px, 3.5vw, 16px);
  }

  .prm-related__label {
    font-size: clamp(14px, 3.5vw, 16px);
  }
}

/* ---- Swiper Overrides ---- */
.prm-related__slider.swiper {
  padding-bottom: 40px; /* Space for dots */
  margin-left: 0;
  margin-right: 0;
  height: 516px !important; /* 476px cards + 40px for dots */
  max-height: 516px !important;
  overflow: hidden !important;
  min-height: 516px !important;
}

.prm-related__slider .swiper-slide {
  width: auto !important; /* Match card width for responsive behavior */
  height: 476px !important;
  display: flex;
  box-sizing: border-box;
  flex-shrink: 0;
}

/* Fallback: If Swiper doesn't initialize, show cards in a flex row with wrapping */
.prm-related__slider:not(.swiper-initialized) .swiper-wrapper {
  flex-wrap: wrap;
  gap: 24px;
  justify-content: flex-start;
}

/* Ensure slides match card width - responsive */
.prm-related__slider.swiper .swiper-slide,
.prm-related__slider .swiper-slide {
  width: auto !important; /* Match card width */
  height: 476px !important;
  max-height: 476px !important;
  display: flex !important;
  flex-direction: column !important;
  visibility: visible !important;
  opacity: 1 !important;
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  margin: 0 !important;
  box-sizing: border-box;
}

/* When Swiper initializes, maintain responsive width */
.prm-related__slider.swiper-initialized .swiper-slide {
  width: auto !important; /* Match card width */
  height: 476px !important;
}

/* Arrow positioning on desktop/tablet - outside slider but visible */
@media (min-width: 768px) {
  .prm-related__arrow--prev {
    left: -60px;
  }
  
  .prm-related__arrow--next {
    right: -60px;
  }
}

/* Arrow positioning on mobile - inside slider */
@media (max-width: 767px) {
  .prm-related {
    padding-left: 0;
    padding-right: 0;
  }
  
  .prm-related__arrow--prev {
    left: 8px;
  }
  
  .prm-related__arrow--next {
    right: 8px;
  }
  
  .prm-related__arrow svg {
    width: 20px;
    height: 20px;
  }
}

/* Mobile (≤767px): 1 card per view - full width */
@media (max-width: 767px) {
  .prm-related__card {
    width: calc(100vw - 80px) !important;
    min-width: 280px !important;
    max-width: calc(100vw - 80px) !important;
    height: auto;
    min-height: 400px;
  }
  
  .prm-related__slider .swiper-slide {
    width: auto !important;
    height: auto;
  }
  
  .prm-related__media {
    height: 240px;
  }
}

/* Tablet (768-1024px): 2 cards per view */
@media (min-width: 768px) and (max-width: 1024px) {
  .prm-related__card {
    /* Width calculated to fit 2 cards: (container - spacing) / 2 */
    /* Container is typically ~900-1000px, spacing is 16px, so: (1000 - 16) / 2 = ~492px */
    /* But we want a bit smaller to ensure fit, so use ~380px */
    width: clamp(320px, calc((100vw - 120px) / 2.2), 420px) !important;
    min-width: 320px !important;
    max-width: 420px !important;
    height: 476px !important;
  }
}

/* Desktop (≥1025px): 3+ cards per view - optimal width for multiple cards */
@media (min-width: 1025px) {
  .prm-related__card {
    /* Calculate width based on viewport to ensure cards scale properly */
    /* For 1140px container with 24px spacing: optimal is ~364px for 3 cards */
    /* Use viewport-based calculation that scales: (100vw - padding) / approximate cards */
    /* This allows Swiper's 'auto' mode to show 3-4 cards depending on screen size */
    width: clamp(
      320px, /* Minimum to ensure readability */
      calc((100vw - 200px) / 3.5), /* Scales with viewport, allows 3-4 cards */
      380px  /* Maximum to prevent cards from being too wide */
    ) !important;
    min-width: 320px !important;
    max-width: 380px !important;
    height: 476px !important;
  }
}

/* ---- Accessibility ---- */
.prm-related__link:focus-visible {
  outline: 2px solid var(--prm-ra-blue);
  outline-offset: 4px;
  border-radius: 4px;
}

/* ---- Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
  .prm-related__card,
  .prm-related__meta,
  .prm-related__post-title,
  .prm-related__excerpt,
  .prm-related__arrow,
  .prm-related__title-arrow {
    transition: none !important;
  }
}

/* ---- Print Styles ---- */
@media print {
  .prm-related__arrow,
  .prm-related__dots {
    display: none;
  }

  .prm-related__card {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

