* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f5f6f8;
  color: #111827;
}

.container {
  width: 100%;
  max-width: 700px;
  margin: auto;
  padding: 20px;
}

header {
  text-align: center;
  margin-bottom: 25px;
}

header h1 {
  margin-bottom: 8px;
  font-size: 30px;
}

header p {
  margin: 0;
  color: #6b7280;
}

.scanner-card,
.result {
  background: white;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

.upload-box {
  display: block;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  padding: 45px 20px;
  text-align: center;
  cursor: pointer;
}

.upload-box:hover {
  border-color: #2563eb;
}

.upload-box input {
  display: none;
}

.camera-icon {
  font-size: 45px;
}

.upload-box h2 {
  margin: 15px 0 8px;
}

.upload-box p {
  margin: 0;
  color: #6b7280;
}

.preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 15px;
}

.preview img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 10px;
}

.scan-button,
.new-scan {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 15px;
  margin-top: 20px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  background: #2563eb;
  color: white;
}

.scan-button:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.loading {
  text-align: center;
  padding: 30px 10px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.hidden {
  display: none !important;
}

.result {
  margin-top: 20px;
}

.result h2 {
  margin-top: 0;
}

.result-section {
  border-top: 1px solid #e5e7eb;
  padding: 20px 0;
}

.result-section h3 {
  margin-top: 0;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.info-grid div {
  background: #f8fafc;
  padding: 12px;
  border-radius: 8px;
}

.info-grid span,
.number-block span {
  display: block;
  font-size: 12px;
  color: #64748b;
  margin-bottom: 5px;
}

.info-grid strong {
  display: block;
  font-size: 15px;
}

.description {
  color: #475569;
  line-height: 1.5;
}

.number-block {
  background: #f8fafc;
  padding: 14px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.number {
  display: inline-block;
  background: #e2e8f0;
  padding: 6px 9px;
  border-radius: 6px;
  margin: 3px;
  font-family: monospace;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  background: #e0f2fe;
  padding: 7px 10px;
  border-radius: 20px;
  font-size: 13px;
}

.confidence {
  margin-top: 10px;
  padding: 15px;
  background: #eff6ff;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
}

.verification {
  margin-top: 15px;
  padding: 15px;
  background: #fff7ed;
  border-radius: 10px;
  color: #9a3412;
}

.verification p {
  margin-bottom: 0;
}

.new-scan {
  background: #111827;
}

@media (max-width: 600px) {
  .container {
    padding: 12px;
  }

  header h1 {
    font-size: 25px;
  }

  .scanner-card,
  .result {
    padding: 15px;
  }

  .upload-box {
    padding: 35px 15px;
  }

  .preview {
    grid-template-columns: repeat(2, 1fr);
  }

  .preview img {
    height: 110px;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }
}

/* Uploaded image vs database matched image */

.image-comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 16px 0;
  align-items: start;
}

.image-panel {
  min-width: 0;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}

.image-panel h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: #334155;
}

.image-panel .preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 130px;
}

.image-panel .preview img {
  width: 100%;
  max-width: 180px;
  height: 150px;
  object-fit: contain;
  border-radius: 8px;
  background: white;
}

.image-placeholder {
  color: #64748b;
  font-size: 12px;
  text-align: center;
}

@media (max-width: 480px) {
  .image-comparison {
    grid-template-columns: 1fr;
  }
}




/* Camera and gallery actions */
.scan-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  width: 100%;
}

.action-button {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 12px;
  border: 1px solid #d6deea;
  border-radius: 10px;
  background: #eef3f9;
  color: #172b4d;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.action-button:active {
  transform: scale(0.98);
}

/* Responsive layout */
* {
  box-sizing: border-box;
}

html {
  width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
}

.container {
  width: min(100% - 32px, 710px);
  margin: 0 auto;
}

.scanner-card,
.upload-box,
.result,
.info-card {
  min-width: 0;
  max-width: 100%;
}

.upload-box {
  width: 100%;
  padding: clamp(18px, 4vw, 32px);
}

.preview img,
.database-preview img {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 10px;
}

.image-comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.image-panel {
  min-width: 0;
  overflow-wrap: anywhere;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.scan-button,
.new-scan {
  width: 100%;
  min-height: 48px;
  touch-action: manipulation;
}

@media (max-width: 480px) {
  .container {
    width: calc(100% - 24px);
  }

  header {
    padding: 20px 4px 16px;
    text-align: center;
  }

  header h1 {
    font-size: clamp(24px, 7vw, 30px);
  }

  header p {
    font-size: 14px;
    line-height: 1.5;
  }

  .scanner-card {
    padding: 14px;
    border-radius: 16px;
  }

  .upload-box {
    padding: 22px 12px;
  }

  .scan-actions {
    flex-direction: column;
    gap: 10px;
  }

  .action-button {
    width: 100%;
    font-size: 16px;
  }

  .image-comparison {
    grid-template-columns: minmax(0, 1fr);
  }

  .info-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .result-section {
    padding: 14px;
  }

  .result h2 {
    font-size: 22px;
  }

  .result h3 {
    font-size: 17px;
  }

  .description,
  .number-block,
  .verification {
    overflow-wrap: anywhere;
  }
}



/* Hide camera button on desktop */
#cameraButton {
  display: none;
}

/* Show camera option only on mobile */
@media (max-width: 768px) {
  #cameraButton {
    display: block;
  }

  .scan-actions {
    flex-direction: column;
  }

  .scan-actions .action-button {
    width: 100%;
  }
}
