:root {
  color-scheme: light;
  --bg: #f5f2eb;
  --panel: #fffdfa;
  --text: #152225;
  --muted: #5e696c;
  --line: #d8d1c3;
  --accent: #0f766e;
  --accent-strong: #0b5d58;
  --accent-soft: #d9efeb;
  --gold: #b7791f;
  --red: #b42318;
  --green: #2f7d32;
  --map-water: #d7e8ec;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

/* Critical Leaflet layout fallback. The app also links Leaflet's CDN CSS, but
   the map must still render when that external stylesheet is blocked. */
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.leaflet-container {
  overflow: hidden;
  background: #d7e8ec;
  outline-offset: 1px;
  -webkit-tap-highlight-color: transparent;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  border: 0;
  visibility: hidden;
}

.leaflet-tile-loaded {
  visibility: inherit;
}

.leaflet-zoom-animated {
  transform-origin: 0 0;
}

.leaflet-interactive {
  cursor: pointer;
}

.leaflet-grab {
  cursor: grab;
}

.leaflet-dragging .leaflet-grab {
  cursor: move;
}

.leaflet-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  float: left;
  clear: both;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control-zoom {
  margin-top: 10px;
  margin-left: 10px;
  border: 1px solid rgba(21, 34, 37, 0.18);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 18px rgba(21, 34, 37, 0.14);
}

.leaflet-control-zoom a {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  color: var(--text);
  background: #fffdfa;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
}

.leaflet-control-zoom a + a {
  border-top: 1px solid var(--line);
}

.leaflet-control-attribution {
  margin: 0;
  padding: 3px 6px;
  color: var(--muted);
  background: rgba(255, 253, 250, 0.88);
  font-size: 0.68rem;
}

.leaflet-control-attribution a {
  color: var(--accent-strong);
}

.leaflet-right .leaflet-control {
  float: right;
  margin-right: 10px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 10px;
}

.leaflet-popup {
  position: absolute;
  text-align: center;
}

.leaflet-popup-content-wrapper {
  padding: 1px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(21, 34, 37, 0.22);
}

.leaflet-popup-content {
  min-width: 120px;
  margin: 12px;
  font-size: 0.82rem;
  line-height: 1.35;
}

.leaflet-popup-tip-container {
  position: absolute;
  left: 50%;
  width: 40px;
  height: 20px;
  margin-left: -20px;
  overflow: hidden;
  pointer-events: none;
}

.leaflet-popup-tip {
  width: 14px;
  height: 14px;
  margin: -7px auto 0;
  background: #fff;
  transform: rotate(45deg);
  box-shadow: 0 10px 24px rgba(21, 34, 37, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  min-height: 100vh;
}

.map-stage {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background: var(--map-water);
}

.map {
  position: absolute;
  inset: 0;
}

.search-panel {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 800;
  width: min(560px, calc(100% - 40px));
  padding: 12px;
  border: 1px solid rgba(21, 34, 37, 0.12);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.96);
  box-shadow: 0 16px 36px rgba(21, 34, 37, 0.16);
}

.search-label {
  display: block;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.search-row input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #ffffff;
  outline: none;
}

.search-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.primary-button,
.tool-button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  font-weight: 700;
}

.primary-button {
  padding: 0 18px;
  color: #fff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.search-results {
  max-height: 280px;
  margin-top: 10px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.result-button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid #ece6dc;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.result-button:hover,
.result-button:focus {
  background: var(--accent-soft);
  outline: none;
}

.result-button strong {
  display: block;
  font-size: 0.95rem;
}

.result-button span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8rem;
}

.map-tools {
  position: absolute;
  right: 20px;
  bottom: 68px;
  z-index: 750;
  display: flex;
  gap: 8px;
}

.tool-button {
  padding: 0 12px;
  border: 1px solid rgba(21, 34, 37, 0.14);
  color: var(--text);
  background: rgba(255, 253, 250, 0.94);
  box-shadow: 0 10px 22px rgba(21, 34, 37, 0.12);
}

