/* Scanner Styles - Theme clair */

/* Scanner Result - Error */
.scanner-error-result {
  text-align: center;
  padding: 40px 20px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  animation: fade-in 0.4s ease;
}

.scanner-error-result-icon {
  width: 80px;
  height: 80px;
  background: var(--danger-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px auto;
  color: #fff;
}

.scanner-error-result-title {
  font-size: 20px;
  font-weight: 600;
  color: #1d1d1f;
  margin: 0 0 12px 0;
}

.scanner-error-result-description {
  font-size: 14px;
  color: #86868b;
  margin: 0 0 24px 0;
  max-width: 300px;
  line-height: 1.6;
  margin-left: auto;
  margin-right: auto;
}

.scanner-error-result #scannerRetryResultBtn {
  margin-top: 8px;
}

/* Scanner Result - Card Preview */
.scanner-preview-container {
  padding: 0;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  animation: fade-in 0.4s ease;
}

.scanner-preview-image-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.scanner-preview-image {
  width: min(160px, 40vw);
  aspect-ratio: 5 / 7;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  transition: opacity 0.3s ease;
}

.scanner-preview-image.loaded {
  opacity: 1;
}

.scanner-preview-image.lazy-image {
  opacity: 0;
}

/* Scanner Preview Details */
.scanner-preview-details {
  background: var(--surface-container);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 24px;
}

.scanner-preview-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.scanner-preview-row:last-child {
  border-bottom: none;
}

.scanner-preview-label {
  font-size: 13px;
  font-weight: 500;
  color: #86868b;
}

.scanner-preview-value {
  font-size: 14px;
  font-weight: 600;
  color: #1d1d1f;
}

.scanner-preview-value .scanner-dropdown-placeholder {
  display: inline-block;
}

.scanner-preview-value .lfs-wrapper,
.scanner-preview-value .ts-wrapper,
.scanner-preview-value .ss-wrapper {
  cursor: pointer;
}

.scanner-preview-value .lfs-wrapper .lfs-flag {
  display: flex;
  align-items: center;
}

.scanner-preview-value .lfs-wrapper .lfs-flag img {
  width: 20px;
  height: 14px;
  border-radius: 2px;
}

.scanner-preview-value .ts-wrapper .ts-selected {
  display: flex;
  align-items: center;
  gap: 6px;
}

.scanner-preview-value .ts-wrapper .ts-badge {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.scanner-preview-value .ts-wrapper .ts-label {
  font-size: 14px;
  font-weight: 600;
}

.scanner-preview-value .ss-wrapper .ss-selected {
  display: flex;
  align-items: center;
  gap: 6px;
}

.scanner-preview-value .ss-wrapper .ss-abbr {
  font-size: 12px;
  font-weight: 700;
  color: #344362;
}

.scanner-preview-value .ss-wrapper .ss-label {
  font-size: 14px;
  font-weight: 600;
}

.scanner-preview-value .lfs-wrapper.open,
.scanner-preview-value .ts-wrapper.open,
.scanner-preview-value .ss-wrapper.open {
  position: relative;
}

.scanner-preview-row .lfs-dropdown,
.scanner-preview-row .ts-dropdown,
.scanner-preview-row .ss-dropdown {
  position: fixed;
  z-index: 10000;
}

/* Scanner Preview Price */
.scanner-preview-price {
  background: var(--surface-container);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 24px;
}

.scanner-price-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 0;
  color: #86868b;
  font-size: 14px;
}

.scanner-price-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Uses @keyframes spin from index.html */

.scanner-preview-price .sc-modal-price-chart {
  margin: 0;
}

.scanner-preview-price .sc-modal-chart-container {
  min-height: 180px;
}

/* Scanner Preview Actions - using unified buttons */
.scanner-preview-actions {
  display: flex;
  flex-direction: row;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.scanner-preview-actions .dex-btn {
  flex: 1;
  max-width: 200px;
}

.scanner-preview-actions .dex-btn-success:disabled {
  background: var(--text-secondary);
  cursor: not-allowed;
  transform: none;
}

.scanner-spinner-small {
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  display: inline-block;
}

/* Scanner Success Add - using unified buttons */
.scanner-success-add {
  text-align: center;
  padding: 40px 20px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  animation: fade-in 0.4s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scanner-success-add .dex-btn-block {
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.scanner-success-add-icon {
  width: 80px;
  height: 80px;
  background: var(--success-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px auto;
  color: #fff;
}

.scanner-success-add-title {
  font-size: 22px;
  font-weight: 600;
  color: #1d1d1f;
  margin: 0 0 12px 0;
}

.scanner-success-add-description {
  font-size: 14px;
  color: #86868b;
  margin: 0 0 32px 0;
}

/* Scanner Result - Cards Grid */
.scanner-result-grid-container {
  padding: 16px 0;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  animation: fade-in 0.4s ease;
}

.scanner-result-header {
  text-align: center;
  margin-bottom: 24px;
  padding: 0 16px;
}

.scanner-result-title {
  font-size: 22px;
  font-weight: 600;
  color: #1d1d1f;
  margin: 0 0 8px 0;
}

.scanner-result-subtitle {
  font-size: 14px;
  color: #86868b;
  margin: 0;
}

.scanner-result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  padding: 0 16px;
}

.scanner-result-card-item {
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-container);
  aspect-ratio: 5 / 7;
}

.scanner-result-card-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(52, 67, 98, 0.2);
}

.scanner-result-card-item:active {
  transform: translateY(-2px);
}

.scanner-result-card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.scanner-result-card-image.loaded {
  opacity: 1;
}

/* Scanner Page Container */
#scanner.page {
  flex-direction: column;
  height: 100%;
  background: linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%);
  position: relative;
  overflow: hidden;
}

