/**
 * Card Scanner CSS
 * Styles för visitkortsskanner med fokus på UX och mobile-first
 */

/* ==================== Overlay & Container ==================== */

.scanner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.scanner-overlay[style*="display: flex"] {
    opacity: 1;
}

.scanner-container {
    width: 100%;
    height: 100%;
    background: #1e293b;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ==================== Scanner Header ==================== */

.scanner-header {
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.scanner-header h3 {
    margin: 0;
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
}

.btn-close-scanner {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1.25rem;
}

.btn-close-scanner:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* ==================== Camera View ==================== */

.camera-view {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

#cameraStream {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Camera Guide (visitkorts-ram) */
.camera-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    max-width: 400px;
    aspect-ratio: 1.6;
    pointer-events: none;
}

.guide-box {
    width: 100%;
    height: 100%;
    position: relative;
    border: 2px dashed rgba(255, 255, 255, 0.6);
    border-radius: 12px;
}

.guide-box p {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 0.9rem;
    text-align: center;
    background: rgba(0, 0, 0, 0.7);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    white-space: nowrap;
}

/* Tips overlay */
.camera-tips {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    max-width: 90%;
    text-align: center;
    z-index: 10;
}

.camera-tips i {
    color: #10b981;
    margin-right: 0.5rem;
}

/* Animated guide corners */
.guide-corner {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 3px solid #10b981;
    animation: pulse 2s ease-in-out infinite;
}

.guide-corner.tl {
    top: -2px;
    left: -2px;
    border-right: none;
    border-bottom: none;
    border-top-left-radius: 12px;
}

.guide-corner.tr {
    top: -2px;
    right: -2px;
    border-left: none;
    border-bottom: none;
    border-top-right-radius: 12px;
}

.guide-corner.bl {
    bottom: -2px;
    left: -2px;
    border-right: none;
    border-top: none;
    border-bottom-left-radius: 12px;
}

.guide-corner.br {
    bottom: -2px;
    right: -2px;
    border-left: none;
    border-top: none;
    border-bottom-right-radius: 12px;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(0.95);
    }
}

/* ==================== File Upload View ==================== */

.file-upload-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    gap: 1.5rem;
}

.file-upload-view i {
    font-size: 4rem;
    color: #0ea5e9;
}

.file-upload-view h4 {
    color: white;
    font-size: 1.25rem;
    margin: 0;
}

#cardImageFile {
    display: none;
}

.btn-upload {
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    color: white;
    padding: 1rem 2rem;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-block;
    box-shadow: 0 4px 12px rgba(30, 41, 59, 0.3);
}

.btn-upload:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(30, 41, 59, 0.45);
}

/* ==================== Processing View ==================== */

.processing-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    gap: 1.5rem;
}

.processing-spinner i {
    font-size: 4rem;
    color: #0ea5e9;
    animation: spin 1s linear infinite;
}

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

.processing-view h4 {
    color: white;
    font-size: 1.25rem;
    margin: 0;
}

.progress-bar-container {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #0ea5e9 0%, #10b981 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

#ocrProgressText {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    margin: 0;
}

/* ==================== Preview View ==================== */

.preview-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    overflow-y: auto;
}

.preview-view h4 {
    color: white;
    font-size: 1.25rem;
    margin: 0 0 1.5rem 0;
    text-align: center;
}

.scanned-preview {
    flex: 1;
    overflow-y: auto;
}

