/**
 * Card Scanner - Mobile Optimizations
 * Förbättrad UX för mobila enheter
 */

/* === Touch Targets === */
/* Alla klickbara element ska vara minst 44x44px för touch */

.scanner-button,
.scanner-action-btn,
.chip input[type="checkbox"] + span {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Större knappar för primära actions */
.btn-capture,
.btn-use-data,
.btn-scan-again {
  min-height: 56px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 12px;
}

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

/* Camera view improvements (without breaking existing layout) */
#cameraView video {
  /* Prevent video flickering on iOS */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* === Real-time Quality Indicator === */
.quality-indicator {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 20;
  min-width: 200px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.quality-icon {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quality-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #94a3b8;
  transition: all 0.3s ease;
}

/* Quality States */
.quality-indicator[data-quality="excellent"] .quality-dot {
  background: #22c55e;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.6);
  animation: pulse-green 2s infinite;
}

.quality-indicator[data-quality="good"] .quality-dot {
  background: #3b82f6;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.6);
}

.quality-indicator[data-quality="fair"] .quality-dot {
  background: #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
}

.quality-indicator[data-quality="poor"] .quality-dot {
  background: #ef4444;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
  animation: pulse-red 1s infinite;
}

@keyframes pulse-green {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.8;
  }
}

@keyframes pulse-red {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

.quality-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: white;
}

.quality-status {
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}

.quality-message {
  font-size: 12px;
  opacity: 0.9;
  line-height: 1.2;
}

/* Camera overlay guide */
.camera-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 400px;
  aspect-ratio: 1.586; /* Standard business card ratio */
  border: 3px solid rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: guidePulse 2s ease-in-out infinite;
}

@keyframes guidePulse {
  0%, 100% {
    border-color: rgba(255, 255, 255, 0.8);
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    border-color: rgba(59, 130, 246, 0.9);
    transform: translate(-50%, -50%) scale(1.02);
  }
}

/* Camera guide corners */
.camera-guide::before,
.camera-guide::after,
.camera-guide-top-left,
.camera-guide-top-right {
  content: '';
  position: absolute;
  width: 30px;
  height: 30px;
  border: 4px solid #3b82f6;
}

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

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

.camera-guide-bottom-left {
  position: absolute;
  bottom: -2px;
  left: -2px;
  width: 30px;
  height: 30px;
  border: 4px solid #3b82f6;
  border-right: none;
  border-top: none;
  border-bottom-left-radius: 12px;
}

.camera-guide-bottom-right {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 30px;
  height: 30px;
  border: 4px solid #3b82f6;
  border-left: none;
  border-top: none;
  border-bottom-right-radius: 12px;
}

/* Camera instructions */
.camera-instructions {
  position: absolute;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  color: white;
  padding: 16px 24px;
  border-radius: 12px;
  max-width: 90%;
  text-align: center;
  font-size: 16px;
  line-height: 1.5;
  animation: fadeInUp 0.5s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Camera Action Buttons (Fixed at bottom) */
.camera-action-buttons {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 12px;
  padding: 20px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  backdrop-filter: blur(10px);
  z-index: 100;
}

.camera-action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 70px;
  touch-action: manipulation;
}

.camera-action-btn i {
  font-size: 24px;
}

.camera-action-btn span {
  font-size: 13px;
}

.camera-btn-primary {
  background: rgba(59, 130, 246, 0.9);
  border-color: rgba(59, 130, 246, 1);
  flex: 1.2; /* Större än de andra */
}

.camera-btn-primary:active {
  background: rgba(37, 99, 235, 0.9);
  transform: scale(0.95);
}

.camera-btn-secondary:active {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0.95);
}

/* Old camera controls (keep for backwards compatibility) */
.camera-controls {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  align-items: center;
}

.btn-capture {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: white;
  border: 6px solid #3b82f6;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
  position: relative;
}

.btn-capture:active {
  transform: scale(0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-capture::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  background: #3b82f6;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.btn-capture:active::before {
  width: 50px;
  height: 50px;
}

.btn-close-camera,
.btn-flip-camera {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-close-camera:active,
.btn-flip-camera:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.3);
}

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

#processingView {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  min-height: 400px;
}

.processing-spinner {
  width: 80px;
  height: 80px;
  border: 6px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.processing-message {
  margin-top: 32px;
  font-size: 18px;
  font-weight: 600;
  color: #334155;
  text-align: center;
}

.processing-progress {
  width: 100%;
  max-width: 300px;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  margin-top: 16px;
  overflow: hidden;
}

.processing-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #2563eb);
  border-radius: 4px;
  transition: width 0.3s ease;
}

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

