/**
 * Photo Uploader Component Styles
 * Uses BEM naming convention for component isolation
 * All selectors prefixed with photo- to prevent collisions
 */

/* Core component classes */
.photo-uploader-modal {
    z-index: 30000 !important; 
    background-color: rgba(0, 0, 0, 0.5) !important;
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.photo-uploader-modal__dialog {
    z-index: 30100 !important;
    margin: 1.75rem auto;
    max-width: 800px;
}

.photo-uploader-modal__content {
    z-index: 30200 !important;
    border-radius: 0.3rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.5) !important;
    position: relative;
}

.photo-uploader-modal__header {
    border-bottom: 1px solid #dee2e6;
    padding: 1rem;
}

.photo-uploader-modal__body {
    padding: 1rem;
}

.photo-uploader-modal__footer {
    border-top: 1px solid #dee2e6;
    padding: 1rem;
}

/* Backdrop specific to photo uploader */
.photo-uploader-backdrop {
    z-index: 29000 !important;
    opacity: 0.5 !important;
}

/* Image container for cropper */
.photo-uploader__img-container {
    max-height: 400px;
    margin-bottom: 1rem;
}

/* Fixed cropper container */
.image-cropper-container {
    position: relative;
    margin: 0 auto;
    width: 250px;
    height: 250px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    overflow: hidden;
}

/* Mobile version */
@media (max-width: 576px) {
    .image-cropper-container {
        width: 180px;
        height: 180px;
    }
}

/* Cropper Image */
#cropperImage {
    display: block;
    max-width: 100%;
    max-height: 400px;
    width: auto;
    height: auto;
}

/* Cropper wrapper container */
#cropperWrapper {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    min-height: 300px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

/* Ensure crop area is visible */
#cropArea {
    display: block !important;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

/* Force cropper container to be visible and properly sized */
.cropper-container {
    width: 100% !important;
    height: 300px !important;
    max-width: 400px !important;
    margin: 0 auto !important;
    display: block !important;
    position: relative !important;
    overflow: hidden !important;
}

/* Base cropper elements */
.cropper-container {
    font-size: 0;
    line-height: 0;
    position: relative;
    user-select: none;
    direction: ltr;
    touch-action: none;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    z-index: 1;
}

/* Ensure cropper elements are visible */
.cropper-wrap-box {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
}

.cropper-canvas {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
}

.cropper-drag-box {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: #fff;
    opacity: 0;
}

.cropper-modal {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: #000;
    opacity: 0.5;
}

.cropper-canvas, 
.cropper-drag-box, 
.cropper-crop-box, 
.cropper-modal {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

/* Limit crop box inside the container */
.cropper-crop-box {
    max-width: 100%;
    max-height: 100%;
    border: 2px solid #39f;
    opacity: 1;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
}

.cropper-view-box {
    display: block;
    height: 100%;
    outline: 2px solid #39f;
    outline-color: rgba(51, 153, 255, 0.75);
    overflow: hidden;
    width: 100%;
}

.cropper-crop-box.circle {
    border-radius: 50%;
}

/* Make crop box handles visible and interactive */
.cropper-point {
    width: 8px;
    height: 8px;
    background-color: #39f;
    opacity: 0.75;
    position: absolute;
}

.cropper-point.point-e {
    top: 50%;
    right: -4px;
    margin-top: -4px;
    cursor: e-resize;
}

.cropper-point.point-n {
    top: -4px;
    left: 50%;
    margin-left: -4px;
    cursor: n-resize;
}

.cropper-point.point-w {
    top: 50%;
    left: -4px;
    margin-top: -4px;
    cursor: w-resize;
}

.cropper-point.point-s {
    bottom: -4px;
    left: 50%;
    margin-left: -4px;
    cursor: s-resize;
}

.cropper-point.point-ne {
    top: -4px;
    right: -4px;
    cursor: ne-resize;
}

.cropper-point.point-nw {
    top: -4px;
    left: -4px;
    cursor: nw-resize;
}

.cropper-point.point-sw {
    bottom: -4px;
    left: -4px;
    cursor: sw-resize;
}

.cropper-point.point-se {
    bottom: -4px;
    right: -4px;
    cursor: se-resize;
}

/* Circle mode styles */
.photo-uploader__circle .cropper-view-box,
.photo-uploader__circle .cropper-face {
    border-radius: 50%;
    overflow: hidden;
}

/* Circular overlay mask for preview */
.circle-mask-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: radial-gradient(
        circle at center,
        transparent 49.5%,
        rgba(0, 0, 0, 0.5) 50%
    );
    z-index: 20;
    display: none;
}

