/* Image Modal Mobile Responsiveness */

/* Base modal styling */
#image-modal {
    /* Ensure modal adapts to viewport height on mobile */
    height: 100vh !important;
    height: 100dvh !important;
    /* Dynamic viewport height for mobile browsers */
}

/* Modal content container */
#image-modal>div {
    max-height: 100% !important;
    overflow: hidden;
}

/* Modal footer base styling - target the footer flex container */
#image-modal div[style*="border-top"] div[style*="justify-content: space-between"] {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
    gap: 1rem !important;
}

/* Navigation buttons on larger screens */
@media (min-width: 769px) {

    #image-modal button[id*="modal-prev-btn"],
    #image-modal button[id*="modal-next-btn"] {
        transition: opacity 0.2s ease;
    }

    #image-modal button[id*="modal-prev-btn"]:hover,
    #image-modal button[id*="modal-next-btn"]:hover {
        opacity: 0.8;
    }
}

/* Tablet responsiveness */
@media (max-width: 1024px) {
    #image-modal {
        padding: 1rem !important;
    }
}

/* Mobile responsiveness */
@media (max-width: 768px) {

    /* Adjust modal padding on mobile */
    #image-modal {
        padding: 0.5rem !important;
    }

    /* Make modal footer responsive - stack vertically */
    #image-modal div[style*="border-top"] div[style*="justify-content: space-between"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
    }

    /* Style the buttons container on mobile */
    #image-modal div[style*="border-top"] div[style*="justify-content: space-between"]>div:last-child {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        width: 100% !important;
    }

    /* Make modal buttons full width on mobile */
    #image-modal .rz-button {
        width: 100% !important;
        justify-content: center !important;
        min-height: 2.75rem !important;
        font-size: 0.9rem !important;
        padding: 0.75rem 1rem !important;
    }

    /* Reduce modal header and footer padding */
    #image-modal div[style*="padding: 1rem"] {
        padding: 0.75rem !important;
    }

    /* Ensure text content has proper spacing */
    #image-modal div[style*="border-top"] div[style*="justify-content: space-between"]>div:first-child {
        margin-bottom: 0.5rem;
        line-height: 1.4;
    }

    /* Improve text readability in modal */
    #image-modal div[style*="border-top"] div strong {
        display: block;
        margin-bottom: 0.5rem;
        font-size: 1rem;
    }

    #image-modal div[style*="border-top"] div small {
        display: block;
        line-height: 1.4;
        margin-bottom: 0.35rem;
        font-size: 0.85rem;
    }

    /* Caption styling */
    #image-modal div[style*="font-style: italic"] {
        margin: 0.75rem 0 !important;
        padding: 0.5rem;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 4px;
        border-left: 3px solid var(--rz-primary);
    }

    /* Navigation buttons on mobile */
    #image-modal button[id*="modal-prev-btn"],
    #image-modal button[id*="modal-next-btn"] {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.2rem !important;
    }

    /* Close button */
    #image-modal button[id*="modal-close-btn"] {
        padding: 0.5rem !important;
        font-size: 1.2rem !important;
        min-width: auto !important;
        width: auto !important;
    }
}

@media (max-width: 480px) {

    /* Extra small screens - further optimize modal */
    #image-modal {
        padding: 0.25rem !important;
    }

    /* Further reduce padding */
    #image-modal div[style*="padding: 1rem"],
    #image-modal div[style*="padding: 0.75rem"] {
        padding: 0.5rem !important;
    }

    /* Optimize button sizing for small screens */
    #image-modal .rz-button {
        min-height: 2.5rem !important;
        font-size: 0.85rem !important;
        padding: 0.625rem 0.75rem !important;
    }

    /* Stack buttons with smaller gap */
    #image-modal div[style*="border-top"] div[style*="justify-content: space-between"]>div:last-child {
        gap: 0.5rem !important;
    }

    /* Reduce modal header font sizes */
    #image-modal h6 {
        font-size: 1rem !important;
        line-height: 1.3 !important;
        margin: 0 !important;
    }

    #image-modal small {
        font-size: 0.75rem !important;
    }

    /* Optimize text in footer */
    #image-modal div[style*="border-top"] div strong {
        font-size: 0.9rem;
    }

    #image-modal div[style*="border-top"] div small {
        font-size: 0.8rem;
        margin-bottom: 0.25rem;
    }

    /* Smaller navigation buttons */
    #image-modal button[id*="modal-prev-btn"],
    #image-modal button[id*="modal-next-btn"] {
        width: 35px !important;
        height: 35px !important;
        font-size: 1rem !important;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #image-modal {
        padding: 0.25rem !important;
    }

    #image-modal div[style*="padding: 1rem"] {
        padding: 0.5rem !important;
    }

    /* Ensure buttons don't take too much space in landscape */
    #image-modal div[style*="border-top"] div[style*="justify-content: space-between"]>div:last-child {
        flex-direction: row !important;
        justify-content: center !important;
        gap: 0.5rem !important;
    }

    #image-modal .rz-button {
        width: auto !important;
        min-width: 120px !important;
        flex: 1;
    }
}

/* Ensure proper touch targets on touch devices */
@media (hover: none) and (pointer: coarse) {
    #image-modal .rz-button {
        min-height: 2.75rem !important;
        touch-action: manipulation;
    }

    #image-modal button[id*="modal-prev-btn"],
    #image-modal button[id*="modal-next-btn"],
    #image-modal button[id*="modal-close-btn"] {
        min-height: 2.75rem !important;
        min-width: 2.75rem !important;
        touch-action: manipulation;
    }
}