/* Parcel Detail Page — reuses dashboard CSS variables */

:root {
  --blue: #1e3a5f;
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-600: #2563eb;
  --light-blue: #d4e6f1;
  --gray: #f8f9fa;
  --border: #e2e8f0;
  --text: #2c3e50;
  --muted: #475569;
  --muted-light: #64748b;
  --red: #922b21;
  --light-red: #fadbd8;
  --green: #1e8449;
  --light-green: #d5f5e3;
  --white: #fff;
  --gold: #b7950b;
  --light-gold: #fef9e7;
  --purple: #6c3483;
  --light-purple: #e8daef;
  --page-bg: #f1f3f5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  line-height: 1.5;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background: var(--page-bg);
}

/* Back link */
.back-link {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--blue-600);
  text-decoration: none;
  margin-bottom: 12px;
}
.back-link:hover { text-decoration: underline; }

/* Page header */
.parcel-header {
  margin-bottom: 20px;
}
.parcel-header-top {
  display: flex;
  align-items: center;
  gap: 12px;
}
.parcel-header h1 {
  font-size: 1.5rem;
  color: var(--text);
  margin-bottom: 4px;
}
.parcel-header .subtitle {
  font-size: 0.9rem;
  color: var(--muted);
}

/* Header action buttons */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.watchlist-star {
  background: none;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  padding: 4px 8px;
  color: var(--muted);
  transition: all 0.15s;
}
.watchlist-star:hover {
  border-color: var(--gold);
  color: var(--gold);
}
.watchlist-star.active {
  color: var(--gold);
  border-color: var(--gold);
  background: var(--light-gold);
}
.btn-pdf {
  display: inline-block;
  padding: 5px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--blue);
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-pdf:hover {
  border-color: var(--blue-600);
  background: var(--blue-50);
}
.btn-deal-memo {
  color: var(--white);
  background: var(--blue);
  border-color: var(--blue);
}
.btn-deal-memo:hover {
  background: var(--blue-600);
  border-color: var(--blue-600);
}
.btn-appeal {
  color: #b91c1c;
  border-color: #b91c1c;
}
.btn-appeal:hover {
  color: var(--white);
  background: #b91c1c;
  border-color: #b91c1c;
}
.btn-story-gen {
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--white);
  background: var(--blue-600);
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-story-gen:hover { opacity: 0.85; }
.btn-story-gen:disabled { opacity: 0.5; cursor: default; }
.story-empty {
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
  padding: 8px 0;
}
.story-loading {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}
.story-text p {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 12px;
}
.story-text p:last-child { margin-bottom: 0; }

/* Two-column grid */
.top-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

/* Cards */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  overflow: hidden;
}
.card-header {
  background: var(--blue);
  color: #fff;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 600;
}
.card-body {
  padding: 16px;
}

/* Info grid */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 20px;
}
.info-item {}
.info-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.info-value {
  font-size: 0.88rem;
  color: var(--text);
  word-break: break-word;
}
.info-full {
  grid-column: 1 / -1;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--light-green); color: var(--green); }
