/* =========================================================================
   Core Viewer Styles
   ========================================================================= */

.viewer-container,
.viewer-container * {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.viewer-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    touch-action: none;
    background: #000;
    display: none;
    z-index: 999999;
    -webkit-font-smoothing: subpixel-antialiased;
}

.viewer-container.active {
    display: block;
    pointer-events: all;
}

.viewer-container.clipping-mode {
    cursor: crosshair !important;
}

/* =========================================================================
   Image Wrapper & Image
   ========================================================================= */

.image-wrapper {
    position: absolute;
    will-change: transform;
    cursor: grab;
    transform-origin: top left;
    backface-visibility: hidden;
    image-rendering: high-quality;
}

.image-wrapper.grabbing {
    cursor: grabbing;
    transition: none;
}

.viewer-container.clipping-mode .image-wrapper {
    pointer-events: none;
}

.viewer-image {
    display: block;
    max-width: none !important;
    -ms-interpolation-mode: nearest-neighbor;
    transform: translateZ(0);
    backface-visibility: hidden;
    outline: 1px solid transparent;
    image-rendering: high-quality;
    touch-action: none;
    -ms-touch-action: none;
    -webkit-touch-callout: none;
}

/* =========================================================================
   Controls (Slider, Nav, Close)
   ========================================================================= */

.viewer-controls {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 20px;
    display: flex;
    gap: 15px;
    z-index: 1000;
}

.zoom-slider {
    width: 200px;
    height: 6px;
    background: #555;
    border-radius: 3px;
    position: relative;
}

.zoom-slider-track {
    height: 100%;
    background: #4285f4;
    border-radius: 3px;
    width: 0%;
}

.slider-handle {
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    cursor: ew-resize;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

.slider-handle:active {
    cursor: col-resize;
    transform: translate(-50%, -50%) scale(1.1);
}

.viewer-nav {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 1000;
}

.viewer-nav-button {
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    position: relative;
    transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.viewer-nav-button:active {
    transform: scale(0.9);
}

.viewer-nav-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    padding: 5px;
}

.viewer-prev::before {
    transform: translate(-25%, -50%) rotate(135deg);
}

.viewer-next::before {
    transform: translate(-75%, -50%) rotate(-45deg);
}

.viewer-close {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    z-index: 1000;
    transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.viewer-close:active {
    transform: scale(0.9);
}

.viewer-close::before,
.viewer-close::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 2px;
    background: #fff;
    transform: translate(-50%, -50%);
}

.viewer-close::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.viewer-close::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

/* =========================================================================
   Clipping Feature Styles
   ========================================================================= */

.viewer-clip-button {
    position: fixed;
    top: 20px;
    left: 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 8px 16px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: background-color 0.2s;
}

.viewer-clip-button:hover {
    background-color: #0056b3;
}

.viewer-clip-button.active {
    background-color: #28a745;
}

.selection-rectangle {
    position: fixed;
    border: 2px dashed #ffffff;
    background-color: rgba(0, 123, 255, 0.4);
    box-sizing: border-box;
    z-index: 1000;
    pointer-events: none;
}

.resize-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background-color: white;
    border: 1px solid #333;
    border-radius: 50%;
    pointer-events: all;
    z-index: 1001;
}

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

/* Midpoint handles */
.resize-handle.n-mid { top: -8px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle.s-mid { bottom: -8px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle.e-mid { right: -8px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.resize-handle.w-mid { left: -8px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

/* Quarter-point handles */
.resize-handle.n-q1 { top: -8px; left: 25%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle.n-q3 { top: -8px; left: 75%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle.s-q1 { bottom: -8px; left: 25%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle.s-q3 { bottom: -8px; left: 75%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle.e-q1 { right: -8px; top: 25%; transform: translateY(-50%); cursor: ew-resize; }
.resize-handle.e-q3 { right: -8px; top: 75%; transform: translateY(-50%); cursor: ew-resize; }
.resize-handle.w-q1 { left: -8px; top: 25%; transform: translateY(-50%); cursor: ew-resize; }
.resize-handle.w-q3 { left: -8px; top: 75%; transform: translateY(-50%); cursor: ew-resize; }

.clip-actions {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 10px;
    border-radius: 8px;
    display: none;
    gap: 10px;
    z-index: 1001;
}

.clip-actions.visible {
    display: flex;
}

.clip-actions button {
    background-color: #4285f4;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
}

.clip-actions button:hover {
    background-color: #357ae8;
}

/* NEW: Unique styling for the cancel button */
.clip-actions #clipCancel {
    background-color: #dc3545;
}

.clip-actions #clipCancel:hover {
    background-color: #c82333;
}

/* =========================================================================
   Mobile & Loading Styles
   ========================================================================= */

@media (hover: none) and (pointer: coarse) {
    .slider-handle { width: 28px; height: 28px; }
    .viewer-nav { bottom: 60px; }
    .viewer-controls { bottom: 120px; padding: 12px 24px; }
    .viewer-nav-button,
    .viewer-close { width: 48px; height: 48px; }
    .clip-actions { bottom: 180px; }
}

.viewer-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 20px 30px;
    border-radius: 8px;
    color: white;
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 1000000;
    pointer-events: none;
}

.viewer-loading.active {
    display: flex;
}

.loading-spinner {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

.loading-text {
    font-family: Arial, sans-serif;
    font-size: 16px;
}

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

/* =========================================================================
   Clip Message Window
   ========================================================================= */

.clip-message-window {
    position: fixed;
    top: 80px; 
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    padding: 12px 40px 12px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-family: Arial, sans-serif;
    z-index: 1002;
    display: none; 
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    pointer-events: auto; 
}

.clip-message-window.visible {
    display: block;
    animation: fadeIn 0.3s ease;
}

.clip-message-dismiss {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.clip-message-dismiss:hover {
    opacity: 1;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, -10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}