:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #111827;
  --muted: #667085;
  --line: #e5e7eb;
  --accent: #111827;
  --soft: #eef1f5;
  --green: #16704a;
  --red: #a33a3a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.topbar {
  padding: 34px max(24px, calc((100vw - 1320px)/2));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 30px;
}
h1,h2,h3,h4,p { margin-top: 0; }
h1 { font-size: 32px; margin-bottom: 8px; letter-spacing: -.04em; }
h2 { font-size: clamp(30px, 4vw, 52px); line-height: 1.02; letter-spacing: -.05em; margin: 8px 0 18px; max-width: 720px; }
h3 { margin-bottom: 5px; font-size: 18px; }
h4 { margin-bottom: 4px; font-size: 15px; }
.sub, .card-head p, .hero p { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 750; color: #7a8494; }
.badge, .tag {
  height: fit-content; border: 1px solid #cfd5dd; padding: 7px 10px;
  border-radius: 999px; font-size: 10px; font-weight: 800; letter-spacing: .08em;
}
main { max-width: 1320px; margin: auto; padding: 30px 24px 70px; }
.hero { display: flex; justify-content: space-between; align-items: end; padding: 25px 0 35px; gap: 40px; }
.metrics { display: grid; grid-template-columns: repeat(5,1fr); gap: 12px; margin-bottom: 18px; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .value { font-size: 27px; font-weight: 750; margin: 8px 0 2px; letter-spacing: -.03em; }
.metric .detail { color: var(--muted); font-size: 11px; }
.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.two { grid-template-columns: 1fr 1fr; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; margin-bottom: 18px; }
.chart-card { min-height: 370px; }
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 20px; margin-bottom: 14px; }
.card-head p { font-size: 12px; margin: 0; }
canvas { max-height: 285px; }

/* ── Base inputs ── */
input, select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  background: var(--panel); color: var(--text); font-size: 13px;
  outline: none; transition: border-color .15s;
}
input:focus, select:focus { border-color: #9ca3af; }

/* ── Explorer filter grid ── */
.explorer-filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.filter-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.filter-group {
  display: flex; align-items: center; gap: 4px;
  background: var(--soft); border: 1px solid var(--line);
  border-radius: 9px; padding: 4px 10px;
}
.filter-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.filter-sep   { font-size: 11px; color: var(--muted); }
.filter-select-wide { min-width: 200px; }
.filter-select      { min-width: 130px; }
.filter-short { width: 72px; border: none; background: transparent; padding: 2px 4px; font-size: 13px; }
.filter-short:focus { border: none; outline: none; }
.filter-check {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--muted); cursor: pointer;
  padding: 4px 8px;
}
/* Legacy classes kept for modal / other uses */
.filter-num  { width: 130px; }
.filter-text { min-width: 180px; }

/* ── Purchase type radios ── */
.radio-label {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 10px; border-radius: 7px; border: 1px solid var(--line);
  background: white; cursor: pointer; font-size: 12px; white-space: nowrap;
}
.radio-label:has(input:checked) {
  background: var(--accent); color: white; border-color: var(--accent);
}