.badge-red { background: var(--light-red); color: var(--red); }
.badge-gold { background: var(--light-gold); color: var(--gold); }
.badge-blue { background: var(--light-blue); color: var(--blue); }
.badge-purple { background: var(--light-purple); color: var(--purple); }
.badge-gray { background: #f2f3f4; color: var(--muted); }

/* Map */
#parcelMap {
  height: 350px;
  min-height: 250px;
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.data-table th {
  background: var(--blue);
  color: #fff;
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: nowrap;
}
.data-table td.wrap { white-space: normal; max-width: 280px; }
.data-table tr:hover td { background: #e8f0fe; }
.data-table tr:nth-child(even) td { background: #f4f6f8; }
.data-table tr:nth-child(even):hover td { background: #e8f0fe; }
.data-table .amt { text-align: right; font-variant-numeric: tabular-nums; }

/* Tags (same as dashboard) */
.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
}
.tag-permits { background: var(--light-blue); color: var(--blue); }
.tag-planning { background: var(--light-purple); color: var(--purple); }
.tag-sales { background: var(--light-gold); color: var(--gold); }
.tag-sheriff { background: var(--light-red); color: var(--red); }

.tag-dev { background: #d1f2eb; color: #0e6655; }

/* Loading / error */
.loading {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.error-msg {
  text-align: center;
  padding: 48px 24px;
  color: var(--red);
}
.spinner-sm {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty { color: var(--muted); font-size: 0.85rem; padding: 16px; text-align: center; }

/* Notes card */
#notesText {
  width: 100%;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
}
#notesText:focus { border-color: var(--blue-600); }
.notes-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.notes-saved-msg {
  font-size: 0.75rem;
  color: var(--green);
  min-height: 1em;
}
.notes-clear-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
}
.notes-clear-btn:hover { border-color: var(--red); color: var(--red); }

/* Similar parcels grid */
.similar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.similar-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: all 0.15s;
}
.similar-card:hover { border-color: var(--blue-600); background: var(--blue-50); }
.similar-card-type { font-size: 0.68rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.similar-card-addr { font-size: 0.83rem; font-weight: 600; color: var(--text); margin: 3px 0 2px; line-height: 1.3; }
.similar-card-meta { font-size: 0.75rem; color: var(--muted-light); }

/* Trend chart canvas */
#trendCanvas { max-height: 260px; }

/* Share button */
.btn-share {
  display: inline-block;
  padding: 5px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--blue);
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-share:hover {
  border-color: var(--blue-600);
  background: var(--blue-50);
}

/* Score badges (header) */
.score-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.score-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}
.score-badge-opp {
  background: var(--light-green);
  color: var(--green);
}
.score-badge-distress {
  background: var(--light-red);
  color: var(--red);
}

/* Visual Timeline */
.timeline {
  position: relative;
  padding: 16px 16px 16px 0;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 89px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-year {
  position: relative;
  padding: 8px 0 4px 108px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--blue);
}
.timeline-year span {
  background: var(--page-bg);
  padding: 0 8px;
  position: relative;
  z-index: 1;
}
.timeline-year::after {
  content: "";
  position: absolute;
  left: 70px;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--border);
}
.timeline-item {
  display: flex;
  align-items: flex-start;
  gap: 0;
  padding: 6px 0;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.1s;
}
.timeline-item:hover {
  background: var(--blue-50);
}
.timeline-date {
  width: 76px;
  flex-shrink: 0;
  text-align: right;
  padding-right: 12px;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}
.timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
  margin-right: 12px;
  position: relative;
  z-index: 1;
  border: 2px solid var(--white);
  box-shadow: 0 0 0 1px var(--border);
}
.dot-permits { background: var(--blue-600); }
.dot-dev { background: #0e6655; }
.dot-planning { background: var(--purple); }
.dot-sales { background: var(--gold); }
.dot-sheriff { background: var(--red); }
.dot-default { background: var(--muted-light); }
.timeline-content {
  flex: 1;
  min-width: 0;
}
.timeline-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.timeline-title {
  font-size: 0.82rem;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.timeline-amount {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}
.timeline-detail {
  display: none;
  margin-top: 4px;
  padding: 6px 0 2px;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.timeline-item.expanded .timeline-detail {
  display: block;
}

/* Ownership Chain */
.ownership-chain {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.ownership-transfer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.ownership-transfer:last-child {
  border-bottom: none;
}
.ownership-date {
  width: 80px;
  flex-shrink: 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ownership-parties {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.ownership-party {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ownership-arrow {
  color: var(--muted-light);
  font-size: 1rem;
  flex-shrink: 0;
}
.ownership-price {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Responsive */
@media (max-width: 768px) {
  .top-grid {
    grid-template-columns: 1fr;
  }
  .info-grid {
    grid-template-columns: 1fr;
  }
  body { padding: 12px; }
  .parcel-header h1 { font-size: 1.2rem; }
  .parcel-header-top { flex-wrap: wrap; }
  .timeline::before { left: 49px; }
  .timeline-date { width: 40px; font-size: 0.72rem; padding-right: 8px; }
  .timeline-year { padding-left: 68px; }
  .timeline-year::after { left: 30px; }
  .ownership-transfer { flex-wrap: wrap; }
  .ownership-parties { flex-wrap: wrap; }
}

/* Comp similarity score bars */
.score-bar {
  display: inline-block;
  min-width: 28px;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.82em;
  font-weight: 600;
  color: #fff;
  text-align: center;
  cursor: help;
}
.score-high { background: var(--green); }
.score-mid  { background: var(--gold); }
.score-low  { background: var(--red); }

/* AI similarity match badge on Similar Properties cards */
.similar-card-score {
  font-size: 11px;
  font-weight: 600;
  color: #2e7d32;
  background: #e8f5e9;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 6px;
  white-space: nowrap;
}