#scanner.page.active {
  display: flex;
}

/* Scanner Content Container */
#scanner-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Hide scanner content when result is active */
#scanner.has-scanner-result #scanner-content {
  display: none;
}

/* Scanner Result Page (nested in #scanner) */
#scanner_result.scanner-subpage {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  flex-direction: column;
  height: 100%;
  background: var(--background);
  z-index: 10;
  overflow: hidden;
}

#scanner_result.scanner-subpage.active {
  display: flex;
}

/* Content Area */
.scanner-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

/* Idle State */
.scanner-idle {
  text-align: center;
  animation: fade-in 0.4s ease;
}

.scanner-idle-icon {
  width: 180px;
  height: 180px;
  margin-bottom: 28px;
  animation: float 3s ease-in-out infinite;
}

.scanner-idle-title {
  font-size: 24px;
  font-weight: 700;
  color: #1d1d1f;
  margin: 0 0 12px 0;
}

.scanner-idle-description {
  font-size: 15px;
  color: #86868b;
  margin: 0 0 24px 0;
  max-width: 320px;
  line-height: 1.6;
}

.scanner-idle #scannerStartBtn {
  margin-top: 12px;
}

/* Requesting/Loading State */
.scanner-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.scanner-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.scanner-loading-text {
  font-size: 16px;
  color: var(--text-secondary);
  margin: 0;
}

/* Active State - Video Container */
.scanner-active {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: fade-in 0.3s ease;
}

.scanner-video-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.3) 0%,
    rgba(0, 0, 0, 0.6) 30%,
    rgba(0, 0, 0, 0.6) 70%,
    rgba(0, 0, 0, 0.3) 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Card Frame Overlay - Ratio 5:7 - Gradient Animated */
.scanner-card-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  aspect-ratio: 5 / 7;
  width: min(320px, 75vw);
  max-height: 80%;
  border: none;
  border-radius: 16px;
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.5),
    inset 0 0 0 3px transparent;
  pointer-events: none;
  z-index: 10;
  background: transparent;
}

