:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --panel: #ffffff;
  --ink: #1d2528;
  --muted: #687276;
  --line: #d8dedb;
  --line-strong: #aeb9b5;
  --accent: #0b6f74;
  --accent-soft: #e0f0ef;
  --warn: #8a4b00;
  --amber: #c98a1a;      /* mid-band mark: map circles + legend swatch */
  --amber-ink: #a06a10;  /* same hue, darkened to 4.6:1 on white for text */
  --good: #17633c;
  --bad: #9b2c2c;
  --select: #d100d1;
  --select-soft: #ffe4ff;
  --shadow: 0 12px 30px rgba(25, 37, 38, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

button,
input {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 24px 10px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.15;
}

h2 {
  font-size: 19px;
}

.header-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-meta span,
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 8px 11px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.workbench {
  --left: 66%;
  display: grid;
  grid-template-columns: minmax(520px, var(--left)) 10px minmax(390px, 1fr);
  height: calc(100vh - 184px);
  min-height: 620px;
  padding: 0 32px 32px;
}

.table-pane,
.detail-pane {
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.table-pane {
  border-radius: 8px 0 0 8px;
}

.detail-pane {
  border-radius: 0 8px 8px 0;
  overflow-y: auto;
}

.splitter {
  cursor: col-resize;
  background: linear-gradient(90deg, transparent 0, transparent 3px, var(--line-strong) 3px, var(--line-strong) 7px, transparent 7px);
}

.pane-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex: 0 0 auto;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.pane-toolbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

#searchBox {
  width: min(360px, 42%);
  min-width: 260px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfa;
}

.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef3ef;
  color: #2c383b;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

th.sorted::after {
  content: " " attr(data-direction);
  color: var(--accent);
}

td {
  font-size: 15px;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: var(--accent-soft);
}

tbody tr.selected {
  background: var(--select-soft);
  box-shadow: inset 5px 0 0 var(--select);
}

tbody tr.sold-over-list {
  box-shadow: inset 4px 0 0 var(--good);
}

tbody tr.sold-over-list:hover {
  background: #e4f2ea;
}

tbody tr.sold-over-list.selected {
  background: var(--select-soft);
  box-shadow: inset 5px 0 0 var(--select);
}

.sold-over-list-cell {
  color: var(--good);
  font-weight: 900;
}

.over-list-note {
  margin-top: 2px;
  color: var(--good);
  font-size: 12px;
  font-weight: 800;
}

.address-cell {
  min-width: 210px;
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.fee-rate {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

/* Seller's view: selling ABOVE assessment is the good outcome (green), BELOW is
   the bad one (red). A buyer's CMA would invert these. */
.ratio-over {
  color: var(--good);
  font-weight: 800;
}

/* Not --warn: that brown reads as plain ink next to --ink and the amber
   vanishes. This is the legend/map amber, darkened to pass as text. */
.ratio-near {
  color: var(--amber-ink);
  font-weight: 800;
}

.ratio-under {
  color: var(--bad);
  font-weight: 800;
}

.detail {
  padding: 18px;
}

.detail-hero {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 18px;
  align-items: start;
}

.detail-hero img {
  width: 190px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #e9ece8;
}

.detail-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.detail-title h2 {
  font-size: 24px;
  line-height: 1.2;
}

.detail-title p {
  margin-top: 4px;
  color: var(--muted);
}

.price-block {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.fact {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.fact span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.fact strong {
  display: block;
  margin-top: 5px;
  font-size: 19px;
}

.detail-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.detail-section h3 {
  margin-bottom: 10px;
  font-size: 17px;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.description {
  color: #2f393c;
  line-height: 1.5;
}

.field-note {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.map-link {
  display: inline-flex;
  margin-top: 10px;
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

@media (max-width: 1100px) {
  .app-header {
    padding-left: 18px;
    padding-right: 18px;
  }

  .app-header {
    align-items: start;
    flex-direction: column;
  }

  .workbench {
    display: block;
    height: auto;
    min-height: 0;
    padding: 0 18px 18px;
  }

  .table-pane,
  .detail-pane {
    border-radius: 8px;
  }

  .detail-pane {
    margin-top: 14px;
  }

  .splitter {
    display: none;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 15px;
  }

  .pane-toolbar,
  .detail-hero,
  .price-block,
  .fact-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  #searchBox {
    width: 100%;
    min-width: 0;
  }

  .detail-hero img {
    width: 100%;
  }
}

/* ---- subject banner ---- */
.subject {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 0 24px 10px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #ffffff, var(--accent-soft));
  border: 1px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.subject-mark {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 7px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.subject-body { flex: 1 1 320px; }
.subject-body h2 { font-size: 18px; }
.subject-body h2 span { color: var(--muted); font-weight: 600; font-size: 15px; }
.subject-body p { margin-top: 3px; color: var(--muted); font-size: 13.5px; }
.subject-figures { display: flex; gap: 16px; flex-wrap: wrap; }
.subject-figures span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.02em; }
.subject-figures strong { display: block; margin-top: 2px; font-size: 18px; }

/* ---- map ---- */
.map-section { margin: 0 32px 18px; position: relative; }
#map {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content: ""; width: 11px; height: 11px; border-radius: 50%; }
.lg-over::before { background: #17633c; }
.lg-near::before { background: var(--amber); }
.lg-under::before { background: #9b2c2c; }
.lg-subject { color: #b8860b; }
.lg-subject::before { content: none; }
.lg-note { color: var(--muted); font-weight: 600; }
.subject-pin {
  color: #f4b400;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  text-shadow: 0 0 3px #7a5a00, 0 1px 3px rgba(0, 0, 0, 0.5);
}
.maplibregl-popup-content { font-size: 13px; padding: 8px 11px; border-radius: 8px; }

/* ---- misc ---- */
.photo-fallback {
  width: 190px;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  border: 1px dashed var(--line-strong);
  background: #eef3ef;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}
.chip-subject { background: var(--accent); color: #fff; border-color: var(--accent); }
.workbench { height: 560px; min-height: 520px; }
.app-footer { display: none; }
.app-footer p { color: var(--muted); font-size: 12.5px; line-height: 1.5; max-width: 900px; }

@media (max-width: 1100px) {
  .subject, .map-section, .app-footer, .version-bar { margin-left: 18px; margin-right: 18px; padding-left: 18px; padding-right: 18px; }
  .map-section { padding-left: 0; padding-right: 0; }
  .workbench { height: auto; }
}

/* ---- four-pane workspace ---- */
.quad-workbench {
  --left: 50%;
  --top: 62%;
  display: grid;
  grid-template-columns: minmax(360px, var(--left)) 10px minmax(360px, 1fr);
  grid-template-rows: minmax(0, var(--top)) 10px minmax(0, 1fr);
  grid-template-areas:
    "map splitv viz"
    "splith splith splith"
    "table splitv2 detail";
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 0 24px 16px;
}

.panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.map-pane {
  grid-area: map;
  border-radius: 8px 0 0 0;
}

.viz-pane {
  grid-area: viz;
  border-radius: 0 8px 0 0;
}

.table-pane {
  grid-area: table;
  border-radius: 0 0 0 8px;
}

.detail-pane {
  grid-area: detail;
  border-radius: 0 0 8px 0;
  overflow: auto;
}

.splitter-v {
  grid-column: 2;
  grid-row: 1 / 4;
  cursor: col-resize;
  background: linear-gradient(90deg, transparent 0, transparent 3px, var(--line-strong) 3px, var(--line-strong) 7px, transparent 7px);
}

.splitter-h {
  grid-area: splith;
  cursor: row-resize;
  background: linear-gradient(180deg, transparent 0, transparent 3px, var(--line-strong) 3px, var(--line-strong) 7px, transparent 7px);
}

.pane-toolbar.compact {
  min-height: 60px;
  padding: 10px 14px;
}

.map-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.viz-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 10px 14px 14px;
  overflow: auto;
}

.viz-body.single {
  display: block;
}

.viz-chart {
  width: 100%;
  height: 100%;
  min-height: 340px;
  background: transparent;
  overflow: hidden;
}

.viz-chart svg {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-title {
  font-size: 15px;
  font-weight: 800;
  fill: var(--ink);
}

.chart-label {
  font-size: 12px;
  font-weight: 700;
  fill: var(--muted);
}

.chart-axis,
.chart-grid {
  stroke: #cfd7d3;
  stroke-width: 1;
}

.chart-grid {
  stroke-dasharray: 3 4;
}

.viz-chart circle {
  cursor: pointer;
  stroke: #ffffff;
  stroke-width: 1.5;
}

.viz-chart circle.chart-selected {
  fill: var(--select);
  stroke: #ffffff;
  stroke-width: 4;
}

.visual-answer {
  display: grid;
  gap: 3px;
  padding: 9px 14px 10px;
  border-bottom: 1px solid var(--line);
  background: #f7faf8;
  font-size: 13px;
  line-height: 1.35;
}

.visual-answer strong {
  color: var(--ink);
  font-weight: 800;
}

.visual-answer span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.visual-options {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.visual-options[hidden] {
  display: none;
}

.representation-switch {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.representation-switch button {
  border: 0;
  background: transparent;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.representation-switch button + button {
  border-left: 1px solid var(--line-strong);
}

.representation-switch button.active {
  background: var(--accent);
  color: #fff;
}

.story-lane {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.story-range {
  stroke: #aeb9b5;
  stroke-width: 10;
  stroke-linecap: round;
  opacity: 0.7;
}

.story-median-line {
  stroke: var(--ink);
  stroke-width: 3;
}

.story-median-label,
.story-value,
.assessment-label {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.assessment-line {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 4;
}

.story-sold-median {
  fill: var(--ink);
  stroke: #fff;
  stroke-width: 2;
}

.story-active-median {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 2;
}

.floor-selected {
  fill: var(--select);
  stroke: #fff;
  stroke-width: 4;
  pointer-events: none;
}

.sold-at-list-line {
  stroke: var(--line-strong);
  stroke-width: 2;
  stroke-dasharray: 6 5;
}

.typical-close-line {
  stroke: var(--accent);
  stroke-width: 3;
}

.dom-fast-band {
  fill: var(--accent-soft);
  opacity: 0.62;
}

.dom-fast-label {
  fill: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.dom-median {
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linecap: round;
}

.fee-lower-band {
  fill: var(--accent-soft);
  opacity: 0.42;
}

.fee-higher-band {
  fill: #f1f4f2;
  opacity: 0.72;
}

.fee-split-line {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 5;
}

.fee-split-label {
  fill: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.fee-dom-median {
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linecap: round;
}

.viz-chart circle.fee-point:not(.chart-selected) {
  fill: #376f78;
}

.representation-name {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.representation-range {
  stroke: #aeb9b5;
  stroke-width: 5;
  stroke-linecap: round;
}

.representation-median {
  stroke: var(--ink);
  stroke-width: 3;
}

.viz-chart circle.representation-point:not(.chart-selected) {
  fill: #376f78;
}

.viz-chart .selection-ring {
  fill: none;
  stroke: var(--select);
  stroke-width: 4;
  pointer-events: none;
}

.viz-chart .ratio-over {
  fill: #17633c;
}

.viz-chart .ratio-near,
.viz-chart .ratio-mid {
  fill: var(--amber);
}

.viz-chart .ratio-under {
  fill: #9b2c2c;
}

.viz-chart .bar-over {
  fill: rgba(23, 99, 60, 0.34);
  stroke: #17633c;
}

.viz-chart .bar-under {
  fill: rgba(155, 44, 44, 0.28);
  stroke: #9b2c2c;
}

.viz-chart .bar-selected {
  fill: var(--select-soft);
  stroke: var(--select);
  stroke-width: 4;
}

.tick-label {
  font-size: 11px;
}

.viz-toolbar {
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

.viz-toolbar > div:first-child {
  flex: 1 1 112px;
  min-width: 0;
}

.viz-tabs {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
  flex: none;
}

.viz-tabs button {
  border: 0;
  background: transparent;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.viz-tabs button + button {
  border-left: 1px solid var(--line-strong);
}

.viz-tabs button.active {
  background: var(--accent);
  color: #fff;
}

.time-control {
  display: grid;
  gap: 4px;
  min-width: 145px;
  flex: 0 0 145px;
}

.time-control label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.time-control strong {
  color: var(--ink);
}

#timeSlider {
  width: 100%;
  accent-color: var(--accent);
}

.viz-pane {
  container-type: inline-size;
}

@container (max-width: 720px) {
  .viz-toolbar {
    flex-wrap: wrap;
  }

  .viz-toolbar > div:first-child {
    flex: 1 1 auto;
  }

  .viz-tabs {
    order: 3;
    width: 100%;
  }

  .viz-tabs button {
    flex: 1 1 16.666%;
    min-width: 0;
    padding: 7px 5px;
    font-size: 12px;
  }

  .visual-options {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

.empty-chart {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 800;
}

/* ---- data-version switch (Original CMA vs Updated) ---- */
.version-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 0 32px 14px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.version-switch {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
  flex: none;
}

.version-switch button {
  border: 0;
  background: transparent;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 800;
  color: var(--muted);
  cursor: pointer;
}

.version-switch button + button {
  border-left: 1px solid var(--line-strong);
}

.version-switch button:hover {
  background: var(--accent-soft);
  color: var(--ink);
}

.version-switch button.active {
  background: var(--accent);
  color: #fff;
}

.version-switch button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.version-note {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
  flex: 1 1 340px;
  min-width: 0;
}

.version-note strong { color: var(--ink); }

.version-warn {
  display: block;
  margin-top: 3px;
  color: var(--warn);
  font-weight: 700;
}

@media (max-width: 1180px) {
  body {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .quad-workbench {
    display: block;
    height: auto;
    min-height: 0;
    padding: 0 18px 22px;
  }

  .panel {
    border-radius: 8px;
    margin-bottom: 14px;
  }

  .map-pane,
  .viz-pane {
    height: 480px;
  }

  .table-pane {
    height: 520px;
  }

  .detail-pane {
    max-height: none;
  }

  .splitter-v,
  .splitter-h {
    display: none;
  }
}

.assess-note {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
  font-style: normal;
  font-weight: 600;
}