.photo-uploader__circle .circle-mask-overlay {
    display: block;
}

/* Control buttons area */
.cropper-controls {
    margin-top: 15px;
}

/* Button styling */
.btn-group {
    display: inline-flex;
}

.btn-outline-primary {
    color: #0d6efd;
    border-color: #0d6efd;
}

.btn-outline-primary.active {
    color: #fff;
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.btn-outline-secondary {
    color: #6c757d;
    border-color: #6c757d;
}

/* Loading spinner */
.spinner-border {
    display: inline-block;
    width: 2rem;
    height: 2rem;
    vertical-align: text-bottom;
    border: 0.25em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border .75s linear infinite;
}

@keyframes spinner-border {
    to { transform: rotate(360deg); }
}

/* Circle photo display for results */
img[src*="_circle"] {
    border-radius: 50%;
}

.photo-upload-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

.current-photo {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.upload-container {
    background-color: var(--bs-body-bg);
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    padding: 30px;
    margin-bottom: 30px;
}

.upload-step h5 {
    color: var(--bs-body-color);
    font-weight: 600;
    margin-bottom: 1rem;
}

.upload-step p.text-muted {
    color: var(--bs-secondary-color) !important;
}

/* Fixed container to enforce size */
.cropper-container-fixed {
    max-width: 100%;
    max-height: 350px;
    min-width: 300px;
    min-height: 300px;
    width: auto;
    height: auto;
    margin: 0 auto;
    background: #f8f9fa;
    border: 1px solid #ddd;
    overflow: hidden;
    position: relative;
    display: inline-block;
}

/* Cropper wrapper */
.cropper-wrapper {
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    max-height: 100%;
    position: relative;
}

/* Force image to be visible */
.image-preview {
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    max-height: 100%;
    display: block;
}

/* Override cropper containers */
.cropper-container {
    max-width: 100% !important;
    max-height: 100% !important;
}

/* Ensure cropper elements are visible */
.cropper-view-box,
.cropper-face,
.cropper-line,
.cropper-point {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Preview container */
.preview-container {
    padding: 10px;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    background-color: #f8f9fa;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.preview {
    overflow: hidden;
    background-color: white;
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
}

.preview.square {
    border-radius: 5px;
}

.preview.circle {
    border-radius: 50%;
}

/* Controls area */
.controls-container {
    margin: 15px auto;
    text-align: center;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .cropper-container-fixed {
        width: 280px;
        height: 280px;
    }
}

.action-buttons {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
    gap: 15px;
}

/* Critical cropper styles */
.cropper-view-box,
.cropper-face {
    cursor: move !important;
}

.circle-aspect {
    border-radius: 50% !important;
    overflow: hidden !important;
}

/* Essential cropper element visibility fixes */
.cropper-container,
.cropper-wrap-box,
.cropper-canvas,
.cropper-drag-box,
.cropper-crop-box,
.cropper-modal {
    position: absolute !important;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    top: 0;
    left: 0;
}

.cropper-drag-box {
    background: none !important;
    opacity: 0 !important;
}

.cropper-view-box,
.cropper-face {
    opacity: 1 !important;
    cursor: move !important;
    pointer-events: auto !important;
}

.cropper-point {
    opacity: 0.75 !important;
    pointer-events: auto !important;
}

.cropper-line {
    opacity: 0.65 !important;
    pointer-events: auto !important;
}

.file-error {
    color: var(--bs-danger);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: none;
}

/* Responsive improvements */
@media (max-width: 768px) {
    .cropper-wrapper {
        width: 180px;
        height: 180px;
        max-width: 90vw;
        max-height: 90vw;
        aspect-ratio: 1/1;
    }
    .cropper-container {
        width: 100% !important;
        height: 100% !important;
    }
    .cropper-view-box,
    .cropper-face {
        border-radius: 0 !important;
    }
    .controls-container {
        flex-direction: column;
        align-items: center;
    }
    .shape-controls,
    .zoom-controls,
    .rotation-controls {
        justify-content: center;
        width: 100%;
    }
    .action-buttons {
        flex-direction: column;
    }
    .action-buttons .btn {
        width: 100%;
    }
}

.cropper-wrapper .circle-mask {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}
.cropper-wrapper.circle-aspect .circle-mask {
    display: block;
    background: radial-gradient(circle at 50% 50%, rgba(0,0,0,0) 60%, rgba(0,0,0,0.10) 62%, rgba(0,0,0,0.10) 100%);
    border-radius: 50%;
}

/* Hide file input for custom styling */
#photoInput {
    display: none;
}

/* Preview canvas sizing */
.preview canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Force crop box to be small and visible */
.cropper-crop-box {
    background: transparent !important;
    border: 2px solid #39f !important;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4) !important; /* Dark overlay outside crop box */
    pointer-events: auto !important;
}

/* Make handles visible for moving only */
.cropper-point {
    visibility: hidden !important;
    pointer-events: none !important;
}
.cropper-point.point-nw,
.cropper-point.point-ne,
.cropper-point.point-sw,
.cropper-point.point-se {
    visibility: hidden !important;
    pointer-events: none !important;
}
.cropper-view-box {
    outline: none !important;
    background: transparent !important;
}
.cropper-face {
    background: transparent !important;
    opacity: 1 !important;
}

/* Croppie container */
.croppie-container {
    width: 300px;
    height: 300px;
    margin: 0 auto;
}

.cr-slider-wrap {
    margin-top: 15px;
}

.preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.shape-controls {
    margin-bottom: 15px;
}

.zoom-controls {
    max-width: 300px;
    margin: 0 auto;
}

/* Ensure modal buttons are above everything else */
#updatePhotoModal .modal-footer {
    display: flex !important;
    justify-content: space-between !important;
    padding: 1rem !important;
    border-top: 1px solid #dee2e6 !important;
    position: relative !important;
    z-index: 99999 !important;
    background-color: white !important;
}

#updatePhotoModal #cropBtn, 
#updatePhotoModal #backBtn,
#updatePhotoModal #cancelBtn {
    position: relative !important;
    z-index: 999999 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    font-weight: 500 !important;
    min-width: 100px !important;
}