/* ── School search + autocomplete ── */
.school-search-wrap { position: relative; }
.filter-school {
  width: 220px; border-radius: 8px; padding: 7px 10px; font-size: 13px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.filter-school:focus { border-color: #9ca3af; outline: none; }
.school-autocomplete {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 300;
  min-width: 240px; max-height: 240px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.13);
  padding: 4px 0;
}
.school-option {
  padding: 7px 14px; font-size: 12px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.school-option:hover { background: var(--soft); }
.school-option.selected { color: var(--green); font-weight: 600; }
.school-option.selected::after { content: " ✓"; }

/* ── Selected school chips ── */
.school-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.school-tag {
  display: inline-flex; align-items: center; gap: 5px;
  background: #e6f4ed; border: 1px solid #b6dfc8; color: var(--green);
  border-radius: 20px; padding: 3px 10px;
  font-size: 11px; font-weight: 600;
}
.school-tag-remove {
  cursor: pointer; font-size: 14px; line-height: 1;
  opacity: .6; margin-left: 1px;
}
.school-tag-remove:hover { opacity: 1; }

/* ── Project search + autocomplete (multi-select) ── */
.project-search-wrap { position: relative; }
.project-autocomplete {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 300;
  min-width: 240px; max-height: 240px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.13);
  padding: 4px 0;
}
.project-option {
  padding: 7px 14px; font-size: 12px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.project-option:hover { background: var(--soft); }
.project-option.selected { color: var(--green); font-weight: 600; }
.project-option.selected::after { content: " ✓"; }

.project-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.project-tag {
  display: inline-flex; align-items: center; gap: 5px;
  background: #e6f4ed; border: 1px solid #b6dfc8; color: var(--green);
  border-radius: 20px; padding: 3px 10px;
  font-size: 11px; font-weight: 600;
}
.project-tag-remove {
  cursor: pointer; font-size: 14px; line-height: 1;
  opacity: .6; margin-left: 1px;
}
.project-tag-remove:hover { opacity: 1; }

/* ── Adjustment bar ── */
.adj-bar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--soft); border-radius: 10px;
  margin-bottom: 14px; font-size: 13px;
}
.adj-label { display: flex; align-items: center; gap: 6px; }
.adj-num { width: 52px; padding: 4px 6px; font-size: 12px; }
.adj-hint { color: var(--muted); font-size: 11px; }
.adj-active { font-size: 12px; font-weight: 600; color: var(--accent); }

/* ── Table ── */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  color: var(--muted); text-align: left; font-size: 10px;
  text-transform: uppercase; letter-spacing: .07em;
  padding: 11px 8px; border-bottom: 1px solid var(--line);
  user-select: none; white-space: nowrap;
}
th[data-col] { cursor: pointer; }
th[data-col]:hover { color: var(--text); }
th.sort-asc::after  { content: " ↑"; color: var(--accent); }
th.sort-desc::after { content: " ↓"; color: var(--accent); }
td { padding: 12px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td:first-child { font-weight: 650; white-space: normal; min-width: 200px; }
.good { color: var(--green); font-weight: 700; }
.bad  { color: var(--red); }
.muted-val { color: var(--muted); }
.cagr-pos { color: var(--green); font-weight: 600; }
.cagr-neg { color: var(--red);   font-weight: 600; }
.bucket-row { cursor: pointer; }
.bucket-row:hover { background: var(--soft); }
.selected-row { background: #eef3ff !important; }

/* ── Info tooltip (JS-driven floating div — not clipped by overflow) ── */
.info-tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--muted); color: #fff;
  font-size: 8px; font-weight: 800; cursor: default;
  margin-left: 3px; vertical-align: middle; flex-shrink: 0;
  text-transform: none; letter-spacing: 0;
}
.float-tip {
  position: fixed; z-index: 9999;
  background: #1c1c2e; color: #f0f0f5;
  font-size: 11px; font-weight: 400; line-height: 1.6;
  padding: 9px 12px; border-radius: 9px;
  width: 240px; max-width: 80vw;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
  white-space: normal;
}

/* ── CAGR method note (modal chart) ── */
.cagr-method {
  font-size: 11px; color: var(--muted); line-height: 1.6;
  background: var(--soft); border-radius: 8px;
  padding: 9px 12px; margin-top: 10px;
}

/* ── Chart date-range filter row ── */
.chart-filter-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 8px; font-size: 12px;
}
input[type="month"] {
  border: 1px solid var(--line); border-radius: 9px; padding: 5px 8px;
  background: white; color: var(--text); font-size: 12px;
}
.chart-size-note {
  font-size: 11px; color: var(--muted); margin-left: auto;
  font-style: italic;
}

