/**
 * WordPress Classic Editor Image Styles
 * 
 * This stylesheet provides responsive support for:
 * - Image alignment (left, right, center, none)
 * - Image captions (.wp-caption and figcaption)
 * - Image galleries
 * - Legacy alignment classes
 * 
 * @package AccessWellbeing
 * @since 1.0.0
 */

/* ==========================================================================
   Base Image Styles
   ========================================================================== */

.blog-post-content img,
.entry-content img,
.post-content img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
}

/* ==========================================================================
   Image Alignment Classes
   ========================================================================== */

/**
 * Align Left
 * Floats image to the left with text wrapping on the right
 */
.alignleft {
    display: inline;
    float: left;
    margin: 0.5rem 1.5rem 1rem 0;
    max-width: 50%;
}

/**
 * Align Right
 * Floats image to the right with text wrapping on the left
 */
.alignright {
    display: inline;
    float: right;
    margin: 0.5rem 0 1rem 1.5rem;
    max-width: 50%;
}

/**
 * Align Center
 * Centers the image with no text wrapping
 */
.aligncenter {
    display: block;
    margin-left: auto;
    margin-right: auto;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    clear: both;
}

/**
 * Align None
 * Default alignment, block level with margins
 */
.alignnone {
    display: block;
    margin: 1.5rem 0;
}

/* ==========================================================================
   WordPress Caption Styles (.wp-caption)
   ========================================================================== */

/**
 * Caption Container
 * Wraps the image and caption text
 */
.wp-caption {
    max-width: 100%;
    background: var(--lighter, #f3f5f5);
    border-radius: 0.75rem;
    padding: 0.5rem;
    margin-bottom: 1.5rem;
}

.wp-caption img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 0.5rem;
}

/**
 * Caption Text
 */
.wp-caption-text,
.wp-caption .wp-caption-text {
    font-size: 0.85rem;
    color: #666;
    text-align: center;
    padding: 0.75rem 0.5rem 0.25rem;
    line-height: 1.4;
    font-style: italic;
}

/* Caption alignment variations */
.wp-caption.alignleft {
    float: left;
    margin: 0.5rem 1.5rem 1rem 0;
    max-width: 50%;
}

.wp-caption.alignright {
    float: right;
    margin: 0.5rem 0 1rem 1.5rem;
    max-width: 50%;
}

.wp-caption.aligncenter {
    float: none;
    display: block;
    margin: 1.5rem auto;
}

.wp-caption.alignnone {
    float: none;
    margin: 1.5rem 0;
}

/* ==========================================================================
   HTML5 Figure and Figcaption Styles
   ========================================================================== */

/**
 * Figure Element
 * Modern semantic image container
 */
.blog-post-content figure,
.entry-content figure,
.post-content figure {
    max-width: 100%;
    margin: 1.5rem 0;
    padding: 0;
}

.blog-post-content figure img,
.entry-content figure img,
.post-content figure img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 0.75rem;
}

/**
 * Figcaption Element
 */
.blog-post-content figcaption,
.entry-content figcaption,
.post-content figcaption {
    font-size: 0.85rem;
    color: #666;
    text-align: center;
    padding: 0.75rem 0.5rem;
    line-height: 1.4;
    font-style: italic;
    background: var(--lighter, #f3f5f5);
    border-radius: 0 0 0.75rem 0.75rem;
    margin-top: -0.5rem;
}

/* Figure alignment */
figure.alignleft {
    float: left;
    margin: 0.5rem 1.5rem 1rem 0;
    max-width: 50%;
}

figure.alignright {
    float: right;
    margin: 0.5rem 0 1rem 1.5rem;
    max-width: 50%;
}

figure.aligncenter {
    display: block;
    margin: 1.5rem auto;
    text-align: center;
}

figure.alignnone {
    margin: 1.5rem 0;
}

/* ==========================================================================
   WordPress Block Editor Image Styles (Gutenberg)
   ========================================================================== */

/**
 * Block Image Alignment
 */
.wp-block-image {
    margin: 1.5rem 0;
}

.wp-block-image img {
    max-width: 100%;
    height: auto;
    border-radius: 0.75rem;
}

.wp-block-image figcaption {
    font-size: 0.85rem;
    color: #666;
    text-align: center;
    padding: 0.75rem 0;
    font-style: italic;
}

.wp-block-image.alignleft {
    float: left;
    margin: 0.5rem 1.5rem 1rem 0;
    max-width: 50%;
}

.wp-block-image.alignright {
    float: right;
    margin: 0.5rem 0 1rem 1.5rem;
    max-width: 50%;
}

.wp-block-image.aligncenter {
    margin: 1.5rem auto;
}

.wp-block-image.alignwide,
.wp-block-image.alignfull {
    max-width: 100%;
    margin: 2rem 0;
}

/* ==========================================================================
   WordPress Gallery Styles
   ========================================================================== */

/**
 * Classic Gallery
 */
.gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 1.5rem 0;
    clear: both;
}

.gallery-item {
    flex: 1 1 calc(33.333% - 1rem);
    min-width: 150px;
    margin: 0;
}

.gallery-item img {
    width: 100%;
    height: auto;
    border-radius: 0.5rem;
    display: block;
}

