.testimonials-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

.testimonials-layout {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 2rem;
    align-items: flex-start;
    margin: 0 auto;
    min-height: 300px;
}

@media (max-width: 768px) {
    .testimonials-layout {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .phone-container {
        order: -1; /* Move phone to top */
        margin-bottom: 2rem;
    }

    .messages-left,
    .messages-right {
        width: 100%;
        height: auto;
        position: static;
    }

    .message-slot {
        position: relative;
        width: 85%;
        margin-bottom: 1rem;
    }

    /* Reset desktop positions */
    .message-slot-1,
    .message-slot-2,
    .message-slot-3,
    .message-slot-4 {
        top: auto;
        bottom: auto;
        left: auto;
        right: auto;
    }

    /* Align all left messages to right */
    .message-slot.left {
        margin-left: auto;
        margin-right: 0;
    }

    /* Align all right messages to left */
    .message-slot.right {
        margin-left: 0;
        margin-right: auto;
    }
}

.phone-container {
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
}

.phone-frame {
    width: 100%;
    height: auto;
    display: block;
}

.messages-left,
.messages-right {
    position: relative;
    width: 300px;
    height: 500px;
}

.messages-left {
    justify-self: end;
}

.messages-right {
    justify-self: start;
}

.message-slot {
    position: absolute;
    width: 90%;
    padding: 15px 20px;
    border-radius: 15px;
    font-size: 13px;
    text-align: left;
    line-height: 1.4;
    opacity: 0;
    transform: scale(0.3);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

/* Position slots */
.message-slot-1 {
    top: 0;
    right: 0;
}

.message-slot-2 {
    bottom: 0;
    right: 0;
}

.message-slot-3 {
    top: 0;
    left: 0;
}

.message-slot-4 {
    bottom: 0;
    left: 0;
}

.message-slot.fade-in {
    opacity: 1;
    transform: scale(1);
}

.message-slot.fade-out {
    opacity: 0;
    transform: scale(0.3);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

/* Common message slot styles */
.message-slot {
    position: relative;
}

.message-slot.left {
    background: #1E1E1E;
    color: white;
    border-bottom-right-radius: 2px;
    margin-bottom: 20px;
}

.message-slot.right {
    background: #1E1E1E;
    color: white;
    border-bottom-left-radius: 2px;
    margin-bottom: 20px;
}

/* Chat bubble tails */
.message-slot.left::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -8px;
    width: 15px;
    height: 15px;
    background: inherit;
    clip-path: polygon(0 0, 0% 100%, 100% 100%);
}

.message-slot.right::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 15px;
    height: 15px;
    background: inherit;
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.message-content {
    margin-bottom: 5px;
}

.message-time {
    display: block;
    font-size: 12px;
    opacity: 0.8;
    text-align: right;
}

@keyframes zoomInFade {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeOut {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.8);
    }
}

.message {
    max-width: 100%;
    padding: 1rem 1.5rem;
    border-radius: 1rem;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    word-wrap: break-word;
    background-color: #333;
    color: white;
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.4;
    opacity: 0;
    transform: scale(0.3);
    will-change: transform, opacity;
}

.message.animate-in {
    animation: zoomInFade 0.5s ease forwards;
}

.message.animate-out {
    animation: fadeOut 0.5s ease forwards;
}

.message.left {
  border-bottom-right-radius: 0.3rem;
  margin-right: 2rem;
}

.message.right {
  border-bottom-left-radius: 0.3rem;
  margin-left: 2rem;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 0.5rem;
    display: block;
}

@media (max-width: 1024px) {
  .testimonials-layout {
      grid-template-columns: 1fr;
      max-width: 800px;
      gap: 3rem;
      padding: 0;
  }

  .phone-container {
      display: none;
  }

  .messages-left,
  .messages-right {
      margin: 0 auto;
  }

  .message.left {
    border-bottom-right-radius: 0.3rem;
    margin-right: 0;
  }
  
  .message.right {
    border-bottom-left-radius: 0.3rem;
    margin-left: 0;
  }
}

/* Mobile responsiveness */
/* Desktop/Mobile Layout Control */
.desktop-layout { display: grid; }
.mobile-layout { display: none; }

@media (max-width: 768px) {
    .desktop-layout { display: none; }
    .mobile-layout { display: block; }

    .mobile-messages {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .mobile-layout .message-slot {
        position: relative;
        width: 100%;
        margin: 0.25rem 0;
        opacity: 0;
        transform: scale(0.3);
        transition: all 0.5s ease;
        will-change: opacity, transform;
    }

    .mobile-layout .message-slot.fade-out {
        opacity: 0;
        transform: scale(0.3);
    }

    .mobile-layout .message-slot.fade-in {
        opacity: 1;
        transform: scale(1);
    }

    /* Ensure transitions work in both directions */
    .mobile-layout .message-slot.fade-in,
    .mobile-layout .message-slot.fade-out {
        transition: opacity 0.5s ease, transform 0.5s ease;
    }

    .mobile-layout .message-slot.left {
        align-self: flex-end;
        margin-left: 1rem;
    }

    .mobile-layout .message-slot.right {
        align-self: flex-start;
        margin-right: 1rem;
    }

    .phone-container {
        display: none;
    }
}
