/* ============================================
   SCANNER MODAL — Mobile-First
   ============================================ */

.scanner-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.scanner-modal.hidden {
    display: none;
}

/* ============================================
   CLOSE-BUTTON
   ============================================ */

.scanner-close {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    right: 16px;
    z-index: 10;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

/* ============================================
   LOADING-STATE
   ============================================ */

.scanner-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #111;
    z-index: 5;
    gap: 16px;
    color: #fff;
    font-size: 15px;
}

.scanner-loading.hidden {
    display: none;
}

/* Spinner — gleicher Stil wie bestehender PDF-Loader */
.scanner-loading .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   VIEWPORT (Video + Overlays)
   ============================================ */

.scanner-viewport {
    position: relative;
    flex: 1;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.scanner-viewport.hidden {
    display: none;
}

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

.scanner-viewport video.hidden,
.scanner-viewport canvas.hidden {
    display: none;
}

/* Eingefrorenes Bild nach Aufnahme */
#scannerCapture {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* SVG-Overlay für Ecken-Polygon */
.scanner-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.scanner-polygon {
    fill: rgba(52, 168, 83, 0.2);
    stroke: #34a853;
    stroke-width: 2.5;
    stroke-linejoin: round;
}

/* ============================================
   CORNER-HANDLES
   ============================================ */

.corner-handle {
    position: absolute;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    touch-action: none;
    cursor: grab;
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.corner-handle.hidden {
    display: none;
}

/* Sichtbarer Kern via ::after */
.corner-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 2px #1a73e8, 0 2px 6px rgba(0, 0, 0, 0.5);
}

.corner-handle:active {
    cursor: grabbing;
}

/* ============================================
   BOTTOM BAR
   ============================================ */

.scanner-bottom-bar {
    position: relative;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    padding: 8px 16px max(12px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

/* ============================================
   THUMBNAILS
   ============================================ */

.scanner-thumbnails {
    display: flex;
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    width: 100%;
    min-height: 0;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.scanner-thumbnails:empty {
    display: none;
}

.scanner-thumbnails::-webkit-scrollbar {
    display: none;
}

.scanner-thumbnail {
    height: 64px;
    width: auto;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
    object-fit: cover;
}

/* ============================================
   BUTTONS
   ============================================ */

.scanner-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    width: 100%;
    position: relative;
}

/* Auslöser-Button */
.capture-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s;
}

.capture-btn:active {
    background: rgba(255, 255, 255, 0.45);
}

.capture-btn.hidden {
    display: none;
}

/* Sekundäre Buttons — Design-Sprache konsistent mit restlicher App */
#scanRetakeBtn,
#scanConfirmBtn,
#scanFinishBtn {
    min-height: 40px;
    padding: 0 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

#scanRetakeBtn {
    background: transparent;
    color: #e8eaed;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#scanConfirmBtn {
    background: #1a73e8;
    color: #fff;
    border: none;
}

#scanFinishBtn {
    background: transparent;
    color: #e8eaed;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#scanRetakeBtn.hidden,
#scanConfirmBtn.hidden,
#scanFinishBtn.hidden {
    display: none;
}

@media (hover: hover) and (pointer: fine) {
    #scanRetakeBtn:hover { background: rgba(255, 255, 255, 0.08); }
    #scanConfirmBtn:hover { background: #1557b0; }
    #scanFinishBtn:hover { background: rgba(255, 255, 255, 0.08); }
}

#scanRetakeBtn:active { background: rgba(255, 255, 255, 0.12); }
#scanConfirmBtn:active { background: #1557b0; }
#scanFinishBtn:active { background: rgba(255, 255, 255, 0.12); }
