:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --surface: #ffffff;
  --text: #0f172a;
  --text-soft: #475569;
  --muted: #94a3b8;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-text: #ffffff;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: #f1f5f9;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: var(--bg);
  color: #f8fafc;
  padding: calc(var(--safe-top) + 14px) 18px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.install-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.container {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 18px calc(28px + var(--safe-bottom));
  position: relative;
}

.step {
  display: none;
  animation: fade 220ms ease;
}
.step.active {
  display: block;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.hint {
  color: var(--text-soft);
  font-size: 15px;
  line-height: 1.4;
  margin: 0 0 22px;
}

/* Capture button */
.capture-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  aspect-ratio: 1.6 / 1;
  background: var(--primary);
  color: var(--primary-text);
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.06s ease, background 0.15s ease;
  user-select: none;
}

.capture-button:active {
  transform: scale(0.985);
  background: var(--primary-hover);
}

/* Preview */
.preview-wrap {
  width: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.preview-wrap img {
  width: 100%;
  height: auto;
  max-height: 60vh;
  object-fit: contain;
  display: block;
}

/* Actions */
.actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  border: 0;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50px;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn-primary:active {
  background: var(--primary-hover);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

/* Form */
h2 {
  font-size: 18px;
  margin: 4px 0 16px;
}

#leadForm {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}

#leadForm label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--text-soft);
}

#leadForm label.full {
  grid-column: 1 / -1;
}

#leadForm input,
#leadForm textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px; /* >=16px prevents iOS zoom on focus */
  color: var(--text);
  background: #fff;
  font-family: inherit;
}

#leadForm input:focus,
#leadForm textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: transparent;
}

#leadForm textarea {
  resize: vertical;
}

.raw-text {
  font-size: 13px;
  color: var(--text-soft);
}

.raw-text summary {
  cursor: pointer;
  padding: 6px 0;
}

.raw-text pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin: 6px 0 0;
  font-size: 12px;
  max-height: 160px;
  overflow: auto;
}

/* Spinner */
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.btn-secondary .spinner {
  border-color: rgba(15, 23, 42, 0.2);
  border-top-color: var(--text);
}

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

/* Success */
.success-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  color: var(--success);
}

.success-card h2 {
  color: var(--text);
  margin-top: 14px;
}

.success-card p {
  color: var(--text-soft);
  margin: 6px 0 22px;
}

.success-card .btn-primary {
  width: 100%;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--bg);
  color: #f8fafc;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.25);
  z-index: 100;
  max-width: calc(100% - 36px);
  text-align: center;
}

.toast.danger {
  background: var(--danger);
}
