/*
   JKB PRECISION ALIGNMENT DESIGN (12% Top Margin)
   Sincronización y Suspensión desplazadas un 3% extra adicional (12% total).
   Motor, Carrocería, Lubricación y Refrigeración al 6% superior.
*/

.seccion-autopartes-compact {
  background: transparent;
  padding: 0 0 1vh;
  font-family: 'Poppins', sans-serif;
  height: auto;
  min-height: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  box-sizing: border-box;
  overflow: visible;
  margin: 0;
}

.autopartes-header-compact {
  position: relative;
  z-index: 3;
  width: min(100%, 1180px);
  min-height: 64px;
  margin: 0 auto 18px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  box-sizing: border-box;
  white-space: nowrap;
  background: #ffffff;
  border-bottom: 1px solid rgba(26, 42, 79, 0.12);
}

.autopartes-header-compact h2 {
  font-family: 'Poppins', sans-serif;
  font-size: clamp(1.2rem, 1.8vw, 1.6rem);
  font-weight: 600;
  color: #1a2a4f;
  line-height: 1;
  letter-spacing: -0.2px;
  margin: 0;
}

.autopartes-contacto-compact {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: 'Poppins', sans-serif;
}

.autopartes-contacto-compact span {
  color: #1a2a4f;
  font-size: clamp(0.8rem, 0.9vw, 0.9rem);
  font-weight: 500;
}

.autopartes-contacto-compact a {
  padding: 6px 12px;
  border-radius: 8px;
  color: #fff;
  background: #1a2a4f;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.autopartes-contacto-compact a:last-child {
  background: #25D366;
}

.autopartes-contacto-compact a:hover {
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 10px 22px rgba(26,42,79,0.14);
}

.grid-fichas-compact {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, auto);
  gap: 0;
  max-width: 100%;
  margin: 0 auto;
  padding: 0;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #e8e8e8;
  border-radius: 0;
  overflow: hidden;
}

.ficha-compact {
  background: #ffffff;
  border: none;
  border-bottom: 1px solid #e8e8e8;
  border-right: 1px solid #e8e8e8;
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  display: flex;
  flex-direction: row;
  position: relative;
  overflow: visible;
  padding: 14px 20px;
  justify-content: flex-start;
  align-items: center;
  box-sizing: border-box;
  gap: 24px;
  cursor: pointer;
}

/* Eliminar bordes internos sobrantes */
.ficha-compact:nth-child(2n) {
  border-right: none;
}
.ficha-compact:nth-last-child(-n+2) {
  border-bottom: none;
}

.ficha-compact:hover {
  border-color: transparent;
  box-shadow: none;
  transform: none;
}

/* ── Línea divisoria hover horizontal (inferior) ── */
.ficha-compact::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, #1a2a4f, transparent);
  transition: width 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94), left 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 5;
}

.ficha-compact:hover::after {
  width: 100%;
  left: 50%;
}

/* Línea vertical hover para separación entre columnas */
.ficha-compact:nth-child(odd)::before {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  width: 1px;
  height: 0;
  background: linear-gradient(180deg, transparent, #1a2a4f, transparent);
  transition: height 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94), top 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 5;
}

.ficha-compact:nth-child(odd):hover::before {
  height: 100%;
  top: 50%;
}

.ficha-imagen-compact {
  flex: 0 0 203px;
  width: 203px;
  height: 203px;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1;
  transition: all 0.4s ease;
  position: relative;
  top: auto;
  left: auto;
  transform: none;
}

.ficha-imagen-compact img {
  max-width: 203px;
  max-height: 186px;
  width: auto;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.06));
  transition: transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.ficha-carroceria .ficha-imagen-compact img,
.ficha-refrigeracion .ficha-imagen-compact img {
  max-width: 237px;
  max-height: 203px;
}

.ficha-motor .ficha-imagen-compact img {
  max-width: 304px;
  max-height: 220px;
  margin-top: 0;
}

.ficha-compact:hover .ficha-imagen-compact img {
  transform: scale(1.06);
}

