/* ── 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); } }
