* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f3f4f6; color: #1f2937;
  min-height: 100vh; min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

/* ---- Common ---- */
.btn {
  display: block; width: 100%; padding: 18px;
  font-size: 20px; font-weight: 700; border: none;
  border-radius: 12px; cursor: pointer; -webkit-appearance: none;
}
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.5; }
.btn-primary { background: #1e40af; color: white; }
.btn-secondary { background: #e5e7eb; color: #374151; }
.btn-success { background: #059669; color: white; }
.error-msg {
  background: #fef2f2; border: 2px solid #fca5a5; color: #dc2626;
  padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 16px; text-align: center;
}
.loading {
  display: inline-block; width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,0.3); border-top-color: white;
  border-radius: 50%; animation: spin 0.6s linear infinite;
  vertical-align: middle; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.top-bar {
  background: #1e40af; color: white;
  padding: 12px 16px; display: flex;
  align-items: center; justify-content: space-between;
  flex-shrink: 0; z-index: 10;
}
.top-bar h2 { font-size: 18px; font-weight: 700; }
.top-bar button {
  background: rgba(255,255,255,0.2); border: none; color: white;
  padding: 8px 16px; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.ok-btn { background: #059669 !important; }

/* ---- Login ---- */
.login-page {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
}
.login-page h1 { color: white; font-size: 28px; margin-bottom: 8px; }
.login-page .subtitle { color: #bfdbfe; font-size: 16px; margin-bottom: 32px; }
.login-box {
  background: white; border-radius: 16px; padding: 32px 24px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 16px; font-weight: 600; color: #374151; margin-bottom: 8px; }
.form-group input {
  width: 100%; padding: 16px; font-size: 18px;
  border: 2px solid #d1d5db; border-radius: 12px; outline: none; -webkit-appearance: none;
}
.form-group input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.2); }

/* ---- Camera ---- */
.camera-page {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; background: #000;
}
.video-container {
  flex: 1; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.video-container video { width: 100%; height: 100%; object-fit: cover; }
.guide-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.guide-frame {
  width: 88%; height: 65%;
  border: 3px solid rgba(255,255,255,0.7); border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.3);
}
.guide-text {
  color: white; font-size: 15px; font-weight: 600;
  margin-top: 12px; text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}
.capture-bar {
  padding: 16px 24px; display: flex;
  align-items: center; justify-content: space-between;
  background: rgba(0,0,0,0.7); flex-shrink: 0;
}
.capture-btn {
  width: 76px; height: 76px; border-radius: 50%;
  border: 5px solid white; background: rgba(255,255,255,0.3);
  cursor: pointer; -webkit-appearance: none; flex-shrink: 0;
}
.capture-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.6); }
.side-btn {
  width: 52px; height: 52px; border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.4); background: rgba(255,255,255,0.15);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}

/* ---- Crop / Corner adjustment ---- */
.crop-page {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; background: #1a1a1a;
}
.crop-container {
  flex: 1; display: flex; align-items: center; justify-content: center;
  overflow: hidden; padding: 8px;
}
#crop-canvas {
  display: block; touch-action: none;
  border-radius: 4px;
}
.crop-hint {
  color: #9ca3af; font-size: 14px; text-align: center;
  padding: 10px 16px; flex-shrink: 0;
}

/* ---- Processing ---- */
.processing-page {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
}
.processing-page p { font-size: 18px; color: #6b7280; }
.loading-spinner {
  width: 48px; height: 48px;
  border: 5px solid #e5e7eb; border-top-color: #1e40af;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}

/* ---- Preview ---- */
.preview-page {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; background: #f3f4f6;
}
.preview-content {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 16px; gap: 16px;
}
.scanned-img {
  max-width: 100%; max-height: 55vh;
  border-radius: 8px; border: 2px solid #d1d5db; background: white;
  object-fit: contain;
}
.preview-actions {
  display: flex; flex-direction: column; gap: 12px;
  width: 100%; max-width: 400px;
}

/* ---- Form ---- */
.form-page { min-height: 100vh; min-height: 100dvh; background: #f3f4f6; }
.form-content { padding: 16px; max-width: 500px; margin: 0 auto; }
.preview-img {
  width: 100%; max-height: 200px; object-fit: contain;
  border-radius: 12px; border: 2px solid #d1d5db; background: white; margin-bottom: 16px;
}
.form-content .form-group input { font-size: 22px; padding: 18px; }
.form-content .form-group input[type="number"] { font-size: 28px; font-weight: 700; text-align: center; }
.form-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; padding-bottom: 40px; }

/* ---- Fallback ---- */
.fallback-page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.fallback-content {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 32px; text-align: center; gap: 16px;
}
.fallback-content p { font-size: 18px; color: #6b7280; }

/* ---- Success ---- */
.success-page {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; background: #f0fdf4;
}
.success-icon { font-size: 80px; margin-bottom: 24px; }
.success-page h2 { font-size: 24px; color: #059669; margin-bottom: 8px; }
.success-page p { font-size: 16px; color: #6b7280; margin-bottom: 32px; }