/* ── Línea hover entre imagen y texto (con tolerancia) ── */
.ficha-imagen-compact::after {
  content: '';
  position: absolute;
  right: -16px;
  top: 50%;
  width: 2px;
  height: 0;
  background: linear-gradient(180deg, transparent 5%, #1a2a4f 30%, #1a2a4f 70%, transparent 95%);
  border-radius: 2px;
  transition: height 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94), top 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 5;
}

.ficha-compact:hover .ficha-imagen-compact::after {
  height: 60%;
  top: 50%;
}

.ficha-contenido-compact {
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  flex: 1;
  position: relative;
  z-index: 2;
  pointer-events: none;
  padding: 0;
  background: transparent;
  bottom: auto;
  left: auto;
}

.ficha-categoria-compact {
  font-size: clamp(0.95rem, 1.2vw, 1.1rem);
  font-weight: 700;
  color: #1a2a4f;
  margin: 0 0 4px 0;
  text-transform: capitalize;
  pointer-events: auto;
  text-shadow: none;
}

.ficha-descripcion-compact {
  font-size: clamp(0.72rem, 0.9vw, 0.82rem);
  color: #444;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: all 0.4s ease;
  margin: 0 0 2px 0 !important;
  padding: 0;
  pointer-events: auto;
  text-shadow: none;
}

.ficha-compact:hover .ficha-descripcion-compact {
  max-height: 4em;
  opacity: 1;
}

.btn-wa-compact {
  min-width: 130px;
  background: #1a2a4f;
  color: #ffffff !important;
  padding: 7px 12px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.75rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  opacity: 0;
  transform: translateY(5px) scale(1.03);
  transition: transform 0.3s ease, opacity 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
  pointer-events: auto;
  box-shadow: 0 6px 18px rgba(26,42,79,0.14);
  margin-top: 0;
  position: relative;
  overflow: hidden;
}

.btn-wa-compact::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 0 28%, rgba(255,255,255,0.18) 45%, transparent 62% 100%);
  transform: translateX(-120%);
  transition: transform 0.58s ease;
  pointer-events: none;
}

.btn-wa-compact i,
.btn-wa-compact span {
  position: relative;
  z-index: 1;
}

.btn-wa-compact i {
  font-size: 0.78rem;
}

.btn-wa-compact .fa-whatsapp {
  color: #25D366;
  font-size: 0.9rem;
}

.ficha-compact:hover .btn-wa-compact {
  opacity: 1;
  transform: translateY(0);
  background: #142343;
  box-shadow: 0 10px 26px rgba(26,42,79,0.2);
  margin-top: 4px;
}

.ficha-compact:hover .btn-wa-compact::before {
  transform: translateX(120%);
}

.btn-wa-compact:hover {
  color: #fff !important;
  background: #25D366 !important;
  transform: translateY(-2px) scale(1.02) !important;
  box-shadow: 0 12px 28px rgba(37,211,102,0.28);
}

.btn-wa-compact:hover .fa-whatsapp {
  color: #fff;
}

@media (max-width: 900px) {
  .autopartes-header-compact {
    width: 100%;
    min-height: auto;
    padding: 14px 18px;
    margin-bottom: 14px;
    justify-content: center;
    gap: 12px;
  }

  .autopartes-header-compact h2 {
    font-size: clamp(1.08rem, 3.5vw, 1.35rem);
  }

  .autopartes-contacto-compact span {
    font-size: 0.82rem;
  }

  .autopartes-contacto-compact a {
    padding: 6px 10px;
  }

  .grid-fichas-compact {
    grid-template-columns: 1fr;
    border: 1px solid #e8e8e8;
    border-radius: 0;
    overflow: hidden;
    max-width: 100%;
    padding: 0;
  }
  .ficha-compact {
    padding: 12px 14px;
    gap: 14px;
    border-bottom: 1px solid #e8e8e8;
    border-right: none;
  }
  .ficha-compact:last-child {
    border-bottom: none;
  }
  /* Ocultar línea vertical en móvil (1 columna) */
  .ficha-compact:nth-child(odd)::before {
    display: none;
  }
  .ficha-imagen-compact {
    flex: 0 0 100px;
    width: 100px;
    height: 100px;
  }
  .ficha-imagen-compact img {
    max-width: 100px;
    max-height: 90px;
  }
  .ficha-carroceria .ficha-imagen-compact img,
  .ficha-refrigeracion .ficha-imagen-compact img {
    max-width: 120px;
    max-height: 100px;
  }
  .ficha-motor .ficha-imagen-compact img {
    max-width: 140px;
    max-height: 110px;
  }
  .ficha-descripcion-compact {
    max-height: none;
    opacity: 1;
    margin: 2px 0 4px !important;
  }
  .btn-wa-compact {
    opacity: 1;
    transform: translateY(0);
    margin-top: 4px;
  }
}