/* Confidence Badge */
.scan-confidence {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.scan-confidence.high {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: #065f46;
}

.scan-confidence.medium {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e;
}

.scan-confidence.low {
    background: linear-gradient(135deg, #fee2e2, #fecaca);
    color: #991b1b;
}

.scan-confidence i {
    font-size: 1.5rem;
}

/* Method Badge */
.method-badge {
    margin-left: auto;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.method-badge.azure {
    background: linear-gradient(135deg, #0078d4, #00a4ef);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 120, 212, 0.3);
}

.method-badge.tesseract {
    background: linear-gradient(135deg, #6b7280, #9ca3af);
    color: white;
    box-shadow: 0 2px 8px rgba(107, 114, 128, 0.3);
}

/* Scanned Fields */
.scanned-fields {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.scanned-field {
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 8px;
    border-left: 3px solid #0ea5e9;
}

.scanned-field label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.field-value {
    color: white;
    font-size: 1rem;
    font-weight: 500;
}

.field-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.category-badge {
    background: rgba(14, 165, 233, 0.2);
    color: #bae6fd;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
}

/* Warning */
.scan-warning {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(251, 191, 36, 0.1);
    color: #fbbf24;
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.scan-warning i {
    font-size: 1.25rem;
}

/* Preview Actions */
.preview-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.preview-actions button {
    flex: 1;
}

/* ==================== Scanner Controls ==================== */

.scanner-controls {
    padding: 1.5rem;
    background: #0f172a;
    display: flex;
    gap: 1rem;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.scanner-controls button {
    flex: 1;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 52px; /* Touch-friendly */
}

.btn-capture {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    flex: 2; /* Större än de andra */
}

.btn-capture:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.6);
}

.btn-switch-mode {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-switch-mode:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-cancel {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-cancel:hover {
    background: rgba(239, 68, 68, 0.2);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.875rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-primary {
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    color: white;
    border: none;
    padding: 0.875rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 12px rgba(30, 41, 59, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(30, 41, 59, 0.45);
}

/* ==================== Scan Button in Modal ==================== */

.scan-card-section {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.12), rgba(30, 41, 59, 0.12));
    border-radius: 12px;
    margin-bottom: 1.5rem;
    border: 2px dashed rgba(51, 65, 85, 0.3);
}

.btn-scan-card {
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    color: white;
    border: none;
    padding: 0.875rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(30, 41, 59, 0.3);
}

.btn-scan-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(30, 41, 59, 0.45);
}

.btn-scan-card i {
    font-size: 1.25rem;
}

.scan-card-help {
    color: #94a3b8;
    font-size: 0.9rem;
}

.scan-divider {
    text-align: center;
    position: relative;
    margin: 1.5rem 0;
}

.scan-divider span {
    background: white;
    padding: 0 1rem;
    color: #94a3b8;
    font-size: 0.9rem;
    font-weight: 500;
    position: relative;
    z-index: 1;
}

.scan-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e2e8f0;
}

/* ==================== Responsive: Desktop ==================== */

@media (min-width: 769px) {
    .scanner-overlay {
        padding: 2rem;
    }

    .scanner-container {
        max-width: 700px;
        max-height: 90vh;
        margin: 0 auto;
        border-radius: 16px;
        overflow: hidden;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    }

    .camera-view {
        border-radius: 0;
    }

    .scanner-controls {
        border-bottom-left-radius: 16px;
        border-bottom-right-radius: 16px;
    }
}

/* ==================== Responsive: Tablet ==================== */

@media (max-width: 768px) and (min-width: 481px) {
    .scanner-header h3 {
        font-size: 1.1rem;
    }

    .btn-close-scanner {
        width: 36px;
        height: 36px;
    }

    .camera-guide {
        width: 80%;
    }

    .scanner-controls {
        flex-wrap: wrap;
    }

    .btn-capture {
        flex: 1 1 100%;
        order: -1;
    }
}

/* ==================== Responsive: Mobile ==================== */

@media (max-width: 480px) {
    .scanner-header {
        padding: 0.875rem 1rem;
    }

    .scanner-header h3 {
        font-size: 1rem;
    }

    .btn-close-scanner {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .camera-guide {
        width: 90%;
    }

    .guide-box p {
        font-size: 0.8rem;
        bottom: -35px;
    }

    .processing-view,
    .file-upload-view {
        padding: 1.5rem;
    }

    .preview-view {
        padding: 1rem;
        height: 100%;
        overflow: hidden;
        position: relative;
    }

    .preview-view h4 {
        font-size: 1.1rem;
    }

    .scanner-controls {
        padding: 1rem;
        flex-direction: column;
        gap: 0.75rem;
    }

    .scanner-controls button {
        width: 100%;
        min-height: 48px;
    }

    .btn-capture {
        order: -1;
    }

    .preview-actions {
        flex-direction: column;
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        margin: 0;
        padding: 0.25rem 0 calc(0.25rem + env(safe-area-inset-bottom));
        background: linear-gradient(180deg, rgba(30, 41, 59, 0) 0%, rgba(30, 41, 59, 0.9) 45%, rgba(30, 41, 59, 1) 100%);
        z-index: 2;
    }

    .scanned-preview {
        min-height: 0;
        overflow-y: auto;
        padding-bottom: 7.5rem;
    }

    .scan-card-section {
        flex-direction: column;
        text-align: center;
    }

    .camera-action-buttons {
        flex-wrap: wrap;
        gap: 0.5rem;
        max-width: 95%;
    }

    .camera-action-btn {
        padding: 0.625rem 0.875rem;
        font-size: 0.813rem;
        flex-direction: column;
        gap: 0.25rem;
        min-width: 70px;
    }

    .camera-action-btn span {
        display: block; /* Visa texten! */
        font-size: 0.688rem;
        line-height: 1;
    }

    .camera-action-btn i {
        font-size: 1.125rem;
    }
}

/* ==================== Accessibility ==================== */

@media (prefers-reduced-motion: reduce) {
    .scanner-overlay,
    .btn-capture,
    .btn-close-scanner,
    .btn-upload,
    .guide-corner {
        animation: none !important;
        transition: none !important;
    }
}

/* Focus styles för keyboard navigation */
button:focus-visible,
.btn-upload:focus-visible {
    outline: 3px solid #10b981;
    outline-offset: 2px;
}

/* ==================== Manual Fill Button Styles ==================== */

/* Camera Action Buttons (new styles) */
.camera-action-buttons {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.75rem;
    z-index: 100;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 90%;
}

.camera-action-btn {
    padding: 0.875rem 1.25rem;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
    white-space: nowrap;
}

.camera-btn-primary {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.camera-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}

.camera-btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.camera-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.camera-btn-outline {
    background: transparent;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
}

.camera-btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.6);
}

/* Preview Actions - Outline Button */
.preview-actions .btn-outline {
    background: transparent;
    color: #94a3b8;
    border: 2px solid rgba(148, 163, 184, 0.3);
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.preview-actions .btn-outline:hover {
    background: rgba(148, 163, 184, 0.1);
    border-color: rgba(148, 163, 184, 0.5);
    color: #cbd5e1;
}

/* File Upload View - "eller" text */
.file-upload-or {
    margin: 1rem 0 0.75rem;
    color: #94a3b8;
    font-size: 0.9rem;
    font-weight: 500;
}

.file-upload-view .btn-outline {
    background: transparent;
    color: #94a3b8;
    border: 2px solid rgba(148, 163, 184, 0.3);
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.file-upload-view .btn-outline:hover {
    background: rgba(148, 163, 184, 0.1);
    border-color: rgba(148, 163, 184, 0.5);
    color: #cbd5e1;
    transform: translateY(-2px);
}

/* ==================== Dark Mode Support ==================== */

@media (prefers-color-scheme: dark) {
    /* Already dark by default, but ensure consistency */
    .scanner-container {
        background: #1e293b;
    }
}

/* ==================== Print (dölj scanner) ==================== */

@media print {
    .scanner-overlay {
        display: none !important;
    }
}
