/* 
   Image Cropper Styles
   قص الصور مع قناع التعتيم
*/

/* =====================================
   Cropper Modal
   ===================================== */
.cropper-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: var(--spacing-md);
}

.cropper-modal.active {
    display: flex;
    animation: cropperFadeIn 0.3s ease;
}

@keyframes cropperFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.cropper-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: cropperSlideIn 0.3s ease;
}

@keyframes cropperSlideIn {
    from { 
        transform: translateY(-30px) scale(0.95);
        opacity: 0;
    }
    to { 
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* =====================================
   Cropper Header
   ===================================== */
.cropper-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.cropper-header h3 {
    color: var(--gold-primary);
    font-size: 1.1rem;
    margin: 0;
}

.cropper-close {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cropper-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* =====================================
   Cropper Body - Image Area
   ===================================== */
.cropper-body {
    flex: 1;
    padding: var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 300px;
    max-height: 60vh;
}

.cropper-image-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cropper-image-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: 100%;
}

.cropper-image {
    display: block;
    max-width: 100%;
    max-height: 55vh;
    width: auto;
    height: auto;
    user-select: none;
    -webkit-user-drag: none;
}

/* =====================================
   Dimmed Overlay (Mask Effect)
   ===================================== */
.cropper-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* The dimming is created using box-shadow on crop-box */

/* =====================================
   Crop Box
   ===================================== */
.cropper-crop-box {
    position: absolute;
    border: 2px solid var(--gold-primary);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
    cursor: move;
    touch-action: none;
    z-index: 10;
}

/* Grid lines inside crop box */
.cropper-crop-box::before,
.cropper-crop-box::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.3);
}

/* Horizontal lines */
.cropper-crop-box::before {
    top: 33.33%;
    left: 0;
    right: 0;
    height: 1px;
    box-shadow: 0 calc(33.33% * 2 - 33.33%) 0 0 rgba(255, 255, 255, 0.3);
}

/* Vertical lines */
.cropper-crop-box::after {
    left: 33.33%;
    top: 0;
    bottom: 0;
    width: 1px;
    box-shadow: calc(33.33% * 2 - 33.33%) 0 0 0 rgba(255, 255, 255, 0.3);
}

/* Grid overlay for rule of thirds */
.cropper-grid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.cropper-grid-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.2);
}

.cropper-grid-line.horizontal {
    left: 0;
    right: 0;
    height: 1px;
}

.cropper-grid-line.horizontal:nth-child(1) { top: 33.33%; }
.cropper-grid-line.horizontal:nth-child(2) { top: 66.66%; }

.cropper-grid-line.vertical {
    top: 0;
    bottom: 0;
    width: 1px;
}

.cropper-grid-line.vertical:nth-child(3) { left: 33.33%; }
.cropper-grid-line.vertical:nth-child(4) { left: 66.66%; }

/* =====================================
   Resize Handles
   ===================================== */
.cropper-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    background: var(--gold-primary);
    border: 2px solid white;
    border-radius: 50%;
    z-index: 20;
    touch-action: none;
}

/* Corner handles */
.cropper-handle.nw { top: -10px; left: -10px; cursor: nw-resize; }
.cropper-handle.ne { top: -10px; right: -10px; cursor: ne-resize; }
.cropper-handle.sw { bottom: -10px; left: -10px; cursor: sw-resize; }
.cropper-handle.se { bottom: -10px; right: -10px; cursor: se-resize; }

/* Edge handles */
.cropper-handle.n { top: -10px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.cropper-handle.s { bottom: -10px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.cropper-handle.w { left: -10px; top: 50%; transform: translateY(-50%); cursor: w-resize; }
.cropper-handle.e { right: -10px; top: 50%; transform: translateY(-50%); cursor: e-resize; }

/* Hide edge handles on fixed aspect ratio */
.cropper-crop-box.fixed-ratio .cropper-handle.n,
.cropper-crop-box.fixed-ratio .cropper-handle.s,
.cropper-crop-box.fixed-ratio .cropper-handle.w,
.cropper-crop-box.fixed-ratio .cropper-handle.e {
    display: none;
}

/* =====================================
   Cropper Footer
   ===================================== */
.cropper-footer {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.cropper-footer .btn-cancel,
.cropper-footer .btn-save {
    flex: 1;
    padding: var(--spacing-sm);
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cropper-footer .btn-cancel {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-secondary);
}

.cropper-footer .btn-cancel:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

.cropper-footer .btn-save {
    background: var(--gold-primary);
    border: none;
    color: var(--bg-primary);
    font-weight: 600;
}

.cropper-footer .btn-save:hover {
    background: var(--gold-light);
}

/* =====================================
   Aspect Ratio Info Badge
   ===================================== */
.cropper-ratio-badge {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gold-primary);
    color: var(--bg-primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    z-index: 30;
}

/* =====================================
   Loading State
   ===================================== */
.cropper-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1rem;
}

.cropper-loading::after {
    content: '';
    width: 24px;
    height: 24px;
    margin-right: 10px;
    border: 3px solid var(--gold-primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: cropperSpin 0.8s linear infinite;
}

@keyframes cropperSpin {
    to { transform: rotate(360deg); }
}

/* =====================================
   Responsive Design
   ===================================== */
@media (max-width: 768px) {
    .cropper-modal {
        padding: var(--spacing-sm);
    }
    
    .cropper-container {
        max-height: 95vh;
        border-radius: var(--radius-md);
    }
    
    .cropper-body {
        min-height: 250px;
        max-height: 50vh;
        padding: var(--spacing-sm);
    }
    
    .cropper-image {
        max-height: 45vh;
    }
    
    .cropper-handle {
        width: 28px;
        height: 28px;
    }
    
    .cropper-handle.nw { top: -14px; left: -14px; }
    .cropper-handle.ne { top: -14px; right: -14px; }
    .cropper-handle.sw { bottom: -14px; left: -14px; }
    .cropper-handle.se { bottom: -14px; right: -14px; }
    
    .cropper-handle.n { top: -14px; }
    .cropper-handle.s { bottom: -14px; }
    .cropper-handle.w { left: -14px; }
    .cropper-handle.e { right: -14px; }
    
    .cropper-footer {
        padding: var(--spacing-sm);
    }
}

/* Touch feedback */
@media (hover: none) and (pointer: coarse) {
    .cropper-crop-box {
        border-width: 3px;
    }
    
    .cropper-handle {
        width: 32px;
        height: 32px;
    }
}