/* ── GFA badge ── */
.badge-gfa {
  display: inline-block; font-size: 9px; font-weight: 800; letter-spacing: .06em;
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
  border-radius: 4px; padding: 1px 4px; vertical-align: middle; margin-left: 4px;
}
.badge-hdb {
  display: inline-block; font-size: 9px; font-weight: 800; letter-spacing: .06em;
  background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd;
  border-radius: 4px; padding: 1px 5px; vertical-align: middle;
}
.badge-condo {
  display: inline-block; font-size: 9px; font-weight: 800; letter-spacing: .06em;
  background: #f3f4f6; color: #374151; border: 1px solid #d1d5db;
  border-radius: 4px; padding: 1px 5px; vertical-align: middle;
}
.radio-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; cursor: pointer; padding: 3px 8px;
  border: 1px solid var(--line); border-radius: 20px; user-select: none;
}
.radio-pill input { accent-color: var(--accent); }
.radio-pill:has(input:checked) {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

/* ── View button ── */
.btn-view {
  border: 1px solid var(--line); border-radius: 7px; background: white;
  padding: 5px 10px; font-size: 11px; cursor: pointer; color: var(--text);
  white-space: nowrap;
}
.btn-view:hover { background: var(--soft); }
.btn-sm { padding: 3px 8px; font-size: 10px; }

/* ── Pagination ── */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 4px 4px; font-size: 13px; flex-wrap: wrap;
}
.pg-info { color: var(--muted); }
.pg-controls { display: flex; align-items: center; gap: 10px; }
.pg-btn {
  border: 1px solid var(--line); border-radius: 7px; background: white;
  padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.pg-btn:disabled { opacity: .4; cursor: default; }
.pg-btn:not(:disabled):hover { background: var(--soft); }

/* ── Modal overlay ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 1000; display: flex; align-items: flex-start;
  justify-content: center; overflow-y: auto; padding: 40px 16px;
}
.modal-overlay[hidden] { display: none; }

/* ── Modal box ── */
.modal-box {
  background: var(--panel); border-radius: 18px; width: 100%;
  max-width: 900px; padding: 28px; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal-head {
  display: flex; justify-content: space-between; align-items: start;
  gap: 16px; margin-bottom: 16px;
}
.modal-close {
  flex-shrink: 0; border: 1px solid var(--line); border-radius: 8px;
  background: white; font-size: 15px; padding: 6px 10px; cursor: pointer;
  line-height: 1;
}
.modal-close:hover { background: var(--soft); }

.adj-bar-modal { margin-bottom: 16px; }

/* ── Modal sections ── */
.modal-section { margin-top: 24px; }
.modal-section-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.muted-sm { color: var(--muted); font-size: 11px; }

.chart-wrap-modal { height: 320px; position: relative; }

.nb-table-wrap { max-height: 280px; overflow-y: auto; }

/* ── Modal address line ── */
.modal-address {
  font-size: 12px; color: var(--muted); margin-top: 4px;
}
.map-link {
  color: var(--green); text-decoration: none; font-weight: 600;
}
.map-link:hover { text-decoration: underline; }

/* ── Chart divider (vertical rule between filter groups) ── */
.chart-divider {
  width: 1px; background: var(--line); align-self: stretch; margin: 0 4px;
  flex-shrink: 0;
}

/* ── Volume summary (filtered date range totals) ── */
.chart-vol-summary {
  font-size: 11px; color: var(--muted); margin-left: auto; font-style: italic;
}

/* ── Responsive ── */
@media(max-width:900px) {
  .metrics { grid-template-columns: repeat(2,1fr); }
  .two { grid-template-columns: 1fr; }
  .hero { align-items: start; flex-direction: column; }
  .topbar { align-items: start; flex-direction: column; }
}
@media(max-width:520px) {
  main { padding: 20px 14px 50px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric .value { font-size: 21px; }
  .modal-box { padding: 18px; }
}

/* MRT price trend comparison */
.mrt-trend-controls { margin-top: 10px; }
.mrt-trend-controls .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.mrt-trend-chart { position: relative; height: 320px; margin-top: 8px; }
