/* ===== Design tokens ===== */
:root {
  --bg: #F5F3EE;
  --surface: #FFFFFF;
  --surface-2: #F8F7F3;
  --ink: #171A18;
  --muted: #686D70;
  --line: #DDD7CB;
  --brand: #123D35;
  --brand-ink: #09251F;
  --accent: #A77A2D;
  --accent-soft: #F1E5CC;
  --cool: #355B7A;
  --warn: #A23E2A;
  --error-bg: #FCEEE8;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(18, 24, 21, .08), 0 14px 32px rgba(18, 24, 21, .10);
  --tabbar-h: 64px;
  --header-h: 56px;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

/* ===== Header ===== */
.app-header {
  position: sticky; top: 0; z-index: 10;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.app-header h1 { font-size: 1.18rem; margin: 0; font-weight: 750; }
.header-actions { display: flex; gap: 4px; }
.icon-btn {
  border: 0; background: transparent; color: var(--ink);
  font-size: 1rem; padding: 8px 10px; cursor: pointer; border-radius: var(--radius);
}
.icon-btn:hover { background: var(--surface-2); }

/* ===== Views ===== */
.view { display: none; padding: 16px; }
.view.active { display: block; }
h2 { margin: 0 0 8px; font-size: 1.25rem; }
.small { font-size: .8rem; }

/* ===== Filters ===== */
.filters { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.location-search {
  flex: 1 1 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}
.filters input, .filters select {
  flex: 1 1 140px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); font-size: .95rem;
  box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
}
.location-search input { min-width: 0; }
.location-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  padding-inline: 10px;
}
#data-meta {
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}
#data-meta span:not(:last-child)::after { content: " ·"; }
.data-caveat { color: var(--warn); }

/* ===== Card list ===== */
.card-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card img { width: 100%; height: 160px; object-fit: cover; display: block; }
.card-body { padding: 14px; cursor: pointer; }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card h3 { margin: 0 0 4px; font-size: 1.02rem; line-height: 1.25; flex: 1; font-weight: 750; }
.card .meta { font-size: .85rem; color: var(--muted); }
.card p { margin: 8px 0 0; font-size: .9rem; }
.card .chips { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.src-badge {
  font-size: .72rem; padding: 3px 8px; border-radius: 999px;
  background: var(--accent-soft); color: #5E4316; white-space: nowrap;
  border: 1px solid #DEC78F;
}
.chip {
  font-size: .75rem; padding: 3px 8px; border-radius: 999px;
  background: #EAF0ED; color: var(--brand-ink); border: 1px solid #CCDAD2;
}
.card .actions { display: flex; gap: 8px; padding: 0 14px 14px; flex-wrap: wrap; }
.address-link {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand);
  font: inherit;
  font-size: .85rem;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
}
.map-choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0 14px 12px;
}
.map-choices[hidden] { display: none; }
.sale-details {
  margin: 0 14px 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.sale-details[hidden] { display: none; }
.detail-copy {
  display: grid;
  gap: 2px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: .82rem;
}
.detail-copy strong { color: var(--ink); font-size: .9rem; }
.sale-details iframe {
  width: 100%;
  height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.btn {
  flex: 1 1 auto; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  font-size: .9rem; cursor: pointer; text-align: center; text-decoration: none;
  min-width: 44px;
  font-weight: 650;
}
.btn.ghost { background: transparent; color: var(--brand); }
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== Empty / error / loading states ===== */
.muted { color: var(--muted); }
.empty, .error {
  padding: 24px; text-align: center; border-radius: var(--radius);
  background: var(--surface); border: 1px dashed var(--line);
}
.error { background: var(--error-bg); border-color: var(--warn); color: var(--warn); }
.empty p, .error p { margin: 0 0 8px; }

/* ===== Map ===== */
#map { height: calc(100vh - var(--header-h) - var(--tabbar-h) - 32px); border-radius: var(--radius); }

/* ===== Identify ===== */
.upload {
  display: block; text-align: center; padding: 40px 16px;
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; color: var(--brand);
  box-shadow: var(--shadow);
}
.preview { max-width: 100%; border-radius: var(--radius); margin-top: 12px; }
.result { margin-top: 16px; }
.result-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.result-list li {
  padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; justify-content: space-between; align-items: center;
}

/* ===== Tabbar ===== */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: rgba(255, 255, 255, .94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.tab {
  border: 0; background: transparent; color: var(--muted);
  font-size: .85rem; cursor: pointer;
}
.tab.active { color: var(--brand); font-weight: 600; }

@media (max-width: 520px) {
  .location-search { grid-template-columns: 1fr; }
  .map-choices { grid-template-columns: 1fr; }
}