/* Gradient border via pseudo-element */
.scanner-card-frame::before {
  content: "";
  position: absolute;
  top: -3px;
  left: -3px;
  right: -3px;
  bottom: -3px;
  border-radius: 18px;
  background: linear-gradient(90deg, #344362, #4a90e2, #344362);
  background-size: 200% 100%;
  animation: gradient-flow 2s ease infinite;
  z-index: -1;
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask-composite: exclude;
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  padding: 3px;
}

@keyframes gradient-flow {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* Glowing corners */
.scanner-card-frame-corner {
  position: absolute;
  width: 24px;
  height: 24px;
  pointer-events: none;
  z-index: 12;
}

.scanner-card-frame-corner::before,
.scanner-card-frame-corner::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 4px;
}

.scanner-card-frame-corner.top-left {
  top: -3px;
  left: -3px;
}
.scanner-card-frame-corner.top-left::before {
  top: 0;
  left: 0;
  width: 24px;
  height: 3px;
}
.scanner-card-frame-corner.top-left::after {
  top: 0;
  left: 0;
  width: 3px;
  height: 24px;
}

.scanner-card-frame-corner.top-right {
  top: -3px;
  right: -3px;
}
.scanner-card-frame-corner.top-right::before {
  top: 0;
  right: 0;
  width: 24px;
  height: 3px;
}
.scanner-card-frame-corner.top-right::after {
  top: 0;
  right: 0;
  width: 3px;
  height: 24px;
}

.scanner-card-frame-corner.bottom-left {
  bottom: -3px;
  left: -3px;
}
.scanner-card-frame-corner.bottom-left::before {
  bottom: 0;
  left: 0;
  width: 24px;
  height: 3px;
}
.scanner-card-frame-corner.bottom-left::after {
  bottom: 0;
  left: 0;
  width: 3px;
  height: 24px;
}

.scanner-card-frame-corner.bottom-right {
  bottom: -3px;
  right: -3px;
}
.scanner-card-frame-corner.bottom-right::before {
  bottom: 0;
  right: 0;
  width: 24px;
  height: 3px;
}
.scanner-card-frame-corner.bottom-right::after {
  bottom: 0;
  right: 0;
  width: 3px;
  height: 24px;
}

/* Frame instructions */
.scanner-frame-instruction {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  z-index: 15;
  padding: 10px 20px;
  background: rgba(52, 67, 98, 0.8);
  border-radius: 24px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%,
  100% {
    box-shadow: 0 0 8px rgba(74, 144, 226, 0.3);
  }
  50% {
    box-shadow: 0 0 16px rgba(74, 144, 226, 0.5);
  }
}

/* Capture Controls */
.scanner-controls {
  padding: 24px;
  background: linear-gradient(180deg, #fff 0%, #f8f9fa 100%);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  gap: 16px;
}

.scanner-btn-capture {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #fff 0%, #f8f9fa 100%);
  border: 4px solid #344362;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 4px 16px rgba(52, 67, 98, 0.2);
}

.scanner-btn-capture::before {
  content: "";
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #344362 0%, #4a90e2 100%);
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(52, 67, 98, 0.3);
}

.scanner-btn-capture:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(52, 67, 98, 0.3);
}

.scanner-btn-capture:hover::before {
  width: 56px;
  height: 56px;
}

.scanner-btn-capture:active::before {
  width: 48px;
  height: 48px;
  box-shadow: 0 1px 4px rgba(52, 67, 98, 0.2);
}

.scanner-btn-capture:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Flash effect on capture */
.scanner-flash {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  opacity: 0;
  z-index: 100;
  pointer-events: none;
}

.scanner-flash.active {
  animation: scanner-flash 0.3s ease-out;
}

@keyframes scanner-flash {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* Uploading State */
.scanner-uploading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(248, 249, 250, 0.98);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

/* Progress Circle */
.scanner-progress-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.scanner-progress-circle {
  width: 100px;
  height: 100px;
  position: relative;
}

.scanner-progress-circle svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.scanner-progress-circle-bg {
  fill: none;
  stroke: var(--border-color);
  stroke-width: 8;
}

.scanner-progress-circle-progress {
  fill: none;
  stroke: #344362;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 251.2;
  stroke-dashoffset: 251.2;
  transition: stroke-dashoffset 0.3s ease;
}

.scanner-progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  font-weight: 600;
  color: #344362;
}

/* Analyzing State */
.scanner-analyzing {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(248, 249, 250, 0.98);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fade-in 0.4s ease;
}

.scanner-analyzing-icon {
  width: 140px;
  height: 140px;
  margin-bottom: 24px;
}

.scanner-analyzing-icon svg {
  width: 100%;
  height: 100%;
}

.scanner-analyzing-title {
  font-size: 20px;
  font-weight: 600;
  color: #1d1d1f;
  margin: 0 0 12px 0;
}

.scanner-analyzing-description {
  font-size: 14px;
  color: #86868b;
  margin: 0 0 24px 0;
  max-width: 280px;
  text-align: center;
  line-height: 1.5;
}

.scanner-analyzing .dex-btn.disabled,
.scanner-analyzing .dex-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.scanner-analyzing .dex-btn {
  margin-top: 16px !important;
}

/* Success State */
.scanner-success {
  text-align: center;
  padding: 40px 20px;
}

.scanner-success-icon {
  width: 80px;
  height: 80px;
  background: var(--success-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px auto;
  color: #fff;
}

.scanner-success-title {
  font-size: 22px;
  font-weight: 600;
  color: #1d1d1f;
  margin: 0 0 12px 0;
}

.scanner-success-description {
  font-size: 14px;
  color: #86868b;
  margin: 0 0 32px 0;
}

/* Error State */
.scanner-error {
  text-align: center;
  padding: 40px 20px;
}

.scanner-error-icon {
  width: 80px;
  height: 80px;
  background: var(--danger-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px auto;
  color: #fff;
}

/* Permission denied specific */
.scanner-permission-denied {
  text-align: center;
  padding: 40px 20px;
}

.scanner-permission-icon {
  width: 80px;
  height: 80px;
  background: #ff9800;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px auto;
  color: #fff;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .scanner-content {
    padding: 16px;
  }

  .scanner-idle-icon {
    width: 140px;
    height: 140px;
  }

  .scanner-idle-title {
    font-size: 20px;
  }

  .scanner-card-frame {
    width: min(300px, 70vw);
  }

  .scanner-card-frame-corner {
    width: 20px;
    height: 20px;
  }

  .scanner-frame-instruction {
    font-size: 13px;
    padding: 8px 16px;
    bottom: 16px;
  }

  .scanner-controls {
    padding: 16px;
  }

  .scanner-btn-capture {
    width: 68px;
    height: 68px;
  }

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

  .scanner-progress-circle {
    width: 80px;
    height: 80px;
  }

  .scanner-progress-text {
    font-size: 16px;
  }

  .scanner-analyzing-icon {
    width: 120px;
    height: 120px;
  }

  .scanner-analyzing-title {
    font-size: 18px;
  }
}

/* Safe area for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .scanner-controls {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* Cordova Mode - Scrollable preview container */
.mobile-app .scanner-preview-container {
  max-height: calc(100vh - 52px);
  overflow-y: auto;
  overflow-x: hidden;
}