.tool-button:hover {
  border-color: var(--accent);
}

.status-bar {
  position: absolute;
  right: 20px;
  bottom: 20px;
  left: 20px;
  z-index: 700;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 6px;
  color: #fff;
  background: rgba(21, 34, 37, 0.82);
  font-size: 0.86rem;
}

.detail-panel {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.panel-header {
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-header h1 {
  margin: 6px 0 0;
  font-size: 1.45rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.empty-state {
  padding: 32px 24px;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.property-state {
  padding-bottom: 24px;
}

.valuation-summary {
  display: grid;
  border-bottom: 1px solid var(--line);
}

.valuation-output {
  min-width: 0;
  padding: 20px 24px;
}

.valuation-output + .valuation-output {
  border-top: 1px solid var(--line);
}

.baseline-output {
  background: #f0f7f4;
}

.weighted-output {
  background: #fff8e8;
}

.value-output-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.value-output-heading .section-kicker {
  min-width: 0;
}

.adjustment-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  color: #355057;
  background: #e8ede9;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.adjustment-badge.positive {
  color: #0f3d2e;
  background: #d7f0dd;
}

.adjustment-badge.negative,
.adjustment-badge.unavailable {
  color: #7a271a;
  background: #f9d7d3;
}

.estimate-value {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: 1.42rem;
  line-height: 1.18;
  letter-spacing: 0;
}

.estimate-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.value-disclaimer {
  margin: 8px 0 0;
  color: #6b5b3f;
  font-size: 0.72rem;
  line-height: 1.4;
}

.valuation-output:last-child {
  border-bottom: 1px solid var(--line);
}

.confidence-badge,
.match-badge,
.count-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.confidence-badge {
  color: #0f3d2e;
  background: #d7f0dd;
}

.confidence-badge.medium {
  color: #6a4000;
  background: #f9e4b7;
}

.confidence-badge.low,
.confidence-badge.insufficient {
  color: #7a271a;
  background: #f9d7d3;
}

.match-badge,
.count-badge {
  color: #355057;
  background: #e8ede9;
}

.model-breakdown {
  margin: 18px 24px 0;
  padding: 14px;
  border: 1px solid #d7e6df;
  border-radius: 8px;
  background: #fbfffd;
}

.model-breakdown h2 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  line-height: 1.2;
}

.breakdown-list,
.school-list,
.panel-section {
  display: grid;
  gap: 8px;
}

.panel-section {
  padding: 22px 24px 0;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-section h2 {
  margin: 0 0 12px;
  font-size: 0.92rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.control-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.model-select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
}

.model-select:focus-visible,
.weight-row input:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.2);
  outline-offset: 2px;
}

.weight-controls {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.weight-row {
  display: grid;
  gap: 5px;
}

.weight-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.82rem;
}

.weight-label-row label {
  min-width: 0;
  font-weight: 700;
}

.weight-label-row output {
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.weight-row input[type="range"] {
  width: 100%;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
}

.model-control-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.4;
}

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

.driver-group {
  min-width: 0;
  padding-top: 8px;
  border-top: 2px solid var(--line);
}

.positive-driver-group {
  border-top-color: var(--green);
}

.risk-driver-group {
  border-top-color: var(--red);
}

.driver-group h3 {
  margin: 0 0 7px;
  font-size: 0.74rem;
}

.driver-list {
  display: grid;
  gap: 6px;
}

.driver-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: start;
  min-width: 0;
  font-size: 0.74rem;
  line-height: 1.3;
}

