/* ── CSS custom properties (shadcn-inspired, space-separated HSL) ── */
:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 71% 45%;
  --success-foreground: 0 0% 98%;
  --warning: 38 92% 50%;
  --warning-foreground: 240 5.9% 10%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;
}

.dark {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 3.9%;
  --card-foreground: 0 0% 98%;
  --popover: 240 10% 3.9%;
  --popover-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;
}

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
               Ubuntu, Cantarell, sans-serif;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.5;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  background-color: hsl(var(--background));
  position: sticky;
  top: 0;
  z-index: 10;
}

header .brand {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
  color: hsl(var(--foreground));
}

header .header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

main {
  flex: 1;
  padding: 1rem;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 44px;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.15s, background-color 0.15s;
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) { opacity: 0.9; }

.btn-secondary {
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--border));
}

.btn-secondary:hover:not(:disabled) { opacity: 0.8; }

.btn-destructive {
  background-color: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
}

.btn-destructive:hover:not(:disabled) { opacity: 0.9; }

.btn-ghost {
  background-color: transparent;
  color: hsl(var(--foreground));
  padding: 0.5rem;
  height: 44px;
  width: 44px;
}

.btn-ghost:hover:not(:disabled) {
  background-color: hsl(var(--accent));
}

.btn-sm {
  height: 36px;
  padding: 0.25rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-full { width: 100%; }

/* ── Cards ── */
.card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 1rem;
}

@media (min-width: 480px) {
  .card { padding: 1.5rem; }
}

.card-header { margin-bottom: 1rem; }
.card-title { font-size: 1.125rem; font-weight: 600; }
.card-description { font-size: 0.875rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }

/* ── Form elements ── */
.form-group { display: flex; flex-direction: column; gap: 0.375rem; }

label {
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--foreground));
}

.input {
  height: 44px;
  padding: 0 0.75rem;
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  transition: box-shadow 0.15s;
  outline: none;
}

.input:focus {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2);
}

textarea.input {
  height: auto;
  min-height: 80px;
  padding: 0.5rem 0.75rem;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
}

.form-stack { display: flex; flex-direction: column; gap: 1rem; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
}

.badge-muted {
  background-color: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
}

.badge-warning {
  background-color: hsl(var(--warning) / 0.15);
  color: hsl(var(--warning));
  border: 1px solid hsl(var(--warning) / 0.3);
}

.badge-success {
  background-color: hsl(var(--success) / 0.15);
  color: hsl(var(--success));
  border: 1px solid hsl(var(--success) / 0.3);
}

/* ── Toast notifications ── */
#toast-container {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  width: calc(100% - 2rem);
  max-width: 400px;
}

.toast {
  background-color: hsl(var(--foreground));
  color: hsl(var(--background));
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  animation: toast-in 0.2s ease;
  pointer-events: auto;
}

.toast-error {
  background-color: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(0.5rem); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Lead list ── */
.leads-list { display: flex; flex-direction: column; gap: 0.75rem; }

.lead-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.lead-card:hover { opacity: 0.8; }

.lead-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.lead-address {
  font-weight: 500;
  font-size: 0.9375rem;
}

.lead-meta {
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}

/* ── Detail view ── */
.detail-section {
  margin-top: 1.25rem;
}

.detail-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  margin-bottom: 0.75rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
}

.detail-item-label {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.detail-item-value {
  font-size: 0.9375rem;
  font-weight: 500;
  margin-top: 0.125rem;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* ── Photo grid ── */
.photos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.photos-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
}

/* ── Auth screens ── */
.auth-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 3rem;
}

.auth-card {
  width: 100%;
  max-width: 360px;
}

.auth-footer {
  text-align: center;
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
  margin-top: 1rem;
}

.auth-footer a {
  color: hsl(var(--foreground));
  text-decoration: underline;
  cursor: pointer;
}

/* ── Utilities ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

.text-muted { color: hsl(var(--muted-foreground)); font-size: 0.875rem; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }

.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: hsl(var(--muted-foreground));
}

.empty-state-title { font-weight: 500; font-size: 1rem; }
.empty-state-desc { font-size: 0.875rem; margin-top: 0.375rem; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.page-title { font-size: 1.25rem; font-weight: 700; }

.divider {
  height: 1px;
  background-color: hsl(var(--border));
  margin: 1rem 0;
}

/* ── Analysis result cards ── */
.result-card {
  background-color: hsl(var(--secondary));
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 0.75rem;
}

.result-label { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.result-value { font-size: 1.5rem; font-weight: 700; margin-top: 0.25rem; }
.result-value-sm { font-size: 1rem; font-weight: 600; margin-top: 0.125rem; }

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid hsl(var(--border));
}

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

