:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #10151c;
  --ink-2: #55606e;
  --ink-3: #8b95a3;
  --line: #e2e6ec;
  --line-2: #eef1f5;
  --accent: #0b5cd5;
  --accent-soft: #e8f0fd;
  --up: #b42318;
  --up-soft: #fef3f2;
  --down: #067647;
  --down-soft: #ecfdf3;
  --new: #6941c6;
  --new-soft: #f4f3ff;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- header */
header {
  position: sticky; top: 0; z-index: 60;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.brand span { color: var(--ink-3); font-weight: 500; }
.tabs { display: flex; gap: 2px; background: var(--line-2); padding: 3px; border-radius: 8px; }
.tabs button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 6px;
  cursor: pointer; color: var(--ink-2); font-weight: 500;
}
.tabs button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.spacer { flex: 1; }
.stat { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.stat b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- filters */
.filters {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 10px 20px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  position: sticky; top: 57px; z-index: 55;
}
.filters input, .filters select {
  border: 1px solid var(--line); background: var(--panel); border-radius: 7px;
  padding: 6px 9px; min-width: 0;
}
.filters input:focus, .filters select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.filters input[type=search] { flex: 1 1 240px; }
.filters input.num { width: 92px; }
.chip {
  display: inline-block;               /* anchors styled as chips need a real box */
  border: 1px solid var(--line); background: var(--panel); border-radius: 7px;
  padding: 6px 11px; cursor: pointer; color: var(--ink-2);
  text-decoration: none; line-height: 1.3;
}
a.chip:hover { text-decoration: none; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ----------------------------------------------------------------- table */
main { padding: 16px 20px 60px; }
.tablewrap {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto;
}
table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1100px; }
th {
  position: sticky; top: 0; z-index: 10;
  background: var(--panel); border-bottom: 1px solid var(--line);
  text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600;
  color: var(--ink-2); white-space: nowrap; cursor: pointer; user-select: none;
}
th:hover { color: var(--accent); }
th .dir { color: var(--accent); font-size: 10px; }
th.no-sort { cursor: default; }
th.no-sort:hover { color: var(--ink-2); }
td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafbfd; }
tbody tr.open { background: var(--accent-soft); }
.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 13px; }
.muted { color: var(--ink-3); }
.title-cell { max-width: 320px; }
.title-cell .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-cell .s { color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thumb {
  width: 62px; height: 46px; border-radius: 6px; object-fit: cover;
  background: var(--line-2); display: block; border: 1px solid var(--line);
}
.thumb.ph { display: grid; place-items: center; color: var(--ink-3); font-size: 10px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  background: var(--line-2); color: var(--ink-2);
}
.tag.ccr { background: var(--new-soft); color: var(--new); }
.tag.rcr { background: var(--accent-soft); color: var(--accent); }
.tag.ocr { background: var(--down-soft); color: var(--down); }
.tag.NEW { background: var(--new-soft); color: var(--new); }
.tag.PRICE_UP { background: var(--up-soft); color: var(--up); }
.tag.PRICE_DOWN { background: var(--down-soft); color: var(--down); }
.tag.REMOVED { background: var(--line-2); color: var(--ink-2); }
.tag.RELISTED { background: var(--warn-soft); color: var(--warn); }
.tag.AGENT_CHANGE, .tag.AREA_CHANGE { background: var(--warn-soft); color: var(--warn); }
.tag.removed { background: var(--line-2); color: var(--ink-3); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 14px; color: var(--ink-2); }

/* ---------------------------------------------------------------- drawer */
.drawer-back {
  position: fixed; inset: 0; background: rgba(16,24,40,.35);
  z-index: 100; opacity: 0; pointer-events: none; transition: opacity .18s;
}
.drawer-back.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 96vw);
  background: var(--panel); z-index: 101; overflow-y: auto;
  transform: translateX(100%); transition: transform .22s cubic-bezier(.4,0,.2,1);
  box-shadow: -8px 0 40px rgba(16,24,40,.14);
}
.drawer.on { transform: none; }
.drawer header {
  position: sticky; top: 0; display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.drawer h2 { margin: 0 0 4px; font-size: 17px; letter-spacing: -.01em; }
.drawer .close {
  border: 1px solid var(--line); background: var(--panel); width: 30px; height: 30px;
  border-radius: 7px; cursor: pointer; font-size: 17px; line-height: 1; color: var(--ink-2);
}
.drawer .close:hover { border-color: var(--accent); color: var(--accent); }
.dsec { padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.dsec h3 {
  margin: 0 0 10px; font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-3);
}
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 18px; }
.kv div { min-width: 0; }
.kv dt { color: var(--ink-3); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.kv dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.desc { white-space: pre-wrap; color: var(--ink-2); max-height: 260px; overflow-y: auto; }

/* --------------------------------------------------- mini photo grid */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; }
.photos button {
  padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  cursor: zoom-in; background: var(--line-2); aspect-ratio: 4/3; position: relative;
}
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos button:hover { border-color: var(--accent); }
.photos button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------- lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 200; background: rgba(8,12,18,.94);
  display: none; grid-template-rows: auto 1fr auto;
}
.lightbox.on { display: grid; }
.lb-top { display: flex; align-items: center; gap: 14px; padding: 14px 18px; color: #e6eaf0; }
.lb-top .cap { flex: 1; font-size: 13px; color: #aab4c2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-top button, .lb-nav button {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18);
  color: #fff; border-radius: 8px; cursor: pointer; padding: 7px 12px;
}
.lb-top button:hover, .lb-nav button:hover { background: rgba(255,255,255,.2); }
.lb-stage { position: relative; display: grid; place-items: center; padding: 0 18px; min-height: 0; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.lb-nav { position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; pointer-events: none; }
.lb-nav button { pointer-events: auto; width: 44px; height: 60px; font-size: 20px; }
.lb-film { display: flex; gap: 8px; padding: 12px 18px; overflow-x: auto; }
.lb-film img {
  height: 58px; width: 78px; object-fit: cover; border-radius: 6px; cursor: pointer;
  opacity: .45; border: 2px solid transparent; flex: 0 0 auto;
}
.lb-film img.on { opacity: 1; border-color: #fff; }

.empty { padding: 60px 20px; text-align: center; color: var(--ink-3); }
.spin { padding: 40px; text-align: center; color: var(--ink-3); }

/* ------------------------------------------------------ WhatsApp co-broke */
a.wa {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 14px;
  background: #25d366; color: #08361b; border: 1px solid #1eb85a;
  padding: 9px 14px; border-radius: 8px; font-weight: 600; text-decoration: none;
}
a.wa:hover { background: #1eb85a; color: #fff; text-decoration: none; }
a.wa:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ link button */
a.btn-link {
  display: inline-block; padding: 4px 10px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid #cfe0fb; font-size: 11px; font-weight: 700;
  letter-spacing: .03em; text-decoration: none; white-space: nowrap;
}
a.btn-link:hover { background: var(--accent); color: #fff; border-color: var(--accent); text-decoration: none; }
a.btn-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a.btn-link.big { padding: 9px 14px; font-size: 13px; letter-spacing: 0; }

/* --------------------------------------------------------- row action pair */
.acts { display: inline-flex; align-items: center; gap: 6px; }
.btn-wa {
  display: inline-grid; place-items: center; width: 26px; height: 24px;
  border-radius: 6px; background: #25d366; color: #08361b;
  border: 1px solid #1eb85a; text-decoration: none;
}
.btn-wa:hover { background: #1eb85a; color: #fff; }
.btn-wa:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-wa.off { background: var(--line-2); color: var(--ink-3); border-color: var(--line); cursor: not-allowed; }

/* Keep the WhatsApp / LINK controls reachable on a wide table. */
table.pin-actions th:last-child,
table.pin-actions td:last-child {
  position: sticky; right: 0; z-index: 5;
  background: var(--panel);
  box-shadow: -8px 0 10px -8px rgba(16,24,40,.18);
}
table.pin-actions th:last-child { z-index: 12; }
table.pin-actions tbody tr:hover td:last-child { background: #fafbfd; }
table.pin-actions tbody tr.open td:last-child { background: var(--accent-soft); }

/* --------------------------------------------------------- duplicate badge */
.tag.dup { background: var(--warn-soft); color: var(--warn); }
.tag.dup.medium { background: var(--line-2); color: var(--ink-2); }

/* ------------------------------------------- multi-agent rows (co-broking) */
.agents { display: flex; flex-direction: column; gap: 4px; }
.agents .ag {
  height: 24px; display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px;
}
.agents .ag.acts { max-width: none; }

/* ------------------------------------------------------------- disclaimer */
header .disclaimer {
  flex: 1 1 340px;
  min-width: 260px;
  background: var(--warn-soft);
  border: 1px solid #fde68a;
  color: #7c4a03;
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 11.5px;
  line-height: 1.45;
}
header .disclaimer b { color: #6b3f02; }
@media (max-width: 900px) { header .disclaimer { flex-basis: 100%; } }
.tag.agency { background: var(--line-2); color: var(--ink-2); font-size: 10.5px; font-weight: 700; letter-spacing: .02em; }

/* ------------------------------------------------- market summary by district */
.district {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden;
}
.district .dhead { padding: 14px 18px; border-bottom: 1px solid var(--line-2); background: #fbfcfe; }
.district .dtitle { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.district .dcode { font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.district .dstats { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px 16px; }
.district .sub { padding: 12px 18px 16px; }
.district .sub h4 {
  margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-3);
}
.district .sub h4 .muted { text-transform: none; letter-spacing: 0; font-weight: 500; }
.filters select.needs-enrich { border-color: #fde68a; background: var(--warn-soft); }