.driver-item span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.driver-item strong {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty-driver {
  display: block;
  color: var(--muted);
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.neutral {
  color: var(--gold);
}

.model-factor-list {
  display: grid;
  gap: 8px;
}

.model-factor-item {
  border: 1px solid #e8e1d6;
  border-radius: 7px;
  background: #fff;
}

.model-factor-item.low-confidence {
  border-color: #e6d3aa;
}

.model-factor-item.unavailable {
  border-color: #e1cbc7;
}

.model-factor-item summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 10px 12px;
  cursor: pointer;
  list-style-position: inside;
}

.model-factor-item summary > span {
  min-width: 0;
}

.model-factor-item summary strong,
.model-factor-item summary small {
  display: block;
}

.model-factor-item summary strong {
  font-size: 0.86rem;
}

.model-factor-item summary small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
}

.factor-impact {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.factor-detail {
  padding: 0 12px 12px;
  border-top: 1px solid #eee7dc;
}

.factor-detail p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.factor-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 0;
}

.factor-metrics div {
  min-width: 0;
}

.factor-metrics dt {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
}

.factor-metrics dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-size: 0.78rem;
  font-weight: 700;
}

.factor-source strong {
  color: var(--text);
}

.fact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}

.fact-grid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid #e8e1d6;
  border-radius: 7px;
  background: #fff;
}

.fact-grid dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.fact-grid dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  line-height: 1.32;
}

.factor-list,
.sales-list,
.notes-list {
  display: grid;
  gap: 8px;
}

.factor-item,
.breakdown-item,
.school-item,
.sale-item,
.note-item {
  padding: 11px 12px;
  border: 1px solid #e8e1d6;
  border-radius: 7px;
  background: #fff;
}

.breakdown-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 9px 10px;
  border-color: #dce9e3;
}

.factor-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.breakdown-item strong,
.factor-item strong,
.school-item strong,
.sale-item strong {
  display: block;
  font-size: 0.9rem;
}

.breakdown-item span,
.factor-item span,
.school-item span,
.sale-item span,
.note-item {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.breakdown-item b {
  color: var(--accent-strong);
  font-size: 0.85rem;
  white-space: nowrap;
}

.factor-score {
  font-weight: 800;
}

.factor-score.good {
  color: var(--green);
}

.factor-score.neutral {
  color: var(--gold);
}

.factor-score.poor {
  color: var(--red);
}

.sale-item {
  display: grid;
  gap: 5px;
}

.school-group-label {
  margin-top: 4px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.school-item {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
}

.school-item.future {
  border-color: #d9c5a3;
  background: #fffaf1;
}

.school-warning {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.sale-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.notes-panel {
  margin: 22px 24px 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.notes-panel summary {
  cursor: pointer;
  padding: 12px 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.notes-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.notes-panel .notes-list {
  padding-left: 18px;
  list-style: disc;
}

.notes-panel .note-item {
  padding: 0 0 6px 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 0.75rem;
  line-height: 1.35;
  list-style: disc;
}

.source-footer {
  margin-top: auto;
  padding: 18px 24px 24px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.leaflet-container {
  background: #d7e8ec;
  font: inherit;
}

.sale-marker {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: #9f4b1e;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.22);
  font-size: 0.72rem;
  font-weight: 900;
}

.selected-pin {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.25);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .map-stage {
    min-height: 58vh;
  }

  .detail-panel {
    min-height: 42vh;
    max-height: none;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 620px) {
  .search-panel {
    top: 12px;
    left: 12px;
    width: calc(100% - 24px);
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .map-tools {
    right: 12px;
    bottom: 58px;
    left: 12px;
    justify-content: flex-end;
  }

  .status-bar {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  .fact-grid {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .valuation-output,
  .panel-section,
  .model-breakdown,
  .notes-panel,
  .source-footer,
  .empty-state {
    padding-right: 18px;
    padding-left: 18px;
  }

  .model-breakdown,
  .notes-panel {
    margin-right: 18px;
    margin-left: 18px;
  }

  .breakdown-item {
    grid-template-columns: 1fr;
  }

  .driver-grid,
  .factor-metrics {
    grid-template-columns: 1fr;
  }
}
