/* ===== RESET & BASE ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #0f172a;
  color: #fff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow-x: hidden;
}

/* ===== HEADER ===== */
.scanner-header {
  background: rgba(15, 23, 42, 0.95);
  padding: 16px 20px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
  width: 100%;
  max-width: 600px;
  border-radius: 16px 16px 0 0;
  margin-top: 20px;
}

.header-content {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #94a3b8;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  transition: all 0.3s ease;
}

.status-dot.inactive {
  background: #ef4444;
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.scanning {
  background: #3b82f6;
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.checking,
.status-dot.warning {
  background: #eab308;
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.error {
  background: #ef4444;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* ===== MAIN CONTAINER ===== */
.scanner-container {
  flex: 1;
  max-width: 600px;
  width: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ===== CAMERA ===== */
.camera-container {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: #1e293b;
  width: 100%;
  max-width: 500px;
  aspect-ratio: 3/4;
  max-height: 500px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  margin: 0 auto;
}

.camera-view {
  width: 100%;
  height: 100%;
  background: #0f172a;
}

#reader {
  width: 100% !important;
  height: 100% !important;
}

#reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

/* ===== ОВЕРЛЕЙ - СКРЫВАЕМ ПОЛНОСТЬЮ ПРИ АКТИВНОЙ КАМЕРЕ ===== */
.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #0f172a;
  transition: opacity 0.3s ease;
  z-index: 5;
}

/* Скрываем оверлей когда камера активна */
.camera-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Полностью скрываем когда камера активна */
.camera-overlay.hidden {
  display: none;
}

.scan-frame {
  width: 60%;
  height: 40%;
  border: 3px solid rgba(59, 130, 246, 0.8);
  border-radius: 16px;
  position: relative;
}

.scan-corner {
  position: absolute;
  width: 25px;
  height: 25px;
  border: 4px solid #3b82f6;
}

.scan-corner.tl {
  top: -2px;
  left: -2px;
  border-right: none;
  border-bottom: none;
  border-radius: 4px 0 0 0;
}

.scan-corner.tr {
  top: -2px;
  right: -2px;
  border-left: none;
  border-bottom: none;
  border-radius: 0 4px 0 0;
}

.scan-corner.bl {
  bottom: -2px;
  left: -2px;
  border-right: none;
  border-top: none;
  border-radius: 0 0 0 4px;
}

.scan-corner.br {
  bottom: -2px;
  right: -2px;
  border-left: none;
  border-top: none;
  border-radius: 0 0 4px 0;
}

.scan-hint {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  margin-top: 30px;
  background: rgba(0, 0, 0, 0.6);
  padding: 8px 20px;
  border-radius: 20px;
}

/* ===== CONTROLS ===== */
.camera-controls {
  position: absolute;
  bottom: 30px;
  left: 0;
  right: 0;
  padding: 0 20px;
  pointer-events: none;
  z-index: 10;
}

.btn-control {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: all;
}

.btn-control:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.btn-start {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
}

.btn-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(59, 130, 246, 0.5);
}

.btn-start:active {
  transform: translateY(0);
}

.btn-start.scanning {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
}

.btn-start.scanning:hover {
  box-shadow: 0 6px 30px rgba(239, 68, 68, 0.5);
}

/* ===== RESULT ===== */
.result-container {
  margin-top: 16px;
  width: 100%;
  max-width: 500px;
}

.result-card {
  background: #1e293b;
  border-radius: 16px;
  padding: 24px;
  border: 2px solid transparent;
  transition: all 0.5s ease;
}

.result-card.allowed {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

.result-card.already {
  border-color: #eab308;
  background: rgba(234, 179, 8, 0.1);
}

.result-card.denied {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.result-card.empty {
  border-color: #334155;
}

.result-icon {
  text-align: center;
  font-size: 48px;
  margin-bottom: 10px;
}

.result-status {
  text-align: center;
  margin-bottom: 16px;
}

#result-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.result-card.allowed #result-title {
  color: #22c55e;
}

.result-card.already #result-title {
  color: #eab308;
}

.result-card.denied #result-title {
  color: #ef4444;
}

.result-card.empty #result-title {
  color: #94a3b8;
}

#result-subtitle {
  color: #94a3b8;
  font-size: 14px;
}

/* ===== DETAILS ===== */
.result-details {
  margin: 16px 0;
}

.details-section {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 16px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
}

.detail-label {
  color: #94a3b8;
  font-weight: 500;
  font-size: 14px;
}

.detail-value {
  color: #e2e8f0;
  font-weight: 600;
  text-align: right;
  font-size: 14px;
}

/* ===== BUTTON NEXT ===== */
.btn-scan-next {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  margin-top: 16px;
}

.btn-scan-next:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
}

.btn-scan-next:active {
  transform: translateY(0);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  body {
    justify-content: flex-start;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .scanner-header {
    margin-top: 0;
    border-radius: 0;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  }

  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .header-title {
    font-size: 17px;
    line-height: 1.25;
  }

  .header-status {
    font-size: 12px;
    width: 100%;
    min-width: 0;
  }

  .scanner-container {
    flex: none;
    justify-content: flex-start;
    padding: 12px;
  }

  .camera-container {
    aspect-ratio: 1 / 1;
    max-height: none;
    max-width: 100%;
    border-radius: 16px;
  }

  .scan-frame {
    width: min(70%, 260px);
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .scan-hint {
    max-width: calc(100% - 32px);
    margin-top: 18px;
    padding: 8px 14px;
    text-align: center;
  }

  .camera-controls {
    bottom: 16px;
    padding: 0 12px;
  }

  .btn-control {
    font-size: 15px;
    padding: 14px;
    min-width: 0;
    min-height: 52px;
    line-height: 1.2;
  }

  .result-card {
    padding: 16px;
  }

  #result-title {
    font-size: 18px;
  }

  .detail-row {
    gap: 12px;
    align-items: flex-start;
  }

  .detail-label {
    flex: 0 0 auto;
  }

  .detail-value {
    min-width: 0;
    max-width: 62%;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 380px) {
  .scan-frame {
    width: min(68%, 220px);
  }

  .btn-control {
    font-size: 13px;
    padding: 12px;
  }

  .result-card {
    padding: 14px;
  }

  .details-section {
    padding: 12px;
  }
}

/* ===== ANIMATIONS ===== */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-card {
  animation: slideUp 0.4s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

.result-card.denied {
  animation:
    shake 0.4s ease,
    slideUp 0.4s ease;
}