#updatePhotoModal #cropBtn {
    background-color: #0d6efd !important;
    border-color: #0d6efd !important;
    color: white !important;
}

#updatePhotoModal #cropBtn:hover {
    background-color: #0b5ed7 !important;
    border-color: #0a58ca !important;
}

/* Force elements inside the modal to have correct z-index */
#updatePhotoModal .modal-content {
    position: relative !important;
    z-index: 1056 !important;
}

#updatePhotoModal .modal-header,
#updatePhotoModal .modal-body {
    position: relative !important;
    z-index: 1057 !important;
}

/* Make sure cropper elements don't overlap buttons */
.cropper-container,
.cropper-canvas,
.cropper-drag-box,
.cropper-crop-box,
.cropper-modal {
    z-index: 1056 !important;
}

/* Enhanced circular mask for clearer visualization */
.circle-mask-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: radial-gradient(
        circle at center,
        transparent 49.5%,
        rgba(0, 0, 0, 0.5) 50%
    );
    z-index: 1056;
    display: none;
}

.photo-uploader__circle .circle-mask-overlay {
    display: block;
}

/* Fix for buttons to ensure they're visible and clickable */
#updatePhotoModal button {
    position: relative !important;
    z-index: 1057 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* Remove any other elements that might be overlaying the buttons */
.cropper-container *,
.cropper-container ::before,
.cropper-container ::after {
    z-index: 1056 !important;
}

/* Fix for modal backdrop to not interfere with buttons */
.modal-backdrop {
    z-index: 1050 !important;
}

/* Highest level buttons */
#updatePhotoModal .modal-footer button {
    z-index: 1057 !important;
} 