/* Thermal Label Fixer Styles */

#previewContainer {
    position: relative;
    background-color: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 4px;
}

#previewCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

#cropOverlay {
    position: absolute;
    border: 2px dashed #007bff;
    background: rgba(0, 123, 255, 0.1);
    pointer-events: auto;
    cursor: move;
    box-sizing: border-box;
    touch-action: none; /* Prevent default touch behaviors (scroll, zoom) */
    display: none; /* Hidden by default, shown only when file is loaded */
    z-index: 20; /* Ensure it's above canvas but below output preview */
}

#cropOverlay.dragging {
    border-color: #0056b3;
    background: rgba(0, 86, 179, 0.15);
}

.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #007bff;
    border: 2px solid white;
    border-radius: 50%;
    pointer-events: auto;
    z-index: 10;
    touch-action: none; /* Prevent default touch behaviors */
}

/* Larger touch targets on mobile */
@media (max-width: 767.98px) {
    .crop-handle {
        width: 20px;
        height: 20px;
        border-width: 3px;
    }
    
    .crop-handle-nw {
        top: -10px;
        left: -10px;
    }
    
    .crop-handle-ne {
        top: -10px;
        right: -10px;
    }
    
    .crop-handle-sw {
        bottom: -10px;
        left: -10px;
    }
    
    .crop-handle-se {
        bottom: -10px;
        right: -10px;
    }
}

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

.crop-handle-nw {
    top: -6px;
    left: -6px;
    cursor: nwse-resize;
}

.crop-handle-ne {
    top: -6px;
    right: -6px;
    cursor: nesw-resize;
}

.crop-handle-sw {
    bottom: -6px;
    left: -6px;
    cursor: nesw-resize;
}

.crop-handle-se {
    bottom: -6px;
    right: -6px;
    cursor: nwse-resize;
}

#previewPlaceholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--theme-text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    transition: opacity 0.2s ease;
    padding: 2rem;
}

#previewPlaceholder:hover {
    opacity: 0.7;
}

/* Hide placeholder when file is loaded - controlled by JS class */
#previewContainer.has-file #previewPlaceholder {
    display: none;
}

.thermal-output-preview {
    position: absolute;
    right: 12px;
    top: 12px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--theme-shadow);
    width: 260px;
    max-width: calc(100% - 24px);
    z-index: 50;
    /* Allow editing (drag/resize crop) through the overlay */
    pointer-events: none;
}

.thermal-output-preview-title {
    font-size: 12px;
    color: var(--theme-text-muted);
    margin-bottom: 6px;
    pointer-events: none;
}

.thermal-output-preview-hide {
    pointer-events: auto; /* clickable even though panel is pass-through */
}

.thermal-output-preview.thermal-output-preview-fixed {
    border-color: #198754;
    box-shadow: 0 2px 10px rgba(25,135,84,0.18);
}

#outputPreviewCanvas {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid var(--theme-border);
    /* Keep label preview white for readability/scannability */
    background: #ffffff;
    pointer-events: none; /* keep pass-through */
}

/* Loading state */
#previewContainer.loading::after {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--theme-link);
    font-weight: bold;
    z-index: 100;
}

/* Dark/True Dark: make the preview overlay panel itself dark */
html[data-theme="dark"] .thermal-output-preview,
html[data-theme="true-dark"] .thermal-output-preview,
html.theme-dark .thermal-output-preview,
html.theme-true-dark .thermal-output-preview {
    background: rgba(0, 0, 0, 0.78);
}

/* Make preview container larger on smaller displays */
@media (max-width: 991.98px) {
    #previewContainer {
        min-height: 450px !important;
        max-height: 75vh !important;
        align-items: flex-start !important; /* Start from top instead of center */
        padding-top: 15px !important;
    }
}

@media (max-width: 767.98px) {
    #previewContainer {
        min-height: 450px !important;
        max-height: 70vh !important;
        padding: 15px !important;
        align-items: flex-start !important; /* Start from top instead of center */
        padding-top: 15px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Constrain canvas width on mobile */
    #previewContainer #previewCanvas {
        max-width: 100% !important;
        width: auto !important;
        height: auto !important;
        box-sizing: border-box !important;
    }
}
