/**
 * Clean Crop Modal CSS - Single Implementation
 * Replaces all duplicate and conflicting crop modal styles
 */

/* ==========================================================================
   CROP MODAL - CLEAN IMPLEMENTATION
   ========================================================================== */

.photo-uploader-crop-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.85) !important;
    z-index: 10001 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.photo-uploader-crop-modal.active {
    opacity: 1 !important;
    visibility: visible !important;
    display: flex !important;
}

.crop-modal-content {
    background: white !important;
    border-radius: 12px !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
    /* Responsive sizing */
    width: min(95vw, 900px) !important;
    max-height: 95vh !important;
    /* Flexible layout */
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    /* Ensure minimum usable size */
    min-width: 320px !important;
    min-height: 400px !important;
}

.crop-modal-header {
    background: linear-gradient(135deg, #007cba 0%, #00a0d2 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.crop-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.crop-modal-header .modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 20px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.crop-modal-header .modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.crop-modal-body {
    /* Responsive padding */
    padding: clamp(12px, 3vw, 20px);
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 2vw, 16px);
    flex: 1;
    overflow: hidden;
    /* Ensure proper minimum space */
    min-height: 0;
}

.crop-instructions {
    text-align: center;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #007cba;
    font-size: 14px;
    color: #666;
}

.crop-canvas-container {
    position: relative;
    background: #f0f0f0;
    border-radius: 8px;
    border: 2px solid #ddd;
    overflow: hidden;
    height: clamp(300px, 60vh, 70vh);
    width: 100%;
    max-width: min(90vw, 800px);
    min-height: 300px;
    min-width: 300px;
    /* Critical: Ensure all child elements are clipped to container */
    contain: layout style paint;
    /* Improve drag responsiveness on touch/trackpads */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.crop-canvas {
    display: block;
    border-radius: 4px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
}

.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 2;
    /* Ensure overlay elements are clipped to container bounds */
    overflow: hidden;
    clip-path: inset(0);
}

.crop-selection {
    position: absolute;
    border: 2px dashed #dc3232;
    background: none !important;
    cursor: move;
    pointer-events: all;
    min-width: 50px;
    min-height: 50px;
    z-index: 3;
    box-sizing: border-box; /* ensure dashed border sits inside width/height */
    /* Ensure absolutely no visual effects inside */
    box-shadow: none !important;
    backdrop-filter: none !important;
    filter: none !important;
    /* Critical: Prevent extending beyond container bounds */
    max-width: 100%;
    max-height: 100%;
    contain: layout style;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Override any hover/active states that add backgrounds */
.crop-selection:hover,
.crop-selection:active,
.crop-selection:focus {
    background: none !important;
    backdrop-filter: none !important;
    filter: none !important;
    box-shadow: none !important;
    border-color: #dc3232 !important;
}

/* Ensure no transitions cause visual artifacts during dragging */
.crop-selection,
.crop-selection::before,
.crop-selection::after {
    transition: none !important;
    animation: none !important;
}

/* Also ensure safe zone has no hover effects */
.crop-bleeding-area:hover,
.crop-bleeding-area:active,
.crop-bleeding-area:focus {
    background: none !important;
    backdrop-filter: none !important;
    filter: none !important;
    box-shadow: none !important;
}

.crop-selection::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 1px dashed rgba(220, 50, 50, 0.8);
    pointer-events: none;
    background: none !important;
}

.crop-bleeding-area {
    position: absolute;
    border: 2px solid #007cba;
    background: none !important;
    pointer-events: none;
    z-index: 4;
    box-sizing: border-box; /* ensure border does not overflow */
    /* Ensure absolutely no visual effects inside safe zone */
    box-shadow: none !important;
    backdrop-filter: none !important;
    filter: none !important;
    /* Critical: Prevent extending beyond container bounds */
    max-width: 100%;
    max-height: 100%;
    contain: layout style;
}

/* Dark overlay elements - will be positioned by JavaScript */
.crop-overlay-top,
.crop-overlay-bottom,
.crop-overlay-left,
.crop-overlay-right {
    position: absolute;
    background: rgba(0, 0, 0, 0.6);
    pointer-events: none;
    z-index: 2;
}

/* Keep crop selection area completely clear - no overlays inside */

.crop-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: white;
    border: 2px solid #dc3232;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    box-sizing: border-box; /* keep handles centered irrespective of border */
    pointer-events: auto; /* ensure handles capture interactions */
    touch-action: none; /* prevent page scrolling during drag */
}

.crop-handle:hover {
    background: #dc3232;
    transform: scale(1.2);
}

/* Handle positioning */
.crop-handle-nw {
    top: 0;
    left: 0;
    cursor: nw-resize;
}

.crop-handle-ne {
    top: 0;
    right: 0;
    cursor: ne-resize;
}

.crop-handle-sw {
    bottom: 0;
    left: 0;
    cursor: sw-resize;
}

.crop-handle-se {
    bottom: 0;
    right: 0;
    cursor: se-resize;
}

.crop-handle-n {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    cursor: n-resize;
}

.crop-handle-s {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    cursor: s-resize;
}

.crop-handle-e {
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    cursor: e-resize;
}

.crop-handle-w {
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    cursor: w-resize;
}

.crop-info {
    text-align: center;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 14px;
    color: #666;
    border: 1px solid #ddd;
}

.crop-modal-footer {
    padding: 20px;
    background: #f8f9fa;
    border-top: 1px solid #ddd;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.crop-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
}

.crop-btn-secondary {
    background: #6c757d;
    color: white;
}

.crop-btn-secondary:hover {
    background: #545b62;
}

.crop-btn-primary {
    background: linear-gradient(135deg, #007cba 0%, #00a0d2 100%);
    color: white;
}

.crop-btn-primary:hover {
    background: linear-gradient(135deg, #005a87 0%, #007cba 100%);
    transform: translateY(-1px);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .crop-modal-content {
        width: 98vw !important;
        max-height: 98vh !important;
        min-width: 300px !important;
    }

    .crop-canvas-container {
        /* Adjust for smaller screens */
        height: clamp(250px, 50vh, 60vh);
        aspect-ratio: 3/2;
        min-height: 250px;
        min-width: 250px;
    }

    .crop-modal-header,
    .crop-modal-body,
    .crop-modal-footer {
        padding: 12px;
    }

    .crop-handle {
        width: 16px;
        height: 16px;
    }

    .crop-modal-footer {
        flex-direction: column;
        gap: 8px;
    }

    .crop-btn {
        width: 100%;
        padding: 14px 20px;
    }
}

@media (max-width: 480px) {
    .crop-modal-content {
        width: 100vw !important;
        height: 100vh !important;
        max-width: none !important;
        max-height: none !important;
        border-radius: 0 !important;
        min-width: 320px !important;
    }

    .crop-canvas-container {
        height: clamp(200px, 40vh, 50vh);
        aspect-ratio: 1/1;
        min-height: 200px;
        min-width: 200px;
    }

    .crop-handle {
        width: 20px;
        height: 20px;
    }

    .crop-modal-header h3 {
        font-size: 16px;
    }

    .crop-instructions {
        font-size: 12px;
        padding: 8px;
    }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
    .crop-handle {
        width: 28px;
        height: 28px;
    }

    .crop-selection {
        border-width: 3px;
    }
}