#previewView {
  padding: 20px;
  max-height: 80vh;
  overflow-y: auto;
  /* Smooth scrolling on iOS */
  -webkit-overflow-scrolling: touch;
}

.preview-image {
  width: 100%;
  max-width: 400px;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin: 0 auto 24px;
  display: block;
}

.preview-data-grid {
  display: grid;
  gap: 16px;
}

.preview-field {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  transition: all 0.2s ease;
}

.preview-field:focus-within {
  background: white;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.preview-field-label {
  font-size: 14px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 8px;
  display: block;
}

.preview-field-value {
  font-size: 16px;
  color: #1e293b;
  word-break: break-word;
}

/* === Category Chips (Mobile) === */

.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

/* Mobile enhancements for chips (without overriding colors) */
.chip {
  /* Larger touch target for mobile */
  min-height: 44px;
  padding: 10px 16px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.chip:active {
  transform: scale(0.95);
}

/* === Action Buttons === */

.scanner-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  background: white;
  border-top: 1px solid #e2e8f0;
  /* Make sure buttons are at bottom on iOS */
  position: sticky;
  bottom: 0;
  z-index: 10;
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .scanner-actions {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}

/* === Loading States === */

.skeleton {
  background: linear-gradient(
    90deg,
    #e2e8f0 25%,
    #f1f5f9 50%,
    #e2e8f0 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* === Mobile-Specific Improvements === */

@media (max-width: 768px) {
  /* Ensure full-height scanner on mobile */
  #cardScannerOverlay {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
  }

  /* Larger text for better readability */
  .preview-field-value {
    font-size: 17px;
  }

  /* Optimize spacing */
  .preview-data-grid {
    gap: 12px;
  }

  /* Better scrolling */
  #previewView {
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
  }

  /* Adjust camera guide for mobile screens */
  .camera-guide {
    width: 85%;
  }

  .camera-instructions {
    bottom: 120px;
    font-size: 15px;
    padding: 12px 20px;
  }

  /* Camera action buttons on mobile */
  .camera-action-buttons {
    gap: 8px;
    padding: 16px;
  }

  .camera-action-btn {
    min-height: 64px;
    padding: 12px 8px;
  }

  .camera-action-btn span {
    font-size: 12px;
  }
}

/* Small screens - even more compact */
@media (max-width: 375px) {
  .camera-action-buttons {
    gap: 6px;
    padding: 12px;
  }

  .camera-action-btn {
    min-height: 60px;
    padding: 10px 6px;
    gap: 4px;
  }

  .camera-action-btn i {
    font-size: 20px;
  }

  .camera-action-btn span {
    font-size: 11px;
  }
}

/* === Landscape Mode === */

@media (max-width: 896px) and (orientation: landscape) {
  .camera-guide {
    width: 60%;
    max-width: 500px;
  }

  .camera-instructions {
    bottom: 80px;
    font-size: 14px;
  }

  .camera-action-buttons {
    padding: 12px;
  }

  .camera-action-btn {
    min-height: 60px;
    padding: 12px 8px;
    font-size: 12px;
  }

  .camera-action-btn i {
    font-size: 20px;
  }

  .camera-action-btn span {
    font-size: 11px;
  }

  .camera-controls {
    bottom: 20px;
  }

  .btn-capture {
    width: 60px;
    height: 60px;
  }

  .btn-capture::before {
    width: 45px;
    height: 45px;
  }
}

/* === Performance Optimizations === */

/* Hardware acceleration for animations */
.btn-capture,
.camera-guide,
.processing-spinner,
.chip {
  will-change: transform;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  .camera-guide,
  .processing-spinner,
  .skeleton {
    animation: none;
  }

  .btn-capture,
  .chip {
    transition: none;
  }
}

/* === iOS-Specific Fixes === */

/* Prevent zoom on input focus */
@supports (-webkit-touch-callout: none) {
  input,
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* Safe areas for notched devices */
@supports (padding: env(safe-area-inset-top)) {
  #cameraView {
    padding-top: env(safe-area-inset-top);
  }

  .camera-action-buttons {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .camera-instructions {
    bottom: calc(120px + env(safe-area-inset-bottom));
  }

  .camera-controls {
    bottom: calc(40px + env(safe-area-inset-bottom));
  }
}

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

@media (prefers-color-scheme: dark) {
  .preview-field {
    background: #1e293b;
    border-color: #334155;
  }

  .preview-field:focus-within {
    background: #0f172a;
    border-color: #3b82f6;
  }

  .preview-field-label {
    color: #94a3b8;
  }

  .preview-field-value {
    color: #e2e8f0;
  }

  /* Chip styling handled by sellers-contacts.css */
}
