/* Good Morning Gallery Enhanced - Fixed Performance & Aspect Ratio */

/* Gallery Container */
.gmg-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin: 20px 0;
    padding: 0;
}

/* Grid Layout Variations */
.gmg-gallery.gmg-layout-grid[data-columns="2"] {
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}

.gmg-gallery.gmg-layout-grid[data-columns="3"] {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.gmg-gallery.gmg-layout-grid[data-columns="4"] {
    grid-template-columns: repeat(4, minmax(200px, 1fr));
}

.gmg-gallery.gmg-layout-grid[data-columns="5"] {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* Card Styles - Optimized for Performance */
.gmg-card {
    background: #ffffff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); /* Lighter shadow for better performance */
    transition: transform 0.2s ease, box-shadow 0.2s ease; /* Faster, smoother transitions */
    position: relative;
    border: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    max-width: 100%;
    will-change: transform; /* Optimize for animations */
}

.gmg-card:hover {
    transform: translateY(-3px); /* Reduced movement for better performance */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.12);
}

/* Image Container - FIXED ASPECT RATIO ISSUE */
.gmg-image-container {
    position: relative;
    overflow: hidden;
    background: #f8f9fa;
    /* REMOVED: aspect-ratio: 1; - This was cutting off rectangular images! */
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px; /* Minimum height for very wide images */
}

.gmg-image-container img {
    width: 100%;
    height: auto; /* CHANGED: Let height adjust naturally */
    max-height: 400px; /* Prevent extremely tall images */
    display: block;
    object-fit: contain; /* CHANGED: Show full image without cropping */
    transition: transform 0.2s ease; /* Faster transition */
    background: #f8f9fa; /* Match container background */
}

/* Alternative: If you want consistent heights but no cropping */
.gmg-image-container.gmg-fixed-height {
    height: 300px; /* Fixed height */
}

.gmg-image-container.gmg-fixed-height img {
    height: 100%;
    width: auto;
    object-fit: contain; /* Show full image, add letterboxing if needed */
}

.gmg-card:hover .gmg-image-container img {
    transform: scale(1.01); /* Reduced scale for better performance */
}

/* Caption Styling - Optimized */
.gmg-caption {
    padding: 15px 15px 15px 15px !important;
    background: #ffffff;
    text-align: left;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    position: relative;
    display: flex;
    align-items: center;
    min-height: 50px;
    overflow: visible !important;
}

.gmg-caption p {
    margin: 0;
    font-size: 12px;
    line-height: 1.3;
    color: #888888;
    font-weight: 400;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    padding-right: 30px !important;
    flex: 1;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Copy Button - Optimized */
.gmg-caption-copy-btn {
    position: absolute;
    top: 50%;
    right: 0px;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 1;
    z-index: 10;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); /* Lighter shadow */
    transition: all 0.15s ease; /* Faster transition */
}

.gmg-caption-copy-btn:hover {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transform: translateY(-50%) scale(1.02); /* Reduced scale */
}

.gmg-caption-copy-btn:active {
    transform: translateY(-50%) scale(0.98);
}

.gmg-caption-copy-btn img {
    width: 16px;
    height: 16px;
}

/* Action Buttons Container */
.gmg-actions {
    display: flex;
    background: #ffffff;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* Download and Share Buttons - Performance Optimized */
.gmg-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.15s ease; /* Optimized transitions */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border-radius: 0;
    height: 44px;
}

.gmg-btn:first-child {
    border-bottom-left-radius: 20px;
}

.gmg-btn:last-child {
    border-bottom-right-radius: 20px;
}

.gmg-btn + .gmg-btn {
    border-left: 1px solid rgba(255, 255, 255, 0.2);
}

/* Download Button */
.gmg-btn-download {
    background: #6c757d;
}

.gmg-btn-download:hover {
    background: #5a6268;
    transform: translateY(-1px);
    color: #ffffff;
    text-decoration: none;
}

/* Share Button */
.gmg-btn-share {
    background: #25D366;
}

.gmg-btn-share:hover {
    background: #128C7E;
    transform: translateY(-1px);
    color: #ffffff;
    text-decoration: none;
}

.gmg-btn svg {
    width: 14px;
    height: 14px;
    stroke-width: 2;
}

/* Toast Notification - Optimized */
.gmg-toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #333333;
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    z-index: 10000;
    font-weight: 500;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.gmg-toast.show {
    transform: translateX(0);
}

.gmg-toast-message {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* PERFORMANCE BOOST: Disable expensive animations by default */
.gmg-card {
    /* Remove hover animations that slow things down */
    transition: none;
}

.gmg-card:hover {
    /* Remove hover transform - this was causing lag */
    transform: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); /* Keep same shadow */
}

.gmg-image-container img {
    /* Remove image scaling on hover - major performance killer */
    transition: none;
}

.gmg-card:hover .gmg-image-container img {
    transform: none; /* Remove scale effect */
}

/* Only enable animations on powerful devices */
@media (prefers-reduced-motion: no-preference) and (min-width: 1024px) {
    .gmg-card {
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    
    .gmg-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
}

/* Loading States - Optimized */
.gmg-card.loading .gmg-image-container {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.2s infinite; /* Faster animation */
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Responsive Design - Mobile Optimized */
@media (max-width: 768px) {
    .gmg-gallery {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 15px;
        margin: 15px 0;
    }
    
    .gmg-gallery.gmg-layout-grid[data-columns="2"],
    .gmg-gallery.gmg-layout-grid[data-columns="3"],
    .gmg-gallery.gmg-layout-grid[data-columns="4"],
    .gmg-gallery.gmg-layout-grid[data-columns="5"] {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
    
    .gmg-card {
        border-radius: 16px;
    }
    
    .gmg-btn:first-child {
        border-bottom-left-radius: 16px;
    }
    
    .gmg-btn:last-child {
        border-bottom-right-radius: 16px;
    }
    
    .gmg-caption {
        padding: 12px 12px 12px 12px !important;
        min-height: 45px;
    }
    
    .gmg-caption p {
        font-size: 11px;
        padding-right: 25px !important;
    }
    
    .gmg-caption-copy-btn {
        right: 0px;
        width: 24px;
        height: 24px;
    }
    
    .gmg-caption-copy-btn img {
        width: 14px;
        height: 14px;
    }
    
    .gmg-btn {
        padding: 10px 6px;
        font-size: 12px;
        height: 40px;
    }
    
    .gmg-toast {
        bottom: 20px;
        right: 20px;
        left: 20px;
        transform: translateY(100px);
    }
    
    .gmg-toast.show {
        transform: translateY(0);
    }
}

@media (max-width: 480px) {
    .gmg-gallery {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .gmg-gallery.gmg-layout-grid[data-columns="2"],
    .gmg-gallery.gmg-layout-grid[data-columns="3"],
    .gmg-gallery.gmg-layout-grid[data-columns="4"],
    .gmg-gallery.gmg-layout-grid[data-columns="5"] {
        grid-template-columns: 1fr;
    }
    
    .gmg-card {
        border-radius: 12px;
    }
    
    .gmg-btn:first-child {
        border-bottom-left-radius: 12px;
    }
    
    .gmg-btn:last-child {
        border-bottom-right-radius: 12px;
    }
    
    .gmg-btn {
        padding: 8px 4px;
        font-size: 11px;
        height: 36px;
    }
    
    .gmg-btn svg {
        width: 12px;
        height: 12px;
    }
}

/* Accessibility */
.gmg-btn:focus,
.gmg-caption-copy-btn:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.gmg-card:focus-within {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .gmg-actions,
    .gmg-caption-copy-btn,
    .gmg-toast {
        display: none !important;
    }
    
    .gmg-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .gmg-card {
        border: 2px solid #000;
    }
    
    .gmg-btn {
        border: 2px solid #000;
    }
}

/* Pagination Styles */
.gmg-pagination {
    display: flex;
    justify-content: center;
    margin: 30px 0;
    gap: 8px;
    flex-wrap: wrap;
}

.gmg-pagination a, 
.gmg-pagination span {
    padding: 10px 16px;
    border: 1px solid #ddd;
    text-decoration: none;
    color: #0073aa;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 44px;
    text-align: center;
}

.gmg-pagination a:hover {
    background-color: #f0f0f0;
    transform: translateY(-1px); /* Reduced movement */
}

.gmg-pagination .gmg-pagination-current {
    background-color: #0073aa;
    color: white;
    border-color: #0073aa;
}

.gmg-pagination-prev,
.gmg-pagination-next {
    font-weight: 600;
}

@media (max-width: 768px) {
    .gmg-pagination {
        gap: 6px;
        margin: 20px 0;
    }
    
    .gmg-pagination a, 
    .gmg-pagination span {
        padding: 8px 12px;
        min-width: 40px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .gmg-pagination {
        gap: 4px;
    }
    
    .gmg-pagination a, 
    .gmg-pagination span {
        padding: 6px 10px;
        min-width: 36px;
        font-size: 13px;
    }
}

/* Override theme CSS conflicts for copy button image */
.gmg-caption-copy-btn img {
    width: 16px !important;
    height: 16px !important;
    max-width: 16px !important;
    max-height: 16px !important;
    min-width: 16px !important;
    min-height: 16px !important;
    display: block !important;
    object-fit: contain !important;
    flex-shrink: 0 !important;
}