/* Enhanced Image Sizing Support for Blog Content */

/* Blog post content area - respect stored image dimensions */
.blog-content img,
.ql-editor img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1rem auto;
    border: 2px solid #000;
    box-shadow: 4px 4px 0 #000;
    transition: all 0.2s ease;
    /* Ensure GIF animations work */
    image-rendering: auto;
    animation-play-state: running;
}

/* Specific rules for GIF files to ensure animation */
.blog-content img[src*=".gif"],
.ql-editor img[src*=".gif"] {
    image-rendering: auto !important;
    animation-play-state: running !important;
    /* Prevent any CSS that might stop animation */
    will-change: auto;
    backface-visibility: visible;
}

/* PNG transparency support */
.blog-content img[src*=".png"],
.ql-editor img[src*=".png"] {
    background: transparent !important;
    /* Remove any background that might show behind PNG */
}

/* Responsive image sizing - preserve aspect ratio */
.blog-content img[width],
.ql-editor img[width] {
    width: attr(width px) !important;
    max-width: 100%;
}

.blog-content img[height],
.ql-editor img[height] {
    height: attr(height px) !important;
    max-height: none;
}

/* Image hover effects */
.blog-content img:hover,
.ql-editor img:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 #000;
    cursor: pointer;
}

/* PNG specific hover effects - maintain transparency */
.blog-content img[src*=".png"]:hover,
.ql-editor img[src*=".png"]:hover {
    background: transparent !important;
}

/* Optional: PNG images without borders (add 'no-border' class) */
.blog-content img.no-border,
.ql-editor img.no-border,
.blog-content img[src*=".png"].transparent,
.ql-editor img[src*=".png"].transparent {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

.blog-content img.no-border:hover,
.ql-editor img.no-border:hover,
.blog-content img[src*=".png"].transparent:hover,
.ql-editor img[src*=".png"].transparent:hover {
    transform: translate(-2px, -2px);
    box-shadow: 2px 2px 8px rgba(0,0,0,0.1) !important;
    border: none !important;
    background: transparent !important;
}

/* Size presets for editor */
.image-size-25 { width: 25% !important; }
.image-size-50 { width: 50% !important; }
.image-size-75 { width: 75% !important; }
.image-size-100 { width: 100% !important; }

/* Responsive breakpoints for image sizing */
@media (max-width: 768px) {
    .blog-content img,
    .ql-editor img {
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
    }
}

/* Image alignment options */
.image-align-left {
    float: left;
    margin: 0 1rem 1rem 0;
}

.image-align-right {
    float: right;
    margin: 0 0 1rem 1rem;
}

.image-align-center {
    display: block;
    margin: 1rem auto;
    float: none;
}

/* Clear floats after images */
.blog-content::after,
.ql-editor::after {
    content: "";
    display: table;
    clear: both;
}

/* Image caption support */
.image-caption {
    font-size: 0.875rem;
    color: #666;
    text-align: center;
    margin-top: 0.5rem;
    font-style: italic;
}

/* Enhanced resize controls for editor */
.image-resize-controls {
    position: absolute;
    z-index: 1000;
    background: white;
    border: 2px solid #000;
    box-shadow: 4px 4px 0 #000;
    padding: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

.image-resize-controls input {
    width: 60px;
    padding: 2px 4px;
    border: 1px solid #000;
    margin: 0 2px;
    font-family: 'JetBrains Mono', monospace;
}

.image-resize-controls button {
    padding: 2px 6px;
    border: 1px solid #000;
    background: white;
    cursor: pointer;
    margin: 0 1px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
}

.image-resize-controls button:hover {
    background: #000;
    color: white;
}

/* Preserve image dimensions in saved content */
.blog-content img[data-width],
.blog-content img[data-height] {
    width: attr(data-width px);
    height: attr(data-height px);
}

/* Loading placeholder for images */
.image-loading {
    background: #f0f0f0;
    border: 2px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    font-family: 'JetBrains Mono', monospace;
    color: #666;
}

.image-loading::before {
    content: "📷 Loading image...";
}

/* Enhanced Image Selection and Resize Styles */

/* Image selection styles */
.ql-editor img.image-selected {
    outline: 2px solid #3b82f6 !important;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1), 4px 4px 0 #000 !important;
}

/* Resize container */
.resize-container {
    position: absolute;
    border: 2px solid #3b82f6;
    background: transparent;
    pointer-events: none;
    z-index: 1000;
}

/* Resize handles */
.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #3b82f6;
    border: 2px solid white;
    border-radius: 2px;
    pointer-events: all;
    z-index: 1001;
    transition: all 0.1s ease;
}

.resize-handle:hover {
    background: #2563eb;
    transform: scale(1.2);
}

/* Corner handles (larger for easier grabbing) */
.resize-nw, .resize-ne, .resize-sw, .resize-se {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

/* Edge handles */
.resize-n, .resize-s {
    width: 20px;
    height: 8px;
    border-radius: 4px;
}

.resize-e, .resize-w {
    width: 8px;
    height: 20px;
    border-radius: 4px;
}

/* Resize cursor styles */
.resize-nw { cursor: nw-resize; }
.resize-ne { cursor: ne-resize; }
.resize-sw { cursor: sw-resize; }
.resize-se { cursor: se-resize; }
.resize-n { cursor: n-resize; }
.resize-e { cursor: e-resize; }
.resize-s { cursor: s-resize; }
.resize-w { cursor: w-resize; }

/* Image hover effects for resizable images */
.ql-editor img[data-resizable="true"]:hover {
    cursor: pointer;
    opacity: 0.9;
}

/* Selection feedback */
.ql-editor img[data-resizable="true"]:active {
    transform: scale(0.98);
}

/* Mobile responsive handles */
@media (max-width: 768px) {
    .resize-handle {
        width: 14px;
        height: 14px;
    }
    
    .resize-nw, .resize-ne, .resize-sw, .resize-se {
        width: 16px;
        height: 16px;
    }
    
    .resize-n, .resize-s {
        width: 24px;
        height: 10px;
    }
    
    .resize-e, .resize-w {
        width: 10px;
        height: 24px;
    }
}

/* Class-based file type handling for JavaScript insertion */
.blog-content img.transparent,
.ql-editor img.transparent {
    background: transparent !important;
    /* Ensure PNG transparency works */
    background-color: transparent !important;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.3) !important;
}

.blog-content img.animated-gif,
.ql-editor img.animated-gif {
    image-rendering: auto !important;
    animation-play-state: running !important;
    /* Force GIF animation to play */
    will-change: auto;
    backface-visibility: visible;
    /* Prevent compression that might stop animation */
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Combined class support */
.blog-content img.transparent.animated-gif,
.ql-editor img.transparent.animated-gif {
    background: transparent !important;
    image-rendering: auto !important;
    animation-play-state: running !important;
}