/* ── Loading spinner ── */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ── Tab bar ── */
.tab-bar { display: flex; border-bottom: 1px solid hsl(var(--border)); background: hsl(var(--card)); }
.tab-btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; color: hsl(var(--muted-foreground)); font-size: 11px; font-family: inherit; transition: color 0.15s, border-color 0.15s; }
.tab-btn svg { flex-shrink: 0; }
.tab-btn.active { color: hsl(var(--primary)); border-bottom-color: hsl(var(--primary)); }
.tab-content { padding: 16px; }

/* ── Next-step callout ── */
.next-step-callout { display: flex; align-items: flex-start; gap: 10px; padding: 14px; border: 1.5px solid hsl(142 71% 45%); border-radius: var(--radius); background: hsl(142 71% 8%); color: hsl(var(--foreground)); font-size: 14px; margin-bottom: 16px; }
.next-step-callout svg { flex-shrink: 0; margin-top: 2px; color: hsl(142 71% 55%); }

/* ── Photo action row ── */
.photo-action-row { display: flex; gap: 8px; margin-bottom: 16px; }
.photo-action-row .btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); cursor: pointer; }
.photo-add-slot { aspect-ratio: 1; border: 2px dashed hsl(var(--border)); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; color: hsl(var(--muted-foreground)); cursor: pointer; }

/* ── Setup checklist ── */
.setup-screen { max-width: 480px; margin: 0 auto; padding: 24px 16px; }
.setup-screen h2 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.setup-screen .subtitle { color: hsl(var(--muted-foreground)); margin-bottom: 24px; font-size: 14px; }
.setup-checklist { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.setup-item { display: flex; align-items: flex-start; gap: 12px; padding: 14px; background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius); }
.setup-checkbox { width: 20px; height: 20px; border-radius: 4px; border: 2px solid hsl(var(--border)); flex-shrink: 0; display: flex; align-items: center; justify-content: center; margin-top: 1px; transition: background 0.15s, border-color 0.15s; }
.setup-checkbox.checked { background: hsl(142 71% 45%); border-color: hsl(142 71% 45%); color: #fff; }
.setup-item.done .setup-label { color: hsl(var(--muted-foreground)); text-decoration: line-through; }
.setup-label { font-size: 14px; font-weight: 500; }
.setup-sublabel { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 2px; }
.setup-skip { text-align: center; font-size: 13px; color: hsl(var(--muted-foreground)); }
.setup-skip a { color: hsl(var(--muted-foreground)); text-decoration: underline; cursor: pointer; }

/* ── Coupon card ── */
.coupon-card { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: hsl(var(--card)); border: 1px dashed hsl(142 71% 40%); border-radius: var(--radius); margin-top: 8px; font-size: 13px; }
.coupon-code { font-weight: 700; font-family: monospace; letter-spacing: 0.05em; color: hsl(142 71% 55%); }
.coupon-copy { font-size: 12px; cursor: pointer; color: hsl(var(--primary)); background: none; border: 1px solid hsl(var(--primary)); border-radius: 4px; padding: 3px 8px; }

/* ── RentCast source label ── */
.lookup-source { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 4px; font-style: italic; }

/* ── Stage progress ── */
.stage-progress { display: flex; align-items: center; margin-bottom: 20px; }
.stage-dot { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; }
.stage-dot-circle { width: 36px; height: 36px; border-radius: 50%; border: 2px solid hsl(var(--border)); display: flex; align-items: center; justify-content: center; color: hsl(var(--muted-foreground)); background: hsl(var(--card)); }
.stage-dot.active .stage-dot-circle { border-color: hsl(var(--primary)); color: hsl(var(--primary)); background: hsl(var(--primary) / 0.1); }
.stage-dot-label { font-size: 11px; color: hsl(var(--muted-foreground)); text-align: center; }
.stage-dot.active .stage-dot-label { color: hsl(var(--foreground)); font-weight: 600; }
.stage-connector { height: 2px; flex: 1; background: hsl(var(--border)); margin-bottom: 20px; }
.stage-context-note { font-size: 13px; color: hsl(var(--muted-foreground)); margin-bottom: 16px; padding: 10px 14px; background: hsl(var(--card)); border-radius: var(--radius); border: 1px solid hsl(var(--border)); }

/* ── Lead detail header ── */
.lead-header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; background: hsl(var(--card)); border-bottom: 1px solid hsl(var(--border)); position: sticky; top: 0; z-index: 10; }
.lead-header-back { display: flex; align-items: center; gap: 4px; color: hsl(var(--muted-foreground)); background: none; border: none; cursor: pointer; font-size: 13px; padding: 4px; }
.lead-header-center { flex: 1; min-width: 0; }
.lead-header-address { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-header-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Settings affiliate callout ── */
.affiliate-callout { font-size: 13px; color: hsl(var(--muted-foreground)); margin-top: 8px; }
.affiliate-callout a { color: hsl(var(--primary)); }

/* ── Result card ── */
.result-card { padding: 12px 14px; background: hsl(var(--muted)); border-radius: var(--radius); font-size: 14px; }