@media (max-width: 480px) {
  .autopartes-header-compact {
    flex-wrap: wrap;
    padding: 14px 14px;
    gap: 10px;
    white-space: normal;
  }

  .autopartes-header-compact h2 {
    width: 100%;
    text-align: center;
  }

  .autopartes-contacto-compact {
    width: 100%;
    flex-wrap: nowrap;
  }

  .autopartes-contacto-compact span {
    font-size: 0.78rem;
  }

  .autopartes-contacto-compact a {
    flex: 0 0 auto;
    padding: 7px 11px;
  }

  .grid-fichas-compact {
    padding: 0;
  }
  .ficha-compact {
    padding: 10px 12px;
    gap: 12px;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .ficha-contenido-compact {
    text-align: center;
    align-items: center;
  }
  .ficha-descripcion-compact {
    text-align: center;
  }
  .ficha-imagen-compact {
    flex: 0 0 80px;
    width: 80px;
    height: 80px;
  }
  .ficha-imagen-compact img {
    max-width: 80px;
    max-height: 70px;
  }
  /* Ocultar línea separadora imagen-texto en apilado vertical */
  .ficha-imagen-compact::after {
    display: none;
  }
}

/* ====================================================== */
/* ANIMACIÓN SCROLL - PRODUCTOS (ENTRADA/SALIDA)          */
/* Sin alterar nada del CSS existente                     */
/* ====================================================== */

/* Dirección alternada para profundidad editorial */
.ficha-compact:nth-child(odd) {
    --prod-shift-x: -24px;
    --prod-exit-tilt: -3deg;
}

.ficha-compact:nth-child(even) {
    --prod-shift-x: 24px;
    --prod-exit-tilt: 3deg;
}

/* Header: entrada épica y corporativa */
.autopartes-header-compact.prod-enter {
    animation: prodHeaderEnter 1.05s cubic-bezier(0.19, 1, 0.22, 1) forwards;
}

@keyframes prodHeaderEnter {
    0% {
        opacity: 0;
        transform: perspective(980px) translateY(-28px) rotateX(10deg) scale(0.97);
        filter: blur(7px) brightness(0.84);
    }
    62% {
        opacity: 0.92;
        transform: perspective(980px) translateY(3px) rotateX(-1deg) scale(1.004);
        filter: blur(1.2px) brightness(1.04);
    }
    100% {
        opacity: 1;
        transform: perspective(980px) translateY(0) rotateX(0deg) scale(1);
        filter: blur(0) brightness(1);
    }
}

.autopartes-header-compact.prod-exit {
    animation: prodHeaderExit 0.78s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes prodHeaderExit {
    0% {
        opacity: 1;
        transform: perspective(980px) translateY(0) rotateX(0deg) scale(1);
        filter: blur(0) brightness(1);
    }
    100% {
        opacity: 0;
        transform: perspective(980px) translateY(-18px) rotateX(8deg) scale(0.98);
        filter: blur(4px) brightness(0.82);
    }
}

/* Fichas: entrada cinematográfica escalonada */
.ficha-compact.prod-enter {
    animation: prodFichaEnter 1.18s cubic-bezier(0.19, 1, 0.22, 1) var(--prod-delay, 0s) both;
    will-change: transform, opacity, filter;
}

@keyframes prodFichaEnter {
    0% {
        opacity: 0;
        transform: perspective(980px) translate3d(var(--prod-shift-x, 0px), 34px, 0) rotateX(11deg) scale(0.95);
        filter: blur(5px) brightness(0.78) saturate(0.88);
    }
    58% {
        opacity: 0.9;
        transform: perspective(980px) translate3d(0, -3px, 0) rotateX(-1deg) scale(1.006);
        filter: blur(1.1px) brightness(1.05) saturate(1.04);
    }
    84% {
        opacity: 0.98;
        transform: perspective(980px) translate3d(0, 1px, 0) rotateX(0deg) scale(0.998);
        filter: blur(0) brightness(1.02) saturate(1.02);
    }
    100% {
        opacity: 1;
        transform: perspective(980px) translate3d(0, 0, 0) rotateX(0deg) scale(1);
        filter: blur(0) brightness(1) saturate(1);
    }
}

/* Fichas: salida premium con cola visual */
.ficha-compact.prod-exit {
    animation: prodFichaExit 0.86s cubic-bezier(0.4, 0, 0.2, 1) var(--prod-exit-delay, 0s) both;
    will-change: transform, opacity, filter;
}

@keyframes prodFichaExit {
    0% {
        opacity: 1;
        transform: perspective(980px) translate3d(0, 0, 0) rotateX(0deg) scale(1);
        filter: blur(0) brightness(1);
    }
    100% {
        opacity: 0;
        transform: perspective(980px) translate3d(calc(var(--prod-shift-x, 0px) * -0.65), 24px, 0) rotateX(9deg) rotateY(var(--prod-exit-tilt, 0deg)) scale(0.95);
        filter: blur(5px) brightness(0.78) saturate(0.86);
    }
}

@media (prefers-reduced-motion: reduce) {
    .autopartes-header-compact.prod-enter,
    .autopartes-header-compact.prod-exit,
    .ficha-compact.prod-enter,
    .ficha-compact.prod-exit {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
        filter: none !important;
    }
}

/* ====================================================== */
/* JKB TYPOGRAPHY SYSTEM - AUTOPARTES ALIGN               */
/* ====================================================== */
.seccion-autopartes-compact {
    font-family: var(--jk-font-body, "Open Sans", sans-serif);
}

.autopartes-header-compact h2 {
    font-family: var(--jk-font-display, "Poppins", sans-serif);
    font-weight: 700;
    letter-spacing: -0.24px;
    line-height: 1.12;
    color: var(--jk-type-title, #1a2a4f);
}

.autopartes-contacto-compact span {
    font-family: var(--jk-font-body, "Open Sans", sans-serif);
    font-weight: 600;
    letter-spacing: 0;
    line-height: 1.35;
    color: var(--jk-type-subtitle, #2e4e7d);
}

.autopartes-contacto-compact a {
    font-family: var(--jk-font-body, "Open Sans", sans-serif);
    font-weight: 700;
    letter-spacing: 0.01em;
}

.ficha-categoria-compact {
    font-family: var(--jk-font-display, "Poppins", sans-serif);
    font-weight: 700;
    letter-spacing: -0.14px;
    line-height: 1.14;
    color: #173762;
}

.ficha-descripcion-compact {
    font-family: var(--jk-font-body, "Open Sans", sans-serif);
    font-weight: 500;
    letter-spacing: 0;
    line-height: 1.46;
    color: #4d6585;
}

.btn-wa-compact {
    font-family: var(--jk-font-body, "Open Sans", sans-serif);
    font-weight: 700;
    letter-spacing: 0.01em;
}

@media (max-width: 900px) {
    .autopartes-header-compact h2 {
        line-height: 1.16;
        letter-spacing: -0.18px;
    }

    .ficha-categoria-compact {
        line-height: 1.18;
    }

    .ficha-descripcion-compact {
        line-height: 1.5;
    }
}

@media (max-width: 480px) {
    .autopartes-header-compact h2 {
        line-height: 1.18;
        letter-spacing: -0.14px;
    }

    .ficha-categoria-compact {
        letter-spacing: -0.1px;
    }

    .ficha-descripcion-compact {
        font-size: clamp(0.8rem, 3.4vw, 0.88rem);
        line-height: 1.52;
    }
}
