/**
 * scanner.css
 * Styles for Document Scanner upload zone, interactive crop editor, handles, loupe, filters, and export.
 */

/* Scanner Container */
.scanner-container {
    max-width: 1000px;
    margin: 0 auto;
}

/* Upload Card */
.upload-card {
    background: var(--bg-card);
    border: 2px dashed var(--border-hover);
    border-radius: var(--radius-lg);
    padding: 3.5rem 1.5rem;
    text-align: center;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    position: relative;
    cursor: default;
}

.upload-card.dragover {
    border-color: var(--primary);
    background-color: var(--primary-light);
    transform: scale(1.01);
}

.upload-icon-circle {
    width: 72px;
    height: 72px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    font-size: 2rem;
    box-shadow: 0 0 0 8px rgba(37, 99, 235, 0.08);
}

.upload-heading {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.upload-subtext {
    font-size: 1rem;
    color: var(--text-muted);
    max-width: 500px;
    margin: 0 auto 1.75rem;
}

.upload-actions-group {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

/* Primary and Secondary Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background-color: var(--primary);
    color: #ffffff;
    font-weight: 600;
    font-size: 1rem;
    padding: 0.8rem 1.6rem;
    border-radius: var(--radius-md);
    box-shadow: 0 2px 4px 0 rgba(37, 99, 235, 0.25);
    transition: var(--transition);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px 0 rgba(37, 99, 235, 0.35);
    color: #ffffff;
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background-color: var(--bg-card);
    color: var(--text-main);
    font-weight: 600;
    font-size: 1rem;
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.btn-secondary:hover {
    border-color: var(--border-hover);
    background-color: var(--bg-subtle);
    color: var(--text-main);
}

.btn-sm {
    padding: 0.45rem 0.9rem;
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
}

.btn-danger {
    color: var(--danger);
    border-color: #fecaca;
    background-color: #fff;
}

.btn-danger:hover {
    background-color: #fef2f2;
    border-color: #f87171;
}

/* Upload Metadata & Privacy Badge */
.upload-meta {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 1.25rem;
}

.privacy-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 500;
}

/* Scanner Editor Card */
.editor-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Editor Header */
.editor-header {
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-navigator {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.page-indicator {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-main);
    min-width: 110px;
    text-align: center;
}

.editor-header-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

/* Toolbar Control Bar */
.editor-toolbar {
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.toolbar-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 0.25rem;
}

/* Filter Buttons Segmented Group */
.filter-btn-group {
    display: inline-flex;
    background: #e2e8f0;
    border-radius: var(--radius-md);
    padding: 2px;
}

.btn-filter {
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: calc(var(--radius-md) - 2px);
    color: var(--text-muted);
    transition: var(--transition);
}

.btn-filter.active {
    background: #ffffff;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.btn-filter:hover:not(.active) {
    color: var(--text-main);
}

/* Sliders */
.slider-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 500;
}

.slider-group input[type="range"] {
    width: 85px;
    accent-color: var(--primary);
    cursor: pointer;
}

.slider-val-badge {
    font-family: monospace;
    font-size: 0.8rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.1rem 0.35rem;
    min-width: 30px;
    text-align: center;
}

/* Canvas Viewport */
.canvas-viewport {
    position: relative;
    background: #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    max-height: 65vh;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.canvas-viewport canvas {
    display: block;
    max-width: 100%;
    max-height: 65vh;
    object-fit: contain;
    margin: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* SVG Crop Overlay */
.crop-overlay-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.crop-polygon {
    fill: rgba(37, 99, 235, 0.18);
    stroke: #2563eb;
    stroke-width: 2.5;
    stroke-dasharray: 6 3;
    animation: dashAnimation 30s linear infinite;
}

@keyframes dashAnimation {
    to {
        stroke-dashoffset: 1000;
    }
}

.corner-handle {
    fill: #ffffff;
    stroke: #2563eb;
    stroke-width: 4;
    cursor: move;
    pointer-events: all;
    transition: r 0.15s ease, stroke-color 0.15s ease;
}

.corner-handle:hover {
    r: 16;
    stroke: #1d4ed8;
    fill: #eff6ff;
}

/* 4 Sliding Edge Handles (Mobile Style Crop) */
.edge-handle {
    fill: #ffffff;
    stroke: #2563eb;
    stroke-width: 3;
    pointer-events: all;
    transition: transform 0.15s ease, fill 0.15s ease;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.edge-h {
    cursor: ns-resize;
}

.edge-v {
    cursor: ew-resize;
}

.edge-handle:hover {
    fill: #eff6ff;
    stroke: #1d4ed8;
    transform: scale(1.18);
}

/* Rule-of-Thirds Grid Lines */
.crop-grid-line {
    stroke: rgba(255, 255, 255, 0.55);
    stroke-width: 1.2;
    stroke-dasharray: 4 3;
    pointer-events: none;
}

.crop-polygon.box-mode {
    cursor: move;
    pointer-events: all;
}

/* Crop Style Segmented Buttons */
.crop-type-group {
    display: inline-flex;
    background: #e2e8f0;
    border-radius: var(--radius-md);
    padding: 2px;
}

.btn-crop-type {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: calc(var(--radius-md) - 2px);
    color: var(--text-muted);
    transition: var(--transition);
}

.btn-crop-type.active {
    background: #ffffff;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Loupe Magnifier */
.corner-loupe {
    position: fixed;
    width: 120px;
    height: 120px;
    border-radius: var(--radius-full);
    border: 3px solid #ffffff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    background: #000;
    overflow: hidden;
    pointer-events: none;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.corner-loupe canvas {
    width: 100%;
    height: 100%;
}

/* Multi-Page Thumbnails Strip */
.editor-thumbnails-tray {
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    padding: 0.85rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    overflow-x: auto;
}

.pages-thumbs-list {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-grow: 1;
}

.page-thumb-item {
    position: relative;
    width: 72px;
    height: 96px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border-color);
    background: var(--bg-subtle);
    overflow: hidden;
    cursor: pointer;
    flex-shrink: 0;
    transition: var(--transition);
}

.page-thumb-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.page-thumb-item.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.page-thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.thumb-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(15, 23, 42, 0.8);
    color: #ffffff;
    font-size: 0.7rem;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumb-toolbar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.88);
    display: flex;
    justify-content: space-around;
    padding: 2px 0;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.page-thumb-item:hover .thumb-toolbar {
    opacity: 1;
}

.btn-thumb-action {
    color: #cbd5e1;
    font-size: 0.78rem;
    padding: 2px 4px;
    line-height: 1;
}

.btn-thumb-action:hover {
    color: #ffffff;
}

.btn-thumb-delete:hover {
    color: #f87171;
}

/* Editor Bottom Export Bar */
.editor-footer {
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.export-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Camera Modal */
.camera-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.camera-viewport {
    position: relative;
    max-width: 720px;
    width: 100%;
    max-height: 75vh;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
}

.camera-viewport video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.camera-guide-box {
    position: absolute;
    top: 8%;
    left: 8%;
    right: 8%;
    bottom: 8%;
    border: 2px dashed rgba(255, 255, 255, 0.65);
    border-radius: var(--radius-md);
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
}

.camera-controls-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    margin-top: 1.5rem;
}

.btn-shutter {
    width: 68px;
    height: 68px;
    border-radius: var(--radius-full);
    background: #ffffff;
    border: 5px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    transition: var(--transition);
}

.btn-shutter:hover {
    transform: scale(1.08);
    background: #f1f5f9;
}

.camera-flash {
    animation: flashFx 0.25s ease-out;
}

@keyframes flashFx {
    0% { opacity: 0.2; }
    50% { opacity: 1; background: #fff; }
    100% { opacity: 1; }
}

/* Processing Modal & Spinner */
.processing-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.processing-card {
    background: #ffffff;
    border-radius: var(--radius-md);
    padding: 2rem 2.5rem;
    text-align: center;
    box-shadow: var(--shadow-xl);
    max-width: 340px;
    width: 90%;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1.25rem;
}

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

.processing-text {
    font-weight: 600;
    color: var(--text-main);
    font-size: 1rem;
}

/* Toast Notifications */
.app-toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: 0.85rem 1.4rem;
    background: #1e293b;
    color: #ffffff;
    border-radius: var(--radius-md);
    font-size: 0.92rem;
    font-weight: 500;
    box-shadow: var(--shadow-xl);
    z-index: 10002;
    transform: translateY(100px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    pointer-events: none;
    max-width: 90vw;
}

.app-toast.show {
    transform: translateY(0);
    opacity: 1;
}

.app-toast.toast-success {
    background: #065f46;
    border-left: 4px solid #34d399;
}

.app-toast.toast-error {
    background: #991b1b;
    border-left: 4px solid #f87171;
}

.app-toast.toast-info {
    background: #1e293b;
    border-left: 4px solid var(--accent);
}

/* Sub-Toolbar for Tools */
.editor-subtoolbar {
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* Aspect Ratio Pill Group */
.ratio-btn-group {
    display: inline-flex;
    background: #e2e8f0;
    border-radius: var(--radius-md);
    padding: 2px;
}

.btn-ratio {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: calc(var(--radius-md) - 2px);
    color: var(--text-muted);
    transition: var(--transition);
}

.btn-ratio.active {
    background: #ffffff;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.btn-brush-size.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

/* Export Options */
.export-options-group {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.filename-input-group, .quality-select-group {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
}

.input-filename {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    width: 170px;
    background: #fff;
    color: var(--text-main);
}

.select-quality {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    background: #fff;
    color: var(--text-main);
    cursor: pointer;
}

/* Watermark Modal */
.watermark-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.watermark-card {
    background: #ffffff;
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 440px;
    width: 100%;
    box-shadow: var(--shadow-xl);
}

/* Drag and Drop Thumbnail States */
.page-thumb-item {
    user-select: none;
    -webkit-user-drag: element;
}

.page-thumb-item.dragging {
    opacity: 0.4;
    transform: scale(0.95);
    border: 2px dashed var(--primary);
}

.page-thumb-item.drag-over {
    border-left: 4px solid var(--primary);
}

/* Canvas Eraser Cursor */
canvas.cursor-eraser {
    cursor: crosshair !important;
}

/* Helper Utilities */
.hidden {
    display: none !important;
}

/* Mobile Responsiveness for Scanner */
@media (max-width: 768px) {
    .upload-card {
        padding: 2.5rem 1rem;
    }
    .upload-heading {
        font-size: 1.25rem;
    }
    .editor-header, .editor-toolbar, .editor-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    .page-navigator, .editor-header-actions, .toolbar-group, .export-group {
        justify-content: space-between;
        width: 100%;
    }
    .filter-btn-group {
        width: 100%;
        display: flex;
    }
    .btn-filter {
        flex: 1;
        text-align: center;
        padding: 0.45rem 0.2rem;
        font-size: 0.78rem;
    }
    .slider-group {
        width: 100%;
        justify-content: space-between;
    }
    .slider-group input[type="range"] {
        flex-grow: 1;
    }
    .canvas-viewport {
        min-height: 280px;
        max-height: 50vh;
    }
    .thumb-toolbar {
        opacity: 1; /* Always visible on touch devices */
    }
    .btn-primary, .btn-secondary {
        width: 100%;
    }
}
