/* Instagram Feed Styles */
.instagram-feed-container {
    position: relative;
    max-width: 100%;
    overflow: hidden;
}

/* Use CSS variables for dynamic sizing */
.instagram-feed {
    --posts-per-view: 4;
    --gap: 1rem;
    display: flex;
    gap: var(--gap);
    scroll-behavior: smooth;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
    padding: 1rem 0;
    scroll-snap-type: x mandatory;
}

.instagram-feed::-webkit-scrollbar {
    display: none; /* Chrome, Safari and Opera */
}

/* Each card width is calculated so a whole number fits without cropping */
.instagram-post {
    flex: 0 0 calc((100% - (var(--gap) * (var(--posts-per-view) - 1))) / var(--posts-per-view));
    height: 300px;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.35s ease, box-shadow 0.35s ease;
    background: #f5f5f5;
    scroll-snap-align: start;
}

.instagram-post:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

.instagram-post img,
.instagram-post video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.instagram-post:hover img,
.instagram-post:hover video {
    transform: scale(1.05);
}

.instagram-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent 60%);
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: flex-end;
    padding: 1.5rem;
}

.instagram-post:hover .instagram-overlay {
    opacity: 1;
}

.instagram-caption {
    color: white;
    font-size: 0.9rem;
    line-height: 1.4;
    max-height: 80px;
    overflow: hidden;
    position: relative;
}

.instagram-caption.truncated::after {
    content: "...";
    position: absolute;
    bottom: 0;
    right: 0;
    background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.8) 50%);
    padding-left: 20px;
}

.video-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 15px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.video-play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #333;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.instagram-post:hover .video-play-button {
    opacity: 1;
}

/* Navigation Buttons */
.instagram-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #333;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.instagram-nav-btn:hover {
    background: white;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.instagram-nav-prev {
    left: 15px;
}

.instagram-nav-next {
    right: 15px;
}

.instagram-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.instagram-nav-btn:disabled:hover {
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
}

/* Loading State */
.instagram-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: #666;
    font-size: 1.1rem;
}

.instagram-loading i {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: #2c6e49;
}

/* Error State */
.instagram-error {
    text-align: center;
    padding: 2rem;
    color: #e74c3c;
    background: #fdf2f2;
    border-radius: 8px;
    margin: 1rem 0;
}

/* Modal Styles */
.instagram-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    background-color: white;
    margin: 2% auto;
    width: 90%;
    max-width: 1000px;
    max-height: 90vh;
    border-radius: 12px;
    overflow: hidden;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.7); }
    to { opacity: 1; transform: scale(1); }
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.7);
}

.modal-body {
    display: flex;
    height: 80vh;
}

.modal-media {
    flex: 1;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.modal-media img,
.modal-media video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.modal-info {
    width: 350px;
    background: white;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #eee;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: flex-start;
}

.profile-pic {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #ddd;
}

.profile-info h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #333;
}

.post-date {
    color: #666;
    font-size: 0.9rem;
    margin: 0;
}

.modal-caption {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    line-height: 1.6;
    color: #333;
}

.modal-engagement {
    padding: 1.5rem;
    border-top: 1px solid #eee;
}

.engagement-stats {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.engagement-stats span {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #666;
    font-size: 0.9rem;
}

.engagement-stats i {
    color: #e91e63;
}

.view-on-instagram a {
    color: #2c6e49;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

.view-on-instagram a:hover {
    color: #1a4029;
}

/* Responsive Modal */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        height: 95vh;
        margin: 2.5% auto;
    }

    .modal-body {
        flex-direction: column;
        height: auto;
    }

    .modal-media {
        height: 60vh;
    }

    .modal-info {
        width: 100%;
        max-height: 35vh;
        overflow-y: auto;
    }
}

@media (max-width: 1023px) {
    .instagram-feed { --posts-per-view: 3; }
}
@media (max-width: 767px) {
    .instagram-feed { --posts-per-view: 2; }
}
@media (max-width: 479px) {
    .instagram-feed { --posts-per-view: 1; }
    .instagram-post { height: 280px; }
    .instagram-nav-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    .instagram-nav-prev { left: -20px; }
    .instagram-nav-next { right: -20px; }
}

/* Accessibility */
.instagram-post:focus,
.instagram-nav-btn:focus,
.modal-close:focus {
    outline: 2px solid #2c6e49;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .instagram-modal {
        display: none !important;
    }
}