.gallery-caption {
    font-size: 0.8rem;
    color: #666;
    text-align: center;
    padding: 0.5rem;
    font-style: italic;
}

/* Gallery column variations */
.gallery-columns-1 .gallery-item {
    flex-basis: 100%;
}

.gallery-columns-2 .gallery-item {
    flex-basis: calc(50% - 0.5rem);
}

.gallery-columns-3 .gallery-item {
    flex-basis: calc(33.333% - 0.75rem);
}

.gallery-columns-4 .gallery-item {
    flex-basis: calc(25% - 0.75rem);
}

.gallery-columns-5 .gallery-item {
    flex-basis: calc(20% - 0.8rem);
}

.gallery-columns-6 .gallery-item {
    flex-basis: calc(16.666% - 0.85rem);
}

/* ==========================================================================
   Clear Floats
   ========================================================================== */

/**
 * Clearfix for floated images
 * Ensures content after floated images displays correctly
 */
.blog-post-content::after,
.entry-content::after,
.post-content::after {
    content: "";
    display: table;
    clear: both;
}

/**
 * Clear class for manual clearing
 */
.clear {
    clear: both;
}

/* Paragraphs following floated images */
.blog-post-content p::after,
.entry-content p::after,
.post-content p::after {
    content: "";
    display: table;
    clear: none;
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

/**
 * Tablet Breakpoint (max-width: 900px)
 * Reduce float widths on smaller screens
 */
@media (max-width: 900px) {
    .alignleft,
    .alignright,
    .wp-caption.alignleft,
    .wp-caption.alignright,
    figure.alignleft,
    figure.alignright,
    .wp-block-image.alignleft,
    .wp-block-image.alignright {
        max-width: 45%;
    }
    
    /* Gallery adjustments */
    .gallery-columns-5 .gallery-item,
    .gallery-columns-6 .gallery-item {
        flex-basis: calc(33.333% - 0.75rem);
    }
}

/**
 * Mobile Breakpoint (max-width: 600px)
 * Stack images on mobile - disable floats
 */
@media (max-width: 600px) {
    .alignleft,
    .alignright,
    .wp-caption.alignleft,
    .wp-caption.alignright,
    figure.alignleft,
    figure.alignright,
    .wp-block-image.alignleft,
    .wp-block-image.alignright {
        float: none;
        display: block;
        max-width: 100%;
        margin: 1.5rem auto;
    }
    
    /* Center captions on mobile */
    .wp-caption,
    figure {
        margin-left: auto;
        margin-right: auto;
    }
    
    /* Gallery full width on mobile */
    .gallery-item {
        flex-basis: calc(50% - 0.5rem);
    }
    
    .gallery-columns-1 .gallery-item {
        flex-basis: 100%;
    }
    
    .gallery-columns-4 .gallery-item,
    .gallery-columns-5 .gallery-item,
    .gallery-columns-6 .gallery-item {
        flex-basis: calc(50% - 0.5rem);
    }
}

/**
 * Extra Small Breakpoint (max-width: 400px)
 * Single column gallery on very small screens
 */
@media (max-width: 400px) {
    .gallery-item,
    .gallery-columns-2 .gallery-item,
    .gallery-columns-3 .gallery-item,
    .gallery-columns-4 .gallery-item,
    .gallery-columns-5 .gallery-item,
    .gallery-columns-6 .gallery-item {
        flex-basis: 100%;
    }
}

/* ==========================================================================
   WordPress Media & Text Block
   ========================================================================== */

.wp-block-media-text {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: center;
    margin: 2rem 0;
}

.wp-block-media-text.has-media-on-the-right {
    direction: rtl;
}

.wp-block-media-text.has-media-on-the-right > * {
    direction: ltr;
}

.wp-block-media-text__media img {
    width: 100%;
    height: auto;
    border-radius: 0.75rem;
}

.wp-block-media-text__content {
    padding: 0;
}

@media (max-width: 600px) {
    .wp-block-media-text {
        grid-template-columns: 1fr;
    }
    
    .wp-block-media-text.has-media-on-the-right {
        direction: ltr;
    }
    
    .wp-block-media-text__media {
        order: -1;
    }
}

/* ==========================================================================
   Image Links & Hover Effects
   ========================================================================== */

.blog-post-content a img,
.entry-content a img,
.post-content a img {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.blog-post-content a:hover img,
.entry-content a:hover img,
.post-content a:hover img {
    opacity: 0.9;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/**
 * Ensure images with links have visible focus states
 */
.blog-post-content a:focus img,
.entry-content a:focus img,
.post-content a:focus img {
    outline: 3px solid var(--primary, #00a499);
    outline-offset: 3px;
}

/**
 * High contrast mode support
 */
@media (prefers-contrast: high) {
    .wp-caption,
    figure figcaption {
        background: #f0f0f0;
        border: 1px solid #333;
    }
    
    .wp-caption-text,
    figcaption {
        color: #333;
    }
}

/**
 * Reduced motion support
 */
@media (prefers-reduced-motion: reduce) {
    .blog-post-content a img,
    .entry-content a img,
    .post-content a img {
        transition: none;
    }
}